Compare commits
2 Commits
084b715729
...
91b36a53d5
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
91b36a53d5 | ||
|
|
169217fd2c |
@ -13,7 +13,7 @@ target_include_directories(njvm PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/bigint/build
|
|||||||
# Add the library
|
# Add the library
|
||||||
add_library(bigint STATIC ${CMAKE_SOURCE_DIR}/bigint/src/bigint.c
|
add_library(bigint STATIC ${CMAKE_SOURCE_DIR}/bigint/src/bigint.c
|
||||||
support.c
|
support.c
|
||||||
heap.c)
|
GC.c)
|
||||||
|
|
||||||
# Include directories for the bigint library
|
# Include directories for the bigint library
|
||||||
target_include_directories(bigint PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/bigint/build/include)
|
target_include_directories(bigint PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/bigint/build/include)
|
||||||
|
|||||||
52
GC.c
Normal file
52
GC.c
Normal file
@ -0,0 +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;
|
||||||
|
ObjRef *data;
|
||||||
|
} *heapPartRef;
|
||||||
|
|
||||||
|
// 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));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#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
heap.c
11
heap.c
@ -1,11 +0,0 @@
|
|||||||
//
|
|
||||||
// Created by Nils Polek on 23.01.24.
|
|
||||||
//
|
|
||||||
typedef struct {
|
|
||||||
int size;
|
|
||||||
int hcurrent;
|
|
||||||
}heap;
|
|
||||||
|
|
||||||
//void* alloc(int size){
|
|
||||||
// return {}
|
|
||||||
//}
|
|
||||||
12
njvm.c
12
njvm.c
@ -9,22 +9,15 @@
|
|||||||
#include "debugMenu.c"
|
#include "debugMenu.c"
|
||||||
#include "bigint.h"
|
#include "bigint.h"
|
||||||
#include "record.c"
|
#include "record.c"
|
||||||
|
#include "GC.c"
|
||||||
|
|
||||||
// Debug
|
// Debug
|
||||||
int debug = 0;
|
int debug = 0;
|
||||||
|
|
||||||
// Stack
|
|
||||||
struct stack stack;
|
|
||||||
#define SIZE 64
|
|
||||||
|
|
||||||
//Register
|
|
||||||
struct stack reg;
|
|
||||||
|
|
||||||
// Program
|
// Program
|
||||||
struct program program;
|
struct program program;
|
||||||
|
|
||||||
// SDA
|
|
||||||
struct sda sda;
|
|
||||||
unsigned fp;
|
unsigned fp;
|
||||||
|
|
||||||
void version(void) {
|
void version(void) {
|
||||||
@ -313,7 +306,6 @@ void tests(void) {
|
|||||||
|
|
||||||
int main(int argc, char *argv[]) {
|
int main(int argc, char *argv[]) {
|
||||||
|
|
||||||
|
|
||||||
// Initialize the Stack
|
// Initialize the Stack
|
||||||
int size = SIZE;
|
int size = SIZE;
|
||||||
int current = 0;
|
int current = 0;
|
||||||
|
|||||||
8
objref.c
8
objref.c
@ -1,9 +1,11 @@
|
|||||||
#ifndef OBJREF
|
#ifndef OBJREF
|
||||||
#define OBJREF
|
#define OBJREF
|
||||||
|
|
||||||
typedef struct {
|
#include <stdbool.h>
|
||||||
unsigned int size;
|
|
||||||
unsigned char data[1];
|
typedef struct ObjRef{
|
||||||
|
unsigned int size;
|
||||||
|
unsigned char data[1];
|
||||||
} *ObjRef;
|
} *ObjRef;
|
||||||
|
|
||||||
#endif /* ifndef OBJREF
|
#endif /* ifndef OBJREF
|
||||||
|
|||||||
6
stack.c
6
stack.c
@ -7,6 +7,10 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include "stackslot.c"
|
#include "stackslot.c"
|
||||||
|
#include "sda.c"
|
||||||
|
|
||||||
|
// SDA
|
||||||
|
struct sda sda;
|
||||||
|
|
||||||
struct stack {
|
struct stack {
|
||||||
int* size;
|
int* size;
|
||||||
@ -17,7 +21,7 @@ struct stack {
|
|||||||
typedef struct {
|
typedef struct {
|
||||||
unsigned int size;
|
unsigned int size;
|
||||||
ObjRef *refs;
|
ObjRef *refs;
|
||||||
}ObjRefContainer;
|
}ObjRefContainer;
|
||||||
|
|
||||||
void printStack(struct stack stack, int fp) {
|
void printStack(struct stack stack, int fp) {
|
||||||
printf("Stack\nSize:\t\t%i\nCurrent:\t%i\n", *stack.size, *stack.current);
|
printf("Stack\nSize:\t\t%i\nCurrent:\t%i\n", *stack.size, *stack.current);
|
||||||
|
|||||||
89
stackslot.c
89
stackslot.c
@ -1,57 +1,66 @@
|
|||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
#ifndef STACKSLOT
|
#ifndef STACKSLOT
|
||||||
#define STACKSLOT
|
#define STACKSLOT
|
||||||
typedef int Object;
|
typedef int Object;
|
||||||
typedef struct {
|
typedef struct ObjRef{
|
||||||
unsigned int size;
|
bool brokenHeart;
|
||||||
unsigned char data[1];
|
struct ObjRef *forward_pointer;
|
||||||
|
unsigned int size;
|
||||||
|
unsigned char data[1];
|
||||||
} *ObjRef;
|
} *ObjRef;
|
||||||
|
|
||||||
typedef struct{
|
typedef struct {
|
||||||
bool isObjRef;
|
bool isObjRef;
|
||||||
union {
|
union {
|
||||||
ObjRef objRef;
|
ObjRef objRef;
|
||||||
int number;
|
int number;
|
||||||
} u;
|
} u;
|
||||||
} StackSlot;
|
} StackSlot;
|
||||||
|
|
||||||
ObjRef getIntObj(int val){
|
ObjRef getIntObj(int val) {
|
||||||
ObjRef intObject;
|
ObjRef intObject;
|
||||||
unsigned int objSize = sizeof(unsigned int) + sizeof(int);
|
unsigned int objSize = sizeof(unsigned int) + sizeof(int);
|
||||||
if ((intObject = malloc(objSize)) == NULL) {
|
if ((intObject = malloc(objSize)) == NULL) {
|
||||||
perror("malloc");
|
perror("malloc");
|
||||||
}
|
}
|
||||||
*(int *)intObject->data=val;
|
*(int *) intObject->data = val;
|
||||||
intObject->size=sizeof(int);
|
intObject->size = sizeof(int);
|
||||||
return intObject;
|
return intObject;
|
||||||
}
|
}
|
||||||
int getValFromIntObj(ObjRef iref){
|
|
||||||
return *(int *)iref->data;
|
int getValFromIntObj(ObjRef iref) {
|
||||||
|
return *(int *) iref->data;
|
||||||
}
|
}
|
||||||
int getIntValfromStackSlot(StackSlot s){
|
|
||||||
if(s.isObjRef){
|
int getIntValfromStackSlot(StackSlot s) {
|
||||||
return *(int *)s.u.objRef->data;
|
if (s.isObjRef) {
|
||||||
}
|
return *(int *) s.u.objRef->data;
|
||||||
return s.u.number;
|
}
|
||||||
|
return s.u.number;
|
||||||
}
|
}
|
||||||
void setValIntObj(ObjRef iref, int val){
|
|
||||||
iref->size=sizeof(int);
|
void setValIntObj(ObjRef iref, int val) {
|
||||||
*(int *)iref->data=val;
|
iref->size = sizeof(int);
|
||||||
|
*(int *) iref->data = val;
|
||||||
}
|
}
|
||||||
StackSlot stackSlotWithObjRef(ObjRef val){
|
|
||||||
StackSlot *stackSlot;
|
StackSlot stackSlotWithObjRef(ObjRef val) {
|
||||||
stackSlot=malloc(sizeof(StackSlot));
|
StackSlot *stackSlot;
|
||||||
stackSlot->isObjRef=true;
|
stackSlot = malloc(sizeof(StackSlot));
|
||||||
stackSlot->u.objRef=val;
|
stackSlot->isObjRef = true;
|
||||||
return *stackSlot;
|
stackSlot->u.objRef = val;
|
||||||
|
return *stackSlot;
|
||||||
}
|
}
|
||||||
StackSlot stackSlotWitchNumber(int val){
|
|
||||||
StackSlot *stackSlot;
|
StackSlot stackSlotWitchNumber(int val) {
|
||||||
stackSlot= malloc(sizeof(StackSlot));
|
StackSlot *stackSlot;
|
||||||
stackSlot->isObjRef=false;
|
stackSlot = malloc(sizeof(StackSlot));
|
||||||
stackSlot->u.number=val;
|
stackSlot->isObjRef = false;
|
||||||
return *stackSlot;
|
stackSlot->u.number = val;
|
||||||
|
return *stackSlot;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@ -1,3 +1,4 @@
|
|||||||
|
|
||||||
#include "support.h"
|
#include "support.h"
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user