CFLAGS += -DGWION_BUILTIN
-GWLIBS = libgwion.a ast/libgwion_ast.a util/libgwion_util.a
+#GWLIBS = libgwion.a ast/libgwion_ast.a ast/libgwion_grammar.a util/libgwion_util.a
+GWLIBS = libgwion.a ast/libgwion_grammar.a ast/libgwion_ast.a util/libgwion_util.a
_LDFLAGS = ${GWLIBS} ${LDFLAGS}
all: options-show util/libgwion_util.a ast/libgwion_ast.a libgwion.a src/main.o
@(info build util)
ast/libgwion_ast.a:
- @make -C ast
+ @make -C ast libgwion_ast.a
+
+ast/libgwion_grammar.a:
+ @make -C ast libgwion_grammar.a
ast: ast/libgwion_ast.a
@(info build ast)
-Subproject commit 353d33a37749f7509d43f477283a84cf350f462d
+Subproject commit 252ebf19ecd24721e06a99b620cf20c55588a240
struct Arg_;
struct Gwion_ {
- PlugInfo* plug;
Env env;
Emitter emit;
VM* vm;
struct GwionData_ *data;
SymTable *st;
MemPool mp;
+ struct PPArg_ *ppa;
Type *type;
};
struct Vector_ child;
struct Vector_ child2;
struct Vector_ reserved;
- struct Map_ pass_map;
- struct Vector_ pass;
+ struct Passes_ *passes;
+ PlugInfo* plug;
} GwionData;
ANN GwionData* new_gwiondata(MemPool);
-ANN void free_gwiondata(MemPool, GwionData*);
+ANN void free_gwiondata(const struct Gwion_*);
#endif
#ifndef __GWIONPASS
#define __GWIONPASS
+struct Passes_ {
+ struct Map_ map;
+ struct Vector_ vec;
+};
// change this to gwion ?
typedef m_bool (*compilation_pass)(Env, Ast);
+ANEW ANN struct Passes_* new_passes(MemPool mp);
+ANN void free_passes(struct Passes_*);
ANN void pass_register(const Gwion, const m_str, const compilation_pass);
ANN void pass_default(const Gwion);
ANN m_bool pass_set(const Gwion, const Vector);
} PlugInfo;
ANN PlugInfo* new_plug(MemPool, Vector);
-ANN void plug_run(const Gwion gwion, const Vector);
-ANN void free_plug(const Gwion gwion);
-ANN void* get_module(const Gwion, const m_str);
+ANN void plug_run(const struct Gwion_*, const Vector);
+ANN void free_plug(const struct Gwion_*);
+ANN void* get_module(const struct Gwion_*, const m_str);
#define GWIMPORT_NAME import
#define GWMODSTR_NAME gwmodstr
#define GWMODINI_NAME gwmodini
#define GWMODEND_NAME gwmodend
#define GWDRIVER_NAME gwmodend
#define GWMODSTR(a) m_str GWMODSTR_NAME() { return #a; }
-#define GWMODINI(a) ANN2(1) void* GWMODINI_NAME(const Gwion gwion NUSED, const Vector args NUSED)
-#define GWMODEND(a) ANN void GWMODEND_NAME(const Gwion gwion NUSED, void* self NUSED)
+#define GWMODINI(a) ANN2(1) void* GWMODINI_NAME(const struct Gwion_ *gwion NUSED, const Vector args NUSED)
+#define GWMODEND(a) ANN void GWMODEND_NAME(const struct Gwion_ *gwion NUSED, void* self NUSED)
#define GWDRIVER(a) ANN void GWDRIVER_NAME(DriverData* d)
ANN Vector split_args(MemPool, const m_str str);
gw_err(_("option '-%c' needs arguments\n"), key);
return str;
}
+
ANN m_bool _arg_parse(const Gwion gwion, Arg* arg) {
for(int i = 1; i < arg->argc; ++i) {
if(arg->argv[i][0] == '-') {
}
static inline m_bool _check(struct Gwion_* gwion, struct Compiler* c) {
- struct ScannerArg_ arg = { c->name, c->file, gwion->st };
+ struct ScannerArg_ arg = { c->name, c->file, gwion->st, .ppa=gwion->ppa };
+// struct ScannerArg_ arg = { c->name, c->file, gwion->st, .ppa={} };
CHECK_OB((c->ast = parse(&arg)))
gwion->env->name = c->name;
- for(m_uint i = 0; i < vector_size(&gwion->data->pass); ++i) {
- const compilation_pass pass = (compilation_pass)vector_at(&gwion->data->pass, i);
+ for(m_uint i = 0; i < vector_size(&gwion->data->passes->vec); ++i) {
+ const compilation_pass pass = (compilation_pass)vector_at(&gwion->data->passes->vec, i);
CHECK_BB(pass(gwion->env, c->ast))
}
return GW_OK;
ANN m_bool gwion_audio(const Gwion gwion) {
Driver* di = gwion->vm->bbq;
if(di->si->arg) {
- for(m_uint i = 0; i < map_size(&gwion->plug->drv); ++i) {
- const m_str name = (m_str)VKEY(&gwion->plug->drv, i);
+ for(m_uint i = 0; i < map_size(&gwion->data->plug->drv); ++i) {
+ const m_str name = (m_str)VKEY(&gwion->data->plug->drv, i);
const size_t len = strlen(name);
if(!strncmp(name, di->si->arg, len)) {
- di->func = (f_bbqset)VVAL(&gwion->plug->drv, i);
+ di->func = (f_bbqset)VVAL(&gwion->data->plug->drv, i);
break;
}
}
}
ANN static inline m_bool gwion_engine(const Gwion gwion) {
- return type_engine_init(gwion->vm, &gwion->plug->vec[GWPLUG_IMPORT]) > 0;
+ return type_engine_init(gwion->vm, &gwion->data->plug->vec[GWPLUG_IMPORT]) > 0;
}
ANN static inline void gwion_compile(const Gwion gwion, const Vector v) {
gwion->mp = mempool_ini((sizeof(struct VM_Shred_) + SIZEOF_REG + SIZEOF_MEM));
gwion->st = new_symbol_table(gwion->mp, 65347);
gwion->vm = new_vm(gwion->mp, 1);
+ gwion->ppa = mp_calloc(gwion->mp, PPArg);
+ pparg_ini(gwion->mp, gwion->ppa);
gwion->emit = new_emitter(gwion->mp);
gwion->env = new_env(gwion->mp);
gwion->emit->env = gwion->env;
arg->si = gwion->vm->bbq->si;
const m_bool ret = arg_parse(gwion, arg);
if(ret) {
+ gwion->data->plug = new_plug(gwion->mp, &arg->lib);
gwion->emit->info->memoize = arg->memoize;
- gwion->plug = new_plug(gwion->mp, &arg->lib);
shreduler_set_loop(gwion->vm->shreduler, arg->loop);
if(gwion_audio(gwion) > 0 && gwion_engine(gwion)) {
plug_run(gwion, &arg->mod);
free_vm_shred(gwion->vm->cleaner_shred);
free_emitter(gwion->mp, gwion->emit);
free_vm(gwion->vm);
- free_plug(gwion);
- free_gwiondata(gwion->mp, gwion->data);
+ pparg_end(gwion->ppa);
+ mp_free(gwion->mp, PPArg, gwion->ppa);
+ free_gwiondata(gwion);
free_symbols(gwion->st);
xfree(gwion->type);
mempool_end(gwion->mp);
#include "gwion_util.h"
#include "gwion_ast.h"
#include "gwion_env.h"
+#include "plug.h"
#include "gwiondata.h"
#include "vm.h"
#include "instr.h"
-#include "gwion.h"
#include "emit.h"
+#include "gwion.h"
#include "specialid.h"
+#include "pass.h"
ANN GwionData* new_gwiondata(MemPool mp) {
struct GwionData_ *data = mp_calloc(mp, GwionData);
map_init(&data->freearg);
map_init(&data->id);
vector_init(&data->reserved);
- map_init(&data->pass_map);
- vector_init(&data->pass);
+ data->passes = new_passes(mp);
MUTEX_SETUP(data->mutex);
return data;
}
-ANN void free_gwiondata(MemPool mp, GwionData *data) {
+ANN void free_gwiondata(const struct Gwion_ *gwion) {
+ struct GwionData_ *data = gwion->data;
map_release(&data->freearg);
for(m_uint i = 0; i < map_size(&data->id); ++i)
- mp_free(mp, SpecialId, (struct SpecialId_*)map_at(&data->id, i));
+ mp_free(gwion->mp, SpecialId, (struct SpecialId_*)map_at(&data->id, i));
map_release(&data->id);
vector_release(&data->reserved);
- map_release(&data->pass_map);
- vector_release(&data->pass);
+ free_passes(data->passes);
+ if(data->plug)
+ free_plug(gwion);
MUTEX_CLEANUP(data->mutex);
- mp_free(mp, GwionData, data);
+ mp_free(gwion->mp, GwionData, data);
}
Arg arg = { .argc=argc, .argv=argv, .loop=-1 };
signal(SIGINT, sig);
signal(SIGTERM, sig);
- struct Gwion_ gwion = { .plug=NULL };
+ struct Gwion_ gwion = {};
const m_bool ini = gwion_ini(&gwion, &arg);
arg_release(&arg);
if(ini > 0)
ANN void pass_register(const Gwion gwion, const m_str name, const compilation_pass pass) {
const Symbol sym = insert_symbol(gwion->st, name);
- map_set(&gwion->data->pass_map, (vtype)sym, (vtype)pass);
+ map_set(&gwion->data->passes->map, (vtype)sym, (vtype)pass);
}
ANN m_bool pass_set(const Gwion gwion, const Vector passes) {
- const Vector v = &gwion->data->pass;
+ const Vector v = &gwion->data->passes->vec;
vector_clear(v);
for(m_uint i = 0; i < vector_size(passes); ++i) {
const m_str name = (m_str)vector_at(passes, i);
const Symbol sym = insert_symbol(gwion->st, name);
- const compilation_pass pass = (compilation_pass)map_get(&gwion->data->pass_map, (vtype)sym);
+ const compilation_pass pass = (compilation_pass)map_get(&gwion->data->passes->map, (vtype)sym);
if(!pass) {
gw_err("Failed to set compilation passes, back to default\n");
pass_default(gwion);
pass_set(gwion, &v);
vector_release(&v);
}
+
+
+ANEW ANN struct Passes_* new_passes(MemPool mp) {
+ struct Passes_ *a = mp_calloc(mp, Passes);
+ map_init(&a->map);
+ vector_init(&a->vec);
+ return a;
+}
+
+ANN void free_passes(struct Passes_ *a) {
+ map_release(&a->map);
+ vector_release(&a->vec);
+}
typedef m_bool (*import)(Gwi);
typedef m_str (*modstr)(void);
-typedef void* (*modini)(const Gwion, const Vector);
-typedef void* (*modrun)(const Gwion, void*);
-typedef void* (*modend)(const Gwion, void*);
+typedef void* (*modini)(const struct Gwion_*, const Vector);
+typedef void* (*modrun)(const struct Gwion_*, void*);
+typedef void* (*modend)(const struct Gwion_*, void*);
struct Plug_ {
m_str name;
return pi;
}
-void free_plug(const Gwion gwion) {
- PlugInfo *p = gwion->plug;
+void free_plug(const struct Gwion_ *gwion) {
+ PlugInfo *p = gwion->data->plug;
struct Vector_ * const v = p->vec;
for(m_uint i = 0; i < vector_size(&v[GWPLUG_MODULE]); ++i) {
struct Plug_ *plug = (struct Plug_*)vector_at(&v[GWPLUG_MODULE], i);
return NULL;
}
-void plug_run(const Gwion gwion, const Vector args) {
- const Vector v = &gwion->plug->vec[GWPLUG_MODULE];
+void plug_run(const struct Gwion_ *gwion, const Vector args) {
+ const Vector v = &gwion->data->plug->vec[GWPLUG_MODULE];
for(m_uint i = 0; i < vector_size(v); ++i) {
struct Plug_ *plug = (struct Plug_*)vector_at(v, i);
const Vector arg = get_arg(gwion->mp, plug->name, args);
}
}
-ANN void* get_module(const Gwion gwion, const m_str name) {
- const Vector v = &gwion->plug->vec[GWPLUG_MODULE];
+ANN void* get_module(const struct Gwion_ *gwion, const m_str name) {
+ const Vector v = &gwion->data->plug->vec[GWPLUG_MODULE];
for(m_uint i = 0; i < vector_size(v); ++i) {
struct Plug_ *plug = (struct Plug_*)vector_at(v, i);
if(!strcmp(name, plug->name))