Releases: JSAbrahams/mamba
Releases · JSAbrahams/mamba
Dictionaries
Language Features
- Add parsing and checking of dictionary (builders) (#438 )
- Index uses
__getitem__
magic method (#438) - Annotate collections with their type (#437)
- Change
String
toStr
(#435) - Allow arm conditions without identifier in
handle
(#423)
Bug Fixes
- Verify that types actually exist (#429)
- Can again infer type of an if expression (#367)
- Don't generate ternary expression if it contains
raises
(#420)
Internal
Error Handling
- Exceptions in handle arms used when checking #382
- Variables declared in match arm conditions usable in match arm bodies #382
- Create dummy classes in Context for import statements #379
- Allow comments in source without issue by filtering them out in parse stage #381
- Don't allow return outside functions #390
isa
now properly expects an identifier, which identifies a class #391- Expression type of match propagated to arms #397
- Types of equality don't need to be the same #399
Match and If Expressions
- Add if expressions, which are converted to Python ternary expressions
- Allow match expressions (i.e. match to be treated as an expression)
- For both if and match expressions:
- Convert expressions in if and match arms to return in function if necessary
- Propagate assign to variable inwards into arms if necessary
- Check stage checks if body of function was empty
- Interfaces specify that they are
ABC
in Python (Abstract Base Class) None
is treated as a special class, not as a special keyword
Match Statements
- Make use of match statements in output source from Python 3.10.
- Use new assign tokens:
+=
,-=
,*=
,/=
,^=
,<<=
,>>=
- Change not equal token:
/=
->!=
- Add check that
self
fields can only be used if assigned to first. - Improve readability of some error messages.
- Start annotating output, though currently annotations are inconsistent.
- Checker can deal with chains of calls
a.b.c.
... - Simplify grammar such that classes, type definitions, and imports can be placed in any block.
The checker does not yet have logic to deal with such situations, however.
Range and Slice
- Add
Range
andSlice
to the language- A range is an expression, may be iterated over, and has the following notation:
expression ( .. | ..= ) expression [ .. expression]
- A slice is an expression, and has the following notation:
expression ( :: | ::= ) expression [ :: expression ]
Note that unlike Python, we use::
instead of:
to separate single arguments to the slice.
- A range is an expression, may be iterated over, and has the following notation:
- Can iterate over all types which implement an iterator
- Fix several bugs associated with constraining function call arguments with expressions and property calls
Tuples
Constraint generation, substitution, and unification
- Use new constraint substitution and unification algorithm for type inference
- Check that statement raises exception that it mentions
A few language features have been removed, these will be re-added as time goes along:
- Iterating over Tuples
- Mutable fields within tuples
- Nested function calls
- Mutability checks
Remove retry and function default arguments
- Parse docstrings (without checking if they are in the correct location)
- Remove
retry
keyword from the language - Allow passing of default arguments to functions
- Identify constructors in AST and desugar function call identifier as a class name if indeed constructor
Type check f-strings
- Type check expressions within f-strings
- Fix parsing of tuples
- Allow mutable fields within tuples
- Fields within tuples are class fields if the tuple is a top-level declaration in a class
- Disallow access to private fields and functions from outside a class
Basic Type Checker
We have a first basic version of the type checker:
- Remove
?or
from language, which is almost identical to?
- Build Contexts and Environments
- Add simple analysis of project Python files and add these to the typing context
- Check mutability of variables
- Do very simple type checking (in future we should use constraint type checking)
- Add desugaring of inline calls to super and inline constructor arguments
- Add types to variables and functions where necessary
- Check whether a type is iterable by checking that it defines an
__iter()__
method - Implement null safety, with
undefined
representingnull
, orNone
in Python. This is done in a similar fashion to Kotlin, and is baked into the type checker. We opted to not use anOptional
type solution, as this makes code slightly too verbose for our purposes
Note we have used the nightly TryFrom
feature of Rust. So to build the project, you need the nightly version of Rustc.