seanbaxter / circle

The compiler is available for download. Get it!
http://www.circle-lang.org/
2.35k stars 72 forks source link

TLDR: avoid the need for forward declaring identifiers; (add the possibility to declare functions/structs/etc.. not in order) #176

Open chrim05 opened 1 year ago

chrim05 commented 1 year ago

a problem that c/c++ ambiguous syntax made is

auto main() -> int
{
    // the compiler doesn't know what "person_t" is
    return person_t("crim", 1234).age;
}

// because it's declared below the caller
// and this is necessary in c/c++ because
// syntaxes such as
// `a * b` as statements are ambiguous,
// and can be parsed correctly only doing sema during parsing.
// coupling sema and parsing makes it necessary to have a forward declaration
// of "person_t" (actually not possible in this case,
// but it is with functions, which are currently affected by the same problem)
// so that we now know what "a" is, in order to know
// what the statement is as well
struct person_t
{
    char const* name;
    int age;

    person_t(char const* name, int age) { helper(name, age); }

    // in containers such as classes, you can actually
    // use code declared below
    auto helper(char const* name, int age) -> void
    {
        this->name = name;
        this->age = age;
    }
};

but this ambiguities are no longer a thing when using #feature on new_decl_syntax.

here is my question, would it be possible for circle compiler to avoid the need to forward declare members when "new_decl_syntax" is enabled? since it kills ambiguities

(or is this already possible to achieve? because i couldn't find anything related in the circle doc)

chrim05 commented 6 months ago

Updates????