added not operator

This commit is contained in:
cozis
2021-12-08 13:20:34 +01:00
parent 51d744ef2e
commit dbf1c325b0
10 changed files with 216 additions and 1 deletions
+32
View File
@@ -557,6 +557,38 @@ static _Bool step(Runtime *runtime, Error *error)
Error_Report(error, 1, "NEG not implemented");
return 0;
case OPCODE_NOT:
{
assert(opc == 0);
if(runtime->frame->used == 0)
{
Error_Report(error, 1, "Frame doesn't have enough items on the stack to execute NOT");
return 0;
}
Object *top = Stack_Top(runtime->stack, 0);
if(!Runtime_Pop(runtime, error, 1))
return 0;
assert(top != NULL);
_Bool v = Object_ToBool(top, error);
if(error->occurred)
return 0;
Object *negated = Object_FromBool(!v, runtime->heap, error);
if(negated == NULL)
return 0;
if(!Runtime_Push(runtime, error, negated))
return 0;
return 1;
}
case OPCODE_ADD:
case OPCODE_SUB:
case OPCODE_MUL: