Bitshift
This commit is contained in:
7
vm/vm.go
7
vm/vm.go
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user