diff --git a/GC.c b/GC.c index 211037c..b6a65fa 100644 --- a/GC.c +++ b/GC.c @@ -1,77 +1,52 @@ +#ifndef GC +#define GC +#include +#include #include +#include "stackslot.c" +#include "stack.c" +#include "bigint.h" +#include "instruktion.c" +#include "record.c" + typedef struct { + unsigned int freiZeiger; unsigned int size; - unsigned int current; - unsigned char data[1]; -} heapPart; -typedef struct { - heapPart *primary; - heapPart *secondary; - unsigned int size; - unsigned int current; -} heap; + ObjRef *data; +} *heapPartRef; -void scan(heap *h) { - heapPart *part = h->primary; - unsigned int i; - for (i = 0; i < h->current; i++) { - unsigned int j; - for (j = 0; j < part->current; j++) { - void *p = *(void **) (part->data + j); - if (p >= part->data && p < part->data + part->size) { - *(void **) (part->data + j) = h->secondary + h->current; - memcpy(h->secondary + h->current, p, sizeof(void *)); - h->current++; - } +// Stack +struct stack stack; +#define SIZE 64 + +//Register +struct stack reg; + + +heapPartRef primary; +heapPartRef secondary; +unsigned int heapSize; +void initHeap(int size){ + heapSize = 2 * sizeof (unsigned int) + size; + if ((primary = malloc(heapSize)) == NULL) perror("malloc"); + if ((secondary = malloc(heapSize)) == NULL) perror("malloc"); +} + + +// nimmt obj und copier es in den secondary Speicher +void copy(ObjRef obj){ + if(obj->brokenHeart == true) return; + obj->brokenHeart = true; + if (IS_PRIMITIVE(obj)){ + obj->forward_pointer = memcpy(secondary->data[secondary->freiZeiger],obj,obj->size); + secondary->freiZeiger += obj->size; + } else { + GET_ELEMENT_COUNT(obj); + obj->forward_pointer = memcpy(secondary->data[secondary->freiZeiger],obj,sizeof(*obj) + (GET_ELEMENT_COUNT(obj) * sizeof(void *))); + secondary->freiZeiger += sizeof(*obj) + (GET_ELEMENT_COUNT(obj) * sizeof(void *)); + for (int i = 0; i < GET_ELEMENT_COUNT(obj); ++i) { + copy(getField(obj,i)); } - part++; } } - -void collect(heap *h) { - scan(h); - heapPart *tmp = h->primary; - h->primary = h->secondary; - h->secondary = tmp; - h->current = 0; -} - -void *alloc(heap *h, unsigned int size) { - if (h->current == h->size) { - collect(h); - } - heapPart *part = h->primary + h->current; - if (part->current + size > part->size) { - collect(h); - part = h->primary + h->current; - } - void *p = part->data + part->current; - part->current += size; - return p; -} - -void *reallocate(heap *h, void *p, unsigned int size) { - if (p == NULL) { - return alloc(h, size); - } - heapPart *part = h->primary; - unsigned int i; - for (i = 0; i < h->current; i++) { - if (p >= part->data && p < part->data + part->size) { - break; - } - part++; - } - if (i == h->current) { - return NULL; - } - if (size <= part->size) { - return p; - } - void *newP = alloc(h, size); - if (newP == NULL) { - return NULL; - } - memcpy(newP, p, part->size); - return newP; -} +#endif diff --git a/bigint/build/bin/testbip b/bigint/build/bin/testbip index a94228e..84ced15 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 e934acb..3d8c43a 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 2ad822d..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 e934acb..3d8c43a 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 217a32a..dd5174c 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 a94228e..84ced15 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 e5fc067..8acdffd 100644 Binary files a/bigint/tst/testbip.o and b/bigint/tst/testbip.o differ diff --git a/njvm.c b/njvm.c index c95f6ae..4d19931 100644 --- a/njvm.c +++ b/njvm.c @@ -9,22 +9,15 @@ #include "debugMenu.c" #include "bigint.h" #include "record.c" +#include "GC.c" // Debug int debug = 0; -// Stack -struct stack stack; -#define SIZE 64 - -//Register -struct stack reg; - // Program struct program program; -// SDA -struct sda sda; + unsigned fp; void version(void) { diff --git a/njvm.o b/njvm.o index e83c127..b389ffd 100644 Binary files a/njvm.o and b/njvm.o differ diff --git a/objref.c b/objref.c index 9b22149..7dcdf76 100644 --- a/objref.c +++ b/objref.c @@ -1,9 +1,11 @@ #ifndef OBJREF #define OBJREF -typedef struct { - unsigned int size; - unsigned char data[1]; +#include + +typedef struct ObjRef{ + unsigned int size; + unsigned char data[1]; } *ObjRef; #endif /* ifndef OBJREF diff --git a/stack.c b/stack.c index f7a6ee9..0b2ae46 100755 --- a/stack.c +++ b/stack.c @@ -7,6 +7,10 @@ #include #include #include "stackslot.c" +#include "sda.c" + +// SDA +struct sda sda; struct stack { int* size; @@ -17,7 +21,7 @@ struct stack { typedef struct { unsigned int size; ObjRef *refs; -}ObjRefContainer; +}ObjRefContainer; void printStack(struct stack stack, int fp) { printf("Stack\nSize:\t\t%i\nCurrent:\t%i\n", *stack.size, *stack.current); diff --git a/stackslot.c b/stackslot.c index 937ecb9..875f81d 100644 --- a/stackslot.c +++ b/stackslot.c @@ -5,8 +5,9 @@ #ifndef STACKSLOT #define STACKSLOT typedef int Object; -typedef struct { +typedef struct ObjRef{ bool brokenHeart; + struct ObjRef *forward_pointer; unsigned int size; unsigned char data[1]; } *ObjRef; diff --git a/support.c b/support.c index cc7f6b6..8032a60 100644 --- a/support.c +++ b/support.c @@ -1,3 +1,4 @@ + #include "support.h" #include #include diff --git a/support.o b/support.o index dc01f15..32abf61 100644 Binary files a/support.o and b/support.o differ