From fd0e0141c26e9ccb56f3c07afcd6eb99fb7e30a8 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=A9mie=20Astor?= Date: Wed, 3 Jun 2020 15:04:53 +0200 Subject: [PATCH] :art: Improve type_checking --- src/emit/emit.c | 30 +++++++++++++++++------------- src/parse/check.c | 1 + 2 files changed, 18 insertions(+), 13 deletions(-) diff --git a/src/emit/emit.c b/src/emit/emit.c index 5940ff3a..35310790 100644 --- a/src/emit/emit.c +++ b/src/emit/emit.c @@ -227,6 +227,7 @@ ANEW ANN static ArrayInfo* new_arrayinfo(const Emitter emit, const Type t) { ANN static inline void arrayinfo_ctor(const Emitter emit, ArrayInfo *info) { const Type base = info->base; +// TODO: needed for coumpund? if(isa(base, emit->gwion->type[et_object]) > 0 && !GET_FLAG(base, abstract)) { emit_pre_constructor_array(emit, base); info->is_obj = 1; @@ -597,11 +598,11 @@ ANN static void decl_expand(const Emitter emit, const Type t) { } ANN static void emit_struct_decl_finish(const Emitter emit, const Type t, const uint emit_addr) { - emit->code->frame->curr_offset += t->size; - emit_ext_ctor(emit, t->nspc->pre_ctor); - if(!emit_addr) - decl_expand(emit, t); - emit->code->frame->curr_offset -= t->size; + emit->code->frame->curr_offset += t->size + SZ_INT; + emit_ext_ctor(emit, t->nspc->pre_ctor); + if(!emit_addr) + decl_expand(emit, t); + emit->code->frame->curr_offset -= t->size + SZ_INT; } ANN static m_bool emit_exp_decl_static(const Emitter emit, const Var_Decl var_decl, const uint is_ref, const uint emit_addr) { @@ -1068,14 +1069,17 @@ ANN Instr emit_exp_call1(const Emitter emit, const Func f) { const Instr instr = emit_add_instr(emit, (f_instr)(m_uint)exec); instr->m_val = val; instr->m_val2 = val2; - } else if(f->value_ref->from->owner_class && f != emit->env->func && !f->code&& ! is_fptr(emit->gwion, f->value_ref->type)){ + } else if(f != emit->env->func && !f->code&& ! is_fptr(emit->gwion, f->value_ref->type)){ /* not yet emitted static func */ - const Instr instr = vector_size(&emit->code->instr) ? - (Instr)vector_back(&emit->code->instr) : emit_add_instr(emit, PushStaticCode); - assert(instr->opcode == ePushStaticCode); - instr->opcode = eRegPushImm; - const Instr pushcode = emit_add_instr(emit, PushStaticCode); - pushcode->m_val = (m_uint)f; + if(f->value_ref->from->owner_class) { + const Instr instr = vector_size(&emit->code->instr) ? + (Instr)vector_back(&emit->code->instr) : emit_add_instr(emit, PushStaticCode); + assert(instr->opcode == ePushStaticCode); + instr->opcode = eRegPushImm; + } else { + const Instr pushcode = emit_add_instr(emit, PushStaticCode); + pushcode->m_val = (m_uint)f; + } } const m_uint offset = emit_code_offset(emit); regseti(emit, offset); @@ -1963,12 +1967,12 @@ ANN static m_bool emit_func_def(const Emitter emit, const Func_Def f) { return GW_OK; if(SAFE_FLAG(emit->env->class_def, builtin) && GET_FLAG(emit->env->class_def, template)) return GW_OK; + // TODO: we might not need lambdas here if(!emit->env->class_def && !GET_FLAG(fdef, global) && !fdef->base->tmpl && !emit->env->scope->depth) func->value_ref->from->offset = emit_local(emit, emit->gwion->type[et_int]); emit_func_def_init(emit, func); if(GET_FLAG(func, member)) stack_alloc_this(emit); - emit->env->func = func; emit_push_scope(emit); if(!strcmp(s_name(fdef->base->xid), "@gack")) { diff --git a/src/parse/check.c b/src/parse/check.c index 83910ce8..14ddbe3d 100644 --- a/src/parse/check.c +++ b/src/parse/check.c @@ -510,6 +510,7 @@ ANN static m_bool check_func_args(const Env env, Arg_List arg_list) { const Value v = decl->value; if(arg_list->td && !arg_list->td->xid) CHECK_OB((arg_list->type = v->type = check_td(env, arg_list->td))) +// TODO: use coumpound instead of object? if(isa(v->type, env->gwion->type[et_object]) > 0 || isa(v->type, env->gwion->type[et_function]) > 0) UNSET_FLAG(env->func, pure); CHECK_BB(already_defined(env, decl->xid, decl->pos)) -- 2.43.0