summaryrefslogtreecommitdiff
path: root/src/runtime/c/pgf/evaluator.c
diff options
context:
space:
mode:
authorkr.angelov <kr.angelov@gmail.com>2014-09-30 08:42:06 +0000
committerkr.angelov <kr.angelov@gmail.com>2014-09-30 08:42:06 +0000
commit70455b88a724309c2ce97634ae57c1c904808c08 (patch)
tree684b44850964d330276304311cac344f6f8b17ef /src/runtime/c/pgf/evaluator.c
parentf70eecb63c18abad54f1e8b4ac3cb09669725e6a (diff)
bugfix in the gate evaluate_value_lambda
Diffstat (limited to 'src/runtime/c/pgf/evaluator.c')
-rw-r--r--src/runtime/c/pgf/evaluator.c32
1 files changed, 23 insertions, 9 deletions
diff --git a/src/runtime/c/pgf/evaluator.c b/src/runtime/c/pgf/evaluator.c
index 25a9158dc..cec1aa806 100644
--- a/src/runtime/c/pgf/evaluator.c
+++ b/src/runtime/c/pgf/evaluator.c
@@ -6,9 +6,8 @@
#define PGF_ARGS_DELTA 5
PgfClosure*
-pgf_evaluate_expr_thunk(PgfEvalState* state, PgfClosure* closure)
+pgf_evaluate_expr_thunk(PgfEvalState* state, PgfExprThunk* thunk)
{
- PgfExprThunk* thunk = (PgfExprThunk*) closure;
PgfEnv* env = thunk->env;
PgfExpr expr = thunk->expr;
@@ -32,8 +31,8 @@ repeat:;
goto repeat;
} else {
thunk->header.code = state->eval_gates->evaluate_value_lambda;
- thunk->expr = eabs->body;
- res = closure;
+ thunk->expr = expr;
+ res = &thunk->header;
}
break;
}
@@ -55,7 +54,7 @@ repeat:;
}
case PGF_EXPR_LIT: {
PgfExprLit* elit = ei.data;
- PgfValueLit* val = (PgfValueLit*) closure;
+ PgfValueLit* val = (PgfValueLit*) thunk;
val->header.code = state->eval_gates->evaluate_value_lit;
val->lit = elit->lit;
res = &val->header;
@@ -73,7 +72,7 @@ repeat:;
val->args[i] = args[n_args-i-1];
}
- PgfIndirection* indir = (PgfIndirection*) closure;
+ PgfIndirection* indir = (PgfIndirection*) thunk;
indir->header.code = state->eval_gates->evaluate_indirection;
indir->val = &val->header;
@@ -120,7 +119,7 @@ repeat:;
res = &val->header;
}
- PgfIndirection* indir = (PgfIndirection*) closure;
+ PgfIndirection* indir = (PgfIndirection*) thunk;
indir->header.code = state->eval_gates->evaluate_indirection;
indir->val = res;
}
@@ -144,7 +143,7 @@ repeat:;
res = tmp_env->closure;
- PgfIndirection* indir = (PgfIndirection*) closure;
+ PgfIndirection* indir = (PgfIndirection*) thunk;
indir->header.code = state->eval_gates->evaluate_indirection;
indir->val = res;
@@ -178,6 +177,21 @@ repeat:;
return res;
}
+PgfClosure*
+pgf_evaluate_lambda_application(PgfEvalState* state, PgfExprThunk* lambda,
+ PgfClosure* arg)
+{
+ PgfEnv* new_env = gu_new(PgfEnv, state->pool);
+ new_env->next = lambda->env;
+ new_env->closure = arg;
+
+ PgfExprThunk* thunk = gu_new(PgfExprThunk, state->pool);
+ thunk->header.code = state->eval_gates->evaluate_expr_thunk;
+ thunk->env = new_env;
+ thunk->expr = ((PgfExprAbs*) gu_variant_data(lambda->expr))->body;
+ return pgf_evaluate_expr_thunk(state, thunk);
+}
+
static PgfExpr
pgf_value2expr(PgfEvalState* state, int level, PgfClosure* clos, GuPool* pool)
{
@@ -268,7 +282,7 @@ pgf_value2expr(PgfEvalState* state, int level, PgfClosure* clos, GuPool* pool)
args = pap->args;
} else if (clos->code == state->eval_gates->evaluate_value_lambda) {
PgfExprThunk *old_thunk = (PgfExprThunk*) clos;
- PgfExprAbs *old_eabs = gu_variant_open(old_thunk->expr).data;
+ PgfExprAbs *old_eabs = gu_variant_data(old_thunk->expr);
PgfValueGen* gen =
gu_new(PgfValueGen, state->pool);