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

21
njvm.c
View File

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

BIN
njvm.o

Binary file not shown.

BIN
support.o

Binary file not shown.