From: Jérémie Astor Date: Fri, 8 May 2020 11:50:23 +0000 (+0200) Subject: :art: Allow template structures X-Git-Tag: nightly~1631 X-Git-Url: http://10.10.0.4:5575/?a=commitdiff_plain;h=5d6e40dd9d23b3df6b2fe2d55dfc00b150032bcd;p=gwion.git :art: Allow template structures --- diff --git a/src/lib/object_op.c b/src/lib/object_op.c index 6e051bf5..031aac07 100644 --- a/src/lib/object_op.c +++ b/src/lib/object_op.c @@ -137,13 +137,16 @@ static OP_EMIT(opem_implicit_null2obj) { ANN static Type scan_class(const Env env, const Type t, const Type_Decl* td); -OP_CHECK(opck_object_scan) { +static Type opck_object_scan(const Env env, const struct TemplateScan *ts) { + if(ts->td->types) + return scan_class(env, ts->t, ts->td) ?: env->gwion->type[et_null]; + ERR_N(td_pos(ts->td), _("you must provide template types for type '%s'"), ts->t->name) +} + +static OP_CHECK(opck_struct_scan) { struct TemplateScan *ts = (struct TemplateScan*)data; - if(ts->td->types && GET_FLAG(ts->t, template) && ts->t->e->def) - return scan_class(env, ts->t, ts->td); - if(!GET_FLAG(ts->t, template) || GET_FLAG(ts->t, unary)) - return ts->t; - ERR_O(td_pos(ts->td), _("you must provide template types for type '%s'"), ts->t->name) + return (isa(ts->t , env->gwion->type[et_object]) > 0 || GET_FLAG(ts->t, struct)) ? + opck_object_scan(env, ts) : env->gwion->type[et_null]; } static const f_instr dotstatic[] = { DotStatic, DotStatic2, DotStatic3, RegPushImm }; @@ -462,8 +465,8 @@ GWION_IMPORT(object_op) { GWI_BB(gwi_oper_ini(gwi, NULL, "Object", "bool")) GWI_BB(gwi_oper_add(gwi, opck_unary_meta2)) GWI_BB(gwi_oper_end(gwi, "!", IntNot)) - GWI_BB(gwi_oper_ini(gwi, "Object", NULL, NULL)) - GWI_BB(gwi_oper_add(gwi, opck_object_scan)) + GWI_BB(gwi_oper_ini(gwi, (m_str)OP_ANY_TYPE, NULL, NULL)) + GWI_BB(gwi_oper_add(gwi, opck_struct_scan)) GWI_BB(gwi_oper_end(gwi, "@scan", NULL)) gwi_item_ini(gwi, "@null", "null"); gwi_item_end(gwi, 0, NULL); diff --git a/src/parse/template.c b/src/parse/template.c index 8e47c8cb..a0a52c6f 100644 --- a/src/parse/template.c +++ b/src/parse/template.c @@ -94,7 +94,7 @@ static ANN Type maybe_func(const Env env, const Type t, const Type_Decl* td) { ANN Type _scan_type(const Env env, const Type t, const Type_Decl* td) { if(GET_FLAG(t, template)) { - if(GET_FLAG(t, ref)) + if(GET_FLAG(t, ref) || (GET_FLAG(t, unary) && !td->types)) return t; struct TemplateScan ts = { .t=t, .td=td }; struct Op_Import opi = { .op=insert_symbol("@scan"), .lhs=t, .data=(uintptr_t)&ts, .pos=td_pos(td), .op_type=op_scan }; @@ -126,4 +126,3 @@ ANN Type scan_type(const Env env, const Type t, Type_Decl* td) { } return _scan_type(env, t, td); } -