From: fennecdjay Date: Fri, 3 May 2024 02:26:47 +0000 (+0200) Subject: index on master: e523855b :art: fix class const generics X-Git-Tag: nightly~19^2 X-Git-Url: http://10.10.0.4:5575/?a=commitdiff_plain;h=1f8323e558833b51acb00b4d0a0a57b8636b83c7;p=gwion.git index on master: e523855b :art: fix class const generics --- diff --git a/src/env/env_utils.c b/src/env/env_utils.c index 4c59b492..8860af6a 100644 --- a/src/env/env_utils.c +++ b/src/env/env_utils.c @@ -59,8 +59,20 @@ ANN Type find_type(const Env env, Type_Decl *td) { while ((td = td->next) && type && type->nspc) { const Nspc nspc = type->nspc; if(!(type = find_in_parent(type, td->tag.sym))) + ERR_O(td->tag.loc, _("...(cannot find class '%s' in nspc '%s')"), +s_name(td->tag.sym), nspc->name); + +/* + if(!type) ERR_O(td->tag.loc, _("...(cannot find class '%s' in nspc '%s')"), s_name(td->tag.sym), nspc->name); + Type_Decl *next = td->next; + td->next = NULL; +env_push_type(env, type); + type = known_type(env, td); +env_pop(env, 0); // respect scope depth // use env scope + td->next = next; +*/ } return type; } diff --git a/src/import/import_checker.c b/src/import/import_checker.c index c552d696..5cfdee98 100644 --- a/src/import/import_checker.c +++ b/src/import/import_checker.c @@ -19,6 +19,11 @@ struct td_checker { m_str str; const loc_t loc; }; +ANN static void eat_space(struct td_checker *tdc) { + while(isspace(*tdc->str)) { + tdc->str++; + } +} struct AC { m_str str; @@ -79,23 +84,35 @@ ANN bool str2var(const Gwion gwion, Var_Decl *vd, const m_str path, const loc_t vd->value = NULL; return true; } - +ANN static Type_Decl *_str2td(const Gwion, struct td_checker *tdc); #define ARG_ERROR (Arg_List) -1 #define SPEC_ERROR (Specialized_List) -1 #define TMPLARG_ERROR (TmplArg_List) -1 ANN static bool _tmpl_list(const Gwion gwion, struct td_checker *tdc, Specialized_List *sl) { + eat_space(tdc); if(unlikely(!strncmp(tdc->str, "...", 3))) { tdc->str += 3; Specialized spec = { .tag = MK_TAG(insert_symbol(gwion->st, "..."), tdc->loc) }; mp_vector_add(gwion->mp, sl, Specialized, spec); return true; } - DECL_O(const Symbol, sym, = __str2sym(gwion, tdc)); - // TODO: handle traits? - Specialized spec = { .tag = MK_TAG(sym, tdc->loc) }; - mp_vector_add(gwion->mp, sl, Specialized, spec); + if(unlikely(!strncmp(tdc->str, "const ", 6))) { + tdc->str += 6; + // eat space? + eat_space(tdc); + Type_Decl *td = _str2td(gwion, tdc); + eat_space(tdc); + DECL_O(const Symbol, sym, = __str2sym(gwion, tdc)); + Specialized spec = { .td = td, .tag = MK_TAG(sym, tdc->loc) }; + mp_vector_add(gwion->mp, sl, Specialized, spec); + } else { + DECL_O(const Symbol, sym, = __str2sym(gwion, tdc)); + // TODO: handle traits? + Specialized spec = { .tag = MK_TAG(sym, tdc->loc) }; + mp_vector_add(gwion->mp, sl, Specialized, spec); + } if (*tdc->str == ',') { ++tdc->str; if (!_tmpl_list(gwion, tdc, sl)) @@ -142,7 +159,7 @@ ANN bool str2tl(const Gwion gwion, struct td_checker *tdc, TmplArg_List *tl) { if (!str2tl(gwion, tdc, tl)) return false; } - } else GWION_ERR_B(tdc->loc, "invalid character in template list"); + } else GWION_ERR_B(tdc->loc, "invalid character %c in template list", *tdc->str); return true; } @@ -264,7 +281,11 @@ ANN static Type_Decl *_str2td(const Gwion gwion, struct td_checker *tdc) { return td; } +#include "gwion_parse.h" ANN Type_Decl *str2td(const Gwion gwion, const m_str str, const loc_t loc) { + return gwion_parse_type_decl(gwion, str, loc); + + struct td_checker tdc = {.str = str, .loc = loc}; DECL_O(Type_Decl *, td, = _str2td(gwion, &tdc)); if(*tdc.str) { diff --git a/src/import/import_tdef.c b/src/import/import_tdef.c index f6e713d0..b26c3635 100644 --- a/src/import/import_tdef.c +++ b/src/import/import_tdef.c @@ -33,6 +33,16 @@ ANN Type gwi_typedef_end(const Gwi gwi, const ae_flag flag) { new_type_def(gwi->gwion->mp, td, gwi->ck->sym, gwi->loc); if (gwi->ck->when) tdef->when = gwi->ck->when; if (gwi->ck->tmpl) tdef->tmpl = gwi_tmpl(gwi); + + if (safe_tflag(gwi->gwion->env->class_def, tflag_tmpl)) { + Section section = MK_SECTION( + type, type_def, tdef, gwi->loc + ); + gwi_body(gwi, §ion); + ck_end(gwi); + return 1; + } + gwi->ck->td = NULL; gwi->ck->tmpl = NULL; const bool ret = traverse_type_def(gwi->gwion->env, tdef); diff --git a/src/lib/array.c b/src/lib/array.c index ad81b138..b547db6a 100644 --- a/src/lib/array.c +++ b/src/lib/array.c @@ -378,6 +378,7 @@ static OP_CHECK(opck_array) { const Array_Sub array = (Array_Sub)data; const Type t_int = env->gwion->type[et_int]; Exp* e = array->exp; + // FIX: we should only take up to *depth* expressions do CHECK_ON(check_implicit(env, e, t_int)); while ((e = e->next)); const Type t = get_array_type(array->type); diff --git a/src/lib/closure.c b/src/lib/closure.c index 54951c57..533c5f6b 100644 --- a/src/lib/closure.c +++ b/src/lib/closure.c @@ -723,34 +723,34 @@ static GACK(gack_function) { INTERP_PRINTF("%s", t->name); } GWION_IMPORT(func) { gwidoc(gwi, "the base of all functions."); - const Type t_function = gwi_mk_type(gwi, "function", SZ_INT, NULL); + const Type t_function = gwi_mk_type(gwi, "Function", SZ_INT, NULL); GWI_B(gwi_gack(gwi, t_function, gack_function)) GWI_B(gwi_set_global_type(gwi, t_function, et_function)) gwidoc(gwi, "the base of decayed operators."); - const Type t_op = gwi_mk_type(gwi, "operator", SZ_INT, "function"); + const Type t_op = gwi_mk_type(gwi, "Operator", SZ_INT, "Function"); GWI_B(gwi_set_global_type(gwi, t_op, et_op)) gwidoc(gwi, "the base of function pointers."); - const Type t_closure = gwi_class_ini(gwi, "funptr", "Object"); + const Type t_closure = gwi_class_ini(gwi, "Funptr", "Object"); t_closure->nspc->offset = SZ_INT*3; gwi_class_xtor(gwi, fptr_ctor, fptr_dtor); GWI_B(gwi_set_global_type(gwi, t_closure, et_closure)) GWI_B(gwi_func_ini(gwi, "void", "default")); GWI_B(gwi_func_end(gwi, fptr_default, ae_flag_none)); - gwi_class_end(gwi); - - GWI_B(gwi_oper_ini(gwi, "funptr", NULL, NULL)) + gwi_class_end(gwi) +; + GWI_B(gwi_oper_ini(gwi, "Funptr", NULL, NULL)) GWI_B(gwi_oper_add(gwi, opck_closure_scan)) GWI_B(gwi_oper_end(gwi, "class", NULL)) - GWI_B(gwi_oper_ini(gwi, (m_str)OP_ANY_TYPE, "function", NULL)) + GWI_B(gwi_oper_ini(gwi, (m_str)OP_ANY_TYPE, "Function", NULL)) GWI_B(gwi_oper_add(gwi, opck_func_call)) GWI_B(gwi_oper_end(gwi, "=>", NULL)) - GWI_B(gwi_oper_ini(gwi, (m_str)OP_ANY_TYPE, "funptr", NULL)) + GWI_B(gwi_oper_ini(gwi, (m_str)OP_ANY_TYPE, "Funptr", NULL)) GWI_B(gwi_oper_add(gwi, opck_fptr_call)) GWI_B(gwi_oper_end(gwi, "=>", NULL)) - GWI_B(gwi_oper_ini(gwi, "function", "funptr", NULL)) + GWI_B(gwi_oper_ini(gwi, "Function", "Funptr", NULL)) GWI_B(gwi_oper_add(gwi, opck_fptr_assign)) GWI_B(gwi_oper_emi(gwi, opem_fptr_assign)) GWI_B(gwi_oper_end(gwi, ":=>", NULL)) @@ -759,16 +759,16 @@ GWION_IMPORT(func) { GWI_B(gwi_oper_end(gwi, "@implicit", NULL)) GWI_B(gwi_oper_add(gwi, opck_fptr_cast)) GWI_B(gwi_oper_end(gwi, "$", NULL)) - GWI_B(gwi_oper_ini(gwi, "operator", "funptr", NULL)) + GWI_B(gwi_oper_ini(gwi, "Operator", "Funptr", NULL)) GWI_B(gwi_oper_add(gwi, opck_op_impl)) GWI_B(gwi_oper_emi(gwi, opem_op_impl)) GWI_B(gwi_oper_end(gwi, "@implicit", NULL)) GWI_B(gwi_oper_add(gwi, opck_op_cast)) GWI_B(gwi_oper_end(gwi, "$", NULL)) - GWI_B(gwi_oper_ini(gwi, "function", "function", NULL)) + GWI_B(gwi_oper_ini(gwi, "Function", "Function", NULL)) GWI_B(gwi_oper_add(gwi, opck_auto_fptr)) GWI_B(gwi_oper_end(gwi, ":=>", int_r_assign)) - GWI_B(gwi_oper_ini(gwi, "function", NULL, NULL)) + GWI_B(gwi_oper_ini(gwi, "Function", NULL, NULL)) GWI_B(gwi_oper_add(gwi, opck_func_partial)) GWI_B(gwi_oper_end(gwi, "@partial", NULL)) GWI_B(gwi_oper_ini(gwi, "Class", NULL, NULL)) diff --git a/src/lib/deep_equal.c b/src/lib/deep_equal.c index b60a682d..f442dd0b 100644 --- a/src/lib/deep_equal.c +++ b/src/lib/deep_equal.c @@ -247,7 +247,8 @@ GWION_IMPORT(deep_equal) { GWI_B(gwi_oper_emi(gwi, opem_deep_ne_any)) GWI_B(gwi_oper_end(gwi, "<>", NULL)) - GWI_B(gwi_oper_ini(gwi, "@Compound", "@Compound", "bool")) + //GWI_B(gwi_oper_ini(gwi, "@Compound", "@Compound", "bool")) + GWI_B(gwi_oper_ini(gwi, "Compound", "Compound", "bool")) gwidoc(gwi, "Deep Equality"); GWI_B(gwi_oper_add(gwi, opck_deep_equal)) diff --git a/src/lib/engine.c b/src/lib/engine.c index eb400aba..42e1aa02 100644 --- a/src/lib/engine.c +++ b/src/lib/engine.c @@ -107,7 +107,8 @@ ANN static bool import_core_libs(const Gwi gwi) { GWI_B(gwimport_enum(gwi)); - const Type t_compound = gwi_mk_type(gwi, "@Compound", SZ_INT, NULL); + //const Type t_compound = gwi_mk_type(gwi, "@Compound", SZ_INT, NULL); + const Type t_compound = gwi_mk_type(gwi, "Compound", SZ_INT, NULL); GWI_B(gwi_gack(gwi, t_compound, gack_compound)) GWI_B(gwi_set_global_type(gwi, t_compound, et_compound)) @@ -120,6 +121,7 @@ ANN static bool import_core_libs(const Gwi gwi) { GWI_B(gwimport_union(gwi)) GWI_B(gwimport_array(gwi)) + GWI_B(gwimport_vector(gwi)) GWI_B(gwimport_event(gwi)) GWI_B(gwimport_ugen(gwi)) GWI_B(gwimport_xork(gwi)) @@ -133,13 +135,14 @@ ANN static bool import_core_libs(const Gwi gwi) { GWI_B(gwimport_modules(gwi)) gwidoc(gwi, "allow member access."); - GWI_B(gwi_oper_ini(gwi, "@Compound", (m_str)OP_ANY_TYPE, NULL)) + //GWI_B(gwi_oper_ini(gwi, "@Compound", (m_str)OP_ANY_TYPE, NULL)) + GWI_B(gwi_oper_ini(gwi, "Compound", (m_str)OP_ANY_TYPE, NULL)) GWI_B(gwi_oper_add(gwi, opck_object_dot)) GWI_B(gwi_oper_emi(gwi, opem_object_dot)) GWI_B(gwi_oper_end(gwi, ".", NULL)) // allow const generics in functions - GWI_B(gwi_oper_ini(gwi, "function", (m_str)OP_ANY_TYPE, NULL)) + GWI_B(gwi_oper_ini(gwi, "Function", (m_str)OP_ANY_TYPE, NULL)) GWI_B(gwi_oper_add(gwi, opck_object_dot)) GWI_B(gwi_oper_emi(gwi, opem_object_dot)) GWI_B(gwi_oper_end(gwi, ".", NULL)) diff --git a/src/lib/lib_gack.c b/src/lib/lib_gack.c index aa2d225e..69d0dcb5 100644 --- a/src/lib/lib_gack.c +++ b/src/lib/lib_gack.c @@ -41,12 +41,12 @@ static OP_EMIT(opem_gack_implicit) { GWION_IMPORT(gack) { gwidoc(gwi, "a type for *pretty print*."); - const Type t_gack = gwi_mk_type(gwi, "@Gack", SZ_INT, NULL); + const Type t_gack = gwi_mk_type(gwi, "Gack", SZ_INT, NULL); GWI_B(gwi_gack(gwi, t_gack, gack_gack)) GWI_B(gwi_set_global_type(gwi, t_gack, et_gack)); gwidoc(gwi, "@Gack implicit cast"); - GWI_B(gwi_oper_ini(gwi, "@Gack", (m_str)OP_ANY_TYPE, NULL)) + GWI_B(gwi_oper_ini(gwi, "Gack", (m_str)OP_ANY_TYPE, NULL)) GWI_B(gwi_oper_add(gwi, opck_gack_implicit)) GWI_B(gwi_oper_emi(gwi, opem_gack_implicit)) GWI_B(gwi_oper_end(gwi, "@implicit", NULL)) diff --git a/src/lib/modules.c b/src/lib/modules.c index b5792223..d9b37e2f 100644 --- a/src/lib/modules.c +++ b/src/lib/modules.c @@ -278,7 +278,7 @@ static GWION_IMPORT(usrugen) { GWI_B(gwi_func_ini(gwi, "int", "default_tick")) GWI_B(gwi_func_end(gwi, default_tick, 0)) GWI_B(gwi_class_end(gwi)) - GWI_B(gwi_oper_ini(gwi, "function", "UsrUGen", "UsrUGen")) + GWI_B(gwi_oper_ini(gwi, "Function", "UsrUGen", "UsrUGen")) GWI_B(gwi_oper_add(gwi, opck_usrugen)) GWI_B(gwi_oper_emi(gwi, opem_usrugen)) GWI_B(gwi_oper_end(gwi, "~=>", NULL)) diff --git a/src/lib/object.c b/src/lib/object.c index 8bd413fb..8bf9294e 100644 --- a/src/lib/object.c +++ b/src/lib/object.c @@ -140,7 +140,8 @@ static ID_EMIT(opem_super) { } GWION_IMPORT(object) { - const Type t_object = gwi_mk_type(gwi, "Object", SZ_INT, "@Compound"); + //const Type t_object = gwi_mk_type(gwi, "Object", SZ_INT, "@Compound"); + const Type t_object = gwi_mk_type(gwi, "Object", SZ_INT, "Compound"); gwi_set_global_type(gwi, t_object, et_object); set_tflag(t_object, tflag_compound); t_object->nspc = new_nspc(gwi->gwion->mp, "Object"); diff --git a/src/lib/object_op.c b/src/lib/object_op.c index 37962697..99a591fb 100644 --- a/src/lib/object_op.c +++ b/src/lib/object_op.c @@ -381,7 +381,8 @@ GWION_IMPORT(object_op) { GWI_B(gwi_oper_add(gwi, opck_object_at)) GWI_B(gwi_oper_emi(gwi, opem_object_at)) GWI_B(gwi_oper_end(gwi, ":=>", NULL)) - GWI_B(gwi_oper_ini(gwi, (m_str)OP_ANY_TYPE, "@Compound", NULL)) + //GWI_B(gwi_oper_ini(gwi, (m_str)OP_ANY_TYPE, "@Compound", NULL)) + GWI_B(gwi_oper_ini(gwi, (m_str)OP_ANY_TYPE, "Compound", NULL)) GWI_B(gwi_oper_add(gwi, opck_object_instance)) GWI_B(gwi_oper_end(gwi, "=>", NULL)) GWI_B(gwi_oper_ini(gwi, "Object", "Object", "bool")) @@ -397,7 +398,8 @@ GWION_IMPORT(object_op) { GWI_B(gwi_oper_add(gwi, opck_unary_meta2)) GWI_B(gwi_oper_emi(gwi, opem_not_object)) GWI_B(gwi_oper_end(gwi, "!", NULL)) - GWI_B(gwi_oper_ini(gwi, "@Compound", NULL, NULL)) + //GWI_B(gwi_oper_ini(gwi, "@Compound", NULL, NULL)) + GWI_B(gwi_oper_ini(gwi, "Compound", NULL, NULL)) GWI_B(gwi_oper_add(gwi, opck_struct_scan)) GWI_B(gwi_oper_end(gwi, "class", NULL)) return true; diff --git a/src/lib/sift.c b/src/lib/sift.c index cd73de37..f64ce856 100644 --- a/src/lib/sift.c +++ b/src/lib/sift.c @@ -85,19 +85,19 @@ GWION_IMPORT(sift) { "#!- samp => now;\n" "#!- }\n" "#!- }"); - GWI_B(gwi_oper_ini(gwi, "UGen", "function", "Sift")); + GWI_B(gwi_oper_ini(gwi, "UGen", "Function", "Sift")); GWI_B(gwi_oper_add(gwi, opck_ctrl)); GWI_B(gwi_oper_end(gwi, "|>", NULL)); - GWI_B(gwi_oper_ini(gwi, "Sift", "function", "Sift")); + GWI_B(gwi_oper_ini(gwi, "Sift", "Function", "Sift")); GWI_B(gwi_oper_add(gwi, opck_sift)); GWI_B(gwi_oper_end(gwi, "|>", NULL)); - GWI_B(gwi_oper_ini(gwi, "UGen", "funptr", "Sift")); + GWI_B(gwi_oper_ini(gwi, "UGen", "Funptr", "Sift")); GWI_B(gwi_oper_add(gwi, opck_ctrl)); GWI_B(gwi_oper_end(gwi, "|>", NULL)); - GWI_B(gwi_oper_ini(gwi, "Sift", "funptr", "Sift")); + GWI_B(gwi_oper_ini(gwi, "Sift", "Funptr", "Sift")); GWI_B(gwi_oper_add(gwi, opck_sift)); GWI_B(gwi_oper_end(gwi, "|>", NULL)); return true; diff --git a/src/lib/union.c b/src/lib/union.c index 63820265..30191bf2 100644 --- a/src/lib/union.c +++ b/src/lib/union.c @@ -170,7 +170,7 @@ ANN GWION_IMPORT(union) { GWI_B(gwi_oper_emi(gwi, opem_none)) GWI_B(gwi_oper_end(gwi, ":=>", NoOp)) - const Type t_union = gwi_struct_ini(gwi, "union"); + const Type t_union = gwi_struct_ini(gwi, "Union"); //gwi_class_xtor(gwi, NULL, UnionDtor); gwi->gwion->type[et_union] = t_union; @@ -197,7 +197,7 @@ ANN GWION_IMPORT(union) { const struct Op_Func opfunc1 = {.ck = opck_union_new}; CHECK_B(add_op_func_check(gwi->gwion->env, t_union, &opfunc1, 1)); - GWI_B(gwi_oper_ini(gwi, "union", (m_str)OP_ANY_TYPE, NULL)) + GWI_B(gwi_oper_ini(gwi, "Union", (m_str)OP_ANY_TYPE, NULL)) GWI_B(gwi_oper_emi(gwi, opem_union_dot)) GWI_B(gwi_oper_end(gwi, ".", NULL))