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

clean up

parent 4642a828
......@@ -166,16 +166,16 @@ void exec(Code* expr, int frame_ptr, int root_frame_ptr)
{
switch(expr->arg_pattern)
{
case 1:
push_a(local(frame_ptr, ((VarEntry*) ((AppEntry*) expr)->args[0])->index));
break;
case 2:
push_a(&((ThunkEntry*) ((AppEntry*) expr)->args[0])->thunk);
break;
default:
placeholder();
exec(((AppEntry*) expr)->args[0], frame_ptr, stack_top_a);
break;
case 1:
push_a(local(frame_ptr, ((VarEntry*) ((AppEntry*) expr)->args[0])->index));
break;
case 2:
push_a(&((ThunkEntry*) ((AppEntry*) expr)->args[0])->thunk);
break;
default:
placeholder();
exec(((AppEntry*) expr)->args[0], frame_ptr, stack_top_a);
break;
}
((PrimEntry*) ((AppEntry*) expr)->f)->exec(root_frame_ptr);
......@@ -186,45 +186,48 @@ void exec(Code* expr, int frame_ptr, int root_frame_ptr)
}
case CT_APP_PRIM2:
{
// careful, "exec" may trigger garbage collection
// read local variables only after the last exec
switch(expr->arg_pattern)
{
case 1:
push_a(local(frame_ptr, ((VarEntry*) ((AppEntry*) expr)->args[0])->index));
push_a(&((ThunkEntry*) ((AppEntry*) expr)->args[1])->thunk);
break;
case 2:
push_a(&((ThunkEntry*) ((AppEntry*) expr)->args[0])->thunk);
push_a(local(frame_ptr, ((VarEntry*) ((AppEntry*) expr)->args[1])->index));
break;
case 3:
push_a(local(frame_ptr, ((VarEntry*) ((AppEntry*) expr)->args[0])->index));
push_a(local(frame_ptr, ((VarEntry*) ((AppEntry*) expr)->args[1])->index));
break;
case 4:
push_a(&((ThunkEntry*) ((AppEntry*) expr)->args[0])->thunk);
placeholder();
exec(((AppEntry*) expr)->args[1], frame_ptr, stack_top_a);
break;
case 5:
placeholder();
exec(((AppEntry*) expr)->args[0], frame_ptr, stack_top_a);
push_a(&((ThunkEntry*) ((AppEntry*) expr)->args[1])->thunk);
break;
case 6:
push_a(local(frame_ptr, ((VarEntry*) ((AppEntry*) expr)->args[0])->index));
placeholder();
exec(((AppEntry*) expr)->args[1], frame_ptr, stack_top_a);
break;
case 7:
placeholder();
exec(((AppEntry*) expr)->args[0], frame_ptr, stack_top_a);
push_a(local(frame_ptr, ((VarEntry*) ((AppEntry*) expr)->args[1])->index));
break;
default:
placeholder();
exec(((AppEntry*) expr)->args[0], frame_ptr, stack_top_a);
placeholder();
exec(((AppEntry*) expr)->args[1], frame_ptr, stack_top_a);
case 1:
push_a(local(frame_ptr, ((VarEntry*) ((AppEntry*) expr)->args[0])->index));
push_a(&((ThunkEntry*) ((AppEntry*) expr)->args[1])->thunk);
break;
case 2:
push_a(&((ThunkEntry*) ((AppEntry*) expr)->args[0])->thunk);
push_a(local(frame_ptr, ((VarEntry*) ((AppEntry*) expr)->args[1])->index));
break;
case 3:
push_a(local(frame_ptr, ((VarEntry*) ((AppEntry*) expr)->args[0])->index));
push_a(local(frame_ptr, ((VarEntry*) ((AppEntry*) expr)->args[1])->index));
break;
case 4:
push_a(&((ThunkEntry*) ((AppEntry*) expr)->args[0])->thunk);
placeholder();
exec(((AppEntry*) expr)->args[1], frame_ptr, stack_top_a);
break;
case 5:
placeholder();
exec(((AppEntry*) expr)->args[0], frame_ptr, stack_top_a);
push_a(&((ThunkEntry*) ((AppEntry*) expr)->args[1])->thunk);
break;
case 6:
push_a(local(frame_ptr, ((VarEntry*) ((AppEntry*) expr)->args[0])->index));
placeholder();
exec(((AppEntry*) expr)->args[1], frame_ptr, stack_top_a);
break;
case 7:
placeholder();
exec(((AppEntry*) expr)->args[0], frame_ptr, stack_top_a);
push_a(local(frame_ptr, ((VarEntry*) ((AppEntry*) expr)->args[1])->index));
break;
default:
placeholder();
exec(((AppEntry*) expr)->args[0], frame_ptr, stack_top_a);
placeholder();
exec(((AppEntry*) expr)->args[1], frame_ptr, stack_top_a);
}
((PrimEntry*) ((AppEntry*) expr)->f)->exec(root_frame_ptr);
......
......@@ -2,7 +2,7 @@
#define DEBUG_H
//#define DEBUG
#define BENCHMARK
//#define BENCHMARK
#ifndef DEBUG
#define NDEBUG
......
......@@ -12,7 +12,7 @@
int readI(Thunk* thunk) {
assert(thunk != NULL);
if (thunk->desc != (Desc*) __INT__ && thunk->desc != (Desc*) __INT_SHARED__) {
if (thunk->desc != (Desc*) __INT__) {
printf("readI: not an integer: ");
printDesc(thunk->desc);
exit(-1);
......@@ -24,7 +24,7 @@ int readI(Thunk* thunk) {
int readB(Thunk* thunk) {
assert(thunk != NULL);
if (thunk->desc != (Desc*) __BOOL__ && thunk->desc != (Desc*) __BOOL_SHARED__) {
if (thunk->desc != (Desc*) __BOOL__) {
printf("readB: not a boolean: ");
printDesc(thunk->desc);
exit(-1);
......@@ -32,6 +32,18 @@ int readB(Thunk* thunk) {
return thunk->_bool;
}
char readC(Thunk* thunk) {
assert(thunk != NULL);
if (thunk->desc != (Desc*) __CHAR__) {
printf("readC: not a char: ");
printDesc(thunk->desc);
exit(-1);
}
return thunk->_char;
}
#endif
bool is_hnf(Thunk* thunk)
......
......@@ -38,6 +38,7 @@ typedef struct __attribute__((packed)) Thunk {
int readI(Thunk* thunk);
int readB(Thunk* thunk);
char readC(Thunk* thunk);
#else
......
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