[submodule "libcmdapp"]
path = libcmdapp
url = https://github.com/euppal/libcmdapp
+[submodule "fmt"]
+ path = fmt
+ url = https://github.com/Gwion/gwion-fmt
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")\"
_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
-Subproject commit 883e43a8b7068e5f17bfb1963d5eea676a326edb
+Subproject commit 13713de48c46bbbeb8d6b69518a959f6d378c00d
--- /dev/null
+Subproject commit bec8fef4607fac18fa92da87e95e0da1c3ac76f4
#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;
struct OperCK *oper; // _misc
struct Vector_ effects;
loc_t loc;
-#ifdef GWION_DOC
Lint *lint;
-#endif
uint8_t tmpls;
};
}
ANN void gwion_set_debug(const Gwion gwion, const bool dbg);
+ANN void gwion_set_cdoc(const Gwion gwion, const bool dbg);
#endif
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);
-Subproject commit 9a2bcfb85e5ca94cc6f2697f5a41c09c1c18db3f
+Subproject commit b063526d5aa60de490c9ae2fdca6ee9c87bae9c2
DRIVER, SRATE, NINPUT, NOUTPUT,
// pp options
DEFINE, UNDEF, INCLUDE,
- DEBUG,
+ DEBUG, CDOC,
NOPTIONS
};
ARG_DEFINE,
ARG_UNDEF,
ARG_INCLUDE,
- ARG_DEBUG
+ ARG_DEBUG,
+ ARG_CDOC
};
ANN static void arg_init(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++) {
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) {
case 'G':
add2arg(_arg, option->value, ARG_DEBUG);
break;
+ case 'H':
+ get_cdoc(arg_int->gwion, option->value);
+ break;
}
}
}
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;
+}
GwionData *data = gwiondata(mp);
map_init(&data->freearg);
map_init(&data->id);
- vector_init(&data->reserved);
data->passes = new_passes(mp);
return data;
}
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;
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);
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;
}
}
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);
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);
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);
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);
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;
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));
}
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;
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) {
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);
}
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);
// 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;
}