From 1966bbdd1db0cd0527e03d83d3c356d6eff3e478 Mon Sep 17 00:00:00 2001 From: fennecdjay Date: Tue, 25 Dec 2018 21:07:35 +0100 Subject: [PATCH] :art: Update grammar --- ast | 2 +- examples/array_lit.gw | 2 +- examples/binary_tmpl.gw | 2 +- examples/in_class_class.gw | 6 +++--- examples/template.gw | 16 ++++++++-------- examples/template_guess.gw | 2 +- examples/template_vararg.gw | 6 +++--- src/lib/instr.c | 2 +- src/parse/check.c | 8 ++++---- src/parse/scan1.c | 8 ++++++-- src/parse/scan2.c | 4 +++- tests/bug/Tester.gw | 4 ++-- tests/bug/template_no_guess.gw | 2 +- tests/error/cant_find_in_nspc.gw | 4 ++-- tests/error/named_union_global_private_static.gw | 2 +- tests/error/non_function_template.gw | 2 +- tests/error/template_class_no_type.gw | 2 +- tests/error/template_enough.gw | 2 +- tests/error/template_n_mismatch.gw | 8 ++++---- tests/error/template_no_match.gw | 10 +++++----- tests/error/template_non_member.gw | 2 +- tests/error/template_unknown.gw | 4 ++-- tests/error/type_not_template.gw | 2 +- tests/error/type_path_test.gw | 2 +- tests/error/union_global_private_static.gw | 2 +- tests/test_plugins/class_template.gw | 12 ++++++------ tests/test_plugins/extend_pair.gw | 2 +- tests/test_plugins/map2.gw | 2 +- tests/tree/auto_ptr.gw | 2 +- tests/tree/class_template.gw | 14 +++++++------- tests/tree/map.gw | 2 +- tests/tree/named_union_private_static.gw | 2 +- tests/tree/pair.gw | 2 +- tests/tree/static_template.gw | 4 ++-- tests/tree/template_class_ref.gw | 4 ++-- tests/tree/template_ternary.gw | 2 +- tests/tree/template_typedef.gw | 8 ++++---- 37 files changed, 84 insertions(+), 78 deletions(-) diff --git a/ast b/ast index 5f6b5408..ef1917e4 160000 --- a/ast +++ b/ast @@ -1 +1 @@ -Subproject commit 5f6b54084825368096489ced346db65dca4bb15e +Subproject commit ef1917e40d3cae04f108ba71a2f905bb4b714811 diff --git a/examples/array_lit.gw b/examples/array_lit.gw index 2c18fce6..accae62d 100644 --- a/examples/array_lit.gw +++ b/examples/array_lit.gw @@ -12,7 +12,7 @@ Object t[2][12][3][4][5]; int k[1][1]; -<<>>; +<<>>; [ 1.0, 2, 3, 4, 5 ]; [ #(0.0, 0.0) ]; diff --git a/examples/binary_tmpl.gw b/examples/binary_tmpl.gw index 8b030938..71a1ae83 100644 --- a/examples/binary_tmpl.gw +++ b/examples/binary_tmpl.gw @@ -1,4 +1,4 @@ -template“A” fun void test(A a) { <<>>; } +template fun void test(A a) { <<>>; } 1 => test; 1.3 => test; test(1); diff --git a/examples/in_class_class.gw b/examples/in_class_class.gw index 734d7406..e0ec4e4a 100644 --- a/examples/in_class_class.gw +++ b/examples/in_class_class.gw @@ -1,12 +1,12 @@ class C { - template“a” + template function void test(a var){ <<>>; } class D { int i;} } C c; - d; - @d_ref; +C->D d; +C->D @d_ref; <<< c, " ", d, d_ref >>>; diff --git a/examples/template.gw b/examples/template.gw index 9261b460..401d0c5d 100644 --- a/examples/template.gw +++ b/examples/template.gw @@ -1,13 +1,13 @@ -template “a” +template function void test (a var){ <<< var>>>; } -template “a, b” +template function void test (a var, b var2){ <<< var>>>; } //function void test (){ } -test“int”(1); -//test“float”(1.4); -//test“int”(3, 1.4); -//test“float”(3); +test(1); +//test(1.4); +//test(3, 1.4); +//test(3); //test(3, 1.4); -test“float, float”(3, 1.4); -//test“float, float, int”(3, 1.4); +test(3, 1.4); +//test(3, 1.4); diff --git a/examples/template_guess.gw b/examples/template_guess.gw index 886891f2..dcb87d0f 100644 --- a/examples/template_guess.gw +++ b/examples/template_guess.gw @@ -1,4 +1,4 @@ -template “A, B” +template function void test(A a, B b){<<>>;} test(1, 2.1); test(1.1, 2.1); diff --git a/examples/template_vararg.gw b/examples/template_vararg.gw index d860966f..79cddc89 100644 --- a/examples/template_vararg.gw +++ b/examples/template_vararg.gw @@ -1,8 +1,8 @@ -template “a” +template fun void test(...) { vararg.start; <<>>; vararg.end; } -test“int”(1, 2); -test“float”(1, 2, 3); +test(1, 2); +test(1, 2, 3); diff --git a/src/lib/instr.c b/src/lib/instr.c index 496c31ca..f70ffbb3 100644 --- a/src/lib/instr.c +++ b/src/lib/instr.c @@ -430,7 +430,7 @@ INSTR(AllocMember4) { GWDEBUG_EXE INSTR(DotStatic) { GWDEBUG_EXE const Type t = *(Type*)REG(-SZ_INT); m_uint *const data = (m_uint*)(t->nspc->class_data + instr->m_val); - *(m_uint*)REG(-SZ_INT) = *data; + *(m_uint*)REG(-SZ_INT) = data ? *data : 0; } INSTR(DotStatic2) { GWDEBUG_EXE diff --git a/src/parse/check.c b/src/parse/check.c index f46e93b2..da48ad87 100644 --- a/src/parse/check.c +++ b/src/parse/check.c @@ -64,15 +64,15 @@ ANN static m_bool check_fptr_decl(const Env env, const Var_Decl var) { return GW_OK; ERR_B(var->pos, "can't use non public typedef at global scope.") } - if(isa(type, env->class_def) < 0) - ERR_B(var->pos, "can't use static variables for member function.") + if(isa(type, env->class_def) < 0 && !GET_FLAG(func, global)) + ERR_B(var->pos, "can't use non global fptr of other class.") if(GET_FLAG(func, member)) { if(GET_FLAG(v, static)) ERR_B(var->pos, "can't use static variables for member function.") if(!GET_FLAG(v, member)) ERR_B(var->pos, "can't use member variables for static function.") - } else if(GET_FLAG(v, member)) - ERR_B(var->pos, "can't use member variables for static function.") + } //else if(GET_FLAG(v, member)) + //ERR_B(var->pos, "can't use member variables for static function.") return GW_OK; } diff --git a/src/parse/scan1.c b/src/parse/scan1.c index 24ddf79e..be8576cb 100644 --- a/src/parse/scan1.c +++ b/src/parse/scan1.c @@ -52,7 +52,7 @@ ANN static Type scan1_exp_decl_type(const Env env, const Exp_Decl* decl) { if(!GET_FLAG(decl->td, ref) && t == env->class_def) ERR_O(decl->self->pos, "...(note: object of type '%s' declared inside itself)", t->name) } - if(GET_FLAG(decl->td, global) && env->class_def) + if(GET_FLAG(decl->td, global) && env->class_def) // forbid this ? UNSET_FLAG(decl->td, global); } if(GET_FLAG(t, template)) @@ -200,6 +200,8 @@ ANN m_bool scan1_stmt_enum(const Env env, const Stmt_Enum stmt) { GWDEBUG_EXE SET_FLAG(v, static); if(GET_FLAG(stmt, private)) SET_FLAG(v, private); + else if(GET_FLAG(stmt, protect)) + SET_FLAG(v, protect); } SET_FLAG(v, const | ae_flag_enum | ae_flag_checked); nspc_add_value(stmt->t->owner, list->xid, v); @@ -242,8 +244,10 @@ ANN static inline m_bool scan1_stmt_union_array(const Array_Sub array) { GWDEBUG ANN m_bool scan1_stmt_union(const Env env, const Stmt_Union stmt) { GWDEBUG_EXE Decl_List l = stmt->l; const m_uint scope = union_push(env, stmt); - if(stmt->xid || stmt->type_xid) + if(stmt->xid || stmt->type_xid) { UNSET_FLAG(stmt, private); + UNSET_FLAG(stmt, protect); + } do { const Exp_Decl decl = l->self->d.exp_decl; Var_Decl_List list = decl.list; diff --git a/src/parse/scan2.c b/src/parse/scan2.c index 99a1139c..2f31ed83 100644 --- a/src/parse/scan2.c +++ b/src/parse/scan2.c @@ -84,6 +84,8 @@ ANN static Value scan2_func_assign(const Env env, const Func_Def d, else SET_FLAG(v, static); if(GET_FLAG(d, private)) SET_FLAG(v, private); + else if(GET_FLAG(d, protect)) + SET_FLAG(v, protect); } d->func = v->d.func_ref = f; return f->value_ref = v; @@ -462,7 +464,7 @@ ANN m_bool scan2_func_def(const Env env, const Func_Def f) { GWDEBUG_EXE m_uint scope = env->scope; if(GET_FLAG(f, global)) scope = env_push_global(env); - CHECK_OB((value = func_create(env, f, overload, func_name))) + CHECK_OB((value = func_create(env, f, overload, func_name))) if(GET_FLAG(f, global)) env_pop(env, scope); } else diff --git a/tests/bug/Tester.gw b/tests/bug/Tester.gw index b078f866..baa73dcf 100644 --- a/tests/bug/Tester.gw +++ b/tests/bug/Tester.gw @@ -1,8 +1,8 @@ class Tester { - template“A” + template function int assert_equal(string description, A a, A b){ if(a == b) return 0; return 1; } - template“A” + template function int assert_not_equal(string description, A a, A b){ if(a != b) return 0; return 1; } } diff --git a/tests/bug/template_no_guess.gw b/tests/bug/template_no_guess.gw index 2bdf20ea..aaa3b36f 100644 --- a/tests/bug/template_no_guess.gw +++ b/tests/bug/template_no_guess.gw @@ -1,4 +1,4 @@ -//template “a” +//template function void test(){} //function void test(int i[]){<<>>;} //function void test(Object o){} diff --git a/tests/error/cant_find_in_nspc.gw b/tests/error/cant_find_in_nspc.gw index fede3edb..cbab52eb 100644 --- a/tests/error/cant_find_in_nspc.gw +++ b/tests/error/cant_find_in_nspc.gw @@ -6,9 +6,9 @@ class C { } class E extends C { - d; + C->D d; } class F { - d; + F->D d; } diff --git a/tests/error/named_union_global_private_static.gw b/tests/error/named_union_global_private_static.gw index 657baba5..b202b70e 100644 --- a/tests/error/named_union_global_private_static.gw +++ b/tests/error/named_union_global_private_static.gw @@ -1,2 +1,2 @@ // [contains] can only be used at class scope. -union private static { int i; } u; +union static private { int i; } u; diff --git a/tests/error/non_function_template.gw b/tests/error/non_function_template.gw index d650d2e6..795346a0 100644 --- a/tests/error/non_function_template.gw +++ b/tests/error/non_function_template.gw @@ -1,3 +1,3 @@ // [contains] template call of non-function value int test; -test“int”(); +test(); diff --git a/tests/error/template_class_no_type.gw b/tests/error/template_class_no_type.gw index 0939e71f..27e01621 100644 --- a/tests/error/template_class_no_type.gw +++ b/tests/error/template_class_no_type.gw @@ -1,5 +1,5 @@ // [contains] you must provide template types -template“A” +template class C { A a; } diff --git a/tests/error/template_enough.gw b/tests/error/template_enough.gw index fa3481c8..1acbf217 100644 --- a/tests/error/template_enough.gw +++ b/tests/error/template_enough.gw @@ -1,4 +1,4 @@ // [contains] - template“a, b” + template function void test(){} test(); diff --git a/tests/error/template_n_mismatch.gw b/tests/error/template_n_mismatch.gw index 6fe668b0..97dc0cf1 100644 --- a/tests/error/template_n_mismatch.gw +++ b/tests/error/template_n_mismatch.gw @@ -1,8 +1,8 @@ // [contains] arguments do not match for template call -template “i” +template function void test(){ <<<"func">>>;} -template “i” +template function void test(int i){<<<"other func">>>;} -test“int, float, int”(); -//test“int”(); +test(); +//test(); diff --git a/tests/error/template_no_match.gw b/tests/error/template_no_match.gw index 06854139..e95d70c0 100644 --- a/tests/error/template_no_match.gw +++ b/tests/error/template_no_match.gw @@ -1,12 +1,12 @@ // [contains] arguments do not match for template call class C { - template “a” + template function void test(float f) {} - template “a” + template function void test() {} } C c; -//c.test“int”(); -c.test“int”(2.3); -c.test“int”(2.3, 2.3); +//c.test(); +c.test(2.3); +c.test(2.3, 2.3); diff --git a/tests/error/template_non_member.gw b/tests/error/template_non_member.gw index a4662255..f25211d4 100644 --- a/tests/error/template_non_member.gw +++ b/tests/error/template_non_member.gw @@ -1,2 +1,2 @@ // [contains] - Math.rand“int”(); + Math.rand(); diff --git a/tests/error/template_unknown.gw b/tests/error/template_unknown.gw index fe8629d0..b380cc81 100644 --- a/tests/error/template_unknown.gw +++ b/tests/error/template_unknown.gw @@ -1,5 +1,5 @@ // [contains] unknown type - template“my_type” + template function void my_function() { <<<"test">>>; } -my_function“unknown_type”(); +my_function(); diff --git a/tests/error/type_not_template.gw b/tests/error/type_not_template.gw index 5832bdc0..b9f747d8 100644 --- a/tests/error/type_not_template.gw +++ b/tests/error/type_not_template.gw @@ -1,2 +1,2 @@ // [contains] is not template -“int”Object o; +Object o; diff --git a/tests/error/type_path_test.gw b/tests/error/type_path_test.gw index b62aa0b5..c604e5d7 100644 --- a/tests/error/type_path_test.gw +++ b/tests/error/type_path_test.gw @@ -1,2 +1,2 @@ // [contains] unknown type -function void test( a){} +function void test(B->C a){} diff --git a/tests/error/union_global_private_static.gw b/tests/error/union_global_private_static.gw index 6b410044..2564afc9 100644 --- a/tests/error/union_global_private_static.gw +++ b/tests/error/union_global_private_static.gw @@ -1,2 +1,2 @@ // [contains] can only be used at class scope. -union private static { int i; }; +union static private { int i; }; diff --git a/tests/test_plugins/class_template.gw b/tests/test_plugins/class_template.gw index a090ee93..f72be7aa 100644 --- a/tests/test_plugins/class_template.gw +++ b/tests/test_plugins/class_template.gw @@ -1,15 +1,15 @@ //class child {} -//template“A, B” +//template //class C{ A key; B value; } -//“int, int”C c1; -//“float, float”C c2; +//C c1; +//C c2; //<<>>; //<<>>; //<<>>; -“int, int”ClassTemplate ct; +ClassTemplate ct; <<>>; -//“float, float”ClassTemplate ct2; +//ClassTemplate ct2; //<<>>; -//“child, float”ClassTemplate ct3; +//ClassTemplate ct3; //<<>>; diff --git a/tests/test_plugins/extend_pair.gw b/tests/test_plugins/extend_pair.gw index 7676cc9b..48354420 100644 --- a/tests/test_plugins/extend_pair.gw +++ b/tests/test_plugins/extend_pair.gw @@ -1,4 +1,4 @@ -“int, int”PairExt p; +PairExt p; <<

>>; <<>>; <<>>; diff --git a/tests/test_plugins/map2.gw b/tests/test_plugins/map2.gw index b590df3a..9d804604 100644 --- a/tests/test_plugins/map2.gw +++ b/tests/test_plugins/map2.gw @@ -1,4 +1,4 @@ -“int, float”Map pp; +Map pp; <<>>; <<>>; <<>>; diff --git a/tests/tree/auto_ptr.gw b/tests/tree/auto_ptr.gw index b94cf261..a4e81bae 100644 --- a/tests/tree/auto_ptr.gw +++ b/tests/tree/auto_ptr.gw @@ -1,4 +1,4 @@ -“int”Ptr ptr; +Ptr ptr; int i[4]; for(auto@ a : i) <<<*a>>>; diff --git a/tests/tree/class_template.gw b/tests/tree/class_template.gw index bc9fccf9..8f44fb1a 100644 --- a/tests/tree/class_template.gw +++ b/tests/tree/class_template.gw @@ -1,22 +1,22 @@ -template“A, B” +template class C { A a; B b; fun A test() { <<<"lol">>>; } - template“C” + template fun void test2(C c) { <<>>; } } //<<>>; -“int, int”C c; -“float, int”C d; -“polar, int”C e; -“Vec3, int”C f; -“Object, int”C g; +C c; +C d; +C e; +C f; +C g; //C c; <<>>; <<>>; diff --git a/tests/tree/map.gw b/tests/tree/map.gw index 23c2c002..339e5f1e 100644 --- a/tests/tree/map.gw +++ b/tests/tree/map.gw @@ -1,4 +1,4 @@ -“int, int”Map pp; +Map pp; <<>>; <<>>; <<>>; diff --git a/tests/tree/named_union_private_static.gw b/tests/tree/named_union_private_static.gw index 8787d183..e5db91c9 100644 --- a/tests/tree/named_union_private_static.gw +++ b/tests/tree/named_union_private_static.gw @@ -1,4 +1,4 @@ -class C { union private static { int i; } u;<<>>; +class C { union static private { int i; } u;<<>>; } C c; <<>>; diff --git a/tests/tree/pair.gw b/tests/tree/pair.gw index f301b975..1ce7df88 100644 --- a/tests/tree/pair.gw +++ b/tests/tree/pair.gw @@ -1,4 +1,4 @@ -“float, int”Pair p; +Pair p; <<

>>; 1 => p.key; 2 => p.val; diff --git a/tests/tree/static_template.gw b/tests/tree/static_template.gw index 7bf83126..83275c58 100644 --- a/tests/tree/static_template.gw +++ b/tests/tree/static_template.gw @@ -1,10 +1,10 @@ -template “A” +template class C { A a; } class D { - static “int”C c; + static C c; } D d; diff --git a/tests/tree/template_class_ref.gw b/tests/tree/template_class_ref.gw index 683bda01..c8742fbc 100644 --- a/tests/tree/template_class_ref.gw +++ b/tests/tree/template_class_ref.gw @@ -1,5 +1,5 @@ -template“A” +template class C {} -“int”C ref; +C ref; <<>>; diff --git a/tests/tree/template_ternary.gw b/tests/tree/template_ternary.gw index 018faa24..56e4f518 100644 --- a/tests/tree/template_ternary.gw +++ b/tests/tree/template_ternary.gw @@ -1,4 +1,4 @@ -template“A” +template function void test(A a){} (maybe ? test : test)(1); diff --git a/tests/tree/template_typedef.gw b/tests/tree/template_typedef.gw index 539d694e..68c11396 100644 --- a/tests/tree/template_typedef.gw +++ b/tests/tree/template_typedef.gw @@ -1,16 +1,16 @@ -“int, int”Pair p; -typedef “int, int”Pair lol; +Pair p; +typedef Pair lol; lol t; <<>>; <<>>; class C extends lol { int i;} C c; <<>>; -template “A” class D { +template class D { <<<"lol">>>; int i; } -typedef “int”D Lol; +typedef D Lol; class E extends Lol { float f; } -- 2.43.0