prefix expressions

This commit is contained in:
Chuck Smith
2024-02-07 10:51:09 -05:00
parent dcc869a6e2
commit cff4375649
5 changed files with 84 additions and 0 deletions

View File

@@ -91,6 +91,21 @@ func (c *Compiler) Compile(node ast.Node) error {
c.emit(code.OpFalse)
}
case *ast.PrefixExpression:
err := c.Compile(node.Right)
if err != nil {
return err
}
switch node.Operator {
case "!":
c.emit(code.OpBang)
case "-":
c.emit(code.OpMinus)
default:
return fmt.Errorf("unknown operator %s", node.Operator)
}
}
return nil