Simplify return operation
Some checks failed
Build / build (push) Failing after 1m11s
Test / build (push) Failing after 11m42s

This commit is contained in:
Chuck Smith
2024-03-18 16:33:39 -04:00
parent b47a39e1b2
commit 98c8582fdb
7 changed files with 87 additions and 51 deletions

View File

@@ -247,7 +247,7 @@ func (vm *VM) Run() error {
return err
}
case code.OpReturnValue:
case code.OpReturn:
returnValue := vm.pop()
frame := vm.popFrame()
@@ -258,15 +258,6 @@ func (vm *VM) Run() error {
return err
}
case code.OpReturn:
frame := vm.popFrame()
vm.sp = frame.basePointer - 1
err := vm.push(Null)
if err != nil {
return err
}
case code.OpSetLocal:
localIndex := code.ReadUint8(ins[ip+1:])
vm.currentFrame().ip += 1

View File

@@ -252,7 +252,8 @@ func TestConditionals(t *testing.T) {
{"if (1 > 2) { 10 } else { 20 }", 20},
{"if (1 > 2) { 10 }", Null},
{"if (false) { 10 }", Null},
{"if ((if (false) { 10 })) { 10 } else { 20 }", 20},
//{"if ((if (false) { 10 })) { 10 } else { 20 }", 20},
{"let x = 0; if (true) { x = 1; }; if (false) { x = 2; }; x", 1},
}
runVmTests(t, tests)