-Subproject commit 607704e19a25cd9985506c75fe600d2a4213aba1
+Subproject commit 8fdf56e0aabe91bcaded35c38d036e81a3a34432
ANN Var_Decl_List str2varlist(const Gwion, const m_str, const loc_t);
ANN Type_Decl* str2td(const Gwion, const m_str, const loc_t);
ANN Type str2type(const Gwion, const m_str, const loc_t);
+ANN static inline Type_Decl* type2td(const Gwion gwion, const Type t, const loc_t pos) {
+ const m_str str = type2str(gwion->env, t);
+ Type_Decl *td = str2td(gwion, str, pos);
+ free_mstr(gwion->mp, str);
+ return td;
+}
#define gwi_str2sym(gwi, path) str2sym(gwi->gwion, path, gwi->loc)
#define gwi_str2symlist(gwi, path) str2symlist(gwi->gwion, path, gwi->loc)
r = r->info->parent;
if(get_depth(cast->exp->info->type) == get_depth(exp_self(cast)->info->type) && isa(l->info->base_type, r->info->base_type) > 0)
return l;
- return env->gwion->type[et_error];
+ return NULL;
}
static OP_CHECK(opck_array_slice) {
return check_array_access(env, &next);
}
+static OP_CHECK(opck_not_array) {
+ const Array_Sub array = (Array_Sub)data;
+ if(array->depth <= get_depth(array->type))
+ return array->type;
+ ERR_N(array->exp->pos, _("array subscripts (%"UINT_F") exceeds defined dimension (%"UINT_F")"),
+ array->depth, get_depth(array->type))
+}
+
ANN static void array_loop(const Emitter emit, const m_uint depth) {
const Instr pre_pop = emit_add_instr(emit, RegPop);
pre_pop->m_val = depth * SZ_INT;
GWI_BB(gwi_oper_add(gwi, opck_array_slice))
GWI_BB(gwi_oper_emi(gwi, opem_array_slice))
GWI_BB(gwi_oper_end(gwi, "@slice", NULL))
+ GWI_BB(gwi_oper_ini(gwi, (m_str)OP_ANY_TYPE, (m_str)OP_ANY_TYPE, NULL))
+ GWI_BB(gwi_oper_add(gwi, opck_not_array))
+ GWI_BB(gwi_oper_end(gwi, "@array", NULL))
GWI_BB(gwi_oper_ini(gwi, "int", "@Array", NULL))
GWI_BB(gwi_oper_add(gwi, opck_array))
GWI_BB(gwi_oper_emi(gwi, opem_array_access))
ERR_B(e->pos, _("operand is %s"), access);
}
+ANN static inline Type ptr_base(const Env env, const Type t) {
+ return known_type(env, t->info->cdef->base.tmpl->call->td);
+}
+
static OP_CHECK(opck_ptr_assign) {
const Exp_Binary* bin = (Exp_Binary*)data;
CHECK_BO(ptr_access(env, bin->lhs))
do {
Type u = bin->rhs->info->type;
do {
- const m_str str = get_type_name(env, u, 1);
- if(str && !strcmp(t->name, str))
- return bin->lhs->info->type; // use rhs?
- } while((u = u->info->parent));
+ const Type base = ptr_base(env, u);
+ if(isa(t, base) > 0)
+ return t;
+ } while((u = u->info->parent) && u->info->cdef->base.tmpl->call);
} while((t = t->info->parent));
return env->gwion->type[et_error];
}
static OP_CHECK(opck_ptr_deref) {
const Exp_Unary* unary = (Exp_Unary*)data;
- DECL_ON(const m_str, str, = get_type_name(env, unary->exp->info->type, 1))
- return exp_self(unary)->info->type = nspc_lookup_type1(env->curr, insert_symbol(str));
+ return ptr_base(env, unary->exp->info->type);
}
static OP_CHECK(opck_ptr_cast) {
static OP_CHECK(opck_ptr_implicit) {
const struct Implicit* imp = (struct Implicit*)data;
const Exp e = imp->e;
- DECL_OO(const m_str, name, = get_type_name(env, imp->t, 1))
- if(!strcmp(get_type_name(env, imp->t, 1), e->info->type->name)) {
+ const Type base = ptr_base(env, imp->t);
+ if(isa(e->info->type, base) > 0) {
const m_str access = exp_access(e);
if(access)
ERR_N(e->pos, _("can't cast %s value to Ptr"), access);
ANN static ssize_t template_size(const Env env, struct tmpl_info* info) {
DECL_OB(const m_str, str, = tl2str(env, info->td->types))
+ const size_t tmpl_sz = tmpl_set(info, str);
const m_str base = type2str(env, info->base);
- return tmpl_set(info, str) + tmpl_set(info, base) + 4;
+ return tmpl_sz + tmpl_set(info, base) + 4;
}
ANEW ANN static Symbol _template_id(const Env env, struct tmpl_info *const info, const size_t sz) {
INTERP_PRINTF("None")
}
+static OP_CHECK(opck_none) {
+ Exp_Binary *bin = (Exp_Binary*)data;
+ CHECK_NN(opck_rassign(env, data, mut))
+ exp_setvar(bin->rhs, 1);
+ return bin->rhs->info->type;
+}
+
+static OP_EMIT(opem_none) {
+ const Instr instr = emit_add_instr(emit, RegPop);
+ instr->m_val = SZ_INT;
+ return GW_OK;
+}
+
static const f_instr dotmember[] = { DotMember, DotMember2, DotMember3, DotMember4 };
ANN Instr emit_kind(Emitter emit, const m_uint size, const uint addr, const f_instr func[]);
struct SpecialId_ spid = { .type=gwi->gwion->type[et_none], .exec=NoOp, .is_const=1 };
gwi_specialid(gwi, "None", &spid);
+ GWI_BB(gwi_oper_ini(gwi, "None", "None", "None"))
+ GWI_BB(gwi_oper_add(gwi, opck_none))
+ GWI_BB(gwi_oper_emi(gwi, opem_none))
+ GWI_BB(gwi_oper_end(gwi, "=>", NoOp))
+
const Type t_union = gwi_class_ini(gwi, "@Union", "Object");
gwi_class_xtor(gwi, NULL, UnionDtor);
GWI_BB(gwi_item_ini(gwi, "int", "@index"))
}
ANN Type check_array_access(const Env env, const Array_Sub array) {
- if(!get_depth(array->type))
- ERR_O(array->exp->pos, _("array subscripts (%"UINT_F") exceeds defined dimension (%"UINT_F")"),
- array->depth, get_depth(array->type))
+// if(!get_depth(array->type))
+// ERR_O(array->exp->pos, _("array subscripts (%"UINT_F") exceeds defined dimension (%"UINT_F")"),
+// array->depth, get_depth(array->type))
const Symbol sym = insert_symbol("@array");
struct Op_Import opi = { .op=sym, .lhs=array->exp->info->type, .rhs=array->type,
.pos=array->exp->pos, .data=(uintptr_t)array, .op_type=op_array };
const Type ret = op_check_inner(&ock);
if(ret) {
if(ret == env->gwion->type[et_error])
- break;
+ return NULL;
if(!ock.mut)
set_nspc(&opi2, nspc);
return ret;
} while(l && (l = l->info->parent));
}
} while((nspc = nspc->parent));
-// if(env->func && env->func->nspc)
if(opi->op == insert_symbol(env->gwion->st, "$") && opi->rhs == opi->lhs)
return opi->rhs;
if(opi->op == insert_symbol(env->gwion->st, "@func_check"))
-#! [contains] no match found for operator
+#! [contains] can't cast
<<< [ 1 ] $ int[][] >>>;
+++ /dev/null
-class C {
- 12 => var int _i;
- union {
- int i;
- float f;
- } U;
-
- <<< U >>>;
- <<< U.i >>>;
- <<< U.f >>>;
- 12 => U.i;
- <<< U.i >>>;
- 12.3 => U.f;
- <<< U.f >>>;
- <<< U.i >>>;
-}
-
-var C c;
-
-<<< c >>>;
-<<< c.U >>>;
-<<< c.U.i >>>;
-<<< c.U.f >>>;
-123 => c.U.i;
-<<< c.U.i >>>;
-1.23 => c.U.f;
-<<< c.U.f >>>;
-<<< c.U.i >>>;
-<<< c._i >>>;
-
+++ /dev/null
-class C {
- union
- {
- int one;
- string two;
- };
- <<< one, " ", two >>>;
-}
-
i++;
i ? i : !i;
++i;
- union U { int }
- union V:[A] { int }
+ union U { int i; }
+ union V:[A] { int i; }
typeof(i);
if(i) i; else i;
for(var int _i; _i < 1; ++_i);
+++ /dev/null
-union global {
- int int_from_global_nanmed_union;
- float float_from_global_named_union;
-} global_union;
-
-<<< "HERE", global_union >>>;
-<<< 123.456 => global_union.float_from_global_named_union >>>;
-<<< global_union.float_from_global_named_union >>>;
+++ /dev/null
-union global {
- int int_from_global_union;
- float float_from_global_union;
-};
-
-<<< float_from_global_union >>>;
+++ /dev/null
-15 => var int i;
-union {
- int i;
- float f;
-} U;
-7.3 => var float f;
-<<< U >>>;
-<<< U.i >>>;
-<<< U.f >>>;
-12 => U.i;
-<<< U.i >>>;
-12.3 => U.f;
-<<< U.f >>>;
-<<< U.i >>>;
-<<< i >>>;
-<<< f >>>;
+++ /dev/null
-class C {
- union private static {
- int i;
- } u;
- <<< this, " ", u, " ", this.u.i >>>;
-}
-
-var C c;
-<<< c >>>;
+++ /dev/null
-class C {
- union static {
- int i;
- } u;
- <<< this, " ", u, " ", this.u.i >>>;
-}
-
-var C c;
-<<< c >>>;
-<<< C.u >>>;
-<<< C.u.i >>>;
+++ /dev/null
-class C {
- union static { int : float }
-}
+++ /dev/null
-union U { int : string };
-<<< one, " ", two >>>;
+++ /dev/null
-union global GlobalUnion { int : float };
-<<<"test">>>;
+++ /dev/null
-union U:[A]{ int : A }
-
-var U:[float] u;
-<<< u.a >>>;
--- /dev/null
+None => None;
--- /dev/null
+#! [contains] 12
+var int? i;
+<<< 12 => i.val >>>;
+<<< i.val >>>;
--- /dev/null
+#! [contains] 12
+var int? i;
+
+<<< 12 => i.val >>>;
+if(i.is(val))
+ <<< i.val >>>;
+#!<<< None => i.none >>>;
+#!if(i.is(none))
+#! <<< "option unset" >>>;
--- /dev/null
+#! [contains] invalid union acces
+var int? i;
+<<< i.val >>>;
--- /dev/null
+union U {
+ int i;
+ float f;
+}
+
+var U u;
+<<< u.i >>>;
+
+<<< u.f >>>;
+