changed stack size

This commit is contained in:
nilspolek 2024-01-26 19:13:42 +01:00
parent 169217fd2c
commit 91b36a53d5
15 changed files with 60 additions and 84 deletions

115
GC.c
View File

@ -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++;
}
// 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

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
View File

@ -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) {

BIN
njvm.o

Binary file not shown.

View File

@ -1,9 +1,11 @@
#ifndef OBJREF
#define OBJREF
typedef struct {
unsigned int size;
unsigned char data[1];
#include <stdbool.h>
typedef struct ObjRef{
unsigned int size;
unsigned char data[1];
} *ObjRef;
#endif /* ifndef OBJREF

View File

@ -7,6 +7,10 @@
#include <stdio.h>
#include <stdlib.h>
#include "stackslot.c"
#include "sda.c"
// SDA
struct sda sda;
struct stack {
int* size;

View File

@ -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;

View File

@ -1,3 +1,4 @@
#include "support.h"
#include <stdio.h>
#include <stdlib.h>

BIN
support.o

Binary file not shown.