VM!
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package compiler
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"monkey/ast"
|
||||
"monkey/code"
|
||||
"monkey/object"
|
||||
@@ -45,6 +46,13 @@ func (c *Compiler) Compile(node ast.Node) error {
|
||||
return err
|
||||
}
|
||||
|
||||
switch node.Operator {
|
||||
case "+":
|
||||
c.emit(code.OpAdd)
|
||||
default:
|
||||
return fmt.Errorf("unknown operator %s", node.Operator)
|
||||
}
|
||||
|
||||
case *ast.IntegerLiteral:
|
||||
integer := &object.Integer{Value: node.Value}
|
||||
c.emit(code.OpConstant, c.addConstant(integer))
|
||||
|
||||
Reference in New Issue
Block a user