#else
#define GWION_IMPORT(a) ANN m_bool import(const Gwi gwi)
#endif
-#define ALLOC_PTR(p, a, b, c) b* a = (b*)_mp_alloc(p, sizeof(b)); *a = (b)c
+#define ALLOC_PTR(p, a, b, c) b* a = (b*)_mp_calloc(p, sizeof(b)); *a = (b)c
#define _CHECK_OP(op, check, func)\
CHECK_BB(gwi_oper_add(gwi, opck_##check))\
CHECK_BB(gwi_oper_end(gwi, op_##op, func))
ANN void did_you_mean_nspc(const Nspc, const char*);
ANN void did_you_mean_type(const Type, const char*);
-ANN static inline void nspc_allocdata(const Nspc nspc) {
+ANN static inline void nspc_allocdata(MemPool mp, const Nspc nspc) {
if(nspc->info->class_data_size)
- nspc->info->class_data = (m_bit*)xcalloc(1, nspc->info->class_data_size);
+// nspc->info->class_data = (m_bit*)xcalloc(1, nspc->info->class_data_size);
+ nspc->info->class_data = (m_bit*)mp_calloc2(mp, nspc->info->class_data_size);
}
#endif
#define HAS_OBJ RefCount* ref;
ANN static inline RefCount* new_refcount(MemPool mp, void(*free)(void*,void*)) {
- RefCount *ref = mp_alloc(mp, RefCount);
+ RefCount *ref = mp_calloc(mp, RefCount);
ref->count = 1;
ref->free= free;
return ref;
}
ANEW static Frame* new_frame(MemPool p) {
- Frame* frame = mp_alloc(p, Frame);
+ Frame* frame = mp_calloc(p, Frame);
vector_init(&frame->stack);
vector_add(&frame->stack, (vtype)NULL);
return frame;
}
ANN static Local* new_local(MemPool p, const m_uint size, const m_bool is_obj) {
- Local* local = mp_alloc(p, Local);
+ Local* local = mp_calloc(p, Local);
local->size = size;
local->is_obj = is_obj;
return local;
ANN static m_bool emit_func_def(const Emitter emit, const Func_Def func_def);
ANEW static Code* new_code(const Emitter emit, const m_str name) {
- Code* code = mp_alloc(emit->gwion->mp, Code);
+ Code* code = mp_calloc(emit->gwion->mp, Code);
code->name = code_name_set(name, emit->env->name);
vector_init(&code->instr);
vector_init(&code->stack_break);
ANN ArrayInfo* emit_array_extend_inner(const Emitter emit, const Type t, const Exp e) {
CHECK_BO(emit_exp(emit, e, 0))
const Type base = array_base(t);
- ArrayInfo* info = mp_alloc(emit->gwion->mp, ArrayInfo);
+ ArrayInfo* info = mp_calloc(emit->gwion->mp, ArrayInfo);
vector_init(&info->type);
for(m_uint i = 1; i < t->array_depth; ++i)
vector_add(&info->type, (vtype)array_type(emit->env, base, i));
if(is_obj && (is_array || !is_ref))
CHECK_BB(emit_instantiate_object(emit, type, array, is_ref))
const Instr instr = emit_kind(emit, v->type->size, emit_addr, dotstatic);
- v->d.ptr = mp_alloc2(emit->gwion->mp, v->type->size);
+ v->d.ptr = mp_calloc2(emit->gwion->mp, v->type->size);
SET_FLAG(v, union);
instr->m_val = (m_uint)v->d.ptr;
instr->m_val2 = v->type->size;
char c[sz + 1];
memcpy(c, f->name, sz);
c[sz] = '\0';
- struct dottmpl_ *dt = mp_alloc(emit->gwion->mp, dottmpl);
+ struct dottmpl_ *dt = mp_calloc(emit->gwion->mp, dottmpl);
dt->name = s_name(insert_symbol(c));
dt->overload = f->def->tmpl->base;
dt->tl = tmpl_tl(emit->env, c);
} while((l = l->next));
}
-ANN static inline void union_allocdata(const Stmt_Union stmt) {
+ANN static inline void union_allocdata(MemPool mp, const Stmt_Union stmt) {
const Nspc nspc = (stmt->xid ? stmt->value->type : stmt->type)->nspc;
- nspc_allocdata(nspc);
+ nspc_allocdata(mp, nspc);
nspc->info->offset = stmt->s;
}
m_uint scope = emit->env->scope->depth;
const m_bool global = GET_FLAG(stmt, global);
if(stmt->xid) {
- union_allocdata(stmt);
+ union_allocdata(emit->gwion->mp, stmt);
Type_Decl *type_decl = new_type_decl(emit->gwion->mp,
new_id_list(emit->gwion->mp, stmt->xid, loc_cpy(emit->gwion->mp, stmt_self(stmt)->pos)),
stmt->flag);
}
scope = emit_push_type(emit, stmt->value->type);
} else if(stmt->type_xid) {
- union_allocdata(stmt);
+ union_allocdata(emit->gwion->mp, stmt);
scope = emit_push_type(emit, stmt->type);
} else if(emit->env->class_def) {
if(!GET_FLAG(l->self->d.exp_decl.list->self->value, member))
if(!base->nspc->pre_ctor)
CHECK_BB(emit_class_def(emit, base->e->def))
}
- nspc_allocdata(nspc);
+ nspc_allocdata(emit->gwion->mp, nspc);
emit_class_code(emit, type->name);
if(cdef->base.ext && cdef->base.ext->array)
CHECK_BB(emit_array_extend(emit, type->e->parent, cdef->base.ext->array->exp))
__attribute__((returns_nonnull))
ANN2(1) Instr emit_add_instr(const Emitter emit, const f_instr f) {
- const Instr instr = mp_alloc(emit->gwion->mp, Instr);
+ const Instr instr = mp_calloc(emit->gwion->mp, Instr);
if((m_uint)f < 255)
instr->opcode = (m_uint)f;
else {
#include "escape.h"
char* escape_table(void) {
- char *escape = (char*)xcalloc(256, sizeof(char));
+ char *escape = (char*)calloc(256, sizeof(char));
escape['0'] = '0';
escape['\''] = '\'';
escape['"'] = '"';
{ memoize_return1, memoize_return2, memoize_return3, memoize_return4};
Memoize memoize_ini(const Emitter emit, const Func f, const enum Kind kind) {
- Memoize m = mp_alloc(emit->gwion->mp, Memoize);
+ Memoize m = mp_calloc(emit->gwion->mp, Memoize);
vector_init(&m->v);
m->ret_sz = f->def->base->ret_type->size;
m->kind = kind;
}
static inline void memoize_set(Memoize m, const m_bit* arg) {
- m_bit* data = _mp_alloc2(m->p);
+ m_bit* data = _mp_calloc2(m->p, 0);
memcpy(data, arg, m->arg_sz);
if(vector_size(&m->v) < m->limit)
vector_add(&m->v, (vtype)data);
mreturn[m->kind](data + m->arg_sz, shred->reg-m->ret_sz, m->ret_sz);
return;
}
-}
\ No newline at end of file
+}
#include "shreduler_private.h"
ANN VM* gwion_cpy(const VM* src) {
- const Gwion gwion = mp_alloc(src->gwion->mp, Gwion);
+ const Gwion gwion = mp_calloc(src->gwion->mp, Gwion);
gwion->vm = new_vm(src->gwion->mp, 0);
gwion->vm->gwion = gwion;
gwion->vm->bbq->si = soundinfo_cpy(src->gwion->mp, src->bbq->si);
#include "gwiondata.h"
ANN GwionData* new_gwiondata(MemPool mp) {
- struct GwionData_ *data = mp_alloc(mp, GwionData);
+ struct GwionData_ *data = mp_calloc(mp, GwionData);
map_init(&data->freearg);
vector_init(&data->reserved);
MUTEX_SETUP(data->mutex);
}
M_Vector new_m_vector(MemPool p, const m_uint size) {
- const M_Vector array = mp_alloc(p, M_Vector);
+ const M_Vector array = mp_calloc(p, M_Vector);
const size_t sz = (ARRAY_OFFSET*SZ_INT) + (2*size);
array->ptr = (m_bit*)xcalloc(1, sz);
ARRAY_CAP(array) = 2;
}
M_Vector new_m_vector2(MemPool p, const m_uint size, const m_uint len) {
- const M_Vector array = mp_alloc(p, M_Vector);
+ const M_Vector array = mp_calloc(p, M_Vector);
const size_t sz = (ARRAY_OFFSET*SZ_INT) + (len*size);
array->ptr = (m_bit*)xcalloc(1, sz);
m_uint cap = 1;
ANN m_int gwi_class_end(const Gwi gwi) {
if(!gwi->gwion->env->class_def)
GWI_ERR_B("import: too many class_end called.")
- nspc_allocdata(gwi->gwion->env->class_def->nspc);
+ nspc_allocdata(gwi->gwion->mp, gwi->gwion->env->class_def->nspc);
env_pop(gwi->gwion->env, 0);
return GW_OK;
}
}
M_Object new_object(MemPool p, const VM_Shred shred, const Type t) {
- const M_Object a = mp_alloc(p, M_Object);
+ const M_Object a = mp_calloc(p, M_Object);
a->ref = 1;
a->type_ref = t;
a->vtable = &t->nspc->info->vtable;
if(t->nspc->info->offset)
- a->data = (m_bit*)_mp_alloc(p, t->nspc->info->offset);
+ a->data = (m_bit*)_mp_calloc(p, t->nspc->info->offset);
if(shred)
vector_add(&shred->gc, (vtype)a);
return a;
describe_compute(multi, trig, {u->module.gen.trig->compute(u->module.gen.trig);})
ANEW static UGen new_UGen(MemPool p) {
- const UGen u = mp_alloc(p, UGen);
+ const UGen u = mp_calloc(p, UGen);
u->op = ugop_add;
u->compute = gen_compute_mono;
return u;
ANN void ugen_ini(MemPool p, const UGen u, const uint in, const uint out) {
const uint chan = in > out ? in : out;
if(chan == 1) {
- u->connect.net = mp_alloc(p, ugen_net);
+ u->connect.net = mp_calloc(p, ugen_net);
vector_init(&u->connect.net->from);
vector_init(&u->connect.net->to);
} else {
- u->connect.multi = mp_alloc(p, ugen_multi);
+ u->connect.multi = mp_calloc(p, ugen_multi);
u->connect.multi->n_in = in;
u->connect.multi->n_out = out;
u->connect.multi->n_chan = chan;
}
INSTR(VarargIni) {
- struct Vararg_* arg = mp_alloc(shred->info->mp, Vararg);
+ struct Vararg_* arg = mp_calloc(shred->info->mp, Vararg);
POP_REG(shred, instr->m_val - SZ_INT)
arg->d = (m_bit*)xmalloc(instr->m_val);
for(m_uint i = 0; i < instr->m_val; i += SZ_INT)
}
ANN2(2) Context new_context(MemPool p, const Ast ast, const m_str str) {
- const Context context = mp_alloc(p, Context);
+ const Context context = mp_calloc(p, Context);
context->nspc = new_nspc(p, str);
context->tree = ast;
context->name = str;
#include "parse.h"
ANN static struct Env_Scope_ *new_envscope(MemPool p) {
- struct Env_Scope_ *a = mp_alloc(p, Env_Scope);
+ struct Env_Scope_ *a = mp_calloc(p, Env_Scope);
vector_init(&a->breaks);
vector_init(&a->conts);
vector_init(&a->class_stack);
vector_init(&a->nspc_stack);
vector_init(&a->known_ctx);
- a->swi = mp_alloc(p, Scope);
+ a->swi = mp_calloc(p, Scope);
_scope_init(a->swi);
map_init(&a->swi->map);
return a;
free_nspc_value(a, gwion);
if(a->info->class_data)
- free(a->info->class_data);
+ mp_free2(gwion->mp, a->info->class_data_size, a->info->class_data);
if(a->info->vtable.ptr)
vector_release(&a->info->vtable);
if(a->info->op_map.ptr)
}
ANN Nspc new_nspc(MemPool p, const m_str name) {
- const Nspc a = mp_alloc(p, Nspc);
+ const Nspc a = mp_calloc(p, Nspc);
a->name = name;
- a->info = mp_alloc(p, NspcInfo);
+ a->info = mp_calloc(p, NspcInfo);
a->info->value = new_scope(p);
a->info->type = new_scope(p);
a->info->func = new_scope(p);
static inline void _scope_clear(Scope s) { vector_clear((Vector)(void*)s); }
static Switch new_switch(MemPool p) {
- Switch sw = mp_alloc(p, Switch);
+ Switch sw = mp_calloc(p, Switch);
sw->cases = new_map(p); // could be struct ?
vector_init(&sw->exp);
sw->vec = new_vector(p);
};
ANN static Switch new_swinfo(const Env env, const Stmt_Switch stmt) {
- struct SwInfo_ *info = mp_alloc(env->gwion->mp, SwInfo);
+ struct SwInfo_ *info = mp_calloc(env->gwion->mp, SwInfo);
info->s = stmt;
info->t = env->class_def;
info->f = env->func;
}
Type new_type(MemPool p, const m_uint xid, const m_str name, const Type parent) {
- const Type type = mp_alloc(p, Type);
+ const Type type = mp_calloc(p, Type);
type->xid = xid;
type->name = name;
- type->e = mp_alloc(p, TypeInfo);
+ type->e = mp_calloc(p, TypeInfo);
type->e->parent = parent;
if(type->e->parent)
type->size = parent->size;
}
ANN Value new_value(MemPool p, const Type type, const m_str name) {
- const Value a = mp_alloc(p, Value);
+ const Value a = mp_calloc(p, Value);
a->type = type;
a->name = name;
a->ref = new_refcount(p, free_value);
}
ANN Func new_func(MemPool p, const m_str name, const Func_Def def) {
- Func func = mp_alloc(p, Func);
+ Func func = mp_calloc(p, Func);
func->name = name;
func->def = def;
func->ref = new_refcount(p, free_func);
map_set(&nspc->info->op_map, (vtype)opi->op, (vtype)v);
}
// new mo
- mo = mp_alloc(gwion->mp, M_Operator);
+ mo = mp_calloc(gwion->mp, M_Operator);
mo->lhs = opi->lhs;
mo->rhs = opi->rhs;
mo->ret = opi->ret;
vector_add(&pi->vec[GWPLUG_IMPORT], (vtype)imp);
const modini ini = DLSYM(dl, modini, GWMODINI_NAME);
if(ini) {
- struct Plug_ *plug = mp_alloc(p, Plug);
+ struct Plug_ *plug = mp_calloc(p, Plug);
plug->ini = ini;
const modstr str = DLSYM(dl, modstr, GWMODSTR_NAME);
plug->name = str();
}
ANN PlugInfo* new_plug(MemPool p, const Vector list) {
- PlugInfo *pi = (PlugInfo*)mp_alloc(p, PlugInfo);
+ PlugInfo *pi = (PlugInfo*)mp_calloc(p, PlugInfo);
for(m_uint i = 0; i < GWPLUG_LAST; ++i)
vector_init(&pi->vec[i]);
map_init(&pi->drv);
#include <soundinfo.h>
struct SoundInfo_ *new_soundinfo(MemPool p) {
- struct SoundInfo_ *si = mp_alloc(p, SoundInfo);
+ struct SoundInfo_ *si = mp_calloc(p, SoundInfo);
si->in = si->out = 2;
si->sr = 48000;
return si;
}
struct SoundInfo_ *soundinfo_cpy(MemPool p, const struct SoundInfo_ *src) {
- struct SoundInfo_ *si = mp_alloc(p, SoundInfo);
+ struct SoundInfo_ *si = mp_calloc(p, SoundInfo);
si->in = src->in;
si->out = src->out;
si->sr = src->sr;
#include "driver.h"
ANN Driver* new_driver(MemPool p) {
- Driver* di = (Driver*)mp_alloc(p, BBQ);
+ Driver* di = (Driver*)mp_calloc(p, BBQ);
di->func = dummy_driver;
- di->driver = (DriverData*)mp_alloc(p, DriverData);
+ di->driver = (DriverData*)mp_calloc(p, DriverData);
di->is_running = 1;
return di;
}
}
ANN void shreduler_add(const Shreduler s, const VM_Shred shred) {
- shred->tick = mp_alloc(shred->info->mp, ShredTick);
+ shred->tick = mp_calloc(shred->info->mp, ShredTick);
shred->tick->self = shred;
shred->tick->shreduler = s;
shred->tick->xid = ++s->shred_ids;
}
VM* new_vm(MemPool p, const m_bool audio) {
- VM* vm = (VM*)mp_alloc(p, VM);
+ VM* vm = (VM*)mp_calloc(p, VM);
vector_init(&vm->ugen);
vm->bbq = new_driver(p);
vm->bbq->run = audio ? vm_run_audio : vm_run;
- vm->shreduler = (Shreduler)mp_alloc(p, Shreduler);
+ vm->shreduler = (Shreduler)mp_calloc(p, Shreduler);
vector_init(&vm->shreduler->shreds);
MUTEX_SETUP(vm->shreduler->mutex);
vm->shreduler->bbq = vm->bbq;
VM_Code new_vm_code(MemPool p, const Vector instr, const m_uint stack_depth,
const ae_flag flag, const m_str name) {
- VM_Code code = mp_alloc(p, VM_Code);
+ VM_Code code = mp_calloc(p, VM_Code);
code->instr = instr ? vector_copy(p, instr) : NULL;
code->name = strdup(name);
code->stack_depth = stack_depth;
};
static inline struct ShredInfo_ *new_shredinfo(MemPool p, const m_str name) {
- struct ShredInfo_ *info = mp_alloc(p, ShredInfo);
+ struct ShredInfo_ *info = mp_calloc(p, ShredInfo);
info->mp = p;
info->name = strdup(name);
return info;
}
VM_Shred new_vm_shred(MemPool p, VM_Code c) {
- const VM_Shred shred = mp_alloc(p, Stack);
+ const VM_Shred shred = mp_calloc(p, Stack);
shred->code = c;
shred->reg = (m_bit*)shred + sizeof(struct VM_Shred_);
shred->base = shred->mem = shred->reg + SIZEOF_REG;
}
m_uint offset = shred->mem - ((m_bit*)shred + sizeof(struct VM_Shred_) + SIZEOF_REG);
PUSH_MEM(shred, offset);
- Instr instr = mp_alloc(shred->info->mp, Instr);
+ Instr instr = mp_calloc(shred->info->mp, Instr);
struct ret_info* info = (struct ret_info*)xmalloc(sizeof(struct ret_info));
info->offset = offset;
info->code = shred->code;
-Subproject commit bbaef376bdbc13bba73d5f24e58701bcaf885f72
+Subproject commit 059393b7d69ed555bfef29ba99500d508a378637