From: fennecdjay Date: Tue, 4 Oct 2022 09:38:43 +0000 (+0200) Subject: Use xfun_handle where relevant X-Git-Tag: nightly~227 X-Git-Url: http://10.10.0.4:5575/?a=commitdiff_plain;h=09070bb47b4c05bd5c808d058b6fb8741448f610;p=gwion.git Use xfun_handle where relevant --- diff --git a/include/vm.h b/include/vm.h index f66f431f..6ef06b77 100644 --- a/include/vm.h +++ b/include/vm.h @@ -20,7 +20,7 @@ struct VM_Code_ { struct M_Vector_ live_values; uint16_t stack_depth; uint16_t ref; - bool is_prepared; +// bool is_prepared; bool builtin; bool callback; bool is_memoize; @@ -136,6 +136,11 @@ ANN m_str code_name(const m_str, const bool); ANN uint32_t gw_rand(uint32_t s[2]); ANN void gw_seed(uint32_t s[2], const uint64_t); ANN void handle(VM_Shred shred, const m_str effect); +#define xfun_handle(shred, effect) {\ + shred->mem -= ((Instr)vector_at(&shred->code->instr, shred->pc-1))->m_val2; \ + handle(shred, effect); \ +} + ANN bool unwind(const VM_Shred shred, const Symbol effect, const m_uint size); #define BBQ_POS_MAX 16777216 diff --git a/plug b/plug index 14c74b7f..c3d0108e 160000 --- a/plug +++ b/plug @@ -1 +1 @@ -Subproject commit 14c74b7ff5f56000c30668fed553d585862deb87 +Subproject commit c3d0108ef59d40a6079f8da1b7a1c79dc1c80d96 diff --git a/src/lib/closure.c b/src/lib/closure.c index 12a817ca..3e958474 100644 --- a/src/lib/closure.c +++ b/src/lib/closure.c @@ -697,7 +697,7 @@ static DTOR(fptr_dtor) { } static MFUN(fptr_default) { - handle(shred, "EmptyFunctionPointer"); + xfun_handle(shred, "EmptyFunctionPointer"); } static GACK(gack_function) { INTERP_PRINTF("%s", t->name); } diff --git a/src/lib/locale.c b/src/lib/locale.c index 6b7afcdc..b4cdc7c1 100644 --- a/src/lib/locale.c +++ b/src/lib/locale.c @@ -38,7 +38,7 @@ static SFUN(BasicLocale) { const M_Object arg = *(M_Object*)MEM(0); const m_float ret = basic_locale(STRING(arg)); if(ret == -1.0) - handle(shred, "invalid value for locale"); + xfun_handle(shred, "invalid value for locale"); *(m_float*)RETURN = ret; } diff --git a/src/lib/modules.c b/src/lib/modules.c index 73dd192c..46564054 100644 --- a/src/lib/modules.c +++ b/src/lib/modules.c @@ -245,10 +245,6 @@ static INSTR(UsrUGenTick) { const m_uint offset = !instr->m_val ? SZ_INT : 0; shred->reg -= SZ_INT * 2 - offset; const M_Object o = *(M_Object *)(shred->reg + SZ_INT - offset); - if (!o) { - handle(shred, "NullPtrException"); - return; - } struct UUGen_ *uu = UGEN(o)->module.gen.data; if (uu->shred) { free_vm_shred(uu->shred); diff --git a/src/lib/shred.c b/src/lib/shred.c index 4728250a..b9927140 100644 --- a/src/lib/shred.c +++ b/src/lib/shred.c @@ -95,7 +95,7 @@ static SFUN(vm_shred_from_id) { } } } - handle(shred, "InvalidShredRequest"); + xfun_handle(shred, "InvalidShredRequest"); } static MFUN(shred_args) { @@ -109,8 +109,7 @@ static MFUN(shred_arg) { if (s->info->args.ptr && idx >= 0 && (m_uint)idx < vector_size(&s->info->args)) { const m_str str = (m_str)vector_at(&s->info->args, *(m_uint *)MEM(SZ_INT)); *(M_Object *)RETURN = new_string(shred->info->vm->gwion, str); - } else - handle(shred, "InvalidShredArgumentRequest"); + } else xfun_handle(shred, "InvalidShredArgumentRequest"); } #ifndef BUILD_ON_WINDOWS diff --git a/src/lib/string.c b/src/lib/string.c index 9532ef92..ae32cd96 100644 --- a/src/lib/string.c +++ b/src/lib/string.c @@ -172,7 +172,7 @@ static MFUN(string_trim) { break; } if (len - start - end <= 0) { - handle(shred, "InvalidStringTrimRequest"); + xfun_handle(shred, "InvalidStringTrimRequest"); return; } char c[len - start - end + 1]; @@ -213,7 +213,7 @@ static MFUN(string_replace) { const m_uint len = strlen(str); len_insert = strlen(insert); if (index >= (m_int)len || index < 0 || (index + len_insert + 1) <= 0) { - handle(shred, "InvalidStringReplace"); + xfun_handle(shred, "InvalidStringReplace"); return; } char c[index + len_insert + 1]; @@ -232,7 +232,7 @@ static MFUN(string_replaceN) { const m_int _len = *(m_int *)MEM(SZ_INT * 2); if (!arg || index > (m_int)strlen(STRING(o)) || _len > (m_int)strlen(STRING(arg))) { - handle(shred, "InvalidStringReplace"); + xfun_handle(shred, "InvalidStringReplace"); return; } char insert[strlen(STRING(arg)) + 1]; @@ -349,7 +349,7 @@ static MFUN(string_erase) { const m_int size = len - rem + 1; const m_int start = _start >= 0 ? _start : len - _start; if (start >= len || size <= 0) { - handle(shred, "InvalidStringErase"); + xfun_handle(shred, "InvalidStringErase"); return; } char c[size]; @@ -363,7 +363,7 @@ static MFUN(string_save) { const m_str path = STRING(*(M_Object*)MEM(SZ_INT)); FILE *f = fopen(path, "w"); if(!f) { - handle(shred, "StringLoadException"); + xfun_handle(shred, "StringLoadException"); return; } const m_str str = STRING(o); @@ -375,7 +375,7 @@ static SFUN(string_load) { const m_str path = STRING(*(M_Object*)MEM(0)); FILE *f = fopen(path, "r"); if(!f) { - handle(shred, "StringLoadException"); + xfun_handle(shred, "StringLoadException"); return; } fseek(f, 0, SEEK_END); @@ -405,11 +405,11 @@ static MFUN(string_atoi2) { char *endptr = NULL; if(!(*(m_int*)RETURN = strtol(str, &endptr, 10))) { if(errno == EINVAL) { - handle(shred, "ErrorInvalidValue"); + xfun_handle(shred, "ErrorInvalidValue"); return; } if(errno == ERANGE) { - handle(shred, "ValueOutOfRange"); + xfun_handle(shred, "ValueOutOfRange"); return; } } diff --git a/src/lib/ugen.c b/src/lib/ugen.c index 1fcd6f08..59cdfe8e 100644 --- a/src/lib/ugen.c +++ b/src/lib/ugen.c @@ -330,7 +330,7 @@ static MFUN(ugen_channel) { else if (i >= 0 && (m_uint)i < UGEN(o)->connect.multi->n_chan) *(M_Object *)RETURN = UGEN(o)->connect.multi->channel[i]; else - handle(shred, "InvalidChannelRequest"); + xfun_handle(shred, "InvalidChannelRequest"); } static MFUN(ugen_get_op) { *(m_uint *)RETURN = UGEN(o)->op + 1; } diff --git a/src/parse/scan1.c b/src/parse/scan1.c index 190b42ee..e87d8985 100644 --- a/src/parse/scan1.c +++ b/src/parse/scan1.c @@ -322,7 +322,7 @@ ANN static inline m_bool shadow_arg(const Env env, const Symbol sym, Nspc nspc = env->curr; do { const Value v = nspc_lookup_value0(nspc, sym); - if (v) return shadow_err(env, v, loc); + if (v && !env->func->def->builtin) return shadow_err(env, v, loc); } while ((nspc = nspc->parent)); return GW_OK; } diff --git a/src/vm/shreduler.c b/src/vm/shreduler.c index beba69e8..00de675f 100644 --- a/src/vm/shreduler.c +++ b/src/vm/shreduler.c @@ -58,7 +58,7 @@ ANN static void shreduler_erase(const Shreduler s, MUTEX_UNLOCK(shred->mutex); const m_uint size = shred->info->frame.ptr ? vector_size(&shred->info->frame) : 0; - unwind(shred, (Symbol)-1, size); + if(size) unwind(shred, (Symbol)-1, size); vector_rem2(&s->active_shreds, (vtype)shred); release(shred->info->me, shred); }