[ 1.0, 2, 3, 4, 5 ];
[ complex(0.0, 0.0) ];
-[ Vec3(0.0, 0.0, 0.0) ];
-[ Vec4(0.0, 0.0, 0.0, 0.0) ];
polar p[4][4];
<<< p[2][3] >>>;
<<< p[2][3].mod >>>;
-
-Vec3 v[4][4];
-<<< v[2][3] >>>;
-<<< v[2][3].x >>>;
-
-Vec4 w[4][4];
-<<< w[2][3] >>>;
-<<< w[2][3].w >>>;
-<<< a[2][3].i >>>;
1 => test;
1.3 => test;
test(1);
-Vec3(23) => test;
test(1.3);
C->D d => test;
float f;
complex c;
polar p;
- Vec3 v;
- Vec4 w;
Object o;
operator @dtor void () { <<< "dtor" >>>; }
}
int i;
float f;
complex c;
- Vec3 v;
- Vec4 w;
Object o;
fun int m_i() { return i; }
fun float m_f() { return f; }
fun complex m_c() { return c; }
- fun Vec3 m_v() { return v; }
- fun Vec4 m_w() { return w; }
fun Object m_o() { return o; }
}
C c;
#! read members
-<<< c.i, c.c, c.f, c.v, c.w, c.o >>>;
+<<< c.i, c.c, c.f, c.o >>>;
#! call fun members
-<<< c.m_i(), " ", c.m_f(), " ", c.m_c(), " ",
- c.m_v(), " ", c.m_w(), " ", c.m_o() >>>;
+<<< c.m_i(), " ", c.m_f(), " ", c.m_c(), " ", c.m_o() >>>;
#! write members
<<< 12 => c.i >>>;
<<< 1.2 => c.f >>>;
<<< 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 (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 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 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;
<<< 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;
complex cmp;
-Vec3 v;
<<< f >>>;
-v => f;
-Vec4 w;
c => i;
<<< c.f >>>;
<<< f >>>;
c => f;
c => cmp;
-c => v;
-c => w;
static int i;
static float f;
static complex c;
- static Vec3 v;
- static Vec4 w;
static Object o;
fun int m_i() { return i; }
fun float m_f() { return f; }
fun complex m_c() { return c; }
- fun Vec3 m_v() { return v; }
- fun Vec4 m_w() { return w; }
fun Object m_o() { return o; }
fun static int _i() { return i; }
fun static float _f() { return f; }
fun static complex _c() { return c; }
- fun static Vec3 _v() { return v; }
- fun static Vec4 _w() { return w; }
fun static Object _o() { return o; }
}
#! read members
-<<< C.i, C.c, C.f, C.v, C.w, C.o >>>;
+<<< C.i, C.c, C.f, C.o >>>;
#! call fun members
-<<< C._i(), " ", C._f(), " ", C._c(), " ", C._v(), " ", C._w(), " ", C._o() >>>;
+<<< C._i(), " ", C._f(), " ", C._c(), " ", C._o() >>>;
#! write members
<<< 12 => C.i >>>;
<<< 1.2 => C.f >>>;
<<< 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 >>>;
<<< 1.0 => 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 >>>;
{ (2.0 +s) @=> string ref str; }
{ (complex(2,1) + s) @=> string ref str; }
{ (polar(2,1) + s) @=> string ref str; }
-{ (Vec3(2,1, 0) + s) @=> string ref str; }
-{ (Vec4(2,1, 0, -1) + s) @=> string ref str; }
#!{ ("test" + s) @=> string ref str; } // leak
<<< 11.0 +=> 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
else if(i == 3)
<<< vararg $ polar >>>;
else if(i == 4)
- <<< vararg $ Vec3 >>>;
- else if(i == 5)
- <<< vararg $ Vec4 >>>;
- else if(i == 6)
<<< vararg $ Object >>>;
i++;
vararg.end;
}
test(1);
-test(1, 2.3, complex(3, 2), polar(3, 2.1), Vec3(1,2,3), Vec4(1,2,3,4), null);
+test(1, 2.3, complex(3, 2), polar(3, 2.1), null);
+++ /dev/null
-Vec3 v, w;
-
-<<< v == w >>>;
-<<< v != w >>>;
-
-<<< v + w >>>;
-<<< v - w >>>;
-<<< v * w >>>;
-<<< v / w >>>;
-
-
-<<< v.x >>>;
-<<< v.y >>>;
-<<< v.z >>>;
-<<< 1 => v.x >>>;
-<<< 2 => v.y >>>;
-<<< -12 => v.z >>>;
-<<< Vec3(.1, .2, .4) => v >>>;
-<<< v >>>;
-<<< "set ", v.set(1,2,3) >>>;
-<<< "setAll ", v.setAll(1.2) >>>;
-<<< "should be 1.2 1.2 1.2 ", v >>>;
-<<< "Update ", v.update(2) >>>;
-<<< "Update ", v.update(2, .1) >>>;
-<<< "Update ", v.supdate(2) >>>;
-<<< "Update ", v.supdate(2, .1) >>>;
-<<< "magnitude ", v.magnitude() >>>;
-<<< "normalize ", v.normalize() >>>;
-<<< "interp ", v.interp() >>>;
-<<< "interp ", v.interp(2.3) >>>;
-<<< "interp ", v.interp(2.3::samp) >>>;
-
-w.setAll(1);
-v+w;
-v-w;
-v*w;
-v/.1;
-10.+w;
-w+10.;
-10.-w;
-w-10.;
-10./w;
-w/10.;
-10.*w;
-w*10.;
-<<< Vec3(23).x >>>;
+++ /dev/null
-Vec4 v, w;
-<<< v >>>;
-
-<<< v == w>>>;
-<<< v != w>>>;
-
-<<< v + w>>>;
-<<< v - w>>>;
-<<< v * w>>>;
-<<< v / w>>>;
-
-<<< 1.3 + w>>>;
-<<< 1.4 - w>>>;
-<<< 1.4 * w>>>;
-<<< 1.5 / w>>>;
-
-<<< v.x >>>;
-<<< v.y >>>;
-<<< v.z >>>;
-<<< v.w >>>;
-
-<<< 1 => v.x >>>;
-<<< 1 => v.y >>>;
-<<< 1 => v.z >>>;
-<<< 1 => v.w >>>;
-<<< Vec4(.1, .2, .4, .5) => v >>>;
-
-<<< "set ", v.set(1,2,3,4) >>>;
-<<< "setAll ", v.setAll(1.2) >>>;
-<<< "should be 1.2 1.2 1.2 ", v >>>;
-<<< "magnitude ", v.magnitude() >>>;
-<<< "normalize ", v.normalize() >>>;
-w.setAll(1);
-v+w;
-v-w;
-v*w;
-v*2.0;
-.5*v;
-v/.2;
-v=>w;
-v+1.;
-v-1.;
-1.+w;
-w+2.;
#define __LANG_PRIVATE
ANN m_bool import_prim(const Gwi gwi);
ANN m_bool import_complex(const Gwi gwi);
-ANN m_bool import_vec3(const Gwi gwi);
-ANN m_bool import_vec4(const Gwi gwi);
ANN m_bool import_object(const Gwi gwi);
ANN m_bool import_vararg(const Gwi gwi);
ANN m_bool import_string(const Gwi gwi);
}
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;
+ regpop(emit, sz - SZ_INT);
+ const Instr cpy = emit_add_instr(emit, Reg2RegAddr);
+ cpy->m_val = -SZ_INT;
}
ANN static m_bool emit_prim_id(const Emitter emit, const Symbol *data) {
const m_uint index = emit_code_size(emit);
const Instr cpy = emit_add_instr(emit, Reg2RegAddr);
cpy->m_val2 = -SZ_INT;
+ regpushi(emit, SZ_INT);
emit_add_instr(emit, int_post_dec);
const Instr op = emit_add_instr(emit, BranchEqInt);
CHECK_BB(scoped_stmt(emit, stmt->body, 1))
GWI_BB(gwi_oper_end(gwi, "new", NULL))
GWI_BB(import_prim(gwi))
GWI_BB(import_complex(gwi))
- GWI_BB(import_vec3(gwi))
- GWI_BB(import_vec4(gwi))
GWI_BB(import_vararg(gwi))
GWI_BB(import_string(gwi))
GWI_BB(import_shred(gwi))
describe_string_assign(Polar_, m_complex, SZ_COMPLEX,,
num_digit((m_uint)creal(lhs)) + num_digit((m_uint)cimag(lhs) / M_PI) + 16,
"#(%.4f, %.4f)", creal(lhs), cimag(lhs)/M_PI)
-describe_string_assign(Vec3_, m_vec3, SZ_VEC3,,
- num_digit((m_uint)lhs.x) + num_digit((m_uint)lhs.y) + num_digit((m_uint)lhs.z) + 25,
- "#(%.4f, %.4f, %.4f)", lhs.x, lhs.y, lhs.z)
-describe_string_assign(Vec4_, m_vec4, SZ_VEC4,,
- num_digit((m_uint)lhs.x) + num_digit((m_uint)lhs.y) + num_digit((m_uint)lhs.z) + num_digit((m_uint)lhs.w) + 40,
- "#(%.4f, %.4f, %.4f, %.4f)", lhs.x, lhs.y, lhs.z, lhs.w)
describe_string_assign(Object_, M_Object, SZ_INT, release(lhs, shred),
16,
"%p", (void*)lhs)
describe_string(Polar, m_complex, SZ_COMPLEX,
num_digit((m_uint)creal(lhs)) + num_digit((m_uint)cimag(lhs) / M_PI) + (rhs ? strlen(STRING(rhs)) : 0) + 20,,
"%%(%.4f, %.4f*pi)%s", creal(lhs), cimag(lhs) / M_PI, rhs ? STRING(rhs) : "")
-describe_string(Vec3, m_vec3, SZ_VEC3,
- (rhs ? strlen(STRING(rhs)) : 0) + 23 + num_digit((m_uint)lhs.x) +
- num_digit((m_uint)lhs.y) + num_digit((m_uint)lhs.z),,
- "@(%.4f, %.4f, %.4f)%s", lhs.x, lhs.y, lhs.z, rhs ? STRING(rhs) : "")
-describe_string(Vec4, m_vec4, SZ_VEC4,
- (rhs ? strlen(STRING(rhs)) : 0) + 30 + num_digit((m_uint)lhs.x) +
- num_digit((m_uint)lhs.y) + num_digit((m_uint)lhs.z) + num_digit((m_uint)lhs.w),,
- "@(%.4f, %.4f, %.4f, %.4f)%s", lhs.x, lhs.y, lhs.z, lhs.w, rhs ? STRING(rhs) : "")
describe_string(Object, M_Object, SZ_INT,
17 + (rhs ? strlen(STRING(rhs)) : 0), /*release(lhs, shred)*/,
"%p%s", (void*)lhs, rhs ? STRING(rhs) : "")
describe_string_plus(Polar_, SZ_COMPLEX, m_complex,,
num_digit((m_uint)creal(lhs)) + num_digit((m_uint)cimag(lhs)) + 18, "%%(%.4f, %.4f)",
creal(lhs), cimag(lhs) / M_PI)
-describe_string_plus(Vec3_, SZ_VEC3, m_vec3,,
- num_digit((m_uint)lhs.x) + num_digit((m_uint)lhs.y) + num_digit((m_uint)lhs.z) + 22, "@(%.4f, %.4f, %.4f)",
- lhs.x, lhs.y, lhs.z)
-describe_string_plus(Vec4_, SZ_VEC4, m_vec4,,
- num_digit((m_uint)lhs.x) + num_digit((m_uint)lhs.y) + num_digit((m_uint)lhs.z) + num_digit((m_uint)lhs.z) + 30, "@(%.4f, %.4f, %.4f, %.4f)",
- lhs.x, lhs.y, lhs.z, lhs.w)
describe_string_plus(Object_, SZ_INT, M_Object, release(lhs, shred),
16, "%p", (void*)lhs)
GWI_BB(gwi_oper_add(gwi, opck_const_rhs))
GWI_BB(gwi_oper_end(gwi, "+=>", Polar_String_Plus))
- GWI_BB(gwi_oper_ini(gwi,"Vec3", "string", "string"))
- GWI_BB(gwi_oper_add(gwi, opck_const_rhs))
- GWI_BB(gwi_oper_end(gwi, "=>", Vec3_String_Assign))
- GWI_BB(gwi_oper_end(gwi, "+", Vec3_String))
- GWI_BB(gwi_oper_add(gwi, opck_const_rhs))
- GWI_BB(gwi_oper_end(gwi, "+=>", Vec3_String_Plus))
-
- GWI_BB(gwi_oper_ini(gwi, "Vec4", "string", "string"))
- GWI_BB(gwi_oper_add(gwi, opck_const_rhs))
- GWI_BB(gwi_oper_end(gwi, "=>", Vec4_String_Assign))
- GWI_BB(gwi_oper_end(gwi, "+", Vec4_String))
- GWI_BB(gwi_oper_add(gwi, opck_const_rhs))
- GWI_BB(gwi_oper_end(gwi, "+=>", Vec4_String_Plus))
-
GWI_BB(gwi_oper_ini(gwi, "Object", "string", "string"))
GWI_BB(gwi_oper_add(gwi, opck_const_rhs))
GWI_BB(gwi_oper_end(gwi, "=>", Object_String_Assign))
+++ /dev/null
-#include "gwion_util.h"
-#include "gwion_ast.h"
-#include "gwion_env.h"
-#include "vm.h"
-#include "instr.h"
-#include "object.h"
-#include "gwion.h"
-#include "operator.h"
-#include "traverse.h"
-#include "parse.h"
-#include "import.h"
-#include "driver.h"
-#include "gwi.h"
-#include "gack.h"
-#include "emit.h"
-
-INSTR(VecCpy) {
- POP_REG(shred, instr->m_val2);
- for(m_uint i = 0; i < instr->m_val2; i += SZ_FLOAT)
- *(m_float*)(shred->mem +instr->m_val-instr->m_val2+i) = *(m_float*)(shred->reg+i);
- *(m_bit**)(shred->mem + instr->m_val) = (shred->mem + instr->m_val - instr->m_val2);
-}
-
-INSTR(VecMember) {
- if(instr->m_val)
- *(m_float**)REG(-SZ_INT) = (m_float*)(*(m_bit**)REG(-SZ_INT) + instr->m_val2);
- else {
- *(m_float*)REG(-SZ_INT) = *(m_float*)(*(m_bit**)REG(-SZ_INT) + instr->m_val2);
- PUSH_REG(shred, SZ_FLOAT - SZ_INT);
- }
-}
-
-#define describe_vec(func, op) \
-ANN static void vec_##func(const m_bit* v, const int size, const m_float f) { \
- for(int i = size + 1; --i;) \
- *(m_float*)(v + (i-1) * SZ_FLOAT) op##= f; \
-}
-describe_vec(Add, +)
-describe_vec(Sub, -)
-describe_vec(Mul, *)
-describe_vec(Div, /)
-
-static MFUN(vec3_set) {
- m_vec3* v = (m_vec3*)MEM(0);
- v->x = *(m_float*)MEM(SZ_INT);
- v->y = *(m_float*)MEM(SZ_INT + SZ_FLOAT);
- v->z = *(m_float*)MEM(SZ_INT + SZ_FLOAT * 2);
-}
-
-static MFUN(vec3_setAll) {
- m_vec3* v = *(m_vec3**)MEM(0);
- v->x = *(m_float*)MEM(SZ_INT);
- v->y = *(m_float*)MEM(SZ_INT);
- v->z = *(m_float*)MEM(SZ_INT);
-}
-
-static MFUN(vec3_magnitude) {
- const m_vec3* v = *(m_vec3**)MEM(0);
- *(m_float*)RETURN = sqrt(v->x * v->x + v->y * v->y + v->z * v->z);
-}
-
-static MFUN(vec3_normalize) {
- const m_vec3* v = *(m_vec3**)MEM(0);
- const m_float mag = sqrt(v->x * v->x + v->y * v->y + v->z * v->z);
- if(mag > 0)
- vec_Div((m_bit*)v, 3, mag);
-}
-
-#define describe_vec3_x(name, arg) \
-static MFUN(vec3_##name) { \
- m_vec3* v = *(m_vec3**)MEM(0); \
- v->x = (v->y - v->x) * v->z arg; \
- *(m_float*)RETURN = v->x; \
-}
-describe_vec3_x(interp, + v->x)
-describe_vec3_x(float, * v->z * (*(m_float*)MEM(SZ_INT)) + v->x)
-describe_vec3_x(dur, * (*(m_float*)MEM(SZ_INT) / (m_float)shred->info->vm->bbq->si->sr) + v->x)
-
-static MFUN(vec3_update) {
- m_vec3* v = *(m_vec3**)MEM(0);
- v->y = *(m_float*)MEM(SZ_INT);
-}
-
-static MFUN(vec3_update_slew) {
- m_vec3* v = *(m_vec3**)MEM(0);
- v->y = *(m_float*)MEM(SZ_INT);
- v->z = *(m_float*)MEM(SZ_INT + SZ_FLOAT);
-}
-
-static MFUN(vec3_update_set) {
- m_vec3* v = *(m_vec3**)MEM(0);
- v->x = *(m_float*)MEM(SZ_INT);
- v->y = *(m_float*)MEM(SZ_INT);
-
-}
-
-static MFUN(vec3_update_set_slew) {
- m_vec3* v = *(m_vec3**)MEM(0);
- v->x = *(m_float*)MEM(SZ_INT);
- v->y = *(m_float*)MEM(SZ_INT);
- v->z = *(m_float*)MEM(SZ_INT + SZ_FLOAT);
-}
-
-#define describe_vec3(name, op) \
-static INSTR(Vec3##name) {\
- POP_REG(shred, SZ_VEC3); \
- m_vec3 r, * t = (m_vec3*)REG(-SZ_VEC3); \
- r.x = t->x op (t + 1)->x; \
- r.y = t->y op (t + 1)->y; \
- r.z = t->z op (t + 1)->z; \
- *(m_vec3*)REG(-SZ_VEC3) = r; \
-}
-describe_vec3(Add, +)
-describe_vec3(Sub, -)
-describe_vec3(Mul, *)
-describe_vec3(Div, /)
-
-
-#define describe_float_vec3(func) \
-static INSTR(Float##func##Vec3) {\
- POP_REG(shred, SZ_FLOAT); \
- const m_float f = *(m_float*)REG(-SZ_VEC3); \
- const m_vec3 r = *(m_vec3*)REG(-SZ_COMPLEX); \
- vec_Mul((m_bit*)&r, 3, f); \
- *(m_vec3*)REG(-SZ_VEC3) = r; \
-}
-describe_float_vec3(Add)
-describe_float_vec3(Sub)
-describe_float_vec3(Mul)
-describe_float_vec3(Div)
-
-#define describe_vec3_float(func) \
-static INSTR(Vec3##func##Float) {\
- POP_REG(shred, SZ_FLOAT); \
- const m_vec3 r = *(m_vec3*)REG(-SZ_VEC3); \
- const m_float f = *(m_float*)REG(0); \
- vec_##func((m_bit*)&r, 3, f); \
- *(m_vec3*)REG(-SZ_VEC3) = r; \
-}
-describe_vec3_float(Add)
-describe_vec3_float(Sub)
-describe_vec3_float(Mul)
-describe_vec3_float(Div)
-
-static INSTR(Vec3RAssign) {
- POP_REG(shred, SZ_INT);
- m_vec3* r = *(m_vec3**)REG(0);
- r->x = *(m_float*)REG(-SZ_VEC3);
- r->y = *(m_float*)REG(-SZ_COMPLEX);
- r->z = *(m_float*)REG(-SZ_FLOAT);
- *(m_vec3*)REG(0) = *r;
-}
-
-static void vecx_base(const Gwi gwi) {
- gwi_item_ini(gwi, "float", "x");
- gwi_item_end(gwi, ae_flag_member, NULL);
- gwi_item_ini(gwi, "float", "y");
- gwi_item_end(gwi, ae_flag_member, NULL);
- gwi_item_ini(gwi, "float", "z");
- gwi_item_end(gwi, ae_flag_member, NULL);
-}
-
-static GACK(gack_vec3) {
- INTERP_PRINTF("%%(%.4f, %.4f, %.4f)", *(m_float*)VALUE, *(m_float*)(VALUE + SZ_FLOAT), *(m_float*)(VALUE + SZ_FLOAT*2));
-}
-
-EQUALITY_OPER(vec3, SZ_VEC3);
-
-OP_CHECK(opck_vecx_ctor) {
- Exp_Call *call = (Exp_Call*)data;
- Exp e = call->args, last = NULL;
- if(call->args)
- CHECK_ON(check_exp(env, call->args))
- size_t 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;
-}
-OP_CHECK(opck_object_dot);
-
-static OP_EMIT(opem_vec_dot) {
- Exp_Dot *member = (Exp_Dot*)data;
- member->base->emit_var = 1;
- CHECK_BO(emit_exp(emit, member->base, 0))
- const Value v = find_value(member->base->type, member->xid);
- if(GET_FLAG(v, func)) {
- /*regpushi(emit, (m_uint)v->d.func_ref->code);*/
- const Instr instr = emit_add_instr(emit, RegPushImm);
- instr->m_val = (m_uint)v->d.func_ref->code;
- return instr;
- }
- if(!v->from->offset && exp_self(member)->emit_var)
- return (Instr)GW_OK;
- const Instr instr = emit_add_instr(emit, VecMember);
- instr->m_val2 = v->from->offset;
- instr->m_val = exp_self(member)->emit_var;
- return instr;
-}
-
-GWION_IMPORT(vec3) {
- const Type t_vec3 = gwi_class_spe(gwi, "Vec3", SZ_VEC3);
- GWI_BB(gwi_gack(gwi, t_vec3, gack_vec3))
- vecx_base(gwi);
- gwi_func_ini(gwi, "void", "set");
- gwi_func_arg(gwi, "float", "x");
- gwi_func_arg(gwi, "float", "y");
- gwi_func_arg(gwi, "float", "z");
- GWI_BB(gwi_func_end(gwi, vec3_set, ae_flag_none))
- gwi_func_ini(gwi, "void", "setAll");
- gwi_func_arg(gwi, "float", "x");
- GWI_BB(gwi_func_end(gwi, vec3_setAll, ae_flag_none))
- gwi_func_ini(gwi, "float", "magnitude");
- GWI_BB(gwi_func_end(gwi, vec3_magnitude, ae_flag_none))
- gwi_func_ini(gwi, "void", "normalize");
- GWI_BB(gwi_func_end(gwi, vec3_normalize, ae_flag_none))
- gwi_func_ini(gwi, "float", "interp");
- GWI_BB(gwi_func_end(gwi, vec3_interp, ae_flag_none))
- gwi_func_ini(gwi, "float", "interp");
- gwi_func_arg(gwi, "float", "delta");
- GWI_BB(gwi_func_end(gwi, vec3_float, ae_flag_none))
- gwi_func_ini(gwi, "float", "interp");
- gwi_func_arg(gwi, "dur", "delta");
- GWI_BB(gwi_func_end(gwi, vec3_dur, ae_flag_none))
- gwi_func_ini(gwi, "void", "update");
- gwi_func_arg(gwi, "float", "goal");
- GWI_BB(gwi_func_end(gwi, vec3_update, ae_flag_none))
- gwi_func_ini(gwi, "void", "update");
- gwi_func_arg(gwi, "float", "goal");
- gwi_func_arg(gwi, "float", "slew");
- GWI_BB(gwi_func_end(gwi, vec3_update_slew, ae_flag_none))
- gwi_func_ini(gwi, "void", "supdate");
- gwi_func_arg(gwi, "float", "goalAndValue");
- GWI_BB(gwi_func_end(gwi, vec3_update_set, ae_flag_none))
- gwi_func_ini(gwi, "void", "supdate");
- gwi_func_arg(gwi, "float", "goalAndValue");
- gwi_func_arg(gwi, "float", "slew");
- 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, opck_vecx_ctor))
- GWI_BB(gwi_oper_end(gwi, "@ctor", NULL))
-
- GWI_BB(gwi_oper_ini(gwi, "Vec3", (m_str)OP_ANY_TYPE, NULL))
- GWI_BB(gwi_oper_add(gwi, opck_object_dot))
- GWI_BB(gwi_oper_emi(gwi, opem_vec_dot))
- GWI_BB(gwi_oper_end(gwi, "@dot", 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_BB(gwi_oper_ini(gwi, "Vec3", "Vec3", "Vec3"))
- GWI_BB(gwi_oper_end(gwi, "+", Vec3Add))
- GWI_BB(gwi_oper_end(gwi, "-", Vec3Sub))
- GWI_BB(gwi_oper_end(gwi, "*", Vec3Mul))
- GWI_BB(gwi_oper_end(gwi, "/", Vec3Div))
- GWI_BB(gwi_oper_add(gwi, opck_rassign))
- GWI_BB(gwi_oper_end(gwi, "=>", Vec3RAssign))
- GWI_BB(gwi_oper_ini(gwi, "Vec3", "float", "Vec3"))
- GWI_BB(gwi_oper_end(gwi, "+", Vec3AddFloat))
- GWI_BB(gwi_oper_end(gwi, "-", Vec3SubFloat))
- GWI_BB(gwi_oper_end(gwi, "*", Vec3MulFloat))
- GWI_BB(gwi_oper_end(gwi, "/", Vec3DivFloat))
- GWI_BB(gwi_oper_ini(gwi, "float", "Vec3", "Vec3"))
- GWI_BB(gwi_oper_end(gwi, "+", FloatAddVec3))
- GWI_BB(gwi_oper_end(gwi, "-", FloatSubVec3))
- GWI_BB(gwi_oper_end(gwi, "*", FloatMulVec3))
- GWI_BB(gwi_oper_end(gwi, "/", FloatDivVec3))
- return GW_OK;
-}
-
-static MFUN(vec4_set) {
- m_vec4* v = *(m_vec4**)MEM(0);
- v->x = *(m_float*)MEM(SZ_INT);
- v->y = *(m_float*)MEM(SZ_INT + SZ_FLOAT);
- v->z = *(m_float*)MEM(SZ_INT + SZ_FLOAT * 2);
- v->w = *(m_float*)MEM(SZ_INT + SZ_FLOAT * 3);
-}
-
-static MFUN(vec4_setAll) {
- m_vec4* v = *(m_vec4**)MEM(0);
- v->x = *(m_float*)MEM(SZ_INT);
- v->y = *(m_float*)MEM(SZ_INT);
- v->z = *(m_float*)MEM(SZ_INT);
- v->w = *(m_float*)MEM(SZ_INT);
-}
-
-static MFUN(vec4_magnitude) {
- m_vec4* v = *(m_vec4**)MEM(0);
- *(m_float*)RETURN = sqrt(v->x * v->x + v->y * v->y + v->z * v->z + v->w * v->w);
-}
-
-static MFUN(vec4_normalize) {
- m_vec4* v = *(m_vec4**)MEM(0);
- const m_float mag = sqrt(v->x * v->x + v->y * v->y + v->z * v->z + v->w * v->w);
- if(mag > 0)
- vec_Div((m_bit*)v, 4, mag);
-}
-
-#define describe_vec4(name, op) \
-static INSTR(Vec4##name) {\
- POP_REG(shred, SZ_VEC4); \
- m_vec4 r, * t = (m_vec4*)REG(-SZ_VEC4); \
- r.x = t->x op (t + 1)->x; \
- r.y = t->y op (t + 1)->y; \
- r.z = t->z op (t + 1)->z; \
- r.w = t->w op (t + 1)->w; \
- *(m_vec4*)REG(-SZ_VEC4) = r; \
-}
-describe_vec4(Add, +)
-describe_vec4(Sub, -)
-describe_vec4(Mul, *)
-describe_vec4(Div, /)
-
-#define describe_float_vec4(func) \
-static INSTR(Float##func##Vec4) {\
- POP_REG(shred, SZ_FLOAT); \
- m_float f = *(m_float*)REG(-SZ_VEC4); \
- m_vec4 r = *(m_vec4*)REG(-SZ_VEC3); \
- vec_##func((m_bit*)&r, 4, f); \
- *(m_vec4*)REG(-SZ_VEC4) = r; \
-}
-describe_float_vec4(Add)
-describe_float_vec4(Sub)
-describe_float_vec4(Mul)
-describe_float_vec4(Div)
-
-#define describe_vec4_float(func) \
-static INSTR(Vec4##func##Float) {\
- POP_REG(shred, SZ_FLOAT); \
- m_vec4 r = *(m_vec4*)REG(-SZ_VEC4); \
- m_float f = *(m_float*)REG(0); \
- vec_##func((m_bit*)&r, 4, f); \
- *(m_vec4*)REG(-SZ_VEC4) = r; \
-}
-describe_vec4_float(Add)
-describe_vec4_float(Sub)
-describe_vec4_float(Mul)
-describe_vec4_float(Div)
-
-static INSTR(Vec4RAssign) {
- POP_REG(shred, SZ_INT);
- m_vec4* r = *(m_vec4**)REG(0);
- r->x = *(m_float*)REG(-SZ_VEC4);
- r->y = *(m_float*)REG(-SZ_VEC3);
- r->z = *(m_float*)REG(-SZ_COMPLEX);
- r->w = *(m_float*)REG(-SZ_FLOAT);
- *(m_vec4*)REG(0) = *r;
-}
-
-static GACK(gack_vec4) {
- INTERP_PRINTF("%%(%.4f, %.4f, %.4f, %.4f)",
- *(m_float*)VALUE,
- *(m_float*)(VALUE + SZ_FLOAT),
- *(m_float*)(VALUE + SZ_FLOAT*2),
- *(m_float*)(VALUE + SZ_FLOAT*3));
-}
-
-EQUALITY_OPER(vec4, SZ_VEC4);
-
-GWION_IMPORT(vec4) {
- const Type t_vec4 = gwi_class_spe(gwi, "Vec4", SZ_VEC4);
- GWI_BB(gwi_gack(gwi, t_vec4, gack_vec4))
- vecx_base(gwi);
- gwi_item_ini(gwi, "float", "w");
- gwi_item_end(gwi, ae_flag_member, NULL);
- gwi_func_ini(gwi, "void", "set");
- gwi_func_arg(gwi, "float", "x");
- gwi_func_arg(gwi, "float", "y");
- gwi_func_arg(gwi, "float", "z");
- gwi_func_arg(gwi, "float", "w");
- CHECK_BB(gwi_func_end(gwi, vec4_set, ae_flag_none))
- gwi_func_ini(gwi, "void", "setAll");
- gwi_func_arg(gwi, "float", "x");
- CHECK_BB(gwi_func_end(gwi, vec4_setAll, ae_flag_none))
- gwi_func_ini(gwi, "float", "magnitude");
- CHECK_BB(gwi_func_end(gwi, vec4_magnitude, ae_flag_none))
- 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, opck_vecx_ctor))
- GWI_BB(gwi_oper_end(gwi, "@ctor", NULL))
-
- GWI_BB(gwi_oper_ini(gwi, "Vec4", (m_str)OP_ANY_TYPE, NULL))
- GWI_BB(gwi_oper_add(gwi, opck_object_dot))
- GWI_BB(gwi_oper_emi(gwi, opem_vec_dot))
- GWI_BB(gwi_oper_end(gwi, "@dot", 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))
- CHECK_BB(gwi_oper_ini(gwi, "Vec4", "Vec4", "Vec4"))
- CHECK_BB(gwi_oper_end(gwi, "+", Vec4Add))
- CHECK_BB(gwi_oper_end(gwi, "-", Vec4Sub))
- CHECK_BB(gwi_oper_end(gwi, "*", Vec4Mul))
- CHECK_BB(gwi_oper_end(gwi, "/", Vec4Div))
- CHECK_BB(gwi_oper_add(gwi, opck_rassign))
- CHECK_BB(gwi_oper_end(gwi, "=>", Vec4RAssign))
- CHECK_BB(gwi_oper_ini(gwi, "Vec4", "float", "Vec4"))
- CHECK_BB(gwi_oper_end(gwi, "+", Vec4AddFloat))
- CHECK_BB(gwi_oper_end(gwi, "-", Vec4SubFloat))
- CHECK_BB(gwi_oper_end(gwi, "*", Vec4MulFloat))
- CHECK_BB(gwi_oper_end(gwi, "/", Vec4DivFloat))
- CHECK_BB(gwi_oper_ini(gwi, "float", "Vec4", "Vec4"))
- CHECK_BB(gwi_oper_end(gwi, "+", FloatAddVec4))
- CHECK_BB(gwi_oper_end(gwi, "-", FloatSubVec4))
- CHECK_BB(gwi_oper_end(gwi, "*", FloatMulVec4))
- return (m_bool)gwi_oper_end(gwi, "/", FloatDivVec4);
-}
*(m_uint*)(reg + (m_int)VAL) = *(m_uint*)(reg + (m_int)VAL2);
DISPATCH()
regtoregaddr:
- *(m_uint**)reg = &*(m_uint*)(reg-SZ_INT);
- reg += SZ_INT;
+ *(m_uint**)(reg + (m_int)VAL) = &*(m_uint*)(reg + (m_int)VAL2);
DISPATCH()
memsetimm:
*(m_uint*)(mem+VAL) = VAL2;
float f[4];
complex c[4];
polar p[4];
- Vec3 v[4];
- Vec4 w[4];
i[0];
f[0];
c[0];
5.7 => f[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 << 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() >>>;
}
static int i;
static float f;
static complex c;
- static Vec3 v;
- static Vec4 w;
static Object o;
}
<<< C.i >>>;
<<< C.f >>>;
<<< C.c >>>;
-<<< C.v >>>;
-<<< C.w >>>;
<<< C.o >>>;
<<<vararg $ int >>>;
vararg.end;
}
-Vec3(1.3) => test;
+new Object => test;
+++ /dev/null
-#! [contains] extraneous component of
- Vec4(0,0,0,0,0);
-fun Vec4 test(int i) { <<< "test with arg ", i >>>; }
+fun int test(int i) { <<< "test with arg ", i >>>; }
-#!typedef Vec4 PT();
-#!test @=>
PtrTypeI p;
test @=> p;
-#!test @=> PT ti;
<<< test >>>;
-#!<<< ti >>>;
<<< p >>>;
-#!ti();
<<< "test" >>>;
p(2);
<<< "end" >>>;
SFUN(coverage_int) { *(m_uint*)RETURN = 0; }
SFUN(coverage_float) { *(m_float*)RETURN = 0; }
SFUN(coverage_complex) { *(m_complex*)RETURN = 0; }
-SFUN(coverage_vec3) { m_vec3 v = {0,0,0}; *(m_vec3*)RETURN = v; }
-SFUN(coverage_vec4) { m_vec4 v = {0,0,0,0}; *(m_vec4*)RETURN = v; }
GWION_IMPORT(coverage) {
GWI_OB(gwi_class_ini(gwi, "Coverage", NULL))
GWI_BB(gwi_func_end(gwi, coverage_float, ae_flag_static))
GWI_BB(gwi_func_ini(gwi, "complex", "c"))
GWI_BB(gwi_func_end(gwi, coverage_complex, ae_flag_static))
- GWI_BB(gwi_func_ini(gwi, "Vec3", "v"))
- GWI_BB(gwi_func_end(gwi, coverage_vec3, ae_flag_static))
- GWI_BB(gwi_func_ini(gwi, "Vec4", "w"))
- GWI_BB(gwi_func_end(gwi, coverage_vec4, ae_flag_static))
ALLOC_PTR(gwi->gwion->mp, i, m_uint, 5);
GWI_BB(gwi_item_ini(gwi,"int", "s_i"))
GWI_BB(gwi_item_ini(gwi,"complex", "s_c"))
GWI_BB(gwi_item_end(gwi, ae_flag_static, (void*)c))
- const m_vec3 _v = { 2.1, 2.2, 2.3 };
- ALLOC_PTR(gwi->gwion->mp, v, m_vec3, _v);
- GWI_BB(gwi_item_ini(gwi,"Vec3", "s_v"))
- GWI_BB(gwi_item_end(gwi, ae_flag_static, (void*)v))
-
- const m_vec4 _w = { 2.1, 2.2, 2.3, 2.4 };
- ALLOC_PTR(gwi->gwion->mp, w, m_vec4, _w);
- GWI_BB(gwi_item_ini(gwi,"Vec4", "s_w"))
- GWI_BB(gwi_item_end(gwi, ae_flag_static, (void*)w))
-
ALLOC_PTR(gwi->gwion->mp, ci, m_uint, 5);
GWI_BB(gwi_item_ini(gwi,"int", "sc_i"))
GWI_BB(gwi_item_end(gwi, ae_flag_static | ae_flag_const, ci))
GWI_BB(gwi_item_ini(gwi,"complex", "sc_c"))
GWI_BB(gwi_item_end(gwi, ae_flag_static | ae_flag_const, (void*)cc))
- const m_vec3 _cv = { 2.1, 2.2, 2.3 };
- ALLOC_PTR(gwi->gwion->mp, cv, m_vec3, _cv);
- GWI_BB(gwi_item_ini(gwi,"Vec3", "sc_v"))
- GWI_BB(gwi_item_end(gwi, ae_flag_static | ae_flag_const, (void*)cv))
-
- const m_vec4 _cw = { 2.1, 2.2, 2.3, 2.4 };
- ALLOC_PTR(gwi->gwion->mp, cw, m_vec4, _cw);
- GWI_BB(gwi_item_ini(gwi,"Vec4", "sc_w"))
- GWI_BB(gwi_item_end(gwi, ae_flag_static | ae_flag_const, (void*)cw))
-
GWI_BB(gwi_item_ini(gwi,"int[][]", "test_array"))
GWI_BB(gwi_item_end(gwi, ae_flag_none, NULL))
<<< Coverage.i() >>>;
<<< Coverage.f() >>>;
<<< Coverage.c() >>>;
-<<< Coverage.v() >>>;
-<<< Coverage.w() >>>;
<<< Coverage.s_i >>>;
<<< Coverage.s_f >>>;
<<< Coverage.s_c >>>;
-<<< Coverage.s_v >>>;
-<<< Coverage.s_w >>>;
<<< Coverage.sc_i >>>;
<<< Coverage.sc_f >>>;
<<< Coverage.sc_c >>>;
-<<< Coverage.sc_v >>>;
-<<< Coverage.sc_w >>>;
<<< 1 => Coverage.s_i >>>;
<<< 1.2 => Coverage.s_f >>>;
<<< 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] >>>;
#! [contains] must have one
-operator @implicit int(Vec3 v, int i) {}
+operator @implicit int(int i, int i) {}
<<< 3 => pure >>>;
<<< 4 => pure >>>;
<<< 2.2 => pure >>>;
-<<< Vec3(2.3) => pure >>>;
<<< 3 => pure >>>;
<<< 4 => pure >>>;
<<< 2.2 => pure >>>;
-<<< Vec3(2.3) => pure >>>;
}
C c;
fun float test(int i) {}
fun float test(float f) {}
fun float test(complex c) {}
-fun float test(Vec3 v) {}
-fun float test(Vec4 w) {}
fun complex ctest(){}
-fun Vec3 vtest(){}
-fun Vec4 wtest(){}
ctest();
-vtest();
-wtest();
test();
() => test;
test(complex(2.3, 4.5));
complex(2.3, 4.5) => test;
-test(Vec3(1.2, 2.3, 3.4));
-Vec3(1.2, 2.3, 3.4) => test;
-
-test(Vec4(1.2, 2.3, 3.4, 4.5));
-Vec4(1.2, 2.3, 3.4, 4.5) => test;
-
class C
{
fun float test() {}
fun float test(int i) {}
fun float test(float f) {}
fun float test(complex c) {}
- fun float test(Vec3 v) {}
- fun float test(Vec4 w) {}
fun static float s_test() {}
fun static float s_test(int i) {}
fun static float s_test(float f) {}
fun static float s_test(complex c) {}
- fun static float s_test(Vec3 v) {}
- fun static float s_test(Vec4 w) {}
}
C c;
c.test(complex(2.3, 4.5));
complex(2.3, 4.5) => c.test;
-c.test(Vec3(1.2, 2.3, 3.4));
-Vec3(1.2, 2.3, 3.4) => 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(complex(2.3, 4.5));
complex(2.3, 4.5) => 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(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(complex(2.3, 4.5));
complex(2.3, 4.5) => 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(Vec4(1.2, 2.3, 3.4, 4.5));
-Vec4(1.2, 2.3, 3.4, 4.5) => C.s_test;
-
<~int, int~>C c;
<~float, int~>C d;
<~polar, int~>C e;
-<~Vec3, int~>C f;
<~Object, int~>C g;
#!C c;
<<< c.a >>>;
[ 1 ];
int i,j;
typeof(i) k;
- Vec3(0);
'a';
true $ int;
i++;
fun complex testc() {};
-fun Vec3 testv3() {};
-fun Vec4 testv4() {};
testc();
-testv3();
-testv4();
-fun void test() { complex c; c; Vec3 v; v; Vec4 w; w; }
+fun void test() { complex c; c; }
test();
+++ /dev/null
-#! a vec3 with only two expressions
-[ Vec3(0.0- 0.0, 0.0) ];
-Tuple(.2, Vec3(1), 3) @=> <~float, Vec3, int~>Tuple ref t;
+Tuple(.2, null, 3) @=> <~float, Object, int~>Tuple ref t;
t[0];
t[1];
3 => t[2];