From: fennecdjay Date: Wed, 24 Apr 2019 12:42:01 +0000 (+0200) Subject: :art: Locations and bugfixes X-Git-Tag: nightly~2529 X-Git-Url: http://10.11.0.4:5575/?a=commitdiff_plain;h=83763ef3e6fb5d68d6b2c6eb1ac2af0570ada62d;p=gwion.git :art: Locations and bugfixes --- diff --git a/ast b/ast index 83effb10..564a6a87 160000 --- a/ast +++ b/ast @@ -1 +1 @@ -Subproject commit 83effb10458c2461f366b689c315013bbe491f76 +Subproject commit 564a6a8786d2db8fe1bdfa1f2a0ea94685cc04a5 diff --git a/help/struct_check.sh b/help/struct_check.sh new file mode 100755 index 00000000..6e906358 --- /dev/null +++ b/help/struct_check.sh @@ -0,0 +1,7 @@ +#!/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 diff --git a/include/arg.h b/include/arg.h index 034d85a2..336cfdc6 100644 --- a/include/arg.h +++ b/include/arg.h @@ -2,13 +2,13 @@ #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; diff --git a/include/driver.h b/include/driver.h index e3264f4b..af2a71b6 100644 --- a/include/driver.h +++ b/include/driver.h @@ -19,11 +19,11 @@ typedef struct BBQ_ { 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) diff --git a/include/env.h b/include/env.h index 50756c3b..4dc3f5a7 100644 --- a/include/env.h +++ b/include/env.h @@ -21,7 +21,7 @@ struct Env_Scope_ { struct Vector_ breaks; struct Vector_ conts; struct Vector_ known_ctx; - struct Scope_ swi; + Scope swi; size_t depth; size_t type_xid; }; diff --git a/include/func.h b/include/func.h index eba58935..31096f79 100644 --- a/include/func.h +++ b/include/func.h @@ -8,8 +8,8 @@ struct Func_ { 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); diff --git a/include/nspc.h b/include/nspc.h index 1c318c78..7dbdee10 100644 --- a/include/nspc.h +++ b/include/nspc.h @@ -4,9 +4,9 @@ struct NspcInfo_ { 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; }; @@ -27,12 +27,12 @@ extern ANN void nspc_commit(const Nspc); #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; \ @@ -44,10 +44,10 @@ describe_lookup1(A, b) \ #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) diff --git a/include/oo.h b/include/oo.h index 449d8d01..f570a769 100644 --- a/include/oo.h +++ b/include/oo.h @@ -7,8 +7,8 @@ typedef struct 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; diff --git a/include/soundinfo.h b/include/soundinfo.h index b0b3d4d0..5fa57b5a 100644 --- a/include/soundinfo.h +++ b/include/soundinfo.h @@ -1,9 +1,9 @@ #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); diff --git a/include/value.h b/include/value.h index fdf93f27..8f76ed91 100644 --- a/include/value.h +++ b/include/value.h @@ -10,8 +10,8 @@ struct Value_ { 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); diff --git a/include/vm.h b/include/vm.h index 5b6522c2..1bc4fd1e 100644 --- a/include/vm.h +++ b/include/vm.h @@ -8,10 +8,10 @@ struct VM_Code_ { 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; diff --git a/src/lib/object.c b/src/lib/object.c index ff421025..d0cb0d38 100644 --- a/src/lib/object.c +++ b/src/lib/object.c @@ -74,7 +74,7 @@ ANN void __release(const M_Object obj, const VM_Shred shred) { 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) && diff --git a/src/lib/ugen.c b/src/lib/ugen.c index e439d729..f5c687ec 100644 --- a/src/lib/ugen.c +++ b/src/lib/ugen.c @@ -295,9 +295,9 @@ static MFUN(ugen_get_last) { 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) { @@ -313,11 +313,11 @@ 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); diff --git a/src/oo/env.c b/src/oo/env.c index a535ad36..fe08de1a 100644 --- a/src/oo/env.c +++ b/src/oo/env.c @@ -16,15 +16,16 @@ #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; } @@ -32,7 +33,7 @@ Env new_env(MemPool p) { 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; } @@ -60,7 +61,8 @@ ANN static void free_env_scope(struct Env_Scope_ *a, Gwion gwion) { 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); } diff --git a/src/oo/nspc.c b/src/oo/nspc.c index c20ffce7..024d3a60 100644 --- a/src/oo/nspc.c +++ b/src/oo/nspc.c @@ -13,9 +13,9 @@ #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) { @@ -28,7 +28,7 @@ ANN static inline void nspc_release_object(const Nspc a, Value value, Gwion gwio } 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 || @@ -38,16 +38,16 @@ ANN static void free_nspc_value(const Nspc a, Gwion gwion) { } 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) @@ -76,9 +76,9 @@ ANN Nspc new_nspc(MemPool p, const m_str name) { 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; } diff --git a/src/oo/switch.c b/src/oo/switch.c index 169b0316..f2aa16d8 100644 --- a/src/oo/switch.c +++ b/src/oo/switch.c @@ -47,7 +47,7 @@ ANN static Switch new_swinfo(const Env env, const Stmt_Switch stmt) { 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; } @@ -57,10 +57,10 @@ ANN static inline m_bool swinfo_cmp(const struct SwInfo_ *i1, const struct SwInf } 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; } @@ -68,13 +68,13 @@ ANN Switch swinfo_get(const Env env, const struct SwInfo_ *info) { 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; @@ -83,45 +83,42 @@ ANN m_bool switch_decl(const Env env, const loc_t pos) { 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; @@ -129,22 +126,22 @@ ANN m_bool switch_dup(const Env env, const m_int value, const loc_t pos) { } 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; @@ -152,32 +149,32 @@ ANN m_bool switch_default(const Env env, const m_uint pc, const loc_t pos) { } 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; } diff --git a/src/parse/did_you_mean.c b/src/parse/did_you_mean.c index e936ec4b..ad0e1a61 100644 --- a/src/parse/did_you_mean.c +++ b/src/parse/did_you_mean.c @@ -39,7 +39,7 @@ static m_bool wagner_fisher(const char *s, const char* t) { } 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)) diff --git a/util b/util index d225ae77..c77c8dae 160000 --- a/util +++ b/util @@ -1 +1 @@ -Subproject commit d225ae77804624fbfd1d904a1dd028e392139f62 +Subproject commit c77c8dae7d6f932a580bf3dcab5e8e9a39b9f48a