From: fennecdjay Date: Fri, 3 May 2024 02:26:47 +0000 (+0200) Subject: On master: some work X-Git-Tag: nightly~19 X-Git-Url: http://10.10.0.4:5575/?a=commitdiff_plain;h=7e090343a5ad370d5133892a77264462ab416bf2;p=gwion.git On master: some work --- 7e090343a5ad370d5133892a77264462ab416bf2 diff --cc include/compile.h index 1ac65032,1ac65032..0e49410a --- a/include/compile.h +++ b/include/compile.h @@@ -1,14 -1,14 +1,14 @@@ #ifndef __COMPILE #define __COMPILE --m_uint compile_filename_values(struct Gwion_ *vm, const m_str filename, MP_Vector*); --m_uint compile_string_values(struct Gwion_ *vm, const m_str filename, -- const m_str data, MP_Vector*); --m_uint compile_file_values(struct Gwion_ *vm, const m_str filename, FILE *file, MP_Vector*); --m_uint compile_filename_xid_values(struct Gwion_ *vm, const m_str filename, ++m_uint compile_filename_values(struct Gwion_ *vm, const char * filename, MP_Vector*); ++m_uint compile_string_values(struct Gwion_ *vm, const char * filename, ++ const char * data, MP_Vector*); ++m_uint compile_file_values(struct Gwion_ *vm, const char * filename, FILE *file, MP_Vector*); ++m_uint compile_filename_xid_values(struct Gwion_ *vm, const char * filename, const m_uint xid, MP_Vector*); --m_uint compile_string_xid_values(struct Gwion_ *vm, const m_str filename, -- const m_str data, const m_uint xid, MP_Vector*); --m_uint compile_file_xid_values(struct Gwion_ *vm, const m_str filename, FILE *file, ++m_uint compile_string_xid_values(struct Gwion_ *vm, const char * filename, ++ const char * data, const m_uint xid, MP_Vector*); ++m_uint compile_file_xid_values(struct Gwion_ *vm, const char * filename, FILE *file, const m_uint xid, MP_Vector*); #define compile_filename(a, b) compile_filename_values(a, b, NULL) #define compile_string(a, b, c) compile_string_values(a, b, c, NULL) diff --cc include/emit.h index 2f1764f8,2f1764f8..83176bb4 --- a/include/emit.h +++ b/include/emit.h @@@ -156,7 -156,7 +156,10 @@@ ANN VM_Code finalyze(const Emitter emit ANN static inline void emit_push_code(const Emitter emit, const m_str name) { vector_add(&emit->stack, (vtype)emit->code); emit->code = new_code(emit, name); -- if (emit->info->debug) emit_add_instr(emit, DebugLine); ++ if (emit->info->debug) { ++ const Instr instr = emit_add_instr(emit, DebugLine); ++ instr->m_val = emit->status.line; ++ } } ANN static inline void emit_pop_code(const Emitter emit) { diff --cc include/env/type.h index be29078a,be29078a..ac4f6208 --- a/include/env/type.h +++ b/include/env/type.h @@@ -50,10 -50,10 +50,9 @@@ struct Type_ m_str name; Nspc nspc; struct TypeInfo_ *info; -- uint64_t size; -- uint64_t actual_size; --// struct Vector_ effects; // pre-ctor effects -- uint32_t array_depth; ++ uint32_t size; ++ uint32_t actual_size; ++ uint32_t array_depth; // TODO: encode in array type uint16_t ref; uint16_t weight; ae_flag flag; diff --cc include/import/tdef.h index 37c9dce1,37c9dce1..9a8707d8 --- a/include/import/tdef.h +++ b/include/import/tdef.h @@@ -4,7 -4,7 +4,7 @@@ ANN bool gwi_typedef_ini(const Gwi gwi, const restrict m_str type, const restrict m_str name); ANN bool gwi_typedef_exp(const Gwi gwi, const restrict m_str data); --ANN Type gwi_typedef_end(const Gwi gwi, const ae_flag flag); ++ANN bool gwi_typedef_end(const Gwi gwi, const ae_flag flag); ANN void ck_clean_tdef(MemPool, ImportCK *); ANN Type mk_primitive(const Env env, const m_str name, const m_uint size); diff --cc include/lang_private.h index 4e7cddc7,4e7cddc7..eb1cc5ae --- a/include/lang_private.h +++ b/include/lang_private.h @@@ -10,6 -10,6 +10,7 @@@ ANN bool gwimport_shred(const Gwi gwi) ANN bool gwimport_event(const Gwi gwi); ANN bool gwimport_ugen(const Gwi gwi); ANN bool gwimport_array(const Gwi gwi); ++ANN bool gwimport_vector(const Gwi gwi); ANN bool gwimport_xork(const Gwi gwi); ANN bool gwimport_modules(const Gwi gwi); ANN bool gwimport_object_op(const Gwi gwi); diff --cc include/opcode.h index e7242335,e7242335..01331e6d --- a/include/opcode.h +++ b/include/opcode.h @@@ -215,7 -215,7 +215,6 @@@ enum ePerformEffect, eNoOp, eDebugLine, -- eDebugValue, eDebugPush, eDebugPop, eEOC, @@@ -437,7 -437,7 +436,6 @@@ #define PerformEffect (f_instr)ePerformEffect #define NoOp (f_instr)eNoOp #define DebugLine (f_instr)eDebugLine --#define DebugValue (f_instr)eDebugValue #define DebugPush (f_instr)eDebugPush #define DebugPop (f_instr)eDebugPop #define EOC (f_instr)eEOC @@@ -1449,10 -1449,10 +1447,6 @@@ ANN static inline void dump_opcodes(con gw_out(" {-R}%-14"UINT_F"{0}", instr->m_val); gw_out("\n"); break; -- case eDebugValue: -- gw_out("{Y}┃{0}{-}% 4lu{0}: DebugValue ", j); -- gw_out("\n"); -- break; case eDebugPush: gw_out("{Y}┃{0}{-}% 4lu{0}: DebugPush ", j); gw_out("\n"); diff --cc include/operator.h index e1f40d4f,e1f40d4f..488b0472 --- a/include/operator.h +++ b/include/operator.h @@@ -77,11 -77,11 +77,11 @@@ ANN bool add_op(const Gwion gwion, con ANN void* op_get(const Env env, struct Op_Import *opi); ANN Type op_check(const Env, struct Op_Import *); ANN bool op_emit(const Emitter, const struct Op_Import *); --ANN bool operator_set_func(const struct Op_Import *); ++ANN bool operator_set_func(const Env, const struct Op_Import *); ANN void free_op_map(Map map, struct Gwion_ *gwion); ANN void free_op_tmpl(Vector v, struct Gwion_ *gwion); --ANN void operator_suspend(const Nspc, struct Op_Import *); ++ANN void operator_suspend(const Gwion, struct Op_Import *); ANN static inline void operator_resume(struct Op_Import *opi) { assert(opi->ret); *(uintptr_t *)opi->ret = opi->data; diff --cc include/vm.h index 115c69ef,115c69ef..251b2821 --- a/include/vm.h +++ b/include/vm.h @@@ -124,6 -124,6 +124,7 @@@ void vm_prepare(const VM *vm, m_bit*) _ ANN static inline void vm_run(const VM *vm) { vm_prepare(vm, NULL); } ++void vm_force_run(const VM *vm); ANN void vm_run_audio(const VM *vm); ANEW VM * new_vm(MemPool, const bool); ANN void vm_lock(VM const *); diff --cc opcode.txt index 25d2cc84,25d2cc84..3a358bf1 --- a/opcode.txt +++ b/opcode.txt @@@ -212,7 -212,7 +212,6 @@@ HandleEffect~p PerformEffect NoOp DebugLine~u --DebugValue DebugPush DebugPop EOC diff --cc src/compile.c index 50ab04e3,50ab04e3..7bb95a7d --- a/src/compile.c +++ b/src/compile.c @@@ -12,11 -12,11 +12,11 @@@ enum compile_type { COMPILE_NAME, COMPILE_MSTR, COMPILE_FILE }; struct Compiler { -- const m_str base; ++ const char *base; m_str name; union { -- m_str data; -- FILE * file; ++ const char* data; ++ FILE * file; }; Ast ast; struct Vector_ args; @@@ -57,7 -57,7 +57,7 @@@ ANN static bool _compiler_open(struct C xfree(name); return c->name ? !!(c->file = fopen(c->name, "r")) : false; } else if (c->type == COMPILE_MSTR) { -- c->file = c->data ? fmemopen(c->data, strlen(c->data), "r") : NULL; ++ c->file = c->data ? fmemopen((void*)c->data, strlen(c->data), "r") : NULL; return !!c->file; } return true; @@@ -114,7 -114,7 +114,7 @@@ ANN static inline bool passes(struct Gw load_context(ctx, env); for(uint32_t i = 0; i < mp_vector_len(c->values); i++) { const Value v = *mp_vector_at(c->values, Value, i); -- set_vflag(v, vflag_builtin); ++ set_vflag(v, vflag_builtin); // TODO: we should copy the values, maybe if(isa(v->type, gwion->type[et_class])) { const Type t = (Type)v->d.ptr; type_addref(t); @@@ -165,24 -165,24 +165,24 @@@ ANN static m_uint compile(struct Gwion return ret; } --ANN m_uint compile_filename_values(struct Gwion_ *gwion, const m_str filename, MP_Vector *values) { ++ANN m_uint compile_filename_values(struct Gwion_ *gwion, const char *filename, MP_Vector *values) { struct Compiler c = {.base = filename, .type = COMPILE_NAME, .values=values}; return compile(gwion, &c); } --ANN m_uint compile_string_values(struct Gwion_ *gwion, const m_str filename, -- const m_str data, MP_Vector *values) { ++ANN m_uint compile_string_values(struct Gwion_ *gwion, const char *filename, ++ const char *data, MP_Vector *values) { struct Compiler c = {.base = filename, .type = COMPILE_MSTR, .data = data, .values=values}; return compile(gwion, &c); } --ANN m_uint compile_file_values(struct Gwion_ *gwion, const m_str filename, ++ANN m_uint compile_file_values(struct Gwion_ *gwion, const char *filename, FILE *file, MP_Vector *values) { struct Compiler c = {.base = filename, .type = COMPILE_FILE, .file = file, .values=values}; return compile(gwion, &c); } --ANN m_uint compile_filename_xid_values(struct Gwion_ *gwion, const m_str filename, ++ANN m_uint compile_filename_xid_values(struct Gwion_ *gwion, const char* filename, const m_uint xid, MP_Vector *values) { struct Compiler c = {.base = filename, .type = COMPILE_NAME, .values=values}; if (!compile(gwion, &c)) return 0; @@@ -190,8 -190,8 +190,8 @@@ return c.shred->tick->xid = xid; } --ANN m_uint compile_string_xid_values(struct Gwion_ *gwion, const m_str filename, -- const m_str data, const m_uint xid, MP_Vector *values) { ++ANN m_uint compile_string_xid_values(struct Gwion_ *gwion, const char *filename, ++ const char *data, const m_uint xid, MP_Vector *values) { struct Compiler c = {.base = filename, .type = COMPILE_MSTR, .data = data, .values=values}; if (!compile(gwion, &c)) return 0; assert(c.shred); @@@ -199,7 -199,7 +199,7 @@@ return c.shred->tick->xid = xid; } --ANN m_uint compile_file_xid_values(struct Gwion_ *gwion, const m_str filename, ++ANN m_uint compile_file_xid_values(struct Gwion_ *gwion, const char * filename, FILE *file, const m_uint xid, MP_Vector *values) { struct Compiler c = {.base = filename, .type = COMPILE_FILE, .file = file, .values=values}; if (!compile(gwion, &c)) return 0; diff --cc src/emit/emit.c index 20e18472,20e18472..d1d1642d --- a/src/emit/emit.c +++ b/src/emit/emit.c @@@ -55,11 -55,11 +55,6 @@@ static inline m_uint emit_push_global(c return env_push_global(emit->env); } --static inline void emit_debug(const Emitter emit, const Value v) { -- if (!emit->info->debug) return; -- const Instr instr = emit_add_instr(emit, DebugValue); -- instr->m_val = (m_uint)v; --} ANEW static Frame *new_frame(MemPool p) { Frame *frame = mp_calloc(p, Frame); @@@ -260,7 -260,7 +255,12 @@@ ANN void emit_pop_scope(const Emitter e ANN void emit_push_scope(const Emitter emit) { frame_push(emit->code->frame); vector_add(&emit->info->pure, 0); -- if (emit->info->debug) emit_add_instr(emit, DebugPush); ++ //if (emit->info->debug) emit_add_instr(emit, DebugPush); ++ if (emit->info->debug) { ++ ++ const Instr instr = emit_add_instr(emit, DebugPush); ++ instr->m_val = emit->status.line; ++ } } ANN m_uint emit_code_offset(const Emitter emit) { @@@ -978,15 -978,15 +978,22 @@@ static INSTR(UsedBy) const MP_Vector *v =(MP_Vector*)instr->m_val; for(uint32_t i = 0; i < v->len; i++) { const Func f = *mp_vector_at(v, Func, i); -- const Instr instr = (Instr)vector_front(&f->code->instr); -- instr->m_val2++; ++ for(m_uint j = 0; i < vector_size(&f->code->instr); j++) { ++ const Instr instr = (Instr)vector_at(&f->code->instr, j); ++ if(instr->execute == FuncWait) { ++ instr->m_val2++; ++ break; ++ } ++ } } } ANN static void used_by(const Emitter emit, const Value v) { ++puts("emit used by"); MP_Vector *vec = new_mp_vector(emit->gwion->mp, Func, 0); for(uint32_t i = 0; i < v->used_by->len; i++) { const Func f = *mp_vector_at(v->used_by, Func, i); ++ if(f->_wait) puts("Adding to wait list"); if(f->_wait) mp_vector_add(emit->gwion->mp, &vec, Func, f); } free_mp_vector(emit->gwion->mp, Func, v->used_by); @@@ -1010,7 -1010,7 +1017,6 @@@ ANN static bool emit_exp_decl_non_stati else CHECK_B(emit_exp(emit, decl->args)); } f_instr *exec = (f_instr *)allocmember; -- if (!emit->env->scope->depth) emit_debug(emit, v); if (!vflag(v, vflag_member)) { if(v->used_by) used_by(emit, v); v->from->offset = decl_non_static_offset(emit, decl, type); @@@ -1915,10 -1915,10 +1921,15 @@@ DECL_EXP_FUNC(emit, bool, Emitter ANN2(1) /*static */ bool emit_exp(const Emitter emit, /* const */ Exp* e) { Exp* exp = e; do { -- if (emit->info->debug && emit->status.line < e->loc.first.line) { ++ if (emit->info->debug){ ++ ++printf("debug line: %i\n", e->loc.first.line); ++ if(emit->status.line < e->loc.first.line) { const Instr instr = emit_add_instr(emit, DebugLine); instr->m_val = emit->status.line = e->loc.first.line; } ++ emit->status.line = e->loc.first.line; ++ } CHECK_B(emit_exp_func[exp->exp_type](emit, &exp->d)); if (exp->cast_to) CHECK_B(emit_implicit_cast(emit, exp, exp->cast_to)); if (is_object(emit->gwion, exp->type) && @@@ -2207,12 -2207,12 +2218,10 @@@ ANN static bool _emit_stmt_each(const E stmt->var.value->from->offset = val_offset; //value_addref(stmt->v); _nspc_add_value(emit->env->curr, stmt->var.tag.sym, stmt->var.value); -- emit_debug(emit, stmt->var.value); if (stmt->idx.tag.sym) { stmt->idx.value->from->offset = key_offset; _nspc_add_value(emit->env->curr, stmt->idx.tag.sym, stmt->var.value); //value_addref(stmt->idx->v); -- emit_debug(emit, stmt->idx.value); } struct Looper loop = {.exp = stmt->exp, .stmt = stmt->body, @@@ -2606,6 -2606,6 +2615,7 @@@ ANN static bool emit_exp_dot(const Emit ANN static inline void emit_func_def_init(const Emitter emit, const Func func) { emit_push_code(emit, func->name); if(mp_vector_len(func->_wait)) { ++puts("wait"); const Instr instr = emit_add_instr(emit, FuncWait); instr->m_val = (m_uint) func; } @@@ -2617,7 -2617,7 +2627,6 @@@ ANN static void emit_func_def_args(cons const Type type = arg->var.vd.value->type; emit->code->stack_depth += type->size; arg->var.vd.value->from->offset = emit_localn(emit, type); -- emit_debug(emit, arg->var.vd.value); _nspc_add_value(emit->env->curr, insert_symbol(arg->var.vd.value->name), arg->var.vd.value); } } diff --cc src/emit/emitter.c index 1658f36a,1658f36a..d61d3ca5 --- a/src/emit/emitter.c +++ b/src/emit/emitter.c @@@ -52,7 -52,7 +52,7 @@@ emit_add_instr(const Emitter emit, cons ANN2(1) void emit_fast_except(const Emitter emit, const ValueFrom *vf, const loc_t loc) { const Instr instr = emit_add_instr(emit, fast_except); -- if(vf) { ++ if(!emit->info->debug && vf) { struct FastExceptInfo *info = mp_malloc2(emit->gwion->mp, sizeof(struct FastExceptInfo)); info->file = emit->env->name; info->loc = loc; diff --cc src/emit/escape.c index d7bb0e41,d7bb0e41..8454c978 --- a/src/emit/escape.c +++ b/src/emit/escape.c @@@ -6,7 -6,7 +6,7 @@@ #include "emit.h" #include "escape.h" --char escape_table[256] = { ++static char escape_table[256] = { ['0'] = '0', ['\''] = '\'', ['"'] = '"', @@@ -63,7 -63,7 +63,8 @@@ bool escape_str(const Emitter emit, con } } else { char out; -- CHECK_B((*str++ = (char)get_escape(emit, (char)c, &out, loc))); ++ CHECK_B(get_escape(emit, (char)c, &out, loc)); ++ *str++ = out; } } else *str++ = (char)*str_lit; diff --cc src/env/env_utils.c index 4c59b492,8860af6a..a328dc44 --- a/src/env/env_utils.c +++ b/src/env/env_utils.c @@@ -57,10 -57,22 +57,23 @@@ ANN Type find_initial(const Env env, co ANN Type find_type(const Env env, Type_Decl *td) { DECL_O(Type, type, = find_initial(env, td->tag.sym)); while ((td = td->next) && type && type->nspc) { -- const Nspc nspc = type->nspc; -- if(!(type = find_in_parent(type, td->tag.sym))) - ERR_O(td->tag.loc, _("...(cannot find class '%s' in nspc '%s')"), -s_name(td->tag.sym), nspc->name); ++// const Nspc nspc = type->nspc; ++// if(!(type = find_in_parent(type, td->tag.sym))) ++// ++ //enERR_O(td->tag.loc, _("...(cannot find class '%s' in nspc '%s')"), ++//s_name(td->tag.sym), nspc->name); ++ + -/* - if(!type) - ERR_O(td->tag.loc, _("...(cannot find class '%s' in nspc '%s')"), - s_name(td->tag.sym), nspc->name); + Type_Decl *next = td->next; + td->next = NULL; + env_push_type(env, type); + type = known_type(env, td); ++ if(!type) + ERR_O(td->tag.loc, _("...(cannot find class '%s' in nspc '%s')"), - s_name(td->tag.sym), nspc->name); ++ s_name(td->tag.sym), env->class_def->name); + env_pop(env, 0); // respect scope depth // use env scope + td->next = next; -*/ ++ } return type; } diff --cc src/env/func.c index 54e9dc32,54e9dc32..f5556215 --- a/src/env/func.c +++ b/src/env/func.c @@@ -61,6 -61,6 +61,7 @@@ ANN void builtin_func(const Gwion gwion ANN void print_signature(const Gwion gwion, const Func f) { struct GwfmtState ls = {.minimize=true, .ppa = gwion->ppa}; ++// gwfmt_state_init(&ls); text_init(&ls.text, gwion->mp); Gwfmt l = {.mp = gwion->mp, .st = gwion->st, .ls = &ls, .line = 1, .last = cht_nl }; gwfmt_func_def(&l, f->def); diff --cc src/import/import_cdef.c index d453bf9c,d453bf9c..73affeb7 --- a/src/import/import_cdef.c +++ b/src/import/import_cdef.c @@@ -151,5 -151,5 +151,5 @@@ ANN bool gwi_class_end(const Gwi gwi) } */ env_pop(gwi->gwion->env, 0); -- return false; ++ return true; } diff --cc src/import/import_checker.c index c552d696,5cfdee98..e299f5c0 --- a/src/import/import_checker.c +++ b/src/import/import_checker.c @@@ -338,6 -359,6 +359,7 @@@ ANEW ANN m_str type2str(const Gwion gwi ANEW ANN m_str tl2str(const Gwion gwion, const TmplArg_List tl, const loc_t loc NUSED) { struct GwfmtState ls = {.minimize=true, .ppa = gwion->ppa}; ++// gwfmt_state_init(&ls); text_init(&ls.text, gwion->mp); Gwfmt l = {.mp = gwion->mp, .st = gwion->st, .ls = &ls, .line = 1, .last = cht_nl }; struct td_info info = {.tl = tl, .fmt = &l }; diff --cc src/import/import_internals.c index e64bf591,e64bf591..a4a00cd7 --- a/src/import/import_internals.c +++ b/src/import/import_internals.c @@@ -31,6 -31,6 +31,7 @@@ ANN void gwi_reset(const Gwi gwi) ANN static bool run_with_doc(const Gwi gwi, bool (*f)(const Gwi)) { struct GwfmtState ls = {.builtin = true, .nindent = 4}; ++// gwfmt_state_init(&ls); text_init(&ls.text, gwi->gwion->mp); Gwfmt gwfmter = {.mp = gwi->gwion->mp, .ls = &ls, .st = gwi->gwion->st }; gwfmt_indent(&gwfmter); diff --cc src/import/import_tdef.c index f6e713d0,b26c3635..0cdbe664 --- a/src/import/import_tdef.c +++ b/src/import/import_tdef.c @@@ -25,7 -25,7 +25,7 @@@ ANN bool gwi_typedef_exp(const Gwi gwi return true; } --ANN Type gwi_typedef_end(const Gwi gwi, const ae_flag flag) { ++ANN bool gwi_typedef_end(const Gwi gwi, const ae_flag flag) { CHECK_O(ck_ok(gwi, ck_tdef)); Type_Decl *td = gwi->ck->td; td->flag |= flag; @@@ -33,6 -33,16 +33,16 @@@ new_type_def(gwi->gwion->mp, td, gwi->ck->sym, gwi->loc); if (gwi->ck->when) tdef->when = gwi->ck->when; if (gwi->ck->tmpl) tdef->tmpl = gwi_tmpl(gwi); + + if (safe_tflag(gwi->gwion->env->class_def, tflag_tmpl)) { + Section section = MK_SECTION( + type, type_def, tdef, gwi->loc + ); + gwi_body(gwi, §ion); + ck_end(gwi); - return 1; ++ return true; + } + gwi->ck->td = NULL; gwi->ck->tmpl = NULL; const bool ret = traverse_type_def(gwi->gwion->env, tdef); @@@ -46,7 -56,7 +56,7 @@@ tflag_emit); free_type_def(gwi->gwion->mp, tdef); ck_end(gwi); -- return ret ? t : NULL; ++ return ret; } ANN void ck_clean_tdef(MemPool mp, ImportCK *ck) { diff --cc src/lib/engine.c index eb400aba,42e1aa02..a77d0ad2 --- a/src/lib/engine.c +++ b/src/lib/engine.c @@@ -91,7 -91,7 +91,7 @@@ ANN static bool import_core_libs(const set_tflag(t_time, tflag_float); gwidoc(gwi, "internal time for `{/}now{0}{-}`."); -- const Type t_now = gwi_mk_type(gwi, "@now", SZ_FLOAT, "time"); ++ const Type t_now = gwi_mk_type(gwi, "Now", SZ_FLOAT, "time"); GWI_B(gwi_add_type(gwi, t_now)) struct SpecialId_ spid = {.type = t_now, .exec = RegPushNow, .is_const = 1}; gwi_specialid(gwi, "now", &spid); @@@ -118,8 -119,9 +119,8 @@@ GWI_B(gwimport_object_op(gwi)) GWI_B(gwimport_values(gwi)) GWI_B(gwimport_union(gwi)) -- GWI_B(gwimport_array(gwi)) + GWI_B(gwimport_vector(gwi)) GWI_B(gwimport_event(gwi)) GWI_B(gwimport_ugen(gwi)) GWI_B(gwimport_xork(gwi)) diff --cc src/lib/event.c index 83df7b3e,83df7b3e..50ed3534 --- a/src/lib/event.c +++ b/src/lib/event.c @@@ -59,7 -59,7 +59,7 @@@ GWION_IMPORT(event) GWI_B(gwi_func_ini(gwi, "void", "broadcast")) GWI_B(gwi_func_end(gwi, event_broadcast, ae_flag_none)) GWI_B(gwi_class_end(gwi)) -- GWI_B(gwi_oper_ini(gwi, "Event", "@now", "int")) ++ GWI_B(gwi_oper_ini(gwi, "Event", "Now", "int")) GWI_B(gwi_oper_end(gwi, "=>", EventWait)) return true; } diff --cc src/lib/instr.c index 97e68acd,97e68acd..69db6200 --- a/src/lib/instr.c +++ b/src/lib/instr.c @@@ -134,6 -134,6 +134,8 @@@ INSTR(SetFunc) shred->reg += SZ_INT; } ++// TODO: do not add info in debug mode ++// maybe INSTR(FuncWait) { const Func f = (Func)instr->m_val; if(f->_wait->len - instr->m_val2) { diff --cc src/lib/prim.c index 32eaad49,32eaad49..ebb41be3 --- a/src/lib/prim.c +++ b/src/lib/prim.c @@@ -518,7 -518,7 +518,7 @@@ static GWION_IMPORT(time) GWI_B(gwi_oper_ini(gwi, "dur", "time", "time")) CHECK_FF(":=>", rassign, r_assign) GWI_B(gwi_oper_end(gwi, "+", float_add)) -- GWI_B(gwi_oper_ini(gwi, "dur", "@now", "time")) ++ GWI_B(gwi_oper_ini(gwi, "dur", "Now", "time")) _CHECK_OP("=>", now, Dur_Advance) GWI_B(gwi_oper_ini(gwi, "time", "time", "bool")) GWI_B(gwi_oper_end(gwi, "=>", Time_Advance)) diff --cc src/parse/check.c index 11a36191,11a36191..93751c43 --- a/src/parse/check.c +++ b/src/parse/check.c @@@ -423,7 -423,7 +423,7 @@@ ANN static Type prim_id_non_res(const E if (env->func && strcmp(env->func->name, "in spork")) { // if(vflag(v, vflag_fglobal) /*&& !vflag(v, vflag_builtin) */&& !is_func(env->gwion, v->type)) { -- if((GET_FLAG(v, global) || vflag(v, vflag_fglobal)) && !vflag(v, vflag_builtin) && !is_func(env->gwion, v->type)) { ++ if(GET_FLAG(v, global) && !vflag(v, vflag_builtin) && !is_func(env->gwion, v->type)) { if(!env->func->_wait) env->func->_wait = new_mp_vector(env->gwion->mp, Value, 0); if (!v->used_by) { @@@ -1977,7 -1977,7 +1977,7 @@@ ANN bool _check_func_def(const Env env struct Op_Import opi = {}; if (fbflag(fdef->base, fbflag_op)) { func_operator(f, &opi); -- operator_suspend(env->curr, &opi); ++ operator_suspend(env->gwion, &opi); } if(fdef->captures) { uint32_t offset = fdef->stack_depth; @@@ -2246,8 -2246,8 +2246,7 @@@ ANN static bool check_class_tmpl(const const Value v = new_value(env, targ.d.exp->type, MK_TAG(spec.tag.sym, targ.d.exp->loc)); valuefrom(env, v->from); set_vflag(v, vflag_valid); -- //nspc_add_value(nspc, spec.tag.sym, v); -- nspc_add_value_front(t->nspc, spec.tag.sym, v); ++ nspc_add_value(t->nspc, spec.tag.sym, v); SET_FLAG(v, const| ae_flag_static); set_vflag(v, vflag_builtin); } @@@ -2282,7 -2282,7 +2281,8 @@@ ANN static bool _check_class_def(const } ANN bool check_class_def(const Env env, const Class_Def cdef) { -- if (tmpl_base(cdef->base.tmpl)) return true; ++ if (tmpl_base(cdef->base.tmpl)) ++ return true; const Type t = cdef->base.type; if (tflag(t, tflag_check)) return true; set_tflag(t, tflag_check); diff --cc src/parse/operator.c index 3ee1a120,3ee1a120..c1ac396e --- a/src/parse/operator.c +++ b/src/parse/operator.c @@@ -79,7 -79,7 +79,30 @@@ static M_Operator *operator_find2(cons return NULL; } --ANN void operator_suspend(const Nspc n, struct Op_Import *opi) { ++ANN Nspc get_nspc(const Env env) { ++ if(SAFE_FLAG(env->func, private)) // how come ++ return env->curr; ++ Type t = env->class_def; ++ while (t) { ++ if(GET_FLAG(t, private)) ++ return t->nspc; ++ t = t->info->value->from->owner_class; ++ } ++ // does not take global into account tho ++ // or does it? ++ if(env->curr == env->global_nspc) ++ return env->curr; ++ return env->context ++ ? env->context->nspc ++ : env->curr; ++} ++ ++// 1st arg could be Env ++ANN void operator_suspend(const Gwion gwion, struct Op_Import *opi) { ++ // Nspc n = gwion->env->context ++ // ? gwion->env->context->nspc ++ // : gwion->env->curr; ++ const Nspc n = get_nspc(gwion->env); const m_int idx = map_index(&n->operators->map, (vtype)opi->op); const Vector v = (Vector)&VVAL(&n->operators->map, idx); for (m_uint i = vector_size(v) + 1; --i;) { @@@ -149,12 -149,12 +172,16 @@@ ANN bool add_op(const Gwion gwion, cons CHECK_B(op_exist(&ock, n)); } } while ((n = n->parent)); -- if (!gwion->env->curr->operators) -- gwion->env->curr->operators = mp_calloc(gwion->mp, NspcOp); -- if (!gwion->env->curr->operators->map.ptr) -- map_init(&gwion->env->curr->operators->map); ++ // Nspc nspc = gwion->env->context ++ // ? gwion->env->context->nspc ++ // : gwion->env->curr; ++ const Nspc nspc = get_nspc(gwion->env); ++ if (!nspc->operators) ++ nspc->operators = mp_calloc(gwion->mp, NspcOp); ++ if (!nspc->operators->map.ptr) ++ map_init(&nspc->operators->map); struct OpChecker ock = { -- .env = gwion->env, .map = &gwion->env->curr->operators->map, .opi = opi}; ++ .env = gwion->env, .map = &nspc->operators->map, .opi = opi}; const Vector v = op_vector(&ock); const M_Operator *mo = new_mo(gwion->mp, opi); vector_add(v, (vtype)mo); @@@ -351,7 -351,7 +378,7 @@@ ANN Type op_check(const Env env, struc if (!strcmp(op, "$") && opi->rhs == opi->lhs) return opi->rhs; if (!strcmp(op, "@func_check")) return NULL; -- if(!strcmp(op, "=>") && !strcmp(opi->rhs->name, "@now")) { ++ if(!strcmp(op, "=>") && !strcmp(opi->rhs->name, "Now")) { gwlog_error(_("no match found for operator"), "expected duration", env->name, opi->loc, 0); gwlog_hint(_("did you try converting to `dur`?"), env->name, opi->loc); env_set_error(env, true); @@@ -367,8 -367,8 +394,10 @@@ return NULL; } --ANN bool operator_set_func(const struct Op_Import *opi) { -- const Nspc nspc = ((Func)opi->data)->value_ref->from->owner; ++ANN bool operator_set_func(const Env env, const struct Op_Import *opi) { ++ //const Nspc nspc = ((Func)opi->data)->value_ref->from->owner; ++ //const Nspc nspc = ((Func)opi->data)->value_ref->from->ctx->nspc; ++ const Nspc nspc = get_nspc(env); const m_int idx = map_index(&nspc->operators->map, (vtype)opi->op); const Vector v = (Vector)&VVAL(&nspc->operators->map, idx); DECL_B(M_Operator *, mo, = operator_find(v, opi->lhs, opi->rhs)); diff --cc src/parse/scan2.c index 9ed2f744,9ed2f744..dcf6c5d9 --- a/src/parse/scan2.c +++ b/src/parse/scan2.c @@@ -414,7 -414,7 +414,7 @@@ ANN static bool scan2_func_def_op(cons .func = &opfunc}; func_operator(f, &opi); CHECK_B(add_op(env->gwion, &opi)); -- operator_set_func(&opi); ++ operator_set_func(env, &opi); return true; } diff --cc src/parse/type_decl.c index 6efaa75d,6efaa75d..cc0da546 --- a/src/parse/type_decl.c +++ b/src/parse/type_decl.c @@@ -120,6 -120,6 +120,7 @@@ ANN static Type resolve(const Env env, ANN m_str tdpp(MemPool mp, SymTable *st, const Type_Decl *td, const bool no_color, const bool minimize) { struct GwfmtState ls = { .minimize = minimize,}; ++// gwfmt_state_init(&ls); text_init(&ls.text, mp); Gwfmt gwfmter = {.mp = mp, .ls = &ls, .st = st }; bool has_color = tcol_has_color(); diff --cc src/vm/vm.c index 7c8c7800,7c8c7800..624241ba --- a/src/vm/vm.c +++ b/src/vm/vm.c @@@ -120,8 -120,8 +120,12 @@@ ANN static void trace(VM_Shred shred, c } loc_t loc = {.first = {.line = line, .column = 1}, .last = {.line = line, .column = 1}}; -- gwlog_related("called from here", code_name(shred->code->name, true), loc); -- gw_err(" {M}┗━╸{0} {-}in code{0} {+W}%s{0}{-}:{0}\n", shred->code->name); ++ char *filename = strrchr(shred->code->name, '@'); ++ char *better_name = filename ? filename + 1: code_name(shred->code->name, true); ++ puts(better_name); ++ //gwlog_related("called from here", code_file(shred->code->name, true), loc); ++ gwlog_related("called from here", better_name, loc); ++ gw_err(" {+B}┗━╸{0} {-}in code{0} {+W}%s{0}{-}:{0}\n", better_name); if (shred->mem == (m_bit *)shred + sizeof(struct VM_Shred_) + SIZEOF_REG) return; shred_unwind(shred); @@@ -474,7 -474,7 +478,7 @@@ vm_prepare(const VM *vm, m_bit *prepare &&unionother, &&unionaddr, &&staticint, &&staticfloat, &&staticother, &&dotfunc, &&gacktype, &&gackend, &&gack, &&try_ini, &&try_end, &&handleeffect, &&performeffect, &&noop, &&debugline, -- &&debugvalue, &&debugpush, &&debugpop, &&eoc, &&vmin, &&other}; ++ &&debugpush, &&debugpop, &&eoc, &&vmin, &&other}; // &®pushimm}; if(!prepare_code) { @@@ -1294,8 -1294,8 +1298,6 @@@ DISPATCH() vector_set(&shred->info->line, sz - 1, VAL); } DISPATCH(); -- debugvalue: -- DISPATCH(); debugpush: if (!shred->info->line.ptr) vector_init(&shred->info->line); vector_add(&shred->info->line, 0); @@@ -1362,7 -1362,7 +1364,7 @@@ static void *_dispatch[] = &&_unionother, &&_unionaddr, &&_staticint, &&_staticfloat, &&_staticother, &&_dotfunc, &&_gacktype, &&_gackend, &&_gack, &&_try_ini, &&_try_end, &&_handleeffect, &&_performeffect, &&_noop, &&_debugline, -- &&_debugvalue, &&_debugpush, &&_debugpop, &&_eoc, &&_vmin, &&_other}; ++ &&_debugpush, &&_debugpop, &&_eoc, &&_vmin, &&_other}; #define PREPARE(a) \ _##a: \ @@@ -1625,7 -1625,7 +1627,6 @@@ _other } PREPARE(vmin); PREPARE(debugline); -- PREPARE(debugvalue); PREPARE(debugpush); PREPARE(debugpop); _eoc: @@@ -1654,6 -1654,6 +1655,12 @@@ ANN void vm_run_audio(const VM *vm) compute_audio(vm); } ++void vm_force_run(const VM *vm) { ++ const bool is_running = vm->shreduler->bbq->is_running; ++ vm_run(vm); ++ vm->shreduler->bbq->is_running = is_running; ++} ++ VM *new_vm(MemPool p, const bool audio) { VM *vm = (VM *)mp_calloc(p, VM); vector_init(&vm->ugen);