From 12c9bf95bf4723a61e24d44c85c9fc3992a6a36d Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=A9mie=20Astor?= Date: Sun, 15 Nov 2020 11:46:31 +0100 Subject: [PATCH] Clean ast (#223) * :art: Remove goto * :art: Coding style (one line if/else) * :art: Coding style (variable naming) * :art: Coding style (one line if/else [fix]) * :art: Remove goto [fix] * :art: const and ternary * :art: More const * :art: More const, again * :art: Do not expand structures * :art: Remove useless calls * :art: Rewrite ensure_tmpl * :art: Split functions, remove (now) useless variables * :art: move functions closer to each other * :art: Messing with git and myself * :art: Somehow getting it right * :art: Avoid memleak, small functions * :art: Fixes * :art: Improve checking :smile: * :bug: Fix array (somehow forgotten before) * :art: Remove useless addr * :art: Remove useless cast->func * :art: Resolve some conflicts * :art: Remove useless Id_List->pos * :art: Clean headers * :art: Indentation * :art: Improve stmt location * :art: Improve exp location * :art: Upate * :wrench: Test preprocessor options * :wrench: Update ast * :art: Update plugin infos --- README.md | 2 +- ast | 2 +- include/env/func.h | 4 + include/import/item.h | 4 +- plug | 2 +- src/emit/emit.c | 7 +- src/import/import_checker.c | 4 +- src/import/import_item.c | 6 +- src/import/import_special.c | 1 - src/import/import_udef.c | 2 +- src/lib/array.c | 2 +- src/lib/engine.c | 1 - src/lib/lib_func.c | 7 +- src/lib/object_op.c | 2 +- src/parse/check.c | 4 +- src/parse/func_resolve_tmpl.c | 187 ++++++++++++++++------------------ src/parse/scan0.c | 1 - src/parse/scan1.c | 1 - tests/sh/opt.sh | 16 ++- 19 files changed, 125 insertions(+), 130 deletions(-) diff --git a/README.md b/README.md index f3b4ce87..5619ea2d 100644 --- a/README.md +++ b/README.md @@ -100,7 +100,7 @@ mv Jack.so ~/.gwplug Repeat for the other plugins mentioned. The `Soundpipe` plugin requires the soundpipe library, which we hope to have build seamlessly for you when you build the `Soundpipe` module, but we're not quite there yet. Please ask for help if this isn't working. When all those plugin `.so` files are in your `~/.gwplug` directory, you should be able to run a Gwion program that makes sound! In `plug/Modules` there's a `test.gw` program which plays a sine wave for 5 seconds. If the `gwion` you built is still in the base dir of your cloned repo, from the -`plug/Modules` subdirectory you should be able to run `../../gwion -d jack test.gw` and hear some sound! +`plug/Modules` subdirectory you should be able to run `../../gwion -d Jack test.gw` and hear some sound! ## Installation diff --git a/ast b/ast index 126cdeb1..bea5d76b 160000 --- a/ast +++ b/ast @@ -1 +1 @@ -Subproject commit 126cdeb142c8764f331c530ad0cf15494d129c73 +Subproject commit bea5d76b2bdb10a0cbc68b0549d1202db7e5f9e6 diff --git a/include/env/func.h b/include/env/func.h index b0b6203c..fbde81bb 100644 --- a/include/env/func.h +++ b/include/env/func.h @@ -29,6 +29,10 @@ ANN static inline void func_remref(const Func f, struct Gwion_ *const gwion) { i static inline int fflag(const Func f, const enum fflag flag) { return (f->fflag & flag) == flag; } + +static inline int safe_fflag(const Func f, const enum fflag flag) { + return f ? ((f->fflag & flag) == flag) : 0; +} #ifndef __cplusplus static inline void set_fflag(const Func f, const enum fflag flag) { f->fflag |= flag; diff --git a/include/import/item.h b/include/import/item.h index cc5d3e22..48ba820f 100644 --- a/include/import/item.h +++ b/include/import/item.h @@ -2,7 +2,7 @@ #define __IMPORT_ITEM ANN m_int gwi_item_ini(const Gwi gwi, const m_str type, const m_str name); -ANN2(1) m_int gwi_item_end(const Gwi gwi, const ae_flag flag, const m_uint* addr); -#define gwi_item_end(a, b, c) gwi_item_end(a, (const ae_flag)(b), (const m_uint*)c) +ANN2(1) m_int gwi_item_end(const Gwi gwi, const ae_flag flag, m_uint *const addr); +#define gwi_item_end(a, b, c) gwi_item_end(a, (const ae_flag)(b), (m_uint*const)c) ANN void ck_clean_item(MemPool, ImportCK*); #endif diff --git a/plug b/plug index db905ac8..9fe63d36 160000 --- a/plug +++ b/plug @@ -1 +1 @@ -Subproject commit db905ac89bb75021a499bfdd87b64e2ff5589853 +Subproject commit 9fe63d363b74109f2dce1cae20232556aee7d55b diff --git a/src/emit/emit.c b/src/emit/emit.c index 410b0b13..add8932d 100644 --- a/src/emit/emit.c +++ b/src/emit/emit.c @@ -15,7 +15,6 @@ #include "operator.h" #include "import.h" #include "match.h" -#include "parser.h" #include "specialid.h" #include "vararg.h" @@ -710,8 +709,8 @@ ANN static m_bool emit_exp_decl_global(const Emitter emit, const Exp_Decl *decl, CHECK_BB(emit_instantiate_object(emit, type, array, is_ref)) const Instr instr = emit_kind(emit, v->type->size, !struct_ctor(v) ? emit_addr : 1, dotstatic); v->d.ptr = mp_calloc2(emit->gwion->mp, v->type->size); -if(isa(type, emit->gwion->type[et_union]) < 0) - set_vflag(v, vflag_direct);// mpalloc + if(isa(type, emit->gwion->type[et_union]) < 0) + set_vflag(v, vflag_direct);// mpalloc instr->m_val = (m_uint)v->d.ptr; instr->m_val2 = v->type->size; if(is_obj && (is_array || !is_ref) && !GET_FLAG(decl->td, ref)) { @@ -1711,7 +1710,7 @@ ANN static m_bool emit_union_def(const Emitter emit, const Union_Def udef) { type_decl->flag = udef->flag; const Var_Decl var_decl = new_var_decl(emit->gwion->mp, udef->xid, NULL, loc_cpy(emit->gwion->mp, udef->pos)); const Var_Decl_List var_decl_list = new_var_decl_list(emit->gwion->mp, var_decl, NULL); - const Exp exp = new_exp_decl(emit->gwion->mp, type_decl, var_decl_list); + const Exp exp = new_exp_decl(emit->gwion->mp, type_decl, var_decl_list, loc_cpy(emit->gwion->mp, udef->pos)); exp->d.exp_decl.type = udef->value->type; var_decl->value = udef->value; const m_bool ret = emit_exp_decl(emit, &exp->d.exp_decl); diff --git a/src/import/import_checker.c b/src/import/import_checker.c index 4b556234..416a22d7 100644 --- a/src/import/import_checker.c +++ b/src/import/import_checker.c @@ -74,7 +74,7 @@ ANN Symbol str2sym(const Gwion gwion, const m_str path, const loc_t pos) { // only in enum.c ANN ID_List str2symlist(const Gwion gwion, const m_str path, const loc_t pos) { DECL_OO(const Symbol, sym, = str2sym(gwion, path, pos)) - return new_id_list(gwion->mp, sym, loc_cpy(gwion->mp, pos)); + return new_id_list(gwion->mp, sym); } ANN Var_Decl str2var(const Gwion gwion, const m_str path, const loc_t pos) { @@ -101,7 +101,7 @@ ANN static ID_List _tmpl_list(const Gwion gwion, struct td_checker *tdc) { if(!(next = _tmpl_list(gwion, tdc)) || next == (ID_List)GW_ERROR) return (ID_List)GW_ERROR; } - const ID_List list = new_id_list(gwion->mp, sym, loc_cpy(gwion->mp, tdc->pos)); + const ID_List list = new_id_list(gwion->mp, sym); list->next = next; return list; } diff --git a/src/import/import_item.c b/src/import/import_item.c index 3639445f..de57a59f 100644 --- a/src/import/import_item.c +++ b/src/import/import_item.c @@ -19,7 +19,7 @@ ANN m_int gwi_item_ini(const Gwi gwi, const restrict m_str type, const restrict ANN static m_int gwi_item_tmpl(const Gwi gwi) { const MemPool mp = gwi->gwion->mp; - const Stmt stmt = new_stmt_exp(mp, ae_stmt_exp, gwi->ck->exp); + const Stmt stmt = new_stmt_exp(mp, ae_stmt_exp, gwi->ck->exp, loc(gwi)); const Stmt_List slist = new_stmt_list(mp, stmt, NULL); Section* section = new_section_stmt_list(mp, slist); const Ast body = new_ast(mp, section, NULL); @@ -30,15 +30,15 @@ ANN static m_int gwi_item_tmpl(const Gwi gwi) { } #undef gwi_item_end -ANN2(1) m_int gwi_item_end(const Gwi gwi, const ae_flag flag, const m_uint* addr) { +ANN2(1) m_int gwi_item_end(const Gwi gwi, const ae_flag flag, m_uint *const addr) { CHECK_BB(ck_ok(gwi, ck_item)) const Env env = gwi->gwion->env; - gwi->ck->exp->d.exp_decl.list->self->addr = (m_uint*)addr; gwi->ck->exp->d.exp_decl.td->flag = flag; if(env->class_def && tflag(env->class_def, tflag_tmpl)) return gwi_item_tmpl(gwi); CHECK_BB(traverse_exp(env, gwi->ck->exp)) const Value value = gwi->ck->exp->d.exp_decl.list->self->value; + value->d.ptr = addr; set_vflag(value, vflag_builtin); if(!env->class_def) SET_FLAG(value, global); diff --git a/src/import/import_special.c b/src/import/import_special.c index 6a518116..2c242db3 100644 --- a/src/import/import_special.c +++ b/src/import/import_special.c @@ -14,7 +14,6 @@ #include "import.h" #include "gwi.h" #include "gwi.h" -#include "parser.h" #include "specialid.h" #include "pass.h" diff --git a/src/import/import_udef.c b/src/import/import_udef.c index aaa603ff..8c58aa22 100644 --- a/src/import/import_udef.c +++ b/src/import/import_udef.c @@ -19,7 +19,7 @@ ANN Exp make_exp(const Gwi gwi, const m_str type, const m_str name) { DECL_OO(Type_Decl*, td, = gwi_str2decl(gwi, type)) const Var_Decl_List vlist = gwi_str2varlist(gwi, name); if(vlist) - return new_exp_decl(gwi->gwion->mp, td, vlist); + return new_exp_decl(gwi->gwion->mp, td, vlist, loc(gwi)); free_type_decl(gwi->gwion->mp, td); return NULL; } diff --git a/src/lib/array.c b/src/lib/array.c index 0020a0ae..8f378e50 100644 --- a/src/lib/array.c +++ b/src/lib/array.c @@ -138,7 +138,7 @@ static MFUN(vm_vector_cap) { } ANN static Type get_array_type(Type t) { - while(t->info->base_type) + while(t->array_depth && t->info->base_type) t = t->info->base_type; return t; } diff --git a/src/lib/engine.c b/src/lib/engine.c index 9d55f6eb..3688593f 100644 --- a/src/lib/engine.c +++ b/src/lib/engine.c @@ -12,7 +12,6 @@ #include "import.h" #include "gwi.h" #include "engine.h" -#include "parser.h" #include "lang_private.h" #include "specialid.h" #include "gack.h" diff --git a/src/lib/lib_func.c b/src/lib/lib_func.c index 40e06057..4f33ccef 100644 --- a/src/lib/lib_func.c +++ b/src/lib/lib_func.c @@ -238,7 +238,6 @@ static OP_CHECK(opck_fptr_cast) { struct FptrInfo info = { cast->exp->info->type->info->func, t->info->func, cast->exp, exp_self(cast)->pos }; CHECK_BO(fptr_do(env, &info)) - cast->func = cast->exp->info->type->info->func; return t; } @@ -283,9 +282,11 @@ static OP_EMIT(opem_fptr_impl) { ANN Type check_exp_unary_spork(const Env env, const Stmt code); ANN static void fork_exp(const Env env, const Exp_Unary* unary) { - const Stmt stmt = new_stmt_exp(env->gwion->mp, ae_stmt_exp, unary->exp); + const Stmt stmt = new_stmt_exp(env->gwion->mp, ae_stmt_exp, unary->exp, + loc_cpy(env->gwion->mp, unary->exp->pos)); const Stmt_List list = new_stmt_list(env->gwion->mp, stmt, NULL); - const Stmt code = new_stmt_code(env->gwion->mp, list); + const Stmt code = new_stmt_code(env->gwion->mp, list, + loc_cpy(env->gwion->mp, unary->exp->pos)); ((Exp_Unary*)unary)->exp = NULL; ((Exp_Unary*)unary)->code = code; } diff --git a/src/lib/object_op.c b/src/lib/object_op.c index 18545e9e..4b7f7111 100644 --- a/src/lib/object_op.c +++ b/src/lib/object_op.c @@ -407,7 +407,7 @@ ANN static inline Symbol dot_symbol(SymTable *st, const Value v) { ANN Exp symbol_owned_exp(const Gwion gwion, const Symbol *data) { const Value v = prim_self(data)->value; const Exp base = new_prim_id(gwion->mp, dot_symbol(gwion->st, v), loc_cpy(gwion->mp, prim_pos(data))); - const Exp dot = new_exp_dot(gwion->mp, base, *data); + const Exp dot = new_exp_dot(gwion->mp, base, *data, loc_cpy(gwion->mp, prim_pos(data))); const Type owner = v->from->owner_class; dot->d.exp_dot.t_base = dot->d.exp_dot.base->info->type = !GET_FLAG(v, static) ? owner : type_class(gwion, owner); diff --git a/src/parse/check.c b/src/parse/check.c index c8d0b421..b5b903a0 100644 --- a/src/parse/check.c +++ b/src/parse/check.c @@ -758,6 +758,8 @@ ANN static m_bool predefined_call(const Env env, const Type t, const loc_t pos) ANN static Type check_exp_call(const Env env, Exp_Call* exp) { if(exp->tmpl) { CHECK_OO(check_exp(env, exp->func)) + if(exp->args) + CHECK_OO(check_exp(env, exp->args)) const Type t = actual_type(env->gwion, unflag_type(exp->func->info->type)); if(isa(t, env->gwion->type[et_function]) < 0) ERR_O(exp_self(exp)->pos, _("template call of non-function value.")) @@ -765,8 +767,6 @@ ANN static Type check_exp_call(const Env env, Exp_Call* exp) { ERR_O(exp_self(exp)->pos, _("template call of non-template function.")) if(t->info->func->def->base->tmpl->call) { if(env->func == t->info->func) { - if(exp->args) - CHECK_OO(check_exp(env, exp->args)) exp->m_func = env->func; return env->func->def->base->ret_type; } else diff --git a/src/parse/func_resolve_tmpl.c b/src/parse/func_resolve_tmpl.c index 994f4966..46a61bc4 100644 --- a/src/parse/func_resolve_tmpl.c +++ b/src/parse/func_resolve_tmpl.c @@ -16,11 +16,10 @@ #include "tmp_resolve.h" struct ResolverArgs { - Value v; + const Value v; const Exp_Call *e; - m_str tmpl_name; - Func m_func; - Type_List types; + const m_str tmpl_name; + const Type_List types; }; ANN static inline Value template_get_ready(const Env env, const Value v, const m_str tmpl, const m_uint i) { @@ -29,120 +28,97 @@ ANN static inline Value template_get_ready(const Env env, const Value v, const m nspc_lookup_value1(v->from->owner, sym); } -ANN static m_bool check_call(const Env env, const Exp_Call* exp) { - ae_exp_t et = exp->func->exp_type; - if(et != ae_exp_primary && et != ae_exp_dot && et != ae_exp_cast) - ERR_B(exp->func->pos, _("invalid expression for function call.")) - CHECK_OB(check_exp(env, exp->func)) - if(exp->args) - CHECK_OB(check_exp(env, exp->args)) - return GW_OK; +ANN static inline m_bool tmpl_valid(const Env env, const Func_Def fdef) { + return safe_fflag(fdef->base->func, fflag_valid) || + check_traverse_fdef(env, fdef) > 0; } ANN static Func ensure_tmpl(const Env env, const Func_Def fdef, const Exp_Call *exp) { - const m_bool ret = (fdef->base->func && fflag(fdef->base->func, fflag_valid)) || check_traverse_fdef(env, fdef) > 0; - if(ret) { - const Func f = fdef->base->func; - const Func next = f->next; - f->next = NULL; - const Func func = find_func_match(env, f, exp->args); - f->next = next; - if(func) { - set_fflag(func, fflag_tmpl); - set_fflag(func, fflag_valid); - return func; - } - } - return NULL; + if(!tmpl_valid(env, fdef)) + return NULL; + const Func f = fdef->base->func; + const Func next = f->next; + f->next = NULL; + const Func func = find_func_match(env, f, exp->args); + f->next = next; + if(func) + set_fflag(func, fflag_tmpl | fflag_valid); + return func; } -ANN static Func fptr_match(const Env env, struct ResolverArgs* f_ptr_args) { - const Value v = f_ptr_args->v; - const m_str tmpl_name = f_ptr_args->tmpl_name; - const Exp_Call *exp = f_ptr_args->e; - Type_List types = f_ptr_args->types; - const Symbol sym = func_symbol(env, v->from->owner->name, v->name, tmpl_name, 0); +ANN static inline Func ensure_fptr(const Env env, struct ResolverArgs* ra, const Fptr_Def fptr) { + CHECK_BO(traverse_fptr_def(env, fptr)) + return find_func_match(env, fptr->base->func, ra->e->args); +} + +ANN static Func fptr_match(const Env env, struct ResolverArgs* ra) { + const Value v = ra->v; + const Symbol sym = func_symbol(env, v->from->owner->name, v->name, ra->tmpl_name, 0); const Type exists = nspc_lookup_type0(v->from->owner, sym); if(exists) return exists->info->func; - - Func m_func = f_ptr_args->m_func; - Func_Def base = v->d.func_ref ? v->d.func_ref->def : exp->func->info->type->info->func->def; - Func_Base *fbase = cpy_func_base(env->gwion->mp, base->base); + const Func_Def base = v->d.func_ref ? v->d.func_ref->def : ra->e->func->info->type->info->func->def; + const Tmpl tmpl = { .list=base->base->tmpl->list, .call=ra->types }; + CHECK_BO(template_push_types(env, &tmpl)); + Func_Base *const fbase = cpy_func_base(env->gwion->mp, base->base); fbase->xid = sym; fbase->tmpl->base = 0; - fbase->tmpl->call = cpy_type_list(env->gwion->mp, types); - if(template_push_types(env, fbase->tmpl) > 0) { - const Fptr_Def fptr = new_fptr_def(env->gwion->mp, fbase); - if(traverse_fptr_def(env, fptr) > 0 && - (base->base->ret_type = known_type(env, base->base->td)) && - (!exp->args || !!check_exp(env, exp->args))) { - m_func = find_func_match(env, fbase->func, exp->args); - nspc_pop_type(env->gwion->mp, env->curr); - if(m_func) - nspc_add_type_front(v->from->owner, sym, actual_type(env->gwion, m_func->value_ref->type)); - } - if(fptr->type) - type_remref(fptr->type, env->gwion); - free_fptr_def(env->gwion->mp, fptr); - } + fbase->tmpl->call = cpy_type_list(env->gwion->mp, ra->types); + const Fptr_Def fptr = new_fptr_def(env->gwion->mp, fbase); + const Func m_func = ensure_fptr(env, ra, fptr); + if(m_func) + nspc_add_type_front(v->from->owner, sym, actual_type(env->gwion, m_func->value_ref->type)); + if(fptr->type) + type_remref(fptr->type, env->gwion); + free_fptr_def(env->gwion->mp, fptr); + nspc_pop_type(env->gwion->mp, env->curr); return m_func; } -ANN static Func func_match(const Env env, struct ResolverArgs* f_ptr_args) { - const Value v = f_ptr_args->v; - const m_str tmpl_name = f_ptr_args->tmpl_name; - const Exp_Call *exp = f_ptr_args->e; - Func m_func = f_ptr_args->m_func; - Type_List types = f_ptr_args->types; - for(m_uint i = 0; i < v->from->offset + 1; ++i) { - const Value exists = template_get_ready(env, v, tmpl_name, i); - if(exists) { - if(env->func == exists->d.func_ref) { - if(check_call(env, exp) < 0 || - !find_func_match(env, env->func, exp->args)) - continue; - m_func = env->func; - break; - } - if((m_func = ensure_tmpl(env, exists->d.func_ref->def, exp))) - break; - } else { - const Value value = template_get_ready(env, v, "template", i); - if(!value) - continue; - if(vflag(v, vflag_builtin)) - set_vflag(value, vflag_builtin); - const Func_Def fdef = (Func_Def)cpy_func_def(env->gwion->mp, value->d.func_ref->def); - fdef->base->tmpl->call = cpy_type_list(env->gwion->mp, types); - fdef->base->tmpl->base = i; - if((m_func = ensure_tmpl(env, fdef, exp))) { - break; - } - if(!fdef->base->func) { - free_func_def(env->gwion->mp, fdef); - } - } +ANN static Func tmpl_exists(const Env env, struct ResolverArgs* ra, const Value exists) { + if(env->func == exists->d.func_ref) + return find_func_match(env, env->func, ra->e->args) ? env->func : NULL; + return ensure_tmpl(env, exists->d.func_ref->def, ra->e); +} + +ANN static Func create_tmpl(const Env env, struct ResolverArgs* ra, const m_uint i) { + const Value value = template_get_ready(env, ra->v, "template", i); + if(!value) + return NULL; + if(vflag(ra->v, vflag_builtin)) + set_vflag(value, vflag_builtin); + const Func_Def fdef = (Func_Def)cpy_func_def(env->gwion->mp, value->d.func_ref->def); + fdef->base->tmpl->call = cpy_type_list(env->gwion->mp, ra->types); + fdef->base->tmpl->base = i; + const Func func = ensure_tmpl(env, fdef, ra->e); + if(!func && !fdef->base->func) + free_func_def(env->gwion->mp, fdef); + return func; +} + +ANN static Func func_match(const Env env, struct ResolverArgs* ra) { + for(m_uint i = 0; i < ra->v->from->offset + 1; ++i) { + const Value exists = template_get_ready(env, ra->v, ra->tmpl_name, i); + const Func func = exists ? + tmpl_exists(env, ra, exists) : create_tmpl(env, ra, i); + if(func) + return func; } - return m_func; + return NULL; } ANN static Func _find_template_match(const Env env, const Value v, const Exp_Call* exp) { - CHECK_BO(check_call(env, exp)) const Type_List types = exp->tmpl->call; - Func m_func = NULL, former = env->func; + const Func former = env->func; DECL_OO(const m_str, tmpl_name, = tl2str(env, types)) const m_uint scope = env->scope->depth; struct EnvSet es = { .env=env, .data=env, .func=(_exp_func)check_cdef, .scope=scope, .flag=tflag_check }; - struct ResolverArgs f_ptr_args = {.v = v, .e = exp, .tmpl_name = tmpl_name, m_func = m_func, .types = types}; + struct ResolverArgs ra = {.v = v, .e = exp, .tmpl_name = tmpl_name, .types = types}; CHECK_BO(envset_push(&es, v->from->owner_class, v->from->owner)) (void)env_push(env, v->from->owner_class, v->from->owner); - if(is_fptr(env->gwion, v->type)) { - m_func = fptr_match(env, &f_ptr_args); - } else { - m_func = func_match(env, &f_ptr_args); - } + const Func m_func = !is_fptr(env->gwion, v->type) ? + func_match(env, &ra) :fptr_match(env, &ra); free_mstr(env->gwion->mp, tmpl_name); if(es.run) envset_pop(&es, v->from->owner_class); @@ -151,21 +127,28 @@ ANN static Func _find_template_match(const Env env, const Value v, const Exp_Cal return m_func; } +ANN static inline m_bool check_call(const Env env, const Exp_Call* exp) { + const ae_exp_t et = exp->func->exp_type; + if(et != ae_exp_primary && et != ae_exp_dot && et != ae_exp_cast) + ERR_B(exp->func->pos, _("invalid expression for function call.")) + return GW_OK; +} + ANN Func find_template_match(const Env env, const Value value, const Exp_Call* exp) { + CHECK_BO(check_call(env, exp)) const Func f = _find_template_match(env, value, exp); if(f) return f; Type t = value->from->owner_class; while(t && t->nspc) { - Func_Def fdef = value->d.func_ref ? value->d.func_ref->def : value->type->info->func->def; + const Func_Def fdef = value->d.func_ref ? value->d.func_ref->def : value->type->info->func->def; const Value v = nspc_lookup_value0(t->nspc, fdef->base->xid); - if(!v) - goto next; - const Func f = _find_template_match(env, v, exp); - if(f) - return f; - next: - t = t->info->parent; + if(v) { + const Func f = _find_template_match(env, v, exp); + if(f) + return f; + } + t = t->info->parent; } ERR_O(exp_self(exp)->pos, _("arguments do not match for template call")) } diff --git a/src/parse/scan0.c b/src/parse/scan0.c index de2ba44a..ea84c0a1 100644 --- a/src/parse/scan0.c +++ b/src/parse/scan0.c @@ -5,7 +5,6 @@ #include "vm.h" #include "traverse.h" #include "template.h" -#include "parser.h" #include "parse.h" #include "object.h" #include "instr.h" diff --git a/src/parse/scan1.c b/src/parse/scan1.c index 03cc838d..4c6c6c9d 100644 --- a/src/parse/scan1.c +++ b/src/parse/scan1.c @@ -109,7 +109,6 @@ ANN static m_bool scan1_decl(const Env env, const Exp_Decl* decl) { tuple_contains(env, v); } else if(!env->scope->depth) set_vflag(v, vflag_fglobal);// file global - v->d.ptr = var->addr; if(GET_FLAG(decl->td, global)) SET_FLAG(v, global); if(!env->scope->depth) diff --git a/tests/sh/opt.sh b/tests/sh/opt.sh index 4cf3e21d..1c86d66a 100644 --- a/tests/sh/opt.sh +++ b/tests/sh/opt.sh @@ -1,5 +1,5 @@ #!/bin/bash -# [test] #21 +# [test] #24 n=0 [ "$1" ] && n="$1" @@ -90,10 +90,22 @@ run "$n" "invalid global type" "examples/complex/invalid_type0.gw examples/compl n=$((n+1)) run "$n" "invalid global func" "examples/complex/invalid_func0.gw examples/complex/invalid_func1.gw" "file" -# comma in module argument +# comma in module argument, uses the now deprecated -mpp n=$((n+1)) run "$n" "comma in module argument" "-mpp=-Dtest='\"dqs\,qs\"',-Dtsdl" "file" +# define +n=$((n+1)) +run "$n" "define" "-Dtest(a)=#a" "file" + +# undef +n=$((n+1)) +run "$n" "undef" "-Utest" "nofile" + +# include path +n=$((n+1)) +run "$n" "include path" "-I../Gwion" "file" + # test signal # mask asan output for now ./gwion -l1 &>/dev/null & -- 2.43.0