-Subproject commit 83effb10458c2461f366b689c315013bbe491f76
+Subproject commit 564a6a8786d2db8fe1bdfa1f2a0ea94685cc04a5
--- /dev/null
+#!/bin/sh
+: "${PRG:=./gwion}"
+
+pahole -s ${PRG} | while read name size gap
+do [ $size -gt 64 ] && echo $name $size
+ [ $gap -gt 0 ] && echo "$name has a gap"
+done
#define __ARG
typedef struct Arg_ {
- int argc;
char** argv;
struct Vector_ add;
struct Vector_ lib;
struct Vector_ mod;
struct Vector_ config;
struct SoundInfo_ *si;
+ int argc;
m_bool loop;
m_bool memoize;
} Arg;
uint64_t pos;
m_float* in;
m_float* out;
- volatile uint is_running;
struct SoundInfo_ *si;
f_bbqset func;
f_bbqrun run;
struct DriverData_* driver;
+ volatile uint is_running;
} Driver;
#define DRVINI(a) ANN m_bool a(struct VM_ *vm NUSED, Driver* di NUSED)
struct Vector_ breaks;
struct Vector_ conts;
struct Vector_ known_ctx;
- struct Scope_ swi;
+ Scope swi;
size_t depth;
size_t type_xid;
};
Func next;
struct Instr_* variadic;
size_t vt_index;
- ae_flag flag;
HAS_OBJ
+ ae_flag flag;
};
ANEW ANN Func new_func(MemPool, const m_str, const Func_Def);
m_bit* class_data;
struct Vector_ vtable;
struct Map_ op_map;
- struct Scope_ value;
- struct Scope_ type;
- struct Scope_ func;
+ Scope value;
+ Scope type;
+ Scope func;
size_t offset;
size_t class_data_size;
};
#define describe_lookup0(A, b) \
static inline ANN A nspc_lookup_##b##0(const Nspc n, const Symbol s){ \
- return (A)scope_lookup0(&n->info->b, (vtype)s); \
+ return (A)scope_lookup0(n->info->b, (vtype)s); \
}
#define describe_lookup1(A, b) \
static inline ANN A nspc_lookup_##b##1(const Nspc n, const Symbol s) { \
- const A a = (A)scope_lookup1(&n->info->b, (vtype)s); \
+ const A a = (A)scope_lookup1(n->info->b, (vtype)s); \
if(!a && n->parent) \
return nspc_lookup_##b##1(n->parent, s); \
return a; \
#define describe_nspc_func(A, b) \
static inline ANN void nspc_add_##b(const Nspc n, const Symbol s, const A a) { \
- scope_add(&n->info->b, (vtype)s, (vtype)a); \
+ scope_add(n->info->b, (vtype)s, (vtype)a); \
} \
-ANN static inline void nspc_push_##b(MemPool p, const Nspc n) { scope_push(p, &n->info->b); }\
-ANN static inline void nspc_pop_##b (MemPool p, const Nspc n) { scope_pop (p, &n->info->b); }\
+ANN static inline void nspc_push_##b(MemPool p, const Nspc n) { scope_push(p, n->info->b); }\
+ANN static inline void nspc_pop_##b (MemPool p, const Nspc n) { scope_pop (p, n->info->b); }\
describe_lookups(A, b)
describe_nspc_func(Value, value)
typedef struct Func_ * Func;
struct VM_Object_ {
- uint16_t ref_count; // could be an unsigned short
void (*free)(void*,void*);
+ uint16_t ref_count; // could be an unsigned short
};
#define HAS_OBJ struct VM_Object_ obj;
#ifndef __SOUNDINFO
#define __SOUNDINFO
struct SoundInfo_ {
+ m_str arg;
uint32_t sr;
uint8_t in, out;
- m_str arg;
};
struct SoundInfo_ *new_soundinfo(MemPool p);
struct SoundInfo_ *soundinfo_cpy(MemPool p, const struct SoundInfo_ *src);
Func func_ref;
} d;
size_t offset;
- ae_flag flag;
HAS_OBJ
+ ae_flag flag;
};
ANEW ANN Value new_value(MemPool p, const Type type, const m_str name);
m_uint native_func;
};
size_t stack_depth;
- ae_flag flag;
void* memoize;
m_str name;
HAS_OBJ
+ ae_flag flag;
};
typedef struct Shreduler_* Shreduler;
MemPool p = shred->info->mp;// = shred->info->vm->gwion->p;
Type t = obj->type_ref;
while(t->parent) {
- struct scope_iter iter = { &t->nspc->info->value, 0, 0 };\
+ struct scope_iter iter = { t->nspc->info->value, 0, 0 };\
Value v;
while(scope_iter(&iter, &v) > 0) {
if(!GET_FLAG(v, static) && !GET_FLAG(v, pure) &&
struct ugen_importer {
const VM* vm;
const f_tick tick;
+ UGen ugen;
const m_str name;
const uint nchan;
- UGen ugen;
};
ANN static m_int add_ugen(const Gwi gwi, struct ugen_importer* imp) {
static GWION_IMPORT(global_ugens) {
const VM* vm = gwi_vm(gwi);
- struct ugen_importer hole = { vm, compute_mono, "blackhole", 1, NULL };
+ struct ugen_importer hole = { vm, compute_mono, NULL, "blackhole", 1 };
add_ugen(gwi, &hole);
- struct ugen_importer dac = { vm, dac_tick, "dac", vm->bbq->si->out, NULL };
+ struct ugen_importer dac = { vm, dac_tick, NULL, "dac", vm->bbq->si->out };
add_ugen(gwi, &dac);
- struct ugen_importer adc = { vm, adc_tick, "adc", vm->bbq->si->in, NULL };
+ struct ugen_importer adc = { vm, adc_tick, NULL, "adc", vm->bbq->si->in };
add_ugen(gwi, &adc);
ugen_connect(dac.ugen, hole.ugen);
SET_FLAG(t_ugen, abstract);
#include "vm.h"
#include "parse.h"
-ANN static struct Env_Scope_ *new_scope(MemPool p) {
+ANN static struct Env_Scope_ *new_envscope(MemPool p) {
struct Env_Scope_ *a = mp_alloc(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);
- _scope_init(&a->swi);
- map_init(&a->swi.map);
+ a->swi = mp_alloc(p, Scope);
+ _scope_init(a->swi);
+ map_init(&a->swi->map);
return a;
}
const Env env = (Env)xmalloc(sizeof(struct Env_));
env->global_nspc = new_nspc(p, "global_nspc");
env->context = NULL;
- env->scope = new_scope(p);
+ env->scope = new_envscope(p);
env_reset(env);
return env;
}
vector_release(&a->class_stack);
vector_release(&a->breaks);
vector_release(&a->conts);
- switch_release(&a->swi);
+ switch_release(a->swi);
+ mp_free(gwion->p, Scope, a->swi);
mp_free(gwion->p, Env_Scope, a);
}
#include "operator.h"
ANN void nspc_commit(const Nspc nspc) {
- scope_commit(&nspc->info->value);
- scope_commit(&nspc->info->func);
- scope_commit(&nspc->info->type);
+ scope_commit(nspc->info->value);
+ scope_commit(nspc->info->func);
+ scope_commit(nspc->info->type);
}
ANN static inline void nspc_release_object(const Nspc a, Value value, Gwion gwion) {
}
ANN static void free_nspc_value(const Nspc a, Gwion gwion) {
- struct scope_iter iter = { &a->info->value, 0, 0 };
+ struct scope_iter iter = { a->info->value, 0, 0 };
Value v;
while(scope_iter(&iter, &v) > 0) {
if(v->type && (isa(v->type, t_object) > 0 ||
}
REM_REF(v, gwion);
}
- scope_release(gwion->p, &a->info->value);
+ free_scope(gwion->p, a->info->value);
}
#define describe_nspc_free(A, b) \
ANN static void nspc_free_##b(Nspc n, Gwion gwion) {\
- struct scope_iter iter = { &n->info->b, 0, 0 };\
+ struct scope_iter iter = { n->info->b, 0, 0 };\
A a;\
while(scope_iter(&iter, &a) > 0) \
REM_REF(a, gwion);\
- scope_release(gwion->p, &n->info->b);\
+ free_scope(gwion->p, n->info->b);\
}
describe_nspc_free(Func, func)
const Nspc a = mp_alloc(p, Nspc);
a->name = name;
a->info = mp_alloc(p, NspcInfo);
- scope_init(p, &a->info->value);
- scope_init(p, &a->info->type);
- scope_init(p, &a->info->func);
+ a->info->value = new_scope(p);
+ a->info->type = new_scope(p);
+ a->info->func = new_scope(p);
INIT_OO(a, free_nspc);
return a;
}
info->t = env->class_def;
info->f = env->func;
const Switch sw = new_switch(env->gwion->p);
- map_set(&env->scope->swi.map, (vtype)info, (vtype)sw);
+ map_set(&env->scope->swi->map, (vtype)info, (vtype)sw);
sw->depth = env->scope->depth + 2;
return sw;
}
}
ANN Switch swinfo_get(const Env env, const struct SwInfo_ *info) {
- for(m_uint i = 0; i < VLEN(&env->scope->swi.map); ++i) {
- const struct SwInfo_ *key = (const struct SwInfo_*)VKEY(&env->scope->swi.map, i);
+ for(m_uint i = 0; i < VLEN(&env->scope->swi->map); ++i) {
+ const struct SwInfo_ *key = (const struct SwInfo_*)VKEY(&env->scope->swi->map, i);
if(swinfo_cmp(key, info))
- return (Switch)VVAL(&env->scope->swi.map, i);
+ return (Switch)VVAL(&env->scope->swi->map, i);
}
return NULL;
}
ANN m_bool switch_add(const Env env, const Stmt_Switch stmt) {
const struct SwInfo_ info = { stmt, env->class_def, env->func };
Switch sw = (Switch)swinfo_get(env, &info) ?: new_swinfo(env, stmt);
- _scope_add(&env->scope->swi, sw);
+ _scope_add(env->scope->swi, sw);
return GW_OK;
}
ANN m_bool switch_decl(const Env env, const loc_t pos) {
- const Switch sw = (Switch)(VLEN(&env->scope->swi.map) ?
- VVAL(&env->scope->swi.map, VLEN(&env->scope->swi.map) - 1): 0);
+ const Switch sw = (Switch)(VLEN(&env->scope->swi->map) ?
+ VVAL(&env->scope->swi->map, VLEN(&env->scope->swi->map) - 1): 0);
if(sw && sw->depth == env->scope->depth)
ERR_B(pos, "Declaration in switch is prohibited.")
return GW_OK;
ANN void switch_get(const Env env, const Stmt_Switch stmt) {
const struct SwInfo_ info = { stmt, env->class_def, env->func };
const Switch sw = swinfo_get(env, &info);
- _scope_add(&env->scope->swi, sw);
+ _scope_add(env->scope->swi, sw);
}
void switch_reset(const Env env) {
- for(m_uint i = VLEN(&env->scope->swi.map) + 1; --i;) {
- struct SwInfo_ *info = (struct SwInfo_ *)VKEY(&env->scope->swi.map, i - 1);
+ for(m_uint i = VLEN(&env->scope->swi->map) + 1; --i;) {
+ struct SwInfo_ *info = (struct SwInfo_ *)VKEY(&env->scope->swi->map, i - 1);
mp_free(env->gwion->p, SwInfo, info);
- Switch sw = (Switch)VVAL(&env->scope->swi.map, i - 1);
-//if(sw->cases)
-// free_map(env->gwion->p, sw->cases);
+ Switch sw = (Switch)VVAL(&env->scope->swi->map, i - 1);
free_switch(env->gwion->p, sw);
}
- _scope_clear(&env->scope->swi);
- map_clear(&env->scope->swi.map);
+ _scope_clear(env->scope->swi);
+ map_clear(&env->scope->swi->map);
}
ANN void switch_release(const Scope sw) {
vector_release((Vector)sw);
map_release(&sw->map);
-// scope_release(sw);
}
ANN void switch_expset(const Env env, const Exp e) {
- const Switch sw = (Switch)_scope_back(&env->scope->swi);
+ const Switch sw = (Switch)_scope_back(env->scope->swi);
vector_add(&sw->exp, (vtype)e);
}
ANN Exp switch_expget(const Env env) {
- const Switch sw = (Switch)_scope_back(&env->scope->swi);
+ const Switch sw = (Switch)_scope_back(env->scope->swi);
return (Exp)vector_at(&sw->exp, sw->iter++);
}
ANN m_bool switch_inside(const Env env, const loc_t pos) {
- if(!VLEN(&env->scope->swi))
+ if(!VLEN(env->scope->swi))
ERR_B(pos, "case found outside switch statement.")
return GW_OK;
}
ANN m_bool switch_dup(const Env env, const m_int value, const loc_t pos) {
- const Switch sw = (Switch)_scope_back(&env->scope->swi);
+ const Switch sw = (Switch)_scope_back(env->scope->swi);
if(map_get(sw->cases, (vtype)value))
ERR_B(pos, "duplicated cases value %i", value)
sw->ok = 1;
}
ANN void switch_pc(const Env env, const m_uint pc) {
- const Switch sw = (Switch)_scope_back(&env->scope->swi);
+ const Switch sw = (Switch)_scope_back(env->scope->swi);
vector_add(sw->vec, pc);
}
ANN void switch_dynpc(const Env env, const m_int val, const m_uint pc) {
- const Switch sw = (Switch)_scope_back(&env->scope->swi);
+ const Switch sw = (Switch)_scope_back(env->scope->swi);
map_set(sw->cases, val, pc);
}
ANN m_bool switch_dyn(const Env env) {
- const Switch sw = (Switch)_scope_back(&env->scope->swi);
+ const Switch sw = (Switch)_scope_back(env->scope->swi);
return vector_size(&sw->exp);
}
ANN m_bool switch_default(const Env env, const m_uint pc, const loc_t pos) {
- const Switch sw = (Switch)_scope_back(&env->scope->swi);
+ const Switch sw = (Switch)_scope_back(env->scope->swi);
if(sw->default_case_index)
ERR_B(pos, "default case already defined")
sw->default_case_index = pc;
}
ANN Map switch_map(const Env env) {
- const Switch sw = (Switch)_scope_back(&env->scope->swi);
+ const Switch sw = (Switch)_scope_back(env->scope->swi);
return sw->cases;
}
ANN Vector switch_vec(const Env env) {
- const Switch sw = (Switch)_scope_back(&env->scope->swi);
+ const Switch sw = (Switch)_scope_back(env->scope->swi);
return vector_copy(env->gwion->p, sw->vec); // new_vector(); // dyn only
}
ANN m_uint switch_idx(const Env env) {
- const Switch sw = (Switch)_scope_back(&env->scope->swi);
+ const Switch sw = (Switch)_scope_back(env->scope->swi);
return sw->default_case_index;
}
ANN m_bool switch_pop(const Env env) {
- _scope_pop(&env->scope->swi);
+ _scope_pop(env->scope->swi);
return GW_OK;
}
ANN m_bool switch_end(const Env env, const loc_t pos) {
- const Switch sw = (Switch)_scope_pop(&env->scope->swi);
- const vtype index = VKEY(&env->scope->swi.map, VLEN(&env->scope->swi.map) - 1);
+ const Switch sw = (Switch)_scope_pop(env->scope->swi);
+ const vtype index = VKEY(&env->scope->swi->map, VLEN(&env->scope->swi->map) - 1);
sw->ok = 1;
if(!VLEN(sw->cases) && !VLEN(&sw->exp))
ERR_B(pos, "switch statement with no cases.")
- map_remove(&env->scope->swi.map, index);
+ map_remove(&env->scope->swi->map, index);
free_switch(env->gwion->p, sw);
return GW_OK;
}
}
ANN static void ressembles(const Vector v, const Nspc nspc, const char* name) {
- struct scope_iter iter = { &nspc->info->value, 0, 0 };
+ struct scope_iter iter = { nspc->info->value, 0, 0 };
Value value;
while(scope_iter(&iter, &value) > 0) {
if(!strcmp(name, value->name))
-Subproject commit d225ae77804624fbfd1d904a1dd028e392139f62
+Subproject commit c77c8dae7d6f932a580bf3dcab5e8e9a39b9f48a