addz(node TreeNode) macro TreeNode {
type Class = node
type.fields.add(quote {
z Int
})
ret type
}
@addz Foo < Object {
x Int
}
main() Int {
f = Foo()
f.z = 100
ret 0
}
Note that this requires a few things:
An interpreter
A cleaner, more homogenous parse tree
In particular, the code z Int is context-dependent: It could be either a local var definition, or an attribute definition. Probably need to modify the parse tree to make both represented by some common node (e.g., "Var") rather than "Assignment" and "Attribute" as is currently done.
Example:
Note that this requires a few things:
In particular, the code
z Int
is context-dependent: It could be either a local var definition, or an attribute definition. Probably need to modify the parse tree to make both represented by some common node (e.g., "Var") rather than "Assignment" and "Attribute" as is currently done.