JSAbrahams / mamba

🐍 The Mamba programming language, because we care about safety
MIT License
90 stars 4 forks source link

Desugar calls to either python functions or descriptors #19

Closed JSAbrahams closed 5 years ago

JSAbrahams commented 5 years ago

Description of the feature

Calls in the Mamba programming language can either be to a function with no arguments or can be a call to an attribute of an object.

In Python, a.b and a.c() are two different things. In Mamba, We can call function c using a.c, a.c() and a c. During the desugar stage we should either desugar based to a function call or descriptor access based on the type of a in this example.

Description of potential solution

During the desugar stage there should be some sort of context which should allow us to get the type of an expression, and the accompanying functions. With this list of functions, we can determine whether we wish to access a function or an attribute.

Alternatives considered

It is also possible to check the type of everything again in the desugar stage. However, this seems inefficient and would add a lot of unnecessary code, since this is already done in the type checking stage.

Additional context

We should also think of a system of how to check python files directly. Currently, the type checker will now only check the types, and the functions they contain, in Mamba files, and not Python files.

JSAbrahams commented 5 years ago

Can use types defined in #65 and the state and context added in #71 . Perhaps it might be better to annotate ASTNodes with types in the type checker, which will make it easier to check the type of identifiers to check whether they're a field/method, or if not, which fields/methods the class has of said identifier.

JSAbrahams commented 5 years ago

102 should simplify this somewhat, though we still need to check whether something is a function or a property (a function requires brackets in Python).

JSAbrahams commented 5 years ago

Mamba has now been changed such that postfix notation is always interpreted as passing an argument to a function for the sake of readability. To access properties we must always use dot notation.