Skip to content

Moving towards references for the AST #34

@Victorious3

Description

@Victorious3

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

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions