From 9dc55fa489fd0ceb030a9d0a0119ec55fda03a8f Mon Sep 17 00:00:00 2001 From: fennecdjay Date: Wed, 6 Mar 2019 10:37:11 +0100 Subject: [PATCH] :shirt: More clean --- Makefile | 3 -- include/arg.h | 5 ++- include/array.h | 14 ++++---- include/driver.h | 21 ++++++++---- include/func.h | 5 ++- include/plug.h | 2 +- src/arg.c | 81 +++++++++++++++++----------------------------- src/emit/emit.c | 44 +++++++++++-------------- src/gwion.c | 2 +- src/lib/vec.c | 2 +- src/main.c | 8 ++--- src/parse/check.c | 21 ++++-------- src/parse/scan1.c | 9 +++--- src/parse/scan2.c | 4 +-- src/plug.c | 7 ++-- tests/sh/opt.sh | 73 ++--------------------------------------- tests/sh/plugin.sh | 4 +-- 17 files changed, 98 insertions(+), 207 deletions(-) diff --git a/Makefile b/Makefile index 07923bdc..8cdf2314 100644 --- a/Makefile +++ b/Makefile @@ -45,9 +45,6 @@ CFLAGS += -DVMBENCH LDFLAGS += -lbsd endif -# add definitions -CFLAGS+= -DD_FUNC=${D_FUNC} - # add directories CFLAGS+=-DGWPLUG_DIR=\"${GWPLUG_DIR}\" diff --git a/include/arg.h b/include/arg.h index 46f488c3..fb74eb5a 100644 --- a/include/arg.h +++ b/include/arg.h @@ -4,12 +4,11 @@ typedef struct { int argc; char** argv; struct Vector_ add; - struct Vector_ rem; struct Vector_ lib; struct Vector_ mod; m_bool loop; } Arg; -ANN void arg_release(Arg* arg); -ANN uint parse_args(Arg*, DriverInfo*); +ANN void arg_release(Arg*); +ANN void arg_parse(Arg*, DriverInfo*); #endif diff --git a/include/array.h b/include/array.h index b19786eb..1cc83b11 100644 --- a/include/array.h +++ b/include/array.h @@ -14,12 +14,12 @@ typedef struct ArrayInfo_ { unsigned is_obj : 1; } ArrayInfo; -ANN m_uint m_vector_size(const M_Vector v); -ANN void m_vector_set(const M_Vector v, const m_uint i, const void* data); -ANN void m_vector_get(const M_Vector v, const m_uint i, void* data); -ANN void m_vector_add(const M_Vector v, const void* data); -ANN m_bit* m_vector_addr(const M_Vector v, const m_uint i); -ANN void m_vector_rem(const M_Vector v, const m_uint index); +ANN m_uint m_vector_size(const M_Vector); +ANN void m_vector_set(const M_Vector, const m_uint, const void*); +ANN void m_vector_get(const M_Vector, const m_uint, void*); +ANN void m_vector_add(const M_Vector, const void*); +ANN m_bit* m_vector_addr(const M_Vector, const m_uint); +ANN void m_vector_rem(const M_Vector, const m_uint); ANEW M_Vector new_m_vector(const m_uint); -void free_m_vector(M_Vector); +ANN void free_m_vector(M_Vector); #endif diff --git a/include/driver.h b/include/driver.h index e5e6509b..1d8724db 100644 --- a/include/driver.h +++ b/include/driver.h @@ -1,20 +1,27 @@ #ifndef __DRIVER #define __DRIVER +struct Driver_; + +typedef void (*f_drvset)(struct Driver_*); +typedef void (*f_run)(const VM*); -struct _driver; typedef struct DriverInfo_ { uint32_t sr; m_str arg; - void (*func)(struct _driver*); - void (*run)(const VM*); + f_drvset func; + f_run run; void* data; uint8_t in, out; } DriverInfo; -typedef struct _driver { - m_bool (*ini)(VM* vm, DriverInfo*); - void (*run)(VM* vm, struct DriverInfo_*); - void (*del)(VM* vm, struct DriverInfo_*); +typedef m_bool (*f_drvini)(VM*, DriverInfo*); +typedef void (*f_drvrun)(VM* vm, struct DriverInfo_*); +typedef void (*f_drvdel)(VM* vm, struct DriverInfo_*); + +typedef struct Driver_ { + f_drvini ini; + f_drvrun run; + f_drvdel del; } Driver; void dummy_driver(Driver*); diff --git a/include/func.h b/include/func.h index 42468ea3..ef7992a3 100644 --- a/include/func.h +++ b/include/func.h @@ -12,8 +12,7 @@ struct Func_ { HAS_OBJ }; -ANEW ANN Func new_func(const m_str name, const Func_Def def); +ANEW ANN Func new_func(const m_str, const Func_Def); ANN2(1,2) Symbol func_symbol(const m_str, const m_str, const m_str, const m_uint); - -ANN2(1,3,4) m_bool check_lambda(const Env, const Type, Exp_Lambda *lambda, const Func_Def); +ANN2(1,3,4) m_bool check_lambda(const Env, const Type, Exp_Lambda*, const Func_Def); #endif diff --git a/include/plug.h b/include/plug.h index 4d11d435..96653fd5 100644 --- a/include/plug.h +++ b/include/plug.h @@ -23,7 +23,7 @@ void plug_end(const Gwion gwion); #define GWMODSTR(a) m_str GWMODSTR_NAME() { return #a; } #define GWMODINI(a) ANN void* GWMODINI_NAME(const Gwion gwion, const Vector args) #define GWMODEND(a) ANN void GWMODEND_NAME(const Gwion gwion, void* self) -#define GWDRIVER(a) ANN void GWDRIVER_NAME(struct _driver* d) +#define GWDRIVER(a) ANN void GWDRIVER_NAME(Driver* d) ANN void plug_ini(const Gwion gwion, const Vector); ANN Vector split_args(const m_str str); diff --git a/src/arg.c b/src/arg.c index fb255a2b..009476cb 100644 --- a/src/arg.c +++ b/src/arg.c @@ -1,5 +1,4 @@ #include -#include #include "gwion_util.h" #include "oo.h" #include "vm.h" @@ -8,7 +7,6 @@ ANN static void arg_init(Arg* arg) { vector_init(&arg->add); - vector_init(&arg->rem); vector_init(&arg->lib); vector_init(&arg->mod); vector_add(&arg->lib, (vtype)GWPLUG_DIR); @@ -16,21 +14,19 @@ ANN static void arg_init(Arg* arg) { ANN void arg_release(Arg* arg) { vector_release(&arg->add); - vector_release(&arg->rem); vector_release(&arg->lib); vector_release(&arg->mod); } static const struct option long_option[] = { - { "pludir", 0, NULL, 'P' }, + { "pludir", 0, NULL, 'p' }, { "driver", 1, NULL, 'd' }, { "sr", 1, NULL, 's' }, { "in", 1, NULL, 'i' }, { "out", 1, NULL, 'o' }, { "loop", 1, NULL, 'l' }, - { "help", 0, NULL, '?' }, - { "version", 0, NULL, 'v' }, - { "config", 0, NULL, 'C' }, + { "help", 0, NULL, 'h' }, + { "config", 0, NULL, 'c' }, { "module", 0, NULL, 'm' }, { NULL, 0, NULL, 0 } }; @@ -39,67 +35,51 @@ static const char usage[] = "usage: Gwion \n" "\toption can be any of:\n" "GLOBAL options: : description\n" -"\t--help, -?\t : this help\n" -"\t--version -v\t : this help\n" -"VM options:\n" +"\t--help, -h\t : this help\n" "\t--plugdir, -P\t : add a plugin directory\n" -"DRIVER options:\n" -"\t--driver -d\t : set the driver (one of: alsa jack soundio portaudio file dummy silent raw)\n" +"\t--driver -d\t : set the driver\n" +"\t--module -m\t : module setting\n" "\t--sr -s\t : set samplerate\n" ; -ANN static void arg_add(Arg* arg) { - Vector ref = &arg->add; - while(optind < arg->argc) { - m_str str = arg->argv[optind++]; - if(!strcmp(str, "-")) { - ref = &arg->rem; - str = arg->argv[optind++]; - } else if(!strcmp(str, "+")) { - ref = &arg->add; - str = arg->argv[optind++]; - } - vector_add(ref, (vtype)str); - } +ANN static inline void arg_add(Arg* arg) { + while(optind < arg->argc) + vector_add(&arg->add, (vtype)arg->argv[optind++]); } ANN static void arg_drvr(DriverInfo* di, const int i) { - switch(i) { - case 'i': - di->in = (m_uint)strtol(optarg, NULL, 10); - break; - case 'o': - di->out = (m_uint)strtol(optarg, NULL, 10); - break; - case 's': - di->sr = (uint)strtol(optarg, NULL, 10); - break; - case 'd': - di->arg = optarg; - break; - default: - gw_err("Unknown argument '%c'\n", i); + switch(i) { + case 'i': + di->in = (m_uint)strtol(optarg, NULL, 10); + break; + case 'o': + di->out = (m_uint)strtol(optarg, NULL, 10); + break; + case 's': + di->sr = (uint)strtol(optarg, NULL, 10); + break; + case 'd': + di->arg = optarg; + break; } } -ANN uint parse_args(Arg* arg, DriverInfo* di) { - uint quit = 0; - int i, index; +ANN void arg_parse(Arg* arg, DriverInfo* di) { + int i, idx; arg_init(arg); - while((i = getopt_long(arg->argc, arg->argv, "?vl:i:o:s:d:m:P:C ", - long_option, &index)) != -1) { + while((i = getopt_long(arg->argc, arg->argv, "hl:i:o:s:d:m:p:c", + long_option, &idx)) != -1) { switch(i) { - case '?': + case 'h': gw_err(usage); - exit(0); - case 'C': + break; + case 'c': gw_err("CFLAGS: %s\nLDFLAGS: %s\n", CFLAGS, LDFLAGS); - exit(1); break; case 'l': arg->loop = strtol(optarg, NULL, 10) > 0 ? 1 : -1; break; - case 'P': + case 'p': vector_add(&arg->lib, (vtype)optarg); break; case 'm': @@ -110,5 +90,4 @@ ANN uint parse_args(Arg* arg, DriverInfo* di) { } } arg_add(arg); - return quit; } diff --git a/src/emit/emit.c b/src/emit/emit.c index 00297a47..d52bb5ac 100644 --- a/src/emit/emit.c +++ b/src/emit/emit.c @@ -733,7 +733,7 @@ static m_bool emit_template_code(const Emitter emit, const Func f) { CHECK_BB(traverse_template(emit->env, f->value_ref->owner_class->def)) const Value v = f->value_ref; size_t scope = emit_push(emit, v->owner_class, v->owner); - CHECK_BB(emit_func_def(emit, f->def)) // orig + CHECK_BB(emit_func_def(emit, f->def)) emit_pop(emit, scope); return push_func_code(emit, f); } @@ -746,8 +746,7 @@ ANN static Instr emit_call(const Emitter emit, const Func f) { FuncMember : FuncStatic : FuncUsr; return emit_add_instr(emit, exec); } - /*const Instr ex = */emit_add_instr(emit, GWOP_EXCEPT); -// ex->m_val = -SZ_INT; + emit_add_instr(emit, GWOP_EXCEPT); return emit_add_instr(emit, FuncPtr); } @@ -1282,7 +1281,7 @@ ANN static m_bool emit_stmt_union(const Emitter emit, const Stmt_Union stmt) { G if(!stmt->value->type->p) stmt->value->type->p = mp_ini((uint32_t)stmt->value->type->size); Type_Decl *type_decl = new_type_decl(new_id_list(stmt->xid, stmt->self->pos), - emit->env->class_def ? ae_flag_member : 0); // or zero ? + emit->env->class_def ? ae_flag_member : 0); type_decl->flag = stmt->flag; const Var_Decl var_decl = new_var_decl(stmt->xid, NULL, 0); const Var_Decl_List var_decl_list = new_var_decl_list(var_decl, NULL); @@ -1356,7 +1355,7 @@ ANN static m_bool emit_stmt_list(const Emitter emit, Stmt_List l) { GWDEBUG_EXE } ANN static m_bool emit_dot_static_import_data(const Emitter emit, const Value v, const uint emit_addr) { GWDEBUG_EXE - if(v->d.ptr && GET_FLAG(v, builtin)) { // from C + if(v->d.ptr && GET_FLAG(v, builtin)) { if(GET_FLAG(v, enum)) { const Instr func_i = emit_add_instr(emit, RegPushImm); func_i->m_val = (m_uint)v->d.ptr; @@ -1378,7 +1377,7 @@ ANN static m_bool emit_complex_member(const Emitter emit, const Exp_Dot* member) CHECK_BB(emit_exp(emit, base, 0)) const m_bool is_complex = !strcmp((isa(base->type, t_complex) > 0 ? "re" : "phase") , s_name(member->xid)); - if(is_complex && member->self->emit_var) // skip + if(is_complex && member->self->emit_var) return GW_OK; const Instr instr = emit_add_instr(emit, is_complex ? ComplexReal : ComplexImag); instr->m_val = member->self->emit_var; @@ -1398,7 +1397,7 @@ ANN static m_bool emit_VecMember(const Emitter emit, const Exp_Dot* member) { emit_vec_func(emit, v); return GW_OK; } - if(!v->offset && member->self->emit_var) // skip + if(!v->offset && member->self->emit_var) return GW_OK; const Instr instr = emit_add_instr(emit, VecMember); instr->m_val2 = v->offset; @@ -1453,22 +1452,15 @@ ANN static m_bool emit_exp_dot_special(const Emitter emit, const Exp_Dot* member } ANN static m_bool emit_dot_static_func(const Emitter emit, const Func func) { GWDEBUG_EXE -// if(func->code) { -// const Instr func_i = emit_add_instr(emit, RegPushImm); -// func_i->m_val = (m_uint)func->code; -// } else { - // TODO: improve me - const Instr func_i = emit_add_instr(emit, PushStaticCode); - func_i->m_val = (m_uint)func; -// } + const Instr func_i = emit_add_instr(emit, PushStaticCode); + func_i->m_val = (m_uint)func; return GW_OK; } ANN static m_bool emit_member_func(const Emitter emit, const Exp_Dot* member, const Func func) { GWDEBUG_EXE if(emit_exp(emit, member->base, 0) < 0) ERR_B(member->self->pos, "... in member function") // LCOV_EXCL_LINE - /*const Instr ex = */emit_add_instr(emit, GWOP_EXCEPT); - //ex->m_val = -SZ_INT; + emit_add_instr(emit, GWOP_EXCEPT); if(GET_FLAG(member->base->type, force)) { const Instr func_i = emit_add_instr(emit, RegPushImm); func_i->m_val = (m_uint)func->code; @@ -1484,8 +1476,7 @@ ANN static m_bool emit_member_func(const Emitter emit, const Exp_Dot* member, co } ANN static inline void emit_member(const Emitter emit, const Value v, const uint emit_addr) { - /*const Instr ex = */emit_add_instr(emit, GWOP_EXCEPT); - //ex->m_val = -SZ_INT; + emit_add_instr(emit, GWOP_EXCEPT); const m_uint size = v->type->size; const Instr instr = emit_kind(emit, size, emit_addr, dotmember); instr->m_val = v->offset; @@ -1496,8 +1487,8 @@ ANN static m_bool emit_exp_dot_instance(const Emitter emit, const Exp_Dot* membe const Type t_base = member->t_base; const Value value = find_value(t_base, member->xid); const uint emit_addr = member->self->emit_var; - if(isa(member->self->type, t_fptr) > 0) { // function pointer - if(GET_FLAG(value, member)) { // member + if(isa(member->self->type, t_fptr) > 0) { + if(GET_FLAG(value, member)) { if(emit_exp(emit, member->base, 0) < 0) ERR_B(member->self->pos, "... in member function") // LCOV_EXCL_LINE emit_member(emit, value, emit_addr); @@ -1506,12 +1497,12 @@ ANN static m_bool emit_exp_dot_instance(const Emitter emit, const Exp_Dot* membe return emit_dot_static_data(emit, value, emit_addr); } else if(isa(member->self->type, t_function) > 0) return emit_member_func(emit, member, value->d.func_ref); - else { // variable - if(GET_FLAG(value, member)) { // member + else { + if(GET_FLAG(value, member)) { CHECK_BB(emit_exp(emit, member->base, 0)) emit_member(emit, value, emit_addr); return GW_OK; - } else // static + } else CHECK_BB(emit_dot_static_import_data(emit, value, emit_addr)) } return GW_OK; @@ -1601,8 +1592,9 @@ ANN static m_bool emit_func_def_body(const Emitter emit, const Func_Def func_def ANN static m_bool emit_func_def(const Emitter emit, const Func_Def func_def) { GWDEBUG_EXE const Func func = get_func(emit->env, func_def); - if(func->code)return GW_OK; - if(tmpl_list_base(func_def->tmpl)) { // don't check template definition + if(func->code) + return GW_OK; + if(tmpl_list_base(func_def->tmpl)) { UNSET_FLAG(func_def, template); return GW_OK; } diff --git a/src/gwion.c b/src/gwion.c index 014803db..e760a12f 100644 --- a/src/gwion.c +++ b/src/gwion.c @@ -43,7 +43,7 @@ ANN m_bool gwion_audio(const Gwion gwion, DriverInfo* di) { const m_str name = (m_str)VKEY(&gwion->plug->drv, i); const size_t len = strlen(name); if(!strncmp(name, di->arg, len)) { - di->func = (void (*)(struct _driver*))VVAL(&gwion->plug->drv, i); + di->func = (f_drvset)VVAL(&gwion->plug->drv, i); break; } } diff --git a/src/lib/vec.c b/src/lib/vec.c index 045c336f..b0757b23 100644 --- a/src/lib/vec.c +++ b/src/lib/vec.c @@ -236,7 +236,7 @@ static MFUN(vec4_magnitude) { static MFUN(vec4_normalize) { m_vec4* v = *(m_vec4**)MEM(0); - m_float mag = sqrt(v->x * v->x + v->y * v->y + v->z * v->z + v->w * v->w); + const m_float mag = sqrt(v->x * v->x + v->y * v->y + v->z * v->z + v->w * v->w); if(mag > 0) vec_Div((m_bit*)v, 4, mag); } diff --git a/src/main.c b/src/main.c index eb8d347b..ec57e85c 100644 --- a/src/main.c +++ b/src/main.c @@ -17,12 +17,8 @@ static void sig(int unused __attribute__((unused))) { int main(int argc, char** argv) { Arg arg = { .argc = argc, .argv=argv, .loop=-1 }; - DriverInfo di = { .in=2, .out=2, /* .chan=2, */ .sr=48000, /* .bufsize=256, - .bufnum=3, .card="default:CARD=CODEC",*/ .func=D_FUNC, .run=vm_run }; - if(parse_args(&arg, &di)) { - arg_release(&arg); - return 0; - } + DriverInfo di = { .in=2, .out=2, .sr=48000, .func=dummy_driver, .run=vm_run }; + arg_parse(&arg, &di); gwion_init(&gwion, &arg.lib); signal(SIGINT, sig); signal(SIGTERM, sig); diff --git a/src/parse/check.c b/src/parse/check.c index 8ea37542..359b2a21 100644 --- a/src/parse/check.c +++ b/src/parse/check.c @@ -71,8 +71,7 @@ ANN static m_bool check_fptr_decl(const Env env, const Var_Decl var) { ERR_B(var->pos, "can't use static variables for member function.") if(!GET_FLAG(v, member)) ERR_B(var->pos, "can't use member variables for static function.") - } //else if(GET_FLAG(v, member)) - //ERR_B(var->pos, "can't use member variables for static function.") + } return GW_OK; } @@ -172,7 +171,6 @@ ANN static Type prim_id_non_res(const Env env, const Exp_Primary* primary) { ((Exp_Primary*)primary)->value = v; if(GET_FLAG(v, const) || !strcmp(s_name(primary->d.var), "maybe")) primary->self->meta = ae_meta_value; -// OPTIMIZE_PRIM_CONST(primary, v->d.ptr) return v->type; } @@ -507,7 +505,7 @@ ANN static Func get_template_func(const Env env, const Exp_Call* func, const Exp tmpl->base = v->d.func_ref->def->tmpl->list; if(base->exp_type == ae_exp_call) base->d.exp_call.tmpl = tmpl; - else // if(base->exp_type == ae_exp_binary) + else /* if(base->exp_type == ae_exp_binary) */ base->d.exp_binary.tmpl = tmpl; return f; } @@ -552,7 +550,7 @@ ANN static Type check_exp_call_template(const Env env, const Exp_Call *exp) { const Func func = get_template_func(env, &tmp_func, base, value); if(base->exp_type == ae_exp_call) base->d.exp_call.m_func = func; - else // if(base->exp_type == ae_exp_binary) + else /* if(base->exp_type == ae_exp_binary) */ base->d.exp_binary.func = func; return func ? func->def->ret_type : NULL; } @@ -568,7 +566,7 @@ ANN static m_bool check_exp_call1_check(const Env env, const Exp exp) { ANN static inline void set_call(const Exp e, const Func f) { if(e->exp_type == ae_exp_call) e->d.exp_call.m_func = f; - else // if(e->exp_type == ae_exp_binary) + else /* if(e->exp_type == ae_exp_binary) */ e->d.exp_binary.func = f; } @@ -1003,8 +1001,7 @@ ANN static m_bool check_stmt_list(const Env env, Stmt_List l) { GWDEBUG_EXE } ANN static m_bool check_signature_match(const Func_Def f, const Func parent) { GWDEBUG_EXE -// if(GET_FLAG(parent->def, static) || GET_FLAG(f, static)) { - if(GET_FLAG(parent->def, static) != GET_FLAG(f, static)) { // wath me + if(GET_FLAG(parent->def, static) != GET_FLAG(f, static)) { const m_str c_name = f->func->value_ref->owner_class->name; const m_str p_name = parent->value_ref->owner_class->name; const m_str f_name = s_name(f->name); @@ -1014,9 +1011,7 @@ ANN static m_bool check_signature_match(const Func_Def f, const Func parent) { G c_name, f_name, p_name, c_name, GET_FLAG(f, static) ? c_name : p_name, f_name) } - if(!f->tmpl) // ??? - return isa(f->ret_type, parent->def->ret_type); - return GW_OK; + return !f->tmpl ? isa(f->ret_type, parent->def->ret_type) : GW_OK; } ANN static m_bool parent_match_actual(const Env env, const restrict Func_Def f, @@ -1046,12 +1041,10 @@ ANN static m_bool check_parent_match(const Env env, const Func_Def f) { GWDEBUG_ return match; } } -// if(GET_FLAG(func, member)) { if(!env->curr->vtable.ptr) vector_init(&env->curr->vtable); func->vt_index = vector_size(&env->curr->vtable); vector_add(&env->curr->vtable, (vtype)func); -// } return GW_OK; } @@ -1070,7 +1063,7 @@ ANN static m_bool check_func_args(const Env env, Arg_List arg_list) { GWDEBUG_EX ANN static inline Func get_overload(const Env env, const Func_Def def, const m_uint i) { const Symbol sym = func_symbol(env->curr->name, s_name(def->name), NULL, i); - return nspc_lookup_func1(env->curr, sym); // was lookup2 + return nspc_lookup_func1(env->curr, sym); } ANN static m_bool check_func_overload(const Env env, const Func_Def f) { diff --git a/src/parse/scan1.c b/src/parse/scan1.c index 7511fef1..3faddf51 100644 --- a/src/parse/scan1.c +++ b/src/parse/scan1.c @@ -33,6 +33,8 @@ ANN static Type scan1_exp_decl_type(const Env env, Exp_Decl* decl) { ERR_O(decl->self->pos, "can't use private type %s", t->name) if(GET_FLAG(t, protect) && (!env->class_def || isa(t, env->class_def) < 0)) ERR_O(decl->self->pos, "can't use protected type %s", t->name) + if(GET_FLAG(decl->td, global) && env->class_def) + ERR_O(decl->self->pos, "can't declare variable global inside class.") if(env->class_def) { if(!env->scope->depth) { if(!env->func && !GET_FLAG(decl->td, static)) @@ -40,10 +42,7 @@ ANN static Type scan1_exp_decl_type(const Env env, Exp_Decl* decl) { if(!GET_FLAG(decl->td, ref) && t == env->class_def) ERR_O(decl->self->pos, "...(note: object of type '%s' declared inside itself)", t->name) } - if(GET_FLAG(decl->td, global) && env->class_def) // forbid this ? - UNSET_FLAG(decl->td, global); } - // for template decl->base = t->def; decl->type = t; return t; @@ -202,7 +201,7 @@ ANN static m_bool scan1_args(const Env env, Arg_List list) { GWDEBUG_EXE const Var_Decl var = list->var_decl; if(var->xid) CHECK_BB(isres(var->xid)) - if(list->td) // lambda + if(list->td) CHECK_OB((list->type = void_type(env, list->td, var->pos))) } while((list = list->next)); return GW_OK; @@ -280,7 +279,7 @@ ANN m_bool scan1_func_def(const Env env, const Func_Def f) { GWDEBUG_EXE ++env->scope->depth; if(GET_FLAG(f, dtor) && !env->class_def) ERR_B(f->td->xid->pos, "dtor must be in class def!!") - if(f->td)//lambda + if(f->td) CHECK_OB((f->ret_type = known_type(env, f->td))) if(f->arg_list) CHECK_BB(scan1_args(env, f->arg_list)) diff --git a/src/parse/scan2.c b/src/parse/scan2.c index 4f644959..8ba8711e 100644 --- a/src/parse/scan2.c +++ b/src/parse/scan2.c @@ -53,7 +53,7 @@ ANN static Value arg_value(const Env env, const Arg_List list) { if(!var->value) { const Value v = new_value(env->gwion, list->type, var->xid ? s_name(var->xid) : s_name(insert_symbol((m_str)var))); - if(list->td) // lambda + if(list->td) v->flag = list->td->flag | ae_flag_arg; return v; } @@ -475,7 +475,6 @@ ANN2(1,2,4) static Value func_create(const Env env, const Func_Def f, scan2_func_def_flag(f); if(GET_FLAG(f, builtin)) CHECK_BO(scan2_func_def_builtin(func, func->name)) -// if(GET_FLAG(func, member) && !GET_FLAG(func->def, func)) if(GET_FLAG(func, member)) f->stack_depth += SZ_INT; if(GET_FLAG(func->def, variadic)) @@ -507,7 +506,6 @@ ANN m_bool scan2_func_def(const Env env, const Func_Def f) { GWDEBUG_EXE const Func func = nspc_lookup_func1(env->curr, insert_symbol(func_name)); if(func) { f->ret_type = type_decl_resolve(env, f->td); - // check arg_list->type for lambdas return (f->arg_list && f->arg_list->type) ? scan2_args(env, f) : GW_OK; } } diff --git a/src/plug.c b/src/plug.c index 9259b889..66340551 100644 --- a/src/plug.c +++ b/src/plug.c @@ -22,7 +22,7 @@ typedef m_str (*modstr)(void); typedef void* (*modini)(const Gwion, const Vector); typedef void* (*modend)(const Gwion, void*); typedef void* (*modend)(const Gwion, void*); -typedef void (*driver)(struct _driver*); + struct Plug_ { m_str name; modini ini; @@ -49,7 +49,7 @@ ANN static void plug_get(PlugInfo* p, const m_str c) { plug->end = DLFUNC(dl, modend, GWMODEND_NAME); vector_add(&p->vec[GWPLUG_MODULE], (vtype)plug); } - const driver drv = DLFUNC(dl, driver, GWDRIVER_NAME); + const f_drvset drv = DLFUNC(dl, f_drvset, GWDRIVER_NAME); if(drv) { const modstr str = DLFUNC(dl, modstr, GWMODSTR_NAME); map_set(&p->drv, (vtype)str(), (vtype)drv); @@ -95,8 +95,7 @@ void plug_end(const Gwion gwion) { ANN Vector split_args(const m_str str) { const m_str arg = strchr(str, '='); - m_str c, d = strdup(arg+1); - c = d; + m_str d = strdup(arg+1), c = d; const Vector args = new_vector(); while(d) vector_add(args, (vtype)strdup(strsep(&d, ","))); diff --git a/tests/sh/opt.sh b/tests/sh/opt.sh index 337b63b8..c2a77331 100644 --- a/tests/sh/opt.sh +++ b/tests/sh/opt.sh @@ -1,5 +1,5 @@ #!/bin/bash -# [test] #39 +# [test] #17 n=0 [ "$1" ] && n="$1" [ "$n" -eq 0 ] && n=1 @@ -37,36 +37,6 @@ run "$n" "help (short)" "-?" "file" n=$((n+1)) run "$n" "help (long)" "--help" "file" -# host -n=$((n+1)) -run "$n" "config (short)" "-v" "file" -n=$((n+1)) -run "$n" "config (long)" "--version" "file" - -# port -n=$((n+1)) -run "$n" "port invalid (short)" "-p 1" "file" -n=$((n+1)) -run "$n" "port invalid (long)" "--port 1" "file" - -# card default -n=$((n+1)) -run "$n" "card default (short)" "-c default" "file" -n=$((n+1)) -run "$n" "card default (long)" "--card default" "file" - -# card invalid -n=$((n+1)) -run "$n" "card invalid (short)" "-c invalid" "file" -n=$((n+1)) -run "$n" "card invalid (long)" "--card invalid" "file" - -# channels -n=$((n+1)) -run "$n" "channels (short)" "-g 2" "file" -n=$((n+1)) -run "$n" "channels (long)" "--chan 2" "file" - # in channels n=$((n+1)) run "$n" "in channels (short)" "-i 2" "file" @@ -79,57 +49,20 @@ run "$n" "out channels (short)" "-o 2" "file" n=$((n+1)) run "$n" "out channels (long)" "--out 2" "file" -# bufnum -n=$((n+1)) -run "$n" "bufnum (short)" "-n 2" "file" -n=$((n+1)) -run "$n" "bufnum (long)" "--bufnum 3" "file" - -# bufsize -n=$((n+1)) -run "$n" "bufsize (short)" "-b 256" "file" -n=$((n+1)) -run "$n" "bufsize (long)" "--bufsize 256" "file" - -# raw -n=$((n+1)) -run "$n" "raw (short)" "-r" "file" -n=$((n+1)) -run "$n" "raw (long)" "--raw" "file" - # samplerate n=$((n+1)) run "$n" "samplerate (short)" "-s 44100" "file" n=$((n+1)) run "$n" "samplerate (long)" "--sr 44100" "file" -# standalone -n=$((n+1)) -run "$n" "standalone (short)" "-a" "file" -n=$((n+1)) -run "$n" "standalone (long)" "--alone" "file" - -# format -n=$((n+1)) -run "$n" "format (short)" "-f test_format" "file" -n=$((n+1)) -run "$n" "format (long)" "--format test_format" "file" - -# backend -n=$((n+1)) -run "$n" "backend (short)" "-e test_backend" "file" -n=$((n+1)) -run "$n" "backend (long)" "--backend test_backend" "file" - # wrong file n=$((n+1)) run "$n" "wrong file" "non_existant_file" "file" # plug_dir n=$((n+1)) -run "$n" "plugin directory" "-P non_existant_dir" "file" +run "$n" "plugin directory" "-p non_existant_dir" "file" # config n=$((n+1)) -run "$n" "config" "-C" "file" - +run "$n" "config" "-c" "file" diff --git a/tests/sh/plugin.sh b/tests/sh/plugin.sh index bc6ded3d..3dd0f2e6 100644 --- a/tests/sh/plugin.sh +++ b/tests/sh/plugin.sh @@ -13,7 +13,7 @@ export GWION_ADD_DIR test_plugin() { export NAME=$"$1" make - ../../gwion -P. "$NAME.gw" &> /dev/null + ../../gwion -p. "$NAME.gw" &> /dev/null NAME="$1" make clean N=$(printf "% 4i" "$n") echo "ok $N plugin test: '$NAME'" @@ -22,7 +22,7 @@ test_plugin() { # empty plug file touch "empty.so" -./gwion -P. &> /dev/null +./gwion -p. &> /dev/null N=$(printf "% 4i" "$n") echo "ok $N plugin test: 'empty'" n=$((n+1)) -- 2.43.0