From: fennecdjay Date: Fri, 5 Jul 2019 14:10:05 +0000 (+0200) Subject: :art: Operator mutablity now in func X-Git-Tag: nightly~2348^2~46 X-Git-Url: http://10.10.0.4:5575/?a=commitdiff_plain;h=c3743b7190be62c023e57627c4794af21aa6ad6f;p=gwion.git :art: Operator mutablity now in func --- diff --git a/include/gwi.h b/include/gwi.h index 249bf83e..23389900 100644 --- a/include/gwi.h +++ b/include/gwi.h @@ -24,7 +24,7 @@ typedef struct { typedef struct { Operator op; m_str ret, lhs, rhs; - Type (*ck)(Env, void*); + Type (*ck)(Env, void*, m_bool*); m_bool (*em)(Emitter, void*); m_bool mut; } DL_Oper; diff --git a/include/import.h b/include/import.h index efed9751..91de84f4 100644 --- a/include/import.h +++ b/include/import.h @@ -12,7 +12,7 @@ typedef struct Gwi_* Gwi; #define SFUN(a) ANN void a(const M_Object o NUSED, const m_bit* RETURN NUSED, const VM_Shred shred NUSED) #define CTOR(a) ANN void a(const M_Object o NUSED, const m_bit* _ NUSED, const VM_Shred shred NUSED) #define DTOR(a) ANN void a(const M_Object o NUSED, const m_bit* _ NUSED, const VM_Shred shred NUSED) -#define OP_CHECK(a) ANN Type a(const Env env NUSED, void* data NUSED) +#define OP_CHECK(a) ANN Type a(const Env env NUSED, void* data NUSED, m_bool* mut NUSED) #define OP_EMIT(a) ANN m_bool a(const Emitter emit NUSED, void* data NUSED) #ifdef GWION_BUILTIN #define GWION_IMPORT(a) ANN m_bool import_##a(const Gwi gwi) @@ -59,9 +59,8 @@ ANN m_int gwi_func_arg(const Gwi gwi, const __restrict__ m_str t, const __restri ANN m_int gwi_func_end(const Gwi gwi, const ae_flag flag); ANN2(1) m_int gwi_oper_ini(const Gwi gwi, const m_str l, const m_str r, const m_str t); -ANN m_int gwi_oper_add(const Gwi gwi, Type (*check)(Env, void*)); -ANN m_int gwi_oper_emi(const Gwi gwi, m_bool (*check)(Emitter, void*)); -ANN void gwi_oper_mut(const Gwi, const m_bool); +ANN m_int gwi_oper_add(const Gwi gwi, opck); +ANN m_int gwi_oper_emi(const Gwi gwi, opem); ANN2(1) m_int gwi_oper_end(const Gwi gwi, const Operator op, const f_instr f); ANN Type_Decl* str2decl(const Env, const m_str, m_uint* depth); @@ -83,7 +82,7 @@ ANN Type_List str2tl(const Env env, const m_str s, m_uint *depth); #define FREEARG(a) ANN void a(Instr instr NUSED, void *gwion NUSED) typedef void (*f_freearg)(Instr, void*); -ANN void register_freearg(const Gwi, const f_instr, void(*)(const Instr,void*)); +ANN void register_freearg(const Gwi, const f_instr, const f_freearg); ANN void gwi_reserve(const Gwi, const m_str); #endif diff --git a/include/operator.h b/include/operator.h index 1e8b13b3..bcf1c28f 100644 --- a/include/operator.h +++ b/include/operator.h @@ -4,7 +4,7 @@ #define ERR_N(a, b, ...) { env_err(env, (a), (b), ## __VA_ARGS__); return t_null; } -typedef Type (*opck)(const Env, void*); +typedef Type (*opck)(const Env, void*, m_bool*); typedef m_bool (*opem)(const Emitter, void*); struct Op_Import { @@ -14,7 +14,6 @@ struct Op_Import { uintptr_t data; loc_t pos; Operator op; - m_bool mut; }; struct Implicit { diff --git a/src/lib/array.c b/src/lib/array.c index b40d3d87..da46685d 100644 --- a/src/lib/array.c +++ b/src/lib/array.c @@ -11,8 +11,8 @@ #include "object.h" #include "array.h" #include "emit.h" -#include "import.h" #include "operator.h" +#include "import.h" #include "traverse.h" #include "parse.h" @@ -151,7 +151,7 @@ ANN static Type get_array_type(Type t) { static OP_CHECK(opck_array_at) { ARRAY_OPCK - if(opck_const_rhs(env, data) == t_null) + if(opck_const_rhs(env, data, mut) == t_null) return t_null; if(bin->lhs->type->array_depth != bin->rhs->type->array_depth) ERR_N(exp_self(bin)->pos, _("array depths do not match.")) diff --git a/src/lib/complex.c b/src/lib/complex.c index 6ed55aed..167aefda 100644 --- a/src/lib/complex.c +++ b/src/lib/complex.c @@ -7,6 +7,8 @@ #include "type.h" #include "instr.h" #include "object.h" +#include "gwion.h" +#include "operator.h" #include "import.h" #define describe(name, op) \ diff --git a/src/lib/engine.c b/src/lib/engine.c index 3e89351a..7b6655c8 100644 --- a/src/lib/engine.c +++ b/src/lib/engine.c @@ -8,16 +8,16 @@ #include "nspc.h" #include "type.h" #include "object.h" -#include "import.h" -#include "gwi.h" -#include "lang_private.h" #include "emit.h" #include "env.h" #include "vm.h" #include "gwion.h" #include "operator.h" +#include "import.h" +#include "gwi.h" #include "engine.h" #include "parser.h" +#include "lang_private.h" static FREEARG(freearg_switchini) { if(instr->m_val) diff --git a/src/lib/event.c b/src/lib/event.c index 9ea505d7..09f15d41 100644 --- a/src/lib/event.c +++ b/src/lib/event.c @@ -7,6 +7,7 @@ #include "type.h" #include "instr.h" #include "object.h" +#include "operator.h" #include "import.h" static CTOR(event_ctor) { diff --git a/src/lib/func.c b/src/lib/func.c index 7f212721..cc85de4e 100644 --- a/src/lib/func.c +++ b/src/lib/func.c @@ -11,9 +11,9 @@ #include "instr.h" #include "emit.h" #include "object.h" -#include "import.h" #include "nspc.h" #include "operator.h" +#include "import.h" #include "traverse.h" #include "template.h" #include "parse.h" @@ -34,6 +34,7 @@ static OP_CHECK(opck_func_call) { Exp e = exp_self(bin); e->exp_type = ae_exp_call; memcpy(&e->d.exp_call, &call, sizeof(Exp_Call)); + ++*mut; return check_exp_call1(env, &e->d.exp_call) ?: t_null; } @@ -283,7 +284,6 @@ static FREEARG(freearg_dottmpl) { GWION_IMPORT(func) { CHECK_BB(gwi_oper_ini(gwi, (m_str)OP_ANY_TYPE, "@function", NULL)) CHECK_BB(gwi_oper_add(gwi, opck_func_call)) - gwi_oper_mut(gwi, 1); CHECK_BB(gwi_oper_end(gwi, op_chuck, NULL)) CHECK_BB(gwi_oper_ini(gwi, "@function", "@func_ptr", NULL)) CHECK_BB(gwi_oper_add(gwi, opck_fptr_at)) diff --git a/src/lib/import.c b/src/lib/import.c index 03da5720..37cc506d 100644 --- a/src/lib/import.c +++ b/src/lib/import.c @@ -11,13 +11,13 @@ #include "traverse.h" #include "instr.h" #include "object.h" -#include "import.h" -#include "gwi.h" #include "emit.h" #include "func.h" #include "nspc.h" #include "gwion.h" #include "operator.h" +#include "import.h" +#include "gwi.h" #include "mpool.h" #define GWI_ERR_B(a,...) { env_err(gwi->gwion->env, gwi->loc, (a), ## __VA_ARGS__); return GW_ERROR; } @@ -482,7 +482,7 @@ ANN2(1,2) static int import_op(const Gwi gwi, const DL_Oper* op, const Type rhs = op->rhs ? get_type(env, op->rhs) : NULL; const Type ret = get_type(env, op->ret); const struct Op_Import opi = { lhs, rhs, ret, - op->ck, op->em, (uintptr_t)f, gwi->loc, op->op, op->mut }; + op->ck, op->em, (uintptr_t)f, gwi->loc, op->op }; return env_add_op(env, &opi); } @@ -496,7 +496,7 @@ ANN2(1) m_int gwi_oper_ini(const Gwi gwi, const restrict m_str l, return GW_OK; } -ANN m_int gwi_oper_add(const Gwi gwi, Type (*ck)(Env, void*)) { +ANN m_int gwi_oper_add(const Gwi gwi, Type (*ck)(Env, void*, m_bool*)) { gwi->oper.ck = ck; return GW_OK; } @@ -506,10 +506,6 @@ ANN m_int gwi_oper_emi(const Gwi gwi, m_bool (*em)(Emitter, void*)) { return GW_OK; } -ANN void gwi_oper_mut(const Gwi gwi, const m_bool mut) { - gwi->oper.mut = mut; -} - ANN m_int gwi_oper_end(const Gwi gwi, const Operator op, const f_instr f) { gwi->oper.op = op; const m_bool ret = import_op(gwi, &gwi->oper, f); @@ -668,7 +664,7 @@ ANN Type gwi_enum_end(const Gwi gwi) { return t; } -ANN void register_freearg(const Gwi gwi, const f_instr _exec, void(*_free)(const Instr, void*)) { +ANN void register_freearg(const Gwi gwi, const f_instr _exec, const f_freearg _free) { map_set(&gwi->gwion->data->freearg, (vtype)_exec, (vtype)_free); } diff --git a/src/lib/instr.c b/src/lib/instr.c index c9956d5b..1963d9a0 100644 --- a/src/lib/instr.c +++ b/src/lib/instr.c @@ -8,11 +8,13 @@ #include "type.h" #include "instr.h" #include "object.h" -#include "import.h" #include "func.h" #include "array.h" #include "nspc.h" #include "shreduler_private.h" +#include "gwion.h" +#include "operator.h" +#include "import.h" INSTR(DTOR_EOC) { const M_Object o = *(M_Object*)MEM(0); diff --git a/src/lib/modules.c b/src/lib/modules.c index 2f9a1ddf..075e1442 100644 --- a/src/lib/modules.c +++ b/src/lib/modules.c @@ -9,6 +9,7 @@ #include "type.h" #include "instr.h" #include "object.h" +#include "operator.h" #include "import.h" #include "ugen.h" #include "func.h" diff --git a/src/lib/object.c b/src/lib/object.c index 89246da3..bc41aab2 100644 --- a/src/lib/object.c +++ b/src/lib/object.c @@ -11,8 +11,8 @@ #include "value.h" #include "instr.h" #include "object.h" -#include "import.h" #include "operator.h" +#include "import.h" ANN void exception(const VM_Shred shred, const m_str c) { gw_err("%s: shred[id=%" UINT_F ":%s], PC=[%" UINT_F "]\n", @@ -101,7 +101,7 @@ static OP_CHECK(at_object) { const Exp_Binary* bin = (Exp_Binary*)data; const Type l = bin->lhs->type; const Type r = bin->rhs->type; - if(opck_rassign(env, data) == t_null) + if(opck_rassign(env, data, mut) == t_null) return t_null; if(bin->rhs->exp_type == ae_exp_decl) SET_FLAG(bin->rhs->d.exp_decl.td, ref); diff --git a/src/lib/opfunc.c b/src/lib/opfunc.c index ffa29563..9175a4f4 100644 --- a/src/lib/opfunc.c +++ b/src/lib/opfunc.c @@ -7,11 +7,11 @@ #include "value.h" #include "instr.h" #include "object.h" -#include "import.h" #include "emit.h" #include "traverse.h" #include "parse.h" #include "operator.h" +#include "import.h" static inline m_str access(ae_Exp_Meta meta) { return meta == ae_meta_value ? "non-mutable" : "protected"; @@ -44,7 +44,7 @@ OP_CHECK(opck_rhs_emit_var) { OP_CHECK(opck_rassign) { const Exp_Binary* bin = (Exp_Binary*)data; - if(opck_const_rhs(env, data) == t_null) + if(opck_const_rhs(env, data, mut) == t_null) return t_null; bin->rhs->emit_var = 1; return bin->rhs->type; @@ -64,7 +64,7 @@ OP_CHECK(opck_unary_meta2) { OP_CHECK(opck_unary_meta2_uniq) { const Exp_Unary* unary = (Exp_Unary*)data; - CHECK_OO(opck_unary_meta2(env, data)) + CHECK_OO(opck_unary_meta2(env, data, mut)) if(unary->exp->next) ERR_N(exp_self(unary)->pos, _("'%s' must be applied to a unique expression"), op2str(unary->op)) diff --git a/src/lib/prim.c b/src/lib/prim.c index 06e3dcd1..24e30591 100644 --- a/src/lib/prim.c +++ b/src/lib/prim.c @@ -7,10 +7,10 @@ #include "type.h" #include "instr.h" #include "object.h" -#include "import.h" -#include "gwi.h" #include "emit.h" #include "operator.h" +#include "import.h" +#include "gwi.h" #include "driver.h" #include "traverse.h" #include "parse.h" diff --git a/src/lib/ptr.c b/src/lib/ptr.c index de20bee5..f6e1fc42 100644 --- a/src/lib/ptr.c +++ b/src/lib/ptr.c @@ -10,9 +10,9 @@ #include "nspc.h" #include "instr.h" #include "object.h" +#include "operator.h" #include "import.h" #include "emit.h" -#include "operator.h" static OP_CHECK(opck_ptr_assign) { const Exp_Binary* bin = (Exp_Binary*)data; diff --git a/src/lib/shred.c b/src/lib/shred.c index 05de76fe..3e23a30c 100644 --- a/src/lib/shred.c +++ b/src/lib/shred.c @@ -8,9 +8,10 @@ #include "type.h" #include "instr.h" #include "object.h" -#include "import.h" #include "shreduler_private.h" #include "gwion.h" +#include "operator.h" +#include "import.h" static m_int o_fork_thread, o_shred_cancel, o_fork_done, o_fork_ev, o_fork_retsize, o_fork_retval, o_fork_orig; diff --git a/src/lib/string.c b/src/lib/string.c index f65c4d1f..3426d745 100644 --- a/src/lib/string.c +++ b/src/lib/string.c @@ -10,8 +10,9 @@ #include "type.h" #include "instr.h" #include "object.h" -#include "import.h" #include "gwion.h" +#include "operator.h" +#include "import.h" ANN static void push_string(const VM_Shred shred, const M_Object obj, const m_str c) { STRING(obj) = s_name(insert_symbol(shred->info->vm->gwion->st, c)); diff --git a/src/lib/ugen.c b/src/lib/ugen.c index a9e33fe7..dc1cfdb6 100644 --- a/src/lib/ugen.c +++ b/src/lib/ugen.c @@ -8,6 +8,7 @@ #include "type.h" #include "instr.h" #include "object.h" +#include "operator.h" #include "import.h" #include "gwi.h" #include "ugen.h" diff --git a/src/lib/vararg.c b/src/lib/vararg.c index 9620ed23..67c3613b 100644 --- a/src/lib/vararg.c +++ b/src/lib/vararg.c @@ -8,9 +8,10 @@ #include "type.h" #include "instr.h" #include "object.h" -#include "import.h" #include "vararg.h" #include "gwion.h" +#include "operator.h" +#include "import.h" void free_vararg(MemPool p, struct Vararg_* arg) { xfree(arg->d); diff --git a/src/lib/vec.c b/src/lib/vec.c index 0f62962d..4b37423c 100644 --- a/src/lib/vec.c +++ b/src/lib/vec.c @@ -6,6 +6,8 @@ #include "type.h" #include "instr.h" #include "object.h" +#include "gwion.h" +#include "operator.h" #include "import.h" #include "driver.h" diff --git a/src/parse/check.c b/src/parse/check.c index c8cba0e4..1f860e96 100644 --- a/src/parse/check.c +++ b/src/parse/check.c @@ -9,13 +9,14 @@ #include "func.h" #include "instr.h" #include "object.h" -#include "import.h" #include "traverse.h" #include "template.h" #include "optim.h" +#include "gwion.h" +#include "operator.h" +#include "import.h" #include "parse.h" #include "nspc.h" -#include "operator.h" #include "switch.h" ANN static Type check_exp(const Env env, Exp exp); diff --git a/src/parse/operator.c b/src/parse/operator.c index 2c60537f..e9e83224 100644 --- a/src/parse/operator.c +++ b/src/parse/operator.c @@ -20,9 +20,8 @@ typedef struct M_Operator_{ Type lhs, rhs, ret; f_instr instr; Func func; - Type (*ck)(Env, void*); - m_bool (*em)(Emitter, void*); - m_bool mut; + opck ck; + opem em; } M_Operator; ANN void free_op_map(Map map, struct Gwion_ *gwion) { @@ -95,7 +94,6 @@ ANN m_bool add_op(const Gwion gwion, const Nspc nspc, const struct Op_Import* op mo->instr = (f_instr)opi->data; mo->ck = opi->ck; mo->em = opi->em; - mo->mut = opi->mut; vector_add(v, (vtype)mo); return GW_OK; } @@ -113,14 +111,14 @@ ANN static void set_nspc(struct Op_Import* opi, const Nspc nspc) { ((Exp_Unary*)opi->data)->nspc = nspc; } -ANN static Type op_check_inner(const Env env, const Map map, struct Op_Import* opi) { +ANN static Type op_check_inner(const Env env, const Map map, struct Op_Import* opi, + m_bool* mut) { Type t, r = opi->rhs; do { const M_Operator* mo; const Vector v = (Vector)map_get(map, (vtype)opi->op); if(v && (mo = operator_find(v, opi->lhs, r))) { - opi->mut = mo->mut; - if((mo->ck && (t = mo->ck(env, (void*)opi->data)))) + if((mo->ck && (t = mo->ck(env, (void*)opi->data, mut)))) return t; else return mo->ret; @@ -140,12 +138,13 @@ ANN Type op_check(const Env env, struct Op_Import* opi) { if(nspc->info->op_map.ptr) { Type l = opi->lhs; do { + m_bool mut = 0; struct Op_Import opi2 = { .op=opi->op, .lhs=l, .rhs=opi->rhs, .data=opi->data }; - ret = op_check_inner(env, &nspc->info->op_map, &opi2); + ret = op_check_inner(env, &nspc->info->op_map, &opi2, &mut); if(ret) { if(ret == t_null) break; - if(!opi2.mut) + if(!mut) set_nspc(opi, nspc); return ret; } diff --git a/src/vm/vm.c b/src/vm/vm.c index c0c68c43..caa12396 100644 --- a/src/vm/vm.c +++ b/src/vm/vm.c @@ -11,11 +11,12 @@ #include "type.h" #include "instr.h" #include "object.h" -#include "import.h" #include "ugen.h" #include "shreduler_private.h" #include "emit.h" #include "gwion.h" +#include "operator.h" +#include "import.h" #include "map_private.h" #include "value.h" diff --git a/src/vm/vm_code.c b/src/vm/vm_code.c index 1f3e1c9f..e011b1a1 100644 --- a/src/vm/vm_code.c +++ b/src/vm/vm_code.c @@ -12,6 +12,7 @@ #include "array.h" #include "memoize.h" #include "gwion.h" +#include "operator.h" #include "import.h" ANN /*static*/ void free_code_instr(const Vector v, const Gwion gwion) {