reassign values
Some checks failed
Build / build (push) Failing after 1m46s
Test / build (push) Has been cancelled

This commit is contained in:
Chuck Smith
2024-03-15 15:24:48 -04:00
parent c818591f79
commit 2988719c9c
13 changed files with 327 additions and 17 deletions

View File

@@ -198,6 +198,25 @@ func (c *Compiler) Compile(node ast.Node) error {
}
}
case *ast.AssignmentStatement:
symbol, ok := c.symbolTable.Resolve(node.Name.Value)
if !ok {
return fmt.Errorf("undefined variable %s", node.Value)
}
err := c.Compile(node.Value)
if err != nil {
return err
}
if symbol.Scope == GlobalScope {
c.emit(code.OpGetGlobal, symbol.Index)
} else {
c.emit(code.OpGetLocal, symbol.Index)
}
c.emit(code.OpAssign)
case *ast.LetStatement:
symbol, ok := c.symbolTable.Resolve(node.Name.Value)
if !ok {