Moved register state to scopes

This commit is contained in:
2024-07-16 15:30:28 +02:00
parent d1ccd60139
commit d6d018c5c5
22 changed files with 230 additions and 129 deletions

View File

@ -36,7 +36,9 @@ func NewFunction(name string, file *fs.File, body token.List) *Function {
Syscall: x64.SyscallRegisters,
Output: x64.ReturnValueRegisters,
},
scopes: []Scope{{}},
scopes: []*Scope{
{variables: map[string]*Variable{}},
},
finished: make(chan struct{}),
},
}
@ -52,14 +54,14 @@ func (f *Function) Compile() {
// CompileTokens compiles a token list.
func (f *Function) CompileTokens(tokens token.List) error {
tree, err := ast.Parse(tokens)
body, err := ast.Parse(tokens)
if err != nil {
err.(*errors.Error).File = f.File
return err
}
return f.CompileAST(tree)
return f.CompileAST(body)
}
// CompileAST compiles an abstract syntax tree.
@ -97,7 +99,7 @@ func (f *Function) CompileASTNode(node ast.Node) error {
return f.CompileLoop(node)
default:
panic("Unknown AST type")
panic("unknown AST type")
}
}