bool cdoc;
} GwionData;
-ANN GwionData* new_gwiondata(MemPool);
+ANN GwionData* new_gwiondata(const MemPool);
ANN GwionData* cpy_gwiondata(MemPool, const GwionData*);
-ANN void free_gwiondata(const struct Gwion_*);
+ANN void free_gwiondata(const Gwion);
ANN void free_gwiondata_cpy(const MemPool, GwionData*);
#endif
// change this to gwion ?
typedef m_bool (*compilation_pass)(const Env, PassArg);
-ANEW ANN struct Passes_* new_passes(MemPool mp);
+ANEW ANN struct Passes_* new_passes(const Gwion);
ANN void free_passes(MemPool mp, struct Passes_*);
ANN void pass_register(const Gwion, const m_str, const compilation_pass);
ANN void pass_default(const Gwion);
}
ANN m_bool isres(const Env env, const Symbol xid, const loc_t pos) {
- if(vector_find(&env->gwion->data->reserved, (vtype)xid) > -1)
- ERR_B(pos, _("%s is reserved."), s_name(xid));
+ const Map map = &env->gwion->data->id;
+ for(m_uint i = 0; i < map_size(map); i++) {
+ if(xid == (Symbol)VKEY(map, i))
+ ERR_B(pos, _("%s is reserved."), s_name(xid));
+ }
return GW_OK;
}
#define LOCALE_INFO INSTALL_PREFIX "/share"
+ANN static void doc_mode(const Gwion gwion) {
+ struct Vector_ v;
+ vector_init(&v);
+ vector_add(&v, (m_uint)"scan0");
+ pass_set(gwion, &v);
+}
+
ANN m_bool gwion_ini(const Gwion gwion, Arg* arg) {
#ifdef USE_GETTEXT
setlocale(LC_ALL, NULL);
gwion_core(gwion);
gwion->data = new_gwiondata(gwion->mp);
gwion->type = (Type*)xcalloc(MAX_TYPE, sizeof(struct Type_*));
- pass_default(gwion);
arg->si = gwion->vm->bbq->si = new_soundinfo(gwion->mp);
+ new_passes(gwion);
CHECK_BB(arg_parse(gwion, arg));
if(arg->color == COLOR_NEVER)
tcol_override_color_checks(0);
tcol_override_color_checks(isatty(1));
else if(arg->color == COLOR_ALWAYS)
tcol_override_color_checks(1);
+ if(!gwion->data->cdoc)
+ pass_default(gwion);
+ else
+ doc_mode(gwion);
return !arg->quit ? gwion_ok(gwion, arg) : GW_ERROR;
}
return data;
}
-ANN GwionData* new_gwiondata(MemPool mp) {
+ANN GwionData* new_gwiondata(const MemPool mp) {
GwionData *data = gwiondata(mp);
map_init(&data->freearg);
map_init(&data->id);
- data->passes = new_passes(mp);
return data;
}
mp_free(mp, GwionData, data);
}
-ANN void free_gwiondata(const struct Gwion_ *gwion) {
+ANN void free_gwiondata(const Gwion gwion) {
GwionData *data = gwion->data;
map_release(&data->freearg);
for(m_uint i = 0; i < map_size(&data->id); ++i)
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 };
const m_bool ret = !gwion->data->cdoc ?
f(&gwi) : run_with_doc(&gwi, f);
#include "pass.h"
#include "traverse.h"
-static const m_str default_passes_name[] = { "check", "emit" };
-static const compilation_pass default_passes[] = { traverse_ast, emit_ast };
-#define NPASS sizeof(default_passes)/sizeof(default_passes[0])
+#define N_PASS 2
+#define N_SCANPASS 4
+
+static const m_str default_passes_name[2] = { "check", "emit" };
+static const compilation_pass default_passes[4] = { traverse_ast, emit_ast };
+static const m_str scan_passes_name[4] = { "scan0", "scan1", "scan2", "type_check" };
+static const compilation_pass scan_passes[4] = { scan0_ast, scan1_ast, scan2_ast, check_ast };
ANN void pass_register(const Gwion gwion, const m_str name, const compilation_pass pass) {
const Symbol sym = insert_symbol(gwion->st, name);
ANN void pass_default(const Gwion gwion) {
struct Vector_ v;
vector_init(&v);
- for(m_uint i = 0; i < NPASS; ++i) {
+ for(m_uint i = 0; i < N_PASS; ++i)
vector_add(&v, (vtype)default_passes_name[i]);
- pass_register(gwion, default_passes_name[i], default_passes[i]);
- }
pass_set(gwion, &v);
vector_release(&v);
}
-
-ANEW ANN struct Passes_* new_passes(MemPool mp) {
- struct Passes_ *a = mp_calloc(mp, Passes);
+ANEW ANN struct Passes_* new_passes(const Gwion gwion) {
+ struct Passes_ *a = gwion->data->passes = mp_calloc(gwion->mp, Passes);
map_init(&a->map);
+ for(m_uint i = 0; i < N_PASS; ++i)
+ pass_register(gwion, default_passes_name[i], default_passes[i]);
+ for(m_uint i = 0; i < N_SCANPASS; ++i)
+ pass_register(gwion, scan_passes_name[i], scan_passes[i]);
vector_init(&a->vec);
return a;
}