Commit ccc3ca9c authored by Laszlo Domoszlai's avatar Laszlo Domoszlai
Browse files

clean up

parent 6a42ac1c
......@@ -445,7 +445,7 @@ void exec(Code* expr, int frame_ptr, int root_frame_ptr)
assert(is_hnf(arg));
if(get_dst(root_frame_ptr) != NULL && arg->desc->unboxable)
if(get_dst(root_frame_ptr) != NULL && arg->desc->thunk_size <= sizeof(Thunk))
{
memcpy(get_dst(root_frame_ptr), arg, sizeof(Thunk));
}
......
......@@ -2,7 +2,7 @@
#define DEBUG_H
//#define DEBUG
//#define BENCHMARK
#define BENCHMARK
#ifndef DEBUG
#define NDEBUG
......
......@@ -40,14 +40,14 @@ Desc* get_slice(Desc* f, int nrargs) {
return &(((SliceEntry*) f)[-(f->arity - nrargs)].base);
}
FunEntry* alloc_prim(char* name, int unboxable) {
FunEntry* alloc_prim(char* name) {
int len = strlen(name);
FunEntry* entry = (FunEntry*) alloc_desc(sizeof (FunEntry) + len + 1);
entry->base.type = FT_BOXED_LIT;
entry->base.arity = 0;
entry->base.thunk_size = sizeof(Thunk);
entry->base.unboxable = unboxable;
entry->base.hnf = 1;
entry->base.unboxable = true;
memcpy(entry->name, name, len + 1);
set_eval_fun((Desc*) entry);
......@@ -60,8 +60,8 @@ void gen_slices(SliceEntry* dest, Desc* forward_ptr, int arity) {
slice->base.type = FT_SLICE;
slice->base.arity = i;
slice->base.thunk_size = thunk_size_f(i);
slice->base.unboxable = false;
slice->base.hnf = true;
slice->base.unboxable = false;
slice->forward_ptr = forward_ptr;
set_eval_fun((Desc*) slice);
......@@ -94,31 +94,23 @@ int printDesc(Desc* f) {
}
void init_desc() {
__FORWARD_PTR__ = alloc_prim("FWD", 0);
__FORWARD_PTR__ = alloc_prim("FWD");
__FORWARD_PTR__->base.hnf = false;
set_eval_fun((Desc*) __FORWARD_PTR__);
__INT__ = alloc_prim("INT", 1);
__INT_SHARED__ = alloc_prim("INT", 0);
__BOOL__ = alloc_prim("BOOL", 1);
__BOOL_SHARED__ = alloc_prim("BOOL", 0);
__CHAR__ = alloc_prim("CHAR", 1);
__CHAR_SHARED__ = alloc_prim("CHAR", 0);
__REAL__ = alloc_prim("REAL", 1);
__REAL_SHARED__ = alloc_prim("REAL", 0);
__INT__ = alloc_prim("INT");
__BOOL__ = alloc_prim("BOOL");
__CHAR__ = alloc_prim("CHAR");
__REAL__ = alloc_prim("REAL");
__STRING__ = alloc_prim("STRING", 0);
__ARRAY__ = alloc_prim("ARRAY", 0);
__STRING__ = alloc_prim("STRING");
__ARRAY__ = alloc_prim("ARRAY");
}
struct FunEntry* __INT__;
struct FunEntry* __INT_SHARED__;
struct FunEntry* __BOOL__;
struct FunEntry* __BOOL_SHARED__;
struct FunEntry* __CHAR__;
struct FunEntry* __CHAR_SHARED__;
struct FunEntry* __REAL__;
struct FunEntry* __REAL_SHARED__;
struct FunEntry* __STRING__;
struct FunEntry* __ARRAY__;
......
......@@ -72,13 +72,9 @@ Desc* get_slice(Desc* f, int nrargs);
int printDesc(Desc* f);
extern struct FunEntry* __INT__;
extern struct FunEntry* __INT_SHARED__;
extern struct FunEntry* __BOOL__;
extern struct FunEntry* __BOOL_SHARED__;
extern struct FunEntry* __CHAR__;
extern struct FunEntry* __CHAR_SHARED__;
extern struct FunEntry* __REAL__;
extern struct FunEntry* __REAL_SHARED__;
extern struct FunEntry* __STRING__;
extern struct FunEntry* __ARRAY__;
......
......@@ -11,7 +11,7 @@ struct Desc {
FunType type : 4;
unsigned int arity : 8; // LIMITATION: maximum 32 arguments
unsigned int thunk_size : 10; // It gives false result for strings and arrays
unsigned int unboxable : 1;
unsigned int unboxable : 1; // TODO: not uses, remove?
unsigned int hnf : 1;
};
......
......@@ -251,21 +251,21 @@ ThunkEntry* parseLit(char **ptr) {
switch (type) {
case 'I': // Int
{
entry->thunk.desc = (Desc*) __INT_SHARED__;
entry->thunk.desc = (Desc*) __INT__;
if (!parseInt(ptr, &entry->thunk._int)) return 0;
break;
}
case 'C': // Char
{
entry->thunk.desc = (Desc*) __CHAR_SHARED__;
entry->thunk.desc = (Desc*) __CHAR__;
entry->thunk._char = *(*ptr)++;
break;
}
case 'R': // Real
{
entry->thunk.desc = (Desc*) __REAL_SHARED__;
entry->thunk.desc = (Desc*) __REAL__;
if (!parseReal(ptr, &entry->thunk._real)) return 0;
break;
}
......@@ -273,7 +273,7 @@ ThunkEntry* parseLit(char **ptr) {
case '0': // Bool
case '1':
{
entry->thunk.desc = (Desc*) __BOOL_SHARED__;
entry->thunk.desc = (Desc*) __BOOL__;
entry->thunk._bool = type == '1';
break;
}
......
......@@ -49,15 +49,15 @@ void print(bool force) {
printf("[");
if (thunk->desc->type == FT_BOXED_LIT) {
if ((FunEntry*) thunk->desc == __INT__ || (FunEntry*) thunk->desc == __INT_SHARED__) {
if ((FunEntry*) thunk->desc == __INT__) {
printf("%d", thunk->_int);
} else if ((FunEntry*) thunk->desc == __BOOL__ || (FunEntry*) thunk->desc == __BOOL_SHARED__) {
} else if ((FunEntry*) thunk->desc == __BOOL__) {
if (thunk->_bool) {
printf("True");
} else {
printf("False");
}
} else if ((FunEntry*) thunk->desc == __CHAR__ || (FunEntry*) thunk->desc == __CHAR_SHARED__) {
} else if ((FunEntry*) thunk->desc == __CHAR__) {
printf("%c", thunk->_char);
} else {
printf("print: unhandled BOXED LIT\n");
......
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