Skip to content

Commit

Permalink
Merge branch 'ccrma:main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
nshaheed authored Oct 16, 2023
2 parents fe9bfeb + f4583d3 commit c0948b6
Show file tree
Hide file tree
Showing 33 changed files with 1,570 additions and 260 deletions.
79 changes: 79 additions & 0 deletions examples/vector/vec2.ck
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
// vec2 is a primitive type...
// requires chuck-1.5.1.7 or higher

// print vec2 literal
<<< "print vec2 literal:", @(1,2) >>>;

// variable
vec2 a;
// assignment
@(3,4) => a;
// one line
@(5,6) => vec2 b;

// print
<<< "print variables:", a, b >>>;
<<< "print fields (x,y):", a.x, a.y >>>;
<<< "print fields (u,v):", a.u, a.v >>>;
<<< "print fields (s,t):", a.s, a.t >>>;

// equivalence
<<< "a == a :", a == a ? "true" : "false" >>>;
<<< "a != 2*a :", a != 2*a ? "true" : "false" >>>;
<<< "a == b :", a == b ? "true" : "false" >>>;

// casting vec2 to vec3
@(7,8) $ vec3 => vec3 v3;
<<< "casting vec2 to vec3:", v3 >>>;
<<< "casting vec2 to vec4:", @(9,10) $ vec4 >>>;
<<< "casting vec3 to vec2:", @(9,10,11) $ vec2 >>>;
<<< "casting vec4 to vec2:", @(9,10,11,12) $ vec2 >>>;

// add and minus
a + b => vec2 c;
b - a => auto d;
.5 * a => vec2 e;
b * 2 => vec2 f;
b / 2 => vec2 g;
<<< "plus minus:", c, d >>>;
<<< "scalar multiply:", e, f, g >>>;
<<< "adding vec2 literals:", @(11,12) + @(13,14) >>>;
<<< "vec2 + vec3:", @(15,16) + @(17,18,19) >>>;
<<< "vec4 + vec2:", @(20,21,22,23) + @(1,1) >>>;
// add assign
a +=> f;
// times assign
2 *=> g;
<<< "add/times assign:", f, g >>>;
// minus assign
a -=> f;
// divide assign
2 /=> g;
<<< "minus/divide assign:", f, g >>>;

// arrays
vec2 vs[0];
// append
vs << a << b << v3$vec2 << @(24,25) << d;
// foreach
for( auto v : vs ) <<< "foreach 1:", v >>>;

// assign to reference
[@(1,2),a,b] @=> vec2 vsB[];
// foreach
for( auto v : vsB ) <<< "foreach 2:", v >>>;

// map
vec2 map[0]; @(100,101) => map["foo"];
<<< "map:", map["foo"] >>>;

fun void foo( vec2 v ) { <<< "foo():", v >>>; }
fun void bar( vec2 vs[] ) { for( auto v : vs ) <<< "bar():", v >>>; }

// call function
foo( @(1,2) );
// call with array
bar( [@(3,4),@(5,6)] );

// print with IO
cherr <= "cherr: " <= a <= " " <= b <= IO.nl();
12 changes: 7 additions & 5 deletions src/core/chuck_def.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ typedef struct { t_CKFLOAT re ; t_CKFLOAT im ; } t_CKCOMPLEX;
typedef struct { t_CKFLOAT modulus ; t_CKFLOAT phase ; } t_CKPOLAR;

// vector types
typedef struct { t_CKFLOAT x ; t_CKFLOAT y ; } t_CKVEC2;
typedef struct { t_CKFLOAT x ; t_CKFLOAT y ; t_CKFLOAT z ; } t_CKVEC3;
typedef struct { t_CKFLOAT x ; t_CKFLOAT y ; t_CKFLOAT z ; t_CKFLOAT w ; } t_CKVEC4;
typedef struct { t_CKUINT N ; t_CKFLOAT * values ; } t_CKVECTOR;
Expand All @@ -101,6 +102,7 @@ typedef struct { t_CKUINT N ; t_CKFLOAT * values ; } t_CKVECTOR;
#define sz_VOIDPTR sizeof(t_CKVOIDPTR)
#define sz_COMPLEX sizeof(t_CKCOMPLEX)
#define sz_POLAR sizeof(t_CKPOLAR)
#define sz_VEC2 sizeof(t_CKVEC2)
#define sz_VEC3 sizeof(t_CKVEC3)
#define sz_VEC4 sizeof(t_CKVEC4)
#define sz_VECTOR sizeof(t_CKVECTOR)
Expand All @@ -112,11 +114,11 @@ typedef struct { t_CKUINT N ; t_CKFLOAT * values ; } t_CKVECTOR;
enum te_KindOf
{
kindof_VOID = 0,
kindof_INT = 1,
kindof_FLOAT = 2,
kindof_COMPLEX = 3,
kindof_VEC3 = 4,
kindof_VEC4 = 5
kindof_INT,
kindof_FLOAT,
kindof_VEC2, // 1.5.1.7 (ge) was kindof_COMPLEX
kindof_VEC3,
kindof_VEC4
};

