Arithmetic
This commit is contained in:
@@ -34,6 +34,7 @@ func (c *Compiler) Compile(node ast.Node) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
c.emit(code.OpPop)
|
||||
|
||||
case *ast.InfixExpression:
|
||||
err := c.Compile(node.Left)
|
||||
@@ -49,6 +50,12 @@ func (c *Compiler) Compile(node ast.Node) error {
|
||||
switch node.Operator {
|
||||
case "+":
|
||||
c.emit(code.OpAdd)
|
||||
case "-":
|
||||
c.emit(code.OpSub)
|
||||
case "*":
|
||||
c.emit(code.OpMul)
|
||||
case "/":
|
||||
c.emit(code.OpDiv)
|
||||
default:
|
||||
return fmt.Errorf("unknown operator %s", node.Operator)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user