<<< i, " ", j, " ", o, " ", p, " ", r, " ", s, " ", t, " ", k >>>;
[ 1.0, 2, 3, 4, 5 ];
-[ #(0.0, 0.0) ];
-[ @(0.0, 0.0, 0.0) ];
-[ @(0.0, 0.0, 0.0, 0.0) ];
+[ complex(0.0, 0.0) ];
+[ Vec3(0.0, 0.0, 0.0) ];
+[ Vec4(0.0, 0.0, 0.0, 0.0) ];
1 => test;
1.3 => test;
test(1);
-@(23) => test;
+Vec3(23) => test;
test(1.3);
C->D d => test;
#! write members
<<< 12 => c.i >>>;
<<< 1.2 => c.f >>>;
-<<< #(0.1, 2.3) => c.c >>>;
-<<< @(0.1, 2.3, 3.4) => c.v >>>;
-<<< @(0.1, 2.3, 3.4, 5.4) => c.w >>>;
+<<< complex(0.1, 2.3) => c.c >>>;
+<<< Vec3(0.1, 2.3, 3.4) => c.v >>>;
+<<< Vec4(0.1, 2.3, 3.4, 5.4) => c.w >>>;
<<< null @=> c.o >>>;
operator => float (C c, C d){ <<< "float => C: ", c.f => d.f >>>; return 2.0;}
operator => int (int i, C d){ <<< "int => C: ", i => d.f >>>; return 2;}
operator => float (float f, C d){ <<< "float => C: ", f => d.f >>>; return 2.0;}
-operator => complex (complex c, C d){ <<< "complex => C: ", c.re => d.f >>>; return #(1.2, 6.1);}
-operator => polar (polar c, C d){ <<< "complex => C: ", c.mod => d.f >>>; return %(2.3, 4.1);}
-operator => Vec3 (Vec3 c, C d){ <<< c.z => d.f >>>; return @(1.2, 6.1, 2.3);}
-operator => Vec4 (Vec4 c, C d){ <<< "Vec4 => C: ", c.w => d.f >>>; return @(1.2, 6.1, 2.3, 9.3);}
+operator => complex (complex c, C d){ <<< "complex => C: ", c.re => d.f >>>; return complex(1.2, 6.1);}
+operator => polar (polar c, C d){ <<< "complex => C: ", c.mod => d.f >>>; return polar(2.3, 4.1);}
+operator => Vec3 (Vec3 c, C d){ <<< c.z => d.f >>>; return Vec3(1.2, 6.1, 2.3);}
+operator => Vec4 (Vec4 c, C d){ <<< "Vec4 => C: ", c.w => d.f >>>; return Vec4(1.2, 6.1, 2.3, 9.3);}
operator => float (C d, int c){ <<< "int => C: ", c => d.f >>>; return 2.0;}
operator => float (C d, float f){ <<< "C => float: ", f => d.f >>>; return 2.0;}
operator => float (Vec3 v, float f){ <<< "vec3 => C: ", f, " ", v.x => f >>>; return 2.0;}
-operator => complex (C d, complex c){ <<< "complex => C: ", c.re => d.f >>>; return #(1.2, 6.1);}
-operator => polar (C d, polar c){ <<< "complex => C: ", c.mod => d.f >>>; return %(2.3, 4.1);}
-operator => Vec3 (C d, Vec3 c){ <<< c.z => d.f >>>; return @(1.2, 6.1, 2.3);}
-operator => Vec4 (C d, Vec4 c){ <<< "Vec4 => C: ", c.w => d.f >>>; return @(1.2, 6.1, 2.3, 9.3);}
+operator => complex (C d, complex c){ <<< "complex => C: ", c.re => d.f >>>; return complex(1.2, 6.1);}
+operator => polar (C d, polar c){ <<< "complex => C: ", c.mod => d.f >>>; return polar(2.3, 4.1);}
+operator => Vec3 (C d, Vec3 c){ <<< c.z => d.f >>>; return Vec3(1.2, 6.1, 2.3);}
+operator => Vec4 (C d, Vec4 c){ <<< "Vec4 => C: ", c.w => d.f >>>; return Vec4(1.2, 6.1, 2.3, 9.3);}
C c, d;
12.3 => c.f;
<<< c => d >>>;
<<< 2 => d >>>;
<<< 2.3 => d >>>;
-<<< #(7.2, 1.4) => d >>>;
-<<< %(7.2, 1.4) => d >>>;
-<<< @(7.2, 1.4, 8.3) >>>;
-<<< @(7.2, 1.4, 8.3) => d >>>;
-<<< @(7.2, 1.4, 8.3, 2.3) => d >>>;
+<<< complex(7.2, 1.4) => d >>>;
+<<< polar(7.2, 1.4) => d >>>;
+<<< Vec3(7.2, 1.4, 8.3) >>>;
+<<< Vec3(7.2, 1.4, 8.3) => d >>>;
+<<< Vec4(7.2, 1.4, 8.3, 2.3) => d >>>;
int i;
2 => float f;
#! write members
<<< 12 => C.i >>>;
<<< 1.2 => C.f >>>;
-<<< #(0.1, 2.3) => C.c >>>;
-<<< @(0.1, 2.3, 3.4) => C.v >>>;
-<<< @(0.1, 2.3, 3.4, 5.4) => C.w >>>;
+<<< complex(0.1, 2.3) => C.c >>>;
+<<< Vec3(0.1, 2.3, 3.4) => C.v >>>;
+<<< Vec4(0.1, 2.3, 3.4, 5.4) => C.w >>>;
<<< null @=> C.o >>>;
#!null @=> s;
<<< 1 => s >>>;
<<< 1.0 => s >>>;
-<<< #(2,1) => s >>>;
-<<< %(2,1) => s >>>;
-<<< @(2,1,0) => s >>>;
-<<< @(2,1,0,-1) => s >>>;
+<<< complex(2,1) => s >>>;
+<<< polar(2,1) => s >>>;
+<<< Vec3(2,1,0) => s >>>;
+<<< Vec4(2,1,0,-1) => s >>>;
<<< "test" => s >>>; #! new
<<< "test" => s >>>; #! new
<<< s >>>;
{ (1 + s) @=> string @str; }
{ (2.0 +s) @=> string @str; }
-{ (#(2,1) + s) @=> string @str; }
-{ (%(2,1) + s) @=> string @str; }
-{ (@(2,1, 0) + s) @=> string @str; }
-{ (@(2,1, 0, -1) + s) @=> string @str; }
+{ (complex(2,1) + s) @=> string @str; }
+{ (polar(2,1) + s) @=> string @str; }
+{ (Vec3(2,1, 0) + s) @=> string @str; }
+{ (Vec4(2,1, 0, -1) + s) @=> string @str; }
#!{ ("test" + s) @=> string @str; } // leak
<<< 11 +=> s >>>;
<<< 11.0 +=> s >>>;
-<<< #(21,11) +=> s >>>;
-<<< %(22,12) +=> s >>>;
-<<< @(22,11,11) +=> s >>>;
-<<< @(22,11,11,-11) +=> s >>>;
+<<< complex(21,11) +=> s >>>;
+<<< polar(22,12) +=> s >>>;
+<<< Vec3(22,11,11) +=> s >>>;
+<<< Vec4(22,11,11,-11) +=> s >>>;
<<< o +=> s >>>;
<<< "test" + s >>>; #! also leak
<<< null +=> s >>>; #! also hang
vararg.end;
}
test(1);
-test(1, 2.3, #(3, 2), %(3, 2.1), @(1,2,3), @(1,2,3,4), null);
+test(1, 2.3, complex(3, 2), polar(3, 2.1), Vec3(1,2,3), Vec4(1,2,3,4), null);
<<< 1 => v.x >>>;
<<< 2 => v.y >>>;
<<< -12 => v.z >>>;
-<<< @(.1, .2, .4) => v >>>;
+<<< Vec3(.1, .2, .4) => v >>>;
<<< v >>>;
<<< "set ", v.set(1,2,3) >>>;
<<< "setAll ", v.setAll(1.2) >>>;
w/10.;
10.*w;
w*10.;
-<<< @(23).x >>>;
+<<< Vec3(23).x >>>;
<<< 1 => v.y >>>;
<<< 1 => v.z >>>;
<<< 1 => v.w >>>;
-<<< @(.1, .2, .4, .5) => v >>>;
+<<< Vec3(.1, .2, .4, .5) => v >>>;
<<< "set ", v.set(1,2,3,4) >>>;
<<< "setAll ", v.setAll(1.2) >>>;
return GW_OK;
}
+ANN static void emit_vec_addr(const Emitter emit, const m_uint sz) {
+ emit_local(emit, sz, 0);
+ const m_uint offset = emit_local(emit, SZ_INT, 0);
+ const Instr cpy = emit_add_instr(emit, VecCpy);
+ cpy->m_val = offset;
+ cpy->m_val2 = sz;
+ const Instr instr = emit_add_instr(emit, RegPushMem);
+ 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_local(emit, prim_exp(vec)->type->size, 0);
- const m_uint offset = emit_local(emit, SZ_INT, 0);
- const Instr cpy = emit_add_instr(emit, VecCpy);
- cpy->m_val = offset;
- cpy->m_val2 = prim_exp(vec)->type->size;
- const Instr instr = emit_add_instr(emit, RegPushMem);
- instr->m_val = offset;
- }
+ if(prim_exp(vec)->emit_var)
+ emit_vec_addr(emit, prim_exp(vec)->type->size);
return GW_OK;
}
}
ANN static m_bool emit_exp_call(const Emitter emit, const Exp_Call* exp_call) {
- CHECK_BB(prepare_call(emit, exp_call))
- return emit_exp_call1(emit, exp_call->m_func) ? GW_OK : GW_ERROR;
+ if(exp_call->m_func) {
+ CHECK_BB(prepare_call(emit, exp_call))
+ return emit_exp_call1(emit, exp_call->m_func) ? GW_OK : GW_ERROR;
+ }
+ 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);
+ return GW_OK;
}
ANN static m_uint get_decl_size(Var_Decl_List a) {
}
EQUALITY_OPER(complex, SZ_COMPLEX)
-
+OP_CHECK(vecx_ck);
GWION_IMPORT(complex) {
// should be special
const Type t_complex = gwi_class_spe(gwi, "complex", SZ_COMPLEX);
GWI_BB(gwi_item_ini(gwi, "float", "phase"))
GWI_BB(gwi_item_end(gwi, ae_flag_member, NULL))
GWI_BB(gwi_class_end(gwi))
+
+ GWI_BB(gwi_oper_ini(gwi, "complex", NULL, NULL))
+ GWI_BB(gwi_oper_add(gwi, vecx_ck))
+ GWI_BB(gwi_oper_end(gwi, "@ctor", NULL))
+ GWI_BB(gwi_oper_ini(gwi, "polar", NULL, NULL))
+ GWI_BB(gwi_oper_add(gwi, vecx_ck))
+ GWI_BB(gwi_oper_end(gwi, "@ctor", NULL))
GWI_BB(gwi_oper_ini(gwi, "complex", "complex", "bool"))
GWI_BB(gwi_oper_end(gwi, "==", complex_eq))
GWI_BB(gwi_oper_end(gwi, "!=", complex_ne))
EQUALITY_OPER(vec3, SZ_VEC3);
+OP_CHECK(vecx_ck) {
+ Exp_Call *call = (Exp_Call*)data;
+ Exp e = call->args, last = NULL;
+ int i = 0;
+ const Type t_float = env->gwion->type[et_float];
+ while(e) {
+ CHECK_BO(check_implicit(env, e, t_float))
+ i += SZ_FLOAT;
+ last = e;
+ e = e->next;
+ }
+ const Type t = call->func->type->e->d.base_type;
+ while(i > t->size) {
+ env_err(env, last->pos, "extraneous component of %s value", t->name);
+ return NULL;
+ }
+ if(!call->args) {
+ call->args = last = new_prim_float(env->gwion->mp, 0.0, loc_cpy(env->gwion->mp, call->func->pos));
+ last->type = t_float;
+ i += SZ_FLOAT;
+ }
+ while(i < t->size) {
+ last = (last->next = new_prim_float(env->gwion->mp, 0.0, loc_cpy(env->gwion->mp, last->pos)));
+ last->type = t_float;
+ i += SZ_FLOAT;
+ }
+ return t;
+}
+
GWION_IMPORT(vec3) {
const Type t_vec3 = gwi_class_spe(gwi, "Vec3", SZ_VEC3);
gwi->gwion->type[et_vec3] = t_vec3;
GWI_BB(gwi_func_end(gwi, vec3_update_set_slew, ae_flag_none))
GWI_BB(gwi_class_end(gwi))
+ GWI_BB(gwi_oper_ini(gwi, "Vec3", NULL, NULL))
+ GWI_BB(gwi_oper_add(gwi, vecx_ck))
+ GWI_BB(gwi_oper_end(gwi, "@ctor", NULL))
+
GWI_BB(gwi_oper_ini(gwi, "Vec3", "Vec3", "bool"))
GWI_BB(gwi_oper_end(gwi, "==", vec3_eq))
GWI_BB(gwi_oper_end(gwi, "!=", vec3_ne))
gwi_func_ini(gwi, "void", "normalize");
CHECK_BB(gwi_func_end(gwi, vec4_normalize, ae_flag_none))
CHECK_BB(gwi_class_end(gwi))
+
+ GWI_BB(gwi_oper_ini(gwi, "Vec4", NULL, NULL))
+ GWI_BB(gwi_oper_add(gwi, vecx_ck))
+ GWI_BB(gwi_oper_end(gwi, "@ctor", NULL))
+
GWI_BB(gwi_oper_ini(gwi, "Vec4", "Vec4", "bool"))
GWI_BB(gwi_oper_end(gwi, "==", vec4_eq))
GWI_BB(gwi_oper_end(gwi, "!=", vec4_ne))
return GW_OK;
}
-ANN static inline m_bool check_implicit(const Env env, const Exp e, const Type t) {
+ANN /*static inline */m_bool check_implicit(const Env env, const Exp e, const Type t) {
const Symbol sym = insert_symbol("@implicit");
return check_internal(env, sym, e, t);
}
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;
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_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 Type check_exp_call1(const Env env, const Exp_Call *exp) {
CHECK_BO(check_exp_call1_check(env, exp->func))
+ if(isa(exp->func->type, env->gwion->type[et_function]) < 0) {
+ 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);
+ }
if(exp->func->type == env->gwion->type[et_lambda])
return check_lambda_call(env, exp);
if(GET_FLAG(exp->func->type->e->d.func, ref)) {
2 => i[0];
5.7 => f[0];
- #(2.1, 3.4) => c[0];
- %(2.3, 5.6) => p[0];
- @(2.1, 3.2, 4.3) => v[0];
- @(2.1, 3.2, 4.3, 5.4) => w[0];
+ complex(2.1, 3.4) => c[0];
+ polar(2.3, 5.6) => p[0];
+ Vec3(2.1, 3.2, 4.3) => v[0];
+ Vec4(2.1, 3.2, 4.3, 5.4) => w[0];
i << 1;
f << 1.2;
- c << #(2.1, 3.4);
- p << %(2.3, 5.6);
- v << @(2.1, 3.2, 4.3);
- w << @(2.1, 3.2, 4.3, 5.4);
+ c << complex(2.1, 3.4);
+ p << polar(2.3, 5.6);
+ v << Vec3(2.1, 3.2, 4.3);
+ w << Vec4(2.1, 3.2, 4.3, 5.4);
<<< i.size() >>>;
}
#! [contains] extraneous component of complex value
- #(0,0,0,0);
+ complex(0,0,0,0);
#! [contains] ZeroDivideException
-[ #(0.0, 0/0) ];
+[ complex(0.0, 0/0) ];
#! [contains] extraneous component of polar value
-%(0,0,0,0);
+polar(0,0,0,0);
<<<vararg.i>>>;
vararg.end;
}
-@(1.3) => test;
+Vec3(1.3) => test;
#! [contains] extraneous component of
- @(0,0,0,0,0);
+ Vec4(0,0,0,0,0);
<<< 1 => Coverage.s_i >>>;
<<< 1.2 => Coverage.s_f >>>;
-<<< #(1.2, 0.1) => Coverage.s_c >>>;
-<<< @(1.2, 0.1, 2.6) => Coverage.s_v >>>;
-<<< @(1.2, 0.1, 2.6, 4.6) => Coverage.s_w >>>;
+<<< complex(1.2, 0.1) => Coverage.s_c >>>;
+<<< Vec3(1.2, 0.1, 2.6) => Coverage.s_v >>>;
+<<< Vec4(1.2, 0.1, 2.6, 4.6) => Coverage.s_w >>>;
<<< c.test_array[0][0] >>>;
<<< 3 => pure >>>;
<<< 4 => pure >>>;
<<< 2.2 => pure >>>;
-<<< @(2.3) => pure >>>;
+<<< Vec3(2.3) => pure >>>;
<<< 3 => pure >>>;
<<< 4 => pure >>>;
<<< 2.2 => pure >>>;
-<<< @(2.3) => pure >>>;
+<<< Vec3(2.3) => pure >>>;
}
C c;
--- /dev/null
+class B {}
+
+class<~A~>C extends B{}
+
+class<~A,B~>D extends<~A~>C{
+ class<~A~>int{}
+ class G extends ld
+ {A0I:}
+ <~A~>d d;
+}
+
+<~int~>D d;
test(1.2);
1.2 => test;
-test(#(2.3, 4.5));
-#(2.3, 4.5) => test;
+test(complex(2.3, 4.5));
+complex(2.3, 4.5) => test;
-test(@(1.2, 2.3, 3.4));
-@(1.2, 2.3, 3.4) => test;
+test(Vec3(1.2, 2.3, 3.4));
+Vec3(1.2, 2.3, 3.4) => test;
-test(@(1.2, 2.3, 3.4, 4.5));
-@(1.2, 2.3, 3.4, 4.5) => test;
+test(Vec4(1.2, 2.3, 3.4, 4.5));
+Vec4(1.2, 2.3, 3.4, 4.5) => test;
class C
{
c.test(1.2);
1.2 => c.test;
-c.test(#(2.3, 4.5));
-#(2.3, 4.5) => c.test;
+c.test(complex(2.3, 4.5));
+complex(2.3, 4.5) => c.test;
-c.test(@(1.2, 2.3, 3.4));
-@(1.2, 2.3, 3.4) => c.test;
+c.test(Vec3(1.2, 2.3, 3.4));
+Vec3(1.2, 2.3, 3.4) => c.test;
-c.test(@(1.2, 2.3, 3.4, 4.5));
-@(1.2, 2.3, 3.4, 4.5) => c.test;
+c.test(Vec4(1.2, 2.3, 3.4, 4.5));
+Vec4(1.2, 2.3, 3.4, 4.5) => c.test;
c.s_test();
() => c.s_test;
c.s_test(1.2);
1.2 => c.s_test;
-c.s_test(#(2.3, 4.5));
-#(2.3, 4.5) => c.s_test;
+c.s_test(complex(2.3, 4.5));
+complex(2.3, 4.5) => c.s_test;
-c.s_test(@(1.2, 2.3, 3.4));
-@(1.2, 2.3, 3.4) => c.s_test;
+c.s_test(Vec3(1.2, 2.3, 3.4));
+Vec3(1.2, 2.3, 3.4) => c.s_test;
-c.s_test(@(1.2, 2.3, 3.4, 4.5));
-@(1.2, 2.3, 3.4, 4.5) => c.s_test;
+c.s_test(Vec4(1.2, 2.3, 3.4, 4.5));
+Vec4(1.2, 2.3, 3.4, 4.5) => c.s_test;
C.s_test();
() => C.s_test;
C.s_test(1.2);
1.2 => C.s_test;
-C.s_test(#(2.3, 4.5));
-#(2.3, 4.5) => C.s_test;
+C.s_test(complex(2.3, 4.5));
+complex(2.3, 4.5) => C.s_test;
-C.s_test(@(1.2, 2.3, 3.4));
-@(1.2, 2.3, 3.4) => C.s_test;
+C.s_test(Vec3(1.2, 2.3, 3.4));
+Vec3(1.2, 2.3, 3.4) => C.s_test;
-C.s_test(@(1.2, 2.3, 3.4, 4.5));
-@(1.2, 2.3, 3.4, 4.5) => C.s_test;
+C.s_test(Vec4(1.2, 2.3, 3.4, 4.5));
+Vec4(1.2, 2.3, 3.4, 4.5) => C.s_test;
[ 1 ];
int i,j;
typeof(i) k;
- @(0);
+ Vec3(0);
'a';
true $ int;
i++;
#! a vec3 with only two expressions
-[ @(0.0- 0.0, 0.0) ];
+[ Vec3(0.0- 0.0, 0.0) ];
-<(.2, @(1), 3) @=> <~float, Vec3, int~>Tuple @t;
+<(.2, Vec3(1), 3) @=> <~float, Vec3, int~>Tuple @t;
t[0];
t[1];
3 => t[2];