From: Jérémie Astor Date: Sun, 19 Sep 2021 15:08:38 +0000 (+0200) Subject: :art: Add Exp ref and data X-Git-Tag: nightly~436 X-Git-Url: http://10.10.0.4:5575/?a=commitdiff_plain;h=a11eeab72effe66e49800e330068b24ce324c3d3;p=gwion.git :art: Add Exp ref and data --- diff --git a/ast b/ast index 317a4623..e46922eb 160000 --- a/ast +++ b/ast @@ -1 +1 @@ -Subproject commit 317a4623e5e4cd1ca5c46d84d9b53b23a5159678 +Subproject commit e46922eb0cc11d718e4d50431ac45fbe1f5d386b diff --git a/include/emit.h b/include/emit.h index 34a287c3..05c633df 100644 --- a/include/emit.h +++ b/include/emit.h @@ -65,12 +65,9 @@ m_bool emit_instantiate_object(const Emitter, const Type, const Array_Sub, const m_bool); ANN m_uint emit_code_offset(const Emitter emit); ANN m_uint emit_local(const Emitter emit, const Type t); +ANN void* emit_localx(const Emitter emit, const Type t); ANN m_bool emit_exp_spork(const Emitter, const Exp_Unary *); ANN m_bool emit_exp(const Emitter, const Exp); -ANN static inline void emit_gc(const Emitter emit, const m_int offset) { - const Instr gc = emit_add_instr(emit, GcAdd); - gc->m_val = offset; -} ANN Instr emit_object_addref(const Emitter emit, const m_int size, const bool emit_var); diff --git a/include/import.h b/include/import.h index fd10bc9e..e5e466a9 100644 --- a/include/import.h +++ b/include/import.h @@ -81,11 +81,10 @@ OP_CHECK(opck_usr_implicit); OP_CHECK(opck_new); OP_EMIT(opem_new); -ANN2(1, 3) -static inline M_Object new_object_str(const Gwion gwion, const VM_Shred shred, - const m_str str) { +ANN +static inline M_Object new_object_str(const Gwion gwion, const m_str str) { struct loc_t_ loc = {}; DECL_OO(const Type, t, = str2type(gwion, str, loc)); - return new_object(gwion->mp, shred, t); + return new_object(gwion->mp, t); } #endif diff --git a/include/object.h b/include/object.h index 54745c56..45048912 100644 --- a/include/object.h +++ b/include/object.h @@ -11,13 +11,12 @@ struct M_Object_ { ANN void instantiate_object(const VM_Shred, const Type); ANN void free_object(MemPool p, const M_Object); -ANEW M_Object new_object(MemPool, const VM_Shred, const Type); +ANEW M_Object new_object(MemPool, const Type); ANEW struct UGen_ *new_UGen(MemPool); ANEW M_Object new_M_UGen(const struct Gwion_ *); ANN void fork_clean(const VM_Shred, const Vector); ANN ANEW M_Object new_array(MemPool, const Type t, const m_uint length); -ANEW M_Object new_string(MemPool, const VM_Shred, const m_str); -ANEW M_Object new_string2(const struct Gwion_ *, const VM_Shred, const m_str); +ANEW M_Object new_string(const struct Gwion_ *, const m_str); ANEW M_Object new_shred(const VM_Shred); ANN void fork_launch(const M_Object, const m_uint); ANN void __release(const M_Object, const VM_Shred); diff --git a/include/opcode.h b/include/opcode.h index deb28418..571b9196 100644 --- a/include/opcode.h +++ b/include/opcode.h @@ -199,9 +199,6 @@ enum { eUpvalueOther, eUpvalueAddr, eDotFunc, - eGcIni, - eGcAdd, - eGcEnd, eGackType, eGackEnd, eGack, @@ -418,9 +415,6 @@ enum { #define UpvalueOther (f_instr)eUpvalueOther #define UpvalueAddr (f_instr)eUpvalueAddr #define DotFunc (f_instr)eDotFunc -#define GcIni (f_instr)eGcIni -#define GcAdd (f_instr)eGcAdd -#define GcEnd (f_instr)eGcEnd #define GackType (f_instr)eGackType #define GackEnd (f_instr)eGackEnd #define Gack (f_instr)eGack @@ -1365,19 +1359,6 @@ ANN static inline void dump_opcodes(const VM_Code code) { gw_out(" {-M}%-14"UINT_F"{0}", instr->m_val2); gw_out("\n"); break; - case eGcIni: - gw_out("{Y}┃{0}{-}% 4lu{0}: GcIni ", j); - gw_out("\n"); - break; - case eGcAdd: - gw_out("{Y}┃{0}{-}% 4lu{0}: GcAdd ", j); - gw_out(" {-R}%-14"INT_F"{0}", instr->m_val); - gw_out("\n"); - break; - case eGcEnd: - gw_out("{Y}┃{0}{-}% 4lu{0}: GcEnd ", j); - gw_out("\n"); - break; case eGackType: gw_out("{Y}┃{0}{-}% 4lu{0}: GackType ", j); gw_out("\n"); diff --git a/include/vm.h b/include/vm.h index a21b68ec..b88f3e7d 100644 --- a/include/vm.h +++ b/include/vm.h @@ -92,7 +92,6 @@ struct VM_Shred_ { m_bit * mem; m_bit * base; size_t pc; - struct Vector_ gc; struct ShredTick_ *tick; struct ShredInfo_ *info; }; diff --git a/opcode.txt b/opcode.txt index 5117b2d1..460f60a6 100644 --- a/opcode.txt +++ b/opcode.txt @@ -196,9 +196,6 @@ UpvalueFloat~u UpvalueOther~u~u UpvalueAddr~u DotFunc~u~u -GcIni -GcAdd~i -GcEnd GackType GackEnd~u Gack diff --git a/src/emit/emit.c b/src/emit/emit.c index 40093328..87f4fdf5 100644 --- a/src/emit/emit.c +++ b/src/emit/emit.c @@ -37,6 +37,7 @@ typedef struct Local_ { Type type; m_uint offset; + Instr instr; bool skip; bool is_compound; } Local; @@ -298,6 +299,25 @@ ANN m_uint emit_local(const Emitter emit, const Type t) { return l->offset; } +ANN void* emit_localx(const Emitter emit, const Type t) { + Local *const l = frame_local(emit->gwion->mp, emit->code->frame, t); + l->is_compound = true; + VMValue vmval = { + .t = t, .offset = l->offset, .start = emit_code_size(emit)}; + m_vector_add(&emit->code->live_values, &vmval); + ++emit->code->frame->value_count; + l->instr = emit_add_instr(emit, Reg2Mem); + l->instr->m_val = l->offset; + l->instr->m_val2 = -SZ_INT; + return l; +} + +ANN void emit_local_exp(const Emitter emit, const Exp e) { + Local *const l = emit_localx(emit, e->type); + if(e->ref) + e->ref->data = l; +} + ANN m_uint emit_localn(const Emitter emit, const Type t) { Local *const l = frame_local(emit->gwion->mp, emit->code->frame, t); l->skip = true; @@ -608,7 +628,7 @@ ANN static m_bool emit_prim_array(const Emitter emit, const Array_Sub *data) { const Instr instr = emit_add_instr(emit, ArrayInit); instr->m_val = (m_uint)type; instr->m_val2 = array_base_simple(type)->size; - emit_gc(emit, -SZ_INT); + emit_local_exp(emit, prim_exp(data)); emit_notpure(emit); return GW_OK; } @@ -638,7 +658,7 @@ ANN static m_bool emit_prim_range(const Emitter emit, Range **data) { .pos = e->pos, .data = (uintptr_t)prim_exp(data)}; CHECK_BB(op_emit(emit, &opi)); - emit_gc(emit, -SZ_INT); + emit_local_exp(emit, prim_exp(data)); return GW_OK; } @@ -680,7 +700,9 @@ ANN static m_bool emit_exp_slice(const Emitter emit, const Exp_Slice *range) { .rhs = range->base->type, .pos = e->pos, .data = (uintptr_t)exp_self(range)}; - return op_emit(emit, &opi); + CHECK_BB(op_emit(emit, &opi)); + emit_local_exp(emit, exp_self(range)); + return GW_OK; } ANN static inline Instr specialid_instr(const Emitter emit, @@ -707,6 +729,8 @@ ANN static m_bool emit_prim_id(const Emitter emit, const Symbol *data) { struct SpecialId_ *spid = specialid_get(emit->gwion, *data); if (spid) return specialid_instr(emit, spid, prim_self(data)) ? GW_OK : GW_ERROR; + + if(vflag(prim->value, vflag_fglobal)) exp_self(prim)->acquire = 1; return emit_symbol(emit, prim_self(data)); } @@ -743,10 +767,10 @@ ANN static m_bool emit_prim_str(const Emitter emit, const struct AstString *str) CHECK_BB(escape_str(emit, c, prim_pos(str))); } else c[0] = '\0'; - v->d.obj = new_string2(emit->gwion, NULL, c); + v->d.obj = new_string(emit->gwion, c); } regpushi(emit, (m_uint)v->d.obj); - emit_object_addref(emit, -SZ_INT, 0); +// emit_object_addref(emit, -SZ_INT, 0); return GW_OK; } @@ -806,6 +830,7 @@ ANN static m_bool emit_prim_interp(const Emitter emit, const Exp *exp) { CHECK_BB(emit_interp(emit, e)); const Instr instr = emit_add_instr(emit, GackEnd); instr->m_val = 1; + emit_localx(emit, emit->gwion->type[et_string]); return GW_OK; } @@ -879,6 +904,26 @@ ANN static Instr emit_struct_decl(const Emitter emit, const Value v, return instr; } +ANN void unset_local(const Emitter emit, Local *const l) { + l->instr->opcode = eNoOp; +// l->is_compound = false; +// l-> = false; + for(m_uint i = m_vector_size(&emit->code->live_values) + 1; --i;) { + VMValue vmval = *(VMValue*)(ARRAY_PTR((&emit->code->live_values)) + (i-1) * sizeof(VMValue)); + if(vmval.offset != l->offset) continue; + m_vector_rem(&emit->code->live_values, i-1); + break; + } + --emit->code->frame->value_count; +} + +ANN static m_uint decl_non_static_offset(const Emitter emit, const Exp_Decl *decl, const Type t) { + if(!exp_self(decl)->data) + return emit_local(emit, t); + Local *const l = exp_self(decl)->data; + return l->offset; +} + ANN static m_bool emit_exp_decl_non_static(const Emitter emit, const Exp_Decl *decl, const Var_Decl var_decl, @@ -895,7 +940,8 @@ ANN static m_bool emit_exp_decl_non_static(const Emitter emit, 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); +// v->from->offset = exp_self(decl)->data ? ((Local*)exp_self(decl)->data)->offset : emit_local(emit, type); + v->from->offset = decl_non_static_offset(emit, decl, type); exec = (f_instr *)(allocword); if (GET_FLAG(v, late)) { // ref or emit_var ? const Instr clean = emit_add_instr(emit, MemSetImm); @@ -1216,13 +1262,22 @@ ANN static m_bool emit_exp_call(const Emitter emit, const Exp_Call *exp_call) { const Exp e = exp_self(exp_call); if (exp_getvar(e)) regpush(emit, SZ_INT); CHECK_BB(_emit_exp_call(emit, exp_call)); + const Type t = exp_self(exp_call)->type; if (exp_getvar(e)) { regpop(emit, exp_self(exp_call)->type->size); + if(isa(t, emit->gwion->type[et_object]) > 0) + emit_local_exp(emit, e); const Instr instr = emit_add_instr(emit, Reg2RegAddr); instr->m_val = -SZ_INT; - } else if (!is_func(emit->gwion, exp_call->func->type) && + } else { +// if(isa(t, emit->gwion->type[et_object]) > 0) +// if(isa(t, emit->gwion->type[et_object]) > 0) +// emit_local_exp(emit, e); +// emit_localx(emit, t); + if (!is_func(emit->gwion, exp_call->func->type) && tflag(e->type, tflag_struct)) regpop(emit, SZ_INT); + } return GW_OK; } @@ -1605,28 +1660,21 @@ stack_alloc(const Emitter emit) { // maybe vararg could use t_vararg instead emit->code->stack_depth += SZ_INT; } -ANN static inline Instr scoped_ini(const Emitter emit) { +ANN static inline void scoped_ini(const Emitter emit) { ++emit->env->scope->depth; emit_push_scope(emit); - return emit_add_instr(emit, NoOp); } -ANN static inline void scoped_end(const Emitter emit, const Instr gc) { +ANN static inline void scoped_end(const Emitter emit) { emit_pop_scope(emit); - const m_bool pure = - vector_size(&emit->info->pure) && !vector_back(&emit->info->pure); - if (!pure) { - gc->opcode = eGcIni; - emit_add_instr(emit, GcEnd); - } --emit->env->scope->depth; } ANN static m_bool scoped_stmt(const Emitter emit, const Stmt stmt, const m_bool pop) { - const Instr gc = scoped_ini(emit); + scoped_ini(emit); const m_bool ret = emit_stmt(emit, stmt, pop); - scoped_end(emit, gc); + scoped_end(emit); return ret; } @@ -1735,7 +1783,10 @@ ANN m_bool emit_exp_spork(const Emitter emit, const Exp_Unary *unary) { .is_spork = (unary->op == insert_symbol("spork")), .emit_var = exp_getvar(exp_self(unary))}; CHECK_OB((sporker.vm_code = spork_prepare(emit, &sporker))); + if(!sporker.is_spork) + emit_local_exp(emit, exp_self(unary)); spork_ini(emit, &sporker); +//puts("here"); (unary->unary_type == unary_code ? spork_code : spork_func)(emit, &sporker); return GW_OK; } @@ -1949,6 +2000,10 @@ ANN static m_bool emit_stmt_return(const Emitter emit, const Stmt_Exp stmt) { return optimize_tail_call(emit, &stmt->val->d.exp_call); } CHECK_BB(emit_exp_pop_next(emit, stmt->val)); + + if(isa(stmt->val->type, emit->gwion->type[et_object]) > 0 && + (!stmt->val->data && stmt->val->acquire)) + emit_object_addref(emit, -SZ_INT, exp_getvar(stmt->val)); } vector_add(&emit->code->stack_return, (vtype)emit_add_instr(emit, Goto)); return GW_OK; @@ -2147,7 +2202,7 @@ ANN static inline m_bool unroll_run(const Emitter emit, } ANN static m_bool unroll(const Emitter emit, const struct Looper *loop) { - const Instr gc = scoped_ini(emit); + scoped_ini(emit); const Instr unroll = emit_add_instr(emit, Unroll); unroll->m_val = loop->offset; const m_uint start = emit_code_size(emit); @@ -2157,7 +2212,7 @@ ANN static m_bool unroll(const Emitter emit, const struct Looper *loop) { unroll->m_val2 = end - start; const Instr unroll2 = emit_add_instr(emit, Unroll2); unroll2->m_val = (m_uint)unroll; - scoped_end(emit, gc); + scoped_end(emit); return GW_OK; } diff --git a/src/import/import_udef.c b/src/import/import_udef.c index 88f6d5f9..3fe217f2 100644 --- a/src/import/import_udef.c +++ b/src/import/import_udef.c @@ -50,7 +50,7 @@ ANN static Type union_type(const Gwi gwi, const Union_Def udef) { // gwi->gwion->env->class_def->nspc->offset = // udef->o + udef->s; // set_vflag(udef->value, vflag_builtin); - // const M_Object o = new_object(gwi->gwion->mp, NULL, udef->value->type); + // const M_Object o = new_object(gwi->gwion->mp, udef->value->type); // udef->value->d.ptr = (m_uint*)o; if (gwi->gwion->data->cdoc) { lint_indent(gwi->lint); diff --git a/src/lib/array.c b/src/lib/array.c index fa41f106..fe91e862 100644 --- a/src/lib/array.c +++ b/src/lib/array.c @@ -34,7 +34,7 @@ static DTOR(array_dtor_struct) { } ANN M_Object new_array(MemPool p, const Type t, const m_uint length) { - const M_Object a = new_object(p, NULL, t); + const M_Object a = new_object(p, t); const m_uint depth = !tflag(t, tflag_typedef) ? t->array_depth : t->info->parent->array_depth; const m_uint size = depth > 1 ? SZ_INT : array_base(t)->size; @@ -273,7 +273,6 @@ static INSTR(ArraySlice) { static OP_EMIT(opem_array_slice) { emit_add_instr(emit, ArraySlice); - emit_gc(emit, -SZ_INT); return GW_OK; } @@ -517,7 +516,6 @@ static MFUN(vm_vector_map) { const m_uint offset = *(m_uint *)REG(SZ_INT * 3); 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); *(M_Object *)MEM(SZ_INT * 2) = ret; @@ -529,7 +527,6 @@ 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->mp, code->ret_type, 0); - vector_add(&shred->gc, (m_uint)ret); if (ARRAY_LEN(ARRAY(o))) { _init(shred, &compactmap_run_code, offset, SZ_INT); *(M_Object *)MEM(SZ_INT * 2) = ret; @@ -540,7 +537,6 @@ 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->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); *(M_Object *)MEM(SZ_INT * 2) = ret; @@ -957,7 +953,6 @@ INSTR(ArrayAlloc) { return; // TODO make exception vararg } *(void **)(ref->data + SZ_INT) = aai.data; -// vector_add(&shred->gc, (m_uint)ref); // heyo if (!info->is_obj) { POP_REG(shred, SZ_INT * (info->depth - 1)); *(M_Object *)REG(-SZ_INT) = ref; diff --git a/src/lib/engine.c b/src/lib/engine.c index 16054eb5..756bbbde 100644 --- a/src/lib/engine.c +++ b/src/lib/engine.c @@ -77,7 +77,7 @@ static INSTR(PredicateCheck) { } static FREEARG(freearg_release) { - struct Vector_ v = { .ptr = instr->m_val }; + struct Vector_ v = { .ptr = (m_uint*)instr->m_val }; vector_release(&v); } diff --git a/src/lib/object.c b/src/lib/object.c index bd340374..ab73235d 100644 --- a/src/lib/object.c +++ b/src/lib/object.c @@ -20,27 +20,18 @@ #undef insert_symbol -M_Object new_object(MemPool p, const VM_Shred shred, const Type t) { +M_Object new_object(MemPool p, const Type t) { const uint32_t offset = sizeof(struct M_Object_) + t->nspc->offset; const M_Object a = _mp_calloc(p, offset); a->ref = 1; a->type_ref = t; a->offset = t->nspc->offset; a->vtable.ptr = t->nspc->vtable.ptr; - if (shred) vector_add(&shred->gc, (vtype)a); return a; } -M_Object new_string(MemPool p, const VM_Shred shred, const m_str str) { - const M_Object o = - new_object(p, shred, shred->info->vm->gwion->type[et_string]); - STRING(o) = mstrdup(p, str); - return o; -} - -M_Object new_string2(const struct Gwion_ *gwion, const VM_Shred shred, - const m_str str) { - const M_Object o = new_object(gwion->mp, shred, gwion->type[et_string]); +M_Object new_string(const struct Gwion_ *gwion, const m_str str) { + const M_Object o = new_object(gwion->mp, gwion->type[et_string]); STRING(o) = mstrdup(gwion->mp, str); return o; } diff --git a/src/lib/opfunc.c b/src/lib/opfunc.c index 57045b61..40fae1d4 100644 --- a/src/lib/opfunc.c +++ b/src/lib/opfunc.c @@ -132,9 +132,7 @@ OP_EMIT(opem_new) { const Exp_Unary *unary = (Exp_Unary *)data; CHECK_BB(emit_instantiate_object(emit, exp_self(unary)->type, unary->ctor.td->array, 0)); - // we don't need gc for arrays? - // also when in rewrote exp -// if(!(unary->ctor.td->array || unary->ctor.exp)) - emit_gc(emit, -SZ_INT); + if(!unary->ctor.exp) + emit_localx(emit, exp_self(unary)->type); return GW_OK; } diff --git a/src/lib/shred.c b/src/lib/shred.c index a326c7c5..b52f8397 100644 --- a/src/lib/shred.c +++ b/src/lib/shred.c @@ -31,16 +31,16 @@ VM_Shred new_shred_base(const VM_Shred shred, const VM_Code code) { M_Object new_shred(const VM_Shred shred) { const M_Object obj = - new_object(shred->info->mp, NULL, shred->info->vm->gwion->type[et_shred]); + new_object(shred->info->mp, shred->info->vm->gwion->type[et_shred]); ME(obj) = shred; return obj; } ANN static inline M_Object fork_object(const VM_Shred shred, const Type t) { const Gwion gwion = shred->info->vm->gwion; - const M_Object o = new_object(gwion->mp, shred, t); + const M_Object o = new_object(gwion->mp, t); *(M_Object *)(o->data + o_fork_ev) = - new_object(gwion->mp, NULL, gwion->type[et_event]); + new_object(gwion->mp, gwion->type[et_event]); vector_init(&EV_SHREDS(*(M_Object *)(o->data + o_fork_ev))); return o; } @@ -109,7 +109,7 @@ static MFUN(shred_arg) { const m_int idx = *(m_int *)MEM(SZ_INT); 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->mp, shred, str); + *(M_Object *)RETURN = new_string(shred->info->vm->gwion, str); } else handle(shred, "InvalidShredArgumentRequest"); } @@ -124,7 +124,7 @@ static MFUN(shred_arg) { static MFUN(shred##name##_name) { \ const VM_Shred s = ME(o); \ const m_str str = code_name((src), 0); \ - *(m_uint *)RETURN = (m_uint)new_string(shred->info->mp, shred, str); \ + *(m_uint *)RETURN = (m_uint)new_string(shred->info->vm->gwion, str); \ } describe_name(, s->info->orig->name) describe_name(_code, s->code->name) @@ -132,7 +132,7 @@ describe_name(, s->info->orig->name) describe_name(_code, s->code->name) static MFUN(shred##name##_path) { \ const VM_Shred s = ME(o); \ const m_str str = code_name((src), 1); \ - *(m_uint *)RETURN = (m_uint)new_string(shred->info->mp, shred, str); \ + *(m_uint *)RETURN = (m_uint)new_string(shred->info->vm->gwion, str); \ } \ static MFUN(shred##name##_dir) { \ const VM_Shred s = ME(o); \ @@ -148,7 +148,7 @@ describe_name(, s->info->orig->name) describe_name(_code, s->code->name) } \ --sz; \ } \ - *(m_uint *)RETURN = (m_uint)new_string(shred->info->mp, shred, c); \ + *(m_uint *)RETURN = (m_uint)new_string(shred->info->vm->gwion, c); \ } describe_path_and_dir(, s->info->orig->name) describe_path_and_dir(_code, s->code->name) diff --git a/src/lib/string.c b/src/lib/string.c index 82b4ea1e..e5a5287b 100644 --- a/src/lib/string.c +++ b/src/lib/string.c @@ -95,7 +95,7 @@ static INSTR(StringSlice) { char c[sz + 1]; 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->mp, shred, c); + *(M_Object *)REG(-SZ_INT) = new_string(shred->info->vm->gwion, c); } static MFUN(string_len) { *(m_uint *)RETURN = strlen(STRING(o)); } @@ -105,7 +105,7 @@ static MFUN(string_upper) { strcpy(c, STRING(o)); 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->mp, shred, c); + *(M_Object *)RETURN = new_string(shred->info->vm->gwion, c); } static MFUN(string_lower) { @@ -113,7 +113,7 @@ static MFUN(string_lower) { strcpy(c, STRING(o)); 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->mp, shred, c); + *(M_Object *)RETURN = new_string(shred->info->vm->gwion, c); } static MFUN(string_ltrim) { @@ -122,7 +122,7 @@ static MFUN(string_ltrim) { while (str[i] == ' ') i++; char c[strlen(str) - i + 1]; strcpy(c, STRING(o) + i); - *(M_Object *)RETURN = new_string(shred->info->mp, shred, c); + *(M_Object *)RETURN = new_string(shred->info->vm->gwion, c); } static MFUN(string_rtrim) { @@ -134,7 +134,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->mp, shred, c); + *(M_Object *)RETURN = new_string(shred->info->vm->gwion, c); } else { ++o->ref; *(M_Object *)RETURN = o; @@ -164,7 +164,7 @@ static MFUN(string_trim) { char c[len - start - end + 1]; for (i = start; i < len - end; i++) c[i - start] = str[i]; c[len - start - end] = '\0'; - *(M_Object *)RETURN = new_string(shred->info->mp, shred, c); + *(M_Object *)RETURN = new_string(shred->info->vm->gwion, c); } static MFUN(string_charAt) { @@ -205,7 +205,7 @@ static MFUN(string_insert) { for (i = 0; i < len_insert; i++) c[i + index] = insert[i]; 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->mp, shred, c); + *(M_Object *)RETURN = new_string(shred->info->vm->gwion, c); ; } @@ -230,7 +230,7 @@ static MFUN(string_replace) { for (i = 0; i < index; i++) c[i] = str[i]; for (i = 0; i < len_insert; i++) c[i + index] = insert[i]; c[index + len_insert] = '\0'; - *(M_Object *)RETURN = new_string(shred->info->mp, shred, c); + *(M_Object *)RETURN = new_string(shred->info->vm->gwion, c); ; } @@ -257,7 +257,7 @@ static MFUN(string_replaceN) { for (i = 0; i < _len; i++) c[i + index] = insert[i]; 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->mp, shred, c); + *(M_Object *)RETURN = new_string(shred->info->vm->gwion, c); ; } @@ -394,7 +394,7 @@ static SFUN(string_load) { rewind(f); (void)fread(c, 1, sz, f); fclose(f); - *(M_Object*)RETURN = new_string2(shred->info->vm->gwion, shred, c); + *(M_Object*)RETURN = new_string(shred->info->vm->gwion, c); } GWION_IMPORT(string) { diff --git a/src/lib/ugen.c b/src/lib/ugen.c index b8b1157e..75933625 100644 --- a/src/lib/ugen.c +++ b/src/lib/ugen.c @@ -95,7 +95,7 @@ describe_compute(mono, , ) describe_compute(multi, , ) } ANEW M_Object new_M_UGen(const struct Gwion_ *gwion) { - const M_Object o = new_object(gwion->mp, NULL, gwion->type[et_ugen]); + const M_Object o = new_object(gwion->mp, gwion->type[et_ugen]); UGEN(o) = new_UGen(gwion->mp); return o; } @@ -159,9 +159,10 @@ ANN void connect_init(const VM_Shred shred, restrict M_Object *lhs, func(&lhs->connect.net->to, (vtype)rhs); \ rhs->connect.net->size = (uint)vector_size(&rhs->connect.net->from); \ } -describe_connect(C, vector_add) describe_connect(Disc, vector_rem2) +describe_connect(C, vector_add) +describe_connect(Disc, vector_rem2) - ANN static void release_connect(const VM_Shred shred) { +ANN static void release_connect(const VM_Shred shred) { *(M_Object *)REG(0) = *(M_Object *)REG(SZ_INT); PUSH_REG(shred, SZ_INT); } diff --git a/src/lib/vararg.c b/src/lib/vararg.c index 3f8210e3..26994c12 100644 --- a/src/lib/vararg.c +++ b/src/lib/vararg.c @@ -53,7 +53,7 @@ static MFUN(mfun_vararg_cpy) { ++(*(M_Object *)(arg->d + offset))->ref; offset += t->size; } - const M_Object obj = new_object(shred->info->mp, shred, o->type_ref); + const M_Object obj = new_object(shred->info->mp, o->type_ref); *(struct Vararg_ **)obj->data = arg; *(m_uint *)(obj->data + SZ_INT * 2) = *(m_uint *)(o->data + SZ_INT * 2); *(m_uint *)(obj->data + SZ_INT * 3) = *(m_uint *)(o->data + SZ_INT * 3); @@ -63,8 +63,7 @@ static MFUN(mfun_vararg_cpy) { } INSTR(VarargIni) { - const M_Object o = new_object(shred->info->mp, shred, - shred->info->vm->gwion->type[et_vararg]); + const M_Object o = new_object(shred->info->mp, shred->info->vm->gwion->type[et_vararg]); struct Vararg_ *arg = mp_calloc(shred->info->mp, Vararg); *(struct Vararg_ **)o->data = arg; POP_REG(shred, instr->m_val - SZ_INT) diff --git a/src/parse/check.c b/src/parse/check.c index 07836089..12e57540 100644 --- a/src/parse/check.c +++ b/src/parse/check.c @@ -1165,7 +1165,7 @@ ANN static inline m_bool for_empty(const Env env, const Stmt_For stmt) { ERR_B(stmt_self(stmt)->pos, _("empty for loop condition..." "...(note: explicitly use 'true' if it's the intent)" - "...(e.g., 'for(; true;){{ /*...*/ }')")) + "...(e.g., 'for(; true;{{ /*...*/ }')")) return GW_OK; } diff --git a/src/vm/vm.c b/src/vm/vm.c index 14dcfe95..6dbc0bfa 100644 --- a/src/vm/vm.c +++ b/src/vm/vm.c @@ -265,7 +265,6 @@ ANN /*static inline */ VM_Shred init_spork_shred(const VM_Shred shred, sh->tick->parent = shred->tick; if (!shred->tick->child.ptr) vector_init(&shred->tick->child); vector_add(&shred->tick->child, (vtype)sh); -// vector_add(&shred->gc, (vtype)sh->info->me); return sh; } @@ -491,7 +490,7 @@ vm_run(const VM *vm) { // lgtm [cpp/use-of-goto] &&dotother, &&dotaddr, &&unioncheck, &&unionint, &&unionfloat, &&unionother, &&unionaddr, &&staticint, &&staticfloat, &&staticother, &&upvalueint, &&upvaluefloat, &&upvalueother, &&upvalueaddr, &&dotfunc, - &&gcini, &&gcadd, &&gcend, &&gacktype, &&gackend, &&gack, &&try_ini, + &&gacktype, &&gackend, &&gack, &&try_ini, &&try_end, &&handleeffect, &&performeffect, &&noop, &&debugline, &&debugvalue, &&debugpush, &&debugpop, &&eoc, &&unroll2, &&other, &®pushimm}; @@ -1071,7 +1070,7 @@ vm_run(const VM *vm) { // lgtm [cpp/use-of-goto] PRAGMA_POP() DISPATCH() newobj: - *(M_Object *)reg = new_object(vm->gwion->mp, NULL, (Type)VAL2); + *(M_Object *)reg = new_object(vm->gwion->mp, (Type)VAL2); reg += SZ_INT; DISPATCH() addref : { @@ -1219,17 +1218,6 @@ vm_run(const VM *vm) { // lgtm [cpp/use-of-goto] *(VM_Code *)(reg + (m_uint)VAL2) = ((Func)(*(M_Object *)(reg - SZ_INT))->vtable.ptr[OFFSET + VAL])->code; DISPATCH() - gcini: - vector_add(&shred->gc, 0); - DISPATCH(); - gcadd: - vector_add(&shred->gc, *(vtype *)(reg + IVAL)); - DISPATCH(); - gcend : { - M_Object o; - while ((o = (M_Object)vector_pop(&shred->gc))) _release(o, shred); - } - DISPATCH() gacktype : { const M_Object o = *(M_Object *)(reg - SZ_INT); if (o) *(Type *)reg = o->type_ref; @@ -1240,7 +1228,7 @@ vm_run(const VM *vm) { // lgtm [cpp/use-of-goto] if (!VAL) gw_out("%s\n", str); else - *(M_Object *)(reg - SZ_INT) = new_string(vm->gwion->mp, shred, str); + *(M_Object *)(reg - SZ_INT) = new_string(vm->gwion, str); if (str) mp_free2(vm->gwion->mp, strlen(str), str); DISPATCH(); } diff --git a/src/vm/vm_shred.c b/src/vm/vm_shred.c index 3e524339..cfbf1dc1 100644 --- a/src/vm/vm_shred.c +++ b/src/vm/vm_shred.c @@ -36,14 +36,10 @@ VM_Shred new_vm_shred(MemPool p, VM_Code c) { shred->reg = (m_bit *)shred + sizeof(struct VM_Shred_); shred->base = shred->mem = shred->reg + SIZEOF_REG; shred->info = new_shredinfo(p, c); - vector_init(&shred->gc); return shred; } void free_vm_shred(VM_Shred shred) { - for (m_uint i = vector_size(&shred->gc) + 1; --i;) - release((M_Object)vector_at(&shred->gc, i - 1), shred); - vector_release(&shred->gc); if (shred->info->frame.ptr) vector_release(&shred->info->frame); if (shred->tick->child.ptr) vector_release(&shred->tick->child); vmcode_remref(shred->info->orig, shred->info->vm->gwion); diff --git a/tests/plug/global_var.c b/tests/plug/global_var.c index 58316cd3..44eeaf2d 100644 --- a/tests/plug/global_var.c +++ b/tests/plug/global_var.c @@ -11,7 +11,7 @@ GWION_IMPORT(global_var_test) { const M_Object o = - new_object(gwi->gwion->mp, NULL, gwi->gwion->type[et_string]); + new_object(gwi->gwion->mp, gwi->gwion->type[et_string]); STRING(o) = s_name(insert_symbol(gwi->gwion->st, "test")); GWI_BB(gwi_item_ini(gwi, "string", "i")) GWI_BB(gwi_item_end(gwi, 0, obj, o)) diff --git a/tests/plug/static_string.c b/tests/plug/static_string.c index 31434bcd..59b24170 100644 --- a/tests/plug/static_string.c +++ b/tests/plug/static_string.c @@ -12,7 +12,7 @@ GWION_IMPORT(static_string_test) { const M_Object o = - new_object(gwi->gwion->mp, NULL, gwi->gwion->type[et_string]); + new_object(gwi->gwion->mp, gwi->gwion->type[et_string]); STRING(o) = s_name(insert_symbol(gwi->gwion->st, "test static string")); GWI_BB(gwi_item_ini(gwi, "string", "self")) GWI_BB(gwi_item_end(gwi, ae_flag_global, obj, o))