From: fennecdjay Date: Thu, 26 Sep 2019 03:21:08 +0000 (+0200) Subject: :art: dtor and gack now operators X-Git-Tag: nightly~2199^2~3 X-Git-Url: http://10.10.0.4:5575/?a=commitdiff_plain;h=5604fde29ad1798566709b92fafdadf5b43aee73;p=gwion.git :art: dtor and gack now operators --- diff --git a/ast b/ast index c63343d7..a196ff3f 160000 --- a/ast +++ b/ast @@ -1 +1 @@ -Subproject commit c63343d7bf486a47001f32d71b8160bf997ae4d2 +Subproject commit a196ff3fb91adc7c205c23fd4e07946073e5a308 diff --git a/examples/class_coverage.gw b/examples/class_coverage.gw index a9156aea..240b88ac 100644 --- a/examples/class_coverage.gw +++ b/examples/class_coverage.gw @@ -7,7 +7,7 @@ class C Vec3 v; Vec4 w; Object o; - dtor { <<< "dtor" >>>; } + operator @dtor void () { <<< "dtor" >>>; } } C c; diff --git a/examples/dtor.gw b/examples/dtor.gw index 4c3e45f5..a4779ea5 100644 --- a/examples/dtor.gw +++ b/examples/dtor.gw @@ -1,6 +1,6 @@ class C { - dtor {<<< 1 >>>;} + operator @dtor void () {<<< 1 >>>;} } C c; diff --git a/src/emit/emit.c b/src/emit/emit.c index 8f1eddd6..08c096b8 100644 --- a/src/emit/emit.c +++ b/src/emit/emit.c @@ -576,7 +576,7 @@ ANN static m_bool prim_gack(const Emitter emit, const Exp_Primary* primary) { ANN static m_bool prim_unpack(const Emitter emit NUSED, const Exp_Primary* primary) { // TODO err_msg - return primary->d.tuple.ok ? GW_OK : GW_ERROR; + return exp_self(primary)->emit_var ? GW_OK : GW_ERROR; } static const _exp_func prim_func[] = { @@ -1070,7 +1070,8 @@ if(is_spork) { } else { const Instr spork = emit_add_instr(emit, is_spork ? SporkExp : ForkEnd); spork->m_val = exp_self(unary)->emit_var; -// spork->m_val2 = f->def->base->ret_type->size; + if(!(spork->m_val = exp_self(unary)->emit_var)) +return NULL;// err_msg } } else { if(GET_FLAG(f, member) && is_fptr(emit->gwion, f->value_ref->type)) { @@ -1082,7 +1083,8 @@ if(is_spork) { } else emit_exp_spork_finish(emit, f->def->stack_depth); const Instr end = emit_add_instr(emit, is_spork ? SporkEnd : ForkEnd); - end->m_val = exp_self(unary)->emit_var; + if(!is_spork && !(end->m_val = exp_self(unary)->emit_var)) + return NULL;// err_msg end->m_val2 = f->def->base->ret_type->size; } return ini; @@ -1746,14 +1748,13 @@ ANN static void emit_func_def_return(const Emitter emit) { } ANN static void emit_func_def_code(const Emitter emit, const Func func) { - func->code = finalyze(emit, !GET_FLAG(func->def, dtor) ? FuncReturn : DTOR_EOC); - if(GET_FLAG(func->def, dtor)) { + const m_bool is_dtor = func->def->base->xid == insert_symbol("@dtor");// could be get flag + func->code = finalyze(emit, !is_dtor ? FuncReturn : DTOR_EOC); + if(is_dtor) { emit->env->class_def->nspc->dtor = func->code; ADD_REF(func->code) - } else if(func->def->base->xid == insert_symbol("@gack")) { + } else if(func->def->base->xid == insert_symbol("@gack")) emit->env->class_def->e->gack = func->code; - ADD_REF(func->code) - } } ANN static m_bool _fdef_body(const Emitter emit, const Func_Def fdef) { diff --git a/src/lib/tuple.c b/src/lib/tuple.c index a2c11fb9..a1f9474a 100644 --- a/src/lib/tuple.c +++ b/src/lib/tuple.c @@ -147,7 +147,7 @@ static OP_CHECK(opck_at_tuple) { } ++i; } while((e = e->next)); - bin->rhs->d.exp_primary.d.tuple.ok = 1; + bin->rhs->emit_var = 1; return bin->lhs->type; } return opck_at_object_tuple(env, data, mut); diff --git a/src/parse/scan1.c b/src/parse/scan1.c index 092f6fb2..2d85ffcb 100644 --- a/src/parse/scan1.c +++ b/src/parse/scan1.c @@ -359,9 +359,11 @@ ANN m_bool scan1_func_def(const Env env, const Func_Def fdef) { CHECK_BB(env_storage(env, fdef->flag, td_pos(fdef->base->td))) if(tmpl_base(fdef->base->tmpl)) return GW_OK; - if(!env->class_def && (GET_FLAG(fdef, dtor) || fdef->base->xid == insert_symbol("@gack"))) - ERR_B(td_pos(fdef->base->td), _("'%s' must be in class def!!"), s_name(fdef->base->xid)) - if(GET_FLAG(fdef, op) && env->class_def) + if(fdef->base->xid == insert_symbol("@dtor") || fdef->base->xid == insert_symbol("@gack")) { + if(!env->class_def) + ERR_B(td_pos(fdef->base->td), _("'%s' must be in class def!!"), s_name(fdef->base->xid)) + if(fdef->base->args)exit(3); + } else if(GET_FLAG(fdef, op) && env->class_def) SET_FLAG(fdef, static); struct Func_ fake = { .name=s_name(fdef->base->xid) }, *const former = env->func; env->func = &fake; diff --git a/src/parse/scan2.c b/src/parse/scan2.c index ca1544d8..2e649635 100644 --- a/src/parse/scan2.c +++ b/src/parse/scan2.c @@ -409,14 +409,15 @@ ANN static m_bool scan2_func_def_op(const Env env, const Func_Def f) { const m_str str = s_name(f->base->xid); const uint is_unary = GET_FLAG(f, unary) + (!strcmp(str, "@conditionnal") || !strcmp(str, "@unconditionnal")); const Type l = is_unary ? NULL : - f->base->args->var_decl->value->type; - const Type r = is_unary ? f->base->args->var_decl->value->type : + f->base->args ? f->base->args->var_decl->value->type : NULL; + const Type r = f->base->args ? is_unary ? f->base->args->var_decl->value->type : f->base->args->next ? f->base->args->next->var_decl->value->type : - f->base->ret_type; + f->base->ret_type : NULL; struct Op_Import opi = { .op=f->base->xid, .lhs=l, .rhs=r, .ret=f->base->ret_type, .pos=f->pos, .data=(uintptr_t)f->base->func }; - if(!strcmp(str, "@implicit")) + if(!strcmp(str, "@implicit")) { opi.ck = opck_usr_implicit; + } CHECK_BB(add_op(env->gwion, &opi)) operator_set_func(&opi); return GW_OK; @@ -433,10 +434,8 @@ ANN static m_bool scan2_func_def_code(const Env env, const Func_Def f) { ANN static void scan2_func_def_flag(const Env env, const Func_Def f) { if(!GET_FLAG(f, builtin)) SET_FLAG(f->base->func, pure); - if(GET_FLAG(f, dtor)) { + if(f->base->xid == insert_symbol("@dtor")) SET_FLAG(env->class_def, dtor); - SET_FLAG(f->base->func, dtor); - } } ANN static m_str func_tmpl_name(const Env env, const Func_Def f) { diff --git a/tests/error/dtor_outside_class.gw b/tests/error/dtor_outside_class.gw index 612a8474..15859d05 100644 --- a/tests/error/dtor_outside_class.gw +++ b/tests/error/dtor_outside_class.gw @@ -1,2 +1,2 @@ -#! [contains] 'dtor' must be in class def!! -dtor {} +#! [contains] '@dtor' must be in class def!! +operator @dtor void () {} diff --git a/tests/new/dtor.gw b/tests/new/dtor.gw index c6ca2f18..d549ea50 100644 --- a/tests/new/dtor.gw +++ b/tests/new/dtor.gw @@ -1,11 +1,11 @@ class <~A~>C { - dtor { <<< __func__ >>>; } + operator @dtor void { <<< __func__ >>>; } } class <~A~>D extends <~A~>C { - dtor { <<< __func__ >>>; } + operator @dtor { <<< __func__ >>>; } } class E extends <~int~>D { - dtor { <<< __func__ >>>; } + operator @dtor { <<< __func__ >>>; } } E e; diff --git a/tests/new/extend_template_union.gw b/tests/new/extend_template_union.gw index f9e9de1b..e744bd1e 100644 --- a/tests/new/extend_template_union.gw +++ b/tests/new/extend_template_union.gw @@ -7,7 +7,7 @@ union <~A~>U { #!<<< u.i >>>; class <~A~>C extends <~A~>U { fun void test() { <<< this >>>; } - dtor { <<< __func__ >>>; } + operator @dtor void () { <<< __func__ >>>; } } <~float~>C c;