From c9ae1e2428ba07e571181bbb5aa1a306862a1018 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=A9mie=20Astor?= Date: Thu, 13 May 2021 15:42:36 +0200 Subject: [PATCH] :art: Simplify Shred -> mp access --- include/gack.h | 2 +- plug | 2 +- src/emit/emit.c | 11 ++++++----- src/emit/memoize.c | 2 +- src/lib/array.c | 8 ++++---- src/lib/modules.c | 8 ++++---- src/lib/prim.c | 2 +- src/lib/string.c | 22 +++++++++++----------- src/lib/ugen.c | 2 +- src/lib/union.c | 2 +- src/lib/vararg.c | 2 +- src/vm/vm_code.c | 1 - src/vm/vm_name.c | 2 +- 13 files changed, 33 insertions(+), 33 deletions(-) diff --git a/include/gack.h b/include/gack.h index 106a0edc..f7c901a6 100644 --- a/include/gack.h +++ b/include/gack.h @@ -4,7 +4,7 @@ ANN void gack(const VM_Shred, const m_uint); #define INTERP_PRINTF(fmt, ...) { \ m_str ret = *(m_str*)(VALUE - SZ_INT);\ - gw_asprintf(shred->info->vm->gwion->mp, &ret, fmt, ##__VA_ARGS__); \ + gw_asprintf(shred->info->mp, &ret, fmt, ##__VA_ARGS__); \ *(m_str*)(VALUE - SZ_INT) = ret;\ } diff --git a/plug b/plug index b9321362..62ce1764 160000 --- a/plug +++ b/plug @@ -1 +1 @@ -Subproject commit b932136274811c52694dc7f2d3c9de0832e6b64b +Subproject commit 62ce17641d575fb1c0a16194234be257b4a6b85f diff --git a/src/emit/emit.c b/src/emit/emit.c index 9791df9a..29901afa 100644 --- a/src/emit/emit.c +++ b/src/emit/emit.c @@ -816,9 +816,10 @@ ANN static m_bool emit_exp_decl_non_static(const Emitter emit, const Exp_Decl *d if(is_obj && (is_array || !is_ref)) CHECK_BB(emit_instantiate_decl(emit, type, decl->td, array, is_ref)); f_instr *exec = (f_instr*)allocmember; + if(!emit->env->scope->depth) + emit_debug(emit, v); if(!vflag(v, vflag_member)) { v->from->offset = emit_local(emit, type); - emit_debug(emit, v); exec = (f_instr*)(allocword); if(GET_FLAG(v, late)) { // ref or emit_var ? const Instr clean = emit_add_instr(emit, MemSetImm); @@ -1301,10 +1302,10 @@ ANN static m_bool scoped_stmt(const Emitter emit, const Stmt stmt, const m_bool return ret; } -#define SPORK_FUNC_PREFIX "spork~func:%i" -#define FORK_FUNC_PREFIX "fork~func:%i" -#define SPORK_CODE_PREFIX "spork~code:%i" -#define FORK_CODE_PREFIX "fork~code:%i" +#define SPORK_FUNC_PREFIX "spork~func:%u" +#define FORK_FUNC_PREFIX "fork~func:%u" +#define SPORK_CODE_PREFIX "spork~code:%u" +#define FORK_CODE_PREFIX "fork~code:%u" static void push_spork_code(const Emitter emit, const m_str prefix, const loc_t pos) { char c[strlen(SPORK_FUNC_PREFIX) + num_digit(pos.first.line) + 1]; diff --git a/src/emit/memoize.c b/src/emit/memoize.c index 30a73cd2..cc5b598b 100644 --- a/src/emit/memoize.c +++ b/src/emit/memoize.c @@ -41,7 +41,7 @@ ANN static inline m_bit* get_data(MemPool mp, Memoize m) { INSTR(MemoizeStore) { const Memoize m = shred->code->memoize; - m_bit* data = get_data(shred->info->vm->gwion->mp, m); + m_bit* data = get_data(shred->info->mp, m); memcpy(data, shred->mem, m->arg_sz); memcpy(data + m->arg_sz, shred->reg - m->ret_sz, m->ret_sz); } diff --git a/src/lib/array.c b/src/lib/array.c index ba652879..0a2164cf 100644 --- a/src/lib/array.c +++ b/src/lib/array.c @@ -268,7 +268,7 @@ static INSTR(ArraySlice) { handle(shred, "OutOfBoundsArraySliceException"); return; } - const M_Object out = new_array(shred->info->vm->gwion->mp, array->type_ref, sz); + const M_Object out = new_array(shred->info->mp, array->type_ref, sz); for(m_int i = start, j = 0; i != end; i += op, ++j) { m_bit buf[ARRAY_SIZE(in)]; m_vector_get(in, i, &buf); @@ -521,7 +521,7 @@ static INSTR(count_run_end) { static MFUN(vm_vector_map) { const m_uint offset = *(m_uint*)REG(SZ_INT*3); - const M_Object ret = new_array(shred->info->vm->gwion->mp, o->type_ref, ARRAY_LEN(ARRAY(o))); + const M_Object ret = new_array(shred->info->mp, o->type_ref, ARRAY_LEN(ARRAY(o))); vector_add(&shred->gc, (m_uint)ret); if(ARRAY_LEN(ARRAY(o))) { _init(shred, &map_run_code, offset, SZ_INT); @@ -533,7 +533,7 @@ static MFUN(vm_vector_map) { static MFUN(vm_vector_compactmap) { const VM_Code code = *(VM_Code*)REG(SZ_INT*2); const m_uint offset = *(m_uint*)REG(SZ_INT*3); - const M_Object ret = new_array(shred->info->vm->gwion->mp, + const M_Object ret = new_array(shred->info->mp, code->ret_type, 0); vector_add(&shred->gc, (m_uint)ret); if(ARRAY_LEN(ARRAY(o))) { @@ -545,7 +545,7 @@ static MFUN(vm_vector_compactmap) { static MFUN(vm_vector_filter) { const m_uint offset = *(m_uint*)REG(SZ_INT*3); - const M_Object ret = new_array(shred->info->vm->gwion->mp, o->type_ref, 0); + const M_Object ret = new_array(shred->info->mp, o->type_ref, 0); vector_add(&shred->gc, (m_uint)ret); if(ARRAY_LEN(ARRAY(o))) { _init(shred, &filter_run_code, offset, SZ_INT); diff --git a/src/lib/modules.c b/src/lib/modules.c index 016d6e63..ef48b4d4 100644 --- a/src/lib/modules.c +++ b/src/lib/modules.c @@ -192,7 +192,7 @@ static TICK(usrugen_tick) { } static CTOR(usrugen_ctor) { - struct UUGen_* uu = mp_calloc(shred->info->vm->gwion->mp, UUGen); + struct UUGen_* uu = mp_calloc(shred->info->mp, UUGen); uu->self = o; ugen_ini(shred->info->vm->gwion, UGEN(o), 1, 1); ugen_gen(shred->info->vm->gwion, UGEN(o), id_tick, uu, 0); @@ -202,7 +202,7 @@ static DTOR(usrugen_dtor) { struct UUGen_ *uu = UGEN(o)->module.gen.data; if(uu->shred) free_vm_shred(uu->shred); - mp_free(shred->info->vm->gwion->mp, UUGen, UGEN(o)->module.gen.data); + mp_free(shred->info->mp, UUGen, UGEN(o)->module.gen.data); } static OP_CHECK(opck_usrugen) { @@ -262,10 +262,10 @@ static INSTR(UsrUGenTick) { handle(shred, "NullTickException"); return; } - uu->shred = new_vm_shred(shred->info->vm->gwion->mp, *(VM_Code*)(shred->reg-offset)); + uu->shred = new_vm_shred(shred->info->mp, *(VM_Code*)(shred->reg-offset)); vmcode_addref(*(VM_Code*)(shred->reg - offset)); uu->shred->info->vm = shred->info->vm; - code_prepare(vmcode_callback(shred->info->vm->gwion->mp, uu->shred->code)); + code_prepare(vmcode_callback(shred->info->mp, uu->shred->code)); shreduler_ini(uu->shred->info->vm->shreduler, uu->shred); uu->prep = instr->m_val ? member_prep : global_prep; *(M_Object*)(shred->reg - SZ_INT) = o; diff --git a/src/lib/prim.c b/src/lib/prim.c index 38375143..fec7d7ba 100644 --- a/src/lib/prim.c +++ b/src/lib/prim.c @@ -150,7 +150,7 @@ static INSTR(IntRange) { const m_int end = *(m_int*)REG(0); const m_int op = start < end ? 1 : -1; const m_uint sz = op > 0 ? end - start : start - end; - const M_Object array = new_array(shred->info->vm->gwion->mp, (Type)instr->m_val, sz); + const M_Object array = new_array(shred->info->mp, (Type)instr->m_val, sz); for(m_int i = start, j = 0; i != end; i += op, ++j) m_vector_set(ARRAY(array), j, &i); *(M_Object*)REG(-SZ_INT) = array; diff --git a/src/lib/string.c b/src/lib/string.c index 2e8372bf..8acf522b 100644 --- a/src/lib/string.c +++ b/src/lib/string.c @@ -49,11 +49,11 @@ opck_str(eq, !strcmp(bin->lhs->d.prim.d.str, bin->rhs->d.prim.d.str)) opck_str(neq, strcmp(bin->lhs->d.prim.d.str, bin->rhs->d.prim.d.str)) static CTOR(string_ctor) { - STRING(o) = _mp_calloc(shred->info->vm->gwion->mp, 1); + STRING(o) = _mp_calloc(shred->info->mp, 1); } static DTOR(string_dtor) { - free_mstr(shred->info->vm->gwion->mp, STRING(o)); + free_mstr(shred->info->mp, STRING(o)); } ID_CHECK(check_funcpp) { @@ -93,7 +93,7 @@ static INSTR(StringSlice) { for(m_int i = start, j = 0; i != end; i += op, ++j) c[j] = str[i]; c[sz] = '\0'; - *(M_Object*)REG(-SZ_INT) = new_string(shred->info->vm->gwion->mp, shred, c); + *(M_Object*)REG(-SZ_INT) = new_string(shred->info->mp, shred, c); } static MFUN(string_len) { @@ -106,7 +106,7 @@ static MFUN(string_upper) { for(m_uint i = 0; i < strlen(c); i++) if(c[i] >= 'a' && c[i] <= 'z') c[i] += 'A' - 'a'; - *(M_Object*)RETURN = new_string(shred->info->vm->gwion->mp, shred, c); + *(M_Object*)RETURN = new_string(shred->info->mp, shred, c); } static MFUN(string_lower) { @@ -115,7 +115,7 @@ static MFUN(string_lower) { for(m_uint i = 0; i < strlen(c); i++) if(c[i] >= 'A' && c[i] <= 'Z') c[i] -= 'A' - 'a'; - *(M_Object*)RETURN = new_string(shred->info->vm->gwion->mp, shred, c); + *(M_Object*)RETURN = new_string(shred->info->mp, shred, c); } static MFUN(string_ltrim) { @@ -125,7 +125,7 @@ static MFUN(string_ltrim) { i++; char c[strlen(str) - i + 1]; strcpy(c, STRING(o) + i); - *(M_Object*)RETURN = new_string(shred->info->vm->gwion->mp, shred, c); + *(M_Object*)RETURN = new_string(shred->info->mp, shred, c); } static MFUN(string_rtrim) { @@ -138,7 +138,7 @@ static MFUN(string_rtrim) { char c[len + 2]; strncpy(c, str, len + 1); c[len + 1] = '\0'; - *(M_Object*)RETURN = new_string(shred->info->vm->gwion->mp, shred, c); + *(M_Object*)RETURN = new_string(shred->info->mp, shred, c); } else { ++o->ref; *(M_Object*)RETURN = o; @@ -168,7 +168,7 @@ static MFUN(string_trim) { for(i = start; i < len - end; i++) c[i - start] = str[i]; c[len - start - end ] = '\0'; - *(M_Object*)RETURN = new_string(shred->info->vm->gwion->mp, shred, c); + *(M_Object*)RETURN = new_string(shred->info->mp, shred, c); } static MFUN(string_charAt) { @@ -217,7 +217,7 @@ static MFUN(string_insert) { for(i = index; i < (m_int)len; i++) c[i + len_insert] = str[i]; c[len + len_insert] = '\0'; - *(M_Object*)RETURN = new_string(shred->info->vm->gwion->mp, shred, c);; + *(M_Object*)RETURN = new_string(shred->info->mp, shred, c);; } static MFUN(string_replace) { @@ -243,7 +243,7 @@ static MFUN(string_replace) { for(i = 0; i < len_insert; i++) c[i + index] = insert[i]; c[index + len_insert] = '\0'; - *(M_Object*)RETURN = new_string(shred->info->vm->gwion->mp, shred, c);; + *(M_Object*)RETURN = new_string(shred->info->mp, shred, c);; } static MFUN(string_replaceN) { @@ -272,7 +272,7 @@ static MFUN(string_replaceN) { for(i = index + _len; i < (m_int)len; i++) c[i] = str[i]; c[len + _len - 1] = '\0'; - *(M_Object*)RETURN = new_string(shred->info->vm->gwion->mp, shred, c);; + *(M_Object*)RETURN = new_string(shred->info->mp, shred, c);; } static MFUN(string_find) { diff --git a/src/lib/ugen.c b/src/lib/ugen.c index 9908ea12..f6ccf921 100644 --- a/src/lib/ugen.c +++ b/src/lib/ugen.c @@ -292,7 +292,7 @@ ANN static void release_multi(const UGen ug, const VM_Shred shred) { static DTOR(ugen_dtor) { const UGen ug = UGEN(o); - MemPool p = shred->info->vm->gwion->mp; + MemPool p = shred->info->mp; vector_rem2(&shred->info->vm->ugen, (vtype)ug); if(!ug->multi) release_mono(p, ug); diff --git a/src/lib/union.c b/src/lib/union.c index a826bbc0..2ea352d5 100644 --- a/src/lib/union.c +++ b/src/lib/union.c @@ -138,7 +138,7 @@ static INSTR(UnionCtor) { POP_REG(shred, instr->m_val2); POP_REG(shred, SZ_INT); const m_uint index = *(m_uint*)REG(-SZ_INT); - const M_Object o = *(M_Object*)REG(-SZ_INT) = new_object(shred->info->vm->gwion->mp, NULL, (Type)instr->m_val); + const M_Object o = *(M_Object*)REG(-SZ_INT) = new_object(shred->info->mp, NULL, (Type)instr->m_val); *(m_uint*)o->data = index;// + 1; memcpy(o->data + SZ_INT, REG(0), instr->m_val2); } diff --git a/src/lib/vararg.c b/src/lib/vararg.c index fe4d086b..938b7622 100644 --- a/src/lib/vararg.c +++ b/src/lib/vararg.c @@ -37,7 +37,7 @@ static DTOR(vararg_dtor) { offset += t->size; } } - free_vararg(shred->info->vm->gwion->mp, arg); + free_vararg(shred->info->mp, arg); } static MFUN(mfun_vararg_cpy) { diff --git a/src/vm/vm_code.c b/src/vm/vm_code.c index 1aa3ae89..8b176601 100644 --- a/src/vm/vm_code.c +++ b/src/vm/vm_code.c @@ -155,7 +155,6 @@ VM_Code new_vmcode(MemPool p, const Vector instr, const m_uint stack_depth, VM_Code code = mp_calloc(p, VM_Code); code->name = mstrdup(p, name); if(instr) { -// code->instr = vector_copy(p, instr); vector_init(&code->instr); vector_copy2(instr, &code->instr); code->bytecode = tobytecode(p, code); diff --git a/src/vm/vm_name.c b/src/vm/vm_name.c index 19b0b004..aaca8e9f 100644 --- a/src/vm/vm_name.c +++ b/src/vm/vm_name.c @@ -8,7 +8,7 @@ m_str code_name_set(MemPool p, const m_str name, const m_str file) { return str; } -m_str code_name(const m_str name, const m_bool b) { +m_str code_name(const m_str name, const bool b) { const m_str str = strchr(name, '$'); return (b && str) ? (str + 1) : name; } -- 2.43.0