Commit 2920cde0 authored by Laszlo Domoszlai's avatar Laszlo Domoszlai
Browse files

rearrange switch in main loop. put APP first, as more likely. small speedup for Braun

parent f1a3d839
......@@ -12,18 +12,6 @@ struct Thunk* create_thunk(Code* expr, int frame_ptr, int root_frame_ptr)
assert(expr != NULL);
switch (expr->type) {
case CT_LIT:
destroy_stack_frame(root_frame_ptr);
return updateT(NULL, &((LitEntry*) expr)->thunk);
case CT_VAR:
if (expr->local_type == VAR_LOCAL) {
Thunk* thunk = forward_to(NULL, local(frame_ptr, ((VarEntry*) expr)->index));
destroy_stack_frame(root_frame_ptr);
return thunk;
}else{
destroy_stack_frame(root_frame_ptr);
return updateF(NULL, get_slice(((VarEntry*) expr)->f, 0));
}
case CT_APP:
{
// TODO: check over application
......@@ -33,8 +21,6 @@ struct Thunk* create_thunk(Code* expr, int frame_ptr, int root_frame_ptr)
if (var->base.local_type == VAR_LOCAL)
{
// TODO: force
Thunk* basethunk = eval(local(frame_ptr, var->index));
Desc* slice =
......@@ -70,8 +56,19 @@ struct Thunk* create_thunk(Code* expr, int frame_ptr, int root_frame_ptr)
destroy_stack_frame(root_frame_ptr);
return thunk;
}
break;
}
}
case CT_VAR:
if (expr->local_type == VAR_LOCAL) {
Thunk* thunk = forward_to(NULL, local(frame_ptr, ((VarEntry*) expr)->index));
destroy_stack_frame(root_frame_ptr);
return thunk;
}else{
destroy_stack_frame(root_frame_ptr);
return updateF(NULL, get_slice(((VarEntry*) expr)->f, 0));
}
case CT_LIT:
destroy_stack_frame(root_frame_ptr);
return updateT(NULL, &((LitEntry*) expr)->thunk);
}
}
......@@ -83,36 +80,6 @@ void exec(Code* expr, int frame_ptr, int root_frame_ptr)
assert(stack_top_a < STACK_SIZE_A);
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;
case CT_VAR:
if (expr->local_type == VAR_LOCAL) {
Thunk* thunk = forward_to(get_dst(root_frame_ptr), local(frame_ptr, ((VarEntry*) expr)->index));
// Destroy stack frame before eval, it is not needed any more
// Greatly reduces stack usage
destroy_stack_frame(root_frame_ptr);
set_return(root_frame_ptr, eval(thunk));
return;
}else{
// Safe to destroy, the next call has no arguments
destroy_stack_frame(root_frame_ptr);
Desc* slice = get_slice(((VarEntry*) expr)->f, 0);
if(slice->type == FT_FUN)
{
expr = ((FunEntry*)slice)->body;
continue;
}
else
{
set_return(root_frame_ptr, updateF(get_dst(root_frame_ptr), slice));
return;
}
}
case CT_APP:
{
// TODO: check over application
......@@ -176,7 +143,7 @@ void exec(Code* expr, int frame_ptr, int root_frame_ptr)
}
else
{
push_a(create_thunk(((AppEntry*) expr)->args[i], frame_ptr, stack_top_a));
push_a(create_thunk(((AppEntry*) expr)->args[i], frame_ptr, stack_top_a));
}
}
......@@ -200,7 +167,37 @@ void exec(Code* expr, int frame_ptr, int root_frame_ptr)
}
}
break;
}
}
case CT_VAR:
if (expr->local_type == VAR_LOCAL) {
Thunk* thunk = forward_to(get_dst(root_frame_ptr), local(frame_ptr, ((VarEntry*) expr)->index));
// Destroy stack frame before eval, it is not needed any more
// Greatly reduces stack usage
destroy_stack_frame(root_frame_ptr);
set_return(root_frame_ptr, eval(thunk));
return;
}else{
// Safe to destroy, the next call has no arguments
destroy_stack_frame(root_frame_ptr);
Desc* slice = get_slice(((VarEntry*) expr)->f, 0);
if(slice->type == FT_FUN)
{
expr = ((FunEntry*)slice)->body;
continue;
}
else
{
set_return(root_frame_ptr, updateF(get_dst(root_frame_ptr), slice));
return;
}
}
case CT_LIT:
set_return(root_frame_ptr, updateT(get_dst(root_frame_ptr), &((LitEntry*) expr)->thunk));
destroy_stack_frame(root_frame_ptr);
return;
case CT_SELECT:
{
push_a(NULL);
......@@ -257,7 +254,7 @@ void exec(Code* expr, int frame_ptr, int root_frame_ptr)
expr = ((IfEntry*) expr)->fexpr;
continue;
}
}
}
default:
printf("Exec: Unhandled CODE type");
exit(-1);
......
......@@ -29,7 +29,7 @@ int main ( int argc, char *argv[] )
init_desc();
init_prim();
char* input = "..\\tests\\nfib.bsapl";
char* input = "..\\tests\\Braun.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