From 9fd8d5d019359ecffef87f8f9f4311aebd2b2481 Mon Sep 17 00:00:00 2001 From: "kr.angelov" Date: Tue, 30 Sep 2014 08:42:06 +0000 Subject: [PATCH] bugfix in the gate evaluate_value_lambda --- src/runtime/c/pgf/evaluator.c | 32 +++++++++++++++++++++++--------- src/runtime/c/pgf/evaluator.h | 6 +++++- src/runtime/c/pgf/jit.c | 15 +++------------ 3 files changed, 31 insertions(+), 22 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); diff --git a/src/runtime/c/pgf/evaluator.h b/src/runtime/c/pgf/evaluator.h index a6a98cdf1..0e9236abb 100644 --- a/src/runtime/c/pgf/evaluator.h +++ b/src/runtime/c/pgf/evaluator.h @@ -86,6 +86,10 @@ struct PgfEvalGates { }; PgfClosure* -pgf_evaluate_expr_thunk(PgfEvalState* state, PgfClosure* closure); +pgf_evaluate_expr_thunk(PgfEvalState* state, PgfExprThunk* thunk); + +PgfClosure* +pgf_evaluate_lambda_application(PgfEvalState* state, PgfExprThunk* lambda, + PgfClosure* arg); #endif diff --git a/src/runtime/c/pgf/jit.c b/src/runtime/c/pgf/jit.c index 09fdf3bc6..963da45c7 100644 --- a/src/runtime/c/pgf/jit.c +++ b/src/runtime/c/pgf/jit.c @@ -569,23 +569,14 @@ pgf_jit_gates(PgfReader* rdr) gates->evaluate_value_lambda = jit_get_ip().ptr; jit_subr_p(JIT_R0, JIT_FP, JIT_SP); jit_blti_i(gates->update_pap, JIT_R0, 2*sizeof(PgfClosure*)); - jit_prepare(2); - jit_movi_i(JIT_R0, sizeof(PgfEnv)); - jit_pusharg_ui(JIT_R0); - jit_ldxi_p(JIT_R0, JIT_VSTATE, offsetof(PgfEvalState,pool)); - jit_pusharg_p(JIT_R0); - jit_finish(gu_malloc); jit_popr_p(JIT_R2); - jit_ldxi_p(JIT_R1, JIT_VCLOS, offsetof(PgfExprThunk,env)); - jit_stxi_p(offsetof(PgfEnv,next), JIT_RET, JIT_R1); jit_popr_p(JIT_R1); - jit_stxi_p(offsetof(PgfEnv,closure), JIT_RET, JIT_R1); - jit_stxi_p(offsetof(PgfExprThunk,env), JIT_VCLOS, JIT_RET); jit_pushr_p(JIT_R2); - jit_prepare(2); + jit_prepare(3); + jit_pusharg_p(JIT_R1); jit_pusharg_p(JIT_VCLOS); jit_pusharg_p(JIT_VSTATE); - jit_finish(pgf_evaluate_expr_thunk); + jit_finish(pgf_evaluate_lambda_application); jit_retval(JIT_VCLOS); jit_ldr_p(JIT_R0, JIT_VCLOS); jit_jmpr(JIT_R0);