moulo
Some checks failed
Build / build (push) Successful in 9m45s
Test / build (push) Failing after 15m53s

This commit is contained in:
Chuck Smith
2024-03-22 16:49:33 -04:00
parent 6282075e66
commit cbb430b47d
10 changed files with 29 additions and 3 deletions

View File

@@ -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)
}

View File

@@ -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)