-
Notifications
You must be signed in to change notification settings - Fork 2
Open
Description
The current AST uses the nasty union hack to implement something like a generic type.
This is because at the time of writing the AST, there was no other way of doing things.
In order to allow macros, the AST needs to become more usable, so that we can decide on an accepted format.
In theory you'd have something like this:
export type Node = interface {
let kind: NodeKind
let loc: SourceLoc
def children -> &Generator(&Node)
...
def deep_copy() -> &Node
...
}
export type Add = struct { loc: SourceLoc; left: &Node; right: &Node }
export def kind(add: &Add) -> NodeKind { return NodeKind::ADD }
export def children(add: &Add) -> &Node { yield add.left; yield add.right }
export def deep_copy(add: &Add) -> &Node {
return { add.loc, add.left.deep_copy(), add.right.deep_copy() } !&Add
}
deep_copy is just one example of a function that needs to be implemented per Node.
Right now this is done by a few huge switch cases, which definitely needs to go in the future.
Metadata
Metadata
Assignees
Labels
No labels