typedef char * c_str;
Expand Down
2 changes: 0 additions & 2 deletions src/core/chuck_dl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -782,12 +782,10 @@ t_CKBOOL CK_DLL_CALL ck_add_example( Chuck_DL_Query * query, const char * ex )
// set current function documentation
t_CKBOOL CK_DLL_CALL ck_doc_func( Chuck_DL_Query * query, const char * doc )
{
// #ifdef CK_DOC // disable unless CK_DOC
if(query->curr_func)
query->curr_func->doc = doc;
else
return FALSE;
// #endif // CK_DOC

return TRUE;
}
Expand Down
10 changes: 8 additions & 2 deletions src/core/chuck_dl.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ struct Chuck_UAnaBlobProxy;
#define GET_CK_DUR(ptr) (*(t_CKDUR *)ptr)
#define GET_CK_COMPLEX(ptr) (*(t_CKCOMPLEX *)ptr)
#define GET_CK_POLAR(ptr) (*(t_CKPOLAR *)ptr)
#define GET_CK_VEC2(ptr) (*(t_CKVEC2 *)ptr)
#define GET_CK_VEC3(ptr) (*(t_CKVEC3 *)ptr)
#define GET_CK_VEC4(ptr) (*(t_CKVEC4 *)ptr)
#define GET_CK_VECTOR(ptr) (*(t_CKVECTOR *)ptr)
Expand All @@ -110,6 +111,7 @@ struct Chuck_UAnaBlobProxy;
#define GET_NEXT_DUR(ptr) (*((t_CKDUR *&)ptr)++)
#define GET_NEXT_COMPLEX(ptr) (*((t_CKCOMPLEX *&)ptr)++)
#define GET_NEXT_POLAR(ptr) (*((t_CKPOLAR *&)ptr)++)
#define GET_NEXT_VEC2(ptr) (*((t_CKVEC2 *&)ptr)++)
#define GET_NEXT_VEC3(ptr) (*((t_CKVEC3 *&)ptr)++)
#define GET_NEXT_VEC4(ptr) (*((t_CKVEC4 *&)ptr)++)
#define GET_NEXT_VECTOR(ptr) (*((t_CKVECTOR *&)ptr)++)
Expand All @@ -125,6 +127,7 @@ struct Chuck_UAnaBlobProxy;
#define SET_CK_UINT(ptr,v) (*(t_CKUINT *&)ptr=v)
#define SET_CK_TIME(ptr,v) (*(t_CKTIME *&)ptr=v)
#define SET_CK_DUR(ptr,v) (*(t_CKDUR *&)ptr=v)
#define SET_CK_VEC2(ptr,v) (*(t_CKVEC2 *&)ptr=v)
#define SET_CK_VEC3(ptr,v) (*(t_CKVEC3 *&)ptr=v)
#define SET_CK_VEC4(ptr,v) (*(t_CKVEC4 *&)ptr=v)
#define SET_CK_VECTOR(ptr,v) (*(t_CKVECTOR *&)ptr=v)
Expand All @@ -138,6 +141,7 @@ struct Chuck_UAnaBlobProxy;
#define SET_NEXT_UINT(ptr,v) (*((t_CKUINT *&)ptr)++=v)
#define SET_NEXT_TIME(ptr,v) (*((t_CKTIME *&)ptr)++=v)
#define SET_NEXT_DUR(ptr,v) (*((t_CKDUR *&)ptr)++=v)
#define SET_NEXT_VEC2(ptr,v) (*((t_CKVEC2 *&)ptr)++=v)
#define SET_NEXT_VEC3(ptr,v) (*((t_CKVEC3 *&)ptr)++=v)
#define SET_NEXT_VEC4(ptr,v) (*((t_CKVEC4 *&)ptr)++=v)
#define SET_NEXT_VECTOR(ptr,v) (*((t_CKVECTOR *&)ptr)++=v)
Expand All @@ -152,6 +156,7 @@ struct Chuck_UAnaBlobProxy;
#define OBJ_MEMBER_UINT(obj,offset) (*(t_CKUINT *)OBJ_MEMBER_DATA(obj,offset))
#define OBJ_MEMBER_TIME(obj,offset) (*(t_CKTIME *)OBJ_MEMBER_DATA(obj,offset))
#define OBJ_MEMBER_DUR(obj,offset) (*(t_CKDUR *)OBJ_MEMBER_DATA(obj,offset))
#define OBJ_MEMBER_VEC2(obj,offset) (*(t_CKVEC2 *)OBJ_MEMBER_DATA(obj,offset))
#define OBJ_MEMBER_VEC3(obj,offset) (*(t_CKVEC3 *)OBJ_MEMBER_DATA(obj,offset))
#define OBJ_MEMBER_VEC4(obj,offset) (*(t_CKVEC4 *)OBJ_MEMBER_DATA(obj,offset))
#define OBJ_MEMBER_VECTOR(obj,offset) (*(t_CKVECTOR *)OBJ_MEMBER_DATA(obj,offset))
Expand Down Expand Up @@ -191,6 +196,7 @@ union Chuck_DL_Return
t_CKTIME v_time;
t_CKCOMPLEX v_complex;
t_CKPOLAR v_polar;
t_CKVEC2 v_vec2; // ge: added 1.5.1.7
t_CKVEC3 v_vec3; // ge: added 1.3.5.3
t_CKVEC4 v_vec4; // ge: added 1.3.5.3
Chuck_Object * v_object;
Expand Down Expand Up @@ -223,8 +229,8 @@ struct Chuck_DL_Arg
{
case kindof_INT: return sz_INT;
case kindof_FLOAT: return sz_FLOAT;
case kindof_COMPLEX: return sz_COMPLEX;
case kindof_VEC3: return sz_COMPLEX;
case kindof_VEC2: return sz_VEC2;
case kindof_VEC3: return sz_VEC3;
case kindof_VEC4: return sz_VEC4;
case kindof_VOID: return sz_VOID;
}
Expand Down
Loading

0 comments on commit c0948b6

Please sign in to comment.