forked from GitHub/gf-core
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
This commit is contained in:
@@ -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 =
|
||||
|
||||
Reference in New Issue
Block a user