diff --git a/GC.c b/GC.c index 7242172..b0c2f5d 100644 --- a/GC.c +++ b/GC.c @@ -21,7 +21,7 @@ struct sda sda; // Stack struct stack stack; -#define SIZE 100000 +#define SIZE 64 //Register struct stack reg; diff --git a/bigint/build/bin/testbip b/bigint/build/bin/testbip index 227a64e..d7770ea 100755 Binary files a/bigint/build/bin/testbip and b/bigint/build/bin/testbip differ diff --git a/bigint/build/lib/libbigint.a b/bigint/build/lib/libbigint.a index ec9a931..972ccb0 100644 Binary files a/bigint/build/lib/libbigint.a and b/bigint/build/lib/libbigint.a differ diff --git a/bigint/src/libbigint.a b/bigint/src/libbigint.a index ec9a931..972ccb0 100644 Binary files a/bigint/src/libbigint.a and b/bigint/src/libbigint.a differ diff --git a/bigint/tst/testbip b/bigint/tst/testbip index 227a64e..d7770ea 100755 Binary files a/bigint/tst/testbip and b/bigint/tst/testbip differ diff --git a/njvm.c b/njvm.c index 35e25d7..96e2160 100644 --- a/njvm.c +++ b/njvm.c @@ -229,42 +229,42 @@ void execute(struct program program) { push(stack, stackSlotWithObjRef(tempObj)); break; case POPR: - if (debug == 1) printf("popr"); + if (debug == 1) printf("popr\n"); push(reg, pop(stack)); break; case PUSHR: - if (debug == 1) printf("pushr"); + if (debug == 1) printf("pushr\n"); push(stack, pop(reg)); break; case NEW: - if (debug == 1) printf("new"); + if (debug == 1) printf("new\t%i\n", SIGN_EXTEND(IMMEDIATE(program.program[i]))); push(stack, stackSlotWithObjRef(newRecord(SIGN_EXTEND(IMMEDIATE(program.program[i]))))); break; case GETF: - if (debug == 1) printf("getf"); + if (debug == 1) printf("getf\n"); tempObj = pop(stack).u.objRef; push(stack, stackSlotWithObjRef(getField(tempObj,SIGN_EXTEND(IMMEDIATE(program.program[i]))))); break; case PUTF: - if (debug == 1) printf("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); break; case NEWA: - if(debug == 1) printf("newa"); + 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"); + 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()))); break; case PUTFA: - if (debug == 1) printf("putfa"); + if (debug == 1) printf("putfa\n"); tempObj = pop(stack).u.objRef; // Value tempObj2 = pop(stack).u.objRef; // Index bip.op1 = tempObj2; @@ -272,24 +272,24 @@ void execute(struct program program) { setField(pop(stack).u.objRef, tempInt,tempObj); break; case GETSZ: - if (debug == 1) printf("getsz"); + if (debug == 1) printf("getsz\n"); tempObj = pop(stack).u.objRef; if(IS_PRIMITIVE(tempObj)) bigFromInt(-1); else bigFromInt(GET_ELEMENT_COUNT(tempObj)); push(stack, stackSlotWithObjRef(bip.res)); break; case PUSHN: - if (debug == 1) printf("pushn"); + if (debug == 1) printf("pushn\n"); push(stack, stackSlotWithObjRef(NULL)); break; case REFEQ: - if (debug == 1) printf("refeq"); + if (debug == 1) printf("refeq\n"); 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"); + if (debug == 1) printf("refeq\n"); if(pop(stack).u.objRef != pop(stack).u.objRef) bigFromInt(true); else bigFromInt(false); push(stack, stackSlotWithObjRef(bip.res)); @@ -312,6 +312,9 @@ int main(int argc, char *argv[]) { stack.size = &size; stack.current = ¤t; stack.stack = malloc(SIZE * 1024); + if (stack.stack == NULL) { + perror("malloc"); + } // Initialize the registery int rSize = 100000; diff --git a/njvm.o b/njvm.o index a4592eb..1e66d6f 100644 Binary files a/njvm.o and b/njvm.o differ diff --git a/prog.bin b/prog.bin index a12da6a..b97c91f 100644 Binary files a/prog.bin and b/prog.bin differ diff --git a/record.c b/record.c index 8435155..b6345db 100644 --- a/record.c +++ b/record.c @@ -29,17 +29,18 @@ ObjRef getField(ObjRef arr, int point){ return *(ObjRef *)GET_REFS_PTR(arr)[point]->data; } void setField(ObjRef arr, int point, ObjRef value){ - if(0 > point || point > getSize(arr)){ + if(0 > point || point >= getSize(arr)){ printf("Index %i out of bounds for length %i\n",point, getSize(arr)); + exit(EXIT_FAILURE); } + if(IS_PRIMITIVE(arr)) perror("Record is a primitive"); if(IS_PRIMITIVE(value)){ -// printf("Size of value is %i\n", value->size); int size = value->size; - GET_REFS_PTR(arr)[point] = malloc(size); + if((GET_REFS_PTR(arr)[point] = malloc(size)) == NULL) perror("malloc"); GET_REFS_PTR(arr)[point]->size = size; }else{ int size = sizeof(*value) + (GET_ELEMENT_COUNT(value) * sizeof(void *)); - GET_REFS_PTR(arr)[point] = malloc(size); + if((GET_REFS_PTR(arr)[point] = malloc(size)) == NULL) perror("malloc"); GET_REFS_PTR(arr)[point] ->size = size; } * (ObjRef *)GET_REFS_PTR(arr)[point]->data = value; diff --git a/stackslot.c b/stackslot.c index 61dffb7..6e28921 100644 --- a/stackslot.c +++ b/stackslot.c @@ -48,6 +48,7 @@ void setValIntObj(ObjRef iref, int val) { StackSlot stackSlotWithObjRef(ObjRef val) { StackSlot *stackSlot; stackSlot = malloc(sizeof(StackSlot)); + if(stackSlot == NULL) perror("malloc"); stackSlot->isObjRef = true; stackSlot->u.objRef = val; return *stackSlot; @@ -56,6 +57,7 @@ StackSlot stackSlotWithObjRef(ObjRef val) { StackSlot stackSlotWitchNumber(int val) { StackSlot *stackSlot; stackSlot = malloc(sizeof(StackSlot)); + if(stackSlot == NULL) perror("malloc"); stackSlot->isObjRef = false; stackSlot->u.number = val; return *stackSlot; diff --git a/test.nj b/test.nj new file mode 100644 index 0000000..655b850 --- /dev/null +++ b/test.nj @@ -0,0 +1,3 @@ +void main(){ + +} \ No newline at end of file diff --git a/test/tests/14.bin b/test/tests/14.bin new file mode 100644 index 0000000..439ca22 Binary files /dev/null and b/test/tests/14.bin differ diff --git a/test/tests/arrTest.asm b/test/tests/arrTest.asm new file mode 100644 index 0000000..ab013cb --- /dev/null +++ b/test/tests/arrTest.asm @@ -0,0 +1,18 @@ +new 3 +popl 0 + +pushl 0 +pushc 10 +putf 0 +pushl 0 +pushc 11 +putf 1 + +pushl 0 +getf 0 +pushl 0 +getf 1 +add +wrint +halt +// Sollte 10 + 11 ergeben