From 694e335b6a1aa71a187fc99616603ffa66e47ea0 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=A9mie=20Astor?= Date: Sun, 2 May 2021 00:41:04 +0200 Subject: [PATCH] :wrench: Introduce gwcdoc --- Makefile | 3 +++ include/gwi.h | 15 +++++++++++++- src/emit/emit.c | 2 +- src/import/import_cdef.c | 10 +++++++++ src/import/import_enum.c | 4 ++++ src/import/import_fdef.c | 8 +++++++ src/import/import_internals.c | 22 +++++++++++++------- src/import/import_item.c | 6 ++++++ src/import/import_oper.c | 28 +++++++++++++++++++++++-- src/import/import_special.c | 5 +++++ src/import/import_tdef.c | 4 ++++ src/import/import_type.c | 8 +++++++ src/import/import_udef.c | 4 ++++ src/lib/engine.c | 30 +++++++++++++++++++++++++++ src/lib/object_op.c | 2 +- src/lib/ref.c | 13 ++++++++++-- src/parse/check.c | 2 +- src/parse/func_operator.c | 2 +- src/parse/operator.c | 4 ++-- src/parse/scan1.c | 4 ++-- src/plug.c | 3 +++ tests/internal_op/conditionnal.gw | 2 +- tests/internal_op/internal_not_int.gw | 2 +- tests/internal_op/unconditionnal.gw | 2 +- 24 files changed, 161 insertions(+), 24 deletions(-) diff --git a/Makefile b/Makefile index 33b2550e..2cd612c6 100644 --- a/Makefile +++ b/Makefile @@ -90,6 +90,9 @@ ast: ast/libgwion_ast.a afl: gwion-fuzz +gwcdoc: + @+LDFLAGS="-L../fmt/ -lgwfmt" CFLAGS="-I../fmt/include -DGWION_DOC" ${MAKE} PRG=gwcdoc all + gwion-fuzz: @touch src/parse/{scan*.c,check.c} src/emit/emit.c src/main.c @+PRG=gwion-fuzz CC=afl-clang-fast CFLAGS=-D__FUZZING__ ${MAKE} diff --git a/include/gwi.h b/include/gwi.h index 94b22772..3f7add09 100644 --- a/include/gwi.h +++ b/include/gwi.h @@ -1,14 +1,27 @@ #ifndef __GWI #define __GWI +#ifdef GWION_DOC +#include "lint.h" +#define gwiheader(a,...) do { lint_nl(a->lint); lint_indent(a->lint); lint(a->lint, "{-}#!+ {/}%s{0}\n", __VA_ARGS__); } while(0) +#define gwidoc(a,...) do { lint_nl(a->lint); lint_indent(a->lint); lint(a->lint, "{-}#!- {/}%s{0}\n", __VA_ARGS__); } while(0) +#define gwinote(a,...) do { lint_indent(a->lint); lint(a->lint, "{-}#!- {/}%s{0}\n", __VA_ARGS__); } while(0) +#else +#define gwiheader(a,...) +#define gwidoc(a,...) +#define gwinote(a,...) +#endif struct Gwi_ { struct Gwion_ *const gwion; Ast body; struct ImportCK *ck; struct OperCK *oper; // _misc struct Vector_ effects; - uint tmpls; loc_t loc; +#ifdef GWION_DOC + Lint *lint; +#endif + uint tmpls; }; #include "import/internals.h" diff --git a/src/emit/emit.c b/src/emit/emit.c index 50bfd110..6255ac28 100644 --- a/src/emit/emit.c +++ b/src/emit/emit.c @@ -1410,7 +1410,7 @@ ANN static m_bool emit_implicit_cast(const Emitter emit, ANN static Instr _flow(const Emitter emit, const Exp e, const m_bool b) { CHECK_BO(emit_exp_pop_next(emit, e)); emit_exp_addref1(emit, e, -exp_size(e)); - struct Op_Import opi = { .op=insert_symbol(b ? "@conditionnal" : "@unconditionnal"), + struct Op_Import opi = { .op=insert_symbol(b ? "@conditional" : "@unconditional"), .rhs=e->type, .pos=e->pos, .data=(uintptr_t)e }; CHECK_BO(op_emit(emit, &opi)); return (Instr)vector_back(&emit->code->instr); diff --git a/src/import/import_cdef.c b/src/import/import_cdef.c index 48586753..fb1e2148 100644 --- a/src/import/import_cdef.c +++ b/src/import/import_cdef.c @@ -63,6 +63,11 @@ ANN static Type type_finish(const Gwi gwi, const Type t) { gwi->tmpls++; add_template(gwi->gwion->env, t); } +#ifdef GWION_DOC + lint_indent(gwi->lint); + gwi->lint->indent++; + lint_class_def(gwi->lint, t->info->cdef); +#endif return t; } @@ -117,6 +122,11 @@ ANN Type gwi_struct_ini(const Gwi gwi, const m_str name) { } ANN m_int gwi_class_end(const Gwi gwi) { +#ifdef GWION_DOC + gwi->lint->indent--; + lint_rbrace(gwi->lint); + lint_nl(gwi->lint); +#endif if(!gwi->gwion->env->class_def) GWI_ERR_B(_("import: too many class_end called.")) nspc_allocdata(gwi->gwion->mp, gwi->gwion->env->class_def->nspc); diff --git a/src/import/import_enum.c b/src/import/import_enum.c index 8c628090..7c2b9a84 100644 --- a/src/import/import_enum.c +++ b/src/import/import_enum.c @@ -83,6 +83,10 @@ ANN Type gwi_enum_end(const Gwi gwi) { gwi->ck->tmpl = NULL; const m_bool ret = traverse_enum_def(gwion->env, edef); import_enum_end(gwi, &edef->values); +#ifdef GWION_DOC + lint_indent(gwi->lint); + lint_enum_def(gwi->lint, edef); +#endif const Type t = ret > 0 ? edef->t : NULL; if(edef->values.ptr) vector_release(&edef->values); diff --git a/src/import/import_fdef.c b/src/import/import_fdef.c index bafa8e7c..eb3c169e 100644 --- a/src/import/import_fdef.c +++ b/src/import/import_fdef.c @@ -54,6 +54,10 @@ ANEW ANN static Func_Base* gwi_func_base(const Gwi gwi, ImportCK *ck) { ANEW ANN static Func_Def import_fdef(const Gwi gwi, ImportCK *ck) { Func_Base* base = gwi_func_base(gwi, ck); const Func_Def fdef = new_func_def(gwi->gwion->mp, base, NULL); +#ifdef GWION_DOC + lint_indent(gwi->lint); + lint_func_def(gwi->lint, fdef); +#endif if(gwi->effects.ptr) { vector_init(&fdef->base->effects); vector_copy2(&gwi->effects, &fdef->base->effects); @@ -132,6 +136,10 @@ ANN Type gwi_fptr_end(const Gwi gwi, const ae_flag flag) { CHECK_BO(ck_ok(gwi, ck_fdef)); DECL_OO(const Fptr_Def, fptr, = import_fptr(gwi)); fptr->base->flag |= flag; +#ifdef GWION_DOC + lint_indent(gwi->lint); + lint_fptr_def(gwi->lint, fptr); +#endif if(safe_tflag(gwi->gwion->env->class_def, tflag_tmpl)/* && !fptr->base->tmpl*/) { section_fptr(gwi, fptr); ck_end(gwi); diff --git a/src/import/import_internals.c b/src/import/import_internals.c index 9de5c531..95d75916 100644 --- a/src/import/import_internals.c +++ b/src/import/import_internals.c @@ -29,12 +29,18 @@ ANN void gwi_reset(const Gwi gwi) { } ANN m_bool gwi_run(const Gwion gwion, m_bool (*f)(const Gwi)) { - const m_str name = gwion->env->name; - OperCK oper = {}; - struct Gwi_ gwi = { .gwion=gwion, .oper=&oper }; - const m_bool ret = f(&gwi); - if(ret < 0) - gwi_reset(&gwi); - gwion->env->name = name; - return ret; + const m_str name = gwion->env->name; + OperCK oper = {}; + struct Gwi_ gwi = { .gwion=gwion, .oper=&oper }; +#ifdef GWION_DOC + struct LintState ls = { .builtin=true }; + Lint linter = { .mp=gwion->mp, .ls=&ls }; + lint(&linter, "{-}#!+ %s{0}\n", name); + gwi.lint = &linter; +#endif + const m_bool ret = f(&gwi); + if(ret < 0) + gwi_reset(&gwi); + gwion->env->name = name; + return ret; } diff --git a/src/import/import_item.c b/src/import/import_item.c index 5b2f59f0..73c04ee6 100644 --- a/src/import/import_item.c +++ b/src/import/import_item.c @@ -34,6 +34,12 @@ ANN2(1) m_int gwi_item_end(const Gwi gwi, const ae_flag flag, union value_data a CHECK_BB(ck_ok(gwi, ck_item)); const Env env = gwi->gwion->env; gwi->ck->exp->d.exp_decl.td->flag = flag; +#ifdef GWION_DOC + lint_indent(gwi->lint); + lint_exp(gwi->lint, gwi->ck->exp); + lint_sc(gwi->lint); + lint_nl(gwi->lint); +#endif if(env->class_def && tflag(env->class_def, tflag_tmpl)) return gwi_item_tmpl(gwi); CHECK_BB(traverse_exp(env, gwi->ck->exp)); diff --git a/src/import/import_oper.c b/src/import/import_oper.c index 687d215f..ab0214f5 100644 --- a/src/import/import_oper.c +++ b/src/import/import_oper.c @@ -69,6 +69,30 @@ ANN void gwi_oper_eff(const Gwi gwi, const m_str effect) { } ANN m_int gwi_oper_end(const Gwi gwi, const m_str op, const f_instr f) { +#ifdef GWION_DOC + lint_indent(gwi->lint); + lint(gwi->lint, "{+C}operator{0} "); + if(gwi->oper->lhs && !gwi->oper->rhs) { + lint(gwi->lint, "{+}%s{0}", gwi->oper->lhs != (m_str)1 ? gwi->oper->lhs : "@Any"); + lint_space(gwi->lint); + } + if(gwi->oper->ret) { + lint(gwi->lint, "{+}%s{0}", gwi->oper->ret != (m_str)1 ? gwi->oper->ret : "@Any"); + lint_space(gwi->lint); + } + lint(gwi->lint, "{/}%s{0}", op); + lint_lparen(gwi->lint); + if(gwi->oper->lhs && gwi->oper->rhs) { + lint(gwi->lint, "{+}%s{0}", gwi->oper->lhs != (m_str)1 ? gwi->oper->lhs : "@Any"); + lint(gwi->lint, ","); + lint_space(gwi->lint); + } + if(gwi->oper->rhs) + lint(gwi->lint, "{+}%s{0}", gwi->oper->rhs != (m_str)1 ? gwi->oper->rhs : "@Any"); + lint_rparen(gwi->lint); + lint_sc(gwi->lint); + lint_nl(gwi->lint); +#endif gwi->oper->sym = insert_symbol(gwi->gwion->st, op); const m_bool ret = import_op(gwi, gwi->oper, f); gwi->oper->ck = NULL; @@ -79,7 +103,7 @@ ANN m_int gwi_oper_end(const Gwi gwi, const m_str op, const f_instr f) { ANN m_int gwi_oper_cond(const Gwi gwi, const m_str type, const f_instr f1, const f_instr f2) { GWI_BB(gwi_oper_ini(gwi, NULL, type, "bool")) - GWI_BB(gwi_oper_end(gwi, "@conditionnal", f1)) - GWI_BB(gwi_oper_end(gwi, "@unconditionnal", f2)) + GWI_BB(gwi_oper_end(gwi, "@conditional", f1)) + GWI_BB(gwi_oper_end(gwi, "@unconditional", f2)) return GW_OK; } diff --git a/src/import/import_special.c b/src/import/import_special.c index 0e8d80ca..bb902c47 100644 --- a/src/import/import_special.c +++ b/src/import/import_special.c @@ -30,6 +30,11 @@ ANN void gwi_reserve(const Gwi gwi, const m_str str) { } ANN void gwi_specialid(const Gwi gwi, const m_str id, const SpecialId spid) { +#ifdef GWION_DOC + lint(gwi->lint, "{+C}specialid{0} %s{/}%s{0};\n", + spid->is_const ? "{+G}const{0} " : "", + id); +#endif struct SpecialId_ *a = mp_calloc(gwi->gwion->mp, SpecialId); memcpy(a, spid, sizeof(struct SpecialId_)); map_set(&gwi->gwion->data->id, (vtype)insert_symbol(gwi->gwion->st, id), (vtype)a); diff --git a/src/import/import_tdef.c b/src/import/import_tdef.c index 0f6d7f30..0f9c6214 100644 --- a/src/import/import_tdef.c +++ b/src/import/import_tdef.c @@ -33,6 +33,10 @@ ANN Type gwi_typedef_end(const Gwi gwi, const ae_flag flag) { gwi->ck->td = NULL; gwi->ck->tmpl = NULL; const m_bool ret = traverse_type_def(gwi->gwion->env, tdef); +#ifdef GWION_DOC + lint_indent(gwi->lint); + lint_type_def(gwi->lint, tdef); +#endif const Type t = tdef->type; set_tflag(t, tflag_scan0 | tflag_scan1 | tflag_scan2 | tflag_check | tflag_emit); free_type_def(gwi->gwion->mp, tdef); diff --git a/src/import/import_type.c b/src/import/import_type.c index 51f772a2..00dc68d1 100644 --- a/src/import/import_type.c +++ b/src/import/import_type.c @@ -30,6 +30,14 @@ ANN2(1) static Type get_parent(const Gwi gwi, const m_str parent_name) { } ANN2(1,2) Type gwi_mk_type(const Gwi gwi, const m_str name, const m_uint size, const m_str parent_name) { +#ifdef GWION_DOC + lint_indent(gwi->lint); + lint(gwi->lint, "{+C}primitive{0} {+}%s{0}", name); + if(parent_name) + lint(gwi->lint, " {+C}extends{0} {+}%s{0}", parent_name); + lint_sc(gwi->lint); + lint_nl(gwi->lint); +#endif CHECK_OO(gwi_str2sym(gwi, name)); const Type parent = get_parent(gwi, parent_name); const Type t = new_type(gwi->gwion->mp, name, parent); diff --git a/src/import/import_udef.c b/src/import/import_udef.c index 2220377a..5fd9e2eb 100644 --- a/src/import/import_udef.c +++ b/src/import/import_udef.c @@ -52,6 +52,10 @@ ANN static Type union_type(const Gwi gwi, const Union_Def udef) { // set_vflag(udef->value, vflag_builtin); // const M_Object o = new_object(gwi->gwion->mp, NULL, udef->value->type); // udef->value->d.ptr = (m_uint*)o; +#ifdef GWION_DOC + lint_indent(gwi->lint); + lint_union_def(gwi->lint, udef); +#endif return udef->type; } diff --git a/src/lib/engine.c b/src/lib/engine.c index 0464fb05..977ddc5f 100644 --- a/src/lib/engine.c +++ b/src/lib/engine.c @@ -79,43 +79,63 @@ static INSTR(PredicateCheck) { } ANN static m_bool import_core_libs(const Gwi gwi) { + gwidoc(gwi, "one type to rule them all."); const Type t_class = gwi_mk_type(gwi, "@Class", SZ_INT, NULL); set_tflag(t_class, tflag_infer); GWI_BB(gwi_set_global_type(gwi, t_class, et_class)) GWI_BB(gwi_gack(gwi, t_class, gack_class)) + gwidoc(gwi, "this type is infered."); const Type t_auto = gwi_mk_type(gwi, "auto", SZ_INT, NULL); set_tflag(t_auto, tflag_infer); GWI_BB(gwi_set_global_type(gwi, t_auto, et_auto)) + + gwidoc(gwi, "a void type."); const Type t_void = gwi_mk_type(gwi, "void", 0, NULL); GWI_BB(gwi_gack(gwi, t_void, gack_void)) GWI_BB(gwi_set_global_type(gwi, t_void, et_void)) + + gwidoc(gwi, "a type for *pretty print*."); const Type t_gack = gwi_mk_type(gwi, "@Gack", SZ_INT, NULL); GWI_BB(gwi_gack(gwi, t_gack, gack_gack)) GWI_BB(gwi_set_global_type(gwi, t_gack, et_gack)) + + gwidoc(gwi, "integer type."); const Type t_int = gwi_mk_type(gwi, "int", SZ_INT, NULL); GWI_BB(gwi_gack(gwi, t_int, gack_int)) GWI_BB(gwi_set_global_type(gwi, t_int, et_int)) + + gwidoc(gwi, "character type."); const Type t_char = gwi_mk_type(gwi, "char", SZ_INT, "int"); GWI_BB(gwi_gack(gwi, t_char, gack_char)) GWI_BB(gwi_set_global_type(gwi, t_char, et_char)) + + gwidoc(gwi, "float type."); const Type t_float = gwi_mk_type(gwi, "float", SZ_FLOAT, NULL); GWI_BB(gwi_gack(gwi, t_float, gack_float)) GWI_BB(gwi_set_global_type(gwi, t_float, et_float)) + + gwidoc(gwi, "represent duration."); const Type t_dur = gwi_mk_type(gwi, "dur", SZ_FLOAT, NULL); GWI_BB(gwi_gack(gwi, t_dur, gack_float)) GWI_BB(gwi_add_type(gwi, t_dur)) + + gwidoc(gwi, "represent time."); const Type t_time = gwi_mk_type(gwi, "time", SZ_FLOAT, NULL); GWI_BB(gwi_gack(gwi, t_time, gack_float)) GWI_BB(gwi_add_type(gwi, t_time)) + + gwidoc(gwi, "internal time for `{/}now{0}{-}`."); 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); + gwidoc(gwi, "internal predicate representation."); struct SpecialId_ predicate = { .type=t_void, .exec=PredicateCheck, .is_const=1 }; gwi_specialid(gwi, "@predicate", &predicate); + gwidoc(gwi, "internal base of all objects and structures."); const Type t_compound = gwi_mk_type(gwi, "@Compound", SZ_INT, NULL); GWI_BB(gwi_gack(gwi, t_compound, gack_compound)) GWI_BB(gwi_set_global_type(gwi, t_compound, et_compound)) @@ -123,18 +143,24 @@ ANN static m_bool import_core_libs(const Gwi gwi) { GWI_BB(import_object(gwi)) GWI_BB(import_prim(gwi)) + gwidoc(gwi, "the base of all functions."); 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)) + + gwidoc(gwi, "the base of function pointers."); 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)) + + gwidoc(gwi, "the base of decayed operators."); const Type t_op = gwi_mk_type(gwi, "@op", SZ_INT, "@function"); GWI_BB(gwi_set_global_type(gwi, t_op, et_op)) const Type t_lambda = gwi_mk_type(gwi, "@lambda", SZ_INT, "@function"); set_tflag(t_lambda, tflag_infer); GWI_BB(gwi_set_global_type(gwi, t_lambda, et_lambda)) + gwidoc(gwi, "type for internal pointer data."); GWI_BB(gwi_typedef_ini(gwi, "int", "@internal")) GWI_BB(gwi_typedef_end(gwi, ae_flag_none)) @@ -157,6 +183,7 @@ ANN static m_bool import_core_libs(const Gwi gwi) { GWI_BB(import_modules(gwi)) GWI_BB(import_ref(gwi)) + gwidoc(gwi, "Operators class types."); GWI_BB(gwi_oper_ini(gwi, "@Class", "@Class", "int")) GWI_BB(gwi_oper_end(gwi, "==", int_eq)) GWI_BB(gwi_oper_end(gwi, "!=", int_neq)) @@ -165,15 +192,18 @@ ANN static m_bool import_core_libs(const Gwi gwi) { GWI_BB(gwi_oper_end(gwi, "<=", instr_class_le)) GWI_BB(gwi_oper_end(gwi, "<", instr_class_lt)) + gwidoc(gwi, "internal constructor operator."); GWI_BB(gwi_oper_ini(gwi, NULL, (m_str)OP_ANY_TYPE, NULL)) GWI_BB(gwi_oper_add(gwi, opck_basic_ctor)) GWI_BB(gwi_oper_end(gwi, "@ctor", NULL)) + gwidoc(gwi, "allow member access."); GWI_BB(gwi_oper_ini(gwi, "@Compound", (m_str)OP_ANY_TYPE, NULL)) GWI_BB(gwi_oper_add(gwi, opck_object_dot)) GWI_BB(gwi_oper_emi(gwi, opem_object_dot)) GWI_BB(gwi_oper_end(gwi, "@dot", NULL)) + gwidoc(gwi, "allow static access."); GWI_BB(gwi_oper_ini(gwi, "@Class", (m_str)OP_ANY_TYPE, NULL)) GWI_BB(gwi_oper_add(gwi, opck_object_dot)) GWI_BB(gwi_oper_emi(gwi, opem_object_dot)) diff --git a/src/lib/object_op.c b/src/lib/object_op.c index ad914876..eb8b6a23 100644 --- a/src/lib/object_op.c +++ b/src/lib/object_op.c @@ -34,7 +34,7 @@ static OP_CHECK(opck_object_at) { if(bin->rhs->exp_type == ae_exp_decl) SET_FLAG(bin->rhs->d.exp_decl.list->self->value, late); exp_setvar(bin->rhs, 1); - CHECK_BN(isa(bin->lhs->type , bin->rhs->type)); + CHECK_BO(isa(bin->lhs->type , bin->rhs->type)); return bin->rhs->type; } diff --git a/src/lib/ref.c b/src/lib/ref.c index e938b231..305dfbc3 100644 --- a/src/lib/ref.c +++ b/src/lib/ref.c @@ -74,11 +74,20 @@ static OP_CHECK(opck_ref_scan) { } GWION_IMPORT(ref) { + gwidoc(gwi, "Ref: take a reference from a variable."); + gwinote(gwi, "used just as the variable it reference."); + gwinote(gwi, "can only be used as argument."); + gwinote(gwi, "and cannot be returned."); const Type t_foreach = gwi_struct_ini(gwi, "Ref:[A]"); set_tflag(t_foreach, tflag_infer); - GWI_BB(gwi_item_ini(gwi, "@internal", "val")) - GWI_BB(gwi_item_end(gwi, ae_flag_none, num, 0)) + + gwinote(gwi, "a pointer to the referenced variable."); + GWI_BB(gwi_item_ini(gwi, "@internal", "val")) + GWI_BB(gwi_item_end(gwi, ae_flag_none, num, 0)) + GWI_BB(gwi_struct_end(gwi)) + + gwidoc(gwi, "internal `Ref` type creation."); GWI_BB(gwi_oper_ini(gwi, "Ref", NULL, NULL)) GWI_BB(gwi_oper_add(gwi, opck_ref_scan)) GWI_BB(gwi_oper_end(gwi, "@scan", NULL)) diff --git a/src/parse/check.c b/src/parse/check.c index a82abd75..1f4ed77c 100644 --- a/src/parse/check.c +++ b/src/parse/check.c @@ -892,7 +892,7 @@ ANN static Type check_exp_unary(const Env env, const Exp_Unary* unary) { ANN static Type _flow(const Env env, const Exp e, const m_bool b) { DECL_OO(const Type, type, = check_exp(env, e)); - struct Op_Import opi = { .op=insert_symbol(b ? "@conditionnal" : "@unconditionnal"), + struct Op_Import opi = { .op=insert_symbol(b ? "@conditional" : "@unconditional"), .rhs=type, .pos=e->pos, .data=(uintptr_t)e }; return op_check(env, &opi); } diff --git a/src/parse/func_operator.c b/src/parse/func_operator.c index 131fd2cc..8ae9cb00 100644 --- a/src/parse/func_operator.c +++ b/src/parse/func_operator.c @@ -11,7 +11,7 @@ ANN void func_operator(const Func_Def fdef, struct Op_Import *opi) { opi->op =fdef->base->xid; const m_str str = s_name(fdef->base->xid); const uint is_unary = fbflag(fdef->base, fbflag_unary) + - (!strcmp(str, "@conditionnal") || !strcmp(str, "@unconditionnal")); + (!strcmp(str, "@conditional") || !strcmp(str, "@unconditional")); const Arg_List args = fdef->base->args; opi->lhs = is_unary ? NULL : args ? args->var_decl->value->type : NULL; diff --git a/src/parse/operator.c b/src/parse/operator.c index cf7e7afb..4f4a77b4 100644 --- a/src/parse/operator.c +++ b/src/parse/operator.c @@ -215,9 +215,9 @@ ANN static m_bool handle_instr(const Emitter emit, const M_Operator* mo) { const Instr push = emit_add_instr(emit, mo->func->code ? RegPushImm : SetFunc); push->m_val = ((m_uint)mo->func->code ?:(m_uint)mo->func); CHECK_BB(emit_exp_call1(emit, mo->func)); - if(mo->func->def->base->xid == insert_symbol(emit->gwion->st, "@conditionnal")) + if(mo->func->def->base->xid == insert_symbol(emit->gwion->st, "@conditional")) emit_add_instr(emit, BranchEqInt); - else if(mo->func->def->base->xid == insert_symbol(emit->gwion->st, "@unconditionnal")) + else if(mo->func->def->base->xid == insert_symbol(emit->gwion->st, "@unconditional")) emit_add_instr(emit, BranchNeqInt); return GW_OK; } diff --git a/src/parse/scan1.c b/src/parse/scan1.c index 6d7d971f..57eaa8b2 100644 --- a/src/parse/scan1.c +++ b/src/parse/scan1.c @@ -544,8 +544,8 @@ ANN static m_bool scan_internal(const Env env, const Func_Base *base) { return class_internal(env, base); if(op == insert_symbol("@implicit")) return scan_internal_arg(env, base); - if(op == insert_symbol("@conditionnal") || - op == insert_symbol("@unconditionnal")) + if(op == insert_symbol("@conditional") || + op == insert_symbol("@unconditional")) return scan_internal_int(env, base); return GW_OK; } diff --git a/src/plug.c b/src/plug.c index 13514830..6f142b05 100644 --- a/src/plug.c +++ b/src/plug.c @@ -172,7 +172,10 @@ ANN static m_bool _plugin_ini(struct Gwion_ *gwion, const m_str iname) { plug->imp = 1; CHECK_BB(dependencies(gwion, plug)); const m_uint scope = env_push_global(gwion->env); + const m_str name = gwion->env->name; + gwion->env->name = iname; const m_bool ret = gwi_run(gwion, imp); + gwion->env->name = name; env_pop(gwion->env, scope); return ret; } diff --git a/tests/internal_op/conditionnal.gw b/tests/internal_op/conditionnal.gw index 6e7b5590..ede8d2a8 100644 --- a/tests/internal_op/conditionnal.gw +++ b/tests/internal_op/conditionnal.gw @@ -4,7 +4,7 @@ class C { 10 => var int i; } -operator int @conditionnal (C c) { +operator int @conditional (C c) { <<< __func__ >>>; --c.i; return c.i; diff --git a/tests/internal_op/internal_not_int.gw b/tests/internal_op/internal_not_int.gw index 78f83bbb..3bfea070 100644 --- a/tests/internal_op/internal_not_int.gw +++ b/tests/internal_op/internal_not_int.gw @@ -1,2 +1,2 @@ #! [contains] must return -operator Object @conditionnal (int i) {} +operator Object @conditional (int i) { return new Object; } diff --git a/tests/internal_op/unconditionnal.gw b/tests/internal_op/unconditionnal.gw index 1e2c4e3b..3c0c6162 100644 --- a/tests/internal_op/unconditionnal.gw +++ b/tests/internal_op/unconditionnal.gw @@ -4,7 +4,7 @@ class C { 10 => var int i; } -operator int @unconditionnal (C c) { +operator int @unconditional (C c) { <<< __func__ >>>; --c.i; return !c.i; -- 2.43.0