mfichman / jogo

High(er) performance compiled programming language with clean, powerful syntax
MIT License
6 stars 1 forks source link

Macros #72

Open mfichman opened 11 years ago

mfichman commented 11 years ago

Example:

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:

  1. An interpreter
  2. 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.