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

@@ -139,6 +139,8 @@ func (c *Compiler) Compile(node ast.Node) error {
c.emit(code.OpMul)
case "/":
c.emit(code.OpDiv)
case "%":
c.emit(code.OpMod)
case ">":
c.emit(code.OpGreaterThan)
case ">=":

View File

@@ -77,6 +77,16 @@ func TestIntegerArithmetic(t *testing.T) {
code.Make(code.OpPop),
},
},
{
input: "5 % 2",
expectedConstants: []interface{}{5, 2},
expectedInstructions: []code.Instructions{
code.Make(code.OpConstant, 0),
code.Make(code.OpConstant, 1),
code.Make(code.OpMod),
code.Make(code.OpPop),
},
},
{
input: "-1",
expectedConstants: []interface{}{1},