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

@@ -148,6 +148,10 @@ func (c *Compiler) Compile(node ast.Node) error {
c.emit(code.OpBitwiseXOR)
case "&":
c.emit(code.OpBitwiseAND)
case "<<":
c.emit(code.OpLeftShift)
case ">>":
c.emit(code.OpRightShift)
case "||":
c.emit(code.OpOr)
case "&&":

View File

@@ -87,6 +87,26 @@ func TestIntegerArithmetic(t *testing.T) {
code.Make(code.OpPop),
},
},
{
input: "1 << 2",
expectedConstants: []interface{}{1, 2},
expectedInstructions: []code.Instructions{
code.Make(code.OpConstant, 0),
code.Make(code.OpConstant, 1),
code.Make(code.OpLeftShift),
code.Make(code.OpPop),
},
},
{
input: "4 >> 2",
expectedConstants: []interface{}{4, 2},
expectedInstructions: []code.Instructions{
code.Make(code.OpConstant, 0),
code.Make(code.OpConstant, 1),
code.Make(code.OpRightShift),
code.Make(code.OpPop),
},
},
{
input: "-1",
expectedConstants: []interface{}{1},