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.

52
njvm.c
View File

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

BIN
njvm.o

Binary file not shown.