From 8c8b32f91138b82795bb429f75a3c5e9bbbc6a01 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=A9mie=20Astor?= Date: Sun, 14 Nov 2021 16:55:03 +0100 Subject: [PATCH] :art More on libs --- src/lib/deep_equal.c | 10 +++++++++- src/lib/dict.c | 26 ++++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/src/lib/deep_equal.c b/src/lib/deep_equal.c index a94d456a..6d71f3d6 100644 --- a/src/lib/deep_equal.c +++ b/src/lib/deep_equal.c @@ -31,6 +31,7 @@ static OP_CHECK(opck_deep_eq_any) { DECL_ON(const Type, t, = check_exp(env, exp_self(bin))); return t; } + static OP_CHECK(opck_deep_ne_any) { Exp_Binary *bin = data; bin->op = insert_symbol(env->gwion->st, "!="); @@ -120,8 +121,15 @@ static OP_CHECK(opck_deep_equal) { vector_release(&l); vector_release(&r); if(ret) return env->gwion->type[et_bool]; + const Symbol op = bin->op; + bin->op = !strcmp(s_name(bin->op), "?=") + ? insert_symbol(env->gwion->st, "==") : insert_symbol(env->gwion->st, "!="); + env->context->error = true; + const Type ret_type = check_exp(env, exp_self(bin)); + env->context->error = false; + if(ret_type) return env->gwion->type[et_bool]; ERR_N(exp_self(bin)->pos, "no deep operation for: {G+/}%s{0} {+}%s{0} {G+/}%s{0}", - bin->lhs->type->name, s_name(bin->op), bin->rhs->type->name); + bin->lhs->type->name, s_name(op), bin->rhs->type->name); } struct DeepEmit { diff --git a/src/lib/dict.c b/src/lib/dict.c index 55ec0802..7f2c762f 100644 --- a/src/lib/dict.c +++ b/src/lib/dict.c @@ -555,6 +555,32 @@ static OP_EMIT(opem_dict_access) { static OP_CHECK(opck_dict_access) { const Array_Sub array = (Array_Sub)data; HMapInfo *const hinfo = (HMapInfo*)array->type->nspc->class_data; + + struct Exp_ func = { .exp_type = ae_exp_primary, .d = { .prim = { .prim_type = ae_prim_id, .d = { .var = insert_symbol("hash") }} }}; + + struct Exp_ call = { + .exp_type = ae_exp_call, + .d = { + .exp_call = { + .func = &func, + .args = array->exp // beware next + } + } +}; +struct Exp_ lhs = { .exp_type = ae_exp_primary, .type = hinfo->key, .d = { .prim = { .prim_type = ae_prim_id } }}; +struct Exp_ rhs = { .exp_type = ae_exp_primary, .type = hinfo->key, .d = { .prim = { .prim_type = ae_prim_id } }}; +struct Exp_ bin = { .exp_type = ae_exp_binary, .d = { .exp_binary = { .lhs = &lhs, .rhs = &rhs, .op = insert_symbol("?=") } }}; +struct Op_Import opi = { + .lhs = hinfo->key, + .rhs = hinfo->key, + .op = bin.d.exp_binary.op, + .data = (m_uint)&bin +}; + + + CHECK_BN(traverse_exp(env, &call)); + CHECK_ON(op_check(env, &opi)); + if(!array->exp->next) return hinfo->val; struct Array_Sub_ next = { array->exp->next, hinfo->val, array->depth - 1}; -- 2.43.0