JSAbrahams / mamba

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

Just build a type system, all of it (mostly) #159

Closed JSAbrahams closed 4 years ago

JSAbrahams commented 5 years ago

Relevant issues

Summary

Integrate generics by creating layered type checker:

A Context has GenericTypes internally, and exports Types when given a name of Type and a list of Generics.

An Environment maps Strings to ExpressionTypes. ExpressionTypes internally store two booleans, one for mutability, and another for nullability. An ExpressionType stores either a single, tuple, or anonymous function of Types.

In the type inference stage, we return InferTypes. InferTypes store a list of errors that the statement or expression may throw, which should be handled, in addition to an Optional ExpressionType, which may be None for statements.

We should perhaps consider dropping Singlar Types in favour of only Tuples and Anonymous Functions, as Tuples can also just store a vector of a single Type.

Also add Python primitives by default to the context with the accompanying methods that are defined for these primitives.

Added Tests