diff options
| author | kr.angelov <kr.angelov@gmail.com> | 2014-10-08 12:57:29 +0000 |
|---|---|---|
| committer | kr.angelov <kr.angelov@gmail.com> | 2014-10-08 12:57:29 +0000 |
| commit | 9c2f71b07a5de7d6d4d13dc3c72d9b9ddc2f37dc (patch) | |
| tree | cc468098d8b2f567121b860662311b9eb8d18492 /src/runtime/c/pgf/evaluator.c | |
| parent | 67781996b639e9c31acd4a25b229222139686f07 (diff) | |
now we statically allocate closures for all top-level functions and all nullary constructors. closures are dynamically allocated only for CAFs. this reduces memory use and time to allocate dynamic closures
Diffstat (limited to 'src/runtime/c/pgf/evaluator.c')
| -rw-r--r-- | src/runtime/c/pgf/evaluator.c | 25 |
1 files changed, 14 insertions, 11 deletions
diff --git a/src/runtime/c/pgf/evaluator.c b/src/runtime/c/pgf/evaluator.c index eebaefd98..812b9f130 100644 --- a/src/runtime/c/pgf/evaluator.c +++ b/src/runtime/c/pgf/evaluator.c @@ -82,8 +82,8 @@ repeat:; gu_map_get(state->pgf->abstract.funs, efun->fun, PgfAbsFun*); gu_assert(absfun != NULL); - if (absfun->closure_id > 0) { - res = &state->globals[absfun->closure_id-1].header; + if (absfun->closure.code != NULL) { + res = (PgfClosure*) &absfun->closure; if (n_args > 0) { PgfValuePAP* val = gu_new_flex(state->pool, PgfValuePAP, args, n_args); @@ -101,7 +101,7 @@ repeat:; if (n_args == arity) { PgfValue* val = gu_new_flex(state->pool, PgfValue, args, arity); val->header.code = state->eval_gates->evaluate_value; - val->absfun = absfun; + val->con = (PgfClosure*) &absfun->closure; for (size_t i = 0; i < arity; i++) { val->args[i] = args[--n_args]; @@ -240,9 +240,10 @@ pgf_value2expr(PgfEvalState* state, int level, PgfClosure* clos, GuPool* pool) if (clos->code == state->eval_gates->evaluate_value) { PgfValue* val = (PgfValue*) clos; + PgfAbsFun* absfun = gu_container(val->con, PgfAbsFun, closure); - expr = val->absfun->ep.expr; - n_args = val->absfun->arity; + expr = absfun->ep.expr; + n_args = absfun->arity; args = val->args; } else if (clos->code == state->eval_gates->evaluate_value_gen) { PgfValueGen* val = (PgfValueGen*) clos; @@ -360,19 +361,21 @@ pgf_value2expr(PgfEvalState* state, int level, PgfClosure* clos, GuPool* pool) PgfExpr pgf_compute(PgfPGF* pgf, PgfExpr expr, GuExn* err, GuPool* pool, GuPool* out_pool) { - size_t n_closures = gu_seq_length(pgf->abstract.eval_gates->defrules); + size_t n_cafs = + (pgf->abstract.eval_gates->cafs == NULL) + ? 0 : gu_seq_length(pgf->abstract.eval_gates->cafs); PgfEvalState* state = - gu_new_flex(pool, PgfEvalState, globals, n_closures); + gu_new_flex(pool, PgfEvalState, cafs, n_cafs); state->pgf = pgf; state->eval_gates = pgf->abstract.eval_gates; state->pool = pool; state->err = err; - PgfFunction* defrules = gu_seq_data(state->eval_gates->defrules); - for (size_t i = 0; i < n_closures; i++) { - state->globals[i].header.code = defrules[i]; - state->globals[i].val = NULL; + PgfFunction* cafs = gu_seq_data(state->eval_gates->cafs); + for (size_t i = 0; i < n_cafs; i++) { + state->cafs[i].header.code = cafs[i]; + state->cafs[i].val = NULL; } PgfExprThunk* thunk = |
