Commit 2cb21c80 authored by Laszlo Domoszlai's avatar Laszlo Domoszlai
Browse files

split CT_APP nodes

parent 84b0d495
......@@ -49,9 +49,12 @@ struct Thunk* create_thunk(Code* expr, int frame_ptr)
// TODO: check over application
// TODO: enforce strictness in ADT/Record
// TODO: CAS
switch (expr->type) {
case CT_APP:
case CT_APP_PRIM:
case CT_APP_FUN:
case CT_APP_THUNK:
{
Thunk* thunk = createF(((AppEntry*) expr)->f);
......@@ -106,7 +109,8 @@ struct Thunk* create_thunk(Code* expr, int frame_ptr)
case CT_IF:
// Only here to avoid intervalum check at switch
abort("Unexpected code type");
}
return NULL;
}
}
void exec(Code* expr, int frame_ptr, int root_frame_ptr)
......@@ -123,61 +127,53 @@ void exec(Code* expr, int frame_ptr, int root_frame_ptr)
// TODO: enforce strictness in ADT/Record
switch (expr->type) {
case CT_APP:
case CT_APP_PRIM:
{
Desc* slice = ((AppEntry*) expr)->f;
switch (slice->type) {
case FT_PRIM:
{
for (int i = 0; i < expr->nr_args; i++) {
push_a(alloc_b());
exec(((AppEntry*) expr)->args[i], frame_ptr, stack_top_a);
}
((PrimEntry*) slice)->exec(root_frame_ptr);
destroy_stack_frame(root_frame_ptr);
destroy_stack_frame_b(root_frame_ptr_b);
return;
for (int i = 0; i < expr->nr_args; i++) {
push_a(alloc_b());
exec(((AppEntry*) expr)->args[i], frame_ptr, stack_top_a);
}
case FT_FUN:
{
int new_frame_ptr = stack_top_a;
int argmask = 1;
for (int i = 0; i < expr->nr_args; i++) {
arg_from_code(slice, ((AppEntry*) expr)->args[i]);
}
((PrimEntry*) slice)->exec(root_frame_ptr);
destroy_stack_frame(root_frame_ptr);
destroy_stack_frame_b(root_frame_ptr_b);
return;
}
case CT_APP_FUN:
{
Desc* slice = ((AppEntry*) expr)->f;
expr = ((FunEntry*) slice)->body;
frame_ptr = new_frame_ptr;
continue;
int new_frame_ptr = stack_top_a;
int argmask = 1;
for (int i = 0; i < expr->nr_args; i++) {
arg_from_code(slice, ((AppEntry*) expr)->args[i]);
}
case FT_SLICE:
case FT_ADT:
case FT_RECORD:
{
Thunk* thunk = updateF(get_dst(root_frame_ptr), slice);
assert(thunk->desc->arity == expr->nr_args);
expr = ((FunEntry*) slice)->body;
frame_ptr = new_frame_ptr;
continue;
}
case CT_APP_THUNK:
{
Desc* slice = ((AppEntry*) expr)->f;
for (int i = 0; i < expr->nr_args; i++) {
thunk->_args[i]
= create_thunk(((AppEntry*) expr)->args[i], frame_ptr);
}
Thunk* thunk = updateF(get_dst(root_frame_ptr), slice);
set_return(root_frame_ptr, thunk);
destroy_stack_frame(root_frame_ptr);
destroy_stack_frame_b(root_frame_ptr_b);
return;
}
case FT_BOXED_LIT:
abort("Literal unexpected here");
case FT_CAF:
case FT_CAF_REDUCED:
not_implemented("CAF");
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);
}
}
set_return(root_frame_ptr, thunk);
destroy_stack_frame(root_frame_ptr);
destroy_stack_frame_b(root_frame_ptr_b);
return;
}
case CT_APP_DYN:
{
Thunk* basethunk = local(frame_ptr, ((AppEntry*)expr)->var.index);
......
......@@ -4,11 +4,14 @@
#include "thunk.h"
enum CodeType {
CT_VAR, CT_VAR_STRICT, CT_APP, CT_APP_DYN, CT_SELECT, CT_IF, CT_THUNK
CT_VAR, CT_VAR_STRICT,
CT_APP_THUNK, CT_APP_PRIM, CT_APP_FUN, CT_APP_DYN,
CT_SELECT, CT_IF,
CT_THUNK
};
struct Code {
CodeType type : 3;
CodeType type : 4;
unsigned int nr_args : 5; // used in AppEntry
unsigned int nr_cases : 5; // used in SelectEntry
unsigned int strict : 1; // used in VarEntry
......
......@@ -331,7 +331,9 @@ Code* parseApp(char **ptr, bool dynamic) {
entry = (AppEntry*) alloc_code(sizeof (AppEntry));
entry->f = desc;
entry->base.type = CT_APP;
// TODO: CAS
entry->base.type = CT_APP_FUN;
}
else
{
......@@ -354,7 +356,19 @@ Code* parseApp(char **ptr, bool dynamic) {
Desc* desc = parseFunName(ptr); // can fail
if(desc != NULL) desc = get_slice(desc, nrArgs);
entry->f = desc;
entry->base.type = CT_APP;
if(desc->type == FT_PRIM)
{
entry->base.type = CT_APP_PRIM;
}
else if(desc->type == FT_FUN)
{
entry->base.type = CT_APP_FUN;
}
else
{
entry->base.type = CT_APP_THUNK;
}
}
}
......
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