xxx_cdef(check)
xxx_cdef(traverse)
+ANN m_bool scanx_fdef(const Env, void *, const Func_Def, const _exp_func);
+
__attribute__((returns_nonnull))
ANN Type get_type(const Type t);
ANN m_bool check_subscripts(const Env, const Array_Sub);
instr->m_val = val;
}
vector_clear(&emit->code->stack_return);
- emit_pop_scope(emit);
if(emit->info->memoize && GET_FLAG(emit->env->func, pure))
emit_add_instr(emit, MemoizeStore);
}
return ret;
}
+ANN static m_bool emit_fdef(const Emitter emit, const Func_Def fdef) {
+ CHECK_BB(emit_func_def_body(emit, fdef))
+ emit_func_def_return(emit);
+ return GW_OK;
+}
+
+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->env->class_def && !GET_FLAG(fdef, global) && !fdef->base->tmpl)
+ emit_func_def_global(emit, func->value_ref);
+ if(emit->info->memoize && GET_FLAG(func, pure))
+ func->code->memoize = memoize_ini(emit, func,
+ kindof(fdef->base->ret_type->size, !fdef->base->ret_type->size));
+}
+
ANN static m_bool emit_func_def(const Emitter emit, const Func_Def fdef) {
const Func func = fdef->base->func;
const Func former = emit->env->func;
stack_alloc_this(emit);
emit->env->func = func;
emit_push_scope(emit);
- if(fdef->base->tmpl)
- CHECK_BB(template_push_types(emit->env, fdef->base->tmpl))
- const m_bool ret = emit_func_def_body(emit, fdef);
+ const m_bool ret = scanx_fdef(emit->env, emit, fdef, (_exp_func)emit_fdef);
+ emit_pop_scope(emit);
+ emit->env->func = former;
if(ret > 0)
- emit_func_def_return(emit);
- if(fdef->base->tmpl)
- emit_pop_type(emit);
- if(ret > 0) {
- func->code = emit_func_def_code(emit, func);
- emit->env->func = former;
- if(!emit->env->class_def && !GET_FLAG(fdef, global) && !fdef->base->tmpl)
- emit_func_def_global(emit, func->value_ref);
- if(emit->info->memoize && GET_FLAG(func, pure))
- func->code->memoize = memoize_ini(emit, func,
- kindof(func->def->base->ret_type->size, !func->def->base->ret_type->size));
- }
+ emit_fdef_finish(emit, fdef);
return ret;
}
return variadic;
}
-ANN m_bool _check_func_def(const Env env, const Func_Def fdef) {
+ANN m_bool check_fdef(const Env env, const Func_Def fdef) {
if(fdef->base->args)
CHECK_BB(check_func_args(env, fdef->base->args))
else
return GW_OK;
}
-ANN m_bool _check_func_def_tmpl(const Env env, const Func_Def fdef) {
- if(fdef->base->tmpl)
- CHECK_BB(template_push_types(env, fdef->base->tmpl))
- const m_bool ret = _check_func_def(env, fdef);
- if(fdef->base->tmpl)
- nspc_pop_type(env->gwion->mp, env->curr);
- return ret;
-}
-
ANN m_bool check_func_def(const Env env, const Func_Def fdef) {
const Func func = fdef->base->func;
assert(func == fdef->base->func);
env->func = func;
++env->scope->depth;
nspc_push_value(env->gwion->mp, env->curr);
- const m_bool ret = _check_func_def_tmpl(env, fdef);
+ const m_bool ret = scanx_fdef(env, env, fdef, (_exp_func)check_fdef);
nspc_pop_value(env->gwion->mp, env->curr);
--env->scope->depth;
env->func = former;
return GW_OK;
}
-ANN static m_bool _scan1_func_def(const Env env, const Func_Def fdef) {
- if(fdef->base->tmpl)
- CHECK_BB(template_push_types(env, fdef->base->tmpl))
- const m_bool ret = scan1_fdef(env, fdef);
- if(fdef->base->tmpl)
- nspc_pop_type(env->gwion->mp, env->curr);
- return ret;
-}
-
ANN m_bool scan1_func_def(const Env env, const Func_Def fdef) {
if(fdef->base->td)
CHECK_BB(env_storage(env, fdef->flag, td_pos(fdef->base->td)))
struct Func_ fake = { .name=s_name(fdef->base->xid) }, *const former = env->func;
env->func = &fake;
++env->scope->depth;
- const m_bool ret = _scan1_func_def(env, fdef);
+ const m_bool ret = scanx_fdef(env, env, fdef, (_exp_func)scan1_fdef);
--env->scope->depth;
env->func = former;
return ret;
return v;
}
-ANN2(1, 2) static m_bool scan2_func_def_template(const Env env, const Func_Def f, const Value overload) {
+ANN2(1, 2) static m_bool scan2_fdef_tmpl(const Env env, const Func_Def f, const Value overload) {
const m_str name = s_name(f->base->xid);
const Func func = scan_new_func(env, f, name);
const Value value = func_value(env, func, overload);
return template_helper(env, f);
}
-
-ANN2(1,2) m_bool scan2_fdef(const Env env, const Func_Def f, const Value overload) {
+ANN2(1,2) m_bool scan2_fdef_std(const Env env, const Func_Def f, const Value overload) {
const m_str name = func_name(env, f, overload ?: NULL);
if((m_int)name <= GW_OK)
return (m_bool)(m_uint)name;
return GW_OK;
}
-ANN m_bool _scan2_func_def(const Env env, const Func_Def f) {
+ANN m_bool scan2_fdef(const Env env, const Func_Def f) {
const Value overload = nspc_lookup_value0(env->curr, f->base->xid);
if(overload)
CHECK_BB(scan2_func_def_overload(env, f, overload))
- if(f->base->tmpl)
- CHECK_BB(template_push_types(env, f->base->tmpl))
- const m_bool ret = (!tmpl_base(f->base->tmpl) ? scan2_fdef : scan2_func_def_template)(env, f, overload);
- if(f->base->tmpl)
- nspc_pop_type(env->gwion->mp, env->curr);
- return ret;
+ return (!tmpl_base(f->base->tmpl) ? scan2_fdef_std : scan2_fdef_tmpl)(env, f, overload);
}
ANN m_bool scan2_func_def(const Env env, const Func_Def f) {
f->stack_depth = (env->class_def && !GET_FLAG(f, static) && !GET_FLAG(f, global)) ? SZ_INT : 0;
if(GET_FLAG(f, variadic))
f->stack_depth += SZ_INT;
- const m_bool ret = _scan2_func_def(env, f);
+ const m_bool ret = scanx_fdef(env, env, f, (_exp_func)scan2_fdef);
if(GET_FLAG(f, global))
env_pop(env, scope);
return ret;
nspc_pop_type(env->gwion->mp, env->curr);
return ret;
}
+
+ANN m_bool scanx_fdef(const Env env, void *data,
+ const Func_Def fdef, const _exp_func func) {
+ if(fdef->base->tmpl)
+ CHECK_BB(template_push_types(env, fdef->base->tmpl))
+ const m_bool ret = func(data, fdef);
+ if(fdef->base->tmpl)
+ nspc_pop_type(env->gwion->mp, env->curr);
+ return ret;
+}