CHECK_BB(emit_defers(emit));
emit_return_pc(emit, val);
vector_clear(&emit->code->stack_return);
- if (emit->info->memoize && fflag(emit->env->func, fflag_pure)) {
+ const Func f = emit->env->func;
+ if (f->memoize && fflag(f, fflag_pure)) {
const Instr instr = emit_add_instr(emit, MemoizeStore);
- instr->m_val = emit->env->func->def->stack_depth;
+ instr->m_val = f->def->stack_depth;
}
return GW_OK;
}
ANN static VM_Code emit_func_def_code(const Emitter emit, const Func func) {
const VM_Code code = _emit_func_def_code(emit, func);
- if (emit->info->memoize && fflag(func, fflag_pure)) code->is_memoize = true;
+ if (func->memoize && fflag(func, fflag_pure)) code->is_memoize = true;
code->ret_type = func->def->base->ret_type;
return code;
}
}
ANN static m_bool emit_fdef(const Emitter emit, const Func_Def fdef) {
- if (emit->info->memoize && fflag(fdef->base->func, fflag_pure))
+ const Func f = fdef->base->func;
+ if (f->memoize && fflag(f, fflag_pure))
CHECK_BB(emit_memoize(emit, fdef));
CHECK_BB(emit_func_def_body(emit, fdef));
emit_func_def_return(emit);
ANN static void emit_fdef_finish(const Emitter emit, const Func_Def fdef) {
const Func func = fdef->base->func;
func->code = emit_func_def_code(emit, func);
- if (emit->info->memoize && fflag(func, fflag_pure))
+ if (func->memoize && fflag(func, fflag_pure))
func->code->memoize = memoize_ini(emit, func);
}
}
ANN static inline void emit_clear(const Emitter emit) {
- emit->info->memoize = 0;
emit->info->unroll = 0;
emit->info->line = 0;
emit->this_offset = 0;
ANN static m_bool check_stmt_pp(const Env env, const Stmt_PP stmt) {
if (stmt->pp_type == ae_pp_include) env->name = stmt->data;
+ // check for memoization
+ if (env->func && stmt->pp_type == ae_pp_pragma &&
+ !strncmp(stmt->data, "memoize", strlen("memoize")))
+ env->func->memoize = strtol(stmt->data + 7, NULL, 10);
return GW_OK;
}