From 7020c5e2121791d43b097961cf24384ffdbb6972 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=A9mie=20Astor?= Date: Wed, 16 Dec 2020 17:28:31 +0100 Subject: [PATCH] :art: Improve late checking --- src/emit/emit.c | 4 ++++ src/lib/array.c | 13 +------------ src/lib/object_op.c | 3 +-- src/parse/check.c | 3 --- src/parse/scan1.c | 10 ++-------- src/vm/vm.c | 2 +- tests/error/array_excess.gw | 3 --- 7 files changed, 9 insertions(+), 29 deletions(-) delete mode 100644 tests/error/array_excess.gw diff --git a/src/emit/emit.c b/src/emit/emit.c index 577fef59..9d584aa3 100644 --- a/src/emit/emit.c +++ b/src/emit/emit.c @@ -541,6 +541,10 @@ ANN m_bool emit_array_access(const Emitter emit, struct ArrayAccessInfo *const i // look mum no pos struct Op_Import opi = { .op=insert_symbol("@array"), .lhs=info->array.exp->info->type, .rhs=info->array.type, .data=(uintptr_t)info, .op_type=op_array }; + if(type_ref(info->array.type)) { + const Instr instr = emit_add_instr(emit, GWOP_EXCEPT); + instr->m_val = -SZ_INT; + } return op_emit(emit, &opi); } diff --git a/src/lib/array.c b/src/lib/array.c index af6d4301..d9b1e205 100644 --- a/src/lib/array.c +++ b/src/lib/array.c @@ -332,15 +332,7 @@ static OP_CHECK(opck_array) { return array_type(env, array_base(t), t->array_depth - array->depth); const Exp curr = take_exp(array->exp, t->array_depth); struct Array_Sub_ next = { curr->next, array_base(t), array->depth - t->array_depth }; - return check_array_access(env, &next); -} - -static OP_CHECK(opck_not_array) { - const Array_Sub array = (Array_Sub)data; - if(array->depth <= get_depth(array->type)) - return array->type; - ERR_N(array->exp->pos, _("array subscripts (%"UINT_F") exceeds defined dimension (%"UINT_F")"), - array->depth, get_depth(array->type)) + return check_array_access(env, &next) ?: env->gwion->type[et_error]; } ANN static void array_loop(const Emitter emit, const m_uint depth) { @@ -440,9 +432,6 @@ GWION_IMPORT(array) { GWI_BB(gwi_oper_add(gwi, opck_array_slice)) GWI_BB(gwi_oper_emi(gwi, opem_array_slice)) GWI_BB(gwi_oper_end(gwi, "@slice", NULL)) - GWI_BB(gwi_oper_ini(gwi, (m_str)OP_ANY_TYPE, (m_str)OP_ANY_TYPE, NULL)) - GWI_BB(gwi_oper_add(gwi, opck_not_array)) - GWI_BB(gwi_oper_end(gwi, "@array", NULL)) GWI_BB(gwi_oper_ini(gwi, "int", "@Array", NULL)) GWI_BB(gwi_oper_add(gwi, opck_array)) GWI_BB(gwi_oper_emi(gwi, opem_array_access)) diff --git a/src/lib/object_op.c b/src/lib/object_op.c index 48bcea55..7d2a0a35 100644 --- a/src/lib/object_op.c +++ b/src/lib/object_op.c @@ -206,8 +206,7 @@ OP_EMIT(opem_object_dot) { } if(GET_FLAG(value, late) && !exp_getvar(exp_self(member))) { const Instr instr = emit_add_instr(emit, GWOP_EXCEPT); - if(!is_fptr(emit->gwion, value->type)) - instr->m_val = -SZ_INT; + instr->m_val = -SZ_INT; } return GW_OK; } diff --git a/src/parse/check.c b/src/parse/check.c index 27aa1254..5f0ad35f 100644 --- a/src/parse/check.c +++ b/src/parse/check.c @@ -393,9 +393,6 @@ ANN static Type check_prim(const Env env, Exp_Primary *prim) { } ANN Type check_array_access(const Env env, const Array_Sub array) { -// if(!get_depth(array->type)) -// ERR_O(array->exp->pos, _("array subscripts (%"UINT_F") exceeds defined dimension (%"UINT_F")"), -// array->depth, get_depth(array->type)) const Symbol sym = insert_symbol("@array"); struct Op_Import opi = { .op=sym, .lhs=array->exp->info->type, .rhs=array->type, .pos=array->exp->pos, .data=(uintptr_t)array, .op_type=op_array }; diff --git a/src/parse/scan1.c b/src/parse/scan1.c index d00d7064..44699f98 100644 --- a/src/parse/scan1.c +++ b/src/parse/scan1.c @@ -85,14 +85,8 @@ 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)) { - if(!(t == env->class_def && env->scope->depth)) { -// if(decl->td->xid == insert_symbol("auto")) - SET_FLAG(decl->td, late); -// else -// ERR_B(exp_self(decl)->pos, _("Type '%s' is abstract, declare as ref. (use @)"), t->name) - } - } + } else if(GET_FLAG(t, abstract) && !GET_FLAG(decl->td, late)) + SET_FLAG(decl->td, late); const Value v = var->value = var->value ?: new_value(env->gwion->mp, t, s_name(var->xid)); // rewrite logic if(!env->scope->depth && env->class_def && !GET_FLAG(decl->td, static)) diff --git a/src/vm/vm.c b/src/vm/vm.c index f938223a..45dc6e37 100644 --- a/src/vm/vm.c +++ b/src/vm/vm.c @@ -797,7 +797,7 @@ except: * VAL = offset (no default SZ_INT) * * VAL2 = error message * * grep for GWOP_EXCEPT and Except, exception... */ - if(!*(void**)(reg-(m_int)VAL)) { + if(!*(m_bit**)(reg+(m_int)(VAL))) { shred->pc = PC; exception(shred, "NullPtrException"); continue; diff --git a/tests/error/array_excess.gw b/tests/error/array_excess.gw deleted file mode 100644 index 2c0a00f4..00000000 --- a/tests/error/array_excess.gw +++ /dev/null @@ -1,3 +0,0 @@ -#! [contains] exceeds defined dimension -var int i[2]; -i[0][0]; -- 2.43.0