From: fennecdjay Date: Mon, 30 Sep 2019 21:03:50 +0000 (+0200) Subject: :art: USe known_type in mk_type X-Git-Tag: nightly~2198^2~212 X-Git-Url: http://10.10.0.4:5575/?a=commitdiff_plain;h=e37700a0725b353dd17d36c74cd2fe43402ae95b;p=gwion.git :art: USe known_type in mk_type --- diff --git a/include/import.h b/include/import.h index d1d5285a..ac71a28b 100644 --- a/include/import.h +++ b/include/import.h @@ -33,7 +33,7 @@ typedef struct Gwi_* Gwi; ANN VM* gwi_vm(const Gwi); -ANN2(1,2) ANEW Type gwi_mk_type(const Gwi, const m_str, const m_uint, const Type); +ANN2(1,2) ANEW Type gwi_mk_type(const Gwi, const m_str, const m_uint, const m_str); ANN m_int gwi_add_type(const Gwi gwi, Type type); ANN m_int gwi_set_global_type(const Gwi gwi, const Type type, const type_enum te); ANN m_bool gwi_gack(const Gwi gwi, const Type type, const f_gack d); diff --git a/src/emit/emit.c b/src/emit/emit.c index 4545bd69..7f8aabf7 100644 --- a/src/emit/emit.c +++ b/src/emit/emit.c @@ -834,8 +834,8 @@ ANN static Type_List tmpl_tl(const Env env, const m_str name) { const m_str start = strchr(name, '<'); const m_str end = strchr(name, '@'); char c[strlen(name)]; - strcpy(c, start + 1); - c[strlen(start) - strlen(end) - 2] = '\0'; + strcpy(c, start + 2); + c[strlen(start) - strlen(end) - 4] = '\0'; m_uint depth; return str2tl(env, c, &depth); } diff --git a/src/lib/array.c b/src/lib/array.c index 32b401ef..5150ff02 100644 --- a/src/lib/array.c +++ b/src/lib/array.c @@ -192,7 +192,7 @@ static FREEARG(freearg_array) { } GWION_IMPORT(array) { - const Type t_array = gwi_mk_type(gwi, "@Array", SZ_INT, gwi->gwion->type[et_object]); + const Type t_array = gwi_mk_type(gwi, "@Array", SZ_INT, "Object"); gwi->gwion->type[et_array] = t_array; GWI_BB(gwi_class_ini(gwi, t_array, NULL, array_dtor)) diff --git a/src/lib/engine.c b/src/lib/engine.c index 4c08ada0..63f8e374 100644 --- a/src/lib/engine.c +++ b/src/lib/engine.c @@ -21,7 +21,7 @@ #include "specialid.h" static GACK(gack_class) { - printf("class(%p)", (*(Type*)VALUE)->e->d.base_type); + printf("class(%s)", actual_type(shred->info->vm->gwion, t)->name); } static GACK(gack_function) { @@ -93,10 +93,10 @@ ANN static m_bool import_core_libs(const Gwi gwi) { const Type t_function = gwi_mk_type(gwi, "@function", SZ_INT, NULL); GWI_BB(gwi_gack(gwi, t_function, gack_function)) GWI_BB(gwi_set_global_type(gwi, t_function, et_function)) - const Type t_fptr = gwi_mk_type(gwi, "@func_ptr", SZ_INT, t_function); + const Type t_fptr = gwi_mk_type(gwi, "@func_ptr", SZ_INT, "@function"); GWI_BB(gwi_gack(gwi, t_fptr, gack_fptr)) GWI_BB(gwi_set_global_type(gwi, t_fptr, et_fptr)) - const Type t_lambda = gwi_mk_type(gwi, "@lambda", SZ_INT, t_function); + const Type t_lambda = gwi_mk_type(gwi, "@lambda", SZ_INT, "@function"); GWI_BB(gwi_set_global_type(gwi, t_lambda, et_lambda)) const Type t_gack = gwi_mk_type(gwi, "@Gack", SZ_INT, NULL); GWI_BB(gwi_set_global_type(gwi, t_gack, et_gack)) @@ -112,7 +112,7 @@ ANN static m_bool import_core_libs(const Gwi gwi) { const Type t_time = gwi_mk_type(gwi, "time", SZ_FLOAT, NULL); CHECK_BB(gwi_gack(gwi, t_time, gack_float)) GWI_BB(gwi_add_type(gwi, t_time)) - const Type t_now = gwi_mk_type(gwi, "@now", SZ_FLOAT, t_time); + const Type t_now = gwi_mk_type(gwi, "@now", SZ_FLOAT, "time"); GWI_BB(gwi_add_type(gwi, t_now)) struct SpecialId_ spid = { .type=t_now, .exec=RegPushNow, .is_const=1 }; gwi_specialid(gwi, "now", &spid); @@ -130,7 +130,7 @@ ANN static m_bool import_core_libs(const Gwi gwi) { gwi->gwion->type[et_vec4] = t_vec4; CHECK_BB(gwi_gack(gwi, t_vec4, gack_vec4)) GWI_BB(import_object(gwi)) - const Type t_union = gwi_mk_type(gwi, "@Union", SZ_INT, gwi->gwion->type[et_object]); + const Type t_union = gwi_mk_type(gwi, "@Union", SZ_INT, "Object"); gwi->gwion->type[et_union] = t_union; GWI_BB(gwi_class_ini(gwi, t_union, NULL, NULL)) GWI_BB(gwi_class_end(gwi)) diff --git a/src/lib/event.c b/src/lib/event.c index a6ad0016..99f79beb 100644 --- a/src/lib/event.c +++ b/src/lib/event.c @@ -57,7 +57,7 @@ static MFUN(event_broadcast) { } GWION_IMPORT(event) { - const Type t_event = gwi_mk_type(gwi, "Event", SZ_INT, gwi->gwion->type[et_object]); + const Type t_event = gwi_mk_type(gwi, "Event", SZ_INT, "Object"); gwi->gwion->type[et_event] = t_event; GWI_BB(gwi_class_ini(gwi, t_event, event_ctor, event_dtor)) GWI_BB(gwi_item_ini(gwi, "int", "@shreds")) diff --git a/src/lib/import.c b/src/lib/import.c index 66121955..34570620 100644 --- a/src/lib/import.c +++ b/src/lib/import.c @@ -101,6 +101,7 @@ ANN static m_bool name_valid(const Gwi gwi, const m_str a) { continue; if(c == '<') { lvl++; + ++i; continue; } if(c == ',') { @@ -108,7 +109,7 @@ ANN static m_bool name_valid(const Gwi gwi, const m_str a) { GWI_ERR_B(_("illegal use of ',' outside of templating in name '%s'."), a) continue; } - if(c == '>') { + if(c == '~') { if(!lvl) GWI_ERR_B(_("illegal templating in name '%s'."), a) lvl--; @@ -132,7 +133,11 @@ ANN static m_bool path_valid(const Env env, ID_List* list, const struct Path* p) char last = '\0'; for(m_uint i = p->len + 1; --i;) { const char c = p->path[i - 1]; - if(c != '.' && check_illegal(p->curr, c, i) < 0) { + +// TODO: NOW!!! check templating +//if( c == '<' && p->path[i - 2] == '~'); +//else + if(c != '.' && check_illegal(p->curr, c, i) < 0) { env_err(env, &p->loc, _("illegal character '%c' in path '%s'."), c, p->path); return GW_ERROR; } @@ -196,7 +201,10 @@ ANN static m_bool mk_xtor(MemPool p, const Type type, const m_uint d, const ae_f return GW_OK; } -ANN2(1,2) Type gwi_mk_type(const Gwi gwi NUSED, const m_str name, const m_uint size, const Type parent) { +ANN2(1,2) Type gwi_mk_type(const Gwi gwi NUSED, const m_str name, const m_uint size, const m_str parent_name) { + m_uint depth; + const Type_Decl* td = parent_name ? str2decl(gwi->gwion->env, parent_name, &depth) : NULL; + const Type parent = td ? known_type(gwi->gwion->env, td) : NULL; const Type t = new_type(gwi->gwion->mp, 0, name, parent); t->size = size; return t; diff --git a/src/lib/modules.c b/src/lib/modules.c index 919da90f..3cf3af3f 100644 --- a/src/lib/modules.c +++ b/src/lib/modules.c @@ -40,7 +40,7 @@ static MFUN(gain_set_gain) { } static GWION_IMPORT(gain) { - const Type t_gain = gwi_mk_type(gwi, "Gain", SZ_INT, gwi->gwion->type[et_ugen]); + const Type t_gain = gwi_mk_type(gwi, "Gain", SZ_INT, "UGen"); GWI_BB(gwi_class_ini(gwi, t_gain, gain_ctor, basic_dtor)) gwi_func_ini(gwi, "float", "gain", gain_get_gain); GWI_BB(gwi_func_end(gwi, 0)) @@ -70,7 +70,7 @@ static MFUN(impulse_set_next) { } static GWION_IMPORT(impulse) { - const Type t_impulse = gwi_mk_type(gwi, "Impulse", SZ_INT, gwi->gwion->type[et_ugen]); + const Type t_impulse = gwi_mk_type(gwi, "Impulse", SZ_INT, "UGen"); GWI_BB(gwi_class_ini(gwi, t_impulse, impulse_ctor, basic_dtor)) gwi_func_ini(gwi, "float", "next", impulse_get_next); GWI_BB(gwi_func_end(gwi, 0)) @@ -91,7 +91,7 @@ static CTOR(fullrect_ctor) { } static GWION_IMPORT(fullrect) { - const Type t_fullrect = gwi_mk_type(gwi, "FullRect", SZ_INT, gwi->gwion->type[et_ugen]); + const Type t_fullrect = gwi_mk_type(gwi, "FullRect", SZ_INT, "UGen"); GWI_BB(gwi_class_ini(gwi, t_fullrect, fullrect_ctor, basic_dtor)) return gwi_class_end(gwi); } @@ -110,7 +110,7 @@ static CTOR(halfrect_ctor) { } static GWION_IMPORT(halfrect) { - const Type t_halfrect = gwi_mk_type(gwi, "HalfRect", SZ_INT, gwi->gwion->type[et_ugen]); + const Type t_halfrect = gwi_mk_type(gwi, "HalfRect", SZ_INT, "UGen"); GWI_BB(gwi_class_ini(gwi, t_halfrect, halfrect_ctor, basic_dtor)) return gwi_class_end(gwi); } @@ -134,7 +134,7 @@ static MFUN(step_set_next) { } static GWION_IMPORT(step) { - const Type t_step = gwi_mk_type(gwi, "Step", SZ_INT, gwi->gwion->type[et_ugen]); + const Type t_step = gwi_mk_type(gwi, "Step", SZ_INT, "UGen"); GWI_BB(gwi_class_ini(gwi, t_step, step_ctor, basic_dtor)) gwi_func_ini(gwi, "float", "next", step_get_next); GWI_BB(gwi_func_end(gwi, 0)) @@ -158,7 +158,7 @@ static CTOR(zerox_ctor) { } static GWION_IMPORT(zerox) { - const Type t_zerox = gwi_mk_type(gwi, "ZeroX", SZ_INT, gwi->gwion->type[et_ugen]); + const Type t_zerox = gwi_mk_type(gwi, "ZeroX", SZ_INT, "UGen"); GWI_BB(gwi_class_ini(gwi, t_zerox, zerox_ctor, basic_dtor)) return gwi_class_end(gwi); } diff --git a/src/lib/ptr.c b/src/lib/ptr.c index a23884ee..b3f84fde 100644 --- a/src/lib/ptr.c +++ b/src/lib/ptr.c @@ -106,7 +106,7 @@ static OP_EMIT(opem_ptr_deref) { GWION_IMPORT(ptr) { const m_str list[] = { "A" }; - const Type t_ptr = gwi_mk_type(gwi, "Ptr", SZ_INT, gwi->gwion->type[et_object]); + const Type t_ptr = gwi_mk_type(gwi, "Ptr", SZ_INT, "Object"); gwi->gwion->type[et_ptr] = t_ptr; GWI_BB(gwi_tmpl_ini(gwi, 1, list)) GWI_BB(gwi_class_ini(gwi, t_ptr, NULL, NULL)) diff --git a/src/lib/shred.c b/src/lib/shred.c index 1c70b813..1b44af03 100644 --- a/src/lib/shred.c +++ b/src/lib/shred.c @@ -231,7 +231,7 @@ void fork_launch(const VM* vm, const M_Object o, const m_uint sz) { #include "nspc.h" GWION_IMPORT(shred) { - const Type t_shred = gwi_mk_type(gwi, "Shred", SZ_INT, gwi->gwion->type[et_object]); + const Type t_shred = gwi_mk_type(gwi, "Shred", SZ_INT, "Object"); gwi->gwion->type[et_shred] = t_shred; GWI_BB(gwi_class_ini(gwi, t_shred, NULL, shred_dtor)) @@ -302,7 +302,7 @@ GWION_IMPORT(shred) { SET_FLAG((t_shred), abstract); - const Type t_fork = gwi_mk_type(gwi, "Fork", SZ_INT, t_shred); + const Type t_fork = gwi_mk_type(gwi, "Fork", SZ_INT, "Shred"); gwi->gwion->type[et_fork] = t_fork; GWI_BB(gwi_class_ini(gwi, t_fork, NULL, fork_dtor)) gwi_item_ini(gwi, "int", "@thread"); diff --git a/src/lib/string.c b/src/lib/string.c index cb6aeb93..1591c212 100644 --- a/src/lib/string.c +++ b/src/lib/string.c @@ -186,7 +186,7 @@ static GACK(gack_string) { printf("%s", obj ? STRING(obj) : "(null string)"); } GWION_IMPORT(string) { - const Type t_string = gwi_mk_type(gwi, "string", SZ_INT, gwi->gwion->type[et_object]); + const Type t_string = gwi_mk_type(gwi, "string", SZ_INT, "Object"); GWI_BB(gwi_gack(gwi, t_string, gack_string)) GWI_BB(gwi_class_ini(gwi, t_string, string_ctor, NULL)) gwi->gwion->type[et_string] = t_string; diff --git a/src/lib/tuple.c b/src/lib/tuple.c index b12b5cf0..f44cb88b 100644 --- a/src/lib/tuple.c +++ b/src/lib/tuple.c @@ -325,7 +325,7 @@ ANN void free_tupleform(MemPool p, const TupleForm tuple) { } GWION_IMPORT(tuple) { - const Type t_tuple = gwi_mk_type(gwi, "Tuple", SZ_INT, gwi->gwion->type[et_object]); + const Type t_tuple = gwi_mk_type(gwi, "Tuple", SZ_INT, "Object"); gwi->gwion->type[et_tuple] = t_tuple; GWI_BB(gwi_class_ini(gwi, t_tuple, NULL, NULL)) GWI_BB(gwi_class_end(gwi)) diff --git a/src/lib/ugen.c b/src/lib/ugen.c index 117e2ccf..dd21a84c 100644 --- a/src/lib/ugen.c +++ b/src/lib/ugen.c @@ -335,7 +335,7 @@ static OP_CHECK(opck_chuck_ugen) { } GWION_IMPORT(ugen) { - const Type t_ugen = gwi_mk_type(gwi, "UGen", SZ_INT, gwi->gwion->type[et_object]); + const Type t_ugen = gwi_mk_type(gwi, "UGen", SZ_INT, "Object"); gwi->gwion->type[et_ugen] = t_ugen; GWI_BB(gwi_class_ini(gwi, t_ugen, ugen_ctor, ugen_dtor)) GWI_BB(gwi_item_ini(gwi, "int", "@ugen")) diff --git a/src/lib/vararg.c b/src/lib/vararg.c index 2de725e6..852f0ac1 100644 --- a/src/lib/vararg.c +++ b/src/lib/vararg.c @@ -84,8 +84,8 @@ static FREEARG(freearg_vararg) { } GWION_IMPORT(vararg) { - const Type t_vararg = gwi_mk_type(gwi, "@Vararg", SZ_INT, gwi->gwion->type[et_object]); - const Type t_varobj = gwi_mk_type(gwi, "VarObject", SZ_INT, t_vararg); + const Type t_vararg = gwi_mk_type(gwi, "@Vararg", SZ_INT, "Object"); + const Type t_varobj = gwi_mk_type(gwi, "VarObject", SZ_INT, "Object"); SET_FLAG(t_varobj, abstract); const Type t_varloop = gwi_mk_type(gwi, "@VarLoop", SZ_INT, NULL); GWI_BB(gwi_add_type(gwi, t_varobj)) diff --git a/src/main.c b/src/main.c index 5d27a751..30169172 100644 --- a/src/main.c +++ b/src/main.c @@ -15,6 +15,7 @@ static void sig(int unused NUSED) { #endif } +#include "type.h" int main(int argc, char** argv) { Arg arg = { .argc=argc, .argv=argv, .loop=-1 }; signal(SIGINT, sig); diff --git a/src/oo/type.c b/src/oo/type.c index 2f088c78..d1ab558e 100644 --- a/src/oo/type.c +++ b/src/oo/type.c @@ -156,17 +156,18 @@ ANN m_str get_type_name(const Env env, const m_str s, const m_uint index) { const size_t slen = strlen(s); const size_t tlen = slen - len + 1; char c[slen + 1]; - if(!name) return index ? NULL : s_name(insert_symbol(s)); if(index == 0) { snprintf(c, tlen, "%s", s); return s_name(insert_symbol(c)); } + ++name; while(*name++) { - if(*name == '<') + if(*name == '<') { lvl++; - else if(*name == '>' && !lvl--) + name++; + } else if(*name == '~' && !lvl--) break; if(*name == ',' && !lvl) { ++name; diff --git a/src/parse/func.c b/src/parse/func.c index 63b33ba0..a46a218c 100644 --- a/src/parse/func.c +++ b/src/parse/func.c @@ -49,13 +49,13 @@ ANN Func get_func(const Env env, const Func_Def def) { ANN2(1,2) Symbol func_symbol(const Env env, const m_str nspc, const m_str base, const m_str tmpl, const m_uint i) { const size_t base_len = strlen(base); - const size_t tmpl_len = !tmpl ? 0 : strlen(tmpl) + 2; + const size_t tmpl_len = !tmpl ? 0 : strlen(tmpl) + 4; const size_t nspc_len = strlen(nspc); const size_t idx_len = num_digit(i); const size_t len = base_len + tmpl_len + nspc_len + idx_len + 2; char name[len + 1]; CHECK_BO(sprintf(name, "%s%s%s%s@%" UINT_F "@%s", - base, !tmpl ? "" : "<", !tmpl ? "" : tmpl, !tmpl ? "" : ">", + base, !tmpl ? "" : "<~", !tmpl ? "" : tmpl, !tmpl ? "" : "~>", i, nspc)) return insert_symbol(env->gwion->st, name); } diff --git a/src/parse/template.c b/src/parse/template.c index 01b57af4..7c66afb8 100644 --- a/src/parse/template.c +++ b/src/parse/template.c @@ -94,12 +94,18 @@ ANN static void template_name(struct tmpl_info* info, m_str s) { m_str str = s; str = tmpl_get(info, str); *str++ = '<'; + *str++ = '~'; const m_uint size = vector_size(&info->type); for(info->index = 1; info->index < size; ++info->index) { str = tmpl_get(info, str); - *str++ = (info->index < size - 1) ? ',' : '>'; - } - *str = '\0'; + if(info->index < size - 1) + *str++ = ','; + else { + *str++ = '~'; + *str++ = '>'; + } + } + *str = '\0'; } ANEW ANN static Symbol template_id(const Env env, const Class_Def c, const Type_List call) { diff --git a/tests/import/array.c b/tests/import/array.c index c17d062a..33598c72 100644 --- a/tests/import/array.c +++ b/tests/import/array.c @@ -15,7 +15,7 @@ MFUN(test_mfun){} GWION_IMPORT(array_test) { Type t_invalid_var_name; - CHECK_OB((t_invalid_var_name = gwi_mk_type(gwi, "invalid_var_name", SZ_INT, gwi->gwion->type[et_object]))) + CHECK_OB((t_invalid_var_name = gwi_mk_type(gwi, "invalid_var_name", SZ_INT, "Object"))) CHECK_BB(gwi_class_ini(gwi, t_invalid_var_name, NULL, NULL)) CHECK_BB(gwi_item_ini(gwi, "int[]", "int_array")) CHECK_BB(gwi_item_end(gwi, 0, NULL)) // import array var diff --git a/tests/import/begin_class.c b/tests/import/begin_class.c index 431bb007..7f7eda3c 100644 --- a/tests/import/begin_class.c +++ b/tests/import/begin_class.c @@ -14,7 +14,7 @@ MFUN(test_mfun){} GWION_IMPORT(begin_class) { Type t_invalid_var_name; - CHECK_OB((t_invalid_var_name = gwi_mk_type(gwi, "invalid_var_name", SZ_INT, gwi->gwion->type[et_object]))) + CHECK_OB((t_invalid_var_name = gwi_mk_type(gwi, "invalid_var_name", SZ_INT, "Object"))) CHECK_BB(gwi_class_ini(gwi, t_invalid_var_name, NULL, NULL)) CHECK_BB(gwi_class_ini(gwi, t_invalid_var_name, NULL, NULL)) return GW_OK; diff --git a/tests/import/callback.c b/tests/import/callback.c index 5d0323e9..fd4a3785 100644 --- a/tests/import/callback.c +++ b/tests/import/callback.c @@ -73,7 +73,7 @@ GWION_IMPORT(callback) { CHECK_BB(gwi_fptr_ini(gwi, "Vec4", "PtrType")) CHECK_OB(gwi_fptr_end(gwi, 0)) - const Type t_callback = gwi_mk_type(gwi, "Callback", SZ_INT, gwi->gwion->type[et_object]); + const Type t_callback = gwi_mk_type(gwi, "Callback", SZ_INT, "Object"); CHECK_BB(gwi_class_ini(gwi, t_callback, NULL, NULL)) CHECK_BB(gwi_func_ini(gwi, "int", "callback", cb_func)) CHECK_BB(gwi_func_arg(gwi, "PtrType", "func")) diff --git a/tests/import/class_template.c b/tests/import/class_template.c index c507b2ef..68c1974c 100644 --- a/tests/import/class_template.c +++ b/tests/import/class_template.c @@ -30,7 +30,7 @@ GWION_IMPORT(class_template) { Type t_class_template; const m_str list[2] = { "A", "B" }; gwi_tmpl_ini(gwi, 2, list); - CHECK_OB((t_class_template = gwi_mk_type(gwi, "ClassTemplate", SZ_INT, gwi->gwion->type[et_object]))) + CHECK_OB((t_class_template = gwi_mk_type(gwi, "ClassTemplate", SZ_INT, "Object"))) CHECK_BB(gwi_class_ini(gwi, t_class_template, class_template_ctor, NULL)) gwi_tmpl_end(gwi); CHECK_BB(gwi_item_ini(gwi, "A[]", "key")) diff --git a/tests/import/coverage.c b/tests/import/coverage.c index d4f01ed5..183e2d50 100644 --- a/tests/import/coverage.c +++ b/tests/import/coverage.c @@ -20,7 +20,7 @@ SFUN(coverage_vec4) { m_vec4 v = {0,0,0,0}; *(m_vec4*)RETURN = v; } GWION_IMPORT(coverage) { Type t_coverage; - CHECK_OB((t_coverage = gwi_mk_type(gwi, "Coverage", SZ_INT, gwi->gwion->type[et_object]))) + CHECK_OB((t_coverage = gwi_mk_type(gwi, "Coverage", SZ_INT, "Object"))) CHECK_BB(gwi_class_ini(gwi, t_coverage, NULL, NULL)) CHECK_BB(gwi_func_ini(gwi, "int", "i", coverage_int)) CHECK_BB(gwi_func_end(gwi, ae_flag_static)) diff --git a/tests/import/variadic.c b/tests/import/variadic.c index 8e25c674..ae176649 100644 --- a/tests/import/variadic.c +++ b/tests/import/variadic.c @@ -40,7 +40,7 @@ static MFUN(m_variadic) { } GWION_IMPORT(variadic test) { - const Type t_variadic = gwi_mk_type(gwi, "Variadic", SZ_INT, gwi->gwion->type[et_object]); + const Type t_variadic = gwi_mk_type(gwi, "Variadic", SZ_INT, "Object"); CHECK_BB(gwi_class_ini(gwi, t_variadic, NULL, NULL)) CHECK_BB(gwi_func_ini(gwi, "void", "member", m_variadic)) CHECK_BB(gwi_func_arg(gwi, "string", "format"))