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

remove NULL check on destination/target thunk

parent 074f07b1
......@@ -14,11 +14,8 @@
#define forward_thunk(thunk, frame_ptr) \
Thunk* dst = get_dst(frame_ptr); \
if(dst != NULL) \
{ \
dst->desc = (Desc*) __FORWARD_PTR__; \
dst->_forward_ptr = thunk; \
}
dst->desc = (Desc*) __FORWARD_PTR__; \
dst->_forward_ptr = thunk;
#define arg_from_thunk(descarg, arg) \
if(((FunEntry*) (descarg))->strictness & argmask && !arg->desc->hnf) \
......@@ -340,9 +337,11 @@ void exec(Code* expr, int frame_ptr, int root_frame_ptr)
}
case CT_SELECT:
{
push_a(NULL);
Thunk* pattern = alloc_b();
pattern->desc = (Desc*) __STACK_PLACEHOLDER__;
push_a(pattern);
exec(((SelectEntry*) expr)->expr, frame_ptr, stack_top_a);
Thunk* pattern = pop_a();
pattern = pop_a();
assert(is_hnf(pattern));
assert(pattern->desc->type == FT_ADT);
......
......@@ -83,10 +83,12 @@ int main ( int argc, char *argv[] )
struct timeval t1, t2;
gettimeofday(&t1, NULL);
#endif
push_a(NULL);
Thunk* res = alloc_b();
res->desc = (Desc*) __STACK_PLACEHOLDER__;
push_a(res);
exec(expr, stack_top_a, stack_top_a);
Thunk* res = pop_a();
res = pop_a();
#ifdef BENCHMARK
gettimeofday(&t2, NULL);
......
......@@ -8,39 +8,45 @@
#define arg(idx) stack_a[stack_top_a - idx]
void __add(int frame_ptr) {
set_return(frame_ptr, updateI(get_dst(frame_ptr), readI(arg(2)) + readI(arg(1))));
Thunk* target = get_dst(frame_ptr);
target->desc = (Desc*) __INT__;
target->_int = readI(arg(2)) + readI(arg(1));
}
void __sub(int frame_ptr) {
set_return(frame_ptr, updateI(get_dst(frame_ptr), readI(arg(2)) - readI(arg(1))));
Thunk* target = get_dst(frame_ptr);
target->desc = (Desc*) __INT__;
target->_int = readI(arg(2)) - readI(arg(1));
}
void __gt(int frame_ptr) {
set_return(frame_ptr, updateB(get_dst(frame_ptr), readI(arg(2)) > readI(arg(1))));
Thunk* target = get_dst(frame_ptr);
target->desc = (Desc*) __BOOL__;
target->_bool = readI(arg(2)) > readI(arg(1));
}
void __lt(int frame_ptr) {
set_return(frame_ptr, updateB(get_dst(frame_ptr), readI(arg(2)) < readI(arg(1))));
Thunk* target = get_dst(frame_ptr);
target->desc = (Desc*) __BOOL__;
target->_bool = readI(arg(2)) < readI(arg(1));
}
void __eqI(int frame_ptr) {
Thunk* arg1 = arg(2);
Thunk* arg2 = arg(1);
set_return(frame_ptr, updateB(get_dst(frame_ptr), readI(arg1) == readI(arg2)));
Thunk* target = get_dst(frame_ptr);
target->desc = (Desc*) __BOOL__;
target->_bool = readI(arg(2)) == readI(arg(1));
}
void __eqB(int frame_ptr) {
Thunk* arg1 = arg(2);
Thunk* arg2 = arg(1);
set_return(frame_ptr, updateB(get_dst(frame_ptr), readB(arg1) == readB(arg2)));
Thunk* target = get_dst(frame_ptr);
target->desc = (Desc*) __BOOL__;
target->_bool = readB(arg(2)) == readB(arg(1));
}
void __not(int frame_ptr) {
Thunk* arg1 = arg(1);
set_return(frame_ptr, updateB(get_dst(frame_ptr), !readB(arg1)));
Thunk* target = get_dst(frame_ptr);
target->desc = (Desc*) __BOOL__;
target->_bool = !readB(arg(1));
}
void add_prim(int arity, int strictness, char* name, void (*exec)(int)) {
......
......@@ -35,8 +35,6 @@ int readB(Thunk* thunk) {
#endif
struct Thunk* updateI(Thunk* target, int i) {
if (target == NULL) target = (Thunk*) alloc_heap(sizeof (Thunk));
// always can be overwritten with boxed integer
target->desc = (Desc*) __INT__;
target->_int = i;
......@@ -44,8 +42,6 @@ struct Thunk* updateI(Thunk* target, int i) {
}
struct Thunk* updateB(Thunk* target, int b) {
if (target == NULL) target = (Thunk*) alloc_heap(sizeof (Thunk));
// always can be overwritten with boxed integer
target->desc = (Desc*) __BOOL__;
target->_bool = b;
......@@ -53,8 +49,6 @@ struct Thunk* updateB(Thunk* target, int b) {
}
struct Thunk* updateT(Thunk* target, Thunk* source) {
if (target == NULL) target = (Thunk*) alloc_heap(sizeof (Thunk));
memcpy(target, source, sizeof(Thunk));
return target;
}
......@@ -65,14 +59,10 @@ struct Thunk* updateF(Thunk* target, Desc* f) {
Thunk* thunk = target;
int newsize = f->thunk_size;
if (thunk == NULL) {
if (target->desc->thunk_size < newsize) {
thunk = (Thunk*) alloc_heap(newsize);
} else {
if (target->desc->thunk_size < newsize) {
thunk = (Thunk*) alloc_heap(newsize);
target->desc = (Desc*) __FORWARD_PTR__;
target->_forward_ptr = thunk;
}
target->desc = (Desc*) __FORWARD_PTR__;
target->_forward_ptr = thunk;
}
assert(thunk != NULL);
......
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