typedef struct Gwion_* Gwion;
#include "plug.h"
#include "driver.h"
+#include "gwiondata.h"
struct Arg_;
+
struct Gwion_ {
PlugInfo* plug;
Env env;
Emitter emit;
VM* vm;
- struct Map_ freearg;
+ struct GwionData_ *data;
SymTable *st;
MemPool mp;
- struct Vector_ child;
};
ANN m_bool gwion_ini(const Gwion, struct Arg_*);
--- /dev/null
+#ifndef __GWIONDATA
+#define __GWIONDATA
+
+typedef struct GwionData_ {
+ struct Map_ freearg;
+ MUTEX_TYPE mutex;
+ struct Vector_ child;
+ struct Vector_ reserved;
+} GwionData;
+
+ANN GwionData* new_gwiondata(MemPool);
+ANN void free_gwiondata(MemPool, GwionData*);
+#endif
#define FREEARG(a) ANN void a(Instr instr NUSED, void *gwion NUSED)
typedef void (*f_freearg)(Instr, void*);
ANN void register_freearg(const Gwi, const f_instr, void(*)(const Instr,void*));
+ANN void gwi_reserve(const Gwi, const m_str);
+
#endif
static m_bool check(struct Gwion_* gwion, struct Compiler* c) {
CHECK_BB(compiler_open(c))
struct ScannerArg_ arg = { c->name, c->file, gwion->st };
+ MUTEX_LOCK(gwion->data->mutex);
CHECK_OB((c->ast = parse(&arg)))
gwion->env->name = c->name;
- return type_engine_check_prog(gwion->env, c->ast);
+ const m_bool ret = type_engine_check_prog(gwion->env, c->ast);
+ MUTEX_UNLOCK(gwion->data->mutex);
+ return ret;
}
static m_uint compile(struct Gwion_* gwion, struct Compiler* c) {
VM_Shred shred = NULL;
VM_Code code;
compiler_name(gwion->mp, c);
+ MUTEX_LOCK(gwion->data->mutex);
if(check(gwion, c) < 0 ||
!(code = emit_ast(gwion->emit, c->ast)))
gw_err("while compiling file '%s'\n", c->base);
shred->info->args = c->args;
vm_add_shred(gwion->vm, shred);
}
+ MUTEX_UNLOCK(gwion->data->mutex);
compiler_clean(gwion->mp, c);
return shred ? shred->tick->xid : 0;
}
gwion->vm->bbq->si = soundinfo_cpy(src->gwion->mp, src->bbq->si);
gwion->emit = src->gwion->emit;
gwion->env = src->gwion->env;
- gwion->freearg = src->gwion->freearg;
+ gwion->data = src->gwion->data;
gwion->st = src->gwion->st;
gwion->mp = src->gwion->mp;
return gwion->vm;
arg_parse(arg);
gwion->emit->memoize = arg->memoize;
gwion->plug = new_plug(gwion->mp, &arg->lib);
- map_init(&gwion->freearg);
+ gwion->data = new_gwiondata(gwion->mp);
shreduler_set_loop(gwion->vm->shreduler, arg->loop);
if(gwion_audio(gwion) > 0 && gwion_engine(gwion)) {
gwion_compile(gwion, &arg->add);
gwion->vm->cleaner_shred = new_vm_shred(gwion->mp, code);
vm_add_shred(gwion->vm, gwion->vm->cleaner_shred);
MUTEX_LOCK(gwion->vm->shreduler->mutex);
- if(gwion->child.ptr)
- fork_clean(gwion->vm, &gwion->child);
+ if(gwion->data->child.ptr)
+ fork_clean(gwion->vm, &gwion->data->child);
MUTEX_UNLOCK(gwion->vm->shreduler->mutex);
free_env(gwion->env);
free_vm_shred(gwion->vm->cleaner_shred);
free_emitter(gwion->emit);
free_vm(gwion->vm);
free_plug(gwion);
- map_release(&gwion->freearg);
+ free_gwiondata(gwion->mp, gwion->data);
free_symbols(gwion->st);
mempool_end(gwion->mp);
}
--- /dev/null
+#include "gwion_util.h"
+#include "gwiondata.h"
+
+ANN GwionData* new_gwiondata(MemPool mp) {
+ struct GwionData_ *data = mp_alloc(mp, GwionData);
+ map_init(&data->freearg);
+ vector_init(&data->reserved);
+ MUTEX_SETUP(data->mutex);
+ return data;
+}
+
+ANN void free_gwiondata(MemPool mp, GwionData *data) {
+ map_release(&data->freearg);
+ vector_release(&data->reserved);
+ MUTEX_CLEANUP(data->mutex);
+ mp_free(mp, GwionData, data);
+}
register_freearg(gwi, SporkIni, freearg_xork);
register_freearg(gwi, ForkIni, freearg_xork);
register_freearg(gwi, DotTmpl, freearg_dottmpl);
+ gwi_reserve(gwi, "__func__");
return GW_OK;
}
}
ANN void register_freearg(const Gwi gwi, const f_instr _exec, void(*_free)(const Instr, void*)) {
- map_set(&gwi->gwion->freearg, (vtype)_exec, (vtype)_free);
+ map_set(&gwi->gwion->data->freearg, (vtype)_exec, (vtype)_free);
+}
+
+ANN void gwi_reserve(const Gwi gwi, const m_str str) {
+ vector_add(&gwi->gwion->data->reserved, (vtype)insert_symbol(gwi->gwion->st, str));
}
CHECK_BB(gwi_oper_end(gwi, op_not, IntNot))
gwi_item_ini(gwi, "@null", "null");
gwi_item_end(gwi, 0, NULL);
+ gwi_reserve(gwi, "this");
return GW_OK;
}
CHECK_BB(gwi_enum_add(gwi, "true", 1))
t_bool = gwi_enum_end(gwi);
CHECK_BB(gwi_item_ini(gwi, "bool", "maybe"))
- return gwi_item_end(gwi, 0, NULL);
+ CHECK_BB(gwi_item_end(gwi, 0, NULL))
+ gwi_reserve(gwi, "maybe");
+ return GW_OK;
}
static GWION_IMPORT(int) {
gwi_item_end(gwi, ae_flag_const, t_zero);
gwi_item_ini(gwi, "@now", "now");
gwi_item_end(gwi, ae_flag_const, NULL);
+ gwi_reserve(gwi, "now");
return GW_OK;
}
fork_retval(me);
MUTEX_LOCK(vm->shreduler->mutex);
// MUTEX_LOCK(FORK_ORIG(me)->shreduler->mutex);
- vector_rem2(&FORK_ORIG(me)->gwion->child, (vtype)me);
+ vector_rem2(&FORK_ORIG(me)->gwion->data->child, (vtype)me);
// MUTEX_UNLOCK(FORK_ORIG(me)->shreduler->mutex);
*(m_int*)(me->data + o_fork_done) = 1;
broadcast(*(M_Object*)(me->data + o_fork_ev));
void fork_launch(const VM* vm, const M_Object o, const m_uint sz) {
o->ref += 2;
- if(!vm->gwion->child.ptr)
- vector_init(&vm->gwion->child);
- vector_add(&vm->gwion->child, (vtype)o);
+ if(!vm->gwion->data->child.ptr)
+ vector_init(&vm->gwion->data->child);
+ vector_add(&vm->gwion->data->child, (vtype)o);
FORK_ORIG(o) = (VM*)vm;
FORK_RETSIZE(o) = sz;
THREAD_CREATE(FORK_THREAD(o), fork_run, o);
CHECK_BB(gwi_func_end(gwi, 0))
CHECK_BB(gwi_class_end(gwi))
SET_FLAG((t_fork), abstract);
+ gwi_reserve(gwi, "me");
return GW_OK;
}
CHECK_BB(gwi_oper_add(gwi, at_varobj))
CHECK_BB(gwi_oper_end(gwi, op_ref, VarargAssign))
register_freearg(gwi, VarargIni, freearg_vararg);
+ gwi_reserve(gwi, "vararg");
return GW_OK;
}
Type t = decl->type;
const Var_Decl var = list->self;
const Value former = nspc_lookup_value0(env->curr, var->xid);
- if(!GET_FLAG(decl->td, builtin))
- CHECK_BB(isres(env, var->xid, exp_self(decl)->pos))
+ CHECK_BB(isres(env, var->xid, exp_self(decl)->pos))
if(former && !decl->td->exp &&
(!env->class_def || !(GET_FLAG(env->class_def, template) || GET_FLAG(env->class_def, scan1))))
ERR_B(var->pos, "variable %s has already been defined in the same scope...",
#include "parse.h"
ANN m_bool isres(const Env env, const Symbol xid, const loc_t pos) {
- const m_str s = s_name(xid);
- if(!strcmp(s, "this") ||
- !strcmp(s, "me") ||
- !strcmp(s, "now") ||
- !strcmp(s, "maybe") ||
- !strcmp(s, "vararg") ||
+// const m_str s = s_name(xid);
+ if(vector_find(&env->gwion->data->reserved, (vtype)xid) > -1)
+ ERR_B(pos, "%s is reserved.", s_name(xid));
+/*
+ if(!strcmp(s, "this") || //
+ !strcmp(s, "me") || //
+ !strcmp(s, "now") || //
+ !strcmp(s, "maybe") || //
+ !strcmp(s, "vararg") || //
!strcmp(s, "__func__") ||
!name2op(s))
ERR_B(pos, "%s is reserved.", s_name(xid));
+*/
return GW_OK;
}
ANN /*static*/ void free_code_instr(const Vector v, const Gwion gwion) {
for(m_uint i = vector_size(v) + 1; --i;) {
const Instr instr = (Instr)vector_at(v, i - 1);
- const f_freearg f = (f_freearg)(map_get(&gwion->freearg, instr->opcode) ?:
- map_get(&gwion->freearg, (vtype)instr->execute));
+ const f_freearg f = (f_freearg)(map_get(&gwion->data->freearg, instr->opcode) ?:
+ map_get(&gwion->data->freearg, (vtype)instr->execute));
if(f)
f(instr, gwion);
mp_free(gwion->mp, Instr, instr);