From: Jérémie Astor Date: Sun, 13 Sep 2020 20:56:45 +0000 (+0200) Subject: :art: Move templates to the right, C part X-Git-Tag: nightly~1333 X-Git-Url: http://10.10.0.4:5575/?a=commitdiff_plain;h=438cd834d04b713639f3cd45e864011d84786cbb;p=gwion.git :art: Move templates to the right, C part --- diff --git a/ast b/ast index 80bf35b3..39ad6755 160000 --- a/ast +++ b/ast @@ -1 +1 @@ -Subproject commit 80bf35b35aebe23fc18ebc57b5db627ba26a0167 +Subproject commit 39ad675551cd32f3ad2125f3cf9afe6ac416c99e diff --git a/src/import/checker.c b/src/import/checker.c index 3a584d8d..d371e8ab 100644 --- a/src/import/checker.c +++ b/src/import/checker.c @@ -59,7 +59,7 @@ ANN static Symbol __str2sym(const Gwi gwi, struct td_checker *tdc) { ANN static inline Symbol _str2sym(const Gwi gwi, struct td_checker *tdc, const m_str path) { const Symbol sym = __str2sym(gwi, tdc); - if(*tdc->str) + if(*tdc->str && *tdc->str != '<') GWI_ERR_O(_("illegal character '%c' in path '%s'."), *tdc->str, path) return sym; } @@ -126,14 +126,11 @@ ANN static ID_List __tmpl_list(const Gwi gwi, struct td_checker *tdc) { ANN m_bool check_typename_def(const Gwi gwi, ImportCK *ck) { struct td_checker tdc = { .str= ck->name }; + if(!(ck->sym = _str2sym(gwi, &tdc, tdc.str))) + return GW_ERROR; ID_List il = __tmpl_list(gwi, &tdc); if(il == (ID_List)GW_ERROR) return GW_ERROR; - if(!(ck->sym = _str2sym(gwi, &tdc, tdc.str))) { - if(il) - free_id_list(gwi->gwion->mp, il); - return GW_ERROR; - } ck->tmpl = il; ck->name = s_name(ck->sym); return GW_OK; @@ -194,7 +191,7 @@ ANN Type_List __str2tl(const Gwi gwi, struct td_checker *tdc) { return new_type_list(gwi->gwion->mp, td, next); } -ANN Type_List td_tmpl(const Gwi gwi, struct td_checker *tdc) { +ANN static Type_List td_tmpl(const Gwi gwi, struct td_checker *tdc) { if(*tdc->str != '<') return NULL; // GW_PASS ++tdc->str; @@ -224,22 +221,14 @@ ANN static void ac_add_exp(struct AC *ac, const Exp exp) { ANN Type_Decl* _str2decl(const Gwi gwi, struct td_checker *tdc) { + DECL_OO(const Symbol, sym, = __str2sym(gwi, tdc)) + struct AC ac = { .str = tdc->str }; + CHECK_BO(ac_run(gwi, &ac)) + tdc->str = ac.str; Type_List tl = td_tmpl(gwi, tdc); if(tl == (Type_List)GW_ERROR) return NULL; Type_Decl *next = NULL; - const Symbol sym = __str2sym(gwi, tdc); - if(!sym) { - if(tl) - free_type_list(gwi->gwion->mp, tl); - return NULL; - } - struct AC ac = { .str = tdc->str }; - if(ac_run(gwi, &ac) < 0) { - if(tl)free_type_list(gwi->gwion->mp, tl); - return NULL; - } - tdc->str = ac.str; if(*tdc->str == '.') { ++tdc->str; if(!(next = _str2decl(gwi, tdc))) { diff --git a/src/lib/ptr.c b/src/lib/ptr.c index 7b43095b..9395b348 100644 --- a/src/lib/ptr.c +++ b/src/lib/ptr.c @@ -158,8 +158,7 @@ GWION_IMPORT(ptr) { GWI_BB(gwi_oper_ini(gwi, "@Ptr", NULL, NULL)) GWI_BB(gwi_oper_add(gwi, opck_ptr_scan)) GWI_BB(gwi_oper_end(gwi, "@scan", NULL)) - const Type t_ptr = gwi_class_ini(gwi, "<~A~>Ptr", "@Ptr"); -// const Type t_ptr = gwi_class_ini(gwi, "<~A~>Ptr", NULL); + const Type t_ptr = gwi_class_ini(gwi, "Ptr<~A~>", "@Ptr"); gwi->gwion->type[et_ptr] = t_ptr; GWI_BB(gwi_item_ini(gwi, "@internal", "@val")) GWI_BB(gwi_item_end(gwi, 0, NULL)) diff --git a/src/lib/shred.c b/src/lib/shred.c index 33dadda8..d0a105c7 100644 --- a/src/lib/shred.c +++ b/src/lib/shred.c @@ -403,7 +403,7 @@ GWION_IMPORT(shred) { GWI_BB(gwi_class_end(gwi)) SET_FLAG((t_fork), abstract); - const Type t_typed = gwi_class_ini(gwi, "<~A~>TypedFork", "Fork"); + const Type t_typed = gwi_class_ini(gwi, "TypedFork<~A~>", "Fork"); gwi_item_ini(gwi, "A", "retval"); GWI_BB((gwi_item_end(gwi, ae_flag_const, NULL))) GWI_BB(gwi_class_end(gwi)) diff --git a/tests/import/class_template_invalid.c b/tests/import/class_template_invalid.c index 0d61fc3b..e3c6335b 100644 --- a/tests/import/class_template_invalid.c +++ b/tests/import/class_template_invalid.c @@ -15,16 +15,16 @@ static m_int o_map_value; #define MAP_VAL(a) *((M_Object*)(a->data + o_map_value)) GWION_IMPORT(class_template) { - GWI_OB(gwi_class_ini(gwi, "<~A,B~>ClassTemplate", NULL)) + GWI_OB(gwi_class_ini(gwi, "ClassTemplate<~A,B~>", NULL)) GWI_BB(gwi_item_ini(gwi, "A[]", "key")) GWI_BB((o_map_key = gwi_item_end(gwi, ae_flag_member | ae_flag_template, NULL))) GWI_BB(gwi_item_ini(gwi, "B[]", "value")) GWI_BB((o_map_value = gwi_item_end(gwi, ae_flag_member, NULL))) - GWI_BB(gwi_func_ini(gwi, "int", "<~C,D~>test")) + GWI_BB(gwi_func_ini(gwi, "int", "test<~C,D~>")) GWI_BB(gwi_func_end(gwi, (f_xfun)1, ae_flag_none)) GWI_BB(gwi_class_end(gwi)) - GWI_BB(gwi_item_ini(gwi, "<~Ptr<~int~>,int[]~>ClassTemplate", "testObject")) + GWI_BB(gwi_item_ini(gwi, "ClassTemplate<~<~int~>Ptr,int[]~>", "testObject")) GWI_BB(gwi_item_end(gwi, ae_flag_none, NULL)) return GW_OK; } diff --git a/tests/import/fptr_tmpl.c b/tests/import/fptr_tmpl.c index e9b6a8d3..6fdcc1d6 100644 --- a/tests/import/fptr_tmpl.c +++ b/tests/import/fptr_tmpl.c @@ -11,7 +11,7 @@ GWION_IMPORT(typedef_test) { Type t_func_typedef; GWI_OB((t_func_typedef = gwi_mk_type(gwi, "FuncTypedef", SZ_INT , NULL))) - GWI_BB(gwi_fptr_ini(gwi, "int", "<~A~>test")) + GWI_BB(gwi_fptr_ini(gwi, "int", "test<~test~>")) GWI_OB(gwi_fptr_end(gwi, 0)) return GW_OK; } diff --git a/tests/import/fptr_tmpl_fail.c b/tests/import/fptr_tmpl_fail.c index 5ddd4a42..2ec528c3 100644 --- a/tests/import/fptr_tmpl_fail.c +++ b/tests/import/fptr_tmpl_fail.c @@ -9,7 +9,7 @@ #include "import.h" GWION_IMPORT(typedef_test) { - GWI_BB(gwi_fptr_ini(gwi, "int~", "<~A~>test")) + GWI_BB(gwi_fptr_ini(gwi, "int~", "test<~A~>")) GWI_OB(gwi_fptr_end(gwi, 0)) return GW_OK; } diff --git a/tests/import/func_fail3.c b/tests/import/func_fail3.c index 3088d539..09402e9a 100644 --- a/tests/import/func_fail3.c +++ b/tests/import/func_fail3.c @@ -10,7 +10,7 @@ #include "instr.h" GWION_IMPORT(too_many_args) { - GWI_BB(gwi_func_ini(gwi, "<~int~>Ptr", "<~A~>test")) + GWI_BB(gwi_func_ini(gwi, "Ptr<~int~>", "test<~A~>")) GWI_BB(gwi_func_ini(gwi, "int", "test")) GWI_BB(gwi_func_arg(gwi, "int", "i[][]")) GWI_BB(gwi_func_end(gwi, (f_xfun)1, ae_flag_none)) diff --git a/tests/import/func_fail4.c b/tests/import/func_fail4.c index 9781f087..06c7f384 100644 --- a/tests/import/func_fail4.c +++ b/tests/import/func_fail4.c @@ -10,7 +10,7 @@ #include "instr.h" GWION_IMPORT(too_many_args) { - GWI_BB(gwi_func_ini(gwi, "<~int~>Ptr", "<~A~>test")) + GWI_BB(gwi_func_ini(gwi, "Ptr<~int~>", "test<~A~>")) GWI_BB(gwi_func_arg(gwi, "int", "i[][]")) GWI_BB(gwi_item_end(gwi, ae_flag_none, NULL)) return GW_OK; diff --git a/tests/import/func_tmpl.c b/tests/import/func_tmpl.c index edb84841..0214bd24 100644 --- a/tests/import/func_tmpl.c +++ b/tests/import/func_tmpl.c @@ -14,7 +14,7 @@ static SFUN(func_tmpl_xfun) { } GWION_IMPORT(func_tmpl) { - GWI_BB(gwi_func_ini(gwi, "int[]", "<~A~>test")) + GWI_BB(gwi_func_ini(gwi, "int[]", "test<~A~>")) GWI_BB(gwi_func_arg(gwi, "A", "i")) GWI_BB(gwi_func_end(gwi, func_tmpl_xfun, ae_flag_none)) return GW_OK; diff --git a/tests/import/func_tmpl_fail.c b/tests/import/func_tmpl_fail.c index ca5a35d3..f01dddad 100644 --- a/tests/import/func_tmpl_fail.c +++ b/tests/import/func_tmpl_fail.c @@ -14,7 +14,7 @@ static SFUN(func_tmpl_xfun) { } GWION_IMPORT(func_tmpl) { - GWI_BB(gwi_func_ini(gwi, "voit", "<~A~>test")) + GWI_BB(gwi_func_ini(gwi, "voit", "test<~A~>")) GWI_BB(gwi_func_end(gwi, func_tmpl_xfun, ae_flag_none)) return GW_OK; } diff --git a/tests/import/invalid_names.c b/tests/import/invalid_names.c index 16b3b628..66ec9711 100644 --- a/tests/import/invalid_names.c +++ b/tests/import/invalid_names.c @@ -22,7 +22,7 @@ GWION_IMPORT(trig) { const Type t2 = gwi_mk_type(gwi, "T", SZ_INT, NULL); gwi_add_type(gwi, t2); - const Type t3 = gwi_mk_type(gwi, "<~a~>T", SZ_INT, NULL); + const Type t3 = gwi_mk_type(gwi, "T<~a~>", SZ_INT, NULL); gwi_add_type(gwi, t3); return GW_OK; diff --git a/tests/import/invalid_names3.c b/tests/import/invalid_names3.c index 11989406..02c7033a 100644 --- a/tests/import/invalid_names3.c +++ b/tests/import/invalid_names3.c @@ -13,6 +13,6 @@ #include "gwi.h" GWION_IMPORT(trig) { - DECL_OB(const Type, t0, = gwi_mk_type(gwi, "<~a~>T", SZ_INT, NULL)) + DECL_OB(const Type, t0, = gwi_mk_type(gwi, "T<~a~>", SZ_INT, NULL)) return gwi_add_type(gwi, t0); } diff --git a/tests/import/op_already_imported.gw b/tests/import/op_already_imported.gw index 2aeb3617..2bfc227d 100644 --- a/tests/import/op_already_imported.gw +++ b/tests/import/op_already_imported.gw @@ -1,2 +1,2 @@ #! [contains] already imported -<<<1 >>>; +<<< 1 >>>; diff --git a/tests/import/typedef_fail.c b/tests/import/typedef_fail.c index fed34adc..e3151146 100644 --- a/tests/import/typedef_fail.c +++ b/tests/import/typedef_fail.c @@ -9,7 +9,7 @@ #include "import.h" GWION_IMPORT(typedef_test) { - GWI_BB(gwi_typedef_ini(gwi, "int", "<~A~>Typedef")) - GWI_BB(gwi_typedef_ini(gwi, "int", "<~A~>Typedef")) + GWI_BB(gwi_typedef_ini(gwi, "int", "Typedef<~A~>")) + GWI_BB(gwi_typedef_ini(gwi, "int", "Typedef<~A~>")) return GW_OK; } diff --git a/tests/import/typedef_tmpl.c b/tests/import/typedef_tmpl.c index a395b7be..1ae96db9 100644 --- a/tests/import/typedef_tmpl.c +++ b/tests/import/typedef_tmpl.c @@ -9,7 +9,7 @@ #include "import.h" GWION_IMPORT(typedef_test) { - GWI_BB(gwi_typedef_ini(gwi, "<~A~>Ptr", "<~A~>Typedef")) + GWI_BB(gwi_typedef_ini(gwi, "Ptr<~A~>", "Typedef<~A~>")) GWI_OB(gwi_typedef_end(gwi, ae_flag_none)) return GW_OK; } diff --git a/tests/import/union_tmpl.c b/tests/import/union_tmpl.c index 341379d3..aa65700d 100644 --- a/tests/import/union_tmpl.c +++ b/tests/import/union_tmpl.c @@ -9,7 +9,7 @@ #include "import.h" GWION_IMPORT(union_test) { - GWI_BB(gwi_union_ini(gwi, "<~A~>U", NULL)) + GWI_BB(gwi_union_ini(gwi, "U<~A~>", NULL)) GWI_BB(gwi_union_add(gwi,"float", "f")) GWI_BB(gwi_union_add(gwi,"int", "i")) GWI_BB(gwi_union_add(gwi,"A", "a")) diff --git a/tests/import/union_tmpl_fail.c b/tests/import/union_tmpl_fail.c index 05314645..57da35a8 100644 --- a/tests/import/union_tmpl_fail.c +++ b/tests/import/union_tmpl_fail.c @@ -9,7 +9,7 @@ #include "import.h" GWION_IMPORT(union_test) { - GWI_BB(gwi_union_ini(gwi, "<~A~>U", "My")) + GWI_BB(gwi_union_ini(gwi, "U<~A~>", "My")) GWI_BB(gwi_union_add(gwi,"float", "f")) GWI_BB(gwi_union_add(gwi,"int", "i")) GWI_BB(gwi_union_add(gwi,"A", "a")) diff --git a/tests/import/union_tmpl_fail2.c b/tests/import/union_tmpl_fail2.c index 47bb3be6..994dd3ee 100644 --- a/tests/import/union_tmpl_fail2.c +++ b/tests/import/union_tmpl_fail2.c @@ -9,11 +9,11 @@ #include "import.h" GWION_IMPORT(union_test) { - GWI_BB(gwi_union_ini(gwi, "<~A~>U", NULL)) + GWI_BB(gwi_union_ini(gwi, "U<~A~>", NULL)) GWI_BB(gwi_union_add(gwi,"float", "f")) GWI_BB(gwi_union_add(gwi,"int", "i")) GWI_BB(gwi_union_add(gwi,"A", "a")) - GWI_BB(gwi_union_ini(gwi, "<~A~>U", NULL)) + GWI_BB(gwi_union_ini(gwi, "U<~A~>", NULL)) GWI_OB(gwi_union_end(gwi, 0)) return GW_OK; } diff --git a/tests/import/union_tmpl_fail3.c b/tests/import/union_tmpl_fail3.c index b3736a82..f8fa4eb9 100644 --- a/tests/import/union_tmpl_fail3.c +++ b/tests/import/union_tmpl_fail3.c @@ -9,7 +9,7 @@ #include "import.h" GWION_IMPORT(union_test) { - GWI_BB(gwi_union_ini(gwi, "<~A~>U", "Test")) + GWI_BB(gwi_union_ini(gwi, "U<~A~>", "Test")) GWI_BB(gwi_union_add(gwi,"float", "f")) GWI_BB(gwi_union_add(gwi,"int", "i")) GWI_BB(gwi_union_add(gwi,"A", "a"))