From 1a4c46769bd683140f0861b138f21170356e0a49 Mon Sep 17 00:00:00 2001 From: fennecdjay Date: Sun, 9 Jun 2019 22:53:46 +0200 Subject: [PATCH] :art: More on Fptr --- include/type.h | 4 ++++ src/emit/emit.c | 11 ++++++----- src/parse/check.c | 5 ++--- src/parse/func.c | 2 +- src/parse/scan2.c | 2 +- 5 files changed, 14 insertions(+), 10 deletions(-) diff --git a/include/type.h b/include/type.h index 02b4c831..a1c11a73 100644 --- a/include/type.h +++ b/include/type.h @@ -47,5 +47,9 @@ static inline Type actual_type(const Type t) { return isa(t, t_class) > 0 ? t->e->d.base_type : t; } ANN static inline m_uint env_push_type(const Env env, const Type type) { return env_push(env, type, type->nspc); } +ANN static inline m_bool is_fptr(const Type t) { + return isa(actual_type(t), t_fptr) > 0; +} + #endif diff --git a/src/emit/emit.c b/src/emit/emit.c index 644a8546..0497ef8f 100644 --- a/src/emit/emit.c +++ b/src/emit/emit.c @@ -689,7 +689,7 @@ ANN static m_bool prepare_call(const Emitter emit, const Exp_Call* exp_call) { ANN static inline m_int push_tmpl_func(const Emitter emit, const Func f) { const Value v = f->value_ref; if(isa(v->type, t_class) > 0 && - isa(actual_type(v->type), t_fptr) > 0) + is_fptr(v->type)) return emit->env->scope->depth; const m_uint scope = emit_push(emit, v->owner_class, v->owner); CHECK_BB(traverse_func_template(emit->env, f->def)) @@ -702,7 +702,8 @@ ANN static m_bool emit_exp_call_template(const Emitter emit, const Exp_Call* exp exp_call->m_func->def->base->tmpl->call = exp_call->tmpl->call; DECL_BB(const m_int,scope, = push_tmpl_func(emit, exp_call->m_func)) CHECK_BB(prepare_call(emit, exp_call)) - emit_pop_type(emit); + if(!is_fptr(exp_call->m_func->value_ref->type)) + emit_pop_type(emit); emit_pop(emit, (m_uint)scope); UNSET_FLAG(exp_call->m_func, checked); return GW_OK; @@ -863,7 +864,7 @@ ANN static Instr emit_call(const Emitter emit, const Func f) { ANN m_bool emit_exp_call1(const Emitter emit, const Func f) { if(!f->code || (GET_FLAG(f, ref) && !GET_FLAG(f, builtin))) { - if(GET_FLAG(f, template) && emit->env->func != f && isa(actual_type(f->value_ref->type), t_fptr) < 0) + if(GET_FLAG(f, template) && emit->env->func != f && !is_fptr(f->value_ref->type)) CHECK_BB(emit_template_code(emit, f)) } else if((f->value_ref->owner_class && is_special(f->value_ref->owner_class) > 0) || !f->value_ref->owner_class || (GET_FLAG(f, template) && @@ -875,7 +876,7 @@ ANN m_bool emit_exp_call1(const Emitter emit, const Func f) { back->m_val = f->vt_index; } if(vector_size(&emit->code->instr) && GET_FLAG(f, member) && - isa(actual_type(f->value_ref->type), t_fptr) > 0) { + is_fptr(f->value_ref->type)) { const Instr back = (Instr)vector_back(&emit->code->instr); m_bit exec = back->opcode; m_uint val = back->m_val; @@ -970,7 +971,7 @@ ANN m_bool emit_exp_spork(const Emitter emit, const Exp_Unary* unary) { const Instr spork = emit_add_instr(emit, is_spork ? SporkExp : ForkEnd); spork->m_val = emit->code->stack_depth; } else { - if(GET_FLAG(f, member) && isa(actual_type(f->value_ref->type), t_fptr) > 0) { + if(GET_FLAG(f, member) && is_fptr(f->value_ref->type)) { const m_uint depth = f->def->stack_depth; regpop(emit, depth); emit_add_instr(emit, RegPushMem); diff --git a/src/parse/check.c b/src/parse/check.c index b4d55755..511e6f6d 100644 --- a/src/parse/check.c +++ b/src/parse/check.c @@ -442,7 +442,7 @@ ANN static Func _find_template_match(const Env env, const Value v, const Exp_Cal Func m_func = NULL, former = env->func; const m_str tmpl_name = tl2str(env, types); const m_uint scope = env_push(env, v->owner_class, v->owner); - if(isa(actual_type(v->type), t_fptr) > 0) { + if(is_fptr(v->type)) { const Symbol sym = func_symbol(env, v->owner->name, v->name, tmpl_name, 0); const Value value = nspc_lookup_value1(v->owner, sym); Func_Def base = v->d.func_ref->def; @@ -462,10 +462,9 @@ ANN static Func _find_template_match(const Env env, const Value v, const Exp_Cal if(exp->args) CHECK_OO(check_exp(env, exp->args)) const Func func = find_func_match(env, fbase->func, exp->args); - // nspc_pop_type(env->gwion->mp, env->curr); - // env_pop(env, scope); if(!value) map_set(&v->owner->info->type->map, (vtype)sym, (vtype)actual_type(func->value_ref->type)); + nspc_pop_type(env->gwion->mp, env->curr); xfree(tmpl_name); env->func = former; return func; diff --git a/src/parse/func.c b/src/parse/func.c index 13127df2..ec76499e 100644 --- a/src/parse/func.c +++ b/src/parse/func.c @@ -11,7 +11,7 @@ #include "value.h" ANN static void free_func(Func a, Gwion gwion) { - if(GET_FLAG(a, template) && isa(actual_type(a->value_ref->type), t_fptr) < 0) { + if(GET_FLAG(a, template) && !is_fptr(a->value_ref->type)) { free_tmpl(gwion->mp, a->def->base->tmpl); free_func_base(gwion->mp, a->def->base); free_loc(gwion->mp, a->def->pos); diff --git a/src/parse/scan2.c b/src/parse/scan2.c index 02af3dbf..b5b6e890 100644 --- a/src/parse/scan2.c +++ b/src/parse/scan2.c @@ -110,7 +110,7 @@ ANN m_bool scan2_stmt_fptr(const Env env, const Stmt_Fptr ptr) { ptr->value->owner_class = env->class_def; } if(ptr->base->tmpl) - SET_FLAG(ptr->base->func, template); + SET_FLAG(ptr->type, func); nspc_add_value(env->curr, ptr->base->xid, ptr->value); nspc_add_func(ptr->type->e->owner, ptr->base->xid, ptr->base->func); return GW_OK; -- 2.43.0