diff --git a/VERSIONS b/VERSIONS index 8f20ad5df..9d8e099d2 100644 --- a/VERSIONS +++ b/VERSIONS @@ -37,11 +37,17 @@ ChucK VERSIONS log `w` is also set to zero in the resulting vec4 vec3 vec3.cross( vec3 rhs ) vec4 vec4.cross( vec4 rhs ) +(added) Type.of( vec2 ) function to get the associate Type (added) --auto-load-chugin-path: flag -- this behaves as --chugin-path previously did: chugins in the specified path(s) are auto-loaded; .ck files can be @imported (fixed) --chugin: and --chugin-path: now correctly auto-expand paths +(updated) Shred(.parent(), .ancester(), .childMemSize(), .childRegSize()) + now will operate with respect to the shred reference rather than always + w.r.t. the calling shred (e.g., shred that is running when these functions + are called) +(added) Shred.pc(), .regSP(), .memSP() -- for debugging, info, amusement 1.5.4.1 (November 2024) diff --git a/src/core/chuck_lang.cpp b/src/core/chuck_lang.cpp index 62c7b8408..666a1b3da 100644 --- a/src/core/chuck_lang.cpp +++ b/src/core/chuck_lang.cpp @@ -612,21 +612,36 @@ t_CKBOOL init_class_shred( Chuck_Env * env, Chuck_Type * type ) func->doc = "get the operand stack size hint (in bytes) for shreds sporked from this one."; if( !type_engine_import_mfun( env, func ) ) goto error; - // add parent() | 1.5.2.0 (nshaheed) - func = make_new_sfun( "Shred", "parent", shred_parent ); + // add parent() | 1.5.2.0 (nshaheed) | 1.5.4.2 (ge) sfun => mfun + func = make_new_mfun( "Shred", "parent", shred_parent ); func->doc = "get the calling shred's parent shred (i.e., the shred that sporked the calling shred). Returns null if there is no parent Shred. (Related: see Shred.ancestor())"; - if( !type_engine_import_sfun( env, func ) ) goto error; + if( !type_engine_import_mfun( env, func ) ) goto error; - // add ancestor() | 1.5.2.0 (nshaheed) - func = make_new_sfun( "Shred", "ancestor", shred_ancestor ); + // add ancestor() | 1.5.2.0 (nshaheed) | 1.5.4.2 (ge) sfun => mfun + func = make_new_mfun( "Shred", "ancestor", shred_ancestor ); func->doc = "get the calling shred's \"ancestor\" shred (i.e., the top-level shred). Returns itself if the calling shred is the top-level shred. (Related: see Shred.parent())"; - if( !type_engine_import_sfun( env, func ) ) goto error; + if( !type_engine_import_mfun( env, func ) ) goto error; // add gc() | 1.5.2.0 (ge) added // func = make_new_mfun( "void", "gc", shred_gc ); // func->doc = "manually trigger a per-shred garbage collection pass; can be used to clean up certain UGens/objects without waiting for the shred to complete; use with care."; // if( !type_engine_import_mfun( env, func ) ) goto error; + // add pc() | 1.5.4.2 (ge) | 1.5.4.2 (ge) sfun => mfun + func = make_new_mfun( "int", "pc", shred_pc ); + func->doc = "get the calling shred's current program counter (CP); useful for debugging, general information, or amusement."; + if( !type_engine_import_mfun( env, func ) ) goto error; + + // add pc() | 1.5.4.2 (ge) | 1.5.4.2 (ge) sfun => mfun + func = make_new_mfun( "int", "regSP", shred_reg_stack_sp ); + func->doc = "get the calling shred's current register/operand stack pointer; useful for debugging, general information, or amusement."; + if( !type_engine_import_mfun( env, func ) ) goto error; + + // add pc() | 1.5.4.2 (ge) | 1.5.4.2 (ge) sfun => mfun + func = make_new_mfun( "int", "memSP", shred_mem_stack_sp ); + func->doc = "get the calling shred's current memory/call stack pointer; useful for debugging, general information, or amusement."; + if( !type_engine_import_mfun( env, func ) ) goto error; + // add examples if( !type_engine_import_add_ex( env, "shred/spork.ck" ) ) goto error; if( !type_engine_import_add_ex( env, "shred/spork2.ck" ) ) goto error; @@ -1520,6 +1535,12 @@ t_CKBOOL init_class_type( Chuck_Env * env, Chuck_Type * type ) func->doc = "return the Type associated with 'polar'."; if( !type_engine_import_sfun( env, func ) ) goto error; + // add typeOf() + func = make_new_sfun( "Type", "of", type_typeOf_vec2 ); + func->add_arg( "vec2", "val" ); + func->doc = "return the Type associated with 'vec2'."; + if( !type_engine_import_sfun( env, func ) ) goto error; + // add typeOf() func = make_new_sfun( "Type", "of", type_typeOf_vec3 ); func->add_arg( "vec3", "val" ); @@ -2685,68 +2706,103 @@ CK_DLL_SFUN( shred_fromId ) // added 1.3.2.0 CK_DLL_MFUN( shred_ctrl_hintChildMemSize ) // 1.5.1.5 { + // get this pointer + Chuck_VM_Shred * shred = (Chuck_VM_Shred *)SELF; // get arg t_CKINT sizeInBytes = GET_NEXT_INT(ARGS); // set - RETURN->v_int = SHRED->childSetMemSize( sizeInBytes ); + RETURN->v_int = shred->childSetMemSize( sizeInBytes ); } CK_DLL_MFUN( shred_cget_hintChildMemSize ) // 1.5.1.5 { + // get this pointer + Chuck_VM_Shred * shred = (Chuck_VM_Shred *)SELF; // set - RETURN->v_int = SHRED->childGetMemSize(); + RETURN->v_int = shred->childGetMemSize(); } CK_DLL_MFUN( shred_ctrl_hintChildRegSize ) // 1.5.1.5 { + // get this pointer + Chuck_VM_Shred * shred = (Chuck_VM_Shred *)SELF; // get arg t_CKINT sizeInBytes = GET_NEXT_INT(ARGS); // set - RETURN->v_int = SHRED->childSetRegSize( sizeInBytes ); + RETURN->v_int = shred->childSetRegSize( sizeInBytes ); } CK_DLL_MFUN( shred_cget_hintChildRegSize ) // 1.5.1.5 { + // get this pointer + Chuck_VM_Shred * shred = (Chuck_VM_Shred *)SELF; // set - RETURN->v_int = SHRED->childGetRegSize(); + RETURN->v_int = shred->childGetRegSize(); } -CK_DLL_SFUN( shred_parent ) // added 1.5.2.0 (nshaheed) +CK_DLL_MFUN( shred_parent ) // added 1.5.2.0 (nshaheed) { + // get this pointer + Chuck_VM_Shred * shred = (Chuck_VM_Shred *)SELF; // get the parent - Chuck_VM_Shred * parent = SHRED->parent; + Chuck_VM_Shred * parent = shred->parent; // set return value RETURN->v_object = parent; } -CK_DLL_SFUN( shred_ancestor ) // added 1.5.2.0 (nshaheed) +CK_DLL_MFUN( shred_ancestor ) // added 1.5.2.0 (nshaheed) { - // current shred - Chuck_VM_Shred * curr = SHRED; + // get this pointer + Chuck_VM_Shred * shred = (Chuck_VM_Shred *)SELF; // iterate up until parent is null; it's possible that // ancestor() returns the calling shred, if called on // the top-level "ancestor" shred - while( curr->parent != NULL ) + while( shred->parent != NULL ) { // set curr as parent - curr = curr->parent; + shred = shred->parent; } // set return value - RETURN->v_object = curr; + RETURN->v_object = shred; +} + +CK_DLL_MFUN( shred_pc ) // added 1.5.4.2 (ge) +{ + // get this pointer + Chuck_VM_Shred * shred = (Chuck_VM_Shred *)SELF; + // set return value to shred program counter + RETURN->v_int = shred->pc; +} + +CK_DLL_MFUN( shred_reg_stack_sp ) // added 1.5.4.2 (ge) +{ + // get this pointer + Chuck_VM_Shred * shred = (Chuck_VM_Shred *)SELF; + // set return value to shred register/operand stack pointer + RETURN->v_int = (t_CKINT)shred->reg->sp; } +CK_DLL_MFUN( shred_mem_stack_sp ) // added 1.5.4.2 (ge) +{ + // get this pointer + Chuck_VM_Shred * shred = (Chuck_VM_Shred *)SELF; + // set return value to shred register/operand stack pointer + RETURN->v_int = (t_CKINT)shred->mem->sp; +} CK_DLL_MFUN( shred_gc ) // added 1.5.2.0 (ge) { + // get this pointer + Chuck_VM_Shred * shred = (Chuck_VM_Shred *)SELF; // invoke manual per-shred GC pass - SHRED->gc(); + shred->gc(); } @@ -3954,6 +4010,11 @@ CK_DLL_SFUN( type_typeOf_polar ) RETURN->v_object = VM->env()->ckt_polar; } +CK_DLL_SFUN( type_typeOf_vec2 ) +{ + RETURN->v_object = VM->env()->ckt_vec2; +} + CK_DLL_SFUN( type_typeOf_vec3 ) { RETURN->v_object = VM->env()->ckt_vec3; diff --git a/src/core/chuck_lang.h b/src/core/chuck_lang.h index d2c64b36b..0acf8e675 100644 --- a/src/core/chuck_lang.h +++ b/src/core/chuck_lang.h @@ -171,13 +171,16 @@ CK_DLL_MFUN( shred_getArg ); CK_DLL_MFUN( shred_sourcePath ); // added 1.3.0.0 CK_DLL_MFUN( shred_sourceDir ); // added 1.3.0.0 CK_DLL_MFUN( shred_sourceDir2 ); // added 1.3.2.0 -CK_DLL_SFUN( shred_fromId ); // added 1.3.2.0 -CK_DLL_SFUN( shred_parent ); // added 1.5.2.0 (nshaheed) -CK_DLL_SFUN( shred_ancestor ); // added 1.5.2.0 (nshaheed) +CK_DLL_MFUN( shred_parent ); // added 1.5.2.0 (nshaheed) +CK_DLL_MFUN( shred_ancestor ); // added 1.5.2.0 (nshaheed) +CK_DLL_MFUN( shred_pc ); // added 1.5.4.2 (ge) +CK_DLL_MFUN( shred_reg_stack_sp ); // added 1.5.4.2 (ge) +CK_DLL_MFUN( shred_mem_stack_sp ); // added 1.5.4.2 (ge) CK_DLL_MFUN( shred_ctrl_hintChildMemSize ); // added 1.5.1.5 CK_DLL_MFUN( shred_cget_hintChildMemSize ); // added 1.5.1.5 CK_DLL_MFUN( shred_ctrl_hintChildRegSize ); // added 1.5.1.5 CK_DLL_MFUN( shred_cget_hintChildRegSize ); // added 1.5.1.5 +CK_DLL_SFUN( shred_fromId ); // added 1.3.2.0 //----------------------------------------------------------------------------- @@ -320,6 +323,7 @@ CK_DLL_SFUN( type_typeOf_time ); // Type.typeOf( time ) CK_DLL_SFUN( type_typeOf_dur ); // Type.typeOf( dur ) CK_DLL_SFUN( type_typeOf_complex ); // Type.typeOf( complex ) CK_DLL_SFUN( type_typeOf_polar ); // Type.typeOf( polar ) +CK_DLL_SFUN( type_typeOf_vec2 ); // Type.typeOf( vec2 ) CK_DLL_SFUN( type_typeOf_vec3 ); // Type.typeOf( vec3 ) CK_DLL_SFUN( type_typeOf_vec4 ); // Type.typeOf( vec4 ) CK_DLL_SFUN( type_getTypes ); diff --git a/src/core/chuck_vm.cpp b/src/core/chuck_vm.cpp index ada4a8e1b..3f8619ecd 100644 --- a/src/core/chuck_vm.cpp +++ b/src/core/chuck_vm.cpp @@ -1931,51 +1931,54 @@ void Chuck_VM_Shred::detach_ugens() // associated with this shred, instead of waiting for the shred to finish // NOTE this can be useful if a shred dynamically creates a lot of // UGens without exiting -//----------------------------------------------------------------------------- -void Chuck_VM_Shred::prune_ugens() -{ - // check if we have anything in ugen map for this shred - if( !m_ugen_map.size() ) - return; - - // ugens to release - std::vector release_v; - - // get iterator to our map - map::iterator iter = m_ugen_map.begin(); - while( iter != m_ugen_map.end() ) - { - // get the ugen - Chuck_UGen * ugen = iter->first; - - // verify - assert( ugen->refcount() > 0 ); - // check for ugens with only one reference (to this shred) - if( ugen->refcount() == 1 ) release_v.push_back( ugen ); - - // advance the iterator - iter++; - } - - // check if anything to prune - if( release_v.size() ) - { - // log - EM_log( CK_LOG_FINE, "pruning '%ld' ugen(s) from shred: %x...", release_v.size(), this ); - - // loop over vector - for( vector::iterator rvi = release_v.begin(); - rvi != release_v.end(); rvi++ ) - { - // remove from map - m_ugen_map.erase( *rvi ); - // release the ugen - CK_SAFE_RELEASE( *rvi ); - } - // clear the release vector - release_v.clear(); - } -} +// 1.5.4.2 (ge) NOTE this is no longer necessary as the new UGen/shred +// semantics have been updated for these types of checks to happen on +// a per-UGen level +//----------------------------------------------------------------------------- +//void Chuck_VM_Shred::prune_ugens() +//{ +// // check if we have anything in ugen map for this shred +// if( !m_ugen_map.size() ) +// return; +// +// // ugens to release +// std::vector release_v; +// +// // get iterator to our map +// map::iterator iter = m_ugen_map.begin(); +// while( iter != m_ugen_map.end() ) +// { +// // get the ugen +// Chuck_UGen * ugen = iter->first; +// +// // verify +// assert( ugen->refcount() > 0 ); +// // check for ugens with only one reference (to this shred) +// if( ugen->refcount() == 1 ) release_v.push_back( ugen ); +// +// // advance the iterator +// iter++; +// } +// +// // check if anything to prune +// if( release_v.size() ) +// { +// // log +// EM_log( CK_LOG_FINE, "pruning '%ld' ugen(s) from shred: %x...", release_v.size(), this ); +// +// // loop over vector +// for( vector::iterator rvi = release_v.begin(); +// rvi != release_v.end(); rvi++ ) +// { +// // remove from map +// m_ugen_map.erase( *rvi ); +// // release the ugen +// CK_SAFE_RELEASE( *rvi ); +// } +// // clear the release vector +// release_v.clear(); +// } +//} @@ -2010,7 +2013,9 @@ void Chuck_VM_Shred::gc_inc( t_CKDUR inc ) //----------------------------------------------------------------------------- void Chuck_VM_Shred::gc() { - this->prune_ugens(); + // 1.5.4.2 (ge) this type of pruning is no longer necessary; FYI in any + // case, this function was never activated in a release due to instabilty + // this->prune_ugens(); } diff --git a/src/core/chuck_vm.h b/src/core/chuck_vm.h index 475dd58db..40a20f9e7 100644 --- a/src/core/chuck_vm.h +++ b/src/core/chuck_vm.h @@ -192,8 +192,6 @@ struct Chuck_VM_Shred : public Chuck_Object t_CKBOOL remove( Chuck_UGen * ugen ); // detach all associate ugens | 1.5.1.5 (ge) added void detach_ugens(); - // clean up ugens | 1.5.2.0 (ge) added - void prune_ugens(); public: // manually trigger a per-shred garbage collection pass | 1.5.2.0 (ge) added