Commit 27fa3129 authored by Laszlo Domoszlai's avatar Laszlo Domoszlai
Browse files

save a pointer in AppEntry

parent b337916d
......@@ -16,7 +16,7 @@ void exec(Code* expr, int frame_ptr, int root_frame_ptr, Thunk* target, bool for
{
switch (expr->type) {
case CT_LIT:
stack_top_a = root_frame_ptr;
stack_top_a = root_frame_ptr;
switch (expr->local_type) {
case LIT_INT:
......@@ -42,12 +42,11 @@ void exec(Code* expr, int frame_ptr, int root_frame_ptr, Thunk* target, bool for
}
break;
case CT_APP:
{
// TODO: check over application
// TODO: enforce strictness in ADT/Record
VarEntry* var;
var = ((AppEntry*) expr)->var;
VarEntry* var = &((AppEntry*) expr)->var;
Thunk* thunk;
if (var->base.local_type == VAR_LOCAL)
......@@ -120,6 +119,7 @@ void exec(Code* expr, int frame_ptr, int root_frame_ptr, Thunk* target, bool for
}
}
break;
}
case CT_SELECT:
{
exec(((SelectEntry*) expr)->expr, frame_ptr, stack_top_a, NULL, true);
......
......@@ -54,7 +54,7 @@ struct VarEntry {
struct AppEntry {
struct Code base;
struct VarEntry* var; // TODO: remove * here (embed VarEntry to save a space of one pointer)
struct VarEntry var;
struct Code* args[];
};
......
......@@ -266,11 +266,11 @@ LitEntry* parseLit(char **ptr) {
return entry;
}
VarEntry* parseVar(char **ptr) {
VarEntry* parseVar(char **ptr, VarEntry* target) {
// 1. Type char
char type = *(*ptr)++;
struct VarEntry* entry = (VarEntry*) alloc_code(sizeof (VarEntry));
struct VarEntry* entry = target == NULL ? (VarEntry*) alloc_code(sizeof (VarEntry)) : target;
entry->base.type = CT_VAR;
switch (type) {
......@@ -295,21 +295,20 @@ VarEntry* parseVar(char **ptr) {
Code* parseTerm(char **ptr);
AppEntry* parseApp(char **ptr) {
VarEntry* var = parseVar(ptr);
int nrArgs;
if (!parseInt(ptr, &nrArgs)) return 0;
struct AppEntry* entry = (AppEntry*) alloc_code(sizeof (AppEntry) + sizeof (void*) * nrArgs);
entry->base.type = CT_APP;
entry->base.nr_args = nrArgs;
entry->var = var;
for (int i = 0; i < nrArgs; i++) {
entry->args[i] = parseTerm(ptr);
if (entry->args[i] == 0) return 0;
}
parseVar(ptr, &entry->var);
return entry;
}
......@@ -367,7 +366,7 @@ Code* parseTerm(char **ptr) {
case 'L': // Literal
return (Code*) parseLit(ptr);
case 'V': // Variable
return (Code*) parseVar(ptr);
return (Code*) parseVar(ptr, NULL);
case 'A': // Application
return (Code*) parseApp(ptr);
case 'S': // Select
......
......@@ -55,7 +55,7 @@ sText text a = a <++ sNum (textSize text) <++ text
sTerm ctx (SLit lit) a = a <++ "L" <++ lit
sTerm ctx (SVar var) a = a <++ "V" <++ sVar ctx var
sTerm ctx (SApplication var terms) a = a <++ "A" <++ sVar ctx var <++ sList (sTerm ctx) terms
sTerm ctx (SApplication var terms) a = a <++ "A" <++ sList (sTerm ctx) terms <++ sVar ctx var
sTerm ctx (SSelect expr cs) a = a <++ "S" <++ sTerm ctx expr <++ sList (sSelectCase ctx) cs
sTerm ctx (SIf cond texpr fexpr) a = a <++ "I" <++ sTerm ctx cond <++ sTerm ctx texpr <++ sTerm ctx fexpr
......
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