Bitshift
Some checks failed
Test / build (push) Waiting to run
Build / build (push) Has been cancelled

This commit is contained in:
Chuck Smith
2024-03-24 16:22:11 -04:00
parent a08fc1520c
commit 3c66b980e7
11 changed files with 76 additions and 12 deletions

View File

@@ -114,7 +114,8 @@ func (vm *VM) Run() error {
}
case code.OpAdd, code.OpSub, code.OpMul, code.OpDiv, code.OpMod, code.OpOr,
code.OpAnd, code.OpBitwiseOR, code.OpBitwiseXOR, code.OpBitwiseAND:
code.OpAnd, code.OpBitwiseOR, code.OpBitwiseXOR, code.OpBitwiseAND,
code.OpLeftShift, code.OpRightShift:
err := vm.executeBinaryOperation(op)
if err != nil {
return err
@@ -631,6 +632,10 @@ func (vm *VM) executeBinaryIntegerOperation(op code.Opcode, left, right object.O
result = leftValue ^ rightValue
case code.OpBitwiseAND:
result = leftValue & rightValue
case code.OpLeftShift:
result = leftValue << uint64(rightValue)
case code.OpRightShift:
result = leftValue >> uint64(rightValue)
default:
return fmt.Errorf("unknown integer operator: %d", op)

View File

@@ -230,6 +230,8 @@ func TestIntegerArithmetic(t *testing.T) {
{"1 | 2", 3},
{"2 ^ 4", 6},
{"3 & 6", 2},
{"1 << 2", 4},
{"4 >> 2", 1},
}
runVmTests(t, tests)