Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Moving towards references for the AST #34

Open
Victorious3 opened this issue Nov 9, 2023 · 0 comments
Open

Moving towards references for the AST #34

Victorious3 opened this issue Nov 9, 2023 · 0 comments

Comments

@Victorious3
Copy link
Contributor

Victorious3 commented Nov 9, 2023

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant