From: Jérémie Astor Date: Fri, 14 May 2021 23:34:12 +0000 (+0200) Subject: :art: Add --cdoc X-Git-Tag: nightly~668 X-Git-Url: http://10.10.0.4:5575/?a=commitdiff_plain;h=5d9ffeb61614d018a8f0f988408bc1a14176487c;p=gwion.git :art: Add --cdoc --- diff --git a/.gitmodules b/.gitmodules index 85462218..5149f98e 100644 --- a/.gitmodules +++ b/.gitmodules @@ -14,3 +14,6 @@ [submodule "libcmdapp"] path = libcmdapp url = https://github.com/euppal/libcmdapp +[submodule "fmt"] + path = fmt + url = https://github.com/Gwion/gwion-fmt diff --git a/Makefile b/Makefile index a3797bcb..eaa71bc2 100644 --- a/Makefile +++ b/Makefile @@ -22,7 +22,7 @@ test_dir += examples CFLAGS += -Iutil/include -Iast/include -Ilibcmdapp/src -D_GNU_SOURCE -CFLAGS += -Iast/libprettyerr/src +CFLAGS += -Iast/libprettyerr/src -Ifmt/include # add commit hash to version for now CFLAGS += -DGWION_VERSION=\"$(shell git log -n1 --format="%h")\" @@ -51,6 +51,7 @@ CFLAGS += -DGWION_BUILTIN _GWLIBS = util/libgwion_util.a ast/libgwion_ast.a libcmdapp/libcmdapp.a lib${PRG}.a util/libtermcolor/libtermcolor.a ast/libprettyerr/libprettyerr.a GWLIBS := lib${PRG}.a libcmdapp/libcmdapp.a ast/libgwion_ast.a GWLIBS += util/libgwion_util.a ast/libprettyerr/libprettyerr.a util/libtermcolor/libtermcolor.a +GWLIBS += fmt/libgwion-fmt.a _LDFLAGS = ${GWLIBS} ${LDFLAGS} # we are not pedantic diff --git a/ast b/ast index 883e43a8..13713de4 160000 --- a/ast +++ b/ast @@ -1 +1 @@ -Subproject commit 883e43a8b7068e5f17bfb1963d5eea676a326edb +Subproject commit 13713de48c46bbbeb8d6b69518a959f6d378c00d diff --git a/fmt b/fmt new file mode 160000 index 00000000..bec8fef4 --- /dev/null +++ b/fmt @@ -0,0 +1 @@ +Subproject commit bec8fef4607fac18fa92da87e95e0da1c3ac76f4 diff --git a/include/gwi.h b/include/gwi.h index 3fe25e96..5330e939 100644 --- a/include/gwi.h +++ b/include/gwi.h @@ -1,16 +1,11 @@ #ifndef __GWI #define __GWI -#ifdef GWION_DOC #include "gwfmt.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 +#define gwiheader(a,...) if(a->gwion->data->cdoc) do {lint_nl(gwi->lint); lint_indent(gwi->lint); lint(gwi->lint, "{-}#!+ {/}%s{0}\n", __VA_ARGS__); } while(0) +#define gwidoc(a,...) if(a->gwion->data->cdoc) do { lint_nl(a->lint); lint_indent(a->lint); lint(a->lint, "{-}#!- {/}%s{0}\n", __VA_ARGS__); } while(0) +#define gwinote(a,...) if(a->gwion->data->cdoc) do { lint_indent(a->lint); lint(a->lint, "{-}#!- {/}%s{0}\n", __VA_ARGS__); } while(0) + struct Gwi_ { struct Gwion_ *const gwion; Ast body; @@ -18,9 +13,7 @@ struct Gwi_ { struct OperCK *oper; // _misc struct Vector_ effects; loc_t loc; -#ifdef GWION_DOC Lint *lint; -#endif uint8_t tmpls; }; diff --git a/include/gwion.h b/include/gwion.h index 220d040e..688ca942 100644 --- a/include/gwion.h +++ b/include/gwion.h @@ -37,4 +37,5 @@ ANN static inline Type type_class(const Gwion gwion, const Type t) { } ANN void gwion_set_debug(const Gwion gwion, const bool dbg); +ANN void gwion_set_cdoc(const Gwion gwion, const bool dbg); #endif diff --git a/include/gwiondata.h b/include/gwiondata.h index eccc3d15..2c621ef0 100644 --- a/include/gwiondata.h +++ b/include/gwiondata.h @@ -6,9 +6,9 @@ typedef struct GwionData_ { MUTEX_TYPE mutex; struct Vector_ child; struct Vector_ child2; - struct Vector_ reserved; struct Passes_ *passes; struct Map_ plug; + bool cdoc; } GwionData; ANN GwionData* new_gwiondata(MemPool); diff --git a/libcmdapp b/libcmdapp index 9a2bcfb8..b063526d 160000 --- a/libcmdapp +++ b/libcmdapp @@ -1 +1 @@ -Subproject commit 9a2bcfb85e5ca94cc6f2697f5a41c09c1c18db3f +Subproject commit b063526d5aa60de490c9ae2fdca6ee9c87bae9c2 diff --git a/src/arg.c b/src/arg.c index 15d51cb5..133d7ea6 100644 --- a/src/arg.c +++ b/src/arg.c @@ -18,7 +18,7 @@ enum { DRIVER, SRATE, NINPUT, NOUTPUT, // pp options DEFINE, UNDEF, INCLUDE, - DEBUG, + DEBUG, CDOC, NOPTIONS }; @@ -49,7 +49,8 @@ enum arg_type { ARG_DEFINE, ARG_UNDEF, ARG_INCLUDE, - ARG_DEBUG + ARG_DEBUG, + ARG_CDOC }; ANN static void arg_init(Arg* arg) { @@ -70,19 +71,24 @@ ANN void arg_release(Arg* arg) { vector_release(&arg->config); } -static inline bool _get_debug(const m_str dbg) { - if(!dbg || !strcmp(dbg, "true")) +static inline bool str2bool(const char *str) { + if(!str || !strcmp(str, "true")) return true; - if(!strcmp(dbg, "false")) + if(!strcmp(str, "false")) return false; - return atoi(dbg) ? true : false; + return atoi(str) ? true : false; } -ANN static inline void get_debug(const Gwion gwion, const m_str dbg) { - const bool is_dbg = _get_debug(dbg); +ANN static inline void get_debug(const Gwion gwion, const char *dbg) { + const bool is_dbg = str2bool(dbg); gwion_set_debug(gwion, is_dbg); } +ANN static inline void get_cdoc(const Gwion gwion, const char *cdoc) { + const bool is_cdoc = str2bool(cdoc); + gwion_set_cdoc(gwion, is_cdoc); +} + ANN void arg_compile(const Gwion gwion, Arg *arg) { const Vector v = &arg->add; for(m_uint i = 0; i < vector_size(v); i++) { @@ -203,6 +209,11 @@ static void setup_options(cmdapp_t* app, cmdopt_t* opt) { CMDOPT_MAYTAKEARG, NULL, "set/unset debug mode", &opt[DEBUG] ); + cmdapp_set(app, + 'H', "cdoc", + CMDOPT_MAYTAKEARG, NULL, + "set/unset cdoc mode", &opt[CDOC] + ); } static inline void add2arg(Arg *const arg, const char *data, const enum arg_type type) { @@ -326,6 +337,9 @@ static void myproc(void *data, cmdopt_t* option, const char* arg) { case 'G': add2arg(_arg, option->value, ARG_DEBUG); break; + case 'H': + get_cdoc(arg_int->gwion, option->value); + break; } } } diff --git a/src/gwion.c b/src/gwion.c index 879843a5..092fc9f6 100644 --- a/src/gwion.c +++ b/src/gwion.c @@ -211,3 +211,6 @@ ANN Nspc pop_global(struct Gwion_ *gwion) { ANN void gwion_set_debug(const Gwion gwion, const bool dbg) { gwion->emit->info->debug = dbg; } +ANN void gwion_set_cdoc(const Gwion gwion, const bool cdoc) { + gwion->data->cdoc = cdoc; +} diff --git a/src/gwiondata.c b/src/gwiondata.c index a85cd6a5..13d88071 100644 --- a/src/gwiondata.c +++ b/src/gwiondata.c @@ -20,7 +20,6 @@ ANN GwionData* new_gwiondata(MemPool mp) { GwionData *data = gwiondata(mp); map_init(&data->freearg); map_init(&data->id); - vector_init(&data->reserved); data->passes = new_passes(mp); return data; } @@ -29,7 +28,6 @@ ANN GwionData* cpy_gwiondata(MemPool mp, const GwionData* src) { GwionData *data = gwiondata(mp); data->freearg = src->freearg; data->id = src->id; - data->reserved = src->reserved; data->plug = src->plug; data->passes = src->passes; return data; @@ -46,7 +44,6 @@ ANN void free_gwiondata(const struct Gwion_ *gwion) { for(m_uint i = 0; i < map_size(&data->id); ++i) mp_free(gwion->mp, SpecialId, (struct SpecialId_*)map_at(&data->id, i)); map_release(&data->id); - vector_release(&data->reserved); free_passes(gwion->mp, data->passes); if(data->plug.ptr) free_plug(gwion); diff --git a/src/import/import_cdef.c b/src/import/import_cdef.c index fb1e2148..d6fed154 100644 --- a/src/import/import_cdef.c +++ b/src/import/import_cdef.c @@ -63,11 +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 + if(gwi->gwion->data->cdoc) { + lint_indent(gwi->lint); + gwi->lint->indent++; + lint_class_def(gwi->lint, t->info->cdef); + } return t; } @@ -122,11 +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->data->cdoc) { + gwi->lint->indent--; + lint_rbrace(gwi->lint); + lint_nl(gwi->lint); + } 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 7c2b9a84..87a84f9e 100644 --- a/src/import/import_enum.c +++ b/src/import/import_enum.c @@ -83,10 +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 + if(gwi->gwion->data->cdoc) { + lint_indent(gwi->lint); + lint_enum_def(gwi->lint, edef); + } 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 eb3c169e..42f8baab 100644 --- a/src/import/import_fdef.c +++ b/src/import/import_fdef.c @@ -54,10 +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->gwion->data->cdoc) { + lint_indent(gwi->lint); + lint_func_def(gwi->lint, fdef); + } if(gwi->effects.ptr) { vector_init(&fdef->base->effects); vector_copy2(&gwi->effects, &fdef->base->effects); @@ -136,10 +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(gwi->gwion->data->cdoc) { + lint_indent(gwi->lint); + lint_fptr_def(gwi->lint, fptr); + } 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 95d75916..19b25541 100644 --- a/src/import/import_internals.c +++ b/src/import/import_internals.c @@ -28,17 +28,20 @@ ANN void gwi_reset(const Gwi gwi) { env_reset(gwi->gwion->env); } +ANN static m_bool run_with_doc(const Gwi gwi, m_bool (*f)(const Gwi)) { + struct LintState ls = { .builtin=true }; + Lint linter = { .mp=gwi->gwion->mp, .ls=&ls }; + lint(&linter, "{-}#!+ %s{0}\n", gwi->gwion->env->name); + gwi->lint = &linter; + return f(gwi); +} ANN m_bool gwi_run(const Gwion gwion, m_bool (*f)(const Gwi)) { const m_str name = gwion->env->name; OperCK oper = {}; +printf("cdoc %u\n", gwion->data->cdoc); 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); + const m_bool ret = !gwion->data->cdoc ? + f(&gwi) : run_with_doc(&gwi, f); if(ret < 0) gwi_reset(&gwi); gwion->env->name = name; diff --git a/src/import/import_item.c b/src/import/import_item.c index 73c04ee6..f5c29824 100644 --- a/src/import/import_item.c +++ b/src/import/import_item.c @@ -34,12 +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(gwi->gwion->data->cdoc) { + lint_indent(gwi->lint); + lint_exp(gwi->lint, gwi->ck->exp); + lint_sc(gwi->lint); + lint_nl(gwi->lint); + } 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 f5f8ab92..9dea3fa1 100644 --- a/src/import/import_oper.c +++ b/src/import/import_oper.c @@ -69,30 +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->gwion->data->cdoc) { + 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_comma(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); } - 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_comma(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; diff --git a/src/import/import_special.c b/src/import/import_special.c index bb902c47..f1be4ebd 100644 --- a/src/import/import_special.c +++ b/src/import/import_special.c @@ -25,20 +25,14 @@ ANN void gwi_register_pass(const Gwi gwi, const m_str name, const compilation_pa pass_register(gwi->gwion, name, pass); } -ANN void gwi_reserve(const Gwi gwi, const m_str str) { - vector_add(&gwi->gwion->data->reserved, (vtype)insert_symbol(gwi->gwion->st, 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 + if(gwi->gwion->data->cdoc) + lint(gwi->lint, "{+C}specialid{0} %s{/}%s{0};\n", + spid->is_const ? "{+G}const{0} " : "", + id); 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); - gwi_reserve(gwi, id); } ANN void gwi_set_loc(const Gwi gwi, const m_str file, const uint line) { diff --git a/src/import/import_tdef.c b/src/import/import_tdef.c index 0f9c6214..47ae7996 100644 --- a/src/import/import_tdef.c +++ b/src/import/import_tdef.c @@ -33,10 +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 + if(gwi->gwion->data->cdoc) { + lint_indent(gwi->lint); + lint_type_def(gwi->lint, tdef); + } 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 00dc68d1..6237ea57 100644 --- a/src/import/import_type.c +++ b/src/import/import_type.c @@ -30,14 +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 + if(gwi->gwion->data->cdoc) { + 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); + } 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 5fd9e2eb..fe3c74f4 100644 --- a/src/import/import_udef.c +++ b/src/import/import_udef.c @@ -52,10 +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 + if(gwi->gwion->data->cdoc) { + lint_indent(gwi->lint); + lint_union_def(gwi->lint, udef); + } return udef->type; }