From 4fd6882abde3eab05fe7aa2eddc0af1346002351 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=A9mie=20Astor?= Date: Thu, 28 Apr 2022 23:29:46 +0200 Subject: [PATCH] :art: Add Regex and other goodies --- plug | 2 +- src/import/import_cdef.c | 1 + src/lib/lib_func.c | 21 +++++++++++++++++++++ src/parse/check.c | 6 +++++- src/parse/template.c | 15 ++++++++------- 5 files changed, 36 insertions(+), 9 deletions(-) diff --git a/plug b/plug index 104ccd74..bdadd7a5 160000 --- a/plug +++ b/plug @@ -1 +1 @@ -Subproject commit 104ccd7458a57dc23c3fc1fb67782c692706ec40 +Subproject commit bdadd7a53df9a8a6e618859ed4bb38afda0a3789 diff --git a/src/import/import_cdef.c b/src/import/import_cdef.c index 0133f0ac..82019c56 100644 --- a/src/import/import_cdef.c +++ b/src/import/import_cdef.c @@ -106,6 +106,7 @@ ANN Type gwi_struct_ini(const Gwi gwi, const m_str name) { CHECK_BO(check_typename_def(gwi, &ck)); const Type t = new_type(gwi->gwion->mp, s_name(ck.sym), gwi->gwion->type[et_compound]); + t->size = 0; set_tflag(t, tflag_struct); if (!ck.sl) gwi_type_flag(t); diff --git a/src/lib/lib_func.c b/src/lib/lib_func.c index c0f6eaab..f4ffbc0f 100644 --- a/src/lib/lib_func.c +++ b/src/lib/lib_func.c @@ -12,6 +12,7 @@ #include "traverse.h" #include "template.h" #include "parse.h" +#include "partial.h" static OP_CHECK(opck_func_call) { Exp_Binary *bin = (Exp_Binary *)data; @@ -712,6 +713,20 @@ static OP_EMIT(opem_spork) { return emit_exp_spork(emit, unary); } +static OP_CHECK(opck_func_partial) { + Exp_Call *call = (Exp_Call*)data; + return partial_type(env, call); +} + +static OP_CHECK(opck_class_partial) { + Exp_Call *call = (Exp_Call*)data; + struct Op_Import opi = {.op = insert_symbol("@partial"), + .lhs = actual_type(env->gwion, call->func->type), + .pos = call->func->pos, + .data = (uintptr_t)data}; + return op_check(env, &opi); +} + static FREEARG(freearg_xork) { vmcode_remref((VM_Code)instr->m_val, gwion); } static FREEARG(freearg_dottmpl) { @@ -750,6 +765,12 @@ GWION_IMPORT(func) { GWI_BB(gwi_oper_ini(gwi, "@function", "@function", NULL)) GWI_BB(gwi_oper_add(gwi, opck_auto_fptr)) GWI_BB(gwi_oper_end(gwi, "@=>", int_r_assign)) + GWI_BB(gwi_oper_ini(gwi, "@function", NULL, NULL)) + GWI_BB(gwi_oper_add(gwi, opck_func_partial)) + GWI_BB(gwi_oper_end(gwi, "@partial", NULL)) + GWI_BB(gwi_oper_ini(gwi, "Class", NULL, NULL)) + GWI_BB(gwi_oper_add(gwi, opck_class_partial)) + GWI_BB(gwi_oper_end(gwi, "@partial", NULL)) gwi_register_freearg(gwi, SporkIni, freearg_xork); gwi_register_freearg(gwi, DotTmpl, freearg_dottmpl); return GW_OK; diff --git a/src/parse/check.c b/src/parse/check.c index 4bfef633..9c07fb53 100644 --- a/src/parse/check.c +++ b/src/parse/check.c @@ -988,7 +988,11 @@ ANN static Type check_exp_call_tmpl(const Env env, Exp_Call *exp, const Type t) ANN static Type check_exp_call(const Env env, Exp_Call *exp) { if (is_partial(env, exp->args)) { CHECK_OO(check_exp(env, exp->func)); - return partial_type(env, exp); + struct Op_Import opi = {.op = insert_symbol("@partial"), + .lhs = exp->func->type, + .pos = exp->func->pos, + .data = (uintptr_t)exp}; + return op_check(env, &opi); } if (exp->tmpl) { DECL_BO(const m_bool, ret, = func_check(env, exp)); diff --git a/src/parse/template.c b/src/parse/template.c index 7b5677cc..4052bec8 100644 --- a/src/parse/template.c +++ b/src/parse/template.c @@ -134,14 +134,15 @@ ANN static Type _scan_type(const Env env, const Type t, Type_Decl *td) { for(uint32_t i = 0; i < tl->len; i++) { Type_Decl *tmp = *mp_vector_at(tl, Type_Decl*, i); DECL_OO(const Type, t, = known_type(env, tmp)); - Specialized *spec = mp_vector_at(sl, Specialized, i); - if(spec->traits) { - Symbol missing = miss_traits(t, spec); - if (missing) { - ERR_O(td->pos, "does not implement requested trait '{/}%s{0}'", - s_name(missing)); - } + if(!sl) continue; + Specialized *spec = mp_vector_at(sl, Specialized, i); + if(spec->traits) { + Symbol missing = miss_traits(t, spec); + if (missing) { + ERR_O(td->pos, "does not implement requested trait '{/}%s{0}'", + s_name(missing)); } + } } struct Op_Import opi = {.op = insert_symbol("@scan"), .lhs = t, -- 2.43.0