fix comparisons

This commit is contained in:
Elias Bennour 2024-01-18 20:18:21 +01:00
parent 6319ddcad9
commit 1f02f49cdf
3 changed files with 11 additions and 12 deletions

23
njvm.c
View File

@ -142,49 +142,48 @@ void execute(struct program program) {
bip.op2 = pop(stack).u.objRef;
bip.op1 = pop(stack).u.objRef;
bigFromInt(bigCmp() != 0);
push(stack,stackSlotWithObjRef(bip.res));
push(stack, stackSlotWithObjRef(bip.res));
break;
case EQ:
if (debug == 1) printf("eq: %i == %i\n", peek(stack, 2), peek(stack, 1));
bip.op2 = pop(stack).u.objRef;
bip.op1 = pop(stack).u.objRef;
if (bigCmp() == 0) push(stack, stackSlotWithObjRef(getIntObj(true)));
else push(stack, stackSlotWithObjRef(getIntObj(false)));
bigFromInt(bigCmp() == 0);
push(stack, stackSlotWithObjRef(bip.res));
break;
case LT:
if (debug == 1) printf("lt: %i < %i\n", peek(stack, 2), peek(stack, 1));
bip.op2 = pop(stack).u.objRef;
bip.op1 = pop(stack).u.objRef;
if (bigCmp() < 0) push(stack, stackSlotWithObjRef(getIntObj(true)));
else push(stack, stackSlotWithObjRef(getIntObj(false)));
bigFromInt(bigCmp() < 0);
push(stack, stackSlotWithObjRef(bip.res));
break;
case LE:
if (debug == 1) printf("le: %i <= %i\n", peek(stack, 2), peek(stack, 1));
bip.op2 = pop(stack).u.objRef;
bip.op1 = pop(stack).u.objRef;
if (bigCmp() <= 0) push(stack, stackSlotWithObjRef(getIntObj(true)));
else push(stack, stackSlotWithObjRef(getIntObj(false)));
bigFromInt(bigCmp() <= 0);
push(stack, stackSlotWithObjRef(bip.res));
break;
case GT:
if (debug == 1) printf("gt: %i > %i\n", peek(stack, 2), peek(stack, 1));
bip.op2 = pop(stack).u.objRef;
bip.op1 = pop(stack).u.objRef;
if (bigCmp() > 0) push(stack, stackSlotWithObjRef(getIntObj(true)));
else push(stack, stackSlotWithObjRef(getIntObj(false)));
bigFromInt(bigCmp() > 0);
push(stack, stackSlotWithObjRef(bip.res));
break;
case GE:
if (debug == 1) printf("ge: %i >= %i\n", peek(stack, 2), peek(stack, 1));
bip.op2 = pop(stack).u.objRef;
bip.op1 = pop(stack).u.objRef;
if (bigCmp() >= 0) push(stack, stackSlotWithObjRef(getIntObj(true)));
else push(stack, stackSlotWithObjRef(getIntObj(false)));
bigFromInt(bigCmp() >= 0);
push(stack, stackSlotWithObjRef(bip.res));
break;
case BRF:
if (debug == 1) printf("brf: %i\n", SIGN_EXTEND(IMMEDIATE(program.program[i])));
if (debug == 1) printf("pop: %i\n", peek(stack, 1));
bip.op1 = pop(stack).u.objRef;
int b = bigToInt();
printf("%i , %i",b, false);
if (b == false) {
i = SIGN_EXTEND(IMMEDIATE(program.program[i])) - 1;
if (debug == 1) printf("new i: %i\n", i);

BIN
njvm.o

Binary file not shown.

BIN
support.o

Binary file not shown.