moulo
This commit is contained in:
5
vm/vm.go
5
vm/vm.go
@@ -112,7 +112,7 @@ func (vm *VM) Run() error {
|
||||
return err
|
||||
}
|
||||
|
||||
case code.OpAdd, code.OpSub, code.OpMul, code.OpDiv:
|
||||
case code.OpAdd, code.OpSub, code.OpMul, code.OpDiv, code.OpMod:
|
||||
err := vm.executeBinaryOperation(op)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -543,6 +543,9 @@ func (vm *VM) executeBinaryIntegerOperation(op code.Opcode, left, right object.O
|
||||
result = leftValue * rightValue
|
||||
case code.OpDiv:
|
||||
result = leftValue / rightValue
|
||||
case code.OpMod:
|
||||
result = leftValue % rightValue
|
||||
|
||||
default:
|
||||
return fmt.Errorf("unknown integer operator: %d", op)
|
||||
}
|
||||
|
||||
@@ -224,6 +224,7 @@ func TestIntegerArithmetic(t *testing.T) {
|
||||
{"-10", -10},
|
||||
{"-50 + 100 + -50", 0},
|
||||
{"(5 + 10 * 2 + 15 / 3) * 2 + -10", 50},
|
||||
{"5 % 2", 1},
|
||||
}
|
||||
|
||||
runVmTests(t, tests)
|
||||
|
||||
Reference in New Issue
Block a user