Repository navigation
v0.1.35
0.1.35
Python language support
- Added Python language support (parse, run, and code-generation target),
emitting strict, idiomatic Python 3.- Indentation-significant blocks are handled by an INDENT/DEDENT/NEWLINE
pre-tokenizer (PythonIndentationPreprocessor), so the petitparser grammar
consumes Python suites like braces; implicit ((/[/{) and explicit (\)
line continuations, blank/comment lines, and string literals are handled,
and the source is dedented by its common minimum indentation (so a
uniformly-indented embedded block parses like a flush-left one). - Strict generation: PEP-484 type hints when the AST type is statically known
(def f(x: int) -> int:,x: str = ...,List[T]/Dict[K, V]), with a
dynamic/untyped fallback;==/!=,and/or/not,//integer division,
True/False/None, f-strings for interpolation, andself-based methods. - Supports functions, variables (Python first-binding-is-declaration scoping),
arithmetic/comparison/boolean expressions,if/elif/else,while,
for ... in,try/except/finally+raise,classwith methods, lists
& dicts, andimport/from ... import. - Registered
python(py/.py) acrossgetParser,createRunner,
createCodeGenerator, and the CLI.
- Indentation-significant blocks are handled by an INDENT/DEDENT/NEWLINE
Wasm: print accepts any value (not only String)
int/doublereuse the host number-to-string imports (env.int_to_str/
env.double_to_str);boollowers in-module to the interned"true"/
"false"literals (viaselect);print(null)prints"null". String
interpolation gained the same parity.- The interpreter's mapped
printnow acceptsnull(nullableObject?), and a
boolargument passed to a public Wasm function is marshalled to its i32 ABI
value.
Classes and instantiation (Dart, Java, and Wasm)
- The
newkeyword is now parsed in Dart and Java (new User());new User()
andUser()resolve to the same constructor (boundary-safe, so identifiers
likenewValueare unaffected). Java also gained a generic
new ClassName(args)rule (previously onlynew ArrayList<…>()/
new HashMap<…>()were recognized). - Classes that declare no constructor get an implicit default (zero-arg)
constructor — on the interpreter and the Wasm backend; field initializers still
apply. - Constructors that set fields:
this.fieldparameters, and constructor
bodies that assign fields (this.field = valueand barefield = value,
with parameters shadowing same-named fields, e.g.User(int id) { this.id = id; }).
Fixed empty-parameter constructors with a body (User() { … }), which threw a
parser cast error. - A class method can instantiate sibling classes and call top-level functions
(ASTClass.getFunctionfalls back to the enclosingASTRoot) — essential for
Java, where all code lives in a class. - Dart arrow (expression-bodied) functions and methods:
T name(params) => expr;
(e.g.String toString() => '…';), for top-level functions and instance
methods, includingvoidbodies. Desugars to{ return expr; }. - WebAssembly compilation of classes (first slice): single classes (no
inheritance) withint/double/bool/String/ object-reference
fields, constructors (this.fieldparams, field initializers, default and
body constructors), instance methods, in-code instantiation, and method calls
(p.sum()and implicit-thisfoo()). An object is an i32 pointer to a
bump-allocated struct; methods takethisas the first parameter; a discovery
pass registers host imports before the code section so cross-function call
indices stay correct.
Object field access on instances (read and write)
- Field assignment
obj.field = value(andthis.field = value), including
compound operators (+=,-=,*=,/=,~/=), via a new
ASTExpressionObjectSetterAssignmentnode — added to the Dart, Java, Kotlin,
JavaScript and TypeScript grammars, the shared source generator (round-trips
back toobj.field = value), and the Wasm backend (stores atrecv + offset). - Field read
obj.fieldis now supported in Java (which had no object
getter-access rule);this.fieldreads resolve to the current instance's field
across all languages (previously routed to a local-getter lookup and failed
with "Can't find getter").
print(obj) calls the user-defined toString()
- Interpreter:
print(instance)invokes a user-declaredtoString()(a class
without one still prints the defaultClass{…}representation), and
ASTExternalFunction.callnow awaits resolved argument values so an async
resolver result isn't passed through as aFuture. - Wasm:
print(instance)(and string coercion / interpolation) calls the
instance's compiledtoString()and prints the resulting string handle.
This makes programs like the following compile and run on Wasm with
interpreter-parity:
class User {
int id;
String name;
User(this.id, this.name);
String toString() => 'User#$id<$name>';
}
void main() {
var user = new User(123, 'Joe');
print(user);
print(user.id * 1000);
}Not included: inheritance / interfaces / abstract / static members /
polymorphism.