Commit 6e5493c4 authored by Laszlo Domoszlai's avatar Laszlo Domoszlai
Browse files

move thunk allocation a bit later for prims, so GC cannot screw up everything

parent b9ecfe99
...@@ -172,13 +172,7 @@ void exec(Code* expr, int frame_ptr, int root_frame_ptr) ...@@ -172,13 +172,7 @@ void exec(Code* expr, int frame_ptr, int root_frame_ptr)
switch (expr->type) { switch (expr->type) {
case CT_APP_PRIM1: case CT_APP_PRIM1:
{ {
if(get_dst(root_frame_ptr) == NULL && (((AppEntry*) expr)->f)->unboxable_return)
{
Thunk* tmp = (Thunk*) alloc_heap(sizeof(Thunk));
set_return(root_frame_ptr, tmp);
}
switch(expr->arg_pattern) switch(expr->arg_pattern)
{ {
case 1: case 1:
...@@ -192,7 +186,13 @@ void exec(Code* expr, int frame_ptr, int root_frame_ptr) ...@@ -192,7 +186,13 @@ void exec(Code* expr, int frame_ptr, int root_frame_ptr)
exec(((AppEntry*) expr)->args[0], frame_ptr, stack_top_a); exec(((AppEntry*) expr)->args[0], frame_ptr, stack_top_a);
break; break;
} }
if(get_dst(root_frame_ptr) == NULL && (((AppEntry*) expr)->f)->unboxable_return)
{
Thunk* tmp = (Thunk*) alloc_heap(sizeof(Thunk));
set_return(root_frame_ptr, tmp);
}
((PrimEntry*) ((AppEntry*) expr)->f)->exec(root_frame_ptr); ((PrimEntry*) ((AppEntry*) expr)->f)->exec(root_frame_ptr);
destroy_stack_frame(root_frame_ptr); destroy_stack_frame(root_frame_ptr);
...@@ -200,13 +200,7 @@ void exec(Code* expr, int frame_ptr, int root_frame_ptr) ...@@ -200,13 +200,7 @@ void exec(Code* expr, int frame_ptr, int root_frame_ptr)
return; return;
} }
case CT_APP_PRIM2: case CT_APP_PRIM2:
{ {
if(get_dst(root_frame_ptr) == NULL && (((AppEntry*) expr)->f)->unboxable_return)
{
Thunk* tmp = (Thunk*) alloc_heap(sizeof(Thunk));
set_return(root_frame_ptr, tmp);
}
// careful, "exec" may trigger garbage collection // careful, "exec" may trigger garbage collection
// read local variables only after the last exec // read local variables only after the last exec
switch(expr->arg_pattern) switch(expr->arg_pattern)
...@@ -250,6 +244,12 @@ void exec(Code* expr, int frame_ptr, int root_frame_ptr) ...@@ -250,6 +244,12 @@ void exec(Code* expr, int frame_ptr, int root_frame_ptr)
exec(((AppEntry*) expr)->args[1], frame_ptr, stack_top_a); exec(((AppEntry*) expr)->args[1], frame_ptr, stack_top_a);
} }
if(get_dst(root_frame_ptr) == NULL && (((AppEntry*) expr)->f)->unboxable_return)
{
Thunk* tmp = (Thunk*) alloc_heap(sizeof(Thunk));
set_return(root_frame_ptr, tmp);
}
((PrimEntry*) ((AppEntry*) expr)->f)->exec(root_frame_ptr); ((PrimEntry*) ((AppEntry*) expr)->f)->exec(root_frame_ptr);
destroy_stack_frame(root_frame_ptr); destroy_stack_frame(root_frame_ptr);
...@@ -258,12 +258,6 @@ void exec(Code* expr, int frame_ptr, int root_frame_ptr) ...@@ -258,12 +258,6 @@ void exec(Code* expr, int frame_ptr, int root_frame_ptr)
} }
case CT_APP_PRIM: case CT_APP_PRIM:
{ {
if(get_dst(root_frame_ptr) == NULL && (((AppEntry*) expr)->f)->unboxable_return)
{
Thunk* tmp = (Thunk*) alloc_heap(sizeof(Thunk));
set_return(root_frame_ptr, tmp);
};
PrimEntry* desc = (PrimEntry*) ((AppEntry*) expr)->f; PrimEntry* desc = (PrimEntry*) ((AppEntry*) expr)->f;
int argmask = 1; int argmask = 1;
...@@ -283,6 +277,12 @@ void exec(Code* expr, int frame_ptr, int root_frame_ptr) ...@@ -283,6 +277,12 @@ void exec(Code* expr, int frame_ptr, int root_frame_ptr)
argmask <<= 1; argmask <<= 1;
} }
if(get_dst(root_frame_ptr) == NULL && (((AppEntry*) expr)->f)->unboxable_return)
{
Thunk* tmp = (Thunk*) alloc_heap(sizeof(Thunk));
set_return(root_frame_ptr, tmp);
}
desc->exec(root_frame_ptr); desc->exec(root_frame_ptr);
destroy_stack_frame(root_frame_ptr); destroy_stack_frame(root_frame_ptr);
...@@ -414,6 +414,12 @@ void exec(Code* expr, int frame_ptr, int root_frame_ptr) ...@@ -414,6 +414,12 @@ void exec(Code* expr, int frame_ptr, int root_frame_ptr)
exec(((AppEntry*) expr)->args[i], frame_ptr, stack_top_a); exec(((AppEntry*) expr)->args[i], frame_ptr, stack_top_a);
} }
if(get_dst(root_frame_ptr) == NULL && slice->unboxable_return)
{
Thunk* tmp = (Thunk*) alloc_heap(sizeof(Thunk));
set_return(root_frame_ptr, tmp);
}
((PrimEntry*) slice)->exec(root_frame_ptr); ((PrimEntry*) slice)->exec(root_frame_ptr);
destroy_stack_frame(root_frame_ptr); destroy_stack_frame(root_frame_ptr);
destroy_stack_frame_b(root_frame_ptr_b); destroy_stack_frame_b(root_frame_ptr_b);
......
...@@ -74,7 +74,7 @@ int main ( int argc, char *argv[] ) ...@@ -74,7 +74,7 @@ int main ( int argc, char *argv[] )
parse(&line, len); parse(&line, len);
input = "..\\tests\\parsetest1.bsapl"; input = "..\\tests\\static_os.bsapl";
if ( argc == 2 ) if ( argc == 2 )
{ {
...@@ -109,9 +109,7 @@ int main ( int argc, char *argv[] ) ...@@ -109,9 +109,7 @@ int main ( int argc, char *argv[] )
gettimeofday(&t1, NULL); gettimeofday(&t1, NULL);
#endif #endif
Thunk* res = alloc_b(); push_a(NULL);
res->desc = (Desc*) __INT__; // does not matter, but should be a proper descriptor
push_a(res);
exec(expr, stack_top_a, stack_top_a); exec(expr, stack_top_a, stack_top_a);
print(true); print(true);
......
Supports Markdown
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