added while and do-while loops

This commit is contained in:
cozis
2021-11-03 01:25:18 +00:00
parent 035649bd63
commit c0d788656e
7 changed files with 328 additions and 7 deletions
+32
View File
@@ -633,6 +633,38 @@ static _Bool step(Runtime *runtime, Error *error)
runtime->frame->index = ops[0].as_int;
return 1;
case OPCODE_JUMPIFANDPOP:
{
assert(opc == 1);
assert(ops[0].type == OPTP_INT);
long long int target = ops[0].as_int;
if(runtime->frame->used == 0)
{
Error_Report(error, 1, "Frame doesn't have enough items on the stack to execute JUMPIFNOTANDPOP");
return 0;
}
Object *top = Stack_Top(runtime->stack, 0);
if(!Runtime_Pop(runtime, error, 1))
return 0;
assert(top != NULL);
if(!Object_IsBool(top))
{
Error_Report(error, 1, "JUMPIFNOTANDPOP expected a boolean on the stack");
return 0;
}
if(Object_ToBool(top, error)) // This can't fail because we know it's a bool.
runtime->frame->index = target;
return 1;
}
case OPCODE_JUMPIFNOTANDPOP:
{
assert(opc == 1);