Commit 7180c216 authored by Laszlo Domoszlai's avatar Laszlo Domoszlai
Browse files

add gc

parent d20a7c78
TARGET = main
LIBS =
CC = clang++
CFLAGS = -O3 -x c++ -Wno-write-strings # -g -pg -fstack-usage
CFLAGS = -O0 -g -x c++ -Wno-write-strings # -g -pg -fstack-usage
.PHONY: default all clean
......@@ -17,7 +17,7 @@ HEADERS = $(wildcard *.h)
.PRECIOUS: $(TARGET) $(OBJECTS)
$(TARGET): $(OBJECTS)
$(CC) $(OBJECTS) -static -static-libgcc -static-libstdc++ -Wl,--stack,16777216 -Wall $(LIBS) -o $@ # -pg -g
$(CC) $(OBJECTS) -static -static-libgcc -static-libstdc++ -Wl,--stack,16777216 -Wall -g $(LIBS) -o $@ # -pg -g
clean:
-rm -f *.o
......
......@@ -3,25 +3,28 @@
#include "debug.h"
#include "mem.h"
#include "gc.h"
int desc_alloc;
int code_alloc;
int nr_heap_alloc;
int heap_alloc;
int stack_top_a;
int stack_top_b;
Thunk* stack_a[STACK_SIZE_A];
Thunk stack_b[STACK_SIZE_B];
#define heap_size 1024*1024*1024
char* heap_start;
char* heap_base_curr;
char* heap_base_swap;
char* heap_curr;
char* gc_trigger;
void print_stat() {
printf("\nallocation:\n");
printf("desc: %d\n", desc_alloc);
printf("code: %d\n", code_alloc);
printf("heap: %d (%d thunks)\n", heap_curr - heap_start, nr_heap_alloc);
printf("heap: %d (%d thunks)\n", heap_alloc, nr_heap_alloc);
}
void init_mem() {
......@@ -31,9 +34,15 @@ void init_mem() {
stack_top_a = 0;
heap_start = (char*) malloc(heap_size);
heap_curr = heap_start;
assert(heap_start != NULL);
heap_base_curr = (char*) malloc(HEAP_SIZE);
heap_base_swap = (char*) malloc(HEAP_SIZE);
assert(heap_base_curr != NULL);
assert(heap_base_swap != NULL);
heap_curr = heap_base_curr;
gc_trigger = heap_base_curr + HEAP_SIZE - 1024;
}
void* alloc_desc(int size) {
......@@ -53,8 +62,9 @@ void* alloc_heap(int size) {
heap_curr += size;
nr_heap_alloc++;
heap_alloc+=size;
assert(heap_curr - heap_start < heap_size);
assert(heap_curr - heap_base_curr < HEAP_SIZE);
return curr;
}
#endif
\ No newline at end of file
......@@ -6,12 +6,17 @@
#define STACK_SIZE_A 10240*50
#define STACK_SIZE_B 10240*50
#define HEAP_SIZE 10*1024*1024
extern int stack_top_a;
extern int stack_top_b;
extern Thunk* stack_a[STACK_SIZE_A];
extern Thunk stack_b[STACK_SIZE_B];
extern char* heap_base_curr;
extern char* heap_base_swap;
extern char* heap_curr;
extern char* gc_trigger;
#define peek_a() stack_a[stack_top_a-1]
#define pop_a() stack_a[--stack_top_a]
......
......@@ -43,6 +43,12 @@ void __lt(int dst_idx) {
target->_bool = readI(arg(2)) < readI(arg(1));
}
void __geC(int dst_idx) {
Thunk* target = get_dst(dst_idx);
target->desc = (Desc*) __BOOL__;
target->_bool = readC(arg(2)) >= readC(arg(1));
}
void __eqI(int dst_idx) {
Thunk* target = get_dst(dst_idx);
target->desc = (Desc*) __BOOL__;
......@@ -61,18 +67,42 @@ void __eqB(int dst_idx) {
target->_bool = readB(arg(2)) == readB(arg(1));
}
void __eqC(int dst_idx) {
Thunk* target = get_dst(dst_idx);
target->desc = (Desc*) __CHAR__;
target->_bool = readC(arg(2)) == readC(arg(1));
}
void __not(int dst_idx) {
Thunk* target = get_dst(dst_idx);
target->desc = (Desc*) __BOOL__;
target->_bool = !readB(arg(1));
}
void __and(int dst_idx) {
Thunk* target = get_dst(dst_idx);
target->desc = (Desc*) __BOOL__;
target->_bool = readB(arg(2)) && readB(arg(1));
}
void __or(int dst_idx) {
Thunk* target = get_dst(dst_idx);
target->desc = (Desc*) __BOOL__;
target->_bool = readB(arg(2)) || readB(arg(1));
}
void __mod(int dst_idx) {
Thunk* target = get_dst(dst_idx);
target->desc = (Desc*) __INT__;
target->_int = readB(arg(2)) % readB(arg(1));
}
void __C2I(int dst_idx) {
Thunk* target = get_dst(dst_idx);
target->desc = (Desc*) __INT__;
target->_int = readC(arg(1));
}
void add_prim(int arity, int strictness, char* name, void (*exec)(int)) {
int nameLength = strlen(name);
......@@ -103,10 +133,15 @@ void init_prim() {
add_prim(2, 3, "mult", &__mult);
add_prim(2, 3, "div", &__div);
add_prim(2, 3, "gt", &__gt);
add_prim(2, 3, "geC", &__geC);
add_prim(2, 3, "lt", &__lt);
add_prim(2, 3, "eqI", &__eqI);
add_prim(2, 3, "neqI", &__neqI);
add_prim(2, 3, "eqB", &__eqB);
add_prim(1, 1, "not", &__not);
add_prim(2, 3, "mod", &__mod);
add_prim(2, 3, "eqC", &__eqC);
add_prim(1, 1, "not", &__not);
add_prim(2, 3, "and", &__and);
add_prim(2, 3, "or", &__or);
add_prim(2, 3, "mod", &__mod);
add_prim(1, 1, "C2I", &__C2I);
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment