instr->m_val = offset;
}
-ANN static m_bool emit_prim_vec(const Emitter emit, const Vec *vec) {
- const ae_prim_t t = prim_self(vec)->prim_type;
- CHECK_BB(emit_exp(emit, vec->exp, 0));
- m_int n = (m_int)((t == ae_prim_vec ? 3 : 2) - vec->dim + 1);
- while(--n > 0)
- emit_add_instr(emit, RegPushImm2);
- if(prim_exp(vec)->emit_var)
- emit_vec_addr(emit, prim_exp(vec)->type->size);
- return GW_OK;
-}
-
ANN static m_bool emit_prim_id(const Emitter emit, const Symbol *data) {
struct SpecialId_ * spid = specialid_get(emit->gwion, *data);
if(spid)
return emit_symbol(emit, prim_self(data));
}
-ANN static m_bool emit_prim_tuple(const Emitter emit, const Tuple *tuple) {
- CHECK_BB(emit_exp(emit, tuple->exp, 1))
- const Instr instr = emit_add_instr(emit, TupleCtor);
- instr->m_val = (m_uint)prim_exp(tuple)->type;
- return GW_OK;
-}
-
ANN static m_bool emit_prim_num(const Emitter emit, const m_uint *num) {
regpushi(emit, *num);
return GW_OK;
}
if(exp_call->args)
CHECK_BB(emit_exp(emit, exp_call->args, 1))
- const Exp e = exp_self(exp_call);
- if(e->emit_var)
- emit_vec_addr(emit, e->type->size);
+ struct Op_Import opi = { .op=insert_symbol("@ctor"), .lhs=exp_call->func->type->e->d.base_type, .data=(uintptr_t)exp_call, .pos=exp_self(exp_call)->pos };
+ CHECK_OB(op_emit(emit, &opi))
+ const Exp e = exp_self(exp_call);
+ if(e->emit_var)
+ emit_vec_addr(emit, e->type->size);
return GW_OK;
}
return at_depth(env, &next);
}
+static OP_CHECK(tuple_ck) {
+ const Exp_Call *call = (Exp_Call*)data;
+ const Exp exp = call->args;
+ CHECK_OO(check_exp(env, exp))
+ struct Vector_ v;
+ vector_init(&v);
+ Exp e = exp;
+ do vector_add(&v, (m_uint)e->type);
+ while((e = e->next));
+ const Type ret = tuple_type(env, &v, exp_self(call)->pos);
+ vector_release(&v);
+ return ret;
+}
+
+static OP_EMIT(tuple_em) {
+ const Exp_Call *call = (Exp_Call*)data;
+ const Instr instr = emit_add_instr(emit, TupleCtor);
+ instr->m_val = (m_uint)exp_self(call)->type;
+ return instr;
+}
+
GWION_IMPORT(tuple) {
const Type t_tuple = gwi_mk_type(gwi, "Tuple", SZ_INT, "Object");
gwi_add_type(gwi, t_tuple);
SET_FLAG(t_tuple, checked | ae_flag_scan2 | ae_flag_check | ae_flag_emit);
gwi->gwion->type[et_tuple] = t_tuple;
SET_FLAG(t_tuple, abstract | ae_flag_template);
+ GWI_BB(gwi_oper_ini(gwi, "Tuple", NULL, NULL))
+ GWI_BB(gwi_oper_add(gwi, tuple_ck))
+ GWI_BB(gwi_oper_emi(gwi, tuple_em))
+ GWI_BB(gwi_oper_end(gwi, "@ctor", NULL))
GWI_BB(gwi_oper_ini(gwi, "Object", "Tuple", NULL))
GWI_BB(gwi_oper_add(gwi, opck_at_tuple))
GWI_BB(gwi_oper_emi(gwi, opem_at_tuple))
OP_CHECK(vecx_ck) {
Exp_Call *call = (Exp_Call*)data;
Exp e = call->args, last = NULL;
- int i = 0;
+ size_t i = 0;
const Type t_float = env->gwion->type[et_float];
while(e) {
CHECK_BO(check_implicit(env, e, t_float))
return prim_id_non_res(env, data);
}
-ANN static m_bool vec_value(const Env env, Exp e) {
- CHECK_OB(check_exp(env, e))
- const Type t_float = env->gwion->type[et_float];
- do CHECK_BB(check_implicit(env, e, t_float))
- while((e = e->next));
- return GW_OK;
-}
-
-struct VecInfo {
- Type t;
- m_str s;
- m_uint n;
-};
-
-ANN static void vec_info(const Env env, const ae_prim_t t, struct VecInfo* v) {
- if(t == ae_prim_complex) {
- v->s = "complex";
- v->t = env->gwion->type[et_complex];
- v->n = 2;
- } else if(t == ae_prim_vec) {
- v->t = env->gwion->type[v->n == 4 ? et_vec4 : et_vec3];
- v->n = 4;
- v->s = "vector";
- } else {
- v->s = "polar";
- v->t = env->gwion->type[et_polar];
- v->n = 2;
- }
-}
-
-ANN static Type check_prim_vec(const Env env, const Vec *vec) {
- const ae_prim_t t = prim_self(vec)->prim_type;
- struct VecInfo info = { .n=vec->dim };
- vec_info(env, t, &info);
- if(vec->dim > info.n)
- ERR_O(vec->exp->pos, _("extraneous component of %s value..."), info.s)
- CHECK_BO(vec_value(env, vec->exp))
- return info.t;
-}
-
ANN static Type check_prim_hack(const Env env, const Exp *data) {
if(env->func)
UNSET_FLAG(env->func, pure);
return env->gwion->type[et_gack];
}
-ANN static Type check_prim_tuple(const Env env, const Tuple *tuple) {
- CHECK_OO(check_exp(env, tuple->exp))
- struct Vector_ v;
- vector_init(&v);
- Exp e = tuple->exp;
- do vector_add(&v, (m_uint)e->type);
- while((e = e->next));
- const Type ret = tuple_type(env, &v, prim_pos(tuple));
- vector_release(&v);
- return ret;
-}
-
#define describe_prim_xxx(name, type) \
ANN static Type check##_prim_##name(const Env env NUSED, const union prim_data* data NUSED) {\
return type; \
ANN2(1,2) static Func find_func_match_actual(const Env env, Func func, const Exp args,
const m_bool implicit, const m_bool specific) {
-printf("func %p %s\n", func, func->name);
do {
Exp e = args;
Arg_List e1 = func->def->base->args;
return func->def->base->ret_type;
}
-ANN static m_bool check_exp_call1_check(const Env env, const Exp exp) {
- CHECK_OB(check_exp(env, exp))
- if(isa(exp->type, env->gwion->type[et_function]) < 0) {
- if(isa(exp->type, env->gwion->type[et_class]) > 0) {
-puts("here:!:");
-//const Type t = exp->type->e->d.base_type;
-//const Func func = nspc_lookup_func0(t->e->owner, insert_symbol(t->name));
-//exp->type = func->value_ref->type;
- } else
- ERR_B(exp->pos, _("function call using a non-function value"))
- }
- return GW_OK;
-}
-
ANN static Type check_lambda_call(const Env env, const Exp_Call *exp) {
if(exp->args)
CHECK_OO(check_exp(env, exp->args))
}
ANN Type check_exp_call1(const Env env, const Exp_Call *exp) {
- CHECK_BO(check_exp_call1_check(env, exp->func))
+ CHECK_OO(check_exp(env, exp->func))
if(isa(exp->func->type, env->gwion->type[et_function]) < 0) {
+ if(isa(exp->func->type, env->gwion->type[et_class]) < 0)
+ ERR_O(exp->func->pos, _("function call using a non-function value"))
if(exp->args)
CHECK_OO(check_exp(env, exp->args))
struct Op_Import opi = { .op=insert_symbol("@ctor"), .lhs=exp->func->type->e->d.base_type, .data=(uintptr_t)exp, .pos=exp_self(exp)->pos };
- return op_check(env, &opi);
+ const Type t = op_check(env, &opi);
+ exp_self(exp)->nspc = t ? t->e->owner : NULL;
+ return t;
}
if(exp->func->type == env->gwion->type[et_lambda])
return check_lambda_call(env, exp);
return scan1_exp(env, prim->d.array->exp);
if(prim->prim_type == ae_prim_range)
return scan1_range(env, prim->d.range);
- if(prim->prim_type == ae_prim_tuple)
- return scan1_exp(env, prim->d.tuple.exp);
// if(prim->prim_type == ae_prim_unpack)
// return scan1_exp(env, prim->d.tuple.exp);
return GW_OK;
return scan2_exp(env, prim->d.array->exp);
else if(prim->prim_type == ae_prim_range)
return scan2_range(env, prim->d.range);
- if(prim->prim_type == ae_prim_tuple)
- return scan2_exp(env, prim->d.tuple.exp);
return GW_OK;
}
-<([1,2], "Tom") @=> <~int[], string~>Tuple @tup;
+Tuple([1,2], "Tom") @=> <~int[], string~>Tuple @tup;
#!<<<tup[1]>>>;
#!<<<tup[0][1]>>>;
#!<<< t[0] >>>;
#!null @=> t[0];
<<< t >>>;
-<("tom", 12) @=> t[0];
-#!t << <("tom", 12);
+Tuple("tom", 12) @=> t[0];
+#!t << Tuple("tom", 12);
#!<<< t.size() >>>;
#!<<< t[0][0] >>>;
#!<<< t[0][1] >>>;
#! [contains] no match found for operator
-<(1) $ Object;
+Tuple(1) $ Object;
#! [contains] can't cast
-<(1) @=> <~int~>Ptr ptr;
+Tuple(1) @=> <~int~>Ptr ptr;
-<<< <("Tom", 12)[0] >>> ;
-#! <<< <("Tom", 12)[1] >>> ;
+<<< Tuple("Tom", 12)[0] >>> ;
+#! <<< Tuple("Tom", 12)[1] >>> ;
-#! <<< <("Tom", 12) @=> <~string, int~>Tuple @t >>> ;
+#! <<< Tuple("Tom", 12) @=> <~string, int~>Tuple @t >>> ;
#! <<< t[0] >>> ;
#! <<< t[1] >>> ;
-<("Tom", 12)[0][2];
+Tuple("Tom", 12)[0][2];
#!null @=> t[0];
<<< t >>>;
<<< t[0] >>>;
-<<< <("tom", 12) @=> t[0] >>> ;
+<<< Tuple("tom", 12) @=> t[0] >>> ;
-#!t << <("tom", 12);
+#!t << Tuple("tom", 12);
#!<<< t.size() >>>;
#!<<< t[0][0] >>>;
#!<<< t[0][1] >>>;
int i;
-<("Tom", 12)[i];
+Tuple("Tom", 12)[i];
-<(1.2,"test")[3];
+Tuple(1.2,"test")[3];
-<<< <("Tom", 6) @=>
+<<< Tuple("Tom", 6) @=>
<~string, int~>Tuple @tup >>>;
<<< typeof(tup) >>>;
<<< tup >>>;
-<("Tom", 6) @=>
+Tuple("Tom", 6) @=>
<~float, int~>Tuple @tup;
<<< typeof(tup) >>>;
<<< tup >>>;
#! [contains] cannot assign
-<("Tom", 6) @=> <("Pat", 22);
+Tuple("Tom", 6) @=> Tuple("Pat", 22);
-<(1) $ <~int~>Tuple;
+Tuple(1) $ <~int~>Tuple;
<<< t[0] >>>;
}
-<( "Tom", 21) => test;
-#!<("Tom") => test;
+Tuple( "Tom", 21) => test;
+#!Tuple("Tom") => test;
fun void test(C c) {
}
-<(1) => test;
+Tuple(1) => test;
-<( new int);
+Tuple( new int);
-<(.2, Vec3(1), 3) @=> <~float, Vec3, int~>Tuple @t;
+Tuple(.2, Vec3(1), 3) @=> <~float, Vec3, int~>Tuple @t;
t[0];
t[1];
3 => t[2];
-<(1, 2, 3) @=> >(b, _, c);
+Tuple(1, 2, 3) @=> >(b, _, c);
<<< c >>>;
-<("Tom", 2, "Taxi driver") @=> <~string,_, string~>Tuple @t;
+Tuple("Tom", 2, "Taxi driver") @=> <~string,_, string~>Tuple @t;
<<< t>>>;
<<< t[0]>>>;
-<("Tom", 2.3, "Cook") @=> t;
+Tuple("Tom", 2.3, "Cook") @=> t;
#!<<< t[1]>>>;
<<< t[2]>>>;
#! [contains] already been defined in the same scope
int i;
-<(12) @=> >(i);
+Tuple(12) @=> >(i);