Commit 2adde4a4 authored by Laszlo Domoszlai's avatar Laszlo Domoszlai
Browse files

remove unnecessary conditions in thunk creation

parent a9f0c3a6
......@@ -27,7 +27,7 @@ struct Thunk* create_thunk(Code* expr, int frame_ptr)
get_slice(basethunk->desc->type == FT_SLICE ?
((SliceEntry*) basethunk->desc)->forward_ptr : basethunk->desc, basethunk->desc->arity + expr->nr_args);
Thunk* thunk = updateF(NULL, slice);
Thunk* thunk = createF(slice);
assert(thunk->desc->arity == basethunk->desc->arity + expr->nr_args);
......@@ -44,7 +44,7 @@ struct Thunk* create_thunk(Code* expr, int frame_ptr)
}
else
{
Thunk* thunk = updateF(NULL, get_slice(var->f, expr->nr_args));
Thunk* thunk = createF(get_slice(var->f, expr->nr_args));
assert(thunk->desc->arity == expr->nr_args);
......@@ -57,12 +57,12 @@ struct Thunk* create_thunk(Code* expr, int frame_ptr)
}
case CT_VAR:
if (expr->local_type == VAR_LOCAL) {
return forward_to(NULL, local(frame_ptr, ((VarEntry*) expr)->index));
return local(frame_ptr, ((VarEntry*) expr)->index);
}else{
return updateF(NULL, get_slice(((VarEntry*) expr)->f, 0));
return createF(get_slice(((VarEntry*) expr)->f, 0));
}
case CT_LIT:
return updateT(NULL, &((LitEntry*) expr)->thunk);
return createT(&((LitEntry*) expr)->thunk);
}
}
......
#ifndef DEBUG_H
#define DEBUG_H
// Adjoxo: 2200
//#define DEBUG
#define BENCHMARK
//#define BENCHMARK
#ifndef DEBUG
#define NDEBUG
......
......@@ -113,6 +113,20 @@ struct Thunk* updateF(Thunk* target, Desc* f) {
return thunk;
}
struct Thunk* createF(Desc* f) {
assert(f != NULL);
Thunk* thunk = (Thunk*) alloc_heap(max(sizeof (Thunk), sizeof (Desc*) + sizeof (Thunk*) * f->arity));
thunk->desc = f;
return thunk;
}
struct Thunk* createT(Thunk* source) {
Thunk* target = (Thunk*) alloc_heap(sizeof (Thunk));
memcpy(target, source, sizeof(Thunk));
return target;
}
bool is_hnf(Thunk* thunk)
{
return !(thunk->desc->type == FT_FUN || thunk->desc->type == FT_PRIM);
......
......@@ -46,6 +46,9 @@ struct Thunk* updateB(Thunk* target, int b);
struct Thunk* updateT(Thunk* target, Thunk* source);
struct Thunk* updateF(Thunk* target, Desc* f);
struct Thunk* createT(Thunk* source);
struct Thunk* createF(Desc* f);
bool is_hnf(Thunk* thunk);
struct Thunk* eval(Thunk* thunk);
......
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