From ffc12a8f711ebd7a30ca6ab8edb821c058ca90dd Mon Sep 17 00:00:00 2001
From: nshaheed
Date: Fri, 13 Oct 2023 11:54:35 -0700
Subject: [PATCH 1/4] Fix lisa example link typo
---
src/core/ugen_xxx.cpp | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/core/ugen_xxx.cpp b/src/core/ugen_xxx.cpp
index e92bb7069..e7bdb82c7 100644
--- a/src/core/ugen_xxx.cpp
+++ b/src/core/ugen_xxx.cpp
@@ -1091,7 +1091,7 @@ DLL_QUERY lisa_query( Chuck_DL_Query * QUERY )
if( !type_engine_import_add_ex( env, "special/LiSa-munger1.ck" ) ) goto error;
if( !type_engine_import_add_ex( env, "special/LiSa-munger2.ck" ) ) goto error;
if( !type_engine_import_add_ex( env, "special/LiSa-munger3.ck" ) ) goto error;
- if( !type_engine_import_add_ex( env, "special/LiSa-load.ck.ck" ) ) goto error;
+ if( !type_engine_import_add_ex( env, "special/LiSa-load.ck" ) ) goto error;
if( !type_engine_import_add_ex( env, "special/LiSa-simplelooping.ck" ) ) goto error;
if( !type_engine_import_add_ex( env, "special/LiSa-trigger.ck" ) ) goto error;
if( !type_engine_import_add_ex( env, "special/LiSa-track1.ck" ) ) goto error;
From aa525935d6a243a613850343936fadb3d97534f2 Mon Sep 17 00:00:00 2001
From: Ge Wang
Date: Fri, 13 Oct 2023 22:56:10 -0700
Subject: [PATCH 2/4] ckdoc trailing punctuation
---
src/core/chuck_dl.cpp | 2 --
src/core/chuck_io.cpp | 6 +++---
src/core/chuck_type.cpp | 6 +++---
src/core/ugen_xxx.cpp | 2 +-
src/core/ulib_ai.cpp | 4 ++--
src/core/ulib_ai.h | 4 ++--
src/core/ulib_doc.cpp | 10 +++++-----
src/core/ulib_math.cpp | 2 +-
src/core/ulib_opsc.cpp | 2 +-
src/core/ulib_std.cpp | 2 +-
src/core/util_string.cpp | 41 +++++++++++++++++++++++++++++++++++++++-
src/core/util_string.h | 5 ++++-
12 files changed, 63 insertions(+), 23 deletions(-)
diff --git a/src/core/chuck_dl.cpp b/src/core/chuck_dl.cpp
index cb2dc7a39..06998d6bc 100644
--- a/src/core/chuck_dl.cpp
+++ b/src/core/chuck_dl.cpp
@@ -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;
}
diff --git a/src/core/chuck_io.cpp b/src/core/chuck_io.cpp
index 73dcd1e9d..a45139293 100644
--- a/src/core/chuck_io.cpp
+++ b/src/core/chuck_io.cpp
@@ -6642,17 +6642,17 @@ t_CKBOOL init_class_serialio( Chuck_Env * env )
// add getByte
func = make_new_mfun("int", "getByte", serialio_getByte);
- func->doc = "get next requested byte. ";
+ func->doc = "get next requested byte.";
if( !type_engine_import_mfun( env, func ) ) goto error;
// add getBytes
func = make_new_mfun("int[]", "getBytes", serialio_getBytes);
- func->doc = "get next requested number of bytes. ";
+ func->doc = "get next requested number of bytes.";
if( !type_engine_import_mfun( env, func ) ) goto error;
// add getInts
func = make_new_mfun("int[]", "getInts", serialio_getInts);
- func->doc = "get next requested number of integers. ";
+ func->doc = "get next requested number of integers.";
if( !type_engine_import_mfun( env, func ) ) goto error;
// add writeByte
diff --git a/src/core/chuck_type.cpp b/src/core/chuck_type.cpp
index 5f51555af..0fe7366ab 100644
--- a/src/core/chuck_type.cpp
+++ b/src/core/chuck_type.cpp
@@ -9117,7 +9117,7 @@ void Chuck_Type::apropos_top( std::string & output, const std::string & PREFIX )
sout << endl;
// description
if( this->doc != "" )
- sout << PREFIX << " |- " << capitalize(this->doc) << "" << endl;
+ sout << PREFIX << " |- " << capitalize_and_periodize(this->doc) << "" << endl;
// inheritance
if( type->parent != NULL )
{
@@ -9202,7 +9202,7 @@ void apropos_func( std::ostringstream & sout, Chuck_Func * theFunc,
// close paren
sout << ");" << endl;
// output doc
- if( theFunc->doc != "" ) sout << PREFIX << " " << capitalize(theFunc->doc) << endl;
+ if( theFunc->doc != "" ) sout << PREFIX << " " << capitalize_and_periodize(theFunc->doc) << endl;
}
@@ -9336,7 +9336,7 @@ void apropos_var( std::ostringstream & sout, Chuck_Value * var,
sout << var->name << ";" << endl;
// output doc
- if( var->doc != "" ) sout << PREFIX << " " << capitalize(var->doc) << endl;
+ if( var->doc != "" ) sout << PREFIX << " " << capitalize_and_periodize(var->doc) << endl;
}
diff --git a/src/core/ugen_xxx.cpp b/src/core/ugen_xxx.cpp
index e7bdb82c7..adcf48c24 100644
--- a/src/core/ugen_xxx.cpp
+++ b/src/core/ugen_xxx.cpp
@@ -851,7 +851,7 @@ DLL_QUERY xxx_query( Chuck_DL_Query * QUERY )
// add cget: valueAt
func = make_new_mfun( "float", "valueAt", sndbuf_cget_valueAt );
func->add_arg( "int", "pos" );
- func->doc = "get sample value at given position (in samples). ";
+ func->doc = "get sample value at given position (in samples).";
if( !type_engine_import_mfun( env, func ) ) goto error;
// end import
diff --git a/src/core/ulib_ai.cpp b/src/core/ulib_ai.cpp
index 8080f5f85..e3d88d39a 100644
--- a/src/core/ulib_ai.cpp
+++ b/src/core/ulib_ai.cpp
@@ -68,10 +68,10 @@
// [6] http://smirk.cs.princeton.edu/
// sMIRk | Small Music Information Retrieval toolKit
//
-// [7] Tzanetakis, G. and P. R. Cook. 2000 "MARSYAS: A Framework for Audio
+// [7] Tzanetakis, G. and P. R. Cook. 2000. "MARSYAS: A Framework for Audio
// Analysis." Organised Sound. 4:(3)
//
-// [8] Tzanetakis, G. and P. R. Cook. 2002 "Musical Genre Classification of
+// [8] Tzanetakis, G. and P. R. Cook. 2002. "Musical Genre Classification of
// Audio Signals." IEEE Transaction on Speech and Audio Processing. 10(5).
//
// [9] Wang, G., R. Fiebrink, P. R. Cook. 2007. "Combining Analysis and
diff --git a/src/core/ulib_ai.h b/src/core/ulib_ai.h
index 70bbfa8b8..6782dd384 100644
--- a/src/core/ulib_ai.h
+++ b/src/core/ulib_ai.h
@@ -68,10 +68,10 @@
// [6] http://smirk.cs.princeton.edu/
// sMIRk | Small Music Information Retrieval toolKit
//
-// [7] Tzanetakis, G. and P. R. Cook. 2000 "MARSYAS: A Framework for Audio
+// [7] Tzanetakis, G. and P. R. Cook. 2000. "MARSYAS: A Framework for Audio
// Analysis." Organised Sound. 4:(3)
//
-// [8] Tzanetakis, G. and P. R. Cook. 2002 "Musical Genre Classification of
+// [8] Tzanetakis, G. and P. R. Cook. 2002. "Musical Genre Classification of
// Audio Signals." IEEE Transaction on Speech and Audio Processing. 10(5).
//
// [9] Wang, G., R. Fiebrink, P. R. Cook. 2007. "Combining Analysis and
diff --git a/src/core/ulib_doc.cpp b/src/core/ulib_doc.cpp
index c1d9d6438..b536c35ef 100644
--- a/src/core/ulib_doc.cpp
+++ b/src/core/ulib_doc.cpp
@@ -391,7 +391,7 @@ class CKDocHTMLOutput : public CKDocOutput
if(type->doc.size() > 0)
{
- std::string doc = capitalize(type->doc);
+ std::string doc = capitalize_and_periodize(type->doc);
m_outputStr += "" + doc + "
\n";
}
else
@@ -478,7 +478,7 @@ class CKDocHTMLOutput : public CKDocOutput
m_outputStr += "" + var->name + "
";
if(var->doc.size() > 0)
- m_outputStr += "" + capitalize(var->doc) + "
\n";
+ m_outputStr += "" + capitalize_and_periodize(var->doc) + "
\n";
else
m_outputStr += "No description available
\n";
@@ -503,7 +503,7 @@ class CKDocHTMLOutput : public CKDocOutput
m_outputStr += "" + var->name + "
";
if(var->doc.size() > 0)
- m_outputStr += "" + capitalize(var->doc) + "
\n";
+ m_outputStr += "" + capitalize_and_periodize(var->doc) + "
\n";
else
m_outputStr += "No description available
\n";
@@ -537,7 +537,7 @@ class CKDocHTMLOutput : public CKDocOutput
m_outputStr += ")\n";
if(m_func->doc.size() > 0)
- m_outputStr += "" + capitalize(m_func->doc) + "
\n";
+ m_outputStr += "" + capitalize_and_periodize(m_func->doc) + "
\n";
else
m_outputStr += "No description available
\n";
@@ -573,7 +573,7 @@ class CKDocHTMLOutput : public CKDocOutput
m_outputStr += ")\n";
if(m_func->doc.size() > 0)
- m_outputStr += "" + capitalize(m_func->doc) + "
\n";
+ m_outputStr += "" + capitalize_and_periodize(m_func->doc) + "
\n";
else
m_outputStr += "No description available
\n";
diff --git a/src/core/ulib_math.cpp b/src/core/ulib_math.cpp
index 06b7d9a57..38c47fd9b 100644
--- a/src/core/ulib_math.cpp
+++ b/src/core/ulib_math.cpp
@@ -133,7 +133,7 @@ DLL_QUERY libmath_query( Chuck_DL_Query * QUERY )
QUERY->add_sfun( QUERY, atan2_impl, "float", "atan2" );
QUERY->add_arg( QUERY, "float", "y" );
QUERY->add_arg( QUERY, "float", "x" );
- QUERY->doc_func( QUERY, "Compute arc tangent of two variables (y/x). " );
+ QUERY->doc_func( QUERY, "Compute arc tangent of two variables (y/x)." );
// sinh
QUERY->add_sfun( QUERY, sinh_impl, "float", "sinh" );
diff --git a/src/core/ulib_opsc.cpp b/src/core/ulib_opsc.cpp
index 1fb75583d..7a452d8d9 100644
--- a/src/core/ulib_opsc.cpp
+++ b/src/core/ulib_opsc.cpp
@@ -358,7 +358,7 @@ class OscInServer
// TODO
}
- // add OSC method, e.g,. "/foo/frequency"
+ // add OSC method, e.g., "/foo/frequency"
void addMethod( const std::string & method, OscIn * obj )
{
// message to server
diff --git a/src/core/ulib_std.cpp b/src/core/ulib_std.cpp
index 123c90b34..d6fd9fec8 100644
--- a/src/core/ulib_std.cpp
+++ b/src/core/ulib_std.cpp
@@ -255,7 +255,7 @@ DLL_QUERY libstd_query( Chuck_DL_Query * QUERY )
// add ftoi
QUERY->add_sfun( QUERY, ftoi_impl, "int", "ftoi" ); //! float to int
QUERY->add_arg( QUERY, "float", "f" );
- QUERY->doc_func( QUERY, "convert float to integer. " );
+ QUERY->doc_func( QUERY, "convert float to integer." );
// add getenv
QUERY->add_sfun( QUERY, getenv_impl, "string", "getenv" ); //! fetch environment variable
diff --git a/src/core/util_string.cpp b/src/core/util_string.cpp
index abe0ae30e..65217cdd1 100644
--- a/src/core/util_string.cpp
+++ b/src/core/util_string.cpp
@@ -167,7 +167,7 @@ string toupper( const string & str )
//-----------------------------------------------------------------------------
// name: capitalize()
-// capitalize first character
+// desc: capiitalize first character
//-----------------------------------------------------------------------------
string capitalize( const string & s )
{
@@ -183,6 +183,45 @@ string capitalize( const string & s )
+//-----------------------------------------------------------------------------
+// name: capitalize_and_periodize()
+// desc: capiitalize first character and ensure trailing period
+//-----------------------------------------------------------------------------
+string capitalize_and_periodize( const string & s )
+{
+ // copy
+ string retval = capitalize( trim(s) );
+ // check
+ if( retval.length() > 0 )
+ {
+ char c = retval[retval.length()-1];
+ // check for other punctuation
+ switch( c )
+ {
+ case '.':
+ case ',':
+ case '!':
+ case '?':
+ case ')':
+ case '(':
+ case '#':
+ case '\'':
+ case '\"':
+ case '\n':
+ break;
+
+ // in all other cases, append .
+ default:
+ retval += '.';
+ }
+ }
+ // done
+ return retval;
+}
+
+
+
+
//-----------------------------------------------------------------------------
// name: trim()
// desc: return a whitespace (spaces and tabs)-trimmed string
diff --git a/src/core/util_string.h b/src/core/util_string.h
index cc37a06c2..ca897ddda 100644
--- a/src/core/util_string.h
+++ b/src/core/util_string.h
@@ -61,9 +61,12 @@ std::string ltrim( const std::string & val );
// right trim
std::string rtrim( const std::string & val );
-// return capitalized copy of a string
+// return capitalized copy of string
std::string capitalize( const std::string & s );
+// return capiitalized copy of string with trailing punc, adding . as needed
+std::string capitalize_and_periodize( const std::string & s );
+
// replace tabs
std::string replace_tabs( const std::string & s,
char replaceEachTabWithThis );
From b5c718a1162f7babbd7418f9668463318df987f3 Mon Sep 17 00:00:00 2001
From: Ge Wang
Date: Sat, 14 Oct 2023 17:46:26 -0700
Subject: [PATCH 3/4] add vec2 primitive type
---
examples/vector/vec2.ck | 79 +++++
src/core/chuck_def.h | 12 +-
src/core/chuck_dl.h | 10 +-
src/core/chuck_emit.cpp | 143 ++++++--
src/core/chuck_instr.cpp | 524 +++++++++++++++++++++++-----
src/core/chuck_instr.h | 239 ++++++++++++-
src/core/chuck_io.cpp | 94 +++++
src/core/chuck_io.h | 10 +
src/core/chuck_lang.cpp | 127 ++++++-
src/core/chuck_lang.h | 8 +-
src/core/chuck_oo.cpp | 73 +++-
src/core/chuck_oo.h | 22 +-
src/core/chuck_type.cpp | 186 ++++++++--
src/core/chuck_type.h | 3 +-
src/core/chuck_vm.cpp | 12 +-
src/core/uana_xform.cpp | 6 +-
src/core/ulib_math.cpp | 25 ++
src/core/ulib_math.h | 1 +
src/core/util_math.cpp | 24 ++
src/core/util_math.h | 4 +
src/test/01-Basic/214-num-types.ck | 6 +-
src/test/01-Basic/214-num-types.txt | 5 +-
src/test/01-Basic/218-vec2.ck | 78 +++++
src/test/01-Basic/218-vec2.txt | 32 ++
24 files changed, 1497 insertions(+), 226 deletions(-)
create mode 100644 examples/vector/vec2.ck
create mode 100644 src/test/01-Basic/218-vec2.ck
create mode 100644 src/test/01-Basic/218-vec2.txt
diff --git a/examples/vector/vec2.ck b/examples/vector/vec2.ck
new file mode 100644
index 000000000..a4a3427c0
--- /dev/null
+++ b/examples/vector/vec2.ck
@@ -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();
diff --git a/src/core/chuck_def.h b/src/core/chuck_def.h
index 82d26f5f5..7e33e3c00 100644
--- a/src/core/chuck_def.h
+++ b/src/core/chuck_def.h
@@ -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;
@@ -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)
@@ -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;
diff --git a/src/core/chuck_dl.h b/src/core/chuck_dl.h
index 06d16959a..b130f0663 100644
--- a/src/core/chuck_dl.h
+++ b/src/core/chuck_dl.h
@@ -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)
@@ -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)++)
@@ -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)
@@ -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)
@@ -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))
@@ -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;
@@ -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;
}
diff --git a/src/core/chuck_emit.cpp b/src/core/chuck_emit.cpp
index 9ad64707f..c3cb12261 100644
--- a/src/core/chuck_emit.cpp
+++ b/src/core/chuck_emit.cpp
@@ -509,8 +509,10 @@ t_CKBOOL emit_engine_emit_stmt( Chuck_Emitter * emit, a_Stmt stmt, t_CKBOOL pop
}
else if( exp->type->size == sz_FLOAT ) // ISSUE: 64-bit (fixed 1.3.1.0)
emit->append( new Chuck_Instr_Reg_Pop_Float );
- else if( exp->type->size == sz_COMPLEX ) // ISSUE: 64-bit (fixed 1.3.1.0)
- emit->append( new Chuck_Instr_Reg_Pop_Complex );
+ else if( exp->type->size == sz_VEC2 ) // ISSUE: 64-bit (fixed 1.3.1.0)
+ {
+ emit->append( new Chuck_Instr_Reg_Pop_Vec2ComplexPolar );
+ }
else if( exp->type->size == sz_VEC3 ) // ge: added 1.3.5.3
emit->append( new Chuck_Instr_Reg_Pop_WordsMulti(sz_VEC3/sz_WORD) );
else if( exp->type->size == sz_VEC4 ) // ge: added 1.3.5.3
@@ -857,8 +859,8 @@ t_CKBOOL emit_engine_emit_for( Chuck_Emitter * emit, a_Stmt_For stmt )
num_words += sz_FLOAT / sz_WORD; // changed to compute number of words; 1.3.1.0
else if( e->type->size == sz_INT ) // ISSUE: 64-bit (fixed 1.3.1.0)
num_words += sz_INT / sz_WORD; // changed to compute number of words; 1.3.1.0
- else if( e->type->size == sz_COMPLEX ) // ISSUE: 64-bit (fixed 1.3.1.0)
- num_words += sz_COMPLEX / sz_WORD; // changed to compute number of words; 1.3.1.0
+ else if( e->type->size == sz_VEC2 ) // ISSUE: 64-bit (fixed 1.3.1.0)
+ num_words += sz_VEC2 / sz_WORD; // changed to compute number of words; 1.3.1.0
else if( e->type->size != 0 )
{
EM_error2( e->where,
@@ -917,7 +919,6 @@ t_CKBOOL emit_engine_emit_for( Chuck_Emitter * emit, a_Stmt_For stmt )
t_CKBOOL emit_engine_emit_foreach( Chuck_Emitter * emit, a_Stmt_ForEach stmt )
{
Chuck_Instr_ForEach_Inc_And_Branch * op = NULL;
- t_CKUINT num_words = 0;
t_CKBOOL ret = TRUE;
// codestr prefix for better description | 1.5.0.8
string codestr_prefix = "/** loop control **/";
@@ -1008,7 +1009,7 @@ t_CKBOOL emit_engine_emit_foreach( Chuck_Emitter * emit, a_Stmt_ForEach stmt )
t_CKUINT start_index = emit->next_index();
// get data kind and size relevant to array
- t_CKUINT dataKind = getkindof( emit->env, stmt->theIter->type );
+ te_KindOf dataKind = getkindof( emit->env, stmt->theIter->type );
t_CKUINT dataSize = stmt->theIter->type->size;
// compare branch condition and increment loop counter
op = new Chuck_Instr_ForEach_Inc_And_Branch( dataKind, dataSize );
@@ -2059,10 +2060,13 @@ t_CKBOOL emit_engine_emit_op( Chuck_Emitter * emit, ae_Operator op, a_Exp lhs, a
case te_polar:
emit->append( instr = new Chuck_Instr_Add_polar );
break;
+ case te_vec2:
+ emit->append( instr = new Chuck_Instr_Add_vec2 );
+ break;
case te_vec3:
emit->append( instr = new Chuck_Instr_Add_vec3 );
break;
- case te_vec4:
+ case te_vec4:
emit->append( instr = new Chuck_Instr_Add_vec4 );
break;
@@ -2135,6 +2139,9 @@ t_CKBOOL emit_engine_emit_op( Chuck_Emitter * emit, ae_Operator op, a_Exp lhs, a
case te_polar:
emit->append( instr = new Chuck_Instr_Add_polar_Assign );
break;
+ case te_vec2:
+ emit->append( instr = new Chuck_Instr_Add_vec2_Assign );
+ break;
case te_vec3:
emit->append( instr = new Chuck_Instr_Add_vec3_Assign );
break;
@@ -2169,6 +2176,9 @@ t_CKBOOL emit_engine_emit_op( Chuck_Emitter * emit, ae_Operator op, a_Exp lhs, a
case te_polar:
emit->append( instr = new Chuck_Instr_Minus_polar );
break;
+ case te_vec2:
+ emit->append( instr = new Chuck_Instr_Minus_vec2 );
+ break;
case te_vec3:
emit->append( instr = new Chuck_Instr_Minus_vec3 );
break;
@@ -2203,6 +2213,9 @@ t_CKBOOL emit_engine_emit_op( Chuck_Emitter * emit, ae_Operator op, a_Exp lhs, a
case te_polar:
emit->append( instr = new Chuck_Instr_Minus_polar_Assign );
break;
+ case te_vec2:
+ emit->append( instr = new Chuck_Instr_Minus_vec2_Assign );
+ break;
case te_vec3:
emit->append( instr = new Chuck_Instr_Minus_vec3_Assign );
break;
@@ -2217,7 +2230,15 @@ t_CKBOOL emit_engine_emit_op( Chuck_Emitter * emit, ae_Operator op, a_Exp lhs, a
case ae_op_times:
// check
- if( left == te_float && right == te_vec3 )
+ if( left == te_float && right == te_vec2 ) // 1.5.1.7 (ge) added
+ {
+ emit->append( instr = new Chuck_Instr_float_Times_vec2 );
+ }
+ else if( left == te_vec2 && right == te_float )
+ {
+ emit->append( instr = new Chuck_Instr_vec2_Times_float );
+ }
+ else if( left == te_float && right == te_vec3 )
{
emit->append( instr = new Chuck_Instr_float_Times_vec3 );
}
@@ -2264,7 +2285,11 @@ t_CKBOOL emit_engine_emit_op( Chuck_Emitter * emit, ae_Operator op, a_Exp lhs, a
case ae_op_times_chuck:
// check
- if( left == te_float && right == te_vec3 )
+ if( left == te_float && right == te_vec2 )
+ {
+ emit->append( instr = new Chuck_Instr_float_Times_vec2_Assign );
+ }
+ else if( left == te_float && right == te_vec3 )
{
emit->append( instr = new Chuck_Instr_float_Times_vec3_Assign );
}
@@ -2296,7 +2321,13 @@ t_CKBOOL emit_engine_emit_op( Chuck_Emitter * emit, ae_Operator op, a_Exp lhs, a
case ae_op_divide:
if( ( left == te_time && right == te_dur ) ) // time / dur = float
+ {
emit->append( instr = new Chuck_Instr_Divide_double );
+ }
+ else if( left == te_vec2 && right == te_float )
+ {
+ emit->append( instr = new Chuck_Instr_vec2_Divide_float );
+ }
else if( left == te_vec3 && right == te_float )
{
emit->append( instr = new Chuck_Instr_vec3_Divide_float );
@@ -2332,9 +2363,14 @@ t_CKBOOL emit_engine_emit_op( Chuck_Emitter * emit, ae_Operator op, a_Exp lhs, a
case ae_op_divide_chuck:
// reverse
if( ( left == te_dur && right == te_time ) ) // time / dur = float
+ {
emit->append( instr = new Chuck_Instr_Divide_double_Assign );
- else
- if( left == te_float && right == te_vec3 )
+ }
+ else if( left == te_float && right == te_vec2 )
+ {
+ emit->append( instr = new Chuck_Instr_vec2_Divide_float_Assign );
+ }
+ else if( left == te_float && right == te_vec3 )
{
emit->append( instr = new Chuck_Instr_vec3_Divide_float_Assign );
}
@@ -2638,6 +2674,9 @@ t_CKBOOL emit_engine_emit_op( Chuck_Emitter * emit, ae_Operator op, a_Exp lhs, a
case te_polar:
emit->append( instr = new Chuck_Instr_Eq_complex );
break;
+ case te_vec2:
+ emit->append( instr = new Chuck_Instr_Eq_vec2 );
+ break;
case te_vec3:
emit->append( instr = new Chuck_Instr_Eq_vec3 );
break;
@@ -2676,6 +2715,9 @@ t_CKBOOL emit_engine_emit_op( Chuck_Emitter * emit, ae_Operator op, a_Exp lhs, a
case te_polar:
emit->append( instr = new Chuck_Instr_Neq_complex );
break;
+ case te_vec2:
+ emit->append( instr = new Chuck_Instr_Neq_vec2 );
+ break;
case te_vec3:
emit->append( instr = new Chuck_Instr_Neq_vec3 );
break;
@@ -2756,6 +2798,11 @@ t_CKBOOL emit_engine_emit_op( Chuck_Emitter * emit, ae_Operator op, a_Exp lhs, a
emit->append( instr = new Chuck_Instr_IO_out_polar );
instr->set_linepos( rhs->line );
}
+ else if( isa( t_right, emit->env->ckt_vec2 ) )
+ {
+ emit->append( instr = new Chuck_Instr_IO_out_vec2 );
+ instr->set_linepos( rhs->line );
+ }
else if( isa( t_right, emit->env->ckt_vec3 ) )
{
emit->append( instr = new Chuck_Instr_IO_out_vec3 );
@@ -3182,7 +3229,7 @@ t_CKBOOL emit_engine_emit_op_at_chuck( Chuck_Emitter * emit, a_Exp lhs, a_Exp rh
emit->append( new Chuck_Instr_Assign_Primitive );
else if( right->size == sz_FLOAT ) // ISSUE: 64-bit (fixed 1.3.1.0)
emit->append( new Chuck_Instr_Assign_Primitive2 );
- else if( right->size == sz_COMPLEX ) // ISSUE: 64-bit (fixed 1.3.1.0)
+ else if( right->size == sz_VEC2 ) // ISSUE: 64-bit (fixed 1.3.1.0)
emit->append( new Chuck_Instr_Assign_Primitive4 );
else if( right->size == sz_VEC3 ) // ge: added 1.3.5.3
emit->append( new Chuck_Instr_Assign_PrimitiveVec3 );
@@ -3689,8 +3736,8 @@ t_CKBOOL emit_engine_emit_vec_lit( Chuck_Emitter * emit, a_Vec val )
if( !emit_engine_emit_exp( emit, val->args ) )
return FALSE;
- // zero pad if needed
- t_CKINT n = 3 - val->numdims;
+ // zero pad if needed, using smallest type: vec2 | 1.5.1.7
+ t_CKINT n = sz_VEC2/sz_FLOAT - val->numdims;
// any remaining
while( n > 0 )
{
@@ -3755,6 +3802,14 @@ t_CKBOOL emit_engine_emit_cast( Chuck_Emitter * emit,
emit->append( new Chuck_Instr_Cast_complex2polar );
else if( equals( to, emit->env->ckt_complex ) && equals( from, emit->env->ckt_polar ) )
emit->append( new Chuck_Instr_Cast_polar2complex );
+ else if( equals( to, emit->env->ckt_vec2 ) && equals( from, emit->env->ckt_vec3 ) ) // 1.5.1.7
+ emit->append( new Chuck_Instr_Cast_vec3tovec2 );
+ else if( equals( to, emit->env->ckt_vec2 ) && equals( from, emit->env->ckt_vec4 ) ) // 1.5.1.7
+ emit->append( new Chuck_Instr_Cast_vec4tovec2 );
+ else if( equals( to, emit->env->ckt_vec3 ) && equals( from, emit->env->ckt_vec2 ) ) // 1.5.1.7
+ emit->append( new Chuck_Instr_Cast_vec2tovec3 );
+ else if( equals( to, emit->env->ckt_vec4 ) && equals( from, emit->env->ckt_vec2 ) ) // 1.5.1.7
+ emit->append( new Chuck_Instr_Cast_vec2tovec4 );
else if( equals( to, emit->env->ckt_vec3 ) && equals( from, emit->env->ckt_vec4 ) )
emit->append( new Chuck_Instr_Cast_vec4tovec3 );
else if( equals( to, emit->env->ckt_vec4 ) && equals( from, emit->env->ckt_vec3 ) )
@@ -3927,7 +3982,7 @@ t_CKBOOL emit_engine_emit_exp_array( Chuck_Emitter * emit, a_Exp_Array array )
// make sure
// ISSUE: 64-bit (fixed 1.3.1.0)
- if( type->size != sz_INT && type->size != sz_FLOAT && type->size != sz_COMPLEX &&
+ if( type->size != sz_INT && type->size != sz_FLOAT && type->size != sz_VEC2 &&
type->size != sz_VEC3 && type->size != sz_VEC4 )
{
EM_error2( array->where,
@@ -4030,7 +4085,7 @@ t_CKBOOL emit_engine_emit_exp_func_call( Chuck_Emitter * emit,
if( func->def()->s_type == ae_func_builtin )
{
// ISSUE: 64-bit (fixed 1.3.1.0)
- if( size == 0 || size == sz_INT || size == sz_FLOAT || size == sz_COMPLEX ||
+ if( size == 0 || size == sz_INT || size == sz_FLOAT || size == sz_VEC2 ||
size == sz_VEC3 || sz_VEC4 )
{
// is member (1.3.1.0: changed to use kind instead of size)
@@ -4129,7 +4184,7 @@ t_CKBOOL emit_engine_emit_exp_func_call( Chuck_Emitter * emit,
//-----------------------------------------------------------------------------
// name: emit_engine_emit_dot_member_special()
-// desc: emit special dot member: complex, polar, vec3, vec4
+// desc: emit special dot member: complex, polar, vec2, vec3, vec4
//-----------------------------------------------------------------------------
t_CKBOOL emit_engine_emit_exp_dot_member_special( Chuck_Emitter * emit,
a_Exp_Dot_Member member )
@@ -4157,9 +4212,9 @@ t_CKBOOL emit_engine_emit_exp_dot_member_special( Chuck_Emitter * emit,
string str = S_name(member->xid);
// check
if( str == "re" )
- emit->append( new Chuck_Instr_Dot_Cmp_First( member->base->s_meta == ae_meta_var, emit_addr, kindof_COMPLEX ) );
+ emit->append( new Chuck_Instr_Dot_Cmp_First( member->base->s_meta == ae_meta_var, emit_addr, kindof_VEC2 ) );
else if( str == "im" )
- emit->append( new Chuck_Instr_Dot_Cmp_Second( member->base->s_meta == ae_meta_var, emit_addr, kindof_COMPLEX ) );
+ emit->append( new Chuck_Instr_Dot_Cmp_Second( member->base->s_meta == ae_meta_var, emit_addr, kindof_VEC2 ) );
else
goto check_func;
@@ -4185,9 +4240,40 @@ t_CKBOOL emit_engine_emit_exp_dot_member_special( Chuck_Emitter * emit,
string str = S_name(member->xid);
// check
if( str == "mag" )
- emit->append( new Chuck_Instr_Dot_Cmp_First( member->base->s_meta == ae_meta_var, emit_addr, kindof_COMPLEX ) );
+ emit->append( new Chuck_Instr_Dot_Cmp_First( member->base->s_meta == ae_meta_var, emit_addr, kindof_VEC2 ) );
else if( str == "phase" )
- emit->append( new Chuck_Instr_Dot_Cmp_Second( member->base->s_meta == ae_meta_var, emit_addr, kindof_COMPLEX ) );
+ emit->append( new Chuck_Instr_Dot_Cmp_Second( member->base->s_meta == ae_meta_var, emit_addr, kindof_VEC2 ) );
+ else
+ goto check_func;
+
+ // done
+ return TRUE;
+ }
+ else if( member->t_base->xid == te_vec2 )
+ {
+ // remember the kind
+ te_KindOf kind = kindof_VEC2;
+ // mark to emit addr
+ if( member->base->s_meta == ae_meta_var )
+ member->base->emit_var = TRUE;
+ else if( emit_addr )
+ {
+ EM_error2( member->base->where,
+ "(emit): cannot assign value to literal '%s' value...",
+ member->t_base->c_name() );
+ return FALSE;
+ }
+
+ // emit the base
+ if( !emit_engine_emit_exp( emit, member->base ) )
+ return FALSE;
+
+ string str = S_name(member->xid);
+ // check for .xy .us
+ if( str == "x" || str == "u" || str == "s" )
+ emit->append( new Chuck_Instr_Dot_Cmp_First( member->base->s_meta == ae_meta_var, emit_addr, kind ) );
+ else if( str == "y" || str == "v" || str == "t" )
+ emit->append( new Chuck_Instr_Dot_Cmp_Second( member->base->s_meta == ae_meta_var, emit_addr, kind ) );
else
goto check_func;
@@ -4334,6 +4420,7 @@ t_CKBOOL emit_engine_emit_exp_dot_member( Chuck_Emitter * emit,
{
case te_complex:
case te_polar:
+ case te_vec2:
case te_vec3:
case te_vec4:
// emit special
@@ -4850,7 +4937,7 @@ t_CKBOOL emit_engine_emit_exp_decl( Chuck_Emitter * emit, a_Exp_Decl decl,
emit->append( new Chuck_Instr_Reg_Push_Imm( 0 ) );
else if( type->size == sz_FLOAT ) // ISSUE: 64-bit
emit->append( new Chuck_Instr_Reg_Push_Imm2( 0.0 ) );
- else if( type->size == sz_COMPLEX ) // ISSUE: 64-bit
+ else if( type->size == sz_VEC2 ) // ISSUE: 64-bit
emit->append( new Chuck_Instr_Reg_Push_Imm4( 0.0, 0.0 ) );
else
{
@@ -4874,8 +4961,8 @@ t_CKBOOL emit_engine_emit_exp_decl( Chuck_Emitter * emit, a_Exp_Decl decl,
emit->append( new Chuck_Instr_Alloc_Member_Word( value->offset ) );
else if( type->size == sz_FLOAT ) // ISSUE: 64-bit (fixed 1.3.1.0)
emit->append( new Chuck_Instr_Alloc_Member_Word2( value->offset ) );
- else if( type->size == sz_COMPLEX ) // ISSUE: 64-bit (fixed 1.3.1.0)
- emit->append( new Chuck_Instr_Alloc_Member_Word4( value->offset ) );
+ else if( type->size == sz_VEC2 ) // ISSUE: 64-bit (fixed 1.3.1.0)
+ emit->append( new Chuck_Instr_Alloc_Member_Word4( value->offset ) ); // 1.5.1.7 (ge) NOTE also handles vec2
else if( type->size == sz_VEC3 ) // ge: added 1.3.5.3
emit->append( new Chuck_Instr_Alloc_Member_Vec3( value->offset ) );
else if( type->size == sz_VEC4 ) // ge: added 1.3.5.3
@@ -4986,7 +5073,7 @@ t_CKBOOL emit_engine_emit_exp_decl( Chuck_Emitter * emit, a_Exp_Decl decl,
instr->set_linepos( decl->line );
emit->append( instr );
}
- else if( type->size == sz_COMPLEX ) // ISSUE: 64-bit (fixed 1.3.1.0)
+ else if( type->size == sz_VEC2 ) // ISSUE: 64-bit (fixed 1.3.1.0)
{
emit->append( new Chuck_Instr_Alloc_Word4( local->offset ) );
}
@@ -5063,7 +5150,7 @@ t_CKBOOL emit_engine_emit_exp_decl( Chuck_Emitter * emit, a_Exp_Decl decl,
else if( type->size == sz_FLOAT ) // ISSUE: 64-bit (fixed 1.3.1.0)
emit->append( new Chuck_Instr_Assign_Primitive2 );
// size 16 primitive
- else if( type->size == sz_COMPLEX ) // ISSUE: 64-bit (fixed 1.3.1.0)
+ else if( type->size == sz_VEC2 ) // ISSUE: 64-bit (fixed 1.3.1.0)
emit->append( new Chuck_Instr_Assign_Primitive4 );
else
assert( FALSE );
@@ -5705,8 +5792,8 @@ t_CKBOOL emit_engine_emit_symbol( Chuck_Emitter * emit, S_Symbol symbol,
emit->append( new Chuck_Instr_Reg_Push_Mem( v->offset, v->is_context_global ) );
else if( v->type->size == sz_FLOAT ) // ISSUE: 64-bit (fixed 1.3.1.0)
emit->append( new Chuck_Instr_Reg_Push_Mem2( v->offset, v->is_context_global ) );
- else if( v->type->size == sz_COMPLEX ) // ISSUE: 64-bit (fixed 1.3.1.0)
- emit->append( new Chuck_Instr_Reg_Push_Mem4( v->offset, v->is_context_global ) );
+ else if( v->type->size == sz_VEC2 ) // ISSUE: 64-bit (fixed 1.3.1.0)
+ emit->append( new Chuck_Instr_Reg_Push_Mem4( v->offset, v->is_context_global ) ); // 1.5.1.7 (ge) NOTE also handles vec2
else if( v->type->size == sz_VEC3 ) // ge: added 1.3.5.3
emit->append( new Chuck_Instr_Reg_Push_Mem_Vec3( v->offset, v->is_context_global ) );
else if( v->type->size == sz_VEC4 ) // ge: added 1.3.5.3
diff --git a/src/core/chuck_instr.cpp b/src/core/chuck_instr.cpp
index 335c6b2fb..388e01315 100644
--- a/src/core/chuck_instr.cpp
+++ b/src/core/chuck_instr.cpp
@@ -789,6 +789,127 @@ void Chuck_Instr_Divide_polar_Reverse::execute( Chuck_VM * vm, Chuck_VM_Shred *
+//-----------------------------------------------------------------------------
+// name: execute()
+// desc: add two vec2 (ge) added 1.5.1.7 with ChuGL
+//-----------------------------------------------------------------------------
+void Chuck_Instr_Add_vec2::execute( Chuck_VM * vm, Chuck_VM_Shred * shred )
+{
+ t_CKVEC2 *& sp = (t_CKVEC2 *&)shred->reg->sp;
+ t_CKFLOAT *& sp_float = (t_CKFLOAT *&)sp;
+ pop_( sp, 2 );
+ // result
+ t_CKVEC2 r;
+ r.x = sp->x + (sp+1)->x;
+ r.y = sp->y + (sp+1)->y;
+ push_( sp_float, r.x );
+ push_( sp_float, r.y );
+}
+
+
+
+
+//-----------------------------------------------------------------------------
+// name: execute()
+// desc: subtract two vec2 (ge) added 1.5.1.7 with ChuGL
+//-----------------------------------------------------------------------------
+void Chuck_Instr_Minus_vec2::execute( Chuck_VM * vm, Chuck_VM_Shred * shred )
+{
+ t_CKVEC2 *& sp = (t_CKVEC2 *&)shred->reg->sp;
+ t_CKFLOAT *& sp_float = (t_CKFLOAT *&)sp;
+ pop_( sp, 2 );
+ // result
+ t_CKVEC2 r;
+ r.x = sp->x - (sp+1)->x;
+ r.y = sp->y - (sp+1)->y;
+ push_( sp_float, r.x );
+ push_( sp_float, r.y );
+}
+
+
+
+
+//-----------------------------------------------------------------------------
+// name: execute()
+// desc: float * vec2 (ge) added 1.5.1.7 with ChuGL
+//-----------------------------------------------------------------------------
+void Chuck_Instr_float_Times_vec2::execute( Chuck_VM * vm, Chuck_VM_Shred * shred )
+{
+ // stack pointer
+ t_CKBYTE *& sp = (t_CKBYTE *&)shred->reg->sp;
+ // pointer number of bytes
+ pop_( sp, sz_FLOAT+sz_VEC2 );
+ // the float
+ t_CKFLOAT f = *((t_CKFLOAT *)sp);
+ // the vector
+ t_CKVEC2 v = *((t_CKVEC2 *)(sp+sz_FLOAT));
+ // result
+ t_CKVEC2 r;
+ r.x = v.x * f;
+ r.y = v.y * f;
+ // pointer as vec2
+ t_CKVEC2 *& sp_vec2 = (t_CKVEC2 *&)sp;
+ // push on reg stack
+ push_( sp_vec2, r );
+}
+
+
+
+
+//-----------------------------------------------------------------------------
+// name: execute()
+// desc: vec2*float (ge) added 1.5.1.7 with ChuGL
+//-----------------------------------------------------------------------------
+void Chuck_Instr_vec2_Times_float::execute( Chuck_VM * vm, Chuck_VM_Shred * shred )
+{
+ // stack pointer
+ t_CKBYTE *& sp = (t_CKBYTE *&)shred->reg->sp;
+ // pointer number of bytes
+ pop_( sp, sz_FLOAT+sz_VEC2 );
+ // the vector
+ t_CKVEC2 v = *((t_CKVEC2 *)sp);
+ // the float
+ t_CKFLOAT f = *((t_CKFLOAT *)(sp+sz_VEC2));
+ // result
+ t_CKVEC2 r;
+ r.x = v.x * f;
+ r.y = v.y * f;
+ // pointer as vec2
+ t_CKVEC2 *& sp_vec2 = (t_CKVEC2 *&)sp;
+ // push on reg stack
+ push_( sp_vec2, r );
+}
+
+
+
+
+//-----------------------------------------------------------------------------
+// name: execute()
+// desc: vec2/float (ge) added 1.5.1.7 with ChuGL
+//-----------------------------------------------------------------------------
+void Chuck_Instr_vec2_Divide_float::execute( Chuck_VM * vm, Chuck_VM_Shred * shred )
+{
+ // stack pointer
+ t_CKBYTE *& sp = (t_CKBYTE *&)shred->reg->sp;
+ // pointer number of bytes
+ pop_( sp, sz_FLOAT+sz_VEC2 );
+ // the vector
+ t_CKVEC2 v = *((t_CKVEC2 *)sp);
+ // the float
+ t_CKFLOAT f = *((t_CKFLOAT *)(sp+sz_VEC2));
+ // result
+ t_CKVEC2 r;
+ r.x = v.x / f;
+ r.y = v.y / f;
+ // pointer as vec2
+ t_CKVEC2 *& sp_vec2 = (t_CKVEC2 *&)sp;
+ // push on reg stack
+ push_( sp_vec2, r );
+}
+
+
+
+
//-----------------------------------------------------------------------------
// name: execute()
// desc: add two vec3; ge: added 1.3.5.3 with other vec3 vec4 instructions
@@ -813,7 +934,7 @@ void Chuck_Instr_Add_vec3::execute( Chuck_VM * vm, Chuck_VM_Shred * shred )
//-----------------------------------------------------------------------------
// name: execute()
-// desc: ...
+// desc: subtract two vec3; ge: added 1.3.5.3 with other vec3 vec4 instructions
//-----------------------------------------------------------------------------
void Chuck_Instr_Minus_vec3::execute( Chuck_VM * vm, Chuck_VM_Shred * shred )
{
@@ -835,7 +956,7 @@ void Chuck_Instr_Minus_vec3::execute( Chuck_VM * vm, Chuck_VM_Shred * shred )
//-----------------------------------------------------------------------------
// name: execute()
-// desc: ...
+// desc: vector cross-product (ge) added 1.3.5.3 with other vec3 vec4 instructions
//-----------------------------------------------------------------------------
void Chuck_Instr_XProduct_vec3::execute( Chuck_VM * vm, Chuck_VM_Shred * shred )
{
@@ -857,7 +978,7 @@ void Chuck_Instr_XProduct_vec3::execute( Chuck_VM * vm, Chuck_VM_Shred * shred )
//-----------------------------------------------------------------------------
// name: execute()
-// desc: ...
+// desc: multiply two vec3; ge: added 1.3.5.3 with other vec3 vec4 instructions
//-----------------------------------------------------------------------------
void Chuck_Instr_float_Times_vec3::execute( Chuck_VM * vm, Chuck_VM_Shred * shred )
{
@@ -885,7 +1006,7 @@ void Chuck_Instr_float_Times_vec3::execute( Chuck_VM * vm, Chuck_VM_Shred * shre
//-----------------------------------------------------------------------------
// name: execute()
-// desc: ...
+// desc: scaling a vec3; ge: added 1.3.5.3 with other vec3 vec4 instructions
//-----------------------------------------------------------------------------
void Chuck_Instr_vec3_Times_float::execute( Chuck_VM * vm, Chuck_VM_Shred * shred )
{
@@ -913,7 +1034,7 @@ void Chuck_Instr_vec3_Times_float::execute( Chuck_VM * vm, Chuck_VM_Shred * shre
//-----------------------------------------------------------------------------
// name: execute()
-// desc: ...
+// desc: divide by scalar; ge: added 1.3.5.3 with other vec3 vec4 instructions
//-----------------------------------------------------------------------------
void Chuck_Instr_vec3_Divide_float::execute( Chuck_VM * vm, Chuck_VM_Shred * shred )
{
@@ -1491,7 +1612,91 @@ void Chuck_Instr_Divide_polar_Assign::execute( Chuck_VM * vm, Chuck_VM_Shred * s
//-----------------------------------------------------------------------------
// name: execute()
-// desc: ...
+// desc: vec2 +=> vec2var
+//-----------------------------------------------------------------------------
+void Chuck_Instr_Add_vec2_Assign::execute( Chuck_VM * vm, Chuck_VM_Shred * shred )
+{
+ t_CKBYTE *& sp = (t_CKBYTE *&)shred->reg->sp;
+ t_CKVEC2 temp;
+ // pop value + pointer
+ pop_( sp, sz_VEC2 + sz_UINT );
+
+ // assign
+ temp.x = (*(t_CKVEC2 **)(sp+sz_VEC2))->x += ((t_CKVEC2 *&)sp)->x;
+ temp.y = (*(t_CKVEC2 **)(sp+sz_VEC2))->y += ((t_CKVEC2 *&)sp)->y;
+ // push result
+ push_( (t_CKVEC2 *&)sp, temp );
+}
+
+
+
+
+//-----------------------------------------------------------------------------
+// name: execute()
+// desc: vec2 -=> vec2var
+//-----------------------------------------------------------------------------
+void Chuck_Instr_Minus_vec2_Assign::execute( Chuck_VM * vm, Chuck_VM_Shred * shred )
+{
+ t_CKBYTE *& sp = (t_CKBYTE *&)shred->reg->sp;
+ t_CKVEC2 temp;
+ // pop value + pointer
+ pop_( sp, sz_VEC2 + sz_UINT );
+
+ // assign
+ temp.x = (*(t_CKVEC2 **)(sp+sz_VEC2))->x -= ((t_CKVEC2 *&)sp)->x;
+ temp.y = (*(t_CKVEC2 **)(sp+sz_VEC2))->y -= ((t_CKVEC2 *&)sp)->y;
+ // push result
+ push_( (t_CKVEC2 *&)sp, temp );
+}
+
+
+
+
+//-----------------------------------------------------------------------------
+// name: execute()
+// desc: float *=> vec2var
+//-----------------------------------------------------------------------------
+void Chuck_Instr_float_Times_vec2_Assign::execute( Chuck_VM * vm, Chuck_VM_Shred * shred )
+{
+ t_CKBYTE *& sp = (t_CKBYTE *&)shred->reg->sp;
+ t_CKVEC2 temp;
+ // pop float + pointer
+ pop_( sp, sz_FLOAT + sz_UINT );
+
+ // assign
+ temp.x = (*(t_CKVEC2 **)(sp+sz_FLOAT))->x *= *((t_CKFLOAT *)sp);
+ temp.y = (*(t_CKVEC2 **)(sp+sz_FLOAT))->y *= *((t_CKFLOAT *)sp);
+ // push result
+ push_( (t_CKVEC2 *&)sp, temp );
+}
+
+
+
+
+//-----------------------------------------------------------------------------
+// name: execute()
+// desc: float /=> vec2var
+//-----------------------------------------------------------------------------
+void Chuck_Instr_vec2_Divide_float_Assign::execute( Chuck_VM * vm, Chuck_VM_Shred * shred )
+{
+ t_CKBYTE *& sp = (t_CKBYTE *&)shred->reg->sp;
+ t_CKVEC2 temp;
+ // pop float + pointer
+ pop_( sp, sz_FLOAT + sz_UINT );
+
+ // assign
+ temp.x = (*(t_CKVEC2 **)(sp+sz_FLOAT))->x /= *((t_CKFLOAT *)sp);
+ temp.y = (*(t_CKVEC2 **)(sp+sz_FLOAT))->y /= *((t_CKFLOAT *)sp);
+ // push result
+ push_( (t_CKVEC2 *&)sp, temp );
+}
+
+
+
+
+//-----------------------------------------------------------------------------
+// name: execute()
+// desc: vec3 +=> vec3var
//-----------------------------------------------------------------------------
void Chuck_Instr_Add_vec3_Assign::execute( Chuck_VM * vm, Chuck_VM_Shred * shred )
{
@@ -1513,7 +1718,7 @@ void Chuck_Instr_Add_vec3_Assign::execute( Chuck_VM * vm, Chuck_VM_Shred * shred
//-----------------------------------------------------------------------------
// name: execute()
-// desc: ...
+// desc: vec3 -=> vec3var
//-----------------------------------------------------------------------------
void Chuck_Instr_Minus_vec3_Assign::execute( Chuck_VM * vm, Chuck_VM_Shred * shred )
{
@@ -1535,7 +1740,7 @@ void Chuck_Instr_Minus_vec3_Assign::execute( Chuck_VM * vm, Chuck_VM_Shred * shr
//-----------------------------------------------------------------------------
// name: execute()
-// desc: ...
+// desc: float *=> vec3var
//-----------------------------------------------------------------------------
void Chuck_Instr_float_Times_vec3_Assign::execute( Chuck_VM * vm, Chuck_VM_Shred * shred )
{
@@ -1557,7 +1762,7 @@ void Chuck_Instr_float_Times_vec3_Assign::execute( Chuck_VM * vm, Chuck_VM_Shred
//-----------------------------------------------------------------------------
// name: execute()
-// desc: ...
+// desc: float /=> vec3var
//-----------------------------------------------------------------------------
void Chuck_Instr_vec3_Divide_float_Assign::execute( Chuck_VM * vm, Chuck_VM_Shred * shred )
{
@@ -1579,7 +1784,7 @@ void Chuck_Instr_vec3_Divide_float_Assign::execute( Chuck_VM * vm, Chuck_VM_Shre
//-----------------------------------------------------------------------------
// name: execute()
-// desc: ...
+// desc: float +=> vec4var
//-----------------------------------------------------------------------------
void Chuck_Instr_Add_vec4_Assign::execute( Chuck_VM * vm, Chuck_VM_Shred * shred )
{
@@ -1602,7 +1807,7 @@ void Chuck_Instr_Add_vec4_Assign::execute( Chuck_VM * vm, Chuck_VM_Shred * shred
//-----------------------------------------------------------------------------
// name: execute()
-// desc: ...
+// desc: floa -=> vec4var
//-----------------------------------------------------------------------------
void Chuck_Instr_Minus_vec4_Assign::execute( Chuck_VM * vm, Chuck_VM_Shred * shred )
{
@@ -1625,7 +1830,7 @@ void Chuck_Instr_Minus_vec4_Assign::execute( Chuck_VM * vm, Chuck_VM_Shred * shr
//-----------------------------------------------------------------------------
// name: execute()
-// desc: ...
+// desc: float *=> vec4var
//-----------------------------------------------------------------------------
void Chuck_Instr_float_Times_vec4_Assign::execute( Chuck_VM * vm, Chuck_VM_Shred * shred )
{
@@ -1648,7 +1853,7 @@ void Chuck_Instr_float_Times_vec4_Assign::execute( Chuck_VM * vm, Chuck_VM_Shred
//-----------------------------------------------------------------------------
// name: execute()
-// desc: ...
+// desc: float /=> vec4var
//-----------------------------------------------------------------------------
void Chuck_Instr_vec4_Divide_float_Assign::execute( Chuck_VM * vm, Chuck_VM_Shred * shred )
{
@@ -2552,7 +2757,7 @@ void Chuck_Instr_Reg_Pop_Mem::execute( Chuck_VM * vm, Chuck_VM_Shred * shred )
//-----------------------------------------------------------------------------
// name: execute()
-// desc: ...
+// desc: pop an int value from reg stack
//-----------------------------------------------------------------------------
void Chuck_Instr_Reg_Pop_Int::execute( Chuck_VM * vm, Chuck_VM_Shred * shred )
{
@@ -2567,7 +2772,7 @@ void Chuck_Instr_Reg_Pop_Int::execute( Chuck_VM * vm, Chuck_VM_Shred * shred )
//-----------------------------------------------------------------------------
// name: execute()
-// desc: ...
+// desc: pop a float value from reg stack
//-----------------------------------------------------------------------------
void Chuck_Instr_Reg_Pop_Float::execute( Chuck_VM * vm, Chuck_VM_Shred * shred )
{
@@ -2582,11 +2787,11 @@ void Chuck_Instr_Reg_Pop_Float::execute( Chuck_VM * vm, Chuck_VM_Shred * shred )
//-----------------------------------------------------------------------------
// name: execute()
-// desc: ...
+// desc: pop a vec2/complex/polar value from reg stack
//-----------------------------------------------------------------------------
-void Chuck_Instr_Reg_Pop_Complex::execute( Chuck_VM * vm, Chuck_VM_Shred * shred )
+void Chuck_Instr_Reg_Pop_Vec2ComplexPolar::execute( Chuck_VM * vm, Chuck_VM_Shred * shred )
{
- t_CKCOMPLEX *& reg_sp = (t_CKCOMPLEX *&)shred->reg->sp;
+ t_CKVEC2 *& reg_sp = (t_CKVEC2 *&)shred->reg->sp;
// pop word from reg stack
pop_( reg_sp, 1 );
@@ -3403,7 +3608,39 @@ void Chuck_Instr_Neq_complex::execute( Chuck_VM * vm, Chuck_VM_Shred * shred )
//-----------------------------------------------------------------------------
// name: execute()
-// desc: ...
+// desc: vec2 == vec2
+//-----------------------------------------------------------------------------
+void Chuck_Instr_Eq_vec2::execute( Chuck_VM * vm, Chuck_VM_Shred * shred )
+{
+ // also works for polar
+ t_CKVEC2 *& sp = (t_CKVEC2 *&)shred->reg->sp;
+ t_CKUINT *& sp_uint = (t_CKUINT *&)sp;
+ pop_( sp, 2 );
+ push_( sp_uint, (sp->x == (sp+1)->x) && (sp->y == (sp+1)->y) );
+}
+
+
+
+
+//-----------------------------------------------------------------------------
+// name: execute()
+// desc: vec2 != vec2
+//-----------------------------------------------------------------------------
+void Chuck_Instr_Neq_vec2::execute( Chuck_VM * vm, Chuck_VM_Shred * shred )
+{
+ // also works for polar
+ t_CKVEC2 *& sp = (t_CKVEC2 *&)shred->reg->sp;
+ t_CKUINT *& sp_uint = (t_CKUINT *&)sp;
+ pop_( sp, 2 );
+ push_( sp_uint, (sp->x != (sp+1)->x) || (sp->y != (sp+1)->y) );
+}
+
+
+
+
+//-----------------------------------------------------------------------------
+// name: execute()
+// desc: vec3 == vec3
//-----------------------------------------------------------------------------
void Chuck_Instr_Eq_vec3::execute( Chuck_VM * vm, Chuck_VM_Shred * shred )
{
@@ -3420,7 +3657,7 @@ void Chuck_Instr_Eq_vec3::execute( Chuck_VM * vm, Chuck_VM_Shred * shred )
//-----------------------------------------------------------------------------
// name: execute()
-// desc: ...
+// desc: vec3 != vec3
//-----------------------------------------------------------------------------
void Chuck_Instr_Neq_vec3::execute( Chuck_VM * vm, Chuck_VM_Shred * shred )
{
@@ -3437,7 +3674,7 @@ void Chuck_Instr_Neq_vec3::execute( Chuck_VM * vm, Chuck_VM_Shred * shred )
//-----------------------------------------------------------------------------
// name: execute()
-// desc: ...
+// desc: vec4 == vec4
//-----------------------------------------------------------------------------
void Chuck_Instr_Eq_vec4::execute( Chuck_VM * vm, Chuck_VM_Shred * shred )
{
@@ -3454,7 +3691,7 @@ void Chuck_Instr_Eq_vec4::execute( Chuck_VM * vm, Chuck_VM_Shred * shred )
//-----------------------------------------------------------------------------
// name: execute()
-// desc: ...
+// desc: vec4 != vec4
//-----------------------------------------------------------------------------
void Chuck_Instr_Neq_vec4::execute( Chuck_VM * vm, Chuck_VM_Shred * shred )
{
@@ -4412,19 +4649,19 @@ void Chuck_Instr_Assign_Primitive2::execute( Chuck_VM * vm, Chuck_VM_Shred * shr
//-----------------------------------------------------------------------------
// name: execute()
-// desc: assign primitive (4 word)
+// desc: assign primitive (4 word) vec2 complex polar
//-----------------------------------------------------------------------------
void Chuck_Instr_Assign_Primitive4::execute( Chuck_VM * vm, Chuck_VM_Shred * shred )
{
t_CKUINT *& reg_sp = (t_CKUINT *&)shred->reg->sp;
// pop word from reg stack
- pop_( reg_sp, 1 + (sz_COMPLEX / sz_UINT) ); // ISSUE: 64-bit (fixed 1.3.1.0)
+ pop_( reg_sp, 1 + (sz_VEC2 / sz_UINT) ); // ISSUE: 64-bit (fixed 1.3.1.0)
// copy popped value into mem stack
- *( (t_CKCOMPLEX*)(*(reg_sp+(sz_COMPLEX/sz_UINT))) ) = *(t_CKCOMPLEX *)reg_sp; // ISSUE: 64-bit (fixed 1.3.1.0)
+ *( (t_CKVEC2*)(*(reg_sp+(sz_VEC2/sz_UINT))) ) = *(t_CKVEC2 *)reg_sp; // ISSUE: 64-bit (fixed 1.3.1.0)
- t_CKCOMPLEX *& sp_complex = (t_CKCOMPLEX *&)reg_sp;
- push_( sp_complex, *sp_complex );
+ t_CKVEC2 *& sp_vec2 = (t_CKVEC2 *&)reg_sp;
+ push_( sp_vec2, *sp_vec2 );
}
@@ -5003,12 +5240,12 @@ void Chuck_Instr_Func_Call_Member::execute( Chuck_VM * vm, Chuck_VM_Shred * shre
t_CKFLOAT *& sp_double = (t_CKFLOAT *&)reg_sp;
push_( sp_double, retval.v_float );
}
- else if( m_val == kindof_COMPLEX ) // ISSUE: 64-bit (fixed 1.3.1.0)
+ else if( m_val == kindof_VEC2 ) // ISSUE: 64-bit (fixed 1.3.1.0) | 1.5.1.7 (ge) complex -> vec2
{
// push the return args
- t_CKCOMPLEX *& sp_complex = (t_CKCOMPLEX *&)reg_sp;
- // TODO: polar same?
- push_( sp_complex, retval.v_complex );
+ t_CKVEC2 *& sp_vec2 = (t_CKVEC2 *&)reg_sp;
+ // in this context vec2 = complex = polar
+ push_( sp_vec2, retval.v_vec2 );
}
else if( m_val == kindof_VEC3 ) // 1.3.5.3
{
@@ -5139,12 +5376,12 @@ void Chuck_Instr_Func_Call_Static::execute( Chuck_VM * vm, Chuck_VM_Shred * shre
t_CKFLOAT *& sp_double = (t_CKFLOAT *&)reg_sp;
push_( sp_double, retval.v_float );
}
- else if( m_val == kindof_COMPLEX ) // ISSUE: 64-bit (fixed 1.3.1.0)
+ else if( m_val == kindof_VEC2 ) // ISSUE: 64-bit (fixed 1.3.1.0) | 1.5.1.7 (ge) complex -> vec2
{
// push the return args
- t_CKCOMPLEX *& sp_complex = (t_CKCOMPLEX *&)reg_sp;
- // TODO: polar same?
- push_( sp_complex, retval.v_complex );
+ t_CKVEC2 *& sp_vec2 = (t_CKVEC2 *&)reg_sp;
+ // in this context vec2 = complex = polar
+ push_( sp_vec2, retval.v_vec2 );
}
else if( m_val == kindof_VEC3 ) // 1.3.5.3
{
@@ -5265,12 +5502,12 @@ void Chuck_Instr_Func_Call_Global::execute( Chuck_VM * vm, Chuck_VM_Shred * shre
t_CKFLOAT *& sp_double = (t_CKFLOAT *&)reg_sp;
push_( sp_double, retval.v_float );
}
- else if( m_val == kindof_COMPLEX ) // ISSUE: 64-bit (fixed 1.3.1.0)
+ else if( m_val == kindof_VEC2 ) // ISSUE: 64-bit (fixed 1.3.1.0) | 1.5.1.7 (ge) complex -> vec2
{
// push the return args
- t_CKCOMPLEX *& sp_complex = (t_CKCOMPLEX *&)reg_sp;
- // TODO: polar same?
- push_( sp_complex, retval.v_complex );
+ t_CKVEC2 *& sp_vec2 = (t_CKVEC2 *&)reg_sp;
+ // in this context vec2 = complex = polar
+ push_( sp_vec2, retval.v_vec2 );
}
else if( m_val == kindof_VEC3 ) // 1.3.5.3
{
@@ -5635,16 +5872,16 @@ void Chuck_Instr_Array_Init_Literal::execute( Chuck_VM * vm, Chuck_VM_Shred * sh
// push the pointer
push_( reg_sp, (t_CKUINT)array );
}
- else if( m_type_ref->size == sz_COMPLEX ) // ISSUE: 64-bit (fixed 1.3.1.0)
+ else if( m_type_ref->size == sz_VEC2 ) // ISSUE: 64-bit (fixed 1.3.1.0) | also should work for vec2 (noted 1.5.1.7)
{
// pop the values
- pop_( reg_sp, m_length * (sz_COMPLEX / sz_INT) ); // 1.3.1.0 added size division
+ pop_( reg_sp, m_length * (sz_VEC2 / sz_INT) ); // 1.3.1.0 added size division
// instantiate array
Chuck_Array16 * array = new Chuck_Array16( m_length );
// problem
if( !array ) goto out_of_memory;
// fill array
- t_CKCOMPLEX * sp = (t_CKCOMPLEX *)reg_sp;
+ t_CKVEC2 * sp = (t_CKVEC2 *)reg_sp;
// intialize object
initialize_object( array, vm->env()->ckt_array, shred, vm );
// differentiate between complex and polar | 1.5.1.0 (ge) added, used for sorting Array16s
@@ -5842,7 +6079,7 @@ Chuck_Object * do_alloc_array( Chuck_VM * vm, // REFACTOR-2017: added
// initialize_object( baseX, vm->env()->ckt_array );
return baseX;
}
- else if( kind == kindof_COMPLEX ) // ISSUE: 64-bit (fixed 1.3.1.0)
+ else if( kind == kindof_VEC2 ) // ISSUE: 64-bit (fixed 1.3.1.0) | 1.5.1.7 (ge) complex -> vec2
{
Chuck_Array16 * baseX = new Chuck_Array16( *capacity );
if( !baseX ) goto out_of_memory;
@@ -6104,9 +6341,10 @@ void Chuck_Instr_Array_Access::execute( Chuck_VM * vm, Chuck_VM_Shred * shred )
t_CKINT ni = 0; // normalized
t_CKUINT val = 0;
t_CKFLOAT fval = 0;
- t_CKCOMPLEX cval;
- cval.re = 0;
- cval.im = 0;
+ t_CKVEC2 v2;
+ v2.x = 0;
+ v2.y = 0;
+ // vec2 should behave here as complex
t_CKVEC3 v3;
t_CKVEC4 v4;
@@ -6166,7 +6404,7 @@ void Chuck_Instr_Array_Access::execute( Chuck_VM * vm, Chuck_VM_Shred * shred )
push_( ((t_CKFLOAT *&)sp), fval );
}
}
- else if( m_kind == kindof_COMPLEX ) // ISSUE: 64-bit
+ else if( m_kind == kindof_VEC2 ) // ISSUE: 64-bit | 1.5.1.7 (ge) complex -> vec2
{
// get array
Chuck_Array16 * arr = (Chuck_Array16 *)(*sp);
@@ -6184,10 +6422,10 @@ void Chuck_Instr_Array_Access::execute( Chuck_VM * vm, Chuck_VM_Shred * shred )
push_( sp, val );
} else {
// get the value
- if( !arr->get( ni, &cval ) )
+ if( !arr->get( ni, &v2 ) )
goto array_out_of_bound;
// push the value
- push_( ((t_CKCOMPLEX *&)sp), cval );
+ push_( ((t_CKVEC2 *&)sp), v2 );
}
}
else if( m_kind == kindof_VEC3 ) // 1.3.5.3
@@ -6278,9 +6516,7 @@ void Chuck_Instr_Array_Map_Access::execute( Chuck_VM * vm, Chuck_VM_Shred * shre
Chuck_String * key = NULL;
t_CKUINT val = 0;
t_CKFLOAT fval = 0;
- t_CKCOMPLEX cval;
- cval.re = 0;
- cval.im = 0;
+ t_CKVEC2 v2; v2.x = v2.y = 0;
t_CKVEC3 v3;
t_CKVEC4 v4;
@@ -6336,7 +6572,7 @@ void Chuck_Instr_Array_Map_Access::execute( Chuck_VM * vm, Chuck_VM_Shred * shre
push_( ((t_CKFLOAT *&)sp), fval );
}
}
- else if( m_kind == kindof_COMPLEX ) // ISSUE: 64-bit (fixed 1.3.1.0)
+ else if( m_kind == kindof_VEC2 ) // ISSUE: 64-bit (fixed 1.3.1.0)
{
// get array
Chuck_Array16 * arr = (Chuck_Array16 *)(*sp);
@@ -6352,10 +6588,10 @@ void Chuck_Instr_Array_Map_Access::execute( Chuck_VM * vm, Chuck_VM_Shred * shre
push_( sp, val );
} else {
// get the value
- if( !arr->get( key->str(), &cval ) )
+ if( !arr->get( key->str(), &v2 ) )
goto error;
// push the value
- push_( ((t_CKCOMPLEX *&)sp), cval );
+ push_( ((t_CKVEC2 *&)sp), v2 );
}
}
else if( m_kind == kindof_VEC3 ) // 1.3.5.3
@@ -6441,9 +6677,9 @@ void Chuck_Instr_Array_Access_Multi::execute( Chuck_VM * vm, Chuck_VM_Shred * sh
t_CKINT i = 0;
t_CKUINT val = 0, j;
t_CKFLOAT fval = 0;
- t_CKCOMPLEX cval;
t_CKINT * ptr = NULL;
- t_CKUINT index = 0; cval.re = cval.im = 0;
+ t_CKUINT index = 0;
+ t_CKVEC2 v2; v2.x = v2.y = 0;
t_CKVEC3 v3;
t_CKVEC4 v4;
@@ -6537,7 +6773,7 @@ void Chuck_Instr_Array_Access_Multi::execute( Chuck_VM * vm, Chuck_VM_Shred * sh
push_( ((t_CKFLOAT *&)sp), fval );
}
}
- else if( m_kind == kindof_COMPLEX ) // ISSUE: 64-bit (fixed 1.3.1.0)
+ else if( m_kind == kindof_VEC2 ) // ISSUE: 64-bit (fixed 1.3.1.0)
{
// get array
Chuck_Array16 * arr = (Chuck_Array16 *)(base);
@@ -6553,10 +6789,10 @@ void Chuck_Instr_Array_Access_Multi::execute( Chuck_VM * vm, Chuck_VM_Shred * sh
push_( sp, val );
} else {
// get the value
- if( !arr->get( i, &cval ) )
+ if( !arr->get( i, &v2 ) )
goto array_out_of_bound;
// push the value
- push_( ((t_CKCOMPLEX *&)sp), cval );
+ push_( ((t_CKVEC2 *&)sp), v2 );
}
}
else if( m_kind == kindof_VEC3 ) // 1.3.5.3
@@ -6656,9 +6892,7 @@ void Chuck_Instr_Array_Append::execute( Chuck_VM * vm, Chuck_VM_Shred * shred )
// t_CKINT i = 0;
t_CKUINT val = 0;
t_CKFLOAT fval = 0;
- t_CKCOMPLEX cval;
- cval.re = 0;
- cval.im = 0;
+ t_CKVEC2 v2; v2.x = v2.y = 0;
t_CKVEC3 v3;
t_CKVEC4 v4;
@@ -6667,7 +6901,7 @@ void Chuck_Instr_Array_Append::execute( Chuck_VM * vm, Chuck_VM_Shred * shred )
// check kind
if( m_val == kindof_INT ) howmuch = 1;
else if( m_val == kindof_FLOAT ) howmuch = sz_FLOAT / sz_INT;
- else if( m_val == kindof_COMPLEX ) howmuch = sz_COMPLEX / sz_INT;
+ else if( m_val == kindof_VEC2 ) howmuch = sz_VEC2 / sz_INT;
else if( m_val == kindof_VEC3 ) howmuch = sz_VEC3 / sz_INT;
else if( m_val == kindof_VEC4 ) howmuch = sz_VEC4 / sz_INT;
// pop (1.3.1.0: use howmuch instead of m_val/4)
@@ -6696,14 +6930,14 @@ void Chuck_Instr_Array_Append::execute( Chuck_VM * vm, Chuck_VM_Shred * shred )
// append
arr->push_back( fval );
}
- else if( m_val == kindof_COMPLEX ) // ISSUE: 64-bit (fixed 1.3.1.0)
+ else if( m_val == kindof_VEC2 ) // ISSUE: 64-bit (fixed 1.3.1.0)
{
// get array
Chuck_Array16 * arr = (Chuck_Array16 *)(*sp);
// get value
- cval = (*(t_CKCOMPLEX *)(sp+1));
+ v2 = (*(t_CKVEC2 *)(sp+1));
// append
- arr->push_back( cval );
+ arr->push_back( v2 );
}
else if( m_val == kindof_VEC3 ) // 1.3.5.3
{
@@ -6780,7 +7014,7 @@ void Chuck_Instr_Dot_Member_Data::execute( Chuck_VM * vm, Chuck_VM_Shred * shred
// 1.3.1.0: check type to use kind instead of size
if( m_kind == kindof_INT ) { push_( sp, *((t_CKUINT *)data) ); } // ISSUE: 64-bit (fixed 1.3.1.0)
else if( m_kind == kindof_FLOAT ) { push_float( sp, *((t_CKFLOAT *)data) ); } // ISSUE: 64-bit (fixed 1.3.1.0)
- else if( m_kind == kindof_COMPLEX ) { push_complex( sp, *((t_CKCOMPLEX *)data) ); } // ISSUE: 64-bit (fixed 1.3.1.0) // TODO: polar same?
+ else if( m_kind == kindof_VEC2 ) { push_vec2( sp, *((t_CKVEC2 *)data) ); } // ISSUE: 64-bit (fixed 1.3.1.0) | in this context, vec2 = complex = polar
else if( m_kind == kindof_VEC3 ) { push_vec3( sp, *((t_CKVEC3 *)data) ); } // 1.3.5.3
else if( m_kind == kindof_VEC4 ) { push_vec4( sp, *((t_CKVEC4 *)data) ); } // 1.3.5.3
else assert( FALSE );
@@ -6894,7 +7128,7 @@ void Chuck_Instr_Dot_Static_Data::execute( Chuck_VM * vm, Chuck_VM_Shred * shred
// 1.3.1.0: check type to use kind instead of size
if( m_kind == kindof_INT ) { push_( sp, *((t_CKUINT *)data) ); } // ISSUE: 64-bit (fixed 1.3.1.0)
else if( m_kind == kindof_FLOAT ) { push_float( sp, *((t_CKFLOAT *)data) ); } // ISSUE: 64-bit (fixed 1.3.1.0)
- else if( m_kind == kindof_COMPLEX ) { push_complex( sp, *((t_CKCOMPLEX *)data) ); } // ISSUE: 64-bit (fixed 1.3.1.0) // TODO: polar same?
+ else if( m_kind == kindof_VEC2 ) { push_vec2( sp, *((t_CKVEC2 *)data) ); } // ISSUE: 64-bit (fixed 1.3.1.0) | in this context, vec2 = complex = polar
else if( m_kind == kindof_VEC3 ) { push_vec3( sp, *((t_CKVEC3 *)data) ); } // 1.3.5.3
else if( m_kind == kindof_VEC4 ) { push_vec4( sp, *((t_CKVEC4 *)data) ); } // 1.3.5.3
else assert( FALSE );
@@ -6925,7 +7159,7 @@ void Chuck_Instr_Dot_Static_Import_Data::execute( Chuck_VM * vm, Chuck_VM_Shred
// 1.3.1.0: check type to use kind instead of size
if( m_kind == kindof_INT ) { push_( sp, *((t_CKUINT *)m_addr) ); } // ISSUE: 64-bit (fixed 1.3.1.0)
else if( m_kind == kindof_FLOAT ) { push_float( sp, *((t_CKFLOAT *)m_addr) ); } // ISSUE: 64-bit (fixed 1.3.1.0)
- else if( m_kind == kindof_COMPLEX ) { push_complex( sp, *((t_CKCOMPLEX *)m_addr) ); } // ISSUE: 64-bit (fixed 1.3.1.0) // TODO: polar same?
+ else if( m_kind == kindof_VEC2 ) { push_vec2( sp, *((t_CKVEC2 *)m_addr) ); } // ISSUE: 64-bit (fixed 1.3.1.0) | in this context, vec2 = complex = polar
else if( m_kind == kindof_VEC3 ) { push_vec3( sp, *((t_CKVEC3 *)m_addr) ); } // 1.3.5.3
else if( m_kind == kindof_VEC4 ) { push_vec4( sp, *((t_CKVEC4 *)m_addr) ); } // 1.3.5.3
else assert( FALSE );
@@ -6957,7 +7191,7 @@ void Chuck_Instr_Dot_Static_Func::execute( Chuck_VM * vm, Chuck_VM_Shred * shred
//-----------------------------------------------------------------------------
// name: execute()
-// desc: print the first field of a complex/polar/vec3/vec4 value
+// desc: access the first field of a complex/polar/vec3/vec4 value
//-----------------------------------------------------------------------------
void Chuck_Instr_Dot_Cmp_First::execute( Chuck_VM * vm, Chuck_VM_Shred * shred )
{
@@ -6970,7 +7204,7 @@ void Chuck_Instr_Dot_Cmp_First::execute( Chuck_VM * vm, Chuck_VM_Shred * shred )
pop_( sp, 1 );
// push var addr or value?
if( m_emit_addr ) {
- // push addr (NOTE this works for complex/polar/vec3/vec4)
+ // push addr (NOTE this works for complex/polar/vec2/vec3/vec4)
push_( sp, (t_CKUINT)(&((*(t_CKCOMPLEX **)sp)->re)) );
} else {
// push value
@@ -6986,10 +7220,10 @@ void Chuck_Instr_Dot_Cmp_First::execute( Chuck_VM * vm, Chuck_VM_Shred * shred )
switch( m_kind )
{
// get corresponding value, pop that value, push field
- case kindof_COMPLEX:
+ case kindof_VEC2:
{
- t_CKCOMPLEX *& sp = (t_CKCOMPLEX *&)shred->reg->sp;
- pop_( sp, 1 ); push_float( sp, sp->re );
+ t_CKVEC2 *& sp = (t_CKVEC2 *&)shred->reg->sp;
+ pop_( sp, 1 ); push_float( sp, sp->x );
}
break;
@@ -7018,7 +7252,7 @@ void Chuck_Instr_Dot_Cmp_First::execute( Chuck_VM * vm, Chuck_VM_Shred * shred )
//-----------------------------------------------------------------------------
// name: execute()
-// desc: print the second field of a complex/polar/vec3/vec4 value
+// desc: access the second field of a complex/polar/vec2/vec3/vec4 value
//-----------------------------------------------------------------------------
void Chuck_Instr_Dot_Cmp_Second::execute( Chuck_VM * vm, Chuck_VM_Shred * shred )
{
@@ -7031,7 +7265,7 @@ void Chuck_Instr_Dot_Cmp_Second::execute( Chuck_VM * vm, Chuck_VM_Shred * shred
pop_( sp, 1 );
// emit as var address or as value?
if( m_emit_addr ) {
- // push addr (works for complex/polar/vec3/vec4)
+ // push addr (works for complex/polar/vec2/vec3/vec4)
push_( sp, (t_CKUINT)(&((*(t_CKCOMPLEX **)sp)->im)) );
} else {
// push value
@@ -7047,10 +7281,10 @@ void Chuck_Instr_Dot_Cmp_Second::execute( Chuck_VM * vm, Chuck_VM_Shred * shred
switch( m_kind )
{
// get corresponding value, pop that value, push field
- case kindof_COMPLEX:
+ case kindof_VEC2:
{
- t_CKCOMPLEX *& sp = (t_CKCOMPLEX *&)shred->reg->sp;
- pop_( sp, 1 ); push_float( sp, sp->im );
+ t_CKVEC2 *& sp = (t_CKVEC2 *&)shred->reg->sp;
+ pop_( sp, 1 ); push_float( sp, sp->y );
}
break;
@@ -7079,7 +7313,7 @@ void Chuck_Instr_Dot_Cmp_Second::execute( Chuck_VM * vm, Chuck_VM_Shred * shred
//-----------------------------------------------------------------------------
// name: execute()
-// desc: print the third field of a complex/polar/vec3/vec4 value
+// desc: access the third field of a vec3/vec4 value
//-----------------------------------------------------------------------------
void Chuck_Instr_Dot_Cmp_Third::execute( Chuck_VM * vm, Chuck_VM_Shred * shred )
{
@@ -7133,7 +7367,7 @@ void Chuck_Instr_Dot_Cmp_Third::execute( Chuck_VM * vm, Chuck_VM_Shred * shred )
//-----------------------------------------------------------------------------
// name: execute()
-// desc: print the fourth field of a complex/polar/vec3/vec4 value
+// desc: access the fourth field of a vec4 value
//-----------------------------------------------------------------------------
void Chuck_Instr_Dot_Cmp_Fourth::execute( Chuck_VM * vm, Chuck_VM_Shred * shred )
{
@@ -7310,11 +7544,40 @@ void Chuck_Instr_Cast_polar2complex::execute( Chuck_VM * vm, Chuck_VM_Shred * sh
//-----------------------------------------------------------------------------
// name: execute()
-// desc: ...
+// desc: cast vec2 to vec3 on reg stack
+//-----------------------------------------------------------------------------
+void Chuck_Instr_Cast_vec2tovec3::execute( Chuck_VM * vm, Chuck_VM_Shred * shred )
+{
+ t_CKFLOAT *& sp = (t_CKFLOAT *&)shred->reg->sp;
+ // zero pad for z
+ push_( sp, 0 );
+}
+
+
+
+
+//-----------------------------------------------------------------------------
+// name: execute()
+// desc: cast vec2 to vec4 on reg stack
+//-----------------------------------------------------------------------------
+void Chuck_Instr_Cast_vec2tovec4::execute( Chuck_VM * vm, Chuck_VM_Shred * shred )
+{
+ t_CKFLOAT *& sp = (t_CKFLOAT *&)shred->reg->sp;
+ // zero pad for z, w
+ push_( sp, 0 );
+ push_( sp, 0 );
+}
+
+
+
+
+//-----------------------------------------------------------------------------
+// name: execute()
+// desc: cast vec3 to vec4 on reg stack
//-----------------------------------------------------------------------------
void Chuck_Instr_Cast_vec3tovec4::execute( Chuck_VM * vm, Chuck_VM_Shred * shred )
{
- t_CKFLOAT * sp = (t_CKFLOAT *)shred->reg->sp;
+ t_CKFLOAT *& sp = (t_CKFLOAT *&)shred->reg->sp;
// zero pad it
push_( sp, 0 );
}
@@ -7324,11 +7587,39 @@ void Chuck_Instr_Cast_vec3tovec4::execute( Chuck_VM * vm, Chuck_VM_Shred * shred
//-----------------------------------------------------------------------------
// name: execute()
-// desc: ...
+// desc: cast vec3 to vec2 on reg stack
+//-----------------------------------------------------------------------------
+void Chuck_Instr_Cast_vec3tovec2::execute( Chuck_VM * vm, Chuck_VM_Shred * shred )
+{
+ t_CKFLOAT *& sp = (t_CKFLOAT *&)shred->reg->sp;
+ // remove z component
+ pop_( sp, 1 );
+}
+
+
+
+
+//-----------------------------------------------------------------------------
+// name: execute()
+// desc: cast vec4 to vec2 on reg stack
+//-----------------------------------------------------------------------------
+void Chuck_Instr_Cast_vec4tovec2::execute( Chuck_VM * vm, Chuck_VM_Shred * shred )
+{
+ t_CKFLOAT *& sp = (t_CKFLOAT *&)shred->reg->sp;
+ // remove z and w components
+ pop_( sp, 2 );
+}
+
+
+
+
+//-----------------------------------------------------------------------------
+// name: execute()
+// desc: cast vec4 to vec3 on reg stack
//-----------------------------------------------------------------------------
void Chuck_Instr_Cast_vec4tovec3::execute( Chuck_VM * vm, Chuck_VM_Shred * shred )
{
- t_CKFLOAT * sp = (t_CKFLOAT *)shred->reg->sp;
+ t_CKFLOAT *& sp = (t_CKFLOAT *&)shred->reg->sp;
// remove w component
pop_( sp, 1 );
}
@@ -7901,12 +8192,12 @@ void Chuck_Instr_ForEach_Inc_And_Branch::execute( Chuck_VM * vm, Chuck_VM_Shred
arr->get( *counter, (t_CKFLOAT *)pVar );
break;
}
- case kindof_COMPLEX:
+ case kindof_VEC2:
{
// cast to specific array type
Chuck_Array16 * arr = (Chuck_Array16 *) array;
// get element
- arr->get( *counter, (t_CKCOMPLEX *)pVar );
+ arr->get( *counter, (t_CKVEC2 *)pVar );
break;
}
case kindof_VEC3:
@@ -8248,6 +8539,48 @@ void Chuck_Instr_IO_out_polar::execute( Chuck_VM * vm, Chuck_VM_Shred * shred )
+//-----------------------------------------------------------------------------
+// name: execute() | 1.5.1.7
+// desc: insert vec2 value into output stream
+//-----------------------------------------------------------------------------
+void Chuck_Instr_IO_out_vec2::execute( Chuck_VM * vm, Chuck_VM_Shred * shred )
+{
+ t_CKINT *& sp = (t_CKINT *&)shred->reg->sp;
+
+ // pop the value
+ pop_( sp, 1 + (sz_VEC2 / sz_INT) ); // ISSUE: 64-bit (fixed 1.3.1.0)
+
+ // ISSUE: 64-bit
+ // the IO
+ Chuck_IO **& ppIO = (Chuck_IO **&)sp;
+
+ // check it
+ if( *(ppIO) == NULL ) goto null_pointer;
+
+ // write the value
+ (*ppIO)->write( *((t_CKVEC2 *)(sp+1)) );
+
+ // push the IO
+ push_( sp, (t_CKINT)(*(ppIO)) );
+
+ return;
+
+null_pointer:
+ // we have a problem
+ EM_exception(
+ "NullPointer: (IO output vec2) on line[%lu] in shred[id=%lu:%s]",
+ m_linepos, shred->xid, shred->name.c_str() );
+ goto done;
+
+done:
+ // do something!
+ shred->is_running = FALSE;
+ shred->is_done = TRUE;
+}
+
+
+
+
//-----------------------------------------------------------------------------
// name: execute() | 1.5.1.0
// desc: insert vec3 value into output stream
@@ -8423,7 +8756,7 @@ void Chuck_Instr_Hack::execute( Chuck_VM * vm, Chuck_VM_Shred * shred )
// print it
CK_FPRINTF_STDERR( "%f :(%s)\n", *(sp-1), m_type_ref->c_name() );
}
- else if( m_type_ref->size == sz_COMPLEX ) // ISSUE: 64-bit (fixed 1.3.1.0)
+ else if( m_type_ref->size == sz_VEC2 ) // ISSUE: 64-bit (fixed 1.3.1.0)
{
if( m_type_ref->xid == te_complex )
{
@@ -8437,6 +8770,12 @@ void Chuck_Instr_Hack::execute( Chuck_VM * vm, Chuck_VM_Shred * shred )
// print it
CK_FPRINTF_STDERR( "%%(%.4f,%.4f*pi) :(%s)\n", *(sp-2), *(sp-1)/CK_ONE_PI, m_type_ref->c_name() );
}
+ else if( m_type_ref->xid == te_vec2 ) // 1.5.1.7
+ {
+ t_CKFLOAT * sp = (t_CKFLOAT *)shred->reg->sp;
+ // print it
+ CK_FPRINTF_STDERR( "@(%.4f,%.4f) :(%s)\n", *(sp-2), *(sp-1), m_type_ref->c_name() );
+ }
else
{
CK_FPRINTF_STDERR( "[chuck]: internal error printing 16-word primitive...\n" );
@@ -8565,7 +8904,7 @@ void Chuck_Instr_Gack::execute( Chuck_VM * vm, Chuck_VM_Shred * shred )
the_sp += sz_FLOAT; // ISSUE: 64-bit (fixed 1.3.1.0)
}
- else if( type->size == sz_COMPLEX ) // ISSUE: 64-bit (fixed 1.3.1.0)
+ else if( type->size == sz_VEC2 ) // ISSUE: 64-bit (fixed 1.3.1.0)
{
t_CKFLOAT * sp = (t_CKFLOAT *)the_sp;
if( type->xid == te_complex )
@@ -8574,8 +8913,11 @@ void Chuck_Instr_Gack::execute( Chuck_VM * vm, Chuck_VM_Shred * shred )
else if( type->xid == te_polar )
// print it
CK_FPRINTF_STDERR( "%%(%.4f,%.4f*pi) ", *(sp), *(sp+1)/CK_ONE_PI );
+ else if( type->xid == te_vec2 ) // 1.5.1.7
+ // print it
+ CK_FPRINTF_STDERR( "@(%.4f,%.4f) ", *(sp), *(sp+1) );
- the_sp += sz_COMPLEX; // ISSUE: 64-bit (fixed 1.3.1.0)
+ the_sp += sz_VEC2; // ISSUE: 64-bit (fixed 1.3.1.0)
}
else if( type->size == sz_VEC3 ) // 1.3.5.3
{
diff --git a/src/core/chuck_instr.h b/src/core/chuck_instr.h
index 09b656736..5e4790f07 100644
--- a/src/core/chuck_instr.h
+++ b/src/core/chuck_instr.h
@@ -609,6 +609,71 @@ struct Chuck_Instr_Divide_polar_Reverse : public Chuck_Instr_Binary_Op
+//-----------------------------------------------------------------------------
+// name: struct Chuck_Instr_Add_vec2
+// desc: add two vec2 (ge) added 1.5.1.7 with the rise of the planet of ChuGL
+//-----------------------------------------------------------------------------
+struct Chuck_Instr_Add_vec2 : public Chuck_Instr_Binary_Op
+{
+public:
+ virtual void execute( Chuck_VM * vm, Chuck_VM_Shred * shred );
+};
+
+
+
+
+//-----------------------------------------------------------------------------
+// name: struct Chuck_Instr_Minus_vec2
+// desc: subtract two vec2 (ge) added 1.5.1.7 with the rise of the planet of ChuGL
+//-----------------------------------------------------------------------------
+struct Chuck_Instr_Minus_vec2 : public Chuck_Instr_Binary_Op
+{
+public:
+ virtual void execute( Chuck_VM * vm, Chuck_VM_Shred * shred );
+};
+
+
+
+
+//-----------------------------------------------------------------------------
+// name: struct Chuck_Instr_float_Times_vec2
+// desc: float * vec2 (ge) added 1.5.1.7 with ChuGL
+//-----------------------------------------------------------------------------
+struct Chuck_Instr_float_Times_vec2 : public Chuck_Instr_Binary_Op
+{
+public:
+ virtual void execute( Chuck_VM * vm, Chuck_VM_Shred * shred );
+};
+
+
+
+
+//-----------------------------------------------------------------------------
+// name: struct Chuck_Instr_vec2_Times_float
+// desc: vec2*float (ge) added 1.5.1.7 with ChuGL
+//-----------------------------------------------------------------------------
+struct Chuck_Instr_vec2_Times_float : public Chuck_Instr_Binary_Op
+{
+public:
+ virtual void execute( Chuck_VM * vm, Chuck_VM_Shred * shred );
+};
+
+
+
+
+//-----------------------------------------------------------------------------
+// name: struct Chuck_Instr_vec2_Divide_float
+// desc: divide two vec2 (ge) added 1.5.1.7 with ChuGL
+//-----------------------------------------------------------------------------
+struct Chuck_Instr_vec2_Divide_float : public Chuck_Instr_Binary_Op
+{
+public:
+ virtual void execute( Chuck_VM * vm, Chuck_VM_Shred * shred );
+};
+
+
+
+
//-----------------------------------------------------------------------------
// name: struct Chuck_Instr_Add_vec3
// desc: add two vec3, 1.3.5.3
@@ -999,6 +1064,32 @@ struct Chuck_Instr_Divide_polar_Assign : public Chuck_Instr_Binary_Op
+//-----------------------------------------------------------------------------
+// name: struct Chuck_Instr_Add_vec2_Assign
+// desc: add assign two vec2
+//-----------------------------------------------------------------------------
+struct Chuck_Instr_Add_vec2_Assign : public Chuck_Instr_Binary_Op
+{
+public:
+ virtual void execute( Chuck_VM * vm, Chuck_VM_Shred * shred );
+};
+
+
+
+
+//-----------------------------------------------------------------------------
+// name: struct Chuck_Instr_Minus_vec2_Assign
+// desc: minus assign two vec2
+//-----------------------------------------------------------------------------
+struct Chuck_Instr_Minus_vec2_Assign : public Chuck_Instr_Binary_Op
+{
+public:
+ virtual void execute( Chuck_VM * vm, Chuck_VM_Shred * shred );
+};
+
+
+
+
//-----------------------------------------------------------------------------
// name: struct Chuck_Instr_Add_vec3_Assign
// desc: add assign two vec3
@@ -1077,6 +1168,19 @@ struct Chuck_Instr_Minus_vec4_Assign : public Chuck_Instr_Binary_Op
+//-----------------------------------------------------------------------------
+// name: struct Chuck_Instr_float_Times_vec2_Assign
+// desc: float *=> vec2
+//-----------------------------------------------------------------------------
+struct Chuck_Instr_float_Times_vec2_Assign : public Chuck_Instr_Binary_Op
+{
+public:
+ virtual void execute( Chuck_VM * vm, Chuck_VM_Shred * shred );
+};
+
+
+
+
//-----------------------------------------------------------------------------
// name: struct Chuck_Instr_float_Times_vec3_Assign
// desc: ...
@@ -1103,6 +1207,18 @@ struct Chuck_Instr_float_Times_vec4_Assign : public Chuck_Instr_Binary_Op
+//-----------------------------------------------------------------------------
+// name: struct Chuck_Instr_vec2_Divide_float_Assign
+// desc: float /=> vec2
+//-----------------------------------------------------------------------------
+struct Chuck_Instr_vec2_Divide_float_Assign : public Chuck_Instr_Binary_Op
+{
+public:
+ virtual void execute( Chuck_VM * vm, Chuck_VM_Shred * shred );
+};
+
+
+
//-----------------------------------------------------------------------------
// name: struct Chuck_Instr_vec3_Divide_float_Assign
// desc: ...
@@ -1651,6 +1767,32 @@ struct Chuck_Instr_Neq_complex : public Chuck_Instr_Binary_Op
+//-----------------------------------------------------------------------------
+// name: struct Chuck_Instr_Eq_vec2
+// desc: vec2 == vec2 | 1.5.1.7 (ge) added
+//-----------------------------------------------------------------------------
+struct Chuck_Instr_Eq_vec2 : public Chuck_Instr_Binary_Op
+{
+public:
+ virtual void execute( Chuck_VM * vm, Chuck_VM_Shred * shred );
+};
+
+
+
+
+//-----------------------------------------------------------------------------
+// name: struct Chuck_Instr_Neq_vec2
+// desc: vec2 != vec2 | 1.5.1.7 (ge) added
+//-----------------------------------------------------------------------------
+struct Chuck_Instr_Neq_vec2 : public Chuck_Instr_Binary_Op
+{
+public:
+ virtual void execute( Chuck_VM * vm, Chuck_VM_Shred * shred );
+};
+
+
+
+
//-----------------------------------------------------------------------------
// name: struct Chuck_Instr_Eq_vec3
// desc: ...
@@ -1926,10 +2068,23 @@ struct Chuck_Instr_Reg_Pop_Float : public Chuck_Instr
//-----------------------------------------------------------------------------
-// name: struct Chuck_Instr_Reg_Pop_Complex
-// desc: pop a complex/polar value from reg stack (change 1.3.1.0)
+// name: struct Chuck_Instr_Reg_Pop_Vec2ComplexPolar
+// desc: pop a complex/polar/vec2 value from reg stack (change 1.3.1.0)
+//-----------------------------------------------------------------------------
+struct Chuck_Instr_Reg_Pop_Vec2ComplexPolar : public Chuck_Instr
+{
+public:
+ virtual void execute( Chuck_VM * vm, Chuck_VM_Shred * shred );
+};
+
+
+
+
+//-----------------------------------------------------------------------------
+// name: struct Chuck_Instr_Reg_Pop_Vec2
+// desc: pop a vec2 value from reg stack | 1.5.1.7
//-----------------------------------------------------------------------------
-struct Chuck_Instr_Reg_Pop_Complex : public Chuck_Instr
+struct Chuck_Instr_Reg_Pop_Vec2 : public Chuck_Instr
{
public:
virtual void execute( Chuck_VM * vm, Chuck_VM_Shred * shred );
@@ -3930,6 +4085,58 @@ struct Chuck_Instr_Cast_polar2complex : public Chuck_Instr
+//-----------------------------------------------------------------------------
+// name: struct Chuck_Instr_Cast_vec2tovec3
+// desc: cast frmo vec2 to vec3
+//-----------------------------------------------------------------------------
+struct Chuck_Instr_Cast_vec2tovec3 : public Chuck_Instr
+{
+public:
+ virtual void execute( Chuck_VM * vm, Chuck_VM_Shred * shred );
+};
+
+
+
+
+//-----------------------------------------------------------------------------
+// name: struct Chuck_Instr_Cast_vec2tovec4
+// desc: cast frmo vec2 to vec4
+//-----------------------------------------------------------------------------
+struct Chuck_Instr_Cast_vec2tovec4 : public Chuck_Instr
+{
+public:
+ virtual void execute( Chuck_VM * vm, Chuck_VM_Shred * shred );
+};
+
+
+
+
+//-----------------------------------------------------------------------------
+// name: struct Chuck_Instr_Cast_vec3tovec2
+// desc: cast frmo vec3 to vec2
+//-----------------------------------------------------------------------------
+struct Chuck_Instr_Cast_vec3tovec2 : public Chuck_Instr
+{
+public:
+ virtual void execute( Chuck_VM * vm, Chuck_VM_Shred * shred );
+};
+
+
+
+
+//-----------------------------------------------------------------------------
+// name: struct Chuck_Instr_Cast_vec4tovec2
+// desc: cast frmo vec4 to vec2
+//-----------------------------------------------------------------------------
+struct Chuck_Instr_Cast_vec4tovec2 : public Chuck_Instr
+{
+public:
+ virtual void execute( Chuck_VM * vm, Chuck_VM_Shred * shred );
+};
+
+
+
+
//-----------------------------------------------------------------------------
// name: struct Chuck_Instr_Cast_vec3tovec4
// desc: cast frmo vec3 to vec4
@@ -4045,7 +4252,7 @@ struct Chuck_Instr_ForEach_Inc_And_Branch : public Chuck_Instr_Branch_Op
{
public:
// constructor
- Chuck_Instr_ForEach_Inc_And_Branch( t_CKUINT kind, t_CKUINT size )
+ Chuck_Instr_ForEach_Inc_And_Branch( te_KindOf kind, t_CKUINT size )
{ m_dataKind = kind; m_dataSize = size; this->set( 0 ); }
virtual void execute( Chuck_VM * vm, Chuck_VM_Shred * shred );
@@ -4053,10 +4260,10 @@ struct Chuck_Instr_ForEach_Inc_And_Branch : public Chuck_Instr_Branch_Op
// type of VAR (will determine which array to operate on):
// kindof_INT
// kindof_FLOAT
- // kindof_COMPLEX
+ // kindof_VEC2
// kindof_VEC3
// kindof_VEC4
- t_CKUINT m_dataKind;
+ te_KindOf m_dataKind;
// size of VAR
t_CKUINT m_dataSize;
};
@@ -4155,9 +4362,22 @@ struct Chuck_Instr_IO_out_polar : public Chuck_Instr_Binary_Op
+//-----------------------------------------------------------------------------
+// name: struct Chuck_Instr_IO_out_vec2
+// desc: insert vec2 value into output stream
+//-----------------------------------------------------------------------------
+struct Chuck_Instr_IO_out_vec2 : public Chuck_Instr_Binary_Op
+{
+public:
+ virtual void execute( Chuck_VM * vm, Chuck_VM_Shred * shred );
+};
+
+
+
+
//-----------------------------------------------------------------------------
// name: struct Chuck_Instr_IO_out_vec3
-// desc: insert complex value into output stream
+// desc: insert vec3 value into output stream
//-----------------------------------------------------------------------------
struct Chuck_Instr_IO_out_vec3 : public Chuck_Instr_Binary_Op
{
@@ -4170,7 +4390,7 @@ struct Chuck_Instr_IO_out_vec3 : public Chuck_Instr_Binary_Op
//-----------------------------------------------------------------------------
// name: struct Chuck_Instr_IO_out_vec4
-// desc: insert complex value into output stream
+// desc: insert vec4 value into output stream
//-----------------------------------------------------------------------------
struct Chuck_Instr_IO_out_vec4 : public Chuck_Instr_Binary_Op
{
@@ -4183,7 +4403,7 @@ struct Chuck_Instr_IO_out_vec4 : public Chuck_Instr_Binary_Op
//-----------------------------------------------------------------------------
// name: struct Chuck_Instr_IO_out_string
-// desc: ...
+// desc: insert string value into output stream
//-----------------------------------------------------------------------------
struct Chuck_Instr_IO_out_string : public Chuck_Instr_Binary_Op
{
@@ -4251,6 +4471,7 @@ void ck_handle_overflow( Chuck_VM_Shred * shred, Chuck_VM * vm, const std::strin
#define push_( sp, val ) *(sp) = (val); (sp)++
#define push_float( sp, val ) *((t_CKFLOAT *&)sp) = (val); ((t_CKFLOAT *&)sp)++
#define push_complex( sp, val ) *((t_CKCOMPLEX *&)sp) = (val); ((t_CKCOMPLEX *&)sp)++
+#define push_vec2( sp, val ) *((t_CKVEC2 *&)sp) = (val); ((t_CKVEC2 *&)sp)++
#define push_vec3( sp, val ) *((t_CKVEC3 *&)sp) = (val); ((t_CKVEC3 *&)sp)++
#define push_vec4( sp, val ) *((t_CKVEC4 *&)sp) = (val); ((t_CKVEC4 *&)sp)++
#define pop_( sp, n ) sp -= (n)
diff --git a/src/core/chuck_io.cpp b/src/core/chuck_io.cpp
index a45139293..a6894409a 100644
--- a/src/core/chuck_io.cpp
+++ b/src/core/chuck_io.cpp
@@ -4332,6 +4332,63 @@ void Chuck_IO_File::write( const t_CKPOLAR & val, t_CKINT flags )
}
}
+void Chuck_IO_File::write( const t_CKVEC2 & val )
+{
+ this->write( val, Chuck_IO::FLOAT32 );
+}
+
+void Chuck_IO_File::write( const t_CKVEC2 & val, t_CKINT flags )
+{
+ // sanity
+ if( !(m_io.is_open()) ) {
+ EM_error3( "[chuck](via FileIO): cannot write: no file open" );
+ return;
+ }
+ if( m_io.fail() ) {
+ EM_error3( "[chuck](via FileIO): cannot write: I/O stream failed" );
+ return;
+ }
+ if( m_dir ) {
+ EM_error3( "[chuck](via FileIO): cannot write to a directory" );
+ return;
+ }
+
+ // check ASCII or BINARY
+ if( m_flags & TYPE_ASCII )
+ {
+ // insert into stream
+ m_io << "@(" << val.x << "," << val.y << ")";
+ }
+ else if( m_flags & TYPE_BINARY )
+ {
+ // 1.5.0.1 (ge) add distinction between different float sizes
+ if( flags & Chuck_IO::FLOAT32 )
+ {
+ // 32-bit
+ float v = (float)val.x; m_io.write( (char *)&v, 4 );
+ v = (float)val.y; m_io.write( (char *)&v, 4 );
+ }
+ else if( flags & Chuck_IO::FLOAT64 )
+ {
+ // 64-bit
+ double v = (double)val.x; m_io.write( (char *)&v, 8 );
+ v = (double)val.y; m_io.write( (char *)&v, 8 );
+ }
+ else
+ {
+ EM_error3( "[chuck](via FileIO): writeFloat error: invalid/unsupport datatype size flag" );
+ }
+ }
+ else
+ {
+ EM_error3( "[chuck](via FileIO): write error: invalid ASCII/binary flag" );
+ }
+
+ if( m_io.fail() ) { // check both before and after write if stream is ok
+ EM_error3( "[chuck](via FileIO): cannot write: I/O stream failed" );
+ }
+}
+
void Chuck_IO_File::write( const t_CKVEC3 & val )
{
this->write( val, Chuck_IO::FLOAT32 );
@@ -4646,6 +4703,18 @@ void Chuck_IO_Chout::write( const t_CKPOLAR & val, t_CKINT flags )
this->write( val );
}
+void Chuck_IO_Chout::write( const t_CKVEC2 & v )
+{
+ // print vec2 value
+ m_buffer << "@(" << v.x << "," << v.y << ")";
+}
+
+void Chuck_IO_Chout::write( const t_CKVEC2 & v, t_CKINT flags )
+{
+ // ignore flags for chout
+ this->write( v );
+}
+
void Chuck_IO_Chout::write( const t_CKVEC3 & v )
{
// print vec3 value
@@ -4826,6 +4895,19 @@ void Chuck_IO_Cherr::write( const t_CKPOLAR & val, t_CKINT flags )
this->write( val );
}
+void Chuck_IO_Cherr::write( const t_CKVEC2 & v )
+{
+ // print vec2 value
+ m_buffer << "@(" << v.x << "," << v.y << ")";
+ flush(); // always flush for cerr | 1.5.0.0 (ge) added
+}
+
+void Chuck_IO_Cherr::write( const t_CKVEC2 & v, t_CKINT flags )
+{
+ // ignore flags for cherr
+ this->write( v );
+}
+
void Chuck_IO_Cherr::write( const t_CKVEC3 & v )
{
// print vec3 value
@@ -5617,6 +5699,18 @@ void Chuck_IO_Serial::write( const t_CKPOLAR & val, t_CKINT flags )
this->write( val.phase, flags );
}
+void Chuck_IO_Serial::write( const t_CKVEC2 & val )
+{
+ this->write( val, Chuck_IO::FLOAT32 );
+}
+
+void Chuck_IO_Serial::write( const t_CKVEC2 & val, t_CKINT flags )
+{
+ // NOTE this will NOT output chuck-format vec2 @(x,y) in ASCII mode
+ this->write( val.x, flags );
+ this->write( val.y, flags );
+}
+
void Chuck_IO_Serial::write( const t_CKVEC3 & val )
{
this->write( val, Chuck_IO::FLOAT32 );
diff --git a/src/core/chuck_io.h b/src/core/chuck_io.h
index c51dee282..43fd442a9 100644
--- a/src/core/chuck_io.h
+++ b/src/core/chuck_io.h
@@ -102,6 +102,8 @@ struct Chuck_IO : public Chuck_Event
virtual void write( const t_CKCOMPLEX & val, t_CKINT flags ) = 0;
virtual void write( const t_CKPOLAR & val ) = 0;
virtual void write( const t_CKPOLAR & val, t_CKINT flags ) = 0;
+ virtual void write( const t_CKVEC2 & val ) = 0;
+ virtual void write( const t_CKVEC2 & val, t_CKINT flags ) = 0;
virtual void write( const t_CKVEC3 & val ) = 0;
virtual void write( const t_CKVEC3 & val, t_CKINT flags ) = 0;
virtual void write( const t_CKVEC4 & val ) = 0;
@@ -219,6 +221,8 @@ struct Chuck_IO_File : public Chuck_IO
virtual void write( const t_CKCOMPLEX & val, t_CKINT flags );
virtual void write( const t_CKPOLAR & val );
virtual void write( const t_CKPOLAR & val, t_CKINT flags );
+ virtual void write( const t_CKVEC2 & val );
+ virtual void write( const t_CKVEC2 & val, t_CKINT flags );
virtual void write( const t_CKVEC3 & val );
virtual void write( const t_CKVEC3 & val, t_CKINT flags );
virtual void write( const t_CKVEC4 & val );
@@ -296,6 +300,8 @@ struct Chuck_IO_Chout : public Chuck_IO
virtual void write( const t_CKCOMPLEX & val, t_CKINT flags );
virtual void write( const t_CKPOLAR & val );
virtual void write( const t_CKPOLAR & val, t_CKINT flags );
+ virtual void write( const t_CKVEC2 & val );
+ virtual void write( const t_CKVEC2 & val, t_CKINT flags );
virtual void write( const t_CKVEC3 & val );
virtual void write( const t_CKVEC3 & val, t_CKINT flags );
virtual void write( const t_CKVEC4 & val );
@@ -351,6 +357,8 @@ struct Chuck_IO_Cherr : public Chuck_IO
virtual void write( const t_CKCOMPLEX & val, t_CKINT flags );
virtual void write( const t_CKPOLAR & val );
virtual void write( const t_CKPOLAR & val, t_CKINT flags );
+ virtual void write( const t_CKVEC2 & val );
+ virtual void write( const t_CKVEC2 & val, t_CKINT flags );
virtual void write( const t_CKVEC3 & val );
virtual void write( const t_CKVEC3 & val, t_CKINT flags );
virtual void write( const t_CKVEC4 & val );
@@ -639,6 +647,8 @@ struct Chuck_IO_Serial : public Chuck_IO
virtual void write( const t_CKCOMPLEX & val, t_CKINT flags );
virtual void write( const t_CKPOLAR & val );
virtual void write( const t_CKPOLAR & val, t_CKINT flags );
+ virtual void write( const t_CKVEC2 & val );
+ virtual void write( const t_CKVEC2 & val, t_CKINT flags );
virtual void write( const t_CKVEC3 & val );
virtual void write( const t_CKVEC3 & val, t_CKINT flags );
virtual void write( const t_CKVEC4 & val );
diff --git a/src/core/chuck_lang.cpp b/src/core/chuck_lang.cpp
index 0e33bdba5..75d9529a5 100644
--- a/src/core/chuck_lang.cpp
+++ b/src/core/chuck_lang.cpp
@@ -626,6 +626,59 @@ t_CKBOOL init_class_shred( Chuck_Env * env, Chuck_Type * type )
+//-----------------------------------------------------------------------------
+// name: init_class_vec2()
+// desc: initialize primitive type vec2
+//-----------------------------------------------------------------------------
+t_CKBOOL init_class_vec2( Chuck_Env * env, Chuck_Type * type )
+{
+ // init as base class
+ Chuck_DL_Func * func = NULL;
+
+ // log
+ EM_log( CK_LOG_SEVERE, "class 'vec2' (primitive)" );
+
+ // document
+ const char * doc = "a primitive type for a 2-dimensional vector; potentially useful for 2D and UV coordinates.";
+
+ // init as base class
+ if( !type_engine_import_class_begin( env, type, env->global(), NULL, NULL, doc ) )
+ return FALSE;
+
+ // add set(float,float,float)
+ func = make_new_mfun( "void", "set", vec2_set );
+ func->add_arg( "float", "x" );
+ func->add_arg( "float", "y" );
+ if( !type_engine_import_mfun( env, func ) ) goto error;
+
+ // add setAll(float)
+ func = make_new_mfun( "void", "setAll", vec2_setAll );
+ func->add_arg( "float", "value" );
+ if( !type_engine_import_mfun( env, func ) ) goto error;
+
+ // add magnitude()
+ func = make_new_mfun( "float", "magnitude", vec2_magnitude );
+ if( !type_engine_import_mfun( env, func ) ) goto error;
+
+ // add normalize()
+ func = make_new_mfun( "void", "normalize", vec2_normalize );
+ if( !type_engine_import_mfun( env, func ) ) goto error;
+
+ // end the class import
+ type_engine_import_class_end( env );
+
+ return TRUE;
+
+error:
+ // end the class import
+ type_engine_import_class_end( env );
+
+ return FALSE;
+}
+
+
+
+
//-----------------------------------------------------------------------------
// name: init_class_vec3()
// desc: initialize primitive type vec3
@@ -1878,10 +1931,10 @@ CK_DLL_MFUN( uana_cval )
if( i < 0 || cvals.size() <= i ) RETURN->v_complex.re = RETURN->v_complex.im = 0;
else
{
- // get
- t_CKCOMPLEX val;
+ // get as vec2
+ t_CKVEC2 val;
cvals.get( i, &val );
- RETURN->v_complex = val;
+ RETURN->v_vec2 = val;
}
}
@@ -2026,9 +2079,9 @@ CK_DLL_MFUN( uanablob_cval )
else
{
// get
- t_CKCOMPLEX val;
+ t_CKVEC2 val;
cvals->get( i, &val );
- RETURN->v_complex = val;
+ RETURN->v_vec2 = val;
}
}
@@ -2085,6 +2138,54 @@ CK_DLL_MFUN( event_waiting_on )
}
+
+
+//-----------------------------------------------------------------------------
+// vec2 API
+//-----------------------------------------------------------------------------
+CK_DLL_MFUN( vec2_set )
+{
+ // HACK: this is a particularly horrid cast from (Chuck_Object *)
+ // t_CKVEC3 is neither a super- or sub-class of Chuck_Object...
+ t_CKVEC2 * vec2 = (t_CKVEC2 *)SELF;
+ // get index
+ vec2->x = GET_NEXT_FLOAT(ARGS);
+ vec2->y = GET_NEXT_FLOAT(ARGS);
+}
+
+CK_DLL_MFUN( vec2_setAll )
+{
+ // get data pointer
+ t_CKVEC2 * vec2 = (t_CKVEC2 *)SELF;
+ // get index
+ vec2->x = vec2->y = GET_NEXT_FLOAT(ARGS);
+}
+
+CK_DLL_MFUN( vec2_magnitude )
+{
+ // get data pointer
+ t_CKVEC2 * vec2 = (t_CKVEC2 *)SELF;
+ // compute magnitude
+ t_CKFLOAT mag = ::sqrt( vec2->x*vec2->x + vec2->y*vec2->y );
+ // return
+ RETURN->v_float = mag;
+}
+
+CK_DLL_MFUN( vec2_normalize )
+{
+ // get data pointer
+ t_CKVEC2 * vec2 = (t_CKVEC2 *)SELF;
+ // compute magnitude
+ t_CKFLOAT mag = ::sqrt( vec2->x*vec2->x + vec2->y*vec2->y );
+ // check for zero
+ if( mag > 0 )
+ {
+ vec2->x /= mag;
+ vec2->y /= mag;
+ }
+}
+
+
//-----------------------------------------------------------------------------
// vec3 API
//-----------------------------------------------------------------------------
@@ -2224,12 +2325,12 @@ CK_DLL_MFUN( vec4_set )
{
// HACK: this is a particularly horrid cast from (Chuck_Object *)
// t_CKVEC3 is neither a super- or sub-class of Chuck_Object...
- t_CKVEC4 * vec3 = (t_CKVEC4 *)SELF;
+ t_CKVEC4 * vec4 = (t_CKVEC4 *)SELF;
// get index
- vec3->x = GET_NEXT_FLOAT(ARGS);
- vec3->y = GET_NEXT_FLOAT(ARGS);
- vec3->z = GET_NEXT_FLOAT(ARGS);
- vec3->w = GET_NEXT_FLOAT(ARGS);
+ vec4->x = GET_NEXT_FLOAT(ARGS);
+ vec4->y = GET_NEXT_FLOAT(ARGS);
+ vec4->z = GET_NEXT_FLOAT(ARGS);
+ vec4->w = GET_NEXT_FLOAT(ARGS);
}
CK_DLL_MFUN( vec4_setAll )
@@ -3007,7 +3108,7 @@ CK_DLL_MFUN( array_push_back )
else if( array->data_type_kind() == CHUCK_ARRAYFLOAT_DATAKIND )
RETURN->v_int = ((Chuck_ArrayFloat *)array)->push_back( GET_NEXT_FLOAT( ARGS ) );
else if( array->data_type_kind() == CHUCK_ARRAY16_DATAKIND )
- RETURN->v_int = ((Chuck_Array16 *)array)->push_back( GET_NEXT_COMPLEX( ARGS ) );
+ RETURN->v_int = ((Chuck_Array16 *)array)->push_back( GET_NEXT_VEC2( ARGS ) );
else if( array->data_type_kind() == CHUCK_ARRAY24_DATAKIND )
RETURN->v_int = ((Chuck_Array24 *)array)->push_back( GET_NEXT_VEC3( ARGS ) );
else if( array->data_type_kind() == CHUCK_ARRAY32_DATAKIND )
@@ -3029,7 +3130,7 @@ CK_DLL_MFUN( array_insert )
else if( array->data_type_kind() == CHUCK_ARRAYFLOAT_DATAKIND )
RETURN->v_int = ((Chuck_ArrayFloat *)array)->insert( position, GET_NEXT_FLOAT( ARGS ) );
else if( array->data_type_kind() == CHUCK_ARRAY16_DATAKIND )
- RETURN->v_int = ((Chuck_Array16 *)array)->insert( position, GET_NEXT_COMPLEX( ARGS ) );
+ RETURN->v_int = ((Chuck_Array16 *)array)->insert( position, GET_NEXT_VEC2( ARGS ) );
else if( array->data_type_kind() == CHUCK_ARRAY24_DATAKIND )
RETURN->v_int = ((Chuck_Array24 *)array)->insert( position, GET_NEXT_VEC3( ARGS ) );
else if( array->data_type_kind() == CHUCK_ARRAY32_DATAKIND )
@@ -3056,7 +3157,7 @@ CK_DLL_MFUN( array_push_front )
else if( array->data_type_kind() == CHUCK_ARRAYFLOAT_DATAKIND )
RETURN->v_int = ((Chuck_ArrayFloat *)array)->push_front( GET_NEXT_FLOAT( ARGS ) );
else if( array->data_type_kind() == CHUCK_ARRAY16_DATAKIND )
- RETURN->v_int = ((Chuck_Array16 *)array)->push_front( GET_NEXT_COMPLEX( ARGS ) );
+ RETURN->v_int = ((Chuck_Array16 *)array)->push_front( GET_NEXT_VEC2( ARGS ) );
else if( array->data_type_kind() == CHUCK_ARRAY24_DATAKIND )
RETURN->v_int = ((Chuck_Array24 *)array)->push_front( GET_NEXT_VEC3( ARGS ) );
else if( array->data_type_kind() == CHUCK_ARRAY32_DATAKIND )
diff --git a/src/core/chuck_lang.h b/src/core/chuck_lang.h
index 000552cfe..34dfb4a85 100644
--- a/src/core/chuck_lang.h
+++ b/src/core/chuck_lang.h
@@ -56,6 +56,7 @@ t_CKBOOL init_class_event( Chuck_Env * env, Chuck_Type * type );
t_CKBOOL init_class_shred( Chuck_Env * env, Chuck_Type * type );
t_CKBOOL init_class_string( Chuck_Env * env, Chuck_Type * type );
t_CKBOOL init_class_array( Chuck_Env * env, Chuck_Type * type );
+t_CKBOOL init_class_vec2( Chuck_Env * env, Chuck_Type * type ); // 1.5.1.7
t_CKBOOL init_class_vec3( Chuck_Env * env, Chuck_Type * type ); // 1.3.5.3
t_CKBOOL init_class_vec4( Chuck_Env * env, Chuck_Type * type ); // 1.3.5.3
t_CKBOOL init_class_type( Chuck_Env * env, Chuck_Type * type ); // 1.5.0.0
@@ -251,8 +252,13 @@ CK_DLL_MFUN( string_parent);
//-----------------------------------------------------------------------------
-// vector API (vec3, vec4, eventually vector) ge: 1.3.5.3
+// vector API (vec3, vec4, eventually vector) (ge) 1.3.5.3
+// add vec2 (ge) 1.5.1.7
//-----------------------------------------------------------------------------
+CK_DLL_MFUN( vec2_set );
+CK_DLL_MFUN( vec2_setAll );
+CK_DLL_MFUN( vec2_magnitude );
+CK_DLL_MFUN( vec2_normalize );
CK_DLL_MFUN( vec3_set );
CK_DLL_MFUN( vec3_setAll );
CK_DLL_MFUN( vec3_magnitude );
diff --git a/src/core/chuck_oo.cpp b/src/core/chuck_oo.cpp
index 21ef3cf81..b41242034 100644
--- a/src/core/chuck_oo.cpp
+++ b/src/core/chuck_oo.cpp
@@ -1510,7 +1510,7 @@ t_CKUINT Chuck_Array16::addr( const string & key )
// name: get()
// desc: ...
//-----------------------------------------------------------------------------
-t_CKINT Chuck_Array16::get( t_CKINT i, t_CKCOMPLEX * val )
+t_CKINT Chuck_Array16::get( t_CKINT i, t_CKVEC2 * val )
{
// bound check
if( i < 0 || i >= m_vector.capacity() )
@@ -1522,6 +1522,9 @@ t_CKINT Chuck_Array16::get( t_CKINT i, t_CKCOMPLEX * val )
// return good
return 1;
}
+// redirect as vec2
+t_CKINT Chuck_Array16::get( t_CKINT i, t_CKCOMPLEX * val )
+{ return this->get( i, (t_CKVEC2 *)val ); }
@@ -1530,14 +1533,14 @@ t_CKINT Chuck_Array16::get( t_CKINT i, t_CKCOMPLEX * val )
// name: get()
// desc: ...
//-----------------------------------------------------------------------------
-t_CKINT Chuck_Array16::get( const string & key, t_CKCOMPLEX * val )
+t_CKINT Chuck_Array16::get( const string & key, t_CKVEC2 * val )
{
// set to zero
- val->re = 0.0;
- val->im = 0.0;
+ val->x = 0;
+ val->y = 0;
// iterator
- map::iterator iter = m_map.find( key );
+ map::iterator iter = m_map.find( key );
// check
if( iter != m_map.end() )
@@ -1549,6 +1552,9 @@ t_CKINT Chuck_Array16::get( const string & key, t_CKCOMPLEX * val )
// return good
return 1;
}
+// redirect as vec2
+t_CKINT Chuck_Array16::get( const string & key, t_CKCOMPLEX * val )
+{ return this->get( key, (t_CKVEC2 *)val ); }
@@ -1557,7 +1563,7 @@ t_CKINT Chuck_Array16::get( const string & key, t_CKCOMPLEX * val )
// name: set()
// desc: ...
//-----------------------------------------------------------------------------
-t_CKINT Chuck_Array16::set( t_CKINT i, const t_CKCOMPLEX & val )
+t_CKINT Chuck_Array16::set( t_CKINT i, const t_CKVEC2 & val )
{
// bound check
if( i < 0 || i >= m_vector.capacity() )
@@ -1569,6 +1575,9 @@ t_CKINT Chuck_Array16::set( t_CKINT i, const t_CKCOMPLEX & val )
// return good
return 1;
}
+// redirect as vec2
+t_CKINT Chuck_Array16::set( t_CKINT i, const t_CKCOMPLEX & val )
+{ return this->set( i, (t_CKVEC2 &)val ); }
@@ -1577,10 +1586,10 @@ t_CKINT Chuck_Array16::set( t_CKINT i, const t_CKCOMPLEX & val )
// name: set()
// desc: ...
//-----------------------------------------------------------------------------
-t_CKINT Chuck_Array16::set( const string & key, const t_CKCOMPLEX & val )
+t_CKINT Chuck_Array16::set( const string & key, const t_CKVEC2 & val )
{
// 1.3.1.1: removed this
- // map::iterator iter = m_map.find( key );
+ // map::iterator iter = m_map.find( key );
// 1.3.5.3: removed this
// if( val.re == 0 && val.im == 0 ) m_map.erase( key ); else
@@ -1589,6 +1598,9 @@ t_CKINT Chuck_Array16::set( const string & key, const t_CKCOMPLEX & val )
// return good
return 1;
}
+// redirect as vec2
+t_CKINT Chuck_Array16::set( const string & key, const t_CKCOMPLEX & val )
+{ return this->set( key, (t_CKVEC2 &)val ); }
@@ -1597,7 +1609,7 @@ t_CKINT Chuck_Array16::set( const string & key, const t_CKCOMPLEX & val )
// name: insert() | 1.5.0.8 (ge) added
// desc: insert before position | O(n) running time
//-----------------------------------------------------------------------------
-t_CKINT Chuck_Array16::insert( t_CKINT i, const t_CKCOMPLEX & val )
+t_CKINT Chuck_Array16::insert( t_CKINT i, const t_CKVEC2 & val )
{
// bound check
if( i < 0 || i >= m_vector.capacity() )
@@ -1640,7 +1652,7 @@ t_CKINT Chuck_Array16::map_erase( const string & key )
// name: push_back()
// desc: ...
//-----------------------------------------------------------------------------
-t_CKINT Chuck_Array16::push_back( const t_CKCOMPLEX & val )
+t_CKINT Chuck_Array16::push_back( const t_CKVEC2 & val )
{
// add to vector
m_vector.push_back( val );
@@ -1662,8 +1674,8 @@ t_CKINT Chuck_Array16::pop_back( )
return 0;
// zero
- m_vector[m_vector.size()-1].re = 0.0;
- m_vector[m_vector.size()-1].im = 0.0;
+ m_vector[m_vector.size()-1].x = 0;
+ m_vector[m_vector.size()-1].y = 0;
// add to vector
m_vector.pop_back();
@@ -1677,7 +1689,7 @@ t_CKINT Chuck_Array16::pop_back( )
// name: push_front() | 1.5.0.8 (ge) added
// desc: prepend element by value | O(n) running time
//-----------------------------------------------------------------------------
-t_CKINT Chuck_Array16::push_front( const t_CKCOMPLEX & val )
+t_CKINT Chuck_Array16::push_front( const t_CKVEC2 & val )
{
// add to vector
m_vector.insert( m_vector.begin(), val );
@@ -1760,7 +1772,7 @@ void Chuck_Array16::get_keys( std::vector & keys )
// clear the return array
keys.clear();
// iterator
- for( std::map::iterator iter = m_map.begin(); iter !=m_map.end(); iter++ )
+ for( std::map::iterator iter = m_map.begin(); iter !=m_map.end(); iter++ )
{
// add to list
keys.push_back((*iter).first);
@@ -1798,7 +1810,7 @@ void Chuck_Array16::shuffle()
// name: ck_compare_polar()
// desc: compare function for sorting chuck polar values
//-----------------------------------------------------------------------------
-static bool ck_compare_polar( const t_CKCOMPLEX & lhs, const t_CKCOMPLEX & rhs )
+static bool ck_compare_polar( const t_CKVEC2 & lhs, const t_CKVEC2 & rhs )
{
// cast to polar
const t_CKPOLAR * pL = (const t_CKPOLAR *)&lhs;
@@ -1819,6 +1831,29 @@ static bool ck_compare_polar( const t_CKCOMPLEX & lhs, const t_CKCOMPLEX & rhs )
+//-----------------------------------------------------------------------------
+// name: ck_compare_vec2()
+// desc: compare function for sorting chuck vec2 values
+//-----------------------------------------------------------------------------
+static bool ck_compare_vec2( const t_CKVEC2 & lhs, const t_CKVEC2 & rhs )
+{
+ // compare magnitude first
+ t_CKFLOAT x = ck_vec2_magnitude(lhs);
+ t_CKFLOAT y = ck_vec2_magnitude(rhs);
+ // if magnitude equal
+ if( x == y ) {
+ // compare phase
+ t_CKFLOAT xp = ck_vec2_phase(lhs);
+ t_CKFLOAT yp = ck_vec2_phase(rhs);
+ return xp < yp;
+ }
+ // return magnitude comparison
+ return x < y;
+}
+
+
+
+
//-----------------------------------------------------------------------------
// name: ck_compare_complex()
// desc: compare function for sorting chuck complex values
@@ -1856,7 +1891,7 @@ void Chuck_Array16::sort()
if( m_isPolarType )
std::sort( m_vector.begin(), m_vector.end(), ck_compare_polar );
else
- std::sort( m_vector.begin(), m_vector.end(), ck_compare_complex );
+ std::sort( m_vector.begin(), m_vector.end(), ck_compare_vec2 );
}
@@ -1866,7 +1901,7 @@ void Chuck_Array16::sort()
// name: back()
// desc: ...
//-----------------------------------------------------------------------------
-t_CKINT Chuck_Array16::back( t_CKCOMPLEX * val ) const
+t_CKINT Chuck_Array16::back( t_CKVEC2 * val ) const
{
// check
if( m_vector.size() == 0 )
@@ -1961,8 +1996,8 @@ void Chuck_Array16::zero( t_CKUINT start, t_CKUINT end )
for( t_CKUINT i = start; i < end; i++ )
{
// zero
- m_vector[i].re = 0.0;
- m_vector[i].im = 0.0;
+ m_vector[i].x = 0;
+ m_vector[i].y = 0;
}
}
diff --git a/src/core/chuck_oo.h b/src/core/chuck_oo.h
index c7d6953e9..4c976cf58 100644
--- a/src/core/chuck_oo.h
+++ b/src/core/chuck_oo.h
@@ -180,7 +180,7 @@ struct Chuck_Object : public Chuck_VM_Object
#define CHUCK_ARRAY32_DATASIZE sz_VEC4 // 1.3.5.3
#define CHUCK_ARRAYINT_DATAKIND kindof_INT
#define CHUCK_ARRAYFLOAT_DATAKIND kindof_FLOAT
-#define CHUCK_ARRAY16_DATAKIND kindof_COMPLEX
+#define CHUCK_ARRAY16_DATAKIND kindof_VEC2 // 1.5.1.7
#define CHUCK_ARRAY24_DATAKIND kindof_VEC3 // 1.3.5.3
#define CHUCK_ARRAY32_DATAKIND kindof_VEC4 // 1.3.5.3
//-----------------------------------------------------------------------------
@@ -443,7 +443,7 @@ struct Chuck_ArrayFloat : public Chuck_Array
//-----------------------------------------------------------------------------
// name: struct Chuck_Array16
-// desc: native ChucK arrays (for 16-byte)
+// desc: native ChucK arrays (for 16-byte) | vec2, complex, polar
//-----------------------------------------------------------------------------
struct Chuck_Array16 : public Chuck_Array
{
@@ -456,24 +456,28 @@ struct Chuck_Array16 : public Chuck_Array
t_CKUINT addr( t_CKINT i );
t_CKUINT addr( const std::string & key );
// get value
+ t_CKINT get( t_CKINT i, t_CKVEC2 * val );
t_CKINT get( t_CKINT i, t_CKCOMPLEX * val );
+ t_CKINT get( const std::string & key, t_CKVEC2 * val );
t_CKINT get( const std::string & key, t_CKCOMPLEX * val );
// set value
+ t_CKINT set( t_CKINT i, const t_CKVEC2 & val );
t_CKINT set( t_CKINT i, const t_CKCOMPLEX & val );
+ t_CKINT set( const std::string & key, const t_CKVEC2 & val );
t_CKINT set( const std::string & key, const t_CKCOMPLEX & val );
// append value
- t_CKINT push_back( const t_CKCOMPLEX & val );
+ t_CKINT push_back( const t_CKVEC2 & val );
// get value of last element
- t_CKINT back( t_CKCOMPLEX * val ) const;
+ t_CKINT back( t_CKVEC2 * val ) const;
// prepend value | 1.5.0.8 (ge) added
// NOTE linear time O(n) operation
- t_CKINT push_front( const t_CKCOMPLEX & val );
+ t_CKINT push_front( const t_CKVEC2 & val );
// get value of last element
- t_CKINT front( t_CKCOMPLEX * val ) const;
+ t_CKINT front( t_CKVEC2 * val ) const;
// insert before position | 1.5.0.8 (ge)
// NOTE linear time O(n) operation
- t_CKINT insert( t_CKINT pos, const t_CKCOMPLEX & val );
+ t_CKINT insert( t_CKINT pos, const t_CKVEC2 & val );
public: // array interface implementation
// get array size
@@ -520,8 +524,8 @@ struct Chuck_Array16 : public Chuck_Array
virtual t_CKINT map_erase( const std::string & key );
public:
- std::vector m_vector;
- std::map m_map;
+ std::vector m_vector;
+ std::map m_map;
// semantic hint; in certain situations (like sorting)
// need to distinguish between complex and polar | 1.5.1.0
t_CKBOOL m_isPolarType;
diff --git a/src/core/chuck_type.cpp b/src/core/chuck_type.cpp
index 0fe7366ab..8e865312f 100644
--- a/src/core/chuck_type.cpp
+++ b/src/core/chuck_type.cpp
@@ -153,6 +153,7 @@ Chuck_Env::Chuck_Env()
ckt_dur = NULL;
ckt_complex = NULL;
ckt_polar = NULL;
+ ckt_vec2 = NULL;
ckt_vec3 = NULL;
ckt_vec4 = NULL;
ckt_null = NULL;
@@ -209,6 +210,7 @@ t_CKBOOL Chuck_Env::init()
ckt_dur = new Chuck_Type( this, te_dur, "dur", NULL, sizeof(t_CKTIME) );
ckt_complex = new Chuck_Type( this, te_complex, "complex", NULL, sizeof(t_CKCOMPLEX) );
ckt_polar = new Chuck_Type( this, te_polar, "polar", NULL, sizeof(t_CKPOLAR) );
+ ckt_vec2 = new Chuck_Type( this, te_vec2, "vec2", NULL, sizeof(t_CKVEC2) ); // 1.5.1.7
ckt_vec3 = new Chuck_Type( this, te_vec3, "vec3", NULL, sizeof(t_CKVEC3) ); // 1.3.5.3
ckt_vec4 = new Chuck_Type( this, te_vec4, "vec4", NULL, sizeof(t_CKVEC4) ); // 1.3.5.3
ckt_null = new Chuck_Type( this, te_null, "@null", NULL, sizeof(void *) );
@@ -257,6 +259,7 @@ void Chuck_Env::cleanup()
CK_SAFE_UNLOCK_DELETE(ckt_dur);
CK_SAFE_UNLOCK_DELETE(ckt_complex);
CK_SAFE_UNLOCK_DELETE(ckt_polar);
+ CK_SAFE_UNLOCK_DELETE(ckt_vec2);
CK_SAFE_UNLOCK_DELETE(ckt_vec3);
CK_SAFE_UNLOCK_DELETE(ckt_vec4);
CK_SAFE_UNLOCK_DELETE(ckt_fileio);
@@ -503,6 +506,7 @@ t_CKBOOL type_engine_init( Chuck_Carrier * carrier )
env->global()->type.add( env->ckt_dur->base_name, env->ckt_dur ); env->ckt_dur->lock();
env->global()->type.add( env->ckt_complex->base_name, env->ckt_complex ); env->ckt_complex->lock();
env->global()->type.add( env->ckt_polar->base_name, env->ckt_polar ); env->ckt_polar->lock();
+ env->global()->type.add( env->ckt_vec2->base_name, env->ckt_vec2 ); env->ckt_vec2->lock();
env->global()->type.add( env->ckt_vec3->base_name, env->ckt_vec3 ); env->ckt_vec3->lock();
env->global()->type.add( env->ckt_vec4->base_name, env->ckt_vec4 ); env->ckt_vec4->lock();
env->global()->type.add( env->ckt_object->base_name, env->ckt_object ); env->ckt_object->lock();
@@ -560,6 +564,7 @@ t_CKBOOL type_engine_init( Chuck_Carrier * carrier )
init_class_fileio( env, env->ckt_fileio );
init_class_chout( env, env->ckt_chout ); // 1.3.0.0
init_class_cherr( env, env->ckt_cherr ); // 1.3.0.0
+ init_class_vec2( env, env->ckt_vec2 ); // 1.5.1.7
init_class_vec3( env, env->ckt_vec3 ); // 1.3.5.3
init_class_vec4( env, env->ckt_vec4 ); // 1.3.5.3
init_class_function(env, env->ckt_function ); // 1.5.0.0
@@ -1938,6 +1943,10 @@ t_CKTYPE type_engine_check_op( Chuck_Env * env, ae_Operator op, a_Exp lhs, a_Exp
case ae_op_minus:
CK_LR( te_vec3, te_vec4 ) left = lhs->cast_to = env->ckt_vec4;
else CK_LR( te_vec4, te_vec3 ) right = rhs->cast_to = env->ckt_vec4;
+ else CK_LR( te_vec2, te_vec4 ) left = lhs->cast_to = env->ckt_vec4;
+ else CK_LR( te_vec4, te_vec2 ) right = rhs->cast_to = env->ckt_vec4;
+ else CK_LR( te_vec2, te_vec3 ) left = lhs->cast_to = env->ckt_vec3;
+ else CK_LR( te_vec3, te_vec2 ) right = rhs->cast_to = env->ckt_vec3;
case ae_op_times:
case ae_op_divide:
case ae_op_lt:
@@ -1994,8 +2003,10 @@ t_CKTYPE type_engine_check_op( Chuck_Env * env, ae_Operator op, a_Exp lhs, a_Exp
CK_LR( te_int, te_dur ) left = lhs->cast_to = env->ckt_float;
else CK_LR( te_dur, te_int ) right = rhs->cast_to = env->ckt_float;
// vectors, 1.3.5.3
+ else CK_LR( te_int, te_vec2 ) left = lhs->cast_to = env->ckt_float; // 1.5.1.7
else CK_LR( te_int, te_vec3 ) left = lhs->cast_to = env->ckt_float; // 1.3.5.3
else CK_LR( te_int, te_vec4 ) left = lhs->cast_to = env->ckt_float; // 1.3.5.3
+ else CK_LR( te_vec2, te_int ) right = rhs->cast_to = env->ckt_float; // 1.5.1.7
else CK_LR( te_vec3, te_int ) right = rhs->cast_to = env->ckt_float; // 1.3.5.3
else CK_LR( te_vec4, te_int ) right = rhs->cast_to = env->ckt_float; // 1.3.5.3
}
@@ -2003,8 +2014,10 @@ t_CKTYPE type_engine_check_op( Chuck_Env * env, ae_Operator op, a_Exp lhs, a_Exp
{
CK_LR( te_dur, te_int ) right = rhs->cast_to = env->ckt_float;
// vectors, 1.3.5.3
+ else CK_LR( te_int, te_vec2 ) left = lhs->cast_to = env->ckt_float; // 1.5.1.7
else CK_LR( te_int, te_vec3 ) left = lhs->cast_to = env->ckt_float; // 1.3.5.3
else CK_LR( te_int, te_vec4 ) left = lhs->cast_to = env->ckt_float; // 1.3.5.3
+ else CK_LR( te_vec2, te_int ) right = rhs->cast_to = env->ckt_float; // 1.5.1.7
else CK_LR( te_vec3, te_int ) right = rhs->cast_to = env->ckt_float; // 1.3.5.3
else CK_LR( te_vec4, te_int ) right = rhs->cast_to = env->ckt_float; // 1.3.5.3
}
@@ -2012,11 +2025,13 @@ t_CKTYPE type_engine_check_op( Chuck_Env * env, ae_Operator op, a_Exp lhs, a_Exp
// op_chuck
if( op == ae_op_times_chuck )
{
+ CK_LR( te_int, te_vec2 ) left = lhs->cast_to = env->ckt_float; // 1.5.1.7
CK_LR( te_int, te_vec3 ) left = lhs->cast_to = env->ckt_float; // 1.3.5.3
CK_LR( te_int, te_vec4 ) left = lhs->cast_to = env->ckt_float; // 1.3.5.3
}
else if( op == ae_op_divide_chuck )
{
+ CK_LR( te_int, te_vec2 ) left = lhs->cast_to = env->ckt_float; // 1.5.1.7
CK_LR( te_int, te_vec3 ) left = lhs->cast_to = env->ckt_float; // 1.3.5.3
CK_LR( te_int, te_vec4 ) left = lhs->cast_to = env->ckt_float; // 1.3.5.3
}
@@ -2203,8 +2218,11 @@ t_CKTYPE type_engine_check_op( Chuck_Env * env, ae_Operator op, a_Exp lhs, a_Exp
CK_LR( te_polar, te_polar ) return env->ckt_polar;
// CK_COMMUTE( te_float, te_complex ) return env->ckt_complex;
// CK_COMMUTE( te_float, te_polar ) return env->ckt_polar;
+ CK_LR( te_vec2, te_vec2 ) return env->ckt_vec2; // 1.5.1.7
CK_LR( te_vec3, te_vec3 ) return env->ckt_vec3; // 1.3.5.3
CK_LR( te_vec4, te_vec4 ) return env->ckt_vec4; // 1.3.5.3
+ CK_COMMUTE( te_vec2, te_vec3 ) return env->ckt_vec3; // 1.5.1.7
+ CK_COMMUTE( te_vec2, te_vec4 ) return env->ckt_vec4; // 1.5.1.7
CK_COMMUTE( te_vec3, te_vec4 ) return env->ckt_vec4; // 1.3.5.3
CK_COMMUTE( te_dur, te_time ) return env->ckt_time;
if( isa( left, env->ckt_string ) && isa( right, env->ckt_string ) ) return env->ckt_string;
@@ -2224,8 +2242,11 @@ t_CKTYPE type_engine_check_op( Chuck_Env * env, ae_Operator op, a_Exp lhs, a_Exp
CK_LR( te_polar, te_polar ) return env->ckt_polar;
// CK_COMMUTE( te_float, te_complex ) return env->ckt_complex;
// CK_COMMUTE( te_float, te_polar ) return env->ckt_polar;
+ CK_LR( te_vec2, te_vec2 ) return env->ckt_vec2; // 1.5.1.7
CK_LR( te_vec3, te_vec3 ) return env->ckt_vec3; // 1.3.5.3
CK_LR( te_vec4, te_vec4 ) return env->ckt_vec4; // 1.3.5.3
+ CK_COMMUTE( te_vec2, te_vec3 ) return env->ckt_vec3; // 1.5.1.7
+ CK_COMMUTE( te_vec2, te_vec4 ) return env->ckt_vec4; // 1.5.1.7
CK_COMMUTE( te_vec3, te_vec4 ) return env->ckt_vec4; // 1.3.5.3
break;
@@ -2239,8 +2260,11 @@ t_CKTYPE type_engine_check_op( Chuck_Env * env, ae_Operator op, a_Exp lhs, a_Exp
CK_LR( te_polar, te_polar ) return env->ckt_polar;
// CK_COMMUTE( te_float, te_complex ) return env->ckt_complex;
// CK_COMMUTE( te_float, te_polar ) return env->ckt_polar;
+ CK_LR( te_vec2, te_vec2 ) return env->ckt_vec3; // 1.5.1.7
CK_LR( te_vec3, te_vec3 ) return env->ckt_vec3; // 1.3.5.3
CK_LR( te_vec4, te_vec4 ) return env->ckt_vec4; // 1.3.5.3
+ CK_COMMUTE( te_vec2, te_vec3 ) return env->ckt_vec3; // 1.5.1.7
+ CK_COMMUTE( te_vec2, te_vec4 ) return env->ckt_vec4; // 1.5.1.7
CK_COMMUTE( te_vec3, te_vec4 ) return env->ckt_vec4; // 1.3.5.3
break;
@@ -2254,6 +2278,7 @@ t_CKTYPE type_engine_check_op( Chuck_Env * env, ae_Operator op, a_Exp lhs, a_Exp
CK_COMMUTE( te_float, te_dur ) return env->ckt_dur;
// CK_COMMUTE( te_float, te_complex ) return env->ckt_complex;
// CK_COMMUTE( te_float, te_polar ) return env->ckt_polar;
+ CK_COMMUTE( te_float, te_vec2 ) return env->ckt_vec2; // 1.5.1.7
CK_COMMUTE( te_float, te_vec3 ) return env->ckt_vec3; // 1.3.5.3
CK_COMMUTE( te_float, te_vec4 ) return env->ckt_vec4; // 1.3.5.3
break;
@@ -2264,6 +2289,7 @@ t_CKTYPE type_engine_check_op( Chuck_Env * env, ae_Operator op, a_Exp lhs, a_Exp
CK_LR( te_float, te_dur ) return env->ckt_dur;
CK_LR( te_complex, te_complex ) return env->ckt_complex;
CK_LR( te_polar, te_polar ) return env->ckt_polar;
+ CK_LR( te_float, te_vec2 ) return env->ckt_vec2; // 1.5.1.7
CK_LR( te_float, te_vec3 ) return env->ckt_vec3; // 1.3.5.3
CK_LR( te_float, te_vec4 ) return env->ckt_vec4; // 1.3.5.3
break;
@@ -2276,6 +2302,7 @@ t_CKTYPE type_engine_check_op( Chuck_Env * env, ae_Operator op, a_Exp lhs, a_Exp
CK_LR( te_float, te_float ) return env->ckt_float;
CK_LR( te_complex, te_complex ) return env->ckt_complex;
CK_LR( te_polar, te_polar ) return env->ckt_polar;
+ CK_LR( te_vec2, te_float ) return env->ckt_vec2;
CK_LR( te_vec3, te_float ) return env->ckt_vec3;
CK_LR( te_vec4, te_float ) return env->ckt_vec4;
break;
@@ -2287,33 +2314,43 @@ t_CKTYPE type_engine_check_op( Chuck_Env * env, ae_Operator op, a_Exp lhs, a_Exp
CK_LR( te_float, te_dur ) return env->ckt_dur;
CK_LR( te_complex, te_complex ) return env->ckt_complex;
CK_LR( te_polar, te_polar ) return env->ckt_polar;
+ CK_LR( te_float, te_vec2 ) return env->ckt_vec2; // 1.5.1.7
+ CK_LR( te_float, te_vec3 ) return env->ckt_vec3; // 1.5.1.7
+ CK_LR( te_float, te_vec4 ) return env->ckt_vec4; // 1.5.1.7
break;
+ case ae_op_eq:
+ case ae_op_neq:
+ // null
+ // if( isa( left, env->ckt_object ) && isa( right, env->ckt_null ) ) return env->ckt_int;
+ // if( isa( left, env->ckt_null ) && isa( right, env->ckt_object ) ) return env->ckt_int;
+ CK_LR( te_vec2, te_vec2 ) return env->ckt_int; // 1.5.1.7
+ CK_LR( te_vec3, te_vec3 ) return env->ckt_int; // 1.3.5.3
+ CK_LR( te_vec4, te_vec4 ) return env->ckt_int; // 1.3.5.3
+ case ae_op_lt:
case ae_op_le:
+ {
// file output
- if( isa( left, env->ckt_io ) )
+ if( op == ae_op_le && isa( left, env->ckt_io ) )
{
if( isa( right, env->ckt_int ) ) return left;
else if( isa( right, env->ckt_float ) ) return left;
else if( isa( right, env->ckt_string ) ) return left;
else if( isa( right, env->ckt_complex ) ) return left;
else if( isa( right, env->ckt_polar ) ) return left;
+ else if( isa( right, env->ckt_vec2 ) ) return left;
else if( isa( right, env->ckt_vec3 ) ) return left;
else if( isa( right, env->ckt_vec4 ) ) return left;
else // error
{
EM_error2( binary->where, "no suitable IO action for '%s' <= '%s'",
- left->c_name(), right->c_name() );
+ left->c_name(), right->c_name() );
return NULL;
}
}
- case ae_op_eq:
- // null
- // if( isa( left, env->ckt_object ) && isa( right, env->ckt_null ) ) return env->ckt_int;
- // if( isa( left, env->ckt_null ) && isa( right, env->ckt_object ) ) return env->ckt_int;
- case ae_op_lt:
- case ae_op_gt: case ae_op_ge:
- case ae_op_neq:
+ }
+ case ae_op_gt:
+ case ae_op_ge:
CK_LR( te_int, te_int ) return env->ckt_int;
CK_LR( te_float, te_float ) return env->ckt_int;
CK_LR( te_dur, te_dur ) return env->ckt_int;
@@ -2322,9 +2359,9 @@ t_CKTYPE type_engine_check_op( Chuck_Env * env, ae_Operator op, a_Exp lhs, a_Exp
CK_LR( te_polar, te_polar ) return env->ckt_int;
// CK_COMMUTE( te_float, te_complex ) return env->ckt_int;
// CK_COMMUTE( te_float, te_polar ) return env->ckt_int;
- CK_LR( te_vec3, te_vec3 ) return env->ckt_int; // 1.3.5.3
- CK_LR( te_vec4, te_vec4 ) return env->ckt_int; // 1.3.5.3
- CK_COMMUTE( te_vec3, te_vec4 ) return env->ckt_int; // 1.3.5.3
+ // CK_COMMUTE( te_vec2, te_vec3 ) return env->ckt_int; // 1.5.1.7
+ // CK_COMMUTE( te_vec2, te_vec4 ) return env->ckt_int; // 1.5.1.7
+ // CK_COMMUTE( te_vec3, te_vec4 ) return env->ckt_int; // 1.3.5.3
if( isa( left, env->ckt_object ) && isa( right, env->ckt_object ) ) return env->ckt_int;
break;
@@ -2687,6 +2724,8 @@ t_CKTYPE type_engine_check_op_chuck( Chuck_Env * env, a_Exp lhs, a_Exp rhs,
CK_LR( te_int, te_float ) left = lhs->cast_to = env->ckt_float;
CK_LR( te_int, te_complex ) left = lhs->cast_to = env->ckt_complex;
CK_LR( te_int, te_polar ) left = lhs->cast_to = env->ckt_polar;
+ CK_LR( te_vec2, te_vec3 ) left = lhs->cast_to = env->ckt_vec3;
+ CK_LR( te_vec2, te_vec4 ) left = lhs->cast_to = env->ckt_vec4;
CK_LR( te_vec3, te_vec4 ) left = lhs->cast_to = env->ckt_vec4;
// assignment or something else
@@ -3680,6 +3719,10 @@ t_CKTYPE type_engine_check_exp_vec_lit( Chuck_Env * env, a_Exp_Primary exp )
e = e->next;
}
+ // check number of arguments
+ if( val->numdims < 3 )
+ return env->ckt_vec2;
+
// check number of arguments
if( val->numdims < 4 )
return env->ckt_vec3;
@@ -3747,7 +3790,11 @@ t_CKBOOL type_engine_check_cast_valid( Chuck_Env * env, t_CKTYPE to, t_CKTYPE fr
if( isa( to, env->ckt_polar ) && isa( from, env->ckt_float ) ) return TRUE;
if( isa( to, env->ckt_complex ) && isa( from, env->ckt_polar ) ) return TRUE;
if( isa( to, env->ckt_polar ) && isa( from, env->ckt_complex ) ) return TRUE;
+ if( isa( to, env->ckt_vec2 ) && isa( from, env->ckt_vec3 ) ) return TRUE;
+ if( isa( to, env->ckt_vec2 ) && isa( from, env->ckt_vec4 ) ) return TRUE;
+ if( isa( to, env->ckt_vec3 ) && isa( from, env->ckt_vec2 ) ) return TRUE;
if( isa( to, env->ckt_vec3 ) && isa( from, env->ckt_vec4 ) ) return TRUE;
+ if( isa( to, env->ckt_vec4 ) && isa( from, env->ckt_vec2 ) ) return TRUE;
if( isa( to, env->ckt_vec4 ) && isa( from, env->ckt_vec3 ) ) return TRUE;
return FALSE;
@@ -4383,7 +4430,8 @@ t_CKTYPE type_engine_check_exp_func_call( Chuck_Env * env, a_Exp_Func_Call func_
//-----------------------------------------------------------------------------
// name: type_engine_check_exp_dot_member_special()
-// desc: check special case for complex, polar, vec3, vec4; ge: 1.3.5.3
+// desc: check special case for complex, polar, vec3, vec4 (ge) 1.3.5.3
+// add support for vec2 (ge) 1.5.1.7
//-----------------------------------------------------------------------------
t_CKTYPE type_engine_check_exp_dot_member_special( Chuck_Env * env, a_Exp_Dot_Member member )
{
@@ -4440,6 +4488,33 @@ t_CKTYPE type_engine_check_exp_dot_member_special( Chuck_Env * env, a_Exp_Dot_Me
return NULL;
}
}
+ // vec2
+ else if( member->t_base->xid == te_vec2 )
+ {
+ // get as string
+ string str = S_name(member->xid);
+ // verify member is either re or im
+ if( str == "x" || str == "y" || str == "u" || str == "v" || str == "s" || str == "t" )
+ {
+ // check addressing consistency (ISSUE: emit_var set after!)
+ if( member->self->emit_var && member->base->s_meta != ae_meta_var )
+ {
+ // error
+ EM_error2( member->base->where,
+ "cannot assign value to literal vec2 value" );
+ return NULL;
+ }
+
+ return env->ckt_float;
+ }
+ else
+ {
+ // not valid
+ EM_error2( member->where,
+ "type '%s' has no member named '%s'", member->t_base->c_name(), str.c_str() );
+ return NULL;
+ }
+ }
else if( member->t_base->xid == te_vec3 || member->t_base->xid == te_vec4 )
{
// get as string
@@ -4549,6 +4624,7 @@ t_CKTYPE type_engine_check_exp_dot_member( Chuck_Env * env, a_Exp_Dot_Member mem
{
case te_complex:
case te_polar:
+ case te_vec2:
case te_vec3:
case te_vec4:
return type_engine_check_exp_dot_member_special( env, member );
@@ -5564,7 +5640,7 @@ t_CKBOOL type_engine_check_primitive( Chuck_Env * env, Chuck_Type * type )
{
return ( isa(type, env->ckt_void) || isa(type, env->ckt_int) || isa(type, env->ckt_float) || isa(type, env->ckt_dur) ||
isa(type, env->ckt_time) || isa(type, env->ckt_complex) || isa(type, env->ckt_polar) ||
- isa(type, env->ckt_vec3) || isa(type, env->ckt_vec4) )
+ isa(type, env->ckt_vec2) || isa(type, env->ckt_vec3) || isa(type, env->ckt_vec4) )
&& ( type->array_depth == 0 );
}
t_CKBOOL isprim( Chuck_Env * env, Chuck_Type * type )
@@ -5587,8 +5663,8 @@ te_KindOf getkindof( Chuck_Env * env, Chuck_Type * type ) // added 1.3.1.0
kind = kindof_INT;
else if( type->size == sz_FLOAT )
kind = kindof_FLOAT;
- else if( type->size == sz_COMPLEX )
- kind = kindof_COMPLEX;
+ else if( type->size == sz_VEC2 )
+ kind = kindof_VEC2;
else if( type->size == sz_VEC3 )
kind = kindof_VEC3;
else if( type->size == sz_VEC4 )
@@ -6714,8 +6790,11 @@ void type_engine_init_op_overload_builtin( Chuck_Env * env )
registry->reserve( env->ckt_time, ae_op_plus, env->ckt_dur );
registry->reserve( env->ckt_complex, ae_op_plus, env->ckt_complex );
registry->reserve( env->ckt_polar, ae_op_plus, env->ckt_polar );
+ registry->reserve( env->ckt_vec2, ae_op_plus, env->ckt_vec2 ); // 1.5.1.7
registry->reserve( env->ckt_vec3, ae_op_plus, env->ckt_vec3 );
registry->reserve( env->ckt_vec4, ae_op_plus, env->ckt_vec4 );
+ registry->reserve( env->ckt_vec2, ae_op_plus, env->ckt_vec3, TRUE ); // commute | 1.5.1.7
+ registry->reserve( env->ckt_vec2, ae_op_plus, env->ckt_vec4, TRUE ); // commute | 1.5.1.7
registry->reserve( env->ckt_vec3, ae_op_plus, env->ckt_vec4, TRUE ); // commute
registry->reserve( env->ckt_object, ae_op_plus, env->ckt_string ); // object +=> string
registry->reserve( env->ckt_int, ae_op_plus, env->ckt_string, TRUE ); // int/float +=> string
@@ -6728,16 +6807,21 @@ void type_engine_init_op_overload_builtin( Chuck_Env * env )
registry->reserve( env->ckt_dur, ae_op_minus, env->ckt_dur );
registry->reserve( env->ckt_complex, ae_op_minus, env->ckt_complex );
registry->reserve( env->ckt_polar, ae_op_minus, env->ckt_polar );
+ registry->reserve( env->ckt_vec2, ae_op_minus, env->ckt_vec2 ); // 1.5.1.7
registry->reserve( env->ckt_vec3, ae_op_minus, env->ckt_vec3 );
registry->reserve( env->ckt_vec4, ae_op_minus, env->ckt_vec4 );
+ registry->reserve( env->ckt_vec2, ae_op_minus, env->ckt_vec3, TRUE ); // commute | 1.5.1.7
+ registry->reserve( env->ckt_vec2, ae_op_minus, env->ckt_vec4, TRUE ); // commute | 1.5.1.7
registry->reserve( env->ckt_vec3, ae_op_minus, env->ckt_vec4, TRUE );
// *
registry->reserve( env->ckt_int, ae_op_times, env->ckt_int );
registry->reserve( env->ckt_float, ae_op_times, env->ckt_float );
registry->reserve( env->ckt_complex, ae_op_times, env->ckt_complex );
registry->reserve( env->ckt_polar, ae_op_times, env->ckt_polar );
+ /* no 2D cross product; use vec3 and vec4 */
registry->reserve( env->ckt_vec3, ae_op_times, env->ckt_vec3 );
registry->reserve( env->ckt_vec4, ae_op_times, env->ckt_vec4 );
+ registry->reserve( env->ckt_float, ae_op_times, env->ckt_vec2, TRUE ); // commute | 1.5.1.7
registry->reserve( env->ckt_float, ae_op_times, env->ckt_vec3, TRUE );
registry->reserve( env->ckt_float, ae_op_times, env->ckt_vec4, TRUE );
registry->reserve( env->ckt_float, ae_op_times, env->ckt_dur, TRUE );
@@ -6749,6 +6833,9 @@ void type_engine_init_op_overload_builtin( Chuck_Env * env )
registry->reserve( env->ckt_time, ae_op_divide, env->ckt_dur );
registry->reserve( env->ckt_complex, ae_op_divide, env->ckt_complex );
registry->reserve( env->ckt_polar, ae_op_divide, env->ckt_polar );
+ registry->reserve( env->ckt_vec2, ae_op_divide, env->ckt_float );
+ registry->reserve( env->ckt_vec3, ae_op_divide, env->ckt_float );
+ registry->reserve( env->ckt_vec4, ae_op_divide, env->ckt_float );
//-------------------------------------------------------------------------
// == != < > <= >=
@@ -6759,8 +6846,11 @@ void type_engine_init_op_overload_builtin( Chuck_Env * env )
registry->reserve( env->ckt_time, ae_op_eq, env->ckt_time );
registry->reserve( env->ckt_complex, ae_op_eq, env->ckt_complex );
registry->reserve( env->ckt_polar, ae_op_eq, env->ckt_polar );
+ registry->reserve( env->ckt_vec2, ae_op_eq, env->ckt_vec2 );
registry->reserve( env->ckt_vec3, ae_op_eq, env->ckt_vec3 );
registry->reserve( env->ckt_vec4, ae_op_eq, env->ckt_vec4 );
+ registry->reserve( env->ckt_vec2, ae_op_eq, env->ckt_vec3, TRUE );
+ registry->reserve( env->ckt_vec2, ae_op_eq, env->ckt_vec4, TRUE );
registry->reserve( env->ckt_vec3, ae_op_eq, env->ckt_vec4, TRUE );
registry->reserve( env->ckt_object, ae_op_eq, env->ckt_object );
// !=
@@ -6770,8 +6860,11 @@ void type_engine_init_op_overload_builtin( Chuck_Env * env )
registry->reserve( env->ckt_time, ae_op_neq, env->ckt_time );
registry->reserve( env->ckt_complex, ae_op_neq, env->ckt_complex );
registry->reserve( env->ckt_polar, ae_op_neq, env->ckt_polar );
+ registry->reserve( env->ckt_vec2, ae_op_neq, env->ckt_vec2 );
registry->reserve( env->ckt_vec3, ae_op_neq, env->ckt_vec3 );
registry->reserve( env->ckt_vec4, ae_op_neq, env->ckt_vec4 );
+ registry->reserve( env->ckt_vec2, ae_op_neq, env->ckt_vec3, TRUE );
+ registry->reserve( env->ckt_vec2, ae_op_neq, env->ckt_vec4, TRUE );
registry->reserve( env->ckt_vec3, ae_op_neq, env->ckt_vec4, TRUE );
registry->reserve( env->ckt_object, ae_op_neq, env->ckt_object );
// <
@@ -6781,9 +6874,12 @@ void type_engine_init_op_overload_builtin( Chuck_Env * env )
registry->reserve( env->ckt_time, ae_op_lt, env->ckt_time );
registry->reserve( env->ckt_complex, ae_op_lt, env->ckt_complex );
registry->reserve( env->ckt_polar, ae_op_lt, env->ckt_polar );
- registry->reserve( env->ckt_vec3, ae_op_lt, env->ckt_vec3 );
- registry->reserve( env->ckt_vec4, ae_op_lt, env->ckt_vec4 );
- registry->reserve( env->ckt_vec3, ae_op_lt, env->ckt_vec4, TRUE );
+ // registry->reserve( env->ckt_vec2, ae_op_lt, env->ckt_vec2 );
+ // registry->reserve( env->ckt_vec3, ae_op_lt, env->ckt_vec3 );
+ // registry->reserve( env->ckt_vec4, ae_op_lt, env->ckt_vec4 );
+ // registry->reserve( env->ckt_vec2, ae_op_lt, env->ckt_vec3, TRUE );
+ // registry->reserve( env->ckt_vec2, ae_op_lt, env->ckt_vec4, TRUE );
+ // registry->reserve( env->ckt_vec3, ae_op_lt, env->ckt_vec4, TRUE );
registry->reserve( env->ckt_object, ae_op_lt, env->ckt_object );
// >
registry->reserve( env->ckt_int, ae_op_gt, env->ckt_int );
@@ -6792,9 +6888,12 @@ void type_engine_init_op_overload_builtin( Chuck_Env * env )
registry->reserve( env->ckt_time, ae_op_gt, env->ckt_time );
registry->reserve( env->ckt_complex, ae_op_gt, env->ckt_complex );
registry->reserve( env->ckt_polar, ae_op_gt, env->ckt_polar );
- registry->reserve( env->ckt_vec3, ae_op_gt, env->ckt_vec3 );
- registry->reserve( env->ckt_vec4, ae_op_gt, env->ckt_vec4 );
- registry->reserve( env->ckt_vec3, ae_op_gt, env->ckt_vec4, TRUE );
+ // registry->reserve( env->ckt_vec2, ae_op_gt, env->ckt_vec2 );
+ // registry->reserve( env->ckt_vec3, ae_op_gt, env->ckt_vec3 );
+ // registry->reserve( env->ckt_vec4, ae_op_gt, env->ckt_vec4 );
+ // registry->reserve( env->ckt_vec2, ae_op_gt, env->ckt_vec3, TRUE );
+ // registry->reserve( env->ckt_vec2, ae_op_gt, env->ckt_vec4, TRUE );
+ // registry->reserve( env->ckt_vec3, ae_op_gt, env->ckt_vec4, TRUE );
registry->reserve( env->ckt_object, ae_op_gt, env->ckt_object );
// <=
registry->reserve( env->ckt_int, ae_op_le, env->ckt_int );
@@ -6803,9 +6902,12 @@ void type_engine_init_op_overload_builtin( Chuck_Env * env )
registry->reserve( env->ckt_time, ae_op_le, env->ckt_time );
registry->reserve( env->ckt_complex, ae_op_le, env->ckt_complex );
registry->reserve( env->ckt_polar, ae_op_le, env->ckt_polar );
- registry->reserve( env->ckt_vec3, ae_op_le, env->ckt_vec3 );
- registry->reserve( env->ckt_vec4, ae_op_le, env->ckt_vec4 );
- registry->reserve( env->ckt_vec3, ae_op_le, env->ckt_vec4, TRUE );
+ // registry->reserve( env->ckt_vec2, ae_op_le, env->ckt_vec2 );
+ // registry->reserve( env->ckt_vec3, ae_op_le, env->ckt_vec3 );
+ // registry->reserve( env->ckt_vec4, ae_op_le, env->ckt_vec4 );
+ // registry->reserve( env->ckt_vec2, ae_op_le, env->ckt_vec3, TRUE );
+ // registry->reserve( env->ckt_vec2, ae_op_le, env->ckt_vec4, TRUE );
+ // registry->reserve( env->ckt_vec3, ae_op_le, env->ckt_vec4, TRUE );
registry->reserve( env->ckt_object, ae_op_le, env->ckt_object );
// IO <= rhs
registry->reserve( env->ckt_io, ae_op_le, env->ckt_int );
@@ -6814,6 +6916,7 @@ void type_engine_init_op_overload_builtin( Chuck_Env * env )
registry->reserve( env->ckt_io, ae_op_le, env->ckt_time );
registry->reserve( env->ckt_io, ae_op_le, env->ckt_complex );
registry->reserve( env->ckt_io, ae_op_le, env->ckt_polar );
+ registry->reserve( env->ckt_io, ae_op_le, env->ckt_vec2 );
registry->reserve( env->ckt_io, ae_op_le, env->ckt_vec3 );
registry->reserve( env->ckt_io, ae_op_le, env->ckt_vec4 );
// >=
@@ -6823,9 +6926,12 @@ void type_engine_init_op_overload_builtin( Chuck_Env * env )
registry->reserve( env->ckt_time, ae_op_ge, env->ckt_time );
registry->reserve( env->ckt_complex, ae_op_ge, env->ckt_complex );
registry->reserve( env->ckt_polar, ae_op_ge, env->ckt_polar );
- registry->reserve( env->ckt_vec3, ae_op_ge, env->ckt_vec3 );
- registry->reserve( env->ckt_vec4, ae_op_ge, env->ckt_vec4 );
- registry->reserve( env->ckt_vec3, ae_op_ge, env->ckt_vec4, TRUE );
+ // registry->reserve( env->ckt_vec2, ae_op_ge, env->ckt_vec2 );
+ // registry->reserve( env->ckt_vec3, ae_op_ge, env->ckt_vec3 );
+ // registry->reserve( env->ckt_vec4, ae_op_ge, env->ckt_vec4 );
+ // registry->reserve( env->ckt_vec2, ae_op_ge, env->ckt_vec3, TRUE );
+ // registry->reserve( env->ckt_vec2, ae_op_ge, env->ckt_vec4, TRUE );
+ // registry->reserve( env->ckt_vec3, ae_op_ge, env->ckt_vec4, TRUE );
registry->reserve( env->ckt_object, ae_op_ge, env->ckt_object );
//-------------------------------------------------------------------------
@@ -6855,10 +6961,12 @@ void type_engine_init_op_overload_builtin( Chuck_Env * env )
registry->reserve( env->ckt_time, ae_op_plus_chuck, env->ckt_dur );
registry->reserve( env->ckt_complex, ae_op_plus_chuck, env->ckt_complex );
registry->reserve( env->ckt_polar, ae_op_plus_chuck, env->ckt_polar );
+ registry->reserve( env->ckt_vec2, ae_op_plus_chuck, env->ckt_vec2 );
registry->reserve( env->ckt_vec3, ae_op_plus_chuck, env->ckt_vec3 );
registry->reserve( env->ckt_vec4, ae_op_plus_chuck, env->ckt_vec4 );
- registry->reserve( env->ckt_vec3, ae_op_plus_chuck, env->ckt_vec4);
- registry->reserve( env->ckt_vec4, ae_op_plus_chuck, env->ckt_vec3 );
+ registry->reserve( env->ckt_vec2, ae_op_plus_chuck, env->ckt_vec3, TRUE );
+ registry->reserve( env->ckt_vec2, ae_op_plus_chuck, env->ckt_vec4, TRUE );
+ registry->reserve( env->ckt_vec3, ae_op_plus_chuck, env->ckt_vec4, TRUE );
registry->reserve( env->ckt_object, ae_op_plus_chuck, env->ckt_string ); // object +=> string
registry->reserve( env->ckt_int, ae_op_plus_chuck, env->ckt_string ); // int/float +=> string
registry->reserve( env->ckt_float, ae_op_plus_chuck, env->ckt_string ); // string +=> int/float
@@ -6871,18 +6979,22 @@ void type_engine_init_op_overload_builtin( Chuck_Env * env )
registry->reserve( env->ckt_dur, ae_op_minus_chuck, env->ckt_time );
registry->reserve( env->ckt_complex, ae_op_minus_chuck, env->ckt_complex );
registry->reserve( env->ckt_polar, ae_op_minus_chuck, env->ckt_polar );
+ registry->reserve( env->ckt_vec2, ae_op_minus_chuck, env->ckt_vec2 );
registry->reserve( env->ckt_vec3, ae_op_minus_chuck, env->ckt_vec3 );
registry->reserve( env->ckt_vec4, ae_op_minus_chuck, env->ckt_vec4 );
- registry->reserve( env->ckt_vec3, ae_op_minus_chuck, env->ckt_vec4);
- registry->reserve( env->ckt_vec4, ae_op_minus_chuck, env->ckt_vec3 );
+ registry->reserve( env->ckt_vec2, ae_op_minus_chuck, env->ckt_vec3, TRUE );
+ registry->reserve( env->ckt_vec2, ae_op_minus_chuck, env->ckt_vec4, TRUE );
+ registry->reserve( env->ckt_vec3, ae_op_minus_chuck, env->ckt_vec4, TRUE );
// *=>
registry->reserve( env->ckt_int, ae_op_times_chuck, env->ckt_int );
registry->reserve( env->ckt_float, ae_op_times_chuck, env->ckt_float );
registry->reserve( env->ckt_complex, ae_op_times_chuck, env->ckt_complex );
registry->reserve( env->ckt_polar, ae_op_times_chuck, env->ckt_polar );
+ registry->reserve( env->ckt_float, ae_op_times_chuck, env->ckt_vec2 );
registry->reserve( env->ckt_float, ae_op_times_chuck, env->ckt_vec3 );
registry->reserve( env->ckt_float, ae_op_times_chuck, env->ckt_vec4 );
registry->reserve( env->ckt_float, ae_op_times_chuck, env->ckt_dur );
+ registry->reserve( env->ckt_int, ae_op_times_chuck, env->ckt_vec2 );
registry->reserve( env->ckt_int, ae_op_times_chuck, env->ckt_vec3 );
registry->reserve( env->ckt_int, ae_op_times_chuck, env->ckt_vec4 );
registry->reserve( env->ckt_int, ae_op_times_chuck, env->ckt_dur );
@@ -6890,11 +7002,15 @@ void type_engine_init_op_overload_builtin( Chuck_Env * env )
registry->reserve( env->ckt_int, ae_op_divide_chuck, env->ckt_int );
registry->reserve( env->ckt_float, ae_op_divide_chuck, env->ckt_float );
registry->reserve( env->ckt_float, ae_op_divide_chuck, env->ckt_dur );
- registry->reserve( env->ckt_complex, ae_op_divide_chuck, env->ckt_complex );
- registry->reserve( env->ckt_polar, ae_op_divide_chuck, env->ckt_polar );
+ registry->reserve( env->ckt_float, ae_op_divide_chuck, env->ckt_vec2 );
+ registry->reserve( env->ckt_float, ae_op_divide_chuck, env->ckt_vec3 );
+ registry->reserve( env->ckt_float, ae_op_divide_chuck, env->ckt_vec4 );
+ registry->reserve( env->ckt_int, ae_op_divide_chuck, env->ckt_vec2 );
registry->reserve( env->ckt_int, ae_op_divide_chuck, env->ckt_vec3 );
registry->reserve( env->ckt_int, ae_op_divide_chuck, env->ckt_vec4 );
registry->reserve( env->ckt_int, ae_op_divide_chuck, env->ckt_dur );
+ registry->reserve( env->ckt_complex, ae_op_divide_chuck, env->ckt_complex );
+ registry->reserve( env->ckt_polar, ae_op_divide_chuck, env->ckt_polar );
//-------------------------------------------------------------------------
// &=> |=> ^=> >>=> <<=> %=>
@@ -8535,7 +8651,7 @@ t_CKBOOL Chuck_Func::pack_cache( Chuck_DL_Arg * dlargs, t_CKUINT numArgs )
{
case kindof_INT: memcpy( here, &dlargs[j].value.v_int, sizeof(dlargs[j].value.v_int) ); break;
case kindof_FLOAT: memcpy( here, &dlargs[j].value.v_float, sizeof(dlargs[j].value.v_float) ); break;
- case kindof_COMPLEX:memcpy( here, &dlargs[j].value.v_complex, sizeof(dlargs[j].value.v_complex) ); break;
+ case kindof_VEC2: memcpy( here, &dlargs[j].value.v_vec2, sizeof(dlargs[j].value.v_vec2) ); break;
case kindof_VEC3: memcpy( here, &dlargs[j].value.v_vec3, sizeof(dlargs[j].value.v_vec3) ); break;
case kindof_VEC4: memcpy( here, &dlargs[j].value.v_vec4, sizeof(dlargs[j].value.v_vec4) ); break;
diff --git a/src/core/chuck_type.h b/src/core/chuck_type.h
index 160b5aa31..c7ed7c9d2 100644
--- a/src/core/chuck_type.h
+++ b/src/core/chuck_type.h
@@ -52,7 +52,7 @@ typedef enum {
te_function, te_object, te_user, te_array, te_null, te_ugen, te_uana,
te_event, te_void, te_stdout, te_stderr, te_adc, te_dac, te_bunghole,
te_uanablob, te_io, te_fileio, te_chout, te_cherr, te_multi,
- te_vec3, te_vec4, te_vector, te_auto
+ te_vec2, te_vec3, te_vec4, te_vector, te_auto
} te_Type;
@@ -765,6 +765,7 @@ struct Chuck_Env : public Chuck_VM_Object
Chuck_Type * ckt_dur;
Chuck_Type * ckt_complex;
Chuck_Type * ckt_polar;
+ Chuck_Type * ckt_vec2;
Chuck_Type * ckt_vec3;
Chuck_Type * ckt_vec4;
Chuck_Type * ckt_null;
diff --git a/src/core/chuck_vm.cpp b/src/core/chuck_vm.cpp
index a195c82dd..c119d3aa7 100644
--- a/src/core/chuck_vm.cpp
+++ b/src/core/chuck_vm.cpp
@@ -3236,7 +3236,7 @@ t_CKBOOL Chuck_VM_MFunInvoker::setup( Chuck_Func * func, t_CKUINT func_vt_offset
instr_args.push_back( new Chuck_Instr_Reg_Push_Imm2(0) );
break;
- case kindof_COMPLEX:
+ case kindof_VEC2: // vec2 / complex / polar
// push value FLOAT FLOAT
instr_args.push_back( new Chuck_Instr_Reg_Push_Imm2(0) );
instr_args.push_back( new Chuck_Instr_Reg_Push_Imm2(0) );
@@ -3325,9 +3325,9 @@ t_CKBOOL Chuck_VM_MFunInvoker::setup( Chuck_Func * func, t_CKUINT func_vt_offset
instructions.push_back( new Chuck_Instr_Assign_Primitive2 );
instructions.push_back( new Chuck_Instr_Reg_Pop_Float );
break;
- case kindof_COMPLEX: // assign complex / polar
+ case kindof_VEC2: // assign vec2 / complex / polar
instructions.push_back( new Chuck_Instr_Assign_Primitive4 );
- instructions.push_back( new Chuck_Instr_Reg_Pop_Complex );
+ instructions.push_back( new Chuck_Instr_Reg_Pop_Vec2ComplexPolar );
break;
case kindof_VEC3: // assign vec3
instructions.push_back( new Chuck_Instr_Assign_PrimitiveVec3 );
@@ -3456,11 +3456,11 @@ Chuck_DL_Return Chuck_VM_MFunInvoker::invoke( Chuck_Object * obj, const vectorset( arg.value.v_float );
break;
- case kindof_COMPLEX:
+ case kindof_VEC2:
instr_pushFloat = ckvm_next_instr_as_float(instr_args, index); if( !instr_pushFloat ) goto error;
- instr_pushFloat->set( arg.value.v_complex.re );
+ instr_pushFloat->set( arg.value.v_vec2.x );
instr_pushFloat = ckvm_next_instr_as_float(instr_args, index); if( !instr_pushFloat ) goto error;
- instr_pushFloat->set( arg.value.v_complex.im );
+ instr_pushFloat->set( arg.value.v_vec2.y );
break;
case kindof_VEC3:
instr_pushFloat = ckvm_next_instr_as_float(instr_args, index); if( !instr_pushFloat ) goto error;
diff --git a/src/core/uana_xform.cpp b/src/core/uana_xform.cpp
index a204416ce..0bb347ccc 100644
--- a/src/core/uana_xform.cpp
+++ b/src/core/uana_xform.cpp
@@ -1341,7 +1341,7 @@ void IFFT_object::transform( Chuck_Array16 * cmp )
for( t_CKINT i = 0; i < amount; i++ )
{
// real and imag
- cmp->get( i, &v );
+ cmp->get( i, (t_CKVEC2 *)&v );
m_buffer[i*2] = v.re;
m_buffer[i*2+1] = v.im;
}
@@ -1465,7 +1465,7 @@ CK_DLL_TOCK( IFFT_tock )
for( t_CKINT i = 0; i < ifft->m_size/2; i++ )
{
// copy complex value in
- cmp.get( i, &cval );
+ cmp.get( i, (t_CKVEC2 *)&cval );
ifft->m_buffer[i*2] = cval.re;
ifft->m_buffer[i*2+1] = cval.im;
}
@@ -3627,7 +3627,7 @@ CK_DLL_TOCK( IDCT_tock )
for( t_CKINT i = 0; i < idct->m_size/2; i++ )
{
// copy complex value in
- cmp.get( i, &cval );
+ cmp.get( i, (t_CKVEC2 *)&cval );
idct->m_buffer[i*2] = cval.re;
idct->m_buffer[i*2+1] = cval.im;
}
diff --git a/src/core/ulib_math.cpp b/src/core/ulib_math.cpp
index 38c47fd9b..313878021 100644
--- a/src/core/ulib_math.cpp
+++ b/src/core/ulib_math.cpp
@@ -390,6 +390,12 @@ DLL_QUERY libmath_query( Chuck_DL_Query * QUERY )
QUERY->add_arg( QUERY, "float", "b[]" );
QUERY->doc_func( QUERY, "Compute the euclidean distance between arrays a and b." );
+ // add euclean (ge: added 1.5.1.7)
+ QUERY->add_sfun( QUERY, euclidean2d_impl, "float", "euclidean" ); //! euclidean similarity
+ QUERY->add_arg( QUERY, "vec2", "a" );
+ QUERY->add_arg( QUERY, "vec2", "b" );
+ QUERY->doc_func( QUERY, "Compute the euclidean distance between 2D vectors a and b." );
+
// add euclean (ge: added 1.5.0.0)
QUERY->add_sfun( QUERY, euclidean3d_impl, "float", "euclidean" ); //! euclidean similarity
QUERY->add_arg( QUERY, "vec3", "a" );
@@ -1155,6 +1161,25 @@ CK_DLL_SFUN( euclidean_impl )
}
+// euclidean (ge) | added 1.5.1.7
+CK_DLL_SFUN( euclidean2d_impl )
+{
+ t_CKVEC2 a = GET_NEXT_VEC2( ARGS );
+ t_CKVEC2 b = GET_NEXT_VEC2( ARGS );
+
+ // in case of error
+ RETURN->v_float = 0.0;
+
+ t_CKFLOAT d;
+ t_CKFLOAT sum = 0.0;
+ d = a.x - b.x; sum += d*d;
+ d = a.y - b.y; sum += d*d;
+
+ // set return value
+ RETURN->v_float = ::sqrt(sum);
+}
+
+
// euclidean (ge) | added 1.5.0.0
CK_DLL_SFUN( euclidean3d_impl )
{
diff --git a/src/core/ulib_math.h b/src/core/ulib_math.h
index 9fe81b162..38cf044a0 100644
--- a/src/core/ulib_math.h
+++ b/src/core/ulib_math.h
@@ -96,6 +96,7 @@ CK_DLL_SFUN( cossim3d_impl );
CK_DLL_SFUN( cossim4d_impl );
CK_DLL_SFUN( euclidean_impl );
+CK_DLL_SFUN( euclidean2d_impl );
CK_DLL_SFUN( euclidean3d_impl );
CK_DLL_SFUN( euclidean4d_impl );
diff --git a/src/core/util_math.cpp b/src/core/util_math.cpp
index abbcf202c..108b1fbd5 100644
--- a/src/core/util_math.cpp
+++ b/src/core/util_math.cpp
@@ -292,6 +292,30 @@ t_CKFLOAT ck_complex_phase( const t_CKCOMPLEX & cmp )
+//-----------------------------------------------------------------------------
+// name: ck_vec2_magnitude()
+// desc: magnitude of vec2
+//-----------------------------------------------------------------------------
+t_CKFLOAT ck_vec2_magnitude( const t_CKVEC2 & v )
+{
+ return ::sqrt( v.x*v.x + v.y*v.y );
+}
+
+
+
+
+//-----------------------------------------------------------------------------
+// name: ck_vec2_phase()
+// desc: phase of vec2 (treated as a complex value)
+//-----------------------------------------------------------------------------
+t_CKFLOAT ck_vec2_phase( const t_CKVEC2 & cmp )
+{
+ return ::atan2( cmp.x, cmp.y );
+}
+
+
+
+
//-----------------------------------------------------------------------------
// name: ck_vec3_magnitude()
// desc: magnitude of vec3
diff --git a/src/core/util_math.h b/src/core/util_math.h
index ecf4e3900..b1b69ff8f 100644
--- a/src/core/util_math.h
+++ b/src/core/util_math.h
@@ -100,6 +100,10 @@ unsigned long ck_ensurepow2( unsigned long i );
t_CKFLOAT ck_complex_magnitude( const t_CKCOMPLEX & cmp );
// phase of complex number
t_CKFLOAT ck_complex_phase( const t_CKCOMPLEX & cmp );
+// magnitude of vec2
+t_CKFLOAT ck_vec2_magnitude( const t_CKVEC2 & v );
+// phase of vec2
+t_CKFLOAT ck_vec2_phase( const t_CKVEC2 & v );
// magnitude of vec3
t_CKFLOAT ck_vec3_magnitude( const t_CKVEC3 & v );
// magnitude of vec4
diff --git a/src/test/01-Basic/214-num-types.ck b/src/test/01-Basic/214-num-types.ck
index c1ac62cde..1d8f3501d 100644
--- a/src/test/01-Basic/214-num-types.ck
+++ b/src/test/01-Basic/214-num-types.ck
@@ -8,7 +8,9 @@
<<< #(3,4) >>>;
// polar
<<< %(1,pi/2) >>>;
+// vec2
+<<< @(5,6) >>>;
// vec3
-<<< @(5,6,7) >>>;
+<<< @(7,8,9) >>>;
// vec4
-<<< @(5,6,7,8) >>>;
+<<< @(10,11,12,13) >>>;
diff --git a/src/test/01-Basic/214-num-types.txt b/src/test/01-Basic/214-num-types.txt
index a96a15b5e..3f5a35e2b 100644
--- a/src/test/01-Basic/214-num-types.txt
+++ b/src/test/01-Basic/214-num-types.txt
@@ -2,5 +2,6 @@
2.000000 :(float)
#(3.0000,4.0000) :(complex)
%(1.0000,0.5000*pi) :(polar)
-@(5.0000,6.0000,7.0000) :(vec3)
-@(5.0000,6.0000,7.0000,8.0000) :(vec4)
+@(5.0000,6.0000) :(vec2)
+@(7.0000,8.0000,9.0000) :(vec3)
+@(10.0000,11.0000,12.0000,13.0000) :(vec4)
diff --git a/src/test/01-Basic/218-vec2.ck b/src/test/01-Basic/218-vec2.ck
new file mode 100644
index 000000000..a444e5628
--- /dev/null
+++ b/src/test/01-Basic/218-vec2.ck
@@ -0,0 +1,78 @@
+// verifying vec2
+
+// print as vec2
+<<< "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();
diff --git a/src/test/01-Basic/218-vec2.txt b/src/test/01-Basic/218-vec2.txt
new file mode 100644
index 000000000..e8719be6a
--- /dev/null
+++ b/src/test/01-Basic/218-vec2.txt
@@ -0,0 +1,32 @@
+print vec2 literal: @(1.0000,2.0000)
+print variables: @(3.0000,4.0000) @(5.0000,6.0000)
+print fields (x,y): 3.000000 4.000000
+print fields (u,v): 3.000000 4.000000
+print fields (s,t): 3.000000 4.000000
+a == a : true
+a != 2*a : true
+a == b : false
+casting vec2 to vec3: #(7.0000,8.0000,0.0000)
+casting vec2 to vec4: #(9.0000,10.0000,0.0000,0.0000)
+casting vec3 to vec2: @(9.0000,10.0000)
+casting vec4 to vec2: @(9.0000,10.0000)
+plus minus: @(8.0000,10.0000) @(2.0000,2.0000)
+scalar multiply: @(1.5000,2.0000) @(10.0000,12.0000) @(2.5000,3.0000)
+adding vec2 literals: @(24.0000,26.0000)
+vec2 + vec3: #(32.0000,34.0000,19.0000)
+vec4 + vec2: #(21.0000,22.0000,22.0000,23.0000)
+add/times assign: @(13.0000,16.0000) @(5.0000,6.0000)
+minus/divide assign: @(10.0000,12.0000) @(2.5000,3.0000)
+foreach 1: @(3.0000,4.0000)
+foreach 1: @(5.0000,6.0000)
+foreach 1: @(7.0000,8.0000)
+foreach 1: @(24.0000,25.0000)
+foreach 1: @(2.0000,2.0000)
+foreach 2: @(1.0000,2.0000)
+foreach 2: @(3.0000,4.0000)
+foreach 2: @(5.0000,6.0000)
+map: @(100.0000,101.0000)
+foo(): @(1.0000,2.0000)
+bar(): @(3.0000,4.0000)
+bar(): @(5.0000,6.0000)
+cherr: @(3,4) @(5,6)
From f4583d35b0468c204227eac0b978c731b1c93652 Mon Sep 17 00:00:00 2001
From: Ge Wang
Date: Sun, 15 Oct 2023 20:46:16 -0700
Subject: [PATCH 4/4] minor cleanup in Chuck_VM_Object::release()
---
src/core/chuck_oo.cpp | 17 ++++++++---------
src/core/chuck_oo.h | 2 +-
2 files changed, 9 insertions(+), 10 deletions(-)
diff --git a/src/core/chuck_oo.cpp b/src/core/chuck_oo.cpp
index b41242034..dc7f84e6c 100644
--- a/src/core/chuck_oo.cpp
+++ b/src/core/chuck_oo.cpp
@@ -113,7 +113,7 @@ void Chuck_VM_Object::add_ref()
//-----------------------------------------------------------------------------
// name: release()
-// desc: remove reference
+// desc: decrement reference; deletes objects when refcount reaches 0;
//-----------------------------------------------------------------------------
void Chuck_VM_Object::release()
{
@@ -122,10 +122,10 @@ void Chuck_VM_Object::release()
//-----------------------------------------------------------------------------
if( m_ref_count <= 0 )
{
- // print warning
+ // log warning
EM_log( CK_LOG_FINEST, "(internal) Object.release() refcount already %d", m_ref_count );
- // print error
+ // disabled: error out
// EM_error3( "[chuck]: (internal error) Object.release() refcount == %d", m_ref_count );
// make sure there is at least one reference
// assert( m_ref_count > 0 );
@@ -136,8 +136,6 @@ void Chuck_VM_Object::release()
m_ref_count--;
}
- // added 1.3.0.0
- // CK_VM_DEBUG(CK_FPRINTF_STDERR( "Chuck_VM_Object::release() : 0x%08x, %s, %ulu\n", this, mini_type(typeid(*this).name()), m_ref_count));
// updated 1.5.0.5 to use Chuck_VM_Debug
CK_VM_DEBUGGER( release( this ) );
@@ -148,10 +146,10 @@ void Chuck_VM_Object::release()
if( our_locks_in_effect && m_locked )
{
EM_error2( 0, "(internal error) releasing locked VM object!" );
- // fail
+ // bail out
assert( FALSE );
// in case assert is disabled
- *(int *)0 = 1;
+ // *(int *)0 = 1;
}
#ifndef __CHUNREAL_ENGINE__
@@ -165,8 +163,9 @@ void Chuck_VM_Object::release()
// track | 1.5.0.5 (ge)
CK_VM_DEBUGGER( destruct( this ) );
- // REFACTOR-2017: doing this for now
- delete this;
+ // trigger this object's deletion / destructors
+ // should be valid as long as no members are used beyond this point
+ delete this; // REFACTOR-2017
}
}
diff --git a/src/core/chuck_oo.h b/src/core/chuck_oo.h
index 4c976cf58..949ecb260 100644
--- a/src/core/chuck_oo.h
+++ b/src/core/chuck_oo.h
@@ -77,7 +77,7 @@ struct Chuck_VM_Object
public:
// add reference (ge: april 2013: made these virtual)
virtual void add_ref();
- // release reference
+ // decrement reference; deletes objects when refcount reaches 0
virtual void release();
// lock
virtual void lock();