From: Jérémie Astor Date: Tue, 22 Dec 2020 02:08:55 +0000 (+0100) Subject: :art: Warn about late X-Git-Tag: nightly~1078 X-Git-Url: http://10.10.0.4:5575/?a=commitdiff_plain;h=ac32502d88bb62f99776dece0dca849cb578cac7;p=gwion.git :art: Warn about late --- diff --git a/include/env/env.h b/include/env/env.h index 4a6668f0..ef51d6bc 100644 --- a/include/env/env.h +++ b/include/env/env.h @@ -43,7 +43,8 @@ ANN void env_add_type(const Env, const Type); ANN Type find_type(const Env, Type_Decl*); ANN m_bool already_defined(const Env env, const Symbol s, const loc_t pos); ANN m_bool traverse_func_template(const Env, const Func_Def); -ANN2(1,3) void env_err(const Env, const loc_t pos, const m_str fmt, ...); +ANN void env_err(const Env, const loc_t pos, const m_str fmt, ...); +ANN void env_warn(const Env, const loc_t pos, const m_str fmt, ...); ANN Value global_string(const Env env, const m_str str); ANN void release_ctx(struct Env_Scope_ *a, struct Gwion_* gwion); #endif diff --git a/src/emit/emit.c b/src/emit/emit.c index c7025c75..14afb8f2 100644 --- a/src/emit/emit.c +++ b/src/emit/emit.c @@ -813,7 +813,7 @@ ANN static m_bool emit_exp_decl_global(const Emitter emit, const Exp_Decl *decl, set_vflag(v, vflag_direct);// mpalloc instr->m_val = (m_uint)v->d.ptr; instr->m_val2 = v->type->size; - if(is_obj && (is_array || !is_ref)) { + if(is_obj && (is_array || !is_ref || emit_addr)) { const Instr assign = emit_add_instr(emit, Assign); assign->m_val = emit_var; /* @@ -847,12 +847,17 @@ ANN static m_bool emit_decl(const Emitter emit, const Exp_Decl* decl) { const uint ref = GET_FLAG(decl->td, late) || type_ref(decl->type); Var_Decl_List list = decl->list; do { + const Value v = list->self->value; + const uint r = ref || GET_FLAG(v, late); if(GET_FLAG(decl->td, static)) - CHECK_BB(emit_exp_decl_static(emit, decl, list->self, ref, var)) + CHECK_BB(emit_exp_decl_static(emit, decl, list->self, r, var)) else if(!global) - CHECK_BB(emit_exp_decl_non_static(emit, decl, list->self, ref, var)) + CHECK_BB(emit_exp_decl_non_static(emit, decl, list->self, r, var)) else - CHECK_BB(emit_exp_decl_global(emit, decl, list->self, ref, var)) + CHECK_BB(emit_exp_decl_global(emit, decl, list->self, r, var)) + if(GET_FLAG(v->type, abstract) && !GET_FLAG(decl->td, late) && GET_FLAG(v, late)) { + env_warn(emit->env, decl->td->pos, _("Type '%s' is abstract, use late"), v->type->name); + } } while((list = list->next)); return GW_OK; } @@ -863,6 +868,7 @@ ANN /*static */m_bool emit_exp_decl(const Emitter emit, const Exp_Decl* decl) { const m_bool global = GET_FLAG(decl->td, global); const m_uint scope = !global ? emit->env->scope->depth : emit_push_global(emit); const m_bool ret = emit_decl(emit, decl); + if(global) emit_pop(emit, scope); return ret; diff --git a/src/gwion.c b/src/gwion.c index a1b6798f..89f1a653 100644 --- a/src/gwion.c +++ b/src/gwion.c @@ -145,18 +145,33 @@ ANN static void env_header(const Env env) { gw_err(_("in function: '%s'\n"), env->func->name); } +ANN static void env_xxx(const Env env, const loc_t pos, const m_str fmt, va_list arg) { +#ifndef __FUZZING__ + env_header(env); + loc_header(pos, env->name); + vfprintf(stderr, fmt, arg); + fprintf(stderr, "\n"); + loc_err(pos, env->name); +#endif +} + +ANN void env_warn(const Env env, const loc_t pos, const m_str fmt, ...) { +#ifndef __FUZZING__ + va_list arg; + va_start(arg, fmt); + env_xxx(env, pos, fmt, arg); + va_end(arg); +#endif +} + ANN void env_err(const Env env, const loc_t pos, const m_str fmt, ...) { if(env->context && env->context->error) return; #ifndef __FUZZING__ - env_header(env); - loc_header(pos, env->name); va_list arg; va_start(arg, fmt); - vfprintf(stderr, fmt, arg); + env_xxx(env, pos, fmt, arg); va_end(arg); - fprintf(stderr, "\n"); - loc_err(pos, env->name); #endif if(env->context) env->context->error = 1; diff --git a/src/lib/object_op.c b/src/lib/object_op.c index 932f87a3..3f71c388 100644 --- a/src/lib/object_op.c +++ b/src/lib/object_op.c @@ -34,7 +34,7 @@ static OP_CHECK(at_object) { if(opck_rassign(env, data) == env->gwion->type[et_error]) return env->gwion->type[et_error]; if(bin->rhs->exp_type == ae_exp_decl) - SET_FLAG(bin->rhs->d.exp_decl.td, late); // ??? + SET_FLAG(bin->rhs->d.exp_decl.list->self->value, late); exp_setvar(bin->rhs, 1); CHECK_BN(isa(bin->lhs->type , bin->rhs->type)) return bin->rhs->type; diff --git a/src/parse/check.c b/src/parse/check.c index 0562f8bf..c6f78665 100644 --- a/src/parse/check.c +++ b/src/parse/check.c @@ -121,9 +121,8 @@ ANN static m_bool check_var_td(const Env env, const Var_Decl var, Type_Decl *con } ANN static void set_late(const Gwion gwion, const Exp_Decl *decl, const Value v) { - if(!exp_getvar(exp_self(decl)) && - (GET_FLAG(decl->td, late) || is_fptr(gwion, v->type))) { - SET_FLAG(decl->td, late); + if(!exp_getvar(exp_self(decl)) && (GET_FLAG(v->type, abstract) || + GET_FLAG(decl->td, late) || is_fptr(gwion, v->type))) { SET_FLAG(v, late); } else UNSET_FLAG(v, late); diff --git a/src/parse/scan1.c b/src/parse/scan1.c index be1bb5d7..7b83102d 100644 --- a/src/parse/scan1.c +++ b/src/parse/scan1.c @@ -85,9 +85,6 @@ ANN static m_bool scan1_decl(const Env env, const Exp_Decl* decl) { if(var->array->exp) CHECK_BB(scan1_exp(env, var->array->exp)) t = array_type(env, decl->type, var->array->depth); - } else if(GET_FLAG(t, abstract) && !GET_FLAG(decl->td, late)) { - // ERR_B(var->pos, "Type '%s' is abstract, use late", t->name) - SET_FLAG(decl->td, late); } const Value v = var->value = var->value ?: new_value(env->gwion->mp, t, s_name(var->xid)); // rewrite logic @@ -98,10 +95,12 @@ ANN static m_bool scan1_decl(const Env env, const Exp_Decl* decl) { env->class_def->size += t->size; } nspc_add_value(env->curr, var->xid, v); - v->flag |= decl->td->flag; + if(GET_FLAG(t, abstract) && !GET_FLAG(decl->td, late)) + SET_FLAG(v, late); v->type = t; if(array_ref(var->array)) SET_FLAG(decl->td, late); + v->flag |= decl->td->flag; if(env->class_def) { if(env->class_def->info->tuple) tuple_contains(env, v); @@ -127,7 +126,7 @@ ANN m_bool scan1_exp_decl(const Env env, const Exp_Decl* decl) { CHECK_BB(env_storage(env, decl->td->flag, exp_self(decl)->pos)) ((Exp_Decl*)decl)->type = scan1_exp_decl_type(env, (Exp_Decl*)decl); if(array_ref(decl->td->array)) - SET_FLAG(decl->td, late); + SET_FLAG(decl->td, late); CHECK_OB(decl->type) const m_bool global = GET_FLAG(decl->td, global); if(global) {