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

create_thunk returns a Thunk instead of updating the stack frame. Braun much faster this way.

probably because most of the time the value removed immediately from the stack and set in a thunk
this way, this additional step can be saved
parent 016c82fe
......@@ -7,25 +7,22 @@
#include "mem.h"
#include "desc.h"
void create_thunk(Code* expr, int frame_ptr, int root_frame_ptr)
struct Thunk* create_thunk(Code* expr, int frame_ptr, int root_frame_ptr)
{
assert(expr != NULL);
switch (expr->type) {
case CT_LIT:
set_return(root_frame_ptr, updateT(get_dst(root_frame_ptr), &((LitEntry*) expr)->thunk));
destroy_stack_frame(root_frame_ptr);
return;
return updateT(NULL, &((LitEntry*) expr)->thunk);
case CT_VAR:
if (expr->local_type == VAR_LOCAL) {
Thunk* thunk = forward_to(get_dst(root_frame_ptr), local(frame_ptr, ((VarEntry*) expr)->index));
Thunk* thunk = forward_to(NULL, local(frame_ptr, ((VarEntry*) expr)->index));
destroy_stack_frame(root_frame_ptr);
set_return(root_frame_ptr, thunk);
return;
return thunk;
}else{
destroy_stack_frame(root_frame_ptr);
set_return(root_frame_ptr, updateF(get_dst(root_frame_ptr), get_slice(((VarEntry*) expr)->f, 0)));
return;
return updateF(NULL, get_slice(((VarEntry*) expr)->f, 0));
}
case CT_APP:
{
......@@ -44,7 +41,7 @@ void create_thunk(Code* expr, int frame_ptr, int root_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(get_dst(root_frame_ptr), slice);
Thunk* thunk = updateF(NULL, slice);
assert(thunk->desc->arity == basethunk->desc->arity + expr->nr_args);
......@@ -53,30 +50,25 @@ void create_thunk(Code* expr, int frame_ptr, int root_frame_ptr)
}
for (int i = 0; i < expr->nr_args; i++) {
push_a(NULL);
create_thunk(((AppEntry*) expr)->args[i], frame_ptr, stack_top_a);
thunk->_args[basethunk->desc->arity + i] = pop_a();
thunk->_args[basethunk->desc->arity + i]
= create_thunk(((AppEntry*) expr)->args[i], frame_ptr, stack_top_a);
}
set_return(root_frame_ptr, thunk);
destroy_stack_frame(root_frame_ptr);
return;
return thunk;
}
else
{
Thunk* thunk = updateF(get_dst(root_frame_ptr), get_slice(var->f, expr->nr_args));
Thunk* thunk = updateF(NULL, get_slice(var->f, expr->nr_args));
assert(thunk->desc->arity == expr->nr_args);
for (int i = 0; i < expr->nr_args; i++) {
push_a(NULL);
create_thunk(((AppEntry*) expr)->args[i], frame_ptr, stack_top_a);
thunk->_args[i] = pop_a();
thunk->_args[i] = create_thunk(((AppEntry*) expr)->args[i], frame_ptr, stack_top_a);
}
set_return(root_frame_ptr, thunk);
destroy_stack_frame(root_frame_ptr);
return;
return thunk;
}
break;
}
......@@ -147,9 +139,8 @@ void exec(Code* expr, int frame_ptr, int root_frame_ptr)
}
for (int i = 0; i < expr->nr_args; i++) {
push_a(NULL);
create_thunk(((AppEntry*) expr)->args[i], frame_ptr, stack_top_a);
thunk->_args[basethunk->desc->arity + i] = pop_a();
thunk->_args[basethunk->desc->arity + i]
= create_thunk(((AppEntry*) expr)->args[i], frame_ptr, stack_top_a);
}
set_return(root_frame_ptr, thunk);
......@@ -177,14 +168,15 @@ void exec(Code* expr, int frame_ptr, int root_frame_ptr)
int new_frame_ptr = stack_top_a;
for (int i = 0; i < expr->nr_args; i++) {
push_a(NULL);
if(is_strict_fun_arg((FunEntry*) slice, i))
{
push_a(NULL);
exec(((AppEntry*) expr)->args[i], frame_ptr, stack_top_a);
}
else
{
create_thunk(((AppEntry*) expr)->args[i], frame_ptr, stack_top_a);
push_a(create_thunk(((AppEntry*) expr)->args[i], frame_ptr, stack_top_a));
}
}
......@@ -198,9 +190,8 @@ void exec(Code* expr, int frame_ptr, int root_frame_ptr)
assert(thunk->desc->arity == expr->nr_args);
for (int i = 0; i < expr->nr_args; i++) {
push_a(NULL);
create_thunk(((AppEntry*) expr)->args[i], frame_ptr, stack_top_a);
thunk->_args[i] = pop_a();
thunk->_args[i]
= create_thunk(((AppEntry*) expr)->args[i], frame_ptr, stack_top_a);
}
set_return(root_frame_ptr, thunk);
......
......@@ -29,7 +29,7 @@ int main ( int argc, char *argv[] )
init_desc();
init_prim();
char* input = "..\\tests\\Braun.bsapl";
char* input = "..\\tests\\nfib.bsapl";
if ( argc == 2 )
{
......
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