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

+ remove unnecessary argument from create_thunk

+ introduce B stack
parent de9bc49a
......@@ -7,7 +7,7 @@
#include "mem.h"
#include "desc.h"
struct Thunk* create_thunk(Code* expr, int frame_ptr, int root_frame_ptr)
struct Thunk* create_thunk(Code* expr, int frame_ptr)
{
assert(expr != NULL);
......@@ -37,10 +37,9 @@ struct Thunk* create_thunk(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(((AppEntry*) expr)->args[i], frame_ptr, stack_top_a);
= create_thunk(((AppEntry*) expr)->args[i], frame_ptr);
}
destroy_stack_frame(root_frame_ptr);
return thunk;
}
else
......@@ -50,24 +49,19 @@ struct Thunk* create_thunk(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++) {
thunk->_args[i] = create_thunk(((AppEntry*) expr)->args[i], frame_ptr, stack_top_a);
thunk->_args[i] = create_thunk(((AppEntry*) expr)->args[i], frame_ptr);
}
destroy_stack_frame(root_frame_ptr);
return 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;
return forward_to(NULL, local(frame_ptr, ((VarEntry*) expr)->index));
}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);
}
}
......@@ -122,7 +116,7 @@ void exec(Code* expr, int frame_ptr, int root_frame_ptr)
for (int i = 0; i < expr->nr_args; i++) {
// TODO: eval
push_a(create_thunk(((AppEntry*) expr)->args[i], frame_ptr, stack_top_a));
push_a(create_thunk(((AppEntry*) expr)->args[i], frame_ptr));
}
expr = ((FunEntry*) slice)->body;
......@@ -141,7 +135,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(((AppEntry*) expr)->args[i], frame_ptr, stack_top_a);
= create_thunk(((AppEntry*) expr)->args[i], frame_ptr);
}
set_return(root_frame_ptr, thunk);
......@@ -178,7 +172,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));
}
}
......@@ -193,7 +187,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(((AppEntry*) expr)->args[i], frame_ptr, stack_top_a);
= create_thunk(((AppEntry*) expr)->args[i], frame_ptr);
}
set_return(root_frame_ptr, thunk);
......
......@@ -10,7 +10,9 @@ int heap_alloc;
int nr_heap_alloc;
int stack_top_a;
int stack_top_b;
Thunk* stack_a[STACK_SIZE_A];
Thunk stack_b[STACK_SIZE_B];
#define heap_size 1024*1024*1024
char* heap_start;
......
......@@ -7,7 +7,9 @@
#define STACK_SIZE_B 10240
extern int stack_top_a;
extern int stack_top_b;
extern Thunk* stack_a[STACK_SIZE_A];
extern Thunk stack_b[STACK_SIZE_B];
#define peek_a() stack_a[stack_top_a-1]
#define pop_a() stack_a[--stack_top_a]
......@@ -18,6 +20,10 @@ extern Thunk* stack_a[STACK_SIZE_A];
#define destroy_stack_frame(base) stack_top_a = base
#define get_dst(base) stack_a[base-1]
#define alloc_b(nr) stack_top_b+=nr
#define destroy_stack_frame_b(base) stack_top_b = base
void init_mem();
void print_stat();
......
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