This commit is contained in:
nilspolek 2024-01-28 18:38:34 +01:00
parent e3b228061f
commit 0f841f9c22
6 changed files with 32 additions and 22 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

54
njvm.c
View File

@ -52,7 +52,7 @@ void execute(struct program program) {
int tempInt;
for (i = 0; i < *program.size; ++i) {
if (debug == 1 || bp == i) debugMenu(fp, stack, &debug, i, &bp);
if(debug == 1) printf("(%i)",i);
if (debug == 1) printf("(%i)", i);
switch (program.program[i] >> 24) {
case HALT:
if (debug == 1) printf("halt\n");
@ -260,25 +260,25 @@ void execute(struct program program) {
case GETF:
if (debug == 1) printf("getf\n");
tempObj = pop(stack).u.objRef;
push(stack, stackSlotWithObjRef(getField(tempObj,SIGN_EXTEND(IMMEDIATE(program.program[i])))));
push(stack, stackSlotWithObjRef(getField(tempObj, SIGN_EXTEND(IMMEDIATE(program.program[i])))));
break;
case PUTF:
if (debug == 1) printf("putf\t%i\n", SIGN_EXTEND(IMMEDIATE(program.program[i])));
tempObj = pop(stack).u.objRef;
tempObj2 = pop(stack).u.objRef;
setField(tempObj2, SIGN_EXTEND(IMMEDIATE(program.program[i])),tempObj);
setField(tempObj2, SIGN_EXTEND(IMMEDIATE(program.program[i])), tempObj);
break;
case NEWA:
if(debug == 1) printf("newa\n");
if (debug == 1) printf("newa\n");
bip.op1 = pop(stack).u.objRef;
push(stack, stackSlotWithObjRef(newRecord(bigToInt())));
break;
case GETFA:
if(debug == 1) printf("getfa\n");
if (debug == 1) printf("getfa\n");
bip.op1 = pop(stack).u.objRef;
tempInt = bigToInt();
tempObj = pop(stack).u.objRef;
push(stack, stackSlotWithObjRef(getField(tempObj,bigToInt())));
push(stack, stackSlotWithObjRef(getField(tempObj, bigToInt())));
break;
case PUTFA:
if (debug == 1) printf("putfa\n");
@ -286,12 +286,12 @@ void execute(struct program program) {
tempObj2 = pop(stack).u.objRef; // Index
bip.op1 = tempObj2;
tempInt = bigToInt();
setField(pop(stack).u.objRef, tempInt,tempObj);
setField(pop(stack).u.objRef, tempInt, tempObj);
break;
case GETSZ:
if (debug == 1) printf("getsz\n");
tempObj = pop(stack).u.objRef;
if(IS_PRIMITIVE(tempObj)) bigFromInt(-1);
if (IS_PRIMITIVE(tempObj)) bigFromInt(-1);
else bigFromInt(GET_ELEMENT_COUNT(tempObj));
push(stack, stackSlotWithObjRef(bip.res));
break;
@ -301,13 +301,13 @@ void execute(struct program program) {
break;
case REFEQ:
if (debug == 1) printf("refeq\n");
if(pop(stack).u.objRef == pop(stack).u.objRef) bigFromInt(true);
if (pop(stack).u.objRef == pop(stack).u.objRef) bigFromInt(true);
else bigFromInt(false);
push(stack, stackSlotWithObjRef(bip.res));
break;
case REFNE:
if (debug == 1) printf("refeq\n");
if(pop(stack).u.objRef != pop(stack).u.objRef) bigFromInt(true);
if (pop(stack).u.objRef != pop(stack).u.objRef) bigFromInt(true);
else bigFromInt(false);
push(stack, stackSlotWithObjRef(bip.res));
break;
@ -419,43 +419,53 @@ void swap() {
}
void garbageCollector() {
char *memToPurgePtr = halfHeapPtr - ((heapSizeKiB * 1024) / 2);
swap();
//printf("%s\n", "stack");
for (int i = 0; i < stack.current; i++) {
printf("%s\n", "stack");
for (int i = 0; i < *stack.current; i++) {
if (stack.stack[i].isObjRef) {
stack.stack[i].u.objRef = relocate(stack.stack[i].u.objRef);
}
}
//printf("%s\n", "globals");
for (int i = 0; i < sda.size; i++) {
printf("%s\n", "globals");
for (int i = 0; i < *sda.size; i++) {
sda.sda[i] = relocate(sda.sda[i]);
}
//printf("%s\n", "retVal");
// printf("%s\n", "retVal");
//returnValue = relocate(returnValue);
//printf("%s\n", "op1");
printf("%s\n", "op1");
bip.op1 = relocate(bip.op1);
ObjRef b = bip.op1;
if(b!= NULL)
if (b != NULL)
//printf("%d\n", GET_SIZE(b));
//printf("%s\n", "op2");
bip.op2 = relocate(bip.op2);
b = bip.op2;
if(b!= NULL)
if (b != NULL)
//printf("%d\n", GET_SIZE(b));
//printf("%s\n", "res");
bip.res = relocate(bip.res);
b = bip.res;
if(b!= NULL)
if (b != NULL) {
//printf("%d\n", GET_SIZE(b));
//printf("%s\n", "rem");
printf("%s\n", "rem");
bip.op1 = bip.rem;
bigPrint(stdout);
bip.rem = relocate(bip.rem);
printf("%s\n", "rem");
}
b = bip.rem;
if(b!= NULL)
printf("bip finished\n");
if (b != NULL)
//printf("%d\n", GET_SIZE(b));
@ -575,4 +585,4 @@ int main(int argc, char *argv[]) {
printf("Error: no code file specified\n");
return 1;
}
}
}

BIN
njvm.o

Binary file not shown.