From: Jérémie Astor Date: Sat, 12 Jun 2021 16:55:04 +0000 (+0200) Subject: :bug: Fix enum import fail X-Git-Tag: nightly~603 X-Git-Url: http://10.10.0.4:5575/?a=commitdiff_plain;h=6676132df53fecc35afa417a8028adcfc5c1f51b;p=gwion.git :bug: Fix enum import fail --- diff --git a/include/instr.h b/include/instr.h index b084ce4a..e31356e3 100644 --- a/include/instr.h +++ b/include/instr.h @@ -19,13 +19,22 @@ enum Kind { typedef struct Instr_ * Instr; typedef void (*f_instr)(const VM_Shred, const Instr); + +struct InstrVal { + uint16_t one; + uint16_t two; +}; + struct Instr_ { m_uint opcode; union { m_float f; m_uint m_val; }; - m_uint m_val2; + union { + m_uint m_val2; + struct InstrVal udata; + }; void (*execute)(const VM_Shred shred, const Instr instr); }; #define BYTECODE_SZ ((2*sizeof(unsigned)) + sizeof(struct Instr_) - SZ_INT*2) diff --git a/src/import/import_enum.c b/src/import/import_enum.c index 87a84f9e..d1922c92 100644 --- a/src/import/import_enum.c +++ b/src/import/import_enum.c @@ -82,7 +82,8 @@ ANN Type gwi_enum_end(const Gwi gwi) { gwi->ck->xid, gwi->loc); gwi->ck->tmpl = NULL; const m_bool ret = traverse_enum_def(gwion->env, edef); - import_enum_end(gwi, &edef->values); + if(ret > 0) + import_enum_end(gwi, &edef->values); if(gwi->gwion->data->cdoc) { lint_indent(gwi->lint); lint_enum_def(gwi->lint, edef); diff --git a/src/lib/array.c b/src/lib/array.c index a6875bdb..344f1f2c 100644 --- a/src/lib/array.c +++ b/src/lib/array.c @@ -636,8 +636,18 @@ static OP_CHECK(opck_array_scan) { struct TemplateScan *ts = (struct TemplateScan*)data; const Type t_array = env->gwion->type[et_array]; const Class_Def c = t_array->info->cdef; - const Type base = ts->t != t_array ? - ts->t : known_type(env, ts->td->types->td); + DECL_ON(const Type, base, = ts->t != t_array ? + ts->t : known_type(env, ts->td->types->td)); + if(!strncmp(base->name, "Ref:[", 5)) { + gwerr_basic("Can't use ref types as array base", NULL, NULL, "/dev/null", (loc_t){}, 0); + env->context->error = true; + return env->gwion->type[et_error]; + } + if(!strncmp(base->name, "Option:[", 5)) { + gwerr_basic("Can't use option types as array base", NULL, NULL, "/dev/null", (loc_t){}, 0); + env->context->error = true; + return env->gwion->type[et_error]; + } const Symbol sym = array_sym(env, array_base(base), base->array_depth + 1); const Type type = nspc_lookup_type1(base->info->value->from->owner, sym); if(type) @@ -722,7 +732,8 @@ GWION_IMPORT(array) { prepare_map_run(count_byte, count_run_end); prepare_fold_run(foldl_byte, foldl_run_ini); prepare_fold_run(foldr_byte, foldr_run_ini); - const Type t_array = gwi_class_ini(gwi, "Array:[T]", "Object"); + const Type t_array = gwi_class_ini(gwi, "@Array:[T]", "Object"); + set_tflag(t_array, tflag_infer); gwi->gwion->type[et_array] = t_array; gwi_class_xtor(gwi, NULL, array_dtor); GWI_BB(gwi_item_ini(gwi, "@internal", "@array")) @@ -796,31 +807,31 @@ GWION_IMPORT(array) { GWI_BB(gwi_class_end(gwi)) - GWI_BB(gwi_oper_ini(gwi, "Array", "Array", NULL)) + GWI_BB(gwi_oper_ini(gwi, "@Array", "@Array", NULL)) GWI_BB(gwi_oper_add(gwi, opck_array_at)) GWI_BB(gwi_oper_end(gwi, "=>", NULL)) GWI_BB(gwi_oper_add(gwi, opck_array_implicit)) GWI_BB(gwi_oper_end(gwi, "@implicit", NULL)) - GWI_BB(gwi_oper_ini(gwi, "Array", (m_str)OP_ANY_TYPE, NULL)) + GWI_BB(gwi_oper_ini(gwi, "@Array", (m_str)OP_ANY_TYPE, NULL)) GWI_BB(gwi_oper_add(gwi, opck_array_sl)) GWI_BB(gwi_oper_emi(gwi, opem_array_sl)) GWI_BB(gwi_oper_end(gwi, "<<", NULL)) - GWI_BB(gwi_oper_ini(gwi, (m_str)OP_ANY_TYPE, "Array", NULL)) + GWI_BB(gwi_oper_ini(gwi, (m_str)OP_ANY_TYPE, "@Array", NULL)) GWI_BB(gwi_oper_add(gwi, opck_array_sr)) GWI_BB(gwi_oper_emi(gwi, opem_array_sr)) GWI_BB(gwi_oper_end(gwi, ">>", NULL)) - GWI_BB(gwi_oper_ini(gwi, "Array", "Array", NULL)) + GWI_BB(gwi_oper_ini(gwi, "@Array", "@Array", NULL)) GWI_BB(gwi_oper_add(gwi, opck_array_cast)) GWI_BB(gwi_oper_end(gwi, "$", NULL)) - GWI_BB(gwi_oper_ini(gwi, "int", "Array", "int")) + GWI_BB(gwi_oper_ini(gwi, "int", "@Array", "int")) 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, "int", "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)) GWI_BB(gwi_oper_end(gwi, "@array", NULL)) - GWI_BB(gwi_oper_ini(gwi, "Array", NULL, NULL)) + GWI_BB(gwi_oper_ini(gwi, "@Array", NULL, NULL)) GWI_BB(gwi_oper_add(gwi, opck_array_scan)) GWI_BB(gwi_oper_end(gwi, "@scan", NULL)) gwi_register_freearg(gwi, ArrayAlloc, freearg_array); diff --git a/src/parse/check.c b/src/parse/check.c index 63d9b558..022a6eae 100644 --- a/src/parse/check.c +++ b/src/parse/check.c @@ -470,13 +470,15 @@ ANN2(1,2) static Func find_func_match_actual(const Env env, Func func, const Exp Exp e = args; Arg_List e1 = func->def->base->args; while(e) { + if(!strncmp(e->type->name, "Ref:[", 5)) + exp_setvar(e, true); if(!e1) { if(fbflag(func->def->base, fbflag_variadic)) return func; CHECK_OO(func->next); return find_func_match_actual(env, func->next, args, implicit, specific); - } else if(!e->type) //fix bug found with Cytosol - return NULL; + } //else if(!e->type) //fix bug found with Cytosol + //return NULL; if(e1->type == env->gwion->type[et_auto] || (func->def->base->tmpl && is_fptr(env->gwion, func->value_ref->type) > 0)) { const Type owner = func->value_ref->from->owner_class; @@ -1705,7 +1707,8 @@ ANN static m_bool _check_class_def(const Env env, const Class_Def cdef) { Value v; struct scope_iter inner = { value->type->nspc->info->value, 0, 0 }; while(scope_iter(&inner, &v) > 0) { - if(isa(v->type, t) > 0 || isa(t, v->type) > 0) { +// if(isa(v->type, t) > 0 || isa(t, v->type) > 0) { + if(v->type == t) { env_err(env, v->from->loc, _("recursive type")); env->context->error = false; env_err(env, value->from->loc, _("recursive type")); diff --git a/src/vm/vm_code.c b/src/vm/vm_code.c index 8deb304d..14b267e3 100644 --- a/src/vm/vm_code.c +++ b/src/vm/vm_code.c @@ -142,7 +142,7 @@ ANN static m_bit* tobytecode(MemPool p, const VM_Code code) { } *(m_uint*)(data + SZ_INT) = new_pc; } else if(opcode == eRecurs /*|| opcode == eSetCode*/) { - *(m_uint*)(final + j * BYTECODE_SZ + SZ_INT*2) = + *(uint16_t*)(final + j * BYTECODE_SZ + SZ_INT*2) = instr->m_val2 += j+1; } setpc(data, j);