Commit 397719cb authored by Laszlo Domoszlai's avatar Laszlo Domoszlai
Browse files

save create_thunk function pointer into the Code structure.

very small speedup, not sure if it is worthwhile to do
parent c6e8974d
......@@ -38,12 +38,10 @@
} \
else \
{ \
push_a(create_thunk_funs[arg->type](arg, frame_ptr)); \
push_a(arg->create_thunk(arg, frame_ptr)); \
} \
argmask <<= 1;
Thunk* (*create_thunk_funs[9]) (Code* expr, int frame_ptr);
struct Thunk* create_thunk_app_static(Code* expr, int frame_ptr)
{
Thunk* thunk = createF(((AppEntry*) expr)->f);
......@@ -51,7 +49,7 @@ struct Thunk* create_thunk_app_static(Code* expr, int frame_ptr)
assert(thunk->desc->arity == expr->nr_args);
for (int i = 0; i < expr->nr_args; i++) {
thunk->_args[i] = create_thunk_funs[((AppEntry*) expr)->args[i]->type](((AppEntry*) expr)->args[i], frame_ptr);
thunk->_args[i] = ((AppEntry*) expr)->args[i]->create_thunk(((AppEntry*) expr)->args[i], frame_ptr);
}
return thunk;
......@@ -74,7 +72,7 @@ struct Thunk* create_thunk_app_dyn(Code* expr, int frame_ptr)
for (int i = 0; i < expr->nr_args; i++) {
thunk->_args[basethunk->desc->arity + i]
= create_thunk_funs[((AppEntry*) expr)->args[i]->type](((AppEntry*) expr)->args[i], frame_ptr);
= ((AppEntry*) expr)->args[i]->create_thunk(((AppEntry*) expr)->args[i], frame_ptr);
}
return thunk;
......@@ -104,6 +102,8 @@ struct Thunk* create_thunk_thunk(Code* expr, int frame_ptr)
return &((ThunkEntry*) expr)->thunk;
}
Thunk* (*create_thunk_funs[9]) (Code* expr, int frame_ptr);
void init_code()
{
create_thunk_funs[CT_VAR] = create_thunk_var;
......@@ -170,7 +170,7 @@ void exec(Code* expr, int frame_ptr, int root_frame_ptr)
for (int i = 0; i < expr->nr_args; i++) {
thunk->_args[i]
= create_thunk_funs[((AppEntry*) expr)->args[i]->type](((AppEntry*) expr)->args[i], frame_ptr);
= ((AppEntry*) expr)->args[i]->create_thunk(((AppEntry*) expr)->args[i], frame_ptr);
}
set_return(root_frame_ptr, thunk);
......@@ -240,7 +240,7 @@ void exec(Code* expr, int frame_ptr, int root_frame_ptr)
for (int i = 0; i < expr->nr_args; i++) {
thunk->_args[basethunk->desc->arity + i]
= create_thunk_funs[((AppEntry*) expr)->args[i]->type](((AppEntry*) expr)->args[i], frame_ptr);
= ((AppEntry*) expr)->args[i]->create_thunk(((AppEntry*) expr)->args[i], frame_ptr);
}
set_return(root_frame_ptr, thunk);
......
......@@ -15,6 +15,7 @@ struct Code {
unsigned int nr_args : 5; // used in AppEntry
unsigned int nr_cases : 5; // used in SelectEntry
unsigned int strict : 1; // used in VarEntry
struct Thunk* (*create_thunk)(Code*, int);
};
struct ThunkEntry {
......@@ -64,6 +65,7 @@ struct IfEntry {
};
void init_code();
extern Thunk* (*create_thunk_funs[9]) (Code* expr, int frame_ptr);
void exec(Code* expr, int frame_ptr, int root_frame_ptr);
struct Thunk* eval(Thunk* thunk);
......
......@@ -236,6 +236,7 @@ ThunkEntry* parseLit(char **ptr) {
struct ThunkEntry* entry = (ThunkEntry*) alloc_code(sizeof (ThunkEntry) + strlen);
entry->base.type = CT_THUNK;
entry->base.create_thunk = create_thunk_funs[CT_THUNK];
switch (type) {
case 'I': // Int
......@@ -285,11 +286,13 @@ VarEntry* parseVar(char **ptr, VarEntry* target) {
switch (type) {
case 'L': // Local var
entry->base.type = CT_VAR;
entry->base.type = CT_VAR;
entry->base.create_thunk = create_thunk_funs[CT_VAR];
entry->base.strict = false;
break;
case 'S': // Strict local var
entry->base.type = CT_VAR_STRICT;
entry->base.type = CT_VAR_STRICT;
entry->base.create_thunk = create_thunk_funs[CT_VAR_STRICT];
entry->base.strict = true;
break;
default:
......@@ -325,6 +328,7 @@ Code* parseApp(char **ptr, bool dynamic) {
{
struct ThunkEntry* entry = (ThunkEntry*) alloc_code(sizeof (ThunkEntry));
entry->base.type = CT_THUNK;
entry->base.create_thunk = create_thunk_funs[CT_THUNK];
entry->thunk.desc = desc;
return (Code*) entry;
}
......@@ -334,6 +338,7 @@ Code* parseApp(char **ptr, bool dynamic) {
// TODO: CAS
entry->base.type = CT_APP_FUN;
entry->base.create_thunk = create_thunk_funs[CT_APP_FUN];
}
else
{
......@@ -347,7 +352,8 @@ Code* parseApp(char **ptr, bool dynamic) {
if(dynamic)
{
parseVar(ptr, &entry->var);
entry->base.type = CT_APP_DYN;
entry->base.type = CT_APP_DYN;
entry->base.create_thunk = create_thunk_funs[CT_APP_DYN];
}
else
{
......@@ -360,14 +366,17 @@ Code* parseApp(char **ptr, bool dynamic) {
if(desc->type == FT_PRIM)
{
entry->base.type = CT_APP_PRIM;
entry->base.create_thunk = create_thunk_funs[CT_APP_PRIM];
}
else if(desc->type == FT_FUN)
{
entry->base.type = CT_APP_FUN;
entry->base.create_thunk = create_thunk_funs[CT_APP_FUN];
}
else
{
entry->base.type = CT_APP_THUNK;
entry->base.create_thunk = create_thunk_funs[CT_APP_THUNK];
}
}
}
......@@ -384,6 +393,7 @@ SelectEntry* parseSelect(char **ptr) {
struct SelectEntry* entry = (SelectEntry*) alloc_code(sizeof (SelectEntry) + sizeof (SelectCaseEntry) * nrCases);
entry->base.type = CT_SELECT;
entry->base.create_thunk = create_thunk_funs[CT_SELECT];
entry->base.nr_cases = nrCases;
entry->expr = expr;
......@@ -415,6 +425,7 @@ SelectEntry* parseSelect(char **ptr) {
IfEntry* parseIf(char **ptr) {
struct IfEntry* entry = (IfEntry*) alloc_code(sizeof (IfEntry));
entry->base.type = CT_IF;
entry->base.create_thunk = create_thunk_funs[CT_IF];
entry->cond = parseTerm(ptr);
entry->texpr = parseTerm(ptr);
entry->fexpr = parseTerm(ptr);
......
......@@ -87,7 +87,7 @@ struct Thunk* createT(Thunk* source) {
bool is_hnf(Thunk* thunk)
{
return !(thunk->desc->type == FT_FUN || thunk->desc->type == FT_PRIM);
return thunk->desc->hnf;
}
void print(Thunk* thunk, bool force) {
......
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