From: fennecdjay Date: Fri, 20 Jan 2023 14:43:41 +0000 (+0100) Subject: :art: big update X-Git-Tag: nightly~207^2~4 X-Git-Url: http://10.10.0.4:5575/?a=commitdiff_plain;h=07e4320cd8546cd5156af70d2e8f46ddf676a8b3;p=gwion.git :art: big update --- diff --git a/ast b/ast index d87fc045..9c119d73 160000 --- a/ast +++ b/ast @@ -1 +1 @@ -Subproject commit d87fc045c20a0ae0eb83527b374eca08300f841b +Subproject commit 9c119d73b5482d11487ad1cc6c48dd47bda896ee diff --git a/compile_flags.txt b/compile_flags.txt index 9998e440..8de19c2d 100644 --- a/compile_flags.txt +++ b/compile_flags.txt @@ -1,4 +1,5 @@ -Iutil/include -Iast/include +-Iast/libprettyerr/src -Iinclude -Ifmt/include diff --git a/fmt b/fmt index c2c3ab9f..bee2f7b0 160000 --- a/fmt +++ b/fmt @@ -1 +1 @@ -Subproject commit c2c3ab9f1aa60c61729ce6345a516ffdc2087dcc +Subproject commit bee2f7b0dc9942e804aa12d2cf3c29914c38b834 diff --git a/include/env/nspc.h b/include/env/nspc.h index 10377682..a02c3ea2 100644 --- a/include/env/nspc.h +++ b/include/env/nspc.h @@ -51,12 +51,12 @@ extern ANN void nspc_commit(const Nspc); #define describe_lookups(A, b) \ describe_lookup0(A, b) describe_lookup1(A, b) describe_lookup2(A, b) -#define describe_nspc_func(A, b) \ - static inline ANN void nspc_add_##b(const Nspc n, const Symbol s, \ +#define describe_nspc_func(A, b, prefix) \ + static inline ANN void prefix##nspc_add_##b(const Nspc n, const Symbol s, \ const A a) { \ scope_add(n->info->b, (vtype)s, (vtype)a); \ } \ - static inline ANN void nspc_add_##b##_front(const Nspc n, const Symbol s, \ + static inline ANN void prefix##nspc_add_##b##_front(const Nspc n, const Symbol s, \ const A a) { \ map_set(&n->info->b->map, (vtype)s, (vtype)a); \ } \ @@ -68,8 +68,14 @@ extern ANN void nspc_commit(const Nspc); } \ describe_lookups(A, b) -describe_nspc_func(Value, value) describe_nspc_func(Type, type) - describe_nspc_func(Func, func) describe_nspc_func(Trait, trait) +typedef void (*nspc_add_value_t)(const Nspc n, const Symbol s, const Value a); +ANN void nspc_add_value(const Nspc n, const Symbol s, const Value a); +ANN void nspc_add_value_front(const Nspc n, const Symbol s, const Value a); +ANN void nspc_add_value_set_func(nspc_add_value_t add, nspc_add_value_t front); +describe_nspc_func(Value, value,_) +describe_nspc_func(Type, type,) +describe_nspc_func(Func, func,) +describe_nspc_func(Trait, trait,) /* howere there is no need for lookup_func0, push_func, pop_func */ ANN void did_you_mean_nspc(const Nspc, const char *); ANN void did_you_mean_type(const Type, const char *); diff --git a/include/env/value.h b/include/env/value.h index 67d24b39..c36b3dee 100644 --- a/include/env/value.h +++ b/include/env/value.h @@ -54,6 +54,6 @@ ANN static inline void defined_here(const Value v) { ANN static inline void valid_value(const Env env, const Symbol xid, const Value v) { set_vflag(v, vflag_valid); - nspc_add_value(env->curr, xid, v); + _nspc_add_value(env->curr, xid, v); } #endif diff --git a/include/gwion_env.h b/include/gwion_env.h index f9c7e135..387024d5 100644 --- a/include/gwion_env.h +++ b/include/gwion_env.h @@ -23,7 +23,7 @@ ANN static inline void gwerr_secondary_from(const m_str msg, const ValueFrom *fr } ANN static inline void declared_here(const Value v) { - gwerr_secondary_from("declared here", v->from); + gwerr_secondary_from((m_str)"declared here", v->from); } #endif diff --git a/include/pass.h b/include/pass.h index 813da10e..db978889 100644 --- a/include/pass.h +++ b/include/pass.h @@ -1,17 +1,12 @@ #ifndef __GWIONPASS #define __GWIONPASS -typedef union __attribute__((__transparent_union__)) { - Ast *ast; - m_bool * ret; -} PassArg; - struct Passes_ { struct Map_ map; struct Vector_ vec; }; // change this to gwion ? -typedef m_bool (*compilation_pass)(const Env, PassArg); +typedef m_bool (*compilation_pass)(const Env, Ast*); ANEW ANN struct Passes_ *new_passes(const Gwion); ANN void free_passes(MemPool mp, struct Passes_ *); diff --git a/plug b/plug index c08c81a8..bbd7aa68 160000 --- a/plug +++ b/plug @@ -1 +1 @@ -Subproject commit c08c81a8f29a441c94ee4ebb6b7c2e7efd0e074a +Subproject commit bbd7aa68843338c277b4a0b453c0da3181657bd1 diff --git a/src/compile.c b/src/compile.c index b017d7e8..145ebeb9 100644 --- a/src/compile.c +++ b/src/compile.c @@ -133,9 +133,13 @@ ANN static inline m_bool passes(struct Gwion_ *gwion, struct Compiler *c) { return ret; } +static pos_t pos = { 1 , 1 }; +void gwion_set_default_pos(const pos_t _pos) { + pos = _pos; +} ANN static inline m_bool _check(struct Gwion_ *gwion, struct Compiler *c) { struct AstGetter_ arg = {c->name, c->file, gwion->st, .ppa = gwion->ppa}; - CHECK_OB((c->ast = parse(&arg))); + CHECK_OB((c->ast = parse_pos(&arg, pos))); gwion->env->name = c->name; const m_bool ret = passes(gwion, c); return ret; diff --git a/src/emit/emit.c b/src/emit/emit.c index 35e47d6f..bc67142a 100644 --- a/src/emit/emit.c +++ b/src/emit/emit.c @@ -1111,7 +1111,7 @@ ANN static m_bool emit_decl(const Emitter emit, Exp_Decl *const decl) { if (!decl->args && !exp_getvar(exp_self(decl)) && GET_FLAG(array_base_simple(v->type), abstract) && !GET_FLAG(decl->td, late) && GET_FLAG(v, late) && late_array(decl->td) && GET_FLAG(v->type, abstract)) { - env_warn(emit->env, decl->td->pos, _("Type '%s' is abstract, use {+G}late{0} instead of {G+}%s{0}"), + env_err(emit->env, decl->td->pos, _("Type '%s' is abstract, use {+G}late{0} instead of {G+}%s{0}"), v->type->name, !GET_FLAG(decl->td, const) ? "var" : "const"); if(v->type->nspc->vtable.ptr) { const Vector vec = &v->type->nspc->vtable; @@ -1123,6 +1123,7 @@ ANN static m_bool emit_decl(const Emitter emit, Exp_Decl *const decl) { } } } + return GW_ERROR; } if(GET_FLAG(v, late) && exp_getuse(exp_self(decl))) emit_add_instr(emit, GWOP_EXCEPT); @@ -1232,7 +1233,7 @@ ANN static inline void inline_args_ini(const Emitter emit, const Func f, const Value value = arg->var_decl.value; vector_add(v, value->from->offset); value->from->offset = emit_local(emit, value->type); - nspc_add_value(emit->env->curr, arg->var_decl.xid, value); + _nspc_add_value(emit->env->curr, arg->var_decl.xid, value); } emit_regmove(emit, -f->code->stack_depth); emit_regtomem4(emit, f->code->stack_depth, start_offset); @@ -2248,11 +2249,11 @@ ANN static m_bool _emit_stmt_each(const Emitter emit, const Stmt_Each stmt, emit_memsetimm(emit, key_offset, -1); stmt->v->from->offset = val_offset; //value_addref(stmt->v); -nspc_add_value(emit->env->curr, stmt->sym, stmt->v); +_nspc_add_value(emit->env->curr, stmt->sym, stmt->v); emit_debug(emit, stmt->v); if (stmt->idx) { stmt->idx->v->from->offset = key_offset; -nspc_add_value(emit->env->curr, stmt->idx->sym, stmt->idx->v); +_nspc_add_value(emit->env->curr, stmt->idx->sym, stmt->idx->v); //value_addref(stmt->idx->v); emit_debug(emit, stmt->idx->v); } @@ -2665,7 +2666,7 @@ ANN static void emit_func_def_args(const Emitter emit, Arg_List args) { emit->code->stack_depth += type->size; arg->var_decl.value->from->offset = emit_localn(emit, type); emit_debug(emit, arg->var_decl.value); - nspc_add_value(emit->env->curr, insert_symbol(arg->var_decl.value->name), arg->var_decl.value); + _nspc_add_value(emit->env->curr, insert_symbol(arg->var_decl.value->name), arg->var_decl.value); } } diff --git a/src/env/env_utils.c b/src/env/env_utils.c index 180e0a73..f163ddd5 100644 --- a/src/env/env_utils.c +++ b/src/env/env_utils.c @@ -103,7 +103,7 @@ ANN Value global_string(const Env env, const m_str str, const loc_t loc) { if (v) return v; const Value value = new_value(env, env->gwion->type[et_string], s_name(sym), loc); - nspc_add_value_front(env->global_nspc, sym, value); + _nspc_add_value_front(env->global_nspc, sym, value); return value; } diff --git a/src/env/nspc.c b/src/env/nspc.c index b1472bd3..f5421e2e 100644 --- a/src/env/nspc.c +++ b/src/env/nspc.c @@ -96,3 +96,18 @@ ANN Nspc new_nspc(MemPool p, const m_str name) { a->ref = 1; return a; } + +static nspc_add_value_t _add = _nspc_add_value; +static nspc_add_value_t _front = _nspc_add_value_front; +ANN void nspc_add_value(const Nspc n, const Symbol s, const Value a) { + _add(n, s, a); +} +ANN void nspc_add_value_front(const Nspc n, const Symbol s, const Value a) { + _front(n, s, a); +} + +ANN void nspc_add_value_set_func(nspc_add_value_t add, nspc_add_value_t front) { + _add = add; + _front = front; +} + diff --git a/src/import/import_checker.c b/src/import/import_checker.c index 0dea184f..1b0109bd 100644 --- a/src/import/import_checker.c +++ b/src/import/import_checker.c @@ -310,14 +310,16 @@ ANN static m_bool td_info_run(const Env env, struct td_info *info) { ANEW ANN m_str type2str(const Gwion gwion, const Type t, const loc_t pos NUSED) { - GwText text = {.mp = gwion->mp}; + GwText text; + text_init(&text, gwion->mp); td_fullname(gwion->env, &text, t); return text.str; } ANEW ANN m_str tl2str(const Gwion gwion, const Type_List tl, const loc_t pos NUSED) { - struct td_info info = {.tl = tl, {.mp = gwion->mp}}; + struct td_info info = {.tl = tl}; + text_init(&info.text, gwion->mp); CHECK_BO(td_info_run(gwion->env, &info)); return info.text.str; } diff --git a/src/import/import_internals.c b/src/import/import_internals.c index b727a0aa..1542d412 100644 --- a/src/import/import_internals.c +++ b/src/import/import_internals.c @@ -31,11 +31,14 @@ ANN void gwi_reset(const Gwi gwi) { ANN static m_bool run_with_doc(const Gwi gwi, m_bool (*f)(const Gwi)) { struct LintState ls = {.builtin = true, .nindent = 4}; + text_init(&ls.text, gwi->gwion->mp); Lint linter = {.mp = gwi->gwion->mp, .ls = &ls }; lint_indent(&linter); lint(&linter, "{-}#!+ %s{0}\n", gwi->gwion->env->name); gwi->lint = &linter; - return f(gwi); + const m_bool ret = f(gwi); + fprintf(stdout, "%s", ls.text.str); + return ret; } ANN m_bool gwi_run(const Gwion gwion, m_bool (*f)(const Gwi)) { diff --git a/src/parse/check.c b/src/parse/check.c index ce9ee9ea..f44f0468 100644 --- a/src/parse/check.c +++ b/src/parse/check.c @@ -2009,6 +2009,8 @@ ANN static m_bool check_parent(const Env env, const Class_Def cdef) { if (td->array && td->array->exp) CHECK_BB(check_subscripts(env, td->array, 1)); CHECK_BB(ensure_traverse(env, parent)); + if(GET_FLAG(parent, abstract)) + SET_FLAG(cdef->base.type, abstract); return GW_OK; } diff --git a/src/parse/scan1.c b/src/parse/scan1.c index 5a9dc501..e3b4f5ad 100644 --- a/src/parse/scan1.c +++ b/src/parse/scan1.c @@ -142,7 +142,7 @@ ANN static m_bool scan1_decl(const Env env, Exp_Decl *const decl) { } else if (GET_FLAG(decl->td, global)) SET_FLAG(v, global); else if(env->context) - set_vflag(v, vflag_fglobal); // file global + set_vflag(v, vflag_fglobal); // file global } else if (GET_FLAG(decl->td, global)) SET_FLAG(v, global); nspc_add_value(env->curr, vd->xid, v); @@ -766,7 +766,6 @@ ANN static m_bool scan1_parent(const Env env, const Class_Def cdef) { !(tflag(cdef->base.type, tflag_cdef) || tflag(cdef->base.type, tflag_udef))) ERR_B(pos, _("cannot extend primitive type '%s'"), parent->name) if (type_ref(parent)) ERR_B(pos, _("can't use ref type in class extend")) - if (GET_FLAG(parent, abstract)) SET_FLAG(cdef->base.type, abstract); return GW_OK; } diff --git a/src/parse/scan2.c b/src/parse/scan2.c index 057bb9f2..443a6be9 100644 --- a/src/parse/scan2.c +++ b/src/parse/scan2.c @@ -32,7 +32,7 @@ ANN static m_bool scan2_decl(const Env env, const Exp_Decl *decl) { const Type t = decl->type; CHECK_BB(ensure_scan2(env, t)); const Var_Decl vd = decl->vd; - nspc_add_value(env->curr, vd.xid, vd.value); + _nspc_add_value(env->curr, vd.xid, vd.value); return GW_OK; } @@ -379,7 +379,7 @@ static m_bool scan2_fdef_tmpl(const Env env, const Func_Def f, name) const Symbol sym = func_symbol(env, env->curr->name, name, "template", ff->def->vt_index); - nspc_add_value(env->curr, sym, value); + _nspc_add_value(env->curr, sym, value); if (!overload) nspc_add_value(env->curr, f->base->xid, value); nspc_add_func(env->curr, sym, func); func->def->vt_index = ff->def->vt_index; @@ -390,7 +390,7 @@ static m_bool scan2_fdef_tmpl(const Env env, const Func_Def f, } while (type && (type = type->info->parent) && (nspc = type->nspc)); --i; const Symbol sym = func_symbol(env, env->curr->name, name, "template", i); - nspc_add_value(env->curr, sym, value); + _nspc_add_value(env->curr, sym, value); nspc_add_func(env->curr, sym, func); if (!overload) nspc_add_value(env->curr, f->base->xid, value); else func->def->vt_index = ++overload->from->offset; @@ -486,7 +486,7 @@ static Value func_create(const Env env, const Func_Def f, const Value overload, nspc_add_func(env->curr, insert_symbol(func->name), func); const Value v = func_value(env, func, overload); scan2_func_def_flag(env, f); - nspc_add_value(env->curr, insert_symbol(func->name), v); + _nspc_add_value(env->curr, insert_symbol(func->name), v); return v; } diff --git a/src/parse/type_decl.c b/src/parse/type_decl.c index 61e28dc9..81916624 100644 --- a/src/parse/type_decl.c +++ b/src/parse/type_decl.c @@ -47,7 +47,8 @@ ANN static inline Type ref(const Env env, Type_Decl *td) { } ANN static Symbol symname(const Env env, Func_Base *const base, bool *global) { - GwText text = { .mp = env->gwion->mp }; + GwText text; + text_init(&text, env->gwion->mp); text_add(&text, "("); DECL_OO(const Type, t, = known_type(env, base->td)); DECL_OO(const m_str, name, = type2str(env->gwion, t, base->td->pos)); diff --git a/tests/driver/Makefile b/tests/driver/Makefile index 31b8ef39..edc8d0e2 100644 --- a/tests/driver/Makefile +++ b/tests/driver/Makefile @@ -1,4 +1,4 @@ -INC = -I../../include -I../../util/include -I../../util/libtermcolor/include -I../../ast/include -I../../fmt/include +INC = -I../../include -I../../util/include -I../../ast/libprettyerr/src -I../../ast/include -I../../fmt/include CC ?= gcc NAME := ${NAME} diff --git a/tests/module/Makefile b/tests/module/Makefile index 31b8ef39..edc8d0e2 100644 --- a/tests/module/Makefile +++ b/tests/module/Makefile @@ -1,4 +1,4 @@ -INC = -I../../include -I../../util/include -I../../util/libtermcolor/include -I../../ast/include -I../../fmt/include +INC = -I../../include -I../../util/include -I../../ast/libprettyerr/src -I../../ast/include -I../../fmt/include CC ?= gcc NAME := ${NAME} diff --git a/tests/plug/Makefile b/tests/plug/Makefile index 25b07861..bb37cb13 100644 --- a/tests/plug/Makefile +++ b/tests/plug/Makefile @@ -1,4 +1,4 @@ -INC = -I../../include -I../../util/include -I../../util/libtermcolor/include -I../../ast/include -I../../fmt/include +INC = -I../../include -I../../util/include -I../../ast/libprettyerr/src -I../../ast/include -I../../fmt/include CC ?= gcc NAME := ${NAME} diff --git a/util b/util index 08e7ba7e..d4b4d45a 160000 --- a/util +++ b/util @@ -1 +1 @@ -Subproject commit 08e7ba7e688452ba2a827b8a3f9e2a4fa3157759 +Subproject commit d4b4d45ac7f64e3a42076a0aca35ab29b57817e4