diff --git a/bigint/build/bin/testbip b/bigint/build/bin/testbip index 7d91ca7..de7823f 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 4c9a702..c3dcd7f 100644 Binary files a/bigint/build/lib/libbigint.a and b/bigint/build/lib/libbigint.a differ diff --git a/bigint/src/bigint.o b/bigint/src/bigint.o index 162ad9f..4e68f95 100644 Binary files a/bigint/src/bigint.o and b/bigint/src/bigint.o differ diff --git a/bigint/src/libbigint.a b/bigint/src/libbigint.a index 4c9a702..c3dcd7f 100644 Binary files a/bigint/src/libbigint.a and b/bigint/src/libbigint.a differ diff --git a/bigint/tst/support.o b/bigint/tst/support.o index 7f7b6da..f5bd62d 100644 Binary files a/bigint/tst/support.o and b/bigint/tst/support.o differ diff --git a/bigint/tst/testbip b/bigint/tst/testbip index 7d91ca7..de7823f 100755 Binary files a/bigint/tst/testbip and b/bigint/tst/testbip differ diff --git a/bigint/tst/testbip.o b/bigint/tst/testbip.o index d8aaf39..8acdffd 100644 Binary files a/bigint/tst/testbip.o and b/bigint/tst/testbip.o differ diff --git a/instruktion.c b/instruktion.c index db849ae..bda3797 100644 --- a/instruktion.c +++ b/instruktion.c @@ -50,5 +50,6 @@ #define PUSHN 39 #define REFEQ 40 #define REFNE 41 +#define TGC 42 #endif /* ifndef INSREUKTION */ diff --git a/njvm.c b/njvm.c index 86d44fc..9c9fab4 100644 --- a/njvm.c +++ b/njvm.c @@ -34,6 +34,8 @@ struct stack reg; unsigned fp; +void garbageCollector(void); + void version(void) { printf("Ninja Virtual Machine version %i (compiled %s, %s)\n", 0, __DATE__, __TIME__); } @@ -64,9 +66,10 @@ void execute(struct program program) { break; case ADD: if (debug == 1) printf("add: %i + %i\n", peek(stack, 2), peek(stack, 1)); - bip.op2 = pop(stack).u.objRef; bip.op1 = pop(stack).u.objRef; + bip.op2 = pop(stack).u.objRef; bigAdd(); + push(stack, stackSlotWithObjRef(bip.res)); break; case SUB: @@ -311,6 +314,10 @@ void execute(struct program program) { else bigFromInt(false); push(stack, stackSlotWithObjRef(bip.res)); break; + case TGC: + if (debug == 1) printf("tgc\n"); + garbageCollector(); + break; } } end: @@ -366,7 +373,6 @@ ObjRef relocate(ObjRef orig) { return copy; } - void scan(void) { char *scanPtr = memTargetPtr; while (scanPtr < freeHeapPtr) { @@ -399,6 +405,11 @@ void garbageCollector() { char *memToPurgePtr = halfHeapPtr - ((heapSizeKiB * 1024) / 2); swap(); + bip.op1 = relocate(bip.op1); + bip.op2 = relocate(bip.op2); + bip.res = relocate(bip.res); + bip.rem = relocate(bip.rem); + for (int i = 0; i < *stack.size; i++) { if (stack.stack[i].isObjRef) { stack.stack[i].u.objRef = relocate(stack.stack[i].u.objRef); @@ -408,7 +419,6 @@ void garbageCollector() { for (int i = 0; i < *sda.size; i++) { sda.sda[i] = relocate(sda.sda[i]); } - scan(); if (purgeFlag) { diff --git a/njvm.o b/njvm.o index e458976..ae21899 100644 Binary files a/njvm.o and b/njvm.o differ diff --git a/record.c b/record.c index e67ca85..e8ff86a 100644 --- a/record.c +++ b/record.c @@ -5,11 +5,12 @@ #define RECORD #include "stackslot.c" #include "instruktion.c" +#include "njvm.h" ObjRef newRecord(int size){ ObjRef record; unsigned int objSize; objSize = sizeof(*record) + (size * sizeof(void *)); - if((record = malloc(objSize)) == NULL){ + if((record = alloc(objSize)) == NULL){ perror("malloc"); } record->size = MSB; @@ -25,6 +26,7 @@ int getSize(ObjRef arr){ } ObjRef getField(ObjRef arr, int point){ if(arr == NULL) perror("Record is null"); + if(arr->brokenHeart==true) perror("Broken Heart"); if(0 > point || point > getSize(arr)){ printf("Index %i out of bounds for length %i\n",point, getSize(arr)); } @@ -47,7 +49,7 @@ void setField(ObjRef arr, int point, ObjRef value){ else size = sizeof(*value) + (GET_ELEMENT_COUNT(value) * sizeof(void *)); } - if((GET_REFS_PTR(arr)[point] = malloc(size)) == NULL) perror("malloc"); + if((GET_REFS_PTR(arr)[point] = alloc(size)) == NULL) perror("malloc"); GET_REFS_PTR(arr)[point] ->size = size; * (ObjRef *)GET_REFS_PTR(arr)[point]->data = value; } diff --git a/support.c b/support.c index cdd2d80..ca60959 100644 --- a/support.c +++ b/support.c @@ -4,6 +4,7 @@ #include #include "objref.c" +#include "njvm.h" void fatalError(char *msg){ printf("Fatal error: %s\n", msg); @@ -13,7 +14,7 @@ void fatalError(char *msg){ void * newPrimObject(int dataSize) { ObjRef bigObjRef; - bigObjRef = malloc(sizeof(unsigned int) + + bigObjRef = alloc(sizeof(unsigned int) + dataSize * sizeof(unsigned char)); if (bigObjRef == NULL) { fatalError("newPrimObject() got no memory"); diff --git a/support.o b/support.o index 3fa5a66..3d6848d 100644 Binary files a/support.o and b/support.o differ diff --git a/test/tests/arrTest.asm b/test/tests/arrTest.asm index f14f3fc..1829ce3 100644 --- a/test/tests/arrTest.asm +++ b/test/tests/arrTest.asm @@ -1,18 +1,19 @@ -new 3 -popg 0 +new 3 // new Array[3] +popg 0 // save on sda 0 -pushg 0 -pushc 10 -putf 0 -pushg 0 -pushc 11 -putf 1 +pushg 0 // array auf stack +pushc 10 // 10 auf stack +putf 0 // array[0] = 10 +pushg 0 // array auf stack +pushc 11 // 11 auf stack +putf 1 // array[1] = 11 +tgc // garbage collector -pushg 0 -getf 0 -pushg 0 -getf 1 -add -wrint -halt +pushg 0 // array auf stack +getf 0 // array[0] auf stack +pushg 0 // array auf stack +getf 1 // array[1] auf stack +add // array[0] + array[1] auf stack +wrint // ausgabe +halt // ende // Sollte 10 + 11 ergeben diff --git a/test/tests/test.asm b/test/tests/test.asm new file mode 100644 index 0000000..f456212 --- /dev/null +++ b/test/tests/test.asm @@ -0,0 +1,4 @@ +pushc 1 +pushc 2 +add +wrint