From 9473e84bc75eebde1d60b38e2bfb56b898f9c884 Mon Sep 17 00:00:00 2001 From: fennecdjay Date: Wed, 17 Aug 2022 20:10:02 +0200 Subject: [PATCH] :art: Few improvements --- include/env/envset.h | 12 ------------ src/emit/emit.c | 11 +++++------ src/env/envset.c | 18 ++++++++---------- src/gwion.c | 1 - src/lib/array.c | 2 ++ src/lib/closure.c | 4 ++-- src/lib/instr.c | 9 --------- src/lib/object_op.c | 2 +- src/lib/shred.c | 3 ++- src/lib/string.c | 3 --- src/parse/check.c | 6 +++++- src/parse/func_resolve_tmpl.c | 2 +- src/parse/scan1.c | 7 +++++++ src/parse/template.c | 2 +- 14 files changed, 34 insertions(+), 48 deletions(-) diff --git a/include/env/envset.h b/include/env/envset.h index 2c02d912..3bec88e0 100644 --- a/include/env/envset.h +++ b/include/env/envset.h @@ -19,16 +19,4 @@ ANN static inline m_bool envset_pushv(struct EnvSet *es, const Value v) { return envset_push(es, v->from->owner_class, v->from->owner); } ANN2(1) void envset_pop(struct EnvSet *, const Type); - -ANN static inline m_bool extend_push(const Env env, const Type t) { - const Type owner = t->info->value->from->owner_class; - if (owner) CHECK_BB(extend_push(env, owner)); - return env_push_type(env, t); -} - -ANN static inline void extend_pop(const Env env, const Type t) { - env_pop(env, 0); - const Type owner = t->info->value->from->owner_class; - if (owner) extend_pop(env, owner); -} #endif diff --git a/src/emit/emit.c b/src/emit/emit.c index 422b8f07..320b515d 100644 --- a/src/emit/emit.c +++ b/src/emit/emit.c @@ -900,7 +900,7 @@ ANN static m_bool emit_prim_locale(const Emitter emit, const Symbol *id) { const VM_Code code = finalyze(emit, EOC); const VM_Shred shred = new_vm_shred(emit->gwion->mp, code); vm_add_shred(emit->gwion->vm, shred); -// shred->info->me->ref++; + shred->info->me->ref++; vm_run(emit->gwion->vm); emit->gwion->vm->bbq->is_running = true; const m_float ret = *(m_float*)shred->reg; @@ -1408,13 +1408,12 @@ ANN m_bool traverse_dot_tmpl(const Emitter emit, const Func_Def fdef, const Valu .func = (_exp_func)emit_cdef, .scope = scope, .flag = tflag_emit}; - CHECK_BB(envset_push(&es, v->from->owner_class, v->from->owner)); + CHECK_BB(envset_pushv(&es, v)); (void)emit_push(emit, v->from->owner_class, v->from->owner); const m_bool ret = traverse_emit_func_def(emit, fdef); - if (es.run) envset_pop(&es, v->from->owner_class); emit_pop(emit, scope); + envset_pop(&es, v->from->owner_class); emit->env->scope->shadowing = shadowing; - if(ret > 0) set_fflag(fdef->base->func, fflag_tmpl); return ret; } @@ -1458,7 +1457,7 @@ ANN static m_bool emit_template_code(const Emitter emit, const Func f) { CHECK_BB(envset_pushv(&es, v)); (void)emit_push(emit, v->from->owner_class, v->from->owner); const m_bool ret = emit_func_def(emit, f->def); - if (es.run) envset_pop(&es, v->from->owner_class); + envset_pop(&es, v->from->owner_class); emit_pop(emit, scope); return ret > 0 ? push_func_code(emit, f) : GW_ERROR; } @@ -1932,7 +1931,7 @@ ANN static m_bool emit_exp_lambda(const Emitter emit, .flag = tflag_emit}; CHECK_BB(envset_pushv(&es, lambda->def->base->func->value_ref)); const m_bool ret = emit_lambda(emit, lambda); - if (es.run) envset_pop(&es, lambda->owner); + envset_pop(&es, lambda->owner); return ret; } diff --git a/src/env/envset.c b/src/env/envset.c index ac0d37b1..699c4d08 100644 --- a/src/env/envset.c +++ b/src/env/envset.c @@ -6,6 +6,8 @@ #include "template.h" ANN static void check(struct EnvSet *es, const Type t) { + es->_ctx = es->env->context; + es->_filename = es->env->name; const Vector v = &es->env->scope->class_stack; Type owner = t->info->value->from->owner_class; for (vtype i = vector_size(v) + 1; owner && --i;) { @@ -26,16 +28,10 @@ ANN static m_bool push(struct EnvSet *es, const Type t) { env_push(es->env, NULL, t->info->value->from->ctx ? t->info->value->from->ctx->nspc : es->env->curr); - if (es->func && !(t->tflag & es->flag)) - CHECK_BB(es->func((void *)es->data, t)); - env_push_type((void *)es->env, t); + env_push_type((void *)es->env, t); // do not push if is a function? if (tflag(t, tflag_tmpl)) CHECK_BB(template_push_types( es->env, t->info->cdef->base.tmpl)); // incorrect templates? - es->_ctx = es->env->context; - es->_filename = es->env->name; - es->env->context = t->info->value->from->ctx; - es->env->name = t->info->value->from->filename; return GW_OK; } @@ -67,19 +63,21 @@ ANN2(1) static void _envset_pop(struct EnvSet *es, const Type t) { } ANN2(1) void envset_pop(struct EnvSet *es, const Type t) { - _envset_pop(es, t); + if(es->run) _envset_pop(es, t); // if(t && type_global(es->env, t)) // env_pop(es->env, es->scope); if (es->_ctx) es->env->context = es->_ctx; - if (es->_filename) es->env->name = es->_filename; + if (es->_filename) es->env->name = es->_filename; } ANN m_bool envset_run(struct EnvSet *es, const Type t) { check(es, t); const Type owner_class = t->info->value->from->owner_class; if (es->run) CHECK_BB(push(es, owner_class)); + es->env->context = t->info->value->from->ctx; + es->env->name = t->info->value->from->filename; const m_bool ret = t->info->cdef && !(t->tflag & es->flag) ? es->func(es->data, t) : GW_OK; - if (es->run) envset_pop(es, owner_class); + envset_pop(es, owner_class); return ret; } diff --git a/src/gwion.c b/src/gwion.c index 97a74fbf..4dfb87ad 100644 --- a/src/gwion.c +++ b/src/gwion.c @@ -244,7 +244,6 @@ ANN void push_global(struct Gwion_ *gwion, const m_str name) { ANN void pop_global(const Gwion gwion) { Nspc nspc = gwion->env->global_nspc->parent; -// Nspc nspc = gwion->env->global_nspc, parent; while (nspc) { const Nspc parent = nspc->parent; nspc_remref(nspc, gwion); diff --git a/src/lib/array.c b/src/lib/array.c index acf06cdf..9a535caf 100644 --- a/src/lib/array.c +++ b/src/lib/array.c @@ -715,12 +715,14 @@ static OP_CHECK(opck_array_scan) { env_set_error(env, true); return env->gwion->type[et_error]; } +/* if (!strncmp(base->name, "Option:[", 5)) { gwerr_basic("Can't use option types as array base", NULL, NULL, "/dev/null", (loc_t) {}, 0); env_set_error(env, true); return env->gwion->type[et_error]; } +*/ const Symbol sym = array_sym(env, array_base_simple(base), base->array_depth + 1); const Type type = nspc_lookup_type1(base->info->value->from->owner, sym); if (type) return type; diff --git a/src/lib/closure.c b/src/lib/closure.c index b6c68634..7b62ef64 100644 --- a/src/lib/closure.c +++ b/src/lib/closure.c @@ -357,7 +357,7 @@ ANN static m_bool _check_lambda(const Env env, Exp_Lambda *l, nspc_pop_type(env->gwion->mp, env->curr); owner = owner->info->value->from->owner_class; } - if (es.run) envset_pop(&es, owner); + envset_pop(&es, owner); if(ret < 0) { if(args) { for(uint32_t i = 0; i < bases->len; i++) { @@ -703,7 +703,7 @@ static OP_CHECK(opck_closure_scan) { CHECK_BO(envset_pushv(&es, owner->info->value)); const m_bool ret = traverse_fptr_def(env, fdef); const Type t = ret > 0 ? fdef->cdef->base.type : NULL; - if (es.run) envset_pop(&es, owner->info->value->from->owner_class); + envset_pop(&es, owner->info->value->from->owner_class); free_fptr_def(env->gwion->mp, fdef); // clean? if(t) set_tflag(t, tflag_emit); return t; diff --git a/src/lib/instr.c b/src/lib/instr.c index 328a57d5..2d8411e8 100644 --- a/src/lib/instr.c +++ b/src/lib/instr.c @@ -115,17 +115,8 @@ INSTR(DotTmpl) { *(VM_Code *)(shred->reg - SZ_INT) = f->code; return; } - const Emitter emit = shred->info->vm->gwion->emit; const struct dottmpl_ *dt = (struct dottmpl_*)instr->m_val2; - struct EnvSet es = {.env = emit->env, - .data = emit, -// .func = (_exp_func)emit_cdef, - .func = (_exp_func)dummy_func, - .scope = 0, - .flag = tflag_emit}; - if(envset_push(&es, dt->type, dt->nspc) < 0) return; foo(shred, o->type_ref, fbase, dt->tmpl_name); - if (es.run) envset_pop(&es, dt->type); } #define VAL (*(m_uint *)(byte + SZ_INT)) diff --git a/src/lib/object_op.c b/src/lib/object_op.c index 3266bbce..eadc7446 100644 --- a/src/lib/object_op.c +++ b/src/lib/object_op.c @@ -391,7 +391,7 @@ ANN Type scan_class(const Env env, const Type t, const Type_Decl *td) { env->name = env_filename; env->context->name = ctx_filename; if(local)env_pop(env, es.scope); - if (es.run) envset_pop(&es, owner); + envset_pop(&es, owner); return ret; } diff --git a/src/lib/shred.c b/src/lib/shred.c index c90ea8af..4728250a 100644 --- a/src/lib/shred.c +++ b/src/lib/shred.c @@ -204,8 +204,9 @@ static DTOR(fork_dtor) { static MFUN(fork_join) { if (*(m_int *)(o->data + o_fork_done)) return; if (!ME(o)->tick) return; - shreduler_remove(shred->tick->shreduler, shred, false); + shred->info->me->ref++; vector_add(&EV_SHREDS(*(M_Object *)(o->data + o_fork_ev)), (vtype)shred); + shreduler_remove(shred->tick->shreduler, shred, false); } static MFUN(shred_cancel) { diff --git a/src/lib/string.c b/src/lib/string.c index 130b01b3..9532ef92 100644 --- a/src/lib/string.c +++ b/src/lib/string.c @@ -402,10 +402,8 @@ static MFUN(string_atof) { static MFUN(string_atoi2) { const M_Object obj = *(M_Object*)MEM(0); const m_str str = STRING(obj); -puts(str); char *endptr = NULL; if(!(*(m_int*)RETURN = strtol(str, &endptr, 10))) { -printf("lkjlk j %i\n", errno); if(errno == EINVAL) { handle(shred, "ErrorInvalidValue"); return; @@ -415,7 +413,6 @@ printf("lkjlk j %i\n", errno); return; } } -printf("ret: %li\n", *(m_int*)RETURN); **(m_uint**)MEM(SZ_INT) = endptr - str; } diff --git a/src/parse/check.c b/src/parse/check.c index 4899b09c..fbb0ffc0 100644 --- a/src/parse/check.c +++ b/src/parse/check.c @@ -109,6 +109,7 @@ ANN static m_bool check_decl(const Env env, const Exp_Decl *decl) { ANN /*static inline*/ m_bool ensure_check(const Env env, const Type t) { if (tflag(t, tflag_check) || !(tflag(t, tflag_cdef) || tflag(t, tflag_udef))) return GW_OK; + if(!tflag(t, tflag_tmpl)) return GW_OK; struct EnvSet es = {.env = env, .data = env, .func = (_exp_func)check_cdef, @@ -671,7 +672,7 @@ ANN static Type check_predefined(const Env env, Exp_Call *exp, const Value v, CHECK_BO(envset_pushv(&es, v)); func->def->base->fbflag |= fbflag_internal; const m_bool ret = check_traverse_fdef(env, func->def); - if (es.run) envset_pop(&es, v->from->owner_class); + envset_pop(&es, v->from->owner_class); CHECK_BO(ret); } exp->func->type = func->value_ref->type; @@ -894,11 +895,13 @@ ANN Type _check_exp_call1(const Env env, Exp_Call *const exp) { if (t == env->gwion->type[et_op]) return check_op_call(env, exp); if (!t->info->func) // TODO: effects? return check_lambda_call(env, exp); +/* if (fflag(t->info->func, fflag_ftmpl)) { const Value value = t->info->func->value_ref; if (value->from->owner_class) CHECK_BO(ensure_traverse(env, value->from->owner_class)); } +*/ if (exp->args) { CHECK_OO(check_exp(env, exp->args)); Exp e = exp->args; @@ -909,6 +912,7 @@ ANN Type _check_exp_call1(const Env env, Exp_Call *const exp) { return check_exp_call_template(env, (Exp_Call *)exp); // TODO: effects? const Func func = find_func_match(env, t->info->func, exp); if (func) { +/* if (func != env->func && func->def && !fflag(func, fflag_valid)) { if(func->value_ref->from->owner_class) CHECK_BO(ensure_check(env, func->value_ref->from->owner_class)); diff --git a/src/parse/func_resolve_tmpl.c b/src/parse/func_resolve_tmpl.c index 1cbeff5e..010ef247 100644 --- a/src/parse/func_resolve_tmpl.c +++ b/src/parse/func_resolve_tmpl.c @@ -157,7 +157,7 @@ ANN static Func find_tmpl(const Env env, const Value v, Exp_Call *const exp, if(in_tmpl) nspc_pop_type(env->gwion->mp, env->curr); env_pop(env, scope); - if (es.run) envset_pop(&es, v->from->owner_class); + envset_pop(&es, v->from->owner_class); env->func = former; return m_func; } diff --git a/src/parse/scan1.c b/src/parse/scan1.c index adfab34b..54927603 100644 --- a/src/parse/scan1.c +++ b/src/parse/scan1.c @@ -687,6 +687,13 @@ ANN static m_bool _scan1_func_def(const Env env, const Func_Def fdef) { env_set_error(env, true); return GW_ERROR; } + + if(!strcmp(s_name(fdef->base->xid), "new")) { + if(!env->class_def) + ERR_B(fdef->base->pos, _("{G+}new{0} operator must be set inside {C+}class{0}")); + SET_FLAG(env->class_def, abstract); + } + return ret; } diff --git a/src/parse/template.c b/src/parse/template.c index d6b273b3..5936114a 100644 --- a/src/parse/template.c +++ b/src/parse/template.c @@ -209,7 +209,7 @@ ANN Type scan_type(const Env env, const Type t, Type_Decl *td) { (void)env_push(env, owner, owner->nspc); // TODO: is this needed? const Type ret = known_type(env, td->next); env_pop(env, es.scope); - if (es.run) envset_pop(&es, owner); + envset_pop(&es, owner); if (!td->array) return ret; return array_type(env, ret, td->array->depth); } -- 2.43.0