changed stack size
This commit is contained in:
parent
169217fd2c
commit
91b36a53d5
109
GC.c
109
GC.c
@ -1,77 +1,52 @@
|
||||
#ifndef GC
|
||||
#define GC
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#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++;
|
||||
}
|
||||
}
|
||||
part++;
|
||||
}
|
||||
// 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");
|
||||
}
|
||||
|
||||
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);
|
||||
// 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));
|
||||
}
|
||||
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
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
11
njvm.c
11
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) {
|
||||
|
||||
4
objref.c
4
objref.c
@ -1,7 +1,9 @@
|
||||
#ifndef OBJREF
|
||||
#define OBJREF
|
||||
|
||||
typedef struct {
|
||||
#include <stdbool.h>
|
||||
|
||||
typedef struct ObjRef{
|
||||
unsigned int size;
|
||||
unsigned char data[1];
|
||||
} *ObjRef;
|
||||
|
||||
4
stack.c
4
stack.c
@ -7,6 +7,10 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include "stackslot.c"
|
||||
#include "sda.c"
|
||||
|
||||
// SDA
|
||||
struct sda sda;
|
||||
|
||||
struct stack {
|
||||
int* size;
|
||||
|
||||
@ -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;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user