From aba6134405e8de2bae79b57c588864f3518c580f Mon Sep 17 00:00:00 2001 From: Ge Wang Date: Sun, 1 Oct 2023 01:52:39 -0700 Subject: [PATCH 01/26] add shreds watchers to DL and VM --- src/core/chuck_dl.cpp | 28 +++++++++++++- src/core/chuck_dl.h | 48 +++++++++++++++++------ src/core/chuck_vm.cpp | 89 +++++++++++++++++++++++++++++++++++++++++++ src/core/chuck_vm.h | 40 +++++++++++++++++++ 4 files changed, 193 insertions(+), 12 deletions(-) diff --git a/src/core/chuck_dl.cpp b/src/core/chuck_dl.cpp index d426915c1..808ecc5a7 100644 --- a/src/core/chuck_dl.cpp +++ b/src/core/chuck_dl.cpp @@ -706,7 +706,7 @@ t_CKBOOL CK_DLL_CALL ck_end_class( Chuck_DL_Query * query ) //----------------------------------------------------------------------------- // name: ck_create_main_thread_hook() -// desc: ... +// desc: create a main thread hook data structure //----------------------------------------------------------------------------- Chuck_DL_MainThreadHook * CK_DLL_CALL ck_create_main_thread_hook( Chuck_DL_Query * query, f_mainthreadhook hook, @@ -717,6 +717,27 @@ Chuck_DL_MainThreadHook * CK_DLL_CALL ck_create_main_thread_hook( Chuck_DL_Query } +//----------------------------------------------------------------------------- +// name: ck_register_shreds_watcher() +// desc: register a callback function to receive notifications +// from the VM about shreds (add, remove, etc.) +// `options` is a bit-wised OR of ckvmShredsWatcherFlag +//----------------------------------------------------------------------------- +void ck_register_shreds_watcher( Chuck_DL_Query * query, f_shreds_watcher cb, t_CKUINT options, void * bindle ) +{ + // subscribe + query->vm()->subscribe_watcher( cb, options, bindle ); +} + +//----------------------------------------------------------------------------- +// unregister a shreds notification callback +//----------------------------------------------------------------------------- +void ck_unregister_shreds_watcher( Chuck_DL_Query * query, f_shreds_watcher cb ) +{ + query->vm()->remove_watcher( cb ); +} + + //----------------------------------------------------------------------------- // name: ck_doc_class() // desc: set current class documentation @@ -733,6 +754,7 @@ t_CKBOOL CK_DLL_CALL ck_doc_class( Chuck_DL_Query * query, const char * doc ) return TRUE; } + //----------------------------------------------------------------------------- // name: ck_add_example() // desc: set current class documentation @@ -749,6 +771,7 @@ t_CKBOOL CK_DLL_CALL ck_add_example( Chuck_DL_Query * query, const char * ex ) return TRUE; } + // set current function documentation t_CKBOOL CK_DLL_CALL ck_doc_func( Chuck_DL_Query * query, const char * doc ) { @@ -762,6 +785,7 @@ t_CKBOOL CK_DLL_CALL ck_doc_func( Chuck_DL_Query * query, const char * doc ) return TRUE; } + // set last mvar documentation t_CKBOOL CK_DLL_CALL ck_doc_var( Chuck_DL_Query * query, const char * doc ) { @@ -1225,6 +1249,8 @@ Chuck_DL_Query::Chuck_DL_Query( Chuck_Carrier * carrier, Chuck_DLL * dll ) doc_var = ck_doc_var; add_ex = ck_add_example; // 1.5.0.0 (ge) added create_main_thread_hook = ck_create_main_thread_hook; + register_shreds_watcher = ck_register_shreds_watcher; + unregister_shreds_watcher = ck_unregister_shreds_watcher; m_carrier = carrier; dll_ref = dll; // 1.5.1.3 (ge) added diff --git a/src/core/chuck_dl.h b/src/core/chuck_dl.h index e7bf0e638..3f6c99508 100644 --- a/src/core/chuck_dl.h +++ b/src/core/chuck_dl.h @@ -224,7 +224,9 @@ typedef const Chuck_DL_Api::Api *CK_DL_API; // macro for defining ChucK DLL export uana tock functions // example: CK_DLL_TOCK(foo) #define CK_DLL_TOCK(name) CK_DLL_EXPORT(t_CKBOOL) name( Chuck_Object * SELF, Chuck_UAna * UANA, Chuck_UAnaBlobProxy * BLOB, CK_DL_API API ) - +// macro for defining Chuck DLL export shreds watcher functions +// example: CK_DLL_SHREDS_WATCHER(foo) +#define CK_DLL_SHREDS_WATCHER(name) CK_DLL_EXPORT(void) name( Chuck_VM_Shred * SHRED, t_CKINT CODE, t_CKINT PARAM, Chuck_VM * VM, void * BINDLE ) // macros for DLL exports // example: DLL_QUERY query( Chuck_DL_Query * QUERY ) @@ -269,6 +271,8 @@ typedef t_CKBOOL (CK_DLL_CALL * f_tock)( Chuck_Object * SELF, Chuck_UAna * UANA, typedef t_CKBOOL (CK_DLL_CALL * f_mainthreadhook)( void * bindle ); // "main thread" quit (stop running hook) typedef t_CKBOOL (CK_DLL_CALL * f_mainthreadquit)( void * bindle ); +// shreds watcher callback +typedef t_CKBOOL (CK_DLL_CALL * f_shreds_watcher)( Chuck_VM_Shred * SHRED, t_CKINT CODE, t_CKINT PARAM, Chuck_VM * VM, void * BINDLE ); } @@ -326,6 +330,10 @@ typedef void (CK_DLL_CALL * f_add_ugen_funcf_auto_num_channels)( Chuck_DL_Query typedef t_CKBOOL (CK_DLL_CALL * f_end_class)( Chuck_DL_Query * query ); // create main thread hook- used for executing a "hook" function in the main thread of a primary chuck instance typedef Chuck_DL_MainThreadHook * (CK_DLL_CALL * f_create_main_thread_hook)( Chuck_DL_Query * query, f_mainthreadhook hook, f_mainthreadquit quit, void * bindle ); +// register a callback function to receive notification from the VM about shreds (add, remove, etc.) +typedef void (CK_DLL_CALL * f_register_shreds_watcher)( Chuck_DL_Query * query, f_shreds_watcher cb, t_CKUINT options, void * bindle ); +// unegister a shreds notification callback +typedef void (CK_DLL_CALL * f_unregister_shreds_watcher)( Chuck_DL_Query * query, f_shreds_watcher cb ); // documentation // set current class documentation @@ -336,8 +344,19 @@ typedef t_CKBOOL (CK_DLL_CALL * f_add_example)( Chuck_DL_Query * query, const ch typedef t_CKBOOL (CK_DLL_CALL * f_doc_func)( Chuck_DL_Query * query, const char * doc ); // set last mvar documentation typedef t_CKBOOL (CK_DLL_CALL * f_doc_var)( Chuck_DL_Query * query, const char * doc ); -} +// shreds watcher flags; meant to bitwise-OR together in options +// these will also be passed back to the callback... +typedef enum { + CKVM_SHREDS_WATCH_NONE = 0, + CKVM_SHREDS_WATCH_SPORK = 1, + CKVM_SHREDS_WATCH_REMOVE = 2, + CKVM_SHREDS_WATCH_SUSPEND = 4, + CKVM_SHREDS_WATCH_ACTIVATE = 8, + CKVM_SHREDS_WATCH_ALL = 0x7fffffff +} ckvmShredsWatcherFlag; + +} // end extern "C" @@ -413,15 +432,26 @@ struct Chuck_DL_Query // re-added 1.4.0.1 f_create_main_thread_hook create_main_thread_hook; - // DL API reference | 1.5.1.4 - CK_DL_API m_api; + // add binary operator overload; args included | 1.5.1.4 (ge & andrew) + f_add_op_overload_binary add_op_overload_binary; + // add unary (prefix) operator overload; arg included + f_add_op_overload_prefix add_op_overload_prefix; + // add unary (postfix) operator overload; arg included + f_add_op_overload_postfix add_op_overload_postfix; + // register shred notifcations | 1.5.1.4 (ge & andrew) + f_register_shreds_watcher register_shreds_watcher; + // un-register shred notifcations | 1.5.1.4 (ge & andrew) + f_unregister_shreds_watcher unregister_shreds_watcher; + +public: + //------------------------------------------------------------------------- // NOTE: everything below std::anything cannot be reliably accessed // by offset between dynamic modules, since std::anything could be variable // size -- put everything need to be accessed across modules above here! // discovered by the vigilant and forever traumatized Jack Atherton, // fixed during REFACTOR-2017; warning by the guilt-ridden Ge Wang - + //------------------------------------------------------------------------- // dll Chuck_DLL * dll_ref; // reserved @@ -447,12 +477,8 @@ struct Chuck_DL_Query // flag any error encountered during the query | 1.5.0.5 (ge) added t_CKBOOL errorEncountered; - // add binary operator overload; args included | 1.5.1.4 (ge) - f_add_op_overload_binary add_op_overload_binary; - // add unary (prefix) operator overload; arg included - f_add_op_overload_prefix add_op_overload_prefix; - // add unary (postfix) operator overload; arg included - f_add_op_overload_postfix add_op_overload_postfix; + // DL API reference | 1.5.1.4 + CK_DL_API m_api; // collection of operator overloads std::vector op_overloads; diff --git a/src/core/chuck_vm.cpp b/src/core/chuck_vm.cpp index 79687a84d..b3c2f8aa9 100644 --- a/src/core/chuck_vm.cpp +++ b/src/core/chuck_vm.cpp @@ -1225,6 +1225,9 @@ Chuck_VM_Shred * Chuck_VM::spork( Chuck_VM_Shred * shred ) // count m_num_shreds++; + // notify watcher | 1.5.1.4 + notify_watchers( CKVM_SHREDS_WATCH_SPORK, shred, m_shreds_watchers_spork ); + return shred; } @@ -1372,6 +1375,31 @@ t_CKBOOL Chuck_VM::abort_current_shred() +//----------------------------------------------------------------------------- +// name: notify_watchers() +// desc: notify watchers for a particular subscription | 1.5.1.4 +//----------------------------------------------------------------------------- +void Chuck_VM::notify_watchers( ckvmShredsWatcherFlag which, + Chuck_VM_Shred * shred, + list & v ) +{ + // the function to call eventually + f_shreds_watcher f = NULL; + // iterator + list::iterator it; + // iterate + for( it = v.begin(); it != v.end(); it++ ) + { + // the function + f = (*it).cb; + // call it with user data + f( shred, which, 0, this, (*it).userdata ); + } +} + + + + //----------------------------------------------------------------------------- // name: dump_shred() // desc: place a shred into the "dump" to be later released @@ -1387,6 +1415,10 @@ void Chuck_VM::dump_shred( Chuck_VM_Shred * shred ) shred->is_running = FALSE; shred->is_done = TRUE; shred->is_dumped = TRUE; + + // before we reset the shred ID, notify watchers + notify_watchers( CKVM_SHREDS_WATCH_REMOVE, shred, m_shreds_watchers_remove ); + // TODO: cool? shred->xid = 0; // inc @@ -1418,6 +1450,63 @@ void Chuck_VM::release_dump( ) +//----------------------------------------------------------------------------- +// helper function +//----------------------------------------------------------------------------- +static void ckvm_process_watcher( t_CKBOOL add, list & v, + Chuck_VM_Shreds_Watcher & watcher ) +{ + // ensure no duplicates + list::iterator it = std::find( v.begin(), v.end(), watcher ); + + // add or remove + if( add ) + { + // if not found, add + if( it == v.end() ) v.push_back( watcher ); + } + else if( it != v.end() ) + { + // erase it + v.erase( it ); + } +} + + + + +//----------------------------------------------------------------------------- +// name: subscribe_watcher() | 1.5.1.4 +// desc: subscribe shreds watcher callback +//----------------------------------------------------------------------------- +void Chuck_VM::subscribe_watcher( f_shreds_watcher cb, t_CKUINT options, void * data ) +{ + // check + if( !cb ) return; + // watcher bundle + Chuck_VM_Shreds_Watcher w( cb, data ); + // check options and subscribe the watcher + ckvm_process_watcher( options & CKVM_SHREDS_WATCH_SPORK, m_shreds_watchers_spork, w ); + ckvm_process_watcher( options & CKVM_SHREDS_WATCH_REMOVE, m_shreds_watchers_remove, w ); + ckvm_process_watcher( options & CKVM_SHREDS_WATCH_SUSPEND, m_shreds_watchers_suspend, w ); + ckvm_process_watcher( options & CKVM_SHREDS_WATCH_ACTIVATE, m_shreds_watchers_activate, w ); +} + + + + +//----------------------------------------------------------------------------- +// name: remove_watcher() | 1.5.1.4 +// desc: remove shreds watcher callback +//----------------------------------------------------------------------------- +void Chuck_VM::remove_watcher( f_shreds_watcher cb ) +{ + subscribe_watcher( cb, CKVM_SHREDS_WATCH_NONE ); +} + + + + //----------------------------------------------------------------------------- // name: Chuck_VM_Stack() // desc: constructor diff --git a/src/core/chuck_vm.h b/src/core/chuck_vm.h index 0c24e2ca1..aa56f80c5 100644 --- a/src/core/chuck_vm.h +++ b/src/core/chuck_vm.h @@ -293,6 +293,30 @@ struct Chuck_VM_Shred : public Chuck_Object +//----------------------------------------------------------------------------- +// name: struct Chuck_VM_Shreds_Watcher +// desc: ChucK virtual machine +//----------------------------------------------------------------------------- +struct Chuck_VM_Shreds_Watcher +{ + // function pointer to call + f_shreds_watcher cb; + // user data + void * userdata; + + // constructor + Chuck_VM_Shreds_Watcher( f_shreds_watcher f = NULL, void * data = NULL ) : cb(f), userdata(data) { } + // copy constructor + Chuck_VM_Shreds_Watcher( const Chuck_VM_Shreds_Watcher & other ) + : cb(other.cb), userdata(other.userdata) { } + // == + bool operator ==( const Chuck_VM_Shreds_Watcher & other ) + { return this->cb == other.cb; } +}; + + + + //----------------------------------------------------------------------------- // name: struct Chuck_VM_Shred_Status // desc: status pertaining to a single shred @@ -582,6 +606,15 @@ struct Chuck_VM : Chuck_Object // 1.4.1.0 (jack): get associated globals manager Chuck_Globals_Manager * globals_manager() const { return m_globals_manager; } +public: + // subscribe shreds watcher callback | 1.5.1.4 + void subscribe_watcher( f_shreds_watcher cb, t_CKUINT options, void * data = NULL ); + // notify watchers | 1.5.1.4 + void notify_watchers( ckvmShredsWatcherFlag which, Chuck_VM_Shred * shred, + std::list & v ); + // remove shreds watcher callback | 1.5.1.4 + void remove_watcher( f_shreds_watcher cb ); + //----------------------------------------------------------------------------- // data //----------------------------------------------------------------------------- @@ -651,6 +684,13 @@ struct Chuck_VM : Chuck_Object protected: // 1.4.1.0 (jack): manager for global variables Chuck_Globals_Manager * m_globals_manager; + +protected: + // 1.5.1.4 (ge & andrew) shreds watchers + std::list m_shreds_watchers_spork; + std::list m_shreds_watchers_remove; + std::list m_shreds_watchers_suspend; + std::list m_shreds_watchers_activate; }; From f84171922be91cb8e65414d93e368f084854e385 Mon Sep 17 00:00:00 2001 From: Ge Wang Date: Mon, 2 Oct 2023 14:13:38 -0700 Subject: [PATCH 02/26] support calling language-side member functions from c++ --- examples/deep/ks-chord.ck | 2 +- src/core/chuck_def.h | 15 +- src/core/chuck_dl.cpp | 44 +++- src/core/chuck_dl.h | 62 +++++- src/core/chuck_emit.cpp | 30 +-- src/core/chuck_emit.h | 2 +- src/core/chuck_instr.cpp | 74 +++++-- src/core/chuck_instr.h | 54 +++-- src/core/chuck_oo.cpp | 17 +- src/core/chuck_parse.cpp | 2 +- src/core/chuck_type.cpp | 84 ++++++- src/core/chuck_type.h | 18 +- src/core/chuck_vm.cpp | 452 ++++++++++++++++++++++++++++++++++++++ src/core/chuck_vm.h | 64 +++++- src/core/ugen_xxx.cpp | 6 +- src/core/ulib_machine.cpp | 69 ++++++ 16 files changed, 908 insertions(+), 87 deletions(-) diff --git a/examples/deep/ks-chord.ck b/examples/deep/ks-chord.ck index 0fbdeed95..d80265365 100644 --- a/examples/deep/ks-chord.ck +++ b/examples/deep/ks-chord.ck @@ -116,7 +116,7 @@ class KSChord extends Chugraph } // tune 4 objects - fun float tune( float pitch1, float pitch2, float pitch3, float pitch4 ) + fun void tune( float pitch1, float pitch2, float pitch3, float pitch4 ) { pitch1 => chordArray[0].tune; pitch2 => chordArray[1].tune; diff --git a/src/core/chuck_def.h b/src/core/chuck_def.h index aa57c4d7f..82d26f5f5 100644 --- a/src/core/chuck_def.h +++ b/src/core/chuck_def.h @@ -109,12 +109,15 @@ typedef struct { t_CKUINT N ; t_CKFLOAT * values ; } t_CKVECTOR; // kinds (added 1.3.1.0 to faciliate 64-bit support) // to differentiate in case int and float have same size -#define kindof_VOID 0 -#define kindof_INT 1 -#define kindof_FLOAT 2 -#define kindof_COMPLEX 3 -#define kindof_VEC3 4 -#define kindof_VEC4 5 +enum te_KindOf +{ + kindof_VOID = 0, + kindof_INT = 1, + kindof_FLOAT = 2, + kindof_COMPLEX = 3, + kindof_VEC3 = 4, + kindof_VEC4 = 5 +}; typedef char * c_str; typedef const char * c_constr; diff --git a/src/core/chuck_dl.cpp b/src/core/chuck_dl.cpp index 808ecc5a7..2e9d47e61 100644 --- a/src/core/chuck_dl.cpp +++ b/src/core/chuck_dl.cpp @@ -1833,10 +1833,11 @@ array4_get_key(ck_array4_get_key) //----------------------------------------------------------------------------- -// name: ck_invoke_mfun_native() -// desc: directly call a chuck member function's native implementation +// name: ck_invoke_mfun() +// desc: directly call a chuck member function +// (supports both native (c++) and user (chuck) //----------------------------------------------------------------------------- -Chuck_DL_Return ck_invoke_mfun_native( Chuck_Object * obj, t_CKUINT func_vt_offset, Chuck_VM * vm, Chuck_VM_Shred * shred, void * ARGS ) +Chuck_DL_Return ck_invoke_mfun( Chuck_Object * obj, t_CKUINT func_vt_offset, Chuck_VM * vm, Chuck_VM_Shred * caller_shred, Chuck_DL_Arg * args_list, t_CKUINT numArgs ) { Chuck_DL_Return RETURN; // check objt @@ -1849,16 +1850,36 @@ Chuck_DL_Return ck_invoke_mfun_native( Chuck_Object * obj, t_CKUINT func_vt_offs } // get the member function - f_mfun f = (f_mfun)obj->vtable->funcs[func_vt_offset]->code->native_func; - // verify bounds - if( !f ) + Chuck_Func * func = obj->vtable->funcs[func_vt_offset]; + // get the code for the function + Chuck_VM_Code * code = func->code; + // check whether native or user + if( code->native_func ) { - EM_error3( "(internal error) ck_invoke_mfun() cannot find native func to call..." ); - return RETURN; + // native func (defined in c++) + f_mfun f = (f_mfun)code->native_func; + // pack the args_list into memory + func->pack_cache( args_list, numArgs ); + // call the function | added 1.3.0.0: the DL API instance + f( obj, func->args_cache, &RETURN, vm, caller_shred, Chuck_DL_Api::Api::instance() ); + } + else + { + // user func (defined in chuck) + // attach invoker, if needed + if( !func->setup_invoker(func_vt_offset, vm, caller_shred ) ) + { + // error + EM_error3( "ck_invoke_mfun() cannot set up invoker for: %s", func->signature(FALSE,TRUE).c_str() ); + return RETURN; + } + // pack the args_list into vector + vector args_vector; + // iterate over c-style array + for( t_CKUINT i = 0; i < numArgs; i++ ) args_vector.push_back(args_list[i]); + // invoke the invoker + func->invoker_mfun->invoke( obj, args_vector ); } - - // call the function | added 1.3.0.0: the DL API instance - f( obj, ARGS, &RETURN, vm, shred, Chuck_DL_Api::Api::instance() ); // return it return RETURN; @@ -1867,6 +1888,7 @@ Chuck_DL_Return ck_invoke_mfun_native( Chuck_Object * obj, t_CKUINT func_vt_offs + //----------------------------------------------------------------------------- // windows translation //----------------------------------------------------------------------------- diff --git a/src/core/chuck_dl.h b/src/core/chuck_dl.h index 3f6c99508..7512bec5b 100644 --- a/src/core/chuck_dl.h +++ b/src/core/chuck_dl.h @@ -360,15 +360,6 @@ typedef enum { -//----------------------------------------------------------------------------- -// invoking chuck functions from c++ -//----------------------------------------------------------------------------- -// directly invoke a chuck member function's native implementation from c++ -// using object + vtable offset -Chuck_DL_Return ck_invoke_mfun_native( Chuck_Object * obj, t_CKUINT func_vt_offset, - Chuck_VM * vm, Chuck_VM_Shred * shred, void * ARGS ); - - //----------------------------------------------------------------------------- @@ -656,7 +647,6 @@ Chuck_DL_Value * make_new_svar( const char * t, const char * n, t_CKBOOL c, void - //------------------------------------------------------------------------------ // name: union Chuck_DL_Return // desc: dynamic link return function return struct @@ -681,6 +671,40 @@ union Chuck_DL_Return +//------------------------------------------------------------------------------ +// name: struct Chuck_DL_Arg +// desc: import / dynamic link function argument | 1.5.1.4 +//------------------------------------------------------------------------------ +struct Chuck_DL_Arg +{ + // which kind of data (e.g., int and object * are both kinds of ints) + te_KindOf kind; + // the data in a union; re-using DL_Return for this + Chuck_DL_Return value; + + // constructor + Chuck_DL_Arg() { kind = kindof_VOID; } + // size in bytes + t_CKUINT sizeInBytes() + { + // check data kind + switch( kind ) + { + 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_VEC4: return sz_VEC4; + case kindof_VOID: return sz_VOID; + } + // unhandled + return 0; + } +}; + + + + //----------------------------------------------------------------------------- // name: struct Chuck_DLL // desc: dynamic link library @@ -763,7 +787,23 @@ struct Chuck_DL_MainThreadHook }; -/* API to ChucK's innards */ + + +//----------------------------------------------------------------------------- +// invoking chuck functions from c++ +//----------------------------------------------------------------------------- +// directly invoke a chuck member function's native implementation from c++ +// using object + vtable offset | 1.5.1.4 (ge & andrew) +Chuck_DL_Return ck_invoke_mfun( Chuck_Object * obj, t_CKUINT func_vt_offset, + Chuck_VM * vm, Chuck_VM_Shred * shred, + Chuck_DL_Arg * ARGS, t_CKUINT numArgs ); + + + + +//----------------------------------------------------------------------------- +// dynamic linking callable API to ChucK's innards +//----------------------------------------------------------------------------- namespace Chuck_DL_Api { typedef void * Object; diff --git a/src/core/chuck_emit.cpp b/src/core/chuck_emit.cpp index f413bbcd4..ae6d284b9 100644 --- a/src/core/chuck_emit.cpp +++ b/src/core/chuck_emit.cpp @@ -497,24 +497,24 @@ t_CKBOOL emit_engine_emit_stmt( Chuck_Emitter * emit, a_Stmt stmt, t_CKBOOL pop { // (added 1.3.1.0 -- multiply by type size; #64-bit) // (fixed 1.3.1.2 -- uh... decl should also be int-sized, so changed to INT/WORD) - emit->append( new Chuck_Instr_Reg_Pop_Word4( exp->decl.num_var_decls * sz_INT / sz_WORD ) ); + emit->append( new Chuck_Instr_Reg_Pop_WordsMulti( exp->decl.num_var_decls * sz_INT / sz_WORD ) ); } else if( exp->type->size == sz_INT && iskindofint(emit->env, exp->type) ) // ISSUE: 64-bit (fixed 1.3.1.0) { // is an object left on the stack for the stmt if( exp->s_type == ae_exp_func_call && isobj(emit->env, exp->type) ) - { emit->append( new Chuck_Instr_Release_Object3_Pop_Word ); } + { emit->append( new Chuck_Instr_Release_Object3_Pop_Int ); } else // not an object - { emit->append( new Chuck_Instr_Reg_Pop_Word ); } + { emit->append( new Chuck_Instr_Reg_Pop_Int ); } } else if( exp->type->size == sz_FLOAT ) // ISSUE: 64-bit (fixed 1.3.1.0) - emit->append( new Chuck_Instr_Reg_Pop_Word2 ); + 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_Word3 ); + emit->append( new Chuck_Instr_Reg_Pop_Complex ); else if( exp->type->size == sz_VEC3 ) // ge: added 1.3.5.3 - emit->append( new Chuck_Instr_Reg_Pop_Word4(sz_VEC3/sz_WORD) ); + 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 - emit->append( new Chuck_Instr_Reg_Pop_Word4(sz_VEC4/sz_WORD) ); + emit->append( new Chuck_Instr_Reg_Pop_WordsMulti(sz_VEC4/sz_WORD) ); else { EM_error2( exp->where, @@ -871,8 +871,8 @@ t_CKBOOL emit_engine_emit_for( Chuck_Emitter * emit, a_Stmt_For stmt ) e = e->next; } - // pop (changed to Chuck_Instr_Reg_Pop_Word4 in 1.3.1.0) - if( num_words > 0 ) emit->append( new Chuck_Instr_Reg_Pop_Word4( num_words ) ); + // pop (changed to Chuck_Instr_Reg_Pop_WordsMulti in 1.3.1.0) + if( num_words > 0 ) emit->append( new Chuck_Instr_Reg_Pop_WordsMulti( num_words ) ); } // go back to do check the condition @@ -1871,7 +1871,7 @@ t_CKBOOL emit_engine_emit_exp_binary( Chuck_Emitter * emit, a_Exp_Binary binary emit->append( op = new Chuck_Instr_Branch_Eq_int( 0 ) ); // pop default result - emit->append( new Chuck_Instr_Reg_Pop_Word ); + emit->append( new Chuck_Instr_Reg_Pop_Int ); // result of whole expression is now result of rhs right = emit_engine_emit_exp( emit, binary->rhs ); @@ -1903,7 +1903,7 @@ t_CKBOOL emit_engine_emit_exp_binary( Chuck_Emitter * emit, a_Exp_Binary binary emit->append( op = new Chuck_Instr_Branch_Neq_int( 0 ) ); // pop default result - emit->append( new Chuck_Instr_Reg_Pop_Word ); + emit->append( new Chuck_Instr_Reg_Pop_Int ); // result of whole expression is now result of rhs right = emit_engine_emit_exp( emit, binary->rhs ); @@ -3007,7 +3007,7 @@ t_CKBOOL emit_engine_emit_op_chuck( Chuck_Emitter * emit, a_Exp lhs, a_Exp rhs, rhs->s_type == ae_exp_primary && !strcmp( "now", S_name(rhs->primary.var) ) ) { // pop now - emit->append( new Chuck_Instr_Reg_Pop_Word2 ); + emit->append( new Chuck_Instr_Reg_Pop_Float ); emit->append( instr = new Chuck_Instr_Event_Wait ); instr->set_linepos( lhs->line ); @@ -3163,7 +3163,7 @@ t_CKBOOL emit_engine_emit_op_at_chuck( Chuck_Emitter * emit, a_Exp lhs, a_Exp rh if( rhs->s_type == ae_exp_primary && !strcmp( "now", S_name(rhs->primary.var) ) ) { // pop the now addr - emit->append( new Chuck_Instr_Reg_Pop_Word2 ); + emit->append( new Chuck_Instr_Reg_Pop_Float ); // advance time Chuck_Instr * instr = NULL; emit->append( instr = new Chuck_Instr_Time_Advance ); @@ -5505,9 +5505,9 @@ t_CKBOOL emit_engine_emit_spork( Chuck_Emitter * emit, a_Exp_Func_Call exp ) { // is an object? if( isobj( emit->env, exp->ret_type) ) - { emit->append( new Chuck_Instr_Release_Object3_Pop_Word ); } + { emit->append( new Chuck_Instr_Release_Object3_Pop_Int ); } else // not an object - { emit->append( new Chuck_Instr_Reg_Pop_Word ); } + { emit->append( new Chuck_Instr_Reg_Pop_Int ); } } // emit the function call, with special flag diff --git a/src/core/chuck_emit.h b/src/core/chuck_emit.h index 8d50eede9..a058f338e 100644 --- a/src/core/chuck_emit.h +++ b/src/core/chuck_emit.h @@ -57,7 +57,7 @@ struct Chuck_Code public: // name std::string name; - // stack depth + // stack depth (in bytes) t_CKUINT stack_depth; // need this t_CKBOOL need_this; diff --git a/src/core/chuck_instr.cpp b/src/core/chuck_instr.cpp index 9e65dad7a..d75378b8b 100644 --- a/src/core/chuck_instr.cpp +++ b/src/core/chuck_instr.cpp @@ -2554,7 +2554,7 @@ void Chuck_Instr_Reg_Pop_Mem::execute( Chuck_VM * vm, Chuck_VM_Shred * shred ) // name: execute() // desc: ... //----------------------------------------------------------------------------- -void Chuck_Instr_Reg_Pop_Word::execute( Chuck_VM * vm, Chuck_VM_Shred * shred ) +void Chuck_Instr_Reg_Pop_Int::execute( Chuck_VM * vm, Chuck_VM_Shred * shred ) { t_CKUINT *& reg_sp = (t_CKUINT *&)shred->reg->sp; @@ -2569,7 +2569,7 @@ void Chuck_Instr_Reg_Pop_Word::execute( Chuck_VM * vm, Chuck_VM_Shred * shred ) // name: execute() // desc: ... //----------------------------------------------------------------------------- -void Chuck_Instr_Reg_Pop_Word2::execute( Chuck_VM * vm, Chuck_VM_Shred * shred ) +void Chuck_Instr_Reg_Pop_Float::execute( Chuck_VM * vm, Chuck_VM_Shred * shred ) { t_CKFLOAT *& reg_sp = (t_CKFLOAT *&)shred->reg->sp; @@ -2584,7 +2584,7 @@ void Chuck_Instr_Reg_Pop_Word2::execute( Chuck_VM * vm, Chuck_VM_Shred * shred ) // name: execute() // desc: ... //----------------------------------------------------------------------------- -void Chuck_Instr_Reg_Pop_Word3::execute( Chuck_VM * vm, Chuck_VM_Shred * shred ) +void Chuck_Instr_Reg_Pop_Complex::execute( Chuck_VM * vm, Chuck_VM_Shred * shred ) { t_CKCOMPLEX *& reg_sp = (t_CKCOMPLEX *&)shred->reg->sp; @@ -2595,11 +2595,41 @@ void Chuck_Instr_Reg_Pop_Word3::execute( Chuck_VM * vm, Chuck_VM_Shred * shred ) +//----------------------------------------------------------------------------- +// name: execute() +// desc: pop a vec3 value from reg stack +//----------------------------------------------------------------------------- +void Chuck_Instr_Reg_Pop_Vec3::execute( Chuck_VM * vm, Chuck_VM_Shred * shred ) +{ + t_CKVEC3 *& reg_sp = (t_CKVEC3 *&)shred->reg->sp; + + // pop word from reg stack + pop_( reg_sp, 1 ); +} + + + + +//----------------------------------------------------------------------------- +// name: execute() +// desc: pop a vec4 value from reg stack +//----------------------------------------------------------------------------- +void Chuck_Instr_Reg_Pop_Vec4::execute( Chuck_VM * vm, Chuck_VM_Shred * shred ) +{ + t_CKVEC4 *& reg_sp = (t_CKVEC4 *&)shred->reg->sp; + + // pop word from reg stack + pop_( reg_sp, 1 ); +} + + + + //----------------------------------------------------------------------------- // name: execute() // desc: ... //----------------------------------------------------------------------------- -void Chuck_Instr_Reg_Pop_Word4::execute( Chuck_VM * vm, Chuck_VM_Shred * shred ) +void Chuck_Instr_Reg_Pop_WordsMulti::execute( Chuck_VM * vm, Chuck_VM_Shred * shred ) { t_CKBYTE *& reg_sp = (t_CKBYTE *&)shred->reg->sp; @@ -4637,7 +4667,7 @@ void Chuck_Instr_Release_Object2::execute( Chuck_VM * vm, Chuck_VM_Shred * shred // FYI the return value is conveyed on the reg stack; this undoes // the addref before the return; see Chuck_Instr_Reg_AddRef_Object3 //----------------------------------------------------------------------------- -void Chuck_Instr_Release_Object3_Pop_Word::execute( Chuck_VM * vm, Chuck_VM_Shred * shred ) +void Chuck_Instr_Release_Object3_Pop_Int::execute( Chuck_VM * vm, Chuck_VM_Shred * shred ) { t_CKUINT *& reg_sp = (t_CKUINT *&)shred->reg->sp; Chuck_VM_Object * obj = NULL; @@ -4778,7 +4808,7 @@ void Chuck_Instr_Func_Call::execute( Chuck_VM * vm, Chuck_VM_Shred * shred ) // convert to number of int's (was: 4-byte words), extra partial word counts as additional word local_depth = ( local_depth / sz_INT ) + ( local_depth & 0x3 ? 1 : 0 ); // ISSUE: 64-bit (fixed 1.3.1.0) // get the stack depth of the callee function args - t_CKUINT stack_depth = ( func->stack_depth / sz_INT ) + ( func->stack_depth & 0x3 ? 1 : 0 ); // ISSUE: 64-bit (fixed 1.3.1.0) + t_CKUINT stack_depth_ints = ( func->stack_depth / sz_INT ) + ( func->stack_depth & 0x3 ? 1 : 0 ); // ISSUE: 64-bit (fixed 1.3.1.0) // get the previous stack depth - caller function args t_CKUINT prev_stack = ( *(mem_sp-1) / sz_INT ) + ( *(mem_sp-1) & 0x3 ? 1 : 0 ); // ISSUE: 64-bit (fixed 1.3.1.0) @@ -4791,7 +4821,7 @@ void Chuck_Instr_Func_Call::execute( Chuck_VM * vm, Chuck_VM_Shred * shred ) // push the pc push_( mem_sp, (t_CKUINT)(shred->pc + 1) ); // push the stack depth - push_( mem_sp, stack_depth ); + push_( mem_sp, stack_depth_ints ); // set the pc to 0 shred->next_pc = 0; // set the code @@ -4803,37 +4833,37 @@ void Chuck_Instr_Func_Call::execute( Chuck_VM * vm, Chuck_VM_Shred * shred ) if( overflow_( shred->mem ) ) goto error_overflow; // if there are arguments to be passed - if( stack_depth ) + if( stack_depth_ints ) { // pop the arguments, by number of words - pop_( reg_sp, stack_depth ); + pop_( reg_sp, stack_depth_ints ); // make copies (but without modifying actual stack pointers) t_CKUINT * mem_sp2 = (t_CKUINT *)mem_sp; t_CKUINT * reg_sp2 = (t_CKUINT *)reg_sp; // detect would-be overflow | 1.5.1.4 (ge) added - if( would_overflow_( mem_sp2+stack_depth, shred->mem ) ) goto error_overflow; + if( would_overflow_( mem_sp2+stack_depth_ints, shred->mem ) ) goto error_overflow; // need this if( func->need_this ) { // copy this from end of arguments to the front - *mem_sp2++ = *(reg_sp2 + stack_depth - 1); + *mem_sp2++ = *(reg_sp2 + stack_depth_ints - 1); // one less word to copy - stack_depth--; + stack_depth_ints--; } // static inside class | 1.4.1.0 (ge) added else if( func->is_static ) { // copy type from end of arguments to the front - *mem_sp2++ = *(reg_sp2 + stack_depth - 1); + *mem_sp2++ = *(reg_sp2 + stack_depth_ints - 1); // one less word to copy - stack_depth--; + stack_depth_ints--; } // push the arguments - for( t_CKUINT i = 0; i < stack_depth; i++ ) + for( t_CKUINT i = 0; i < stack_depth_ints; i++ ) *mem_sp2++ = *reg_sp2++; } @@ -5391,6 +5421,16 @@ void Chuck_Instr_Time_Advance::execute( Chuck_VM * vm, Chuck_VM_Shred * shred ) // pop word from reg stack pop_( sp, 1 ); + // check for immediate mode exception | 1.5.1.4 (ge) + if( shred->checkImmediatModeException(m_linepos) ) + { + // do something! + shred->is_running = FALSE; + shred->is_done = TRUE; + // bail out + return; + } + // check if( *sp < shred->now ) { @@ -5434,8 +5474,12 @@ void Chuck_Instr_Event_Wait::execute( Chuck_VM * vm, Chuck_VM_Shred * shred ) // check for null if( !event ) goto null_pointer; + // check for immediate mode exception | 1.5.1.4 (ge) added + if( shred->checkImmediatModeException(m_linepos) ) goto done; + // wait event->wait( shred, vm ); + // done return; diff --git a/src/core/chuck_instr.h b/src/core/chuck_instr.h index bc21f6204..c40c84e32 100644 --- a/src/core/chuck_instr.h +++ b/src/core/chuck_instr.h @@ -1900,10 +1900,10 @@ struct Chuck_Instr_Goto : public Chuck_Instr_Branch_Op //----------------------------------------------------------------------------- -// name: struct Chuck_Instr_Reg_Pop_Word -// desc: pop word from reg stack +// name: struct Chuck_Instr_Reg_Pop_Int +// desc: pop an int from reg stack //----------------------------------------------------------------------------- -struct Chuck_Instr_Reg_Pop_Word : public Chuck_Instr +struct Chuck_Instr_Reg_Pop_Int : public Chuck_Instr { public: virtual void execute( Chuck_VM * vm, Chuck_VM_Shred * shred ); @@ -1913,10 +1913,10 @@ struct Chuck_Instr_Reg_Pop_Word : public Chuck_Instr //----------------------------------------------------------------------------- -// name: struct Chuck_Instr_Reg_Pop_Word2 -// desc: pop t_CKFLOAT word from reg stack +// name: struct Chuck_Instr_Reg_Pop_Float +// desc: pop a float value from reg stack //----------------------------------------------------------------------------- -struct Chuck_Instr_Reg_Pop_Word2 : public Chuck_Instr +struct Chuck_Instr_Reg_Pop_Float : public Chuck_Instr { public: virtual void execute( Chuck_VM * vm, Chuck_VM_Shred * shred ); @@ -1926,10 +1926,10 @@ struct Chuck_Instr_Reg_Pop_Word2 : public Chuck_Instr //----------------------------------------------------------------------------- -// name: struct Chuck_Instr_Reg_Pop_Word3 -// desc: pop a complex value from reg stack (change 1.3.1.0) +// name: struct Chuck_Instr_Reg_Pop_Complex +// desc: pop a complex/polar value from reg stack (change 1.3.1.0) //----------------------------------------------------------------------------- -struct Chuck_Instr_Reg_Pop_Word3 : public Chuck_Instr +struct Chuck_Instr_Reg_Pop_Complex : public Chuck_Instr { public: virtual void execute( Chuck_VM * vm, Chuck_VM_Shred * shred ); @@ -1939,13 +1939,39 @@ struct Chuck_Instr_Reg_Pop_Word3 : public Chuck_Instr //----------------------------------------------------------------------------- -// name: struct Chuck_Instr_Reg_Pop_Word4 +// name: struct Chuck_Instr_Reg_Pop_Vec3 +// desc: pop a vec3 value from reg stack | 1.5.1.4 +//----------------------------------------------------------------------------- +struct Chuck_Instr_Reg_Pop_Vec3 : public Chuck_Instr +{ +public: + virtual void execute( Chuck_VM * vm, Chuck_VM_Shred * shred ); +}; + + + + +//----------------------------------------------------------------------------- +// name: struct Chuck_Instr_Reg_Pop_Vec4 +// desc: pop a vec4 value from reg stack | 1.5.1.4 +//----------------------------------------------------------------------------- +struct Chuck_Instr_Reg_Pop_Vec4 : public Chuck_Instr +{ +public: + virtual void execute( Chuck_VM * vm, Chuck_VM_Shred * shred ); +}; + + + + +//----------------------------------------------------------------------------- +// name: struct Chuck_Instr_Reg_Pop_WordsMulti // desc: pop arbitrary num of word from reg stack (added 1.3.1.0) //----------------------------------------------------------------------------- -struct Chuck_Instr_Reg_Pop_Word4 : public Chuck_Instr_Unary_Op +struct Chuck_Instr_Reg_Pop_WordsMulti : public Chuck_Instr_Unary_Op { public: - Chuck_Instr_Reg_Pop_Word4( t_CKUINT num ) { this->set( num ); } + Chuck_Instr_Reg_Pop_WordsMulti( t_CKUINT num ) { this->set( num ); } virtual void execute( Chuck_VM * vm, Chuck_VM_Shred * shred ); }; @@ -3037,11 +3063,11 @@ struct Chuck_Instr_Release_Object2 : public Chuck_Instr_Unary_Op //----------------------------------------------------------------------------- -// name: struct Chuck_Instr_Release_Object3_Pop_Word +// name: struct Chuck_Instr_Release_Object3_Pop_Int // desc: release object reference + pop from reg stack | 1.5.0.0 (ge) added // the variant assumes object pointer directly on stack (not offset) //----------------------------------------------------------------------------- -struct Chuck_Instr_Release_Object3_Pop_Word : public Chuck_Instr +struct Chuck_Instr_Release_Object3_Pop_Int : public Chuck_Instr { public: virtual void execute( Chuck_VM * vm, Chuck_VM_Shred * shred ); diff --git a/src/core/chuck_oo.cpp b/src/core/chuck_oo.cpp index d5e258aee..914dc838b 100644 --- a/src/core/chuck_oo.cpp +++ b/src/core/chuck_oo.cpp @@ -3415,7 +3415,7 @@ void Chuck_Event::wait( Chuck_VM_Shred * shred, Chuck_VM * vm ) // invoke virtual function our_can_wait | 1.5.1.4 // TODO: check this is right shred // TODO: make this work in general case (right only for native_func) - Chuck_DL_Return RETURN = ck_invoke_mfun_native( this, our_can_wait, vm, shred, NULL ); + Chuck_DL_Return RETURN = ck_invoke_mfun( this, our_can_wait, vm, shred, NULL, 0 ); // get the member function // f_mfun canwaitplease = (f_mfun)this->vtable->funcs[our_can_wait]->code->native_func; // added 1.3.0.0: the DL API instance @@ -3448,10 +3448,17 @@ void Chuck_Event::wait( Chuck_VM_Shred * shred, Chuck_VM * vm ) // add shred to shreduler vm->shreduler()->add_blocked( shred ); - // get the virtual function for waiting_on() - f_mfun waiting_on = (f_mfun)this->vtable->funcs[our_waiting_on]->code->native_func; - // call to nofify event that a shred has starting waiting on it - waiting_on( this, NULL, &RETURN, vm, shred, Chuck_DL_Api::Api::instance() ); + // invoke virtual function our_waiting_on | 1.5.1.4 (ge & andrew) + // this is called at the point when a shred has completed the actions + // needed to wait on an Event, and can be notified/broadcasted from + // a different thread + ck_invoke_mfun( this, our_waiting_on, vm, shred, NULL, 0 ); + // TODO: check this is right shred + // TODO: make this work in general case (right only for native_func) + // // get the virtual function for waiting_on() + // f_mfun waiting_on = (f_mfun)this->vtable->funcs[our_waiting_on]->code->native_func; + // // call to nofify event that a shred has starting waiting on it + // waiting_on( this, NULL, &RETURN, vm, shred, Chuck_DL_Api::Api::instance() ); } else // can't wait { diff --git a/src/core/chuck_parse.cpp b/src/core/chuck_parse.cpp index 4622611d0..bf126aa3f 100644 --- a/src/core/chuck_parse.cpp +++ b/src/core/chuck_parse.cpp @@ -665,7 +665,7 @@ string absyn_primary2str( a_Exp_Primary primary ) case ae_primary_array: str = "["+absyn_exp2str(primary->array->exp_list)+"]"; break; case ae_primary_complex: str = "#("+absyn_exp2str(primary->complex->re)+","+absyn_exp2str(primary->complex->im)+")"; break; case ae_primary_polar: str = "%("+absyn_exp2str(primary->polar->mod)+","+absyn_exp2str(primary->polar->phase)+")"; break; - case ae_primary_vec: str = "@("+absyn_exp2str(primary->vec->args)+")"; break; + case ae_primary_vec: str = "@("+absyn_exp2str(primary->vec->args,TRUE)+")"; break; case ae_primary_exp: str = absyn_exp2str(primary->exp); break; case ae_primary_hack: str = "<<< " + absyn_exp2str(primary->exp) + " >>>"; break; case ae_primary_nil: str = "(void)"; break; diff --git a/src/core/chuck_type.cpp b/src/core/chuck_type.cpp index 85e6fee07..5134b255d 100644 --- a/src/core/chuck_type.cpp +++ b/src/core/chuck_type.cpp @@ -5620,10 +5620,10 @@ t_CKBOOL iskindofint( Chuck_Env * env, Chuck_Type * type ) // added 1.3.1.0 { return isa( type, env->ckt_int ) || isobj( env, type ); } t_CKBOOL isvoid( Chuck_Env * env, Chuck_Type * type ) // added 1.5.0.0 { return isa( type, env->ckt_void ); } -t_CKUINT getkindof( Chuck_Env * env, Chuck_Type * type ) // added 1.3.1.0 +te_KindOf getkindof( Chuck_Env * env, Chuck_Type * type ) // added 1.3.1.0 { // the kind (1.3.1.0) - t_CKUINT kind = kindof_VOID; + te_KindOf kind = kindof_VOID; // check size if( type->size == sz_INT && iskindofint(env, type) ) @@ -8369,6 +8369,13 @@ Chuck_Func::~Chuck_Func() CK_SAFE_RELEASE( this->code ); CK_SAFE_RELEASE( this->value_ref ); + // release args cache | 1.5.1.4 + CK_SAFE_DELETE_ARRAY( this->args_cache ); + this->args_cache_size = 0; + + // release invoker(s) | 1.5.1.4 + CK_SAFE_DELETE( this->invoker_mfun ); + // TODO: check if more references to release, e.g., up and next? } @@ -8538,6 +8545,79 @@ void Chuck_Func::funcdef_cleanup() +//----------------------------------------------------------------------------- +// name: pack_cache() | 1.5.1.4 +// desc: pack c-style array of DL_Args into args cache +//----------------------------------------------------------------------------- +t_CKBOOL Chuck_Func::pack_cache( Chuck_DL_Arg * dlargs, t_CKUINT numArgs ) +{ + // data size in bytes + t_CKUINT size = 0; + // count the number of bytes needed + for( t_CKUINT i = 0; i < numArgs; i++ ) + size += dlargs[i].sizeInBytes(); + // (re)allocate if needed + if( size > args_cache_size ) + { + CK_SAFE_DELETE_ARRAY( args_cache ); + args_cache = new t_CKBYTE[size]; + if( !args_cache ) { + EM_error3( "error allocating argument cache of size '%lu'", size ); + return FALSE; + } + memset( args_cache, 0, size ); + args_cache_size = size; + } + + // pointer for copying + t_CKBYTE * here = args_cache; + // iterate and copy + for( t_CKUINT j = 0; j < numArgs; j++ ) + { + switch( dlargs[j].kind ) + { + 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_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; + + // shouldn't get here + case kindof_VOID: + EM_error3( "(internal error) Chuck_Func.pack_cache() void argument encountered..." ); return FALSE; + } + } + + // done + return TRUE; +} + + + + +//----------------------------------------------------------------------------- +// name: setup_invoker() | 1.5.1.4 +// desc: setup invoker for this fun (for calling chuck function from c++) +//----------------------------------------------------------------------------- +t_CKBOOL Chuck_Func::setup_invoker( t_CKUINT func_vt_offset, Chuck_VM * vm, Chuck_VM_Shred * shred ) +{ + // if already setup + if( invoker_mfun != NULL ) return TRUE; + // check if member function + if( !this->is_member ) return FALSE; + // check if needed + if( this->code->native_func ) return FALSE; + // instantiate + invoker_mfun = new Chuck_VM_MFunInvoker; + // set up invoker + invoker_mfun->setup( this, func_vt_offset, vm, shred ); + // done + return TRUE; +} + + + + //----------------------------------------------------------------------------- // name: Chuck_Value_Dependency() // desc: constructor diff --git a/src/core/chuck_type.h b/src/core/chuck_type.h index 7912c5925..1889e1181 100644 --- a/src/core/chuck_type.h +++ b/src/core/chuck_type.h @@ -289,6 +289,7 @@ struct Chuck_Func; struct Chuck_Multi; struct Chuck_VM; struct Chuck_VM_Code; +struct Chuck_VM_MFunInvoker; struct Chuck_DLL; // operator loading structs | 1.5.1.4 struct Chuck_Op_Registry; @@ -1105,6 +1106,18 @@ struct Chuck_Func : public Chuck_VM_Object // documentation std::string doc; +public: + // pack c-style array of DL_Args into args cache + t_CKBOOL pack_cache( Chuck_DL_Arg * dlargs, t_CKUINT numArgs ); + // args cache (used by c++ to chuck function calls) | 1.5.1.4 + t_CKBYTE * args_cache; + // size of args cache + t_CKUINT args_cache_size; + // setup invoker for this fun (for calling chuck function from c++) + t_CKBOOL setup_invoker( t_CKUINT vtable_offet, Chuck_VM * vm, Chuck_VM_Shred * shred ); + // associate mfun invoker (if applicable) + Chuck_VM_MFunInvoker * invoker_mfun; + protected: // AST func def from parser | 1.5.0.5 (ge) moved to protected // access through funcdef_*() functions @@ -1137,6 +1150,9 @@ struct Chuck_Func : public Chuck_VM_Object /*dl_code = NULL;*/ next = NULL; up = NULL; + args_cache = NULL; + args_cache_size = 0; + invoker_mfun = NULL; } // destructor @@ -1189,7 +1205,7 @@ t_CKBOOL isobj( Chuck_Env * env, Chuck_Type * type ); t_CKBOOL isfunc( Chuck_Env * env, Chuck_Type * type ); t_CKBOOL isvoid( Chuck_Env * env, Chuck_Type * type ); t_CKBOOL iskindofint( Chuck_Env * env, Chuck_Type * type ); // added 1.3.1.0: this includes int + pointers -t_CKUINT getkindof( Chuck_Env * env, Chuck_Type * type ); // added 1.3.1.0: to get the kindof a type +te_KindOf getkindof( Chuck_Env * env, Chuck_Type * type ); // added 1.3.1.0: to get the kindof a type //----------------------------------------------------------------------------- diff --git a/src/core/chuck_vm.cpp b/src/core/chuck_vm.cpp index b3c2f8aa9..c96833edc 100644 --- a/src/core/chuck_vm.cpp +++ b/src/core/chuck_vm.cpp @@ -1686,6 +1686,10 @@ Chuck_VM_Shred::Chuck_VM_Shred() childSetMemSize( 0 ); childSetRegSize( 0 ); + // immediate mode | 1.5.1.4 + is_immediate_mode = FALSE; + is_immediate_mode_violation = FALSE; + #ifndef __DISABLE_SERIAL__ m_serials = NULL; #endif @@ -2099,10 +2103,14 @@ t_CKBOOL Chuck_VM_Shred::yield() // need a VM to yield on if( !this->vm_ref ) return FALSE; + // check for immediate mode exception | 1.5.1.4 (ge) + if( this->checkImmediatModeException() ) return FALSE; + // suspend this shred this->is_running = FALSE; // reshredule this at the current time vm_ref->shreduler()->shredule( this, this->now ); + // done return TRUE; } @@ -2198,6 +2206,52 @@ bool Chuck_VM_Shred::popLoopCounter() +//----------------------------------------------------------------------------- +// name: checkImmediatModeException() | 1.5.1.4 (ge) added +// desc: check for immediate mode exception, if detected print and set state +//----------------------------------------------------------------------------- +t_CKBOOL Chuck_VM_Shred::checkImmediatModeException( t_CKUINT linepos ) +{ + // check for immediate mode + if( this->immediateMode() ) + { + // we have a problem + EM_exception( "ImmediateModeTemporalViolation:" ); + // check linepos + if( linepos ) EM_exception( " |- on line %lu within %s", linepos, this->name.c_str() ); + else EM_exception( " |- within %s", this->name.c_str() ); + // more info + EM_error3( + "\nThis exception is thrown if shred has been placed in IMMEDIATE MODE\n" + "and performs any time/event-related, context-switching operations, including:\n" + " 1) advancing time (including by 0 duration),\n" + " 2) or waiting on an Event,\n" + " 3) or callling `me.yield()` or `Machine.eval()`;\n" + " (the latter implicits yields to runs code on a new shred)." ); + // more info + EM_error3( + "\nIMMEDIATE MODE is set by the ChucK virtual machine in specific cases\n" + "where the programmer is to provide a time-critical callback function\n" + "that is expected to return \"immediately\", i.e., without any shreduling.\n" + "Examples include `tick()` in Chugens and `update()` in GGens." ); + // potential fix + EM_error3( + "\nPotential fix: ensure the function in question has no time/event operations as\n" + "described above, either directly in the function or its function calls.\n" + "(NB `spork ~` and `Machine.add()` can be used in this mode, as these are\n" + "non-context-switching.)"); + // set violation + is_immediate_mode_violation = TRUE; + // report back + return TRUE; + } + + // situation normal + return FALSE; +} + + + //----------------------------------------------------------------------------- // name: Chuck_VM_Shreduler() // desc: constructor @@ -2353,6 +2407,14 @@ t_CKBOOL Chuck_VM_Shreduler::shredule( Chuck_VM_Shred * shred, return FALSE; } + // check for immediate mode and report exception | 1.5.1.4 (ge) + if( shred->checkImmediatModeException() ) + { + // let's not shredule! + return FALSE; + } + + // set wake time shred->wake_time = wake_time; // list empty @@ -3079,6 +3141,396 @@ void Chuck_VM_Status::clear() +//----------------------------------------------------------------------------- +// name: Chuck_VM_MFunInvoker() +// desc: constructor +//----------------------------------------------------------------------------- +Chuck_VM_MFunInvoker::Chuck_VM_MFunInvoker() +{ + // zero + shred = NULL; + instr_pushThis = NULL; + instr_pushReturnVar = NULL; +} + + + + +//----------------------------------------------------------------------------- +// name: ~Chuck_VM_MFunInvoker() +// desc: destructor +//----------------------------------------------------------------------------- +Chuck_VM_MFunInvoker::~Chuck_VM_MFunInvoker() +{ + cleanup(); +} + + + + +//----------------------------------------------------------------------------- +// name: setup() +// desc: setup the invoker for use +//----------------------------------------------------------------------------- +t_CKBOOL Chuck_VM_MFunInvoker::setup( Chuck_Func * func, t_CKUINT func_vt_offset, Chuck_VM * vm, Chuck_VM_Shred * caller ) +{ + // clean up first + if( shred ) cleanup(); + + // a vector of VM instructions + vector instructions; + + // get argument list + a_Arg_List args = func->def()->arg_list; + // argument size in bytes + t_CKUINT args_size_bytes = 0; + // type kind + te_KindOf kind = kindof_VOID; + // iterate over arguments + while( args ) + { + // get size + args_size_bytes += args->type->size; + // get kind + kind = getkindof( vm->env(), args->type ); + + // check kind; allocate instruction (with placeholder values; to be filled when invoked) + switch( kind ) + { + case kindof_INT: + // push value INT + instr_args.push_back( new Chuck_Instr_Reg_Push_Imm(0) ); + break; + + case kindof_FLOAT: + // push value FLOAT + instr_args.push_back( new Chuck_Instr_Reg_Push_Imm2(0) ); + break; + + case kindof_COMPLEX: + // 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) ); + break; + + case kindof_VEC3: + // push value FLOA FLOAT FLOAT + instr_args.push_back( new Chuck_Instr_Reg_Push_Imm2(0) ); + instr_args.push_back( new Chuck_Instr_Reg_Push_Imm2(0) ); + instr_args.push_back( new Chuck_Instr_Reg_Push_Imm2(0) ); + break; + + case kindof_VEC4: + // push value FLOA FLOAT FLOAT FLOAT + instr_args.push_back( new Chuck_Instr_Reg_Push_Imm2(0) ); + instr_args.push_back( new Chuck_Instr_Reg_Push_Imm2(0) ); + instr_args.push_back( new Chuck_Instr_Reg_Push_Imm2(0) ); + instr_args.push_back( new Chuck_Instr_Reg_Push_Imm2(0) ); + break; + + // shouldn't get here + case kindof_VOID: + default: + // error + EM_error3( "(internal error) unhandled argument kind in MFunInvoker.init()" ); + // clean up + for( t_CKUINT i = 0; i < instr_args.size(); i++ ) CK_SAFE_DELETE( instr_args[i] ); + // clear the array + instr_args.clear(); + // error out + return FALSE; + } + + // next arg + args = args->next; + } + // account for 'this', since this is a member function + args_size_bytes += sz_VOIDPTR; + + // push arguments + for( t_CKUINT i = 0; i < instr_args.size(); i++ ) + { + // copy references over + instructions.push_back( instr_args[i] ); + } + // push this (as func arg) -- will set later + instr_pushThis = new Chuck_Instr_Reg_Push_Imm( 0 ); + instructions.push_back( instr_pushThis ); + // reg dup last (push this again) (for member func resolution) + instructions.push_back( new Chuck_Instr_Reg_Dup_Last); + // dot member func + instructions.push_back( new Chuck_Instr_Dot_Member_Func(func_vt_offset) ); + // func to code + instructions.push_back( new Chuck_Instr_Func_To_Code ); + // push stack depth (in bytes) + instructions.push_back( new Chuck_Instr_Reg_Push_Imm(args_size_bytes) ); + // func call + instructions.push_back( new Chuck_Instr_Func_Call()); + + // figure out what to assign based on return type kind + kind = getkindof( vm->env(), func->type() ); + + // if not void + if( kind != kindof_VOID ) + { + // push immediate to copy RETURN + instr_pushReturnVar = new Chuck_Instr_Reg_Push_Imm(0); + instructions.push_back( instr_pushReturnVar ); // 1.3.1.0: changed to t_CKUINT + } + + // check kind; allocate instruction (with placeholder values; to be filled when invoked) + switch( kind ) + { + case kindof_INT: // assign int or object ref + if( isobj(vm->env(), func->type()) ) { + // return type is an Object reference + instructions.push_back( new Chuck_Instr_Assign_Object ); + instructions.push_back( new Chuck_Instr_Release_Object3_Pop_Int ); + } else { + // return type is a primitive int + instructions.push_back( new Chuck_Instr_Assign_Primitive ); + instructions.push_back( new Chuck_Instr_Reg_Pop_Int ); + } + break; + case kindof_FLOAT: // assign float + instructions.push_back( new Chuck_Instr_Assign_Primitive2 ); + instructions.push_back( new Chuck_Instr_Reg_Pop_Float ); + break; + case kindof_COMPLEX: // assign complex / polar + instructions.push_back( new Chuck_Instr_Assign_Primitive4 ); + instructions.push_back( new Chuck_Instr_Reg_Pop_Complex ); + break; + case kindof_VEC3: // assign vec3 + instructions.push_back( new Chuck_Instr_Assign_PrimitiveVec3 ); + instructions.push_back( new Chuck_Instr_Reg_Pop_Vec3 ); + break; + case kindof_VEC4: // assign vec4 + instructions.push_back( new Chuck_Instr_Assign_PrimitiveVec4 ); + instructions.push_back( new Chuck_Instr_Reg_Pop_Vec4 ); + break; + + // shouldn't get here + case kindof_VOID: + // do nothing for void return type + break; + + default: + // error + EM_error3( "(internal error) unhandled argument kind in MFunInvoker.init()" ); + // clean up instructions + for( t_CKUINT i = 0; i < instructions.size(); i++ ) CK_SAFE_DELETE( instructions[i] ); + // clear instructions + instructions.clear(); + // error out + return FALSE; + } + + // end of code + instructions.push_back( new Chuck_Instr_EOC); + + // create VM code + Chuck_VM_Code * code = new Chuck_VM_Code; + // allocate instruction array + code->instr = new Chuck_Instr*[instructions.size()]; + // number of instructions + code->num_instr = instructions.size(); + // copy instructions + for( t_CKUINT i = 0; i < instructions.size(); i++ ) code->instr[i] = instructions[i]; + // TODO: should this be > 0 + code->stack_depth = 0; + // TODO: should this be this true? + code->need_this = FALSE; + + // create dedicated shred + shred = new Chuck_VM_Shred; + // set the VM ref (needed by initialize) + shred->vm_ref = vm; + // initialize with code + allocate stacks + shred->initialize( code ); + // set name + shred->name = func->signature(FALSE,TRUE); + // enter immediate mode (will throw runtime exception on any time/event ops) + shred->setImmediateMode( TRUE ); + + // done + return TRUE; +} + + + + +//----------------------------------------------------------------------------- +// helper function +//----------------------------------------------------------------------------- +static Chuck_Instr_Reg_Push_Imm * ckvm_next_instr_as_int( vector & v, t_CKUINT & index ) +{ + // check bounds + if( index >= v.size() ) + { + // error + EM_error3( "(internal error) misaligned arguments (get int) in MFunInvoker.invoke()" ); + return NULL; + } + + return (Chuck_Instr_Reg_Push_Imm *)v[index++]; +} +//----------------------------------------------------------------------------- +// helper function +//----------------------------------------------------------------------------- +static Chuck_Instr_Reg_Push_Imm2 * ckvm_next_instr_as_float( vector & v, t_CKUINT & index ) +{ + // check bounds + if( index >= v.size() ) + { + // error + EM_error3( "(internal error) misaligned arguments (get float) in MFunInvoker.invoke()" ); + return NULL; + } + + return (Chuck_Instr_Reg_Push_Imm2 *)v[index++]; +} + + + + +//----------------------------------------------------------------------------- +// name: invoke() +// desc: invoke the mfun +//----------------------------------------------------------------------------- +Chuck_DL_Return Chuck_VM_MFunInvoker::invoke( Chuck_Object * obj, const vector & args ) +{ + // the return value + Chuck_DL_Return RETURN; + // instruction pointers + Chuck_Instr_Reg_Push_Imm * instr_pushInt = NULL; + Chuck_Instr_Reg_Push_Imm2 * instr_pushFloat = NULL; + // index + t_CKUINT index = 0; + // no shred? + if( !shred ) return RETURN; + // verify + assert( instr_pushThis != NULL ); + + // set the actual argument values into the instructions + for( t_CKUINT i = 0; i < args.size(); i++ ) + { + // the current arg + Chuck_DL_Arg arg = args[i]; + // check the argument kind + switch( arg.kind ) + { + case kindof_INT: + instr_pushInt = ckvm_next_instr_as_int(instr_args, index); if( !instr_pushInt ) goto error; + instr_pushInt->set( arg.value.v_int ); + break; + case kindof_FLOAT: + instr_pushFloat = ckvm_next_instr_as_float(instr_args, index); if( !instr_pushFloat ) goto error; + instr_pushFloat->set( arg.value.v_float ); + break; + case kindof_COMPLEX: + 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 = ckvm_next_instr_as_float(instr_args, index); if( !instr_pushFloat ) goto error; + instr_pushFloat->set( arg.value.v_complex.im ); + break; + case kindof_VEC3: + instr_pushFloat = ckvm_next_instr_as_float(instr_args, index); if( !instr_pushFloat ) goto error; + instr_pushFloat->set( arg.value.v_vec3.x ); + instr_pushFloat = ckvm_next_instr_as_float(instr_args, index); if( !instr_pushFloat ) goto error; + instr_pushFloat->set( arg.value.v_vec3.y ); + instr_pushFloat = ckvm_next_instr_as_float(instr_args, index); if( !instr_pushFloat ) goto error; + instr_pushFloat->set( arg.value.v_vec3.z ); + break; + case kindof_VEC4: + instr_pushFloat = ckvm_next_instr_as_float(instr_args, index); if( !instr_pushFloat ) goto error; + instr_pushFloat->set( arg.value.v_vec4.x ); + instr_pushFloat = ckvm_next_instr_as_float(instr_args, index); if( !instr_pushFloat ) goto error; + instr_pushFloat->set( arg.value.v_vec4.y ); + instr_pushFloat = ckvm_next_instr_as_float(instr_args, index); if( !instr_pushFloat ) goto error; + instr_pushFloat->set( arg.value.v_vec4.z ); + instr_pushFloat = ckvm_next_instr_as_float(instr_args, index); if( !instr_pushFloat ) goto error; + instr_pushFloat->set( arg.value.v_vec4.w ); + break; + case kindof_VOID: + default: + // error + EM_error3( "(internal error) unhandle argument kind in MFunInvoker.invoke()" ); + goto error; + } + } + + // arguments not matched, more expected + if( index < instr_args.size() ) + { + // error + EM_error3( "(internal error) misaligned arguments (left over) in MFunInvoker.invoke()" ); + goto error; + } + + // set this pointer + instr_pushThis->set( (t_CKUINT)obj ); + // set the return var, if the function was set up to return a value + if( instr_pushReturnVar ) instr_pushReturnVar->set( (t_CKUINT)&RETURN ); + + // reset shred: program counter + shred->pc = 0; + // next pc + shred->next_pc = 1; + + // TODO: this + // set parent base_ref; in case mfun is part of a non-public class + // that can access file-global variables outside the class definition +// shred->parent = obj->shredOrigin; +// if( shred->parent ) shred->base_ref = shred->parent->base_ref; +// else shred->base_ref = shred->mem; + + // shred in dump (all done) + shred->is_dumped = FALSE; + // shred done + shred->is_done = FALSE; + // shred running + shred->is_running = FALSE; + // shred abort + shred->is_abort = FALSE; + // set the instr + shred->instr = shred->code->instr; + // zero out the id + shred->xid = 0; + // run shred on VM + shred->run( shred->vm_ref ); + + // done; by the point, return should have been filled with return value, if func has one + return RETURN; + +error: + // do the same thing for now + return RETURN; +} + + + + +//----------------------------------------------------------------------------- +// name: cleanup() +// desc: clean up +//----------------------------------------------------------------------------- +void Chuck_VM_MFunInvoker::cleanup() +{ + // release shred reference + // NB this should also cleanup the code and VM instruction we created in setup + CK_SAFE_RELEASE( shred ); + + // clear the arg instructions + instr_args.clear(); + + // zero out + instr_pushThis = NULL; + instr_pushReturnVar = NULL; +} + + + + // begin CK_VM_DEBUG implementation //----------------------------------------------------------------------------- #if CK_VM_DEBUG_ENABLE diff --git a/src/core/chuck_vm.h b/src/core/chuck_vm.h index aa56f80c5..1657d0868 100644 --- a/src/core/chuck_vm.h +++ b/src/core/chuck_vm.h @@ -64,6 +64,7 @@ struct Chuck_VM_Func; struct Chuck_VM_FTable; struct Chuck_Msg; struct Chuck_Globals_Manager; // added 1.4.1.0 (jack) +struct Chuck_Instr_Reg_Push_Imm; // 1.5.1.4 (ge) class CBufferSimple; #ifndef __DISABLE_SERIAL__ // hack: spencer? @@ -134,7 +135,7 @@ struct Chuck_VM_Code : public Chuck_Object // name of this code std::string name; - // the depth of any function arguments + // the depth of any function arguments (in bytes) t_CKUINT stack_depth; // whether the function needs 'this' pointer or not t_CKBOOL need_this; @@ -283,6 +284,30 @@ struct Chuck_VM_Shred : public Chuck_Object // loop counter pointer stack std::vector m_loopCounters; +public: // immediate mode temporal restriction | 1.5.1.4 (ge) + // while in this mode, exception will be thrown on any time ops: + // 1) if shred advances time (even by 0 duration) + // 2) if shred waits on event + // 3) if shred yields, or calls Machine.eval() + // which implicits yields to runs code on a new shred + // this is typically set in specific cases where the programmer + // is expected to provide a callback function that must return + // immediately without any shreduling; for example Chugen.tick( float in ) + // or GGen.update( float dt ); + + // toggle immediate mode + void setImmediateMode( t_CKBOOL onOff ) { is_immediate_mode = onOff; } + // check if shred is in immediate mode + t_CKBOOL immediateMode() const { return is_immediate_mode; } + // check if shred is in immediate mode + t_CKBOOL immediateModeVioation() const { return is_immediate_mode_violation; } + // test and report for immediate mode violations + t_CKBOOL checkImmediatModeException( t_CKUINT linepos = 0 ); + +protected: + t_CKBOOL is_immediate_mode; + t_CKBOOL is_immediate_mode_violation; + #ifndef __DISABLE_SERIAL__ private: // serial IO list for event synchronization @@ -794,6 +819,43 @@ struct Chuck_Msg +//----------------------------------------------------------------------------- +// name: struct Chuck_VM_MFunInvoker | 1.5.1.4 (ge) +// desc: construct for calling chuck-defined member functions from c++, +// either from VM execution or outside the VM execution context +//----------------------------------------------------------------------------- +struct Chuck_VM_MFunInvoker +{ +public: + // constructor + Chuck_VM_MFunInvoker(); + // destructor + ~Chuck_VM_MFunInvoker(); + +public: + // set up the invoker; needed before invoke() + t_CKBOOL setup( Chuck_Func * func, t_CKUINT func_vt_offset, + Chuck_VM * vm, Chuck_VM_Shred * caller ); + // invoke the member function + Chuck_DL_Return invoke( Chuck_Object * obj, + const std::vector & args ); + // clean up + void cleanup(); + +public: + // dedicated shred to call the mfun on + Chuck_VM_Shred * shred; + // instructions for args (to be filled on invoke) + std::vector instr_args; + // instruction to update on invoke: pushing this pointer + Chuck_Instr_Reg_Push_Imm * instr_pushThis; + // instruction to update on invoke: pushing the var to receive return + Chuck_Instr_Reg_Push_Imm * instr_pushReturnVar; +}; + + + + //----------------------------------------------------------------------------- // VM debug macros | 1.5.0.5 (ge) added // these are governed by the presence of __CHUCK_DEBUG__ (e.g., from makefile) diff --git a/src/core/ugen_xxx.cpp b/src/core/ugen_xxx.cpp index 800579aad..2f9346c32 100644 --- a/src/core/ugen_xxx.cpp +++ b/src/core/ugen_xxx.cpp @@ -1583,8 +1583,8 @@ CK_DLL_CTOR( foogen_ctor ) instrs.push_back(new Chuck_Instr_Dot_Member_Func(tick_fun_index) ); // func to code instrs.push_back(new Chuck_Instr_Func_To_Code); - // push stack depth - instrs.push_back(new Chuck_Instr_Reg_Push_Imm(12)); + // push stack depth for args (this, float input) + instrs.push_back(new Chuck_Instr_Reg_Push_Imm(sz_VOIDPTR+sz_FLOAT)); // 1.5.1.4: changed to sz_+sz_; was: 12 // func call instrs.push_back(new Chuck_Instr_Func_Call()); // push immediate @@ -1592,7 +1592,7 @@ CK_DLL_CTOR( foogen_ctor ) // assign primitive instrs.push_back(new Chuck_Instr_Assign_Primitive2); // pop - instrs.push_back(new Chuck_Instr_Reg_Pop_Word2); + instrs.push_back(new Chuck_Instr_Reg_Pop_Float); // EOC instrs.push_back(new Chuck_Instr_EOC); diff --git a/src/core/ulib_machine.cpp b/src/core/ulib_machine.cpp index dac6c1845..1617924bb 100644 --- a/src/core/ulib_machine.cpp +++ b/src/core/ulib_machine.cpp @@ -71,6 +71,8 @@ CK_DLL_SFUN( machine_opOverloadPush_impl); CK_DLL_SFUN( machine_opOverloadPop_impl); CK_DLL_SFUN( machine_opOverloadReset_impl); CK_DLL_SFUN( machine_opOverloadStackLevel_impl); +CK_DLL_SFUN( machine_testSetup_impl ); +CK_DLL_SFUN( machine_testInvoke_impl ); @@ -159,6 +161,15 @@ DLL_QUERY machine_query( Chuck_DL_Query * QUERY ) // QUERY->add_sfun( QUERY, machine_opOverloadStackLevel_impl, "void", "operatorsStackLevel" ); // QUERY->doc_func( QUERY, "Get the current operator overloading stack level."); +// // add testSetup +// QUERY->add_sfun( QUERY, machine_testSetup_impl, "void", "testSetup" ); +// QUERY->add_arg( QUERY, "Object", "obj" ); +// +// // add testInvoke +// QUERY->add_sfun( QUERY, machine_testInvoke_impl, "void", "testInvoke" ); +// QUERY->add_arg( QUERY, "Object", "obj" ); +// QUERY->add_arg( QUERY, "float", "arg" ); + // add status (legacy version of printStatus; has return value) QUERY->add_sfun( QUERY, machine_printStatus_impl, "int", "status" ); QUERY->doc_func( QUERY, "Print the current status of the VM; legacy version of printStatus()."); @@ -624,3 +635,61 @@ CK_DLL_SFUN( machine_crash_impl ) CK_FPRINTF_STDERR( "[chuck]: crashing...\n" ); *(volatile int *)0 = 0; } + + +// TEST +//Chuck_VM_MFunInvoker * g_testInvoker; +// +//CK_DLL_SFUN( machine_testSetup_impl ) +//{ +// Chuck_Object * obj = GET_NEXT_OBJECT(ARGS); +// +// g_testInvoker = new Chuck_VM_MFunInvoker; +// +// t_CKINT func_vt_offset = -1; +// Chuck_Func * func = NULL; +// +// for(t_CKINT i = 0; i < obj->vtable->funcs.size(); i++) +// { +// func = obj->vtable->funcs[i]; +// if(func->name.find("update") == 0 && +// // ensure has one argument +// func->def()->arg_list != NULL && +// // ensure first argument is float +// func->def()->arg_list->type == SHRED->vm_ref->env()->ckt_float && +// // ensure has only one argument +// func->def()->arg_list->next == NULL && +// // ensure returns float +// func->def()->ret_type == SHRED->vm_ref->env()->ckt_void ) +// { +// func_vt_offset = i; +// break; +// } +// } +// +// // not found +// if( func_vt_offset < 0 ) +// { +// EM_error3( "update() not found yo" ); +// return; +// } +// +// // set up invoker +// g_testInvoker->setup( func, func_vt_offset, VM, SHRED ); +//} +// +//CK_DLL_SFUN( machine_testInvoke_impl ) +//{ +// Chuck_Object * obj = GET_NEXT_OBJECT(ARGS); +// t_CKFLOAT v = GET_NEXT_FLOAT(ARGS); +// +// Chuck_DL_Arg arg; +// arg.kind = kindof_FLOAT; +// arg.value.v_float = v; +// vector args; +// args.push_back(arg); +// +// g_testInvoker->invoke(obj, args ); +// +// CK_SAFE_DELETE( g_testInvoker ); +//} From 5c8dd3e7dc23e1bb190fb55efd2f000beb811d76 Mon Sep 17 00:00:00 2001 From: Ge Wang Date: Mon, 2 Oct 2023 21:54:40 -0700 Subject: [PATCH 03/26] update Chuck_Object for origin_shred and origin_vm --- src/core/chuck.cpp | 6 ++++- src/core/chuck_emit.cpp | 2 +- src/core/chuck_instr.cpp | 53 +++++++++++++++++++-------------------- src/core/chuck_instr.h | 2 +- src/core/chuck_io.cpp | 34 ++++++++++++------------- src/core/chuck_lang.cpp | 12 ++++----- src/core/chuck_oo.cpp | 34 +++++++++++++++++++++++++ src/core/chuck_oo.h | 22 +++++++++++++--- src/core/chuck_scan.cpp | 2 +- src/core/chuck_type.cpp | 8 +++--- src/core/chuck_ugen.cpp | 9 +++---- src/core/chuck_ugen.h | 4 --- src/core/chuck_vm.cpp | 14 ++++++----- src/core/chuck_vm.h | 4 +-- src/core/uana_xform.cpp | 2 +- src/core/ugen_stk.cpp | 2 +- src/core/ugen_xxx.cpp | 5 ++-- src/core/ulib_machine.cpp | 4 +-- src/core/ulib_opsc.cpp | 8 +++--- src/core/ulib_std.cpp | 2 +- 20 files changed, 139 insertions(+), 90 deletions(-) diff --git a/src/core/chuck.cpp b/src/core/chuck.cpp index de87f8589..bf2290fb5 100644 --- a/src/core/chuck.cpp +++ b/src/core/chuck.cpp @@ -535,6 +535,8 @@ t_CKBOOL ChucK::initVM() // instantiate VM m_carrier->vm = new Chuck_VM(); + // add reference (this will be released on shtudwon + CK_SAFE_ADD_REF( m_carrier->vm ); // reference back to carrier m_carrier->vm->setCarrier( m_carrier ); // initialize VM @@ -1035,8 +1037,10 @@ t_CKBOOL ChucK::shutdown() if( m_carrier != NULL ) { // clean up vm, compiler - CK_SAFE_DELETE( m_carrier->vm ); CK_SAFE_DELETE( m_carrier->compiler ); + // release VM (which is itself a Chuck_Obj) + CK_SAFE_RELEASE( m_carrier->vm ); + // zero the env out (cleaned up in compiler) m_carrier->env = NULL; } diff --git a/src/core/chuck_emit.cpp b/src/core/chuck_emit.cpp index ae6d284b9..734f742ab 100644 --- a/src/core/chuck_emit.cpp +++ b/src/core/chuck_emit.cpp @@ -3532,7 +3532,7 @@ t_CKBOOL emit_engine_emit_exp_primary( Chuck_Emitter * emit, a_Exp_Primary exp ) case ae_primary_str: // TODO: fix this str = new Chuck_String(); - if( !str || !initialize_object( str, emit->env->ckt_string ) ) + if( !str || !initialize_object( str, emit->env->ckt_string, NULL, emit->env->vm() ) ) { // error (TODO: why is this a CK_SAFE_RELEASE and not CK_SAFE_DELETE?) CK_SAFE_RELEASE( str ); diff --git a/src/core/chuck_instr.cpp b/src/core/chuck_instr.cpp index d75378b8b..3c8f2144b 100644 --- a/src/core/chuck_instr.cpp +++ b/src/core/chuck_instr.cpp @@ -3991,7 +3991,7 @@ void Chuck_Instr_Pre_Constructor::execute( Chuck_VM * vm, Chuck_VM_Shred * shred // name: instantiate_object() // desc: ... //----------------------------------------------------------------------------- -t_CKBOOL initialize_object( Chuck_Object * object, Chuck_Type * type ) +t_CKBOOL initialize_object( Chuck_Object * object, Chuck_Type * type, Chuck_VM_Shred * shred, Chuck_VM * vm ) { // check if already initialized | 1.5.1.4 if( object->vtable != NULL ) return TRUE; @@ -4000,6 +4000,11 @@ t_CKBOOL initialize_object( Chuck_Object * object, Chuck_Type * type ) assert( type != NULL ); assert( type->info != NULL ); + // set origin shred | 1.5.1.4 (ge) was: ugen->shred = shred; + if( shred ) object->setOriginShred( shred ); + // REFACTOR-2017: added | 1.5.1.4 (ge & andrew) moved here from instantiate_... + object->setOriginVM( vm ); + // allocate virtual table object->vtable = new Chuck_VTable; if( !object->vtable ) goto out_of_memory; @@ -4027,6 +4032,9 @@ t_CKBOOL initialize_object( Chuck_Object * object, Chuck_Type * type ) { // ugen Chuck_UGen * ugen = (Chuck_UGen *)object; + // add ugen to shred | 1.5.1.4 (ge & andrew) moved from instantiate_and_initialize_object() + if( shred ) shred->add( ugen ); + // set tick if( type->ugen_info->tick ) ugen->tick = type->ugen_info->tick; // added 1.3.0.0 -- tickf for multi-channel tick if( type->ugen_info->tickf ) ugen->tickf = type->ugen_info->tickf; @@ -4041,7 +4049,7 @@ t_CKBOOL initialize_object( Chuck_Object * object, Chuck_Type * type ) { // allocate ugen for each | REFACTOR-2017: added ugen->vm Chuck_Object * obj = instantiate_and_initialize_object( - ugen->vm->env()->ckt_ugen, ugen->shred, ugen->vm ); + ugen->originVM()->env()->ckt_ugen, ugen->originShred(), ugen->originVM() ); // cast to ugen ugen->m_multi_chan[i] = (Chuck_UGen *)obj; // additional reference count @@ -4109,6 +4117,7 @@ Chuck_Object * instantiate_and_initialize_object( Chuck_Type * type, Chuck_VM * Chuck_Object * instantiate_and_initialize_object( Chuck_Type * type, Chuck_VM_Shred * shred, Chuck_VM * vm ) { Chuck_Object * object = NULL; + Chuck_UGen * ugen = NULL; Chuck_UAna * uana = NULL; // sanity @@ -4147,8 +4156,6 @@ Chuck_Object * instantiate_and_initialize_object( Chuck_Type * type, Chuck_VM_Sh } else { - // make ugen - Chuck_UGen * ugen = NULL; // ugen vs. uana if( type->ugen_info->tock != NULL ) { @@ -4161,22 +4168,13 @@ Chuck_Object * instantiate_and_initialize_object( Chuck_Type * type, Chuck_VM_Sh object = ugen = new Chuck_UGen; ugen->alloc_v( vm->shreduler()->m_max_block_size ); } - - if( shred ) - { - ugen->shred = shred; - shred->add( ugen ); - } - - // REFACTOR-2017: added - ugen->vm = vm; } // check to see enough memory if( !object ) goto out_of_memory; // initialize - if( !initialize_object( object, type ) ) goto error; + if( !initialize_object( object, type, shred, vm ) ) goto error; return object; @@ -5579,7 +5577,7 @@ void Chuck_Instr_Array_Init_Literal::execute( Chuck_VM * vm, Chuck_VM_Shred * sh if( !array ) goto out_of_memory; // initialize object // TODO: should it be this??? initialize_object( array, m_type_ref ); - initialize_object( array, vm->env()->ckt_array ); + initialize_object( array, vm->env()->ckt_array, shred, vm ); // set size array->set_size( m_length ); // fill array @@ -5599,7 +5597,7 @@ void Chuck_Instr_Array_Init_Literal::execute( Chuck_VM * vm, Chuck_VM_Shred * sh // fill array t_CKFLOAT * sp = (t_CKFLOAT *)reg_sp; // intialize object - initialize_object( array, vm->env()->ckt_array ); + initialize_object( array, vm->env()->ckt_array, shred, vm ); // set size array->set_size( m_length ); // fill array @@ -5619,7 +5617,7 @@ void Chuck_Instr_Array_Init_Literal::execute( Chuck_VM * vm, Chuck_VM_Shred * sh // fill array t_CKCOMPLEX * sp = (t_CKCOMPLEX *)reg_sp; // intialize object - initialize_object( array, vm->env()->ckt_array ); + initialize_object( array, vm->env()->ckt_array, shred, vm ); // differentiate between complex and polar | 1.5.1.0 (ge) added, used for sorting Array16s if( isa(m_type_ref, vm->env()->ckt_polar) ) array->m_isPolarType = TRUE; // set size @@ -5641,7 +5639,7 @@ void Chuck_Instr_Array_Init_Literal::execute( Chuck_VM * vm, Chuck_VM_Shred * sh // fill array t_CKVEC3 * sp = (t_CKVEC3 *)reg_sp; // intialize object - initialize_object( array, vm->env()->ckt_array ); + initialize_object( array, vm->env()->ckt_array, shred, vm ); // set size array->set_size( m_length ); // fill array @@ -5661,7 +5659,7 @@ void Chuck_Instr_Array_Init_Literal::execute( Chuck_VM * vm, Chuck_VM_Shred * sh // fill array t_CKVEC4 * sp = (t_CKVEC4 *)reg_sp; // intialize object - initialize_object( array, vm->env()->ckt_array ); + initialize_object( array, vm->env()->ckt_array, shred, vm ); // set size array->set_size( m_length ); // fill array @@ -5762,6 +5760,7 @@ Chuck_Instr_Array_Alloc::~Chuck_Instr_Array_Alloc() // desc: 1.3.1.0 -- changed size to kind //----------------------------------------------------------------------------- Chuck_Object * do_alloc_array( Chuck_VM * vm, // REFACTOR-2017: added + Chuck_VM_Shred * shred, // 1.5.1.4 added t_CKINT * capacity, const t_CKINT * top, t_CKUINT kind, t_CKBOOL is_obj, t_CKUINT * objs, t_CKINT & index, @@ -5799,7 +5798,7 @@ Chuck_Object * do_alloc_array( Chuck_VM * vm, // REFACTOR-2017: added // initialize object | 1.5.0.0 (ge) use array type instead of base t_array // for the object->type_ref to contain more specific information - initialize_object( baseX, type ); + initialize_object( baseX, type, shred, vm ); // initialize_object( baseX, vm->env()->ckt_array ); return baseX; } @@ -5810,7 +5809,7 @@ Chuck_Object * do_alloc_array( Chuck_VM * vm, // REFACTOR-2017: added // initialize object | 1.5.0.0 (ge) use array type instead of base t_array // for the object->type_ref to contain more specific information - initialize_object( baseX, type ); + initialize_object( baseX, type, shred, vm ); // initialize_object( baseX, vm->env()->ckt_array ); return baseX; } @@ -5826,7 +5825,7 @@ Chuck_Object * do_alloc_array( Chuck_VM * vm, // REFACTOR-2017: added // initialize object | 1.5.0.0 (ge) use array type instead of base t_array // for the object->type_ref to contain more specific information - initialize_object( baseX, type ); + initialize_object( baseX, type, shred, vm ); // initialize_object( baseX, vm->env()->ckt_array ); return baseX; } @@ -5837,7 +5836,7 @@ Chuck_Object * do_alloc_array( Chuck_VM * vm, // REFACTOR-2017: added // initialize object | 1.5.0.0 (ge) use array type instead of base t_array // for the object->type_ref to contain more specific information - initialize_object( baseX, type ); + initialize_object( baseX, type, shred, vm ); // initialize_object( baseX, vm->env()->ckt_array ); return baseX; } @@ -5848,7 +5847,7 @@ Chuck_Object * do_alloc_array( Chuck_VM * vm, // REFACTOR-2017: added // initialize object | 1.5.0.0 (ge) use array type instead of base t_array // for the object->type_ref to contain more specific information - initialize_object( baseX, type ); + initialize_object( baseX, type, shred, vm ); // initialize_object( baseX, vm->env()->ckt_array ); return baseX; } @@ -5879,7 +5878,7 @@ Chuck_Object * do_alloc_array( Chuck_VM * vm, // REFACTOR-2017: added for( i = 0; i < *capacity; i++ ) { // the next | REFACTOR-2017: added vm - next = do_alloc_array( vm, capacity+1, top, kind, is_obj, objs, index, typeNext ); + next = do_alloc_array( vm, shred, capacity+1, top, kind, is_obj, objs, index, typeNext ); // error if NULL if( !next ) goto error; // set that, with ref count @@ -5891,7 +5890,7 @@ Chuck_Object * do_alloc_array( Chuck_VM * vm, // REFACTOR-2017: added // initialize object | 1.5.0.0 (ge) use array type instead of base t_array // for the object->type_ref to contain more specific information - initialize_object( theBase, type ); + initialize_object( theBase, type, shred, vm ); // initialize_object( theBase, vm->env()->ckt_array ); return theBase; @@ -5989,7 +5988,7 @@ void Chuck_Instr_Array_Alloc::execute( Chuck_VM * vm, Chuck_VM_Shred * shred ) } // recursively allocate | REFACTOR-2017: added env - ref = (t_CKUINT)do_alloc_array( vm, + ref = (t_CKUINT)do_alloc_array( vm, shred, (t_CKINT *)(reg_sp - m_depth), (t_CKINT *)(reg_sp - 1), getkindof(vm->env(), m_type_ref_content), // 1.3.1.0: changed; was 'm_type_ref->size' diff --git a/src/core/chuck_instr.h b/src/core/chuck_instr.h index c40c84e32..58181b51d 100644 --- a/src/core/chuck_instr.h +++ b/src/core/chuck_instr.h @@ -4233,7 +4233,7 @@ Chuck_Object * instantiate_and_initialize_object( Chuck_Type * type, Chuck_VM_Sh Chuck_Object * instantiate_and_initialize_object( Chuck_Type * type, Chuck_VM * vm ); Chuck_Object * instantiate_and_initialize_object( Chuck_Type * type, Chuck_VM_Shred * shred, Chuck_VM * vm ); // initialize object using Type -t_CKBOOL initialize_object( Chuck_Object * obj, Chuck_Type * type ); +t_CKBOOL initialize_object( Chuck_Object * obj, Chuck_Type * type, Chuck_VM_Shred * shred, Chuck_VM * vm ); // "throw exception" (halt current shred, print message) void ck_throw_exception(Chuck_VM_Shred * shred, const char * name); diff --git a/src/core/chuck_io.cpp b/src/core/chuck_io.cpp index 9e4676b07..a061b2b79 100644 --- a/src/core/chuck_io.cpp +++ b/src/core/chuck_io.cpp @@ -203,7 +203,7 @@ t_CKBOOL init_class_io( Chuck_Env * env, Chuck_Type * type ) // func->doc = "_"; // if( !type_engine_import_sfun( env, func ) ) goto error; // new line string - initialize_object( g_newline, env->ckt_string ); + initialize_object( g_newline, env->ckt_string, NULL, NULL ); g_newline->set( "\n" ); // add TYPE_ASCII @@ -2603,7 +2603,7 @@ CK_DLL_SFUN( HidIn_read_tilt_sensor ) static t_CKBOOL hi_good = TRUE; Chuck_Array4 * array = new Chuck_Array4( FALSE, 3 ); - initialize_object( array, VM->env()->ckt_array ); // 1.5.0.0 (ge) added + initialize_object( array, VM->env()->ckt_array, SHRED, VM ); // 1.5.0.0 (ge) added array->set( 0, 0 ); array->set( 1, 0 ); array->set( 2, 0 ); @@ -2995,7 +2995,7 @@ Chuck_IO_File::Chuck_IO_File( Chuck_VM * vm ) m_dir = NULL; m_dir_start = 0; m_asyncEvent = new Chuck_Event; - initialize_object( m_asyncEvent, vm->env()->ckt_event ); + initialize_object( m_asyncEvent, vm->env()->ckt_event, NULL, vm ); #ifndef __DISABLE_THREADS__ m_thread = new XThread; #endif @@ -3383,7 +3383,7 @@ Chuck_Array4 * Chuck_IO_File::dirList() { EM_error3( "[chuck](via FileIO): cannot get list: no directory open" ); Chuck_Array4 * ret = new Chuck_Array4( TRUE, 0 ); - initialize_object( ret, m_vmRef->env()->ckt_array ); + initialize_object( ret, m_vmRef->env()->ckt_array, NULL, m_vmRef ); return ret; } @@ -3410,7 +3410,7 @@ Chuck_Array4 * Chuck_IO_File::dirList() // make array Chuck_Array4 * array = new Chuck_Array4( true, entrylist.size() ); - initialize_object( array, m_vmRef->env()->ckt_array ); + initialize_object( array, m_vmRef->env()->ckt_array, NULL, m_vmRef ); for( int i = 0; i < entrylist.size(); i++ ) array->set( i, (t_CKUINT)entrylist[i] ); return array; @@ -3481,7 +3481,7 @@ Chuck_String * Chuck_IO_File::readLine() // chuck str Chuck_String * str = new Chuck_String( s ); // initialize | 1.5.0.0 (ge) | added initialize_object - initialize_object( str, m_vmRef->env()->ckt_string ); + initialize_object( str, m_vmRef->env()->ckt_string, NULL, m_vmRef ); // note this chuck string still needs to be initialized return str; @@ -4383,7 +4383,7 @@ Chuck_IO_Chout::Chuck_IO_Chout( Chuck_Carrier * carrier ) // zero out m_callback = NULL; // initialize (added 1.3.0.0) - initialize_object( this, carrier->env->ckt_chout ); + initialize_object( this, carrier->env->ckt_chout, NULL, carrier->vm ); // lock so can't be deleted conventionally this->lock(); } @@ -4561,7 +4561,7 @@ Chuck_IO_Cherr::Chuck_IO_Cherr( Chuck_Carrier * carrier ) // zero out m_callback = NULL; // initialize (added 1.3.0.0) - initialize_object( this, carrier->env->ckt_cherr ); + initialize_object( this, carrier->env->ckt_cherr, NULL, carrier->vm ); // lock so can't be deleted conventionally this->lock(); } @@ -5198,7 +5198,7 @@ Chuck_String * Chuck_IO_Serial::readLine() } Chuck_String * str = new Chuck_String; - initialize_object(str, m_vmRef->env()->ckt_string); + initialize_object(str, m_vmRef->env()->ckt_string, NULL, m_vmRef); str->set( string((char *)m_tmp_buf) ); @@ -5669,7 +5669,7 @@ Chuck_Array * Chuck_IO_Serial::getBytes() r.m_status == Request::RQ_STATUS_SUCCESS) { arr = (Chuck_Array *) r.m_val; - initialize_object(arr, m_vmRef->env()->ckt_array); + initialize_object(arr, m_vmRef->env()->ckt_array, NULL, m_vmRef); m_asyncResponses.get(r); } @@ -5692,7 +5692,7 @@ Chuck_Array * Chuck_IO_Serial::getInts() r.m_type == TYPE_INT && r.m_status == Request::RQ_STATUS_SUCCESS) { arr = (Chuck_Array *) r.m_val; - initialize_object(arr, m_vmRef->env()->ckt_array); + initialize_object(arr, m_vmRef->env()->ckt_array, NULL, m_vmRef); m_asyncResponses.get(r); } @@ -5715,7 +5715,7 @@ Chuck_Array * Chuck_IO_Serial::getFloats() r.m_type == TYPE_FLOAT && r.m_status == Request::RQ_STATUS_SUCCESS) { arr = (Chuck_Array *) r.m_val; - initialize_object(arr, m_vmRef->env()->ckt_array); + initialize_object(arr, m_vmRef->env()->ckt_array, NULL, m_vmRef); m_asyncResponses.get(r); } @@ -5977,7 +5977,7 @@ t_CKBOOL Chuck_IO_Serial::handle_int_ascii(Chuck_IO_Serial::Request & r) t_CKINT val = 0; int numRead = 0; Chuck_Array4 * array = new Chuck_Array4(FALSE, 0); - initialize_object( array, m_vmRef->env()->ckt_array ); // 1.5.0.0 (ge) added + initialize_object( array, m_vmRef->env()->ckt_array, NULL, m_vmRef ); // 1.5.0.0 (ge) added for(int i = 0; i < r.m_num; i++) { t_CKUINT len = 0; @@ -6050,7 +6050,7 @@ t_CKBOOL Chuck_IO_Serial::handle_byte(Chuck_IO_Serial::Request & r) else { Chuck_Array4 * array = new Chuck_Array4(FALSE, r.m_num); - initialize_object( array, m_vmRef->env()->ckt_array ); // 1.5.0.0 (ge) added + initialize_object( array, m_vmRef->env()->ckt_array, NULL, m_vmRef ); // 1.5.0.0 (ge) added for(int i = 0; i < r.m_num; i++) { array->set(i, m_tmp_buf[i]); @@ -6127,7 +6127,7 @@ t_CKBOOL Chuck_IO_Serial::handle_int_binary(Chuck_IO_Serial::Request & r) uint32_t * m_ints = (uint32_t *) m_tmp_buf; Chuck_Array4 * array = new Chuck_Array4(FALSE, r.m_num); - initialize_object( array, m_vmRef->env()->ckt_array ); // 1.5.0.0 (ge) added + initialize_object( array, m_vmRef->env()->ckt_array, NULL, m_vmRef ); // 1.5.0.0 (ge) added for(int i = 0; i < r.m_num; i++) { array->set(i, m_ints[i]); @@ -6612,12 +6612,12 @@ CK_DLL_SFUN( serialio_list ) // ISSUE: 64-bit Chuck_Array4 * array = new Chuck_Array4(TRUE, 0); - initialize_object( array, SHRED->vm_ref->env()->ckt_array ); + initialize_object( array, SHRED->vm_ref->env()->ckt_array, SHRED, VM ); for(vector::iterator i = devices.begin(); i != devices.end(); i++) { Chuck_String * name = new Chuck_String(*i); - initialize_object(name, SHRED->vm_ref->env()->ckt_string); + initialize_object(name, SHRED->vm_ref->env()->ckt_string, SHRED, VM ); array->push_back((t_CKUINT) name); } diff --git a/src/core/chuck_lang.cpp b/src/core/chuck_lang.cpp index b74a11418..1d1727a72 100644 --- a/src/core/chuck_lang.cpp +++ b/src/core/chuck_lang.cpp @@ -1957,13 +1957,13 @@ CK_DLL_CTOR( uanablob_ctor ) // fvals Chuck_Array8 * arr8 = new Chuck_Array8( 8 ); - initialize_object( arr8, SHRED->vm_ref->env()->ckt_array ); + initialize_object( arr8, SHRED->vm_ref->env()->ckt_array, SHRED, VM ); arr8->add_ref(); OBJ_MEMBER_INT(SELF, uanablob_offset_fvals) = (t_CKINT)arr8; // cvals Chuck_Array16 * arr16 = new Chuck_Array16( 8 ); - initialize_object( arr16, SHRED->vm_ref->env()->ckt_array ); + initialize_object( arr16, SHRED->vm_ref->env()->ckt_array, SHRED, VM ); arr16->add_ref(); OBJ_MEMBER_INT(SELF, uanablob_offset_cvals) = (t_CKINT)arr16; } @@ -3273,7 +3273,7 @@ CK_DLL_MFUN( type_children ) // instantiate Chuck_Array4 * ret = new Chuck_Array4( TRUE ); - initialize_object( ret, VM->env()->ckt_array ); + initialize_object( ret, VM->env()->ckt_array, SHRED, VM ); // results vector types; @@ -3433,7 +3433,7 @@ CK_DLL_SFUN( type_getTypes ) { // instantiate Chuck_Array4 * array = new Chuck_Array4( TRUE ); - initialize_object( array, VM->env()->ckt_array ); + initialize_object( array, VM->env()->ckt_array, SHRED, VM ); // get args t_CKINT attributes = GET_NEXT_INT(ARGS); @@ -3458,7 +3458,7 @@ CK_DLL_SFUN( type_getTypes2 ) { // instantiate Chuck_Array4 * array = new Chuck_Array4( TRUE ); - initialize_object( array, VM->env()->ckt_array ); + initialize_object( array, VM->env()->ckt_array, SHRED, VM ); // get args t_CKBOOL objs = GET_NEXT_INT(ARGS); @@ -3479,7 +3479,7 @@ CK_DLL_SFUN( type_getTypesAll ) { // instantiate Chuck_Array4 * array = new Chuck_Array4( TRUE ); - initialize_object( array, VM->env()->ckt_array ); + initialize_object( array, VM->env()->ckt_array, SHRED, VM ); // get all types typeGetTypes( VM, array, true, true, true, true, true, true, true ); diff --git a/src/core/chuck_oo.cpp b/src/core/chuck_oo.cpp index 914dc838b..bec6aa11e 100644 --- a/src/core/chuck_oo.cpp +++ b/src/core/chuck_oo.cpp @@ -256,6 +256,10 @@ Chuck_Object::Chuck_Object() data = NULL; // zero size data_size = 0; + // zero origin shred + origin_shred = NULL; + // zero origin vm + origin_vm = NULL; } @@ -285,6 +289,10 @@ Chuck_Object::~Chuck_Object() type = type->parent; } + // release + CK_SAFE_RELEASE( origin_shred ); + CK_SAFE_RELEASE( origin_vm ); + // free CK_SAFE_DELETE( vtable ); CK_SAFE_RELEASE( type_ref ); @@ -326,6 +334,32 @@ void Chuck_Object::help() // 1.4.1.0 (ge) +//----------------------------------------------------------------------------- +// name: setOriginShred() +// desc: set origin shred +//----------------------------------------------------------------------------- +void Chuck_Object::setOriginShred( Chuck_VM_Shred * shred ) +{ + // assign + CK_SAFE_REF_ASSIGN( this->origin_shred, shred ); +} + + + + +//----------------------------------------------------------------------------- +// name: setOriginVM() +// desc: set origin shred +//----------------------------------------------------------------------------- +void Chuck_Object::setOriginVM( Chuck_VM * vm ) +{ + // assign + CK_SAFE_REF_ASSIGN( this->origin_vm, vm ); +} + + + + //----------------------------------------------------------------------------- // name: Chuck_Array() // desc: constructor diff --git a/src/core/chuck_oo.h b/src/core/chuck_oo.h index 5c48f8c2f..7d12ae57e 100644 --- a/src/core/chuck_oo.h +++ b/src/core/chuck_oo.h @@ -132,13 +132,11 @@ struct Chuck_Object : public Chuck_VM_Object Chuck_Object(); virtual ~Chuck_Object(); -public: - // output current state (can be overridden) - virtual void dump(); - public: // output type info (can be overriden; but probably shouldn't be) virtual void help(); + // output current state (can be overridden) + virtual void dump(); public: // virtual table @@ -150,6 +148,22 @@ struct Chuck_Object : public Chuck_VM_Object // the size of the data region t_CKUINT data_size; +public: + // set VM on which this object was instantiated | 1.5.1.4 + void setOriginVM( Chuck_VM * vm ); + // set shred on which this object was instantiated | 1.5.1.4 + void setOriginShred( Chuck_VM_Shred * shred ); + // get VM on which this object was instantiated | 1.5.1.4 + Chuck_VM * originVM() const { return origin_vm; } + // get shred on which this object was instantiated | 1.5.1.4 + Chuck_VM_Shred * originShred() const { return origin_shred; } + +protected: + // the shred on which this object was instantiated | 1.5.1.4 + Chuck_VM_Shred * origin_shred; + // the VM on which this object was instantiated | 1.5.1.4 + Chuck_VM * origin_vm; + public: // static // vtable offset for toString() static t_CKUINT our_vt_toString; diff --git a/src/core/chuck_scan.cpp b/src/core/chuck_scan.cpp index 63b9001b9..3e6522832 100644 --- a/src/core/chuck_scan.cpp +++ b/src/core/chuck_scan.cpp @@ -360,7 +360,7 @@ t_CKBOOL type_engine_scan0_class_def( Chuck_Env * env, a_Class_Def class_def ) } // initialize the Type info object | 1.5.0.0 (ge) added - initialize_object( the_class, env->ckt_class ); + initialize_object( the_class, env->ckt_class, NULL, env->vm() ); done: diff --git a/src/core/chuck_type.cpp b/src/core/chuck_type.cpp index 5134b255d..662c0fa99 100644 --- a/src/core/chuck_type.cpp +++ b/src/core/chuck_type.cpp @@ -431,7 +431,7 @@ t_CKBOOL Chuck_Env::is_global() t_CKBOOL type_engine_init_special( Chuck_Env * env, Chuck_Type * objT ) { // call initialize_object() to initialize objT itself as an instance of Object - initialize_object( objT, env->ckt_class ); + initialize_object( objT, env->ckt_class, NULL, env->vm() ); // ensure namespace allocation if( objT->info == NULL ) @@ -454,7 +454,7 @@ t_CKBOOL type_engine_init_special( Chuck_Env * env, Chuck_Type * objT ) { // initialize each function type as an object instance // (special cases: these should not be initialized yet) - initialize_object( f->value_ref->type, env->ckt_class ); + initialize_object( f->value_ref->type, env->ckt_class, NULL, env->vm() ); // next f f = f->next; } @@ -6394,7 +6394,7 @@ t_CKBOOL type_engine_import_class_end( Chuck_Env * env ) env->class_def->base_name != env->ckt_array->base_name ) { // initialize the type as object | 1.5.0.0 (ge) added - initialize_object( env->class_def, env->ckt_class ); + initialize_object( env->class_def, env->ckt_class, NULL, env->vm() ); } // pop the class @@ -7194,7 +7194,7 @@ Chuck_Type * Chuck_Context::new_Chuck_Type( Chuck_Env * env ) if( env->ckt_class->info != NULL ) { // initialize it as Type object | 1.5.0.0 (ge) added - initialize_object( theType, env->ckt_class ); + initialize_object( theType, env->ckt_class, NULL, env->vm() ); } return theType; diff --git a/src/core/chuck_ugen.cpp b/src/core/chuck_ugen.cpp index a28775d07..a7666b83f 100644 --- a/src/core/chuck_ugen.cpp +++ b/src/core/chuck_ugen.cpp @@ -212,7 +212,6 @@ void Chuck_UGen::init() m_sum_v = NULL; m_current_v = NULL; - shred = NULL; owner = NULL; // what a hack @@ -239,8 +238,8 @@ void Chuck_UGen::init() //----------------------------------------------------------------------------- void Chuck_UGen::done() { - if( this->shred ) - shred->remove( this ); + if( this->origin_shred ) + origin_shred->remove( this ); assert( this->m_ref_count == 0 ); @@ -1322,7 +1321,7 @@ void Chuck_UGen::init_subgraph() Chuck_Object * obj = NULL; // instantiate object for inlet - obj = instantiate_and_initialize_object( this->shred->vm_ref->env()->ckt_ugen, this->shred ); + obj = instantiate_and_initialize_object( this->origin_shred->vm_ref->env()->ckt_ugen, this->origin_shred ); // set as inlet m_inlet = (Chuck_UGen *)obj; // additional reference count @@ -1333,7 +1332,7 @@ void Chuck_UGen::init_subgraph() this->add_ref(); // instantiate object for outlet - obj = instantiate_and_initialize_object( this->shred->vm_ref->env()->ckt_ugen, this->shred ); + obj = instantiate_and_initialize_object( this->origin_shred->vm_ref->env()->ckt_ugen, this->origin_shred ); // set as outlet m_outlet = (Chuck_UGen *)obj; // additional reference count diff --git a/src/core/chuck_ugen.h b/src/core/chuck_ugen.h index 83b0901fa..0f4a121ed 100644 --- a/src/core/chuck_ugen.h +++ b/src/core/chuck_ugen.h @@ -148,10 +148,6 @@ struct Chuck_UGen : public Chuck_Object SAMPLE * m_sum_v; SAMPLE * m_current_v; - // the shred on which the ugen is created - Chuck_VM_Shred * shred; - // the vm on which the ugen is created - Chuck_VM * vm; // owner Chuck_UGen * owner; diff --git a/src/core/chuck_vm.cpp b/src/core/chuck_vm.cpp index c96833edc..5e2bbf24f 100644 --- a/src/core/chuck_vm.cpp +++ b/src/core/chuck_vm.cpp @@ -347,7 +347,7 @@ t_CKBOOL Chuck_VM::initialize_synthesis( ) m_bunghole = new Chuck_UGen; m_bunghole->add_ref(); m_bunghole->lock(); - initialize_object( m_bunghole, env()->ckt_ugen ); + initialize_object( m_bunghole, env()->ckt_ugen, NULL, this ); m_bunghole->tick = NULL; m_bunghole->alloc_v( m_shreduler->m_max_block_size ); m_shreduler->m_dac = m_dac; @@ -1725,6 +1725,9 @@ t_CKBOOL Chuck_VM_Shred::initialize( Chuck_VM_Code * c, // FYI explicitly call shutdown() before re-initializing shred if( mem ) return FALSE; + // verify + assert( vm_ref != NULL ); + // allocate new stacks mem = new Chuck_VM_Stack; reg = new Chuck_VM_Stack; @@ -1758,7 +1761,7 @@ t_CKBOOL Chuck_VM_Shred::initialize( Chuck_VM_Code * c, xid = 0; // initialize - if( !initialize_object( this, vm_ref->env()->ckt_shred ) ) goto error; + if( !initialize_object( this, vm_ref->env()->ckt_shred, this, vm_ref ) ) goto error; // inherit size hints for shreds sporked from this shred | 1.5.1.4 childSetMemSize( mem_stack_size ); @@ -3477,12 +3480,11 @@ Chuck_DL_Return Chuck_VM_MFunInvoker::invoke( Chuck_Object * obj, const vectornext_pc = 1; - // TODO: this // set parent base_ref; in case mfun is part of a non-public class // that can access file-global variables outside the class definition -// shred->parent = obj->shredOrigin; -// if( shred->parent ) shred->base_ref = shred->parent->base_ref; -// else shred->base_ref = shred->mem; + shred->parent = obj->originShred(); + if( shred->parent ) shred->base_ref = shred->parent->base_ref; + else shred->base_ref = shred->mem; // shred in dump (all done) shred->is_dumped = FALSE; diff --git a/src/core/chuck_vm.h b/src/core/chuck_vm.h index 1657d0868..acfdc2566 100644 --- a/src/core/chuck_vm.h +++ b/src/core/chuck_vm.h @@ -402,7 +402,7 @@ struct Chuck_VM_Status : public Chuck_Object // name: struct Chuck_VM_Shreduler // desc: a ChucK shreduler shredules shreds //----------------------------------------------------------------------------- -struct Chuck_VM_Shreduler : Chuck_Object +struct Chuck_VM_Shreduler : public Chuck_Object { //----------------------------------------------------------------------------- // functions @@ -529,7 +529,7 @@ struct Chuck_VM_Shreduler : Chuck_Object // name: struct Chuck_VM // desc: ChucK virtual machine //----------------------------------------------------------------------------- -struct Chuck_VM : Chuck_Object +struct Chuck_VM : public Chuck_Object { //----------------------------------------------------------------------------- // functions diff --git a/src/core/uana_xform.cpp b/src/core/uana_xform.cpp index d942b5b48..8ca958b11 100644 --- a/src/core/uana_xform.cpp +++ b/src/core/uana_xform.cpp @@ -325,7 +325,7 @@ DLL_QUERY xform_query( Chuck_DL_Query * QUERY ) // initialize static data Windowing_array = new Chuck_Array8(); - initialize_object( Windowing_array, QUERY->env()->ckt_array ); + initialize_object( Windowing_array, QUERY->env()->ckt_array, NULL, QUERY->env()->vm() ); // TODO: yes? reference count Windowing_array->add_ref(); // set size diff --git a/src/core/ugen_stk.cpp b/src/core/ugen_stk.cpp index c1c58659e..a6160bc4e 100644 --- a/src/core/ugen_stk.cpp +++ b/src/core/ugen_stk.cpp @@ -27936,7 +27936,7 @@ CK_DLL_DTOR( WvOut_dtor ) w->closeFile(); // REFACTOR-2017: get the carrier - Chuck_Carrier * carrier = getCarrier( ((Chuck_UGen *)(SELF))->vm, "WvOut dtor" ); + Chuck_Carrier * carrier = getCarrier( ((Chuck_UGen *)(SELF))->originVM(), "WvOut dtor" ); // check if( carrier != NULL ) { diff --git a/src/core/ugen_xxx.cpp b/src/core/ugen_xxx.cpp index 2f9346c32..35611b5bb 100644 --- a/src/core/ugen_xxx.cpp +++ b/src/core/ugen_xxx.cpp @@ -2450,7 +2450,8 @@ CK_DLL_TICK( delayp_tick ) if ( !d->buffer ) return FALSE; // area - d->now = ((Chuck_UGen*)SELF)->shred->vm_ref->shreduler()->now_system; + d->now = ((Chuck_UGen*)SELF)->originVM()->shreduler()->now_system; // 1.5.1.4 + // d->now = ((Chuck_UGen*)SELF)->originShred()->vm_ref->shreduler()->now_system; //calculate new write-offset position ( we interpolate if we've been assigned a new write-offset ) if ( d->now >= d->move_end_time || d->move_duration == 0 ) d->offset = d->offset_target; @@ -2563,7 +2564,7 @@ CK_DLL_CTRL( delayp_ctrl_delay ) d->offset_target = target; d->offset_start = d->last_offset; - t_CKTIME snow = ((Chuck_UGen*)SELF)->shred->now; + t_CKTIME snow = ((Chuck_UGen*)SELF)->originShred()->now; d->move_end_time = snow + d->move_duration; } RETURN->v_dur = d->last_offset; // TODO: diff --git a/src/core/ulib_machine.cpp b/src/core/ulib_machine.cpp index 1617924bb..a9beb1f2f 100644 --- a/src/core/ulib_machine.cpp +++ b/src/core/ulib_machine.cpp @@ -513,7 +513,7 @@ CK_DLL_SFUN( machine_silent_impl ) CK_DLL_SFUN( machine_shreds_impl ) { Chuck_Array4 *array = new Chuck_Array4(FALSE); - initialize_object(array, SHRED->vm_ref->env()->ckt_array); + initialize_object(array, SHRED->vm_ref->env()->ckt_array, SHRED, VM); array->clear(); Chuck_VM_Status status; @@ -571,7 +571,7 @@ CK_DLL_SFUN( machine_version_impl ) // make chuck string Chuck_String * s = new Chuck_String( vs ); // initialize - initialize_object(s, VM->carrier()->env->ckt_string ); + initialize_object(s, VM->carrier()->env->ckt_string, SHRED, VM ); // return RETURN->v_string = s; } diff --git a/src/core/ulib_opsc.cpp b/src/core/ulib_opsc.cpp index 314009ae1..c71b611d7 100644 --- a/src/core/ulib_opsc.cpp +++ b/src/core/ulib_opsc.cpp @@ -1558,7 +1558,7 @@ CK_DLL_CTOR( oscmsg_ctor ) OBJ_MEMBER_STRING( SELF, oscmsg_offset_typetag ) = typetag; Chuck_Array4 * args = new Chuck_Array4( TRUE ); - initialize_object( args, SHRED->vm_ref->env()->ckt_array ); + initialize_object( args, SHRED->vm_ref->env()->ckt_array, SHRED, VM ); args->clear(); CK_SAFE_ADD_REF( args ); OBJ_MEMBER_OBJECT( SELF, oscmsg_offset_args ) = args; @@ -2141,7 +2141,7 @@ CK_DLL_MFUN( osc_address_next_string ) { OSC_Address_Space * addr = (OSC_Address_Space *)OBJ_MEMBER_INT( SELF, osc_address_offset_data ); char * cs = addr->next_string(); Chuck_String * ckstr = (cs) ? new Chuck_String( cs ) : new Chuck_String( "" ); - initialize_object( ckstr, SHRED->vm_ref->env()->ckt_string ); + initialize_object( ckstr, SHRED->vm_ref->env()->ckt_string, SHRED, VM ); RETURN->v_string = ckstr; } @@ -2258,7 +2258,7 @@ CK_DLL_MFUN( osc_recv_new_address ) // more correct...? Chuck_Event * new_event_obj = new Chuck_Event(); - initialize_object( new_event_obj, osc_addr_type_ptr ); + initialize_object( new_event_obj, osc_addr_type_ptr, SHRED, VM ); new_addr_obj->SELF = new_event_obj; OBJ_MEMBER_INT( new_event_obj, osc_address_offset_data ) = (t_CKINT)new_addr_obj; @@ -2288,7 +2288,7 @@ CK_DLL_MFUN( osc_recv_new_address_type ) // more correct...? Chuck_Event * new_event_obj = new Chuck_Event(); - initialize_object( new_event_obj, osc_addr_type_ptr ); + initialize_object( new_event_obj, osc_addr_type_ptr, SHRED, VM ); new_addr_obj->SELF = new_event_obj; OBJ_MEMBER_INT( new_event_obj, osc_address_offset_data ) = (t_CKINT)new_addr_obj; diff --git a/src/core/ulib_std.cpp b/src/core/ulib_std.cpp index 53b56dccf..b073fce79 100644 --- a/src/core/ulib_std.cpp +++ b/src/core/ulib_std.cpp @@ -975,7 +975,7 @@ static Chuck_Array4 * ck_range( t_CKINT start, t_CKINT stop, t_CKINT step, Chuck // allocate array object Chuck_Array4 * range = new Chuck_Array4(FALSE, size); // initialize with trappings of Object - initialize_object(range, SHRED->vm_ref->env()->ckt_array); + initialize_object(range, SHRED->vm_ref->env()->ckt_array, SHRED, SHRED->vm_ref); // the value t_CKINT value = start; From 53d1dba4a04c0c7557b2e95fd7301544680a3f6f Mon Sep 17 00:00:00 2001 From: Ge Wang Date: Mon, 2 Oct 2023 22:37:58 -0700 Subject: [PATCH 04/26] correct watcher func prototype --- src/core/chuck_dl.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/core/chuck_dl.h b/src/core/chuck_dl.h index 7512bec5b..c46a2f3ed 100644 --- a/src/core/chuck_dl.h +++ b/src/core/chuck_dl.h @@ -272,7 +272,7 @@ typedef t_CKBOOL (CK_DLL_CALL * f_mainthreadhook)( void * bindle ); // "main thread" quit (stop running hook) typedef t_CKBOOL (CK_DLL_CALL * f_mainthreadquit)( void * bindle ); // shreds watcher callback -typedef t_CKBOOL (CK_DLL_CALL * f_shreds_watcher)( Chuck_VM_Shred * SHRED, t_CKINT CODE, t_CKINT PARAM, Chuck_VM * VM, void * BINDLE ); +typedef void (CK_DLL_CALL * f_shreds_watcher)( Chuck_VM_Shred * SHRED, t_CKINT CODE, t_CKINT PARAM, Chuck_VM * VM, void * BINDLE ); } From 541585e6b636dfce82b134b6b70be96d4c6dbff2 Mon Sep 17 00:00:00 2001 From: Ge Wang Date: Mon, 2 Oct 2023 23:52:29 -0700 Subject: [PATCH 05/26] invoke_mfun_immediate_mode() DL api func --- src/core/chuck_dl.cpp | 13 ++-- src/core/chuck_dl.h | 137 +++++++++++++++++++++++------------------- src/core/chuck_oo.cpp | 17 +----- 3 files changed, 85 insertions(+), 82 deletions(-) diff --git a/src/core/chuck_dl.cpp b/src/core/chuck_dl.cpp index 2e9d47e61..678cf31fd 100644 --- a/src/core/chuck_dl.cpp +++ b/src/core/chuck_dl.cpp @@ -1249,8 +1249,9 @@ Chuck_DL_Query::Chuck_DL_Query( Chuck_Carrier * carrier, Chuck_DLL * dll ) doc_var = ck_doc_var; add_ex = ck_add_example; // 1.5.0.0 (ge) added create_main_thread_hook = ck_create_main_thread_hook; - register_shreds_watcher = ck_register_shreds_watcher; - unregister_shreds_watcher = ck_unregister_shreds_watcher; + register_shreds_watcher = ck_register_shreds_watcher; // 1.5.1.4 (ge & andrew) + unregister_shreds_watcher = ck_unregister_shreds_watcher; // 1.5.1.4 (ge & andrew) + invoke_mfun_immediate_mode = ck_invoke_mfun_immediate_mode; // 1.5.1.4 (ge & andrew) m_carrier = carrier; dll_ref = dll; // 1.5.1.3 (ge) added @@ -1833,11 +1834,11 @@ array4_get_key(ck_array4_get_key) //----------------------------------------------------------------------------- -// name: ck_invoke_mfun() +// name: ck_invoke_mfun_immediate_mode() // desc: directly call a chuck member function // (supports both native (c++) and user (chuck) //----------------------------------------------------------------------------- -Chuck_DL_Return ck_invoke_mfun( Chuck_Object * obj, t_CKUINT func_vt_offset, Chuck_VM * vm, Chuck_VM_Shred * caller_shred, Chuck_DL_Arg * args_list, t_CKUINT numArgs ) +Chuck_DL_Return ck_invoke_mfun_immediate_mode( Chuck_Object * obj, t_CKUINT func_vt_offset, Chuck_VM * vm, Chuck_VM_Shred * caller_shred, Chuck_DL_Arg * args_list, t_CKUINT numArgs ) { Chuck_DL_Return RETURN; // check objt @@ -1845,7 +1846,7 @@ Chuck_DL_Return ck_invoke_mfun( Chuck_Object * obj, t_CKUINT func_vt_offset, Chu // verify bounds if( func_vt_offset >= obj->vtable->funcs.size() ) { - EM_error3( "(internal error) ck_invoke_mfun() encountered invalid virtual function index: %lu", func_vt_offset ); + EM_error3( "(internal error) ck_invoke_mfun_immediate_mode() encountered invalid virtual function index: %lu", func_vt_offset ); return RETURN; } @@ -1870,7 +1871,7 @@ Chuck_DL_Return ck_invoke_mfun( Chuck_Object * obj, t_CKUINT func_vt_offset, Chu if( !func->setup_invoker(func_vt_offset, vm, caller_shred ) ) { // error - EM_error3( "ck_invoke_mfun() cannot set up invoker for: %s", func->signature(FALSE,TRUE).c_str() ); + EM_error3( "ck_invoke_mfun_immediate_mode() cannot set up invoker for: %s", func->signature(FALSE,TRUE).c_str() ); return RETURN; } // pack the args_list into vector diff --git a/src/core/chuck_dl.h b/src/core/chuck_dl.h index c46a2f3ed..226d825fd 100644 --- a/src/core/chuck_dl.h +++ b/src/core/chuck_dl.h @@ -172,6 +172,67 @@ struct Chuck_UAnaBlobProxy; typedef const Chuck_DL_Api::Api *CK_DL_API; + + + +//------------------------------------------------------------------------------ +// name: union Chuck_DL_Return +// desc: dynamic link return function return struct +//------------------------------------------------------------------------------ +union Chuck_DL_Return +{ + t_CKINT v_int; + t_CKUINT v_uint; + t_CKFLOAT v_float; + t_CKDUR v_dur; + t_CKTIME v_time; + t_CKCOMPLEX v_complex; + t_CKPOLAR v_polar; + t_CKVEC3 v_vec3; // ge: added 1.3.5.3 + t_CKVEC4 v_vec4; // ge: added 1.3.5.3 + Chuck_Object * v_object; + Chuck_String * v_string; + + Chuck_DL_Return() { v_vec4.x = v_vec4.y = v_vec4.z = v_vec4.w = 0; } +}; + + + + +//------------------------------------------------------------------------------ +// name: struct Chuck_DL_Arg +// desc: import / dynamic link function argument | 1.5.1.4 +//------------------------------------------------------------------------------ +struct Chuck_DL_Arg +{ + // which kind of data (e.g., int and object * are both kinds of ints) + te_KindOf kind; + // the data in a union; re-using DL_Return for this + Chuck_DL_Return value; + + // constructor + Chuck_DL_Arg() { kind = kindof_VOID; } + // size in bytes + t_CKUINT sizeInBytes() + { + // check data kind + switch( kind ) + { + 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_VEC4: return sz_VEC4; + case kindof_VOID: return sz_VOID; + } + // unhandled + return 0; + } +}; + + + + // macro for defining ChucK DLL export functions // example: CK_DLL_EXPORT(int) foo() { return 1; } #define CK_DLL_EXPORT(type) CK_DLL_LINKAGE type CK_DLL_CALL @@ -332,8 +393,10 @@ typedef t_CKBOOL (CK_DLL_CALL * f_end_class)( Chuck_DL_Query * query ); typedef Chuck_DL_MainThreadHook * (CK_DLL_CALL * f_create_main_thread_hook)( Chuck_DL_Query * query, f_mainthreadhook hook, f_mainthreadquit quit, void * bindle ); // register a callback function to receive notification from the VM about shreds (add, remove, etc.) typedef void (CK_DLL_CALL * f_register_shreds_watcher)( Chuck_DL_Query * query, f_shreds_watcher cb, t_CKUINT options, void * bindle ); -// unegister a shreds notification callback +// unregister a shreds notification callback typedef void (CK_DLL_CALL * f_unregister_shreds_watcher)( Chuck_DL_Query * query, f_shreds_watcher cb ); +// call a Chuck_Object member function (defined in chuck or in c++) in IMMEDIATE MODE +typedef Chuck_DL_Return (CK_DLL_CALL * f_invoke_mfun)( Chuck_Object * obj, t_CKUINT func_vt_offset, Chuck_VM * vm, Chuck_VM_Shred * shred, Chuck_DL_Arg * ARGS, t_CKUINT numArgs ); // documentation // set current class documentation @@ -435,6 +498,12 @@ struct Chuck_DL_Query // un-register shred notifcations | 1.5.1.4 (ge & andrew) f_unregister_shreds_watcher unregister_shreds_watcher; + // invoke a member function (defined either in chuck or c++) + // NOTE this will call the member function in IMMEDIATE MODE, + // marking it as a time-critical function when called in this manner; + // any time/event operations therein will throw an exception + f_invoke_mfun invoke_mfun_immediate_mode; + public: //------------------------------------------------------------------------- // NOTE: everything below std::anything cannot be reliably accessed @@ -647,63 +716,6 @@ Chuck_DL_Value * make_new_svar( const char * t, const char * n, t_CKBOOL c, void -//------------------------------------------------------------------------------ -// name: union Chuck_DL_Return -// desc: dynamic link return function return struct -//------------------------------------------------------------------------------ -union Chuck_DL_Return -{ - t_CKINT v_int; - t_CKUINT v_uint; - t_CKFLOAT v_float; - t_CKDUR v_dur; - t_CKTIME v_time; - t_CKCOMPLEX v_complex; - t_CKPOLAR v_polar; - t_CKVEC3 v_vec3; // ge: added 1.3.5.3 - t_CKVEC4 v_vec4; // ge: added 1.3.5.3 - Chuck_Object * v_object; - Chuck_String * v_string; - - Chuck_DL_Return() { v_vec4.x = v_vec4.y = v_vec4.z = v_vec4.w = 0; } -}; - - - - -//------------------------------------------------------------------------------ -// name: struct Chuck_DL_Arg -// desc: import / dynamic link function argument | 1.5.1.4 -//------------------------------------------------------------------------------ -struct Chuck_DL_Arg -{ - // which kind of data (e.g., int and object * are both kinds of ints) - te_KindOf kind; - // the data in a union; re-using DL_Return for this - Chuck_DL_Return value; - - // constructor - Chuck_DL_Arg() { kind = kindof_VOID; } - // size in bytes - t_CKUINT sizeInBytes() - { - // check data kind - switch( kind ) - { - 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_VEC4: return sz_VEC4; - case kindof_VOID: return sz_VOID; - } - // unhandled - return 0; - } -}; - - - //----------------------------------------------------------------------------- // name: struct Chuck_DLL @@ -794,9 +806,12 @@ struct Chuck_DL_MainThreadHook //----------------------------------------------------------------------------- // directly invoke a chuck member function's native implementation from c++ // using object + vtable offset | 1.5.1.4 (ge & andrew) -Chuck_DL_Return ck_invoke_mfun( Chuck_Object * obj, t_CKUINT func_vt_offset, - Chuck_VM * vm, Chuck_VM_Shred * shred, - Chuck_DL_Arg * ARGS, t_CKUINT numArgs ); +// NOTE this will call the member function in IMMEDIATE MODE, +// marking it as a time-critical function when called in this manner; +// any time/event operations therein will throw an exception +Chuck_DL_Return ck_invoke_mfun_immediate_mode( Chuck_Object * obj, t_CKUINT func_vt_offset, + Chuck_VM * vm, Chuck_VM_Shred * shred, + Chuck_DL_Arg * ARGS, t_CKUINT numArgs ); diff --git a/src/core/chuck_oo.cpp b/src/core/chuck_oo.cpp index bec6aa11e..a60d874a1 100644 --- a/src/core/chuck_oo.cpp +++ b/src/core/chuck_oo.cpp @@ -3447,14 +3447,7 @@ void Chuck_Event::wait( Chuck_VM_Shred * shred, Chuck_VM * vm ) assert( shred->vm_ref == vm ); // invoke virtual function our_can_wait | 1.5.1.4 - // TODO: check this is right shred - // TODO: make this work in general case (right only for native_func) - Chuck_DL_Return RETURN = ck_invoke_mfun( this, our_can_wait, vm, shred, NULL, 0 ); - // get the member function - // f_mfun canwaitplease = (f_mfun)this->vtable->funcs[our_can_wait]->code->native_func; - // added 1.3.0.0: the DL API instance - // canwaitplease( this, NULL, &RETURN, vm, shred, Chuck_DL_Api::Api::instance() ); - + Chuck_DL_Return RETURN = ck_invoke_mfun_immediate_mode( this, our_can_wait, vm, shred, NULL, 0 ); // see if we can wait if( RETURN.v_int ) { @@ -3486,13 +3479,7 @@ void Chuck_Event::wait( Chuck_VM_Shred * shred, Chuck_VM * vm ) // this is called at the point when a shred has completed the actions // needed to wait on an Event, and can be notified/broadcasted from // a different thread - ck_invoke_mfun( this, our_waiting_on, vm, shred, NULL, 0 ); - // TODO: check this is right shred - // TODO: make this work in general case (right only for native_func) - // // get the virtual function for waiting_on() - // f_mfun waiting_on = (f_mfun)this->vtable->funcs[our_waiting_on]->code->native_func; - // // call to nofify event that a shred has starting waiting on it - // waiting_on( this, NULL, &RETURN, vm, shred, Chuck_DL_Api::Api::instance() ); + ck_invoke_mfun_immediate_mode( this, our_waiting_on, vm, shred, NULL, 0 ); } else // can't wait { From ac848b15e7191dcf916bd748127993c5851d3ce3 Mon Sep 17 00:00:00 2001 From: Ge Wang Date: Tue, 3 Oct 2023 00:41:08 -0700 Subject: [PATCH 06/26] rename Chuck_Array*; chuck VM DL api (breaking changes) --- src/core/chuck_dl.cpp | 103 +++++++++------ src/core/chuck_dl.h | 26 ++-- src/core/chuck_globals.cpp | 32 ++--- src/core/chuck_instr.cpp | 38 +++--- src/core/chuck_io.cpp | 26 ++-- src/core/chuck_io.h | 4 +- src/core/chuck_lang.cpp | 38 +++--- src/core/chuck_lang.h | 2 +- src/core/chuck_oo.cpp | 112 ++++++++-------- src/core/chuck_oo.h | 18 +-- src/core/chuck_ugen.cpp | 8 +- src/core/uana_extract.cpp | 134 +++++++++---------- src/core/uana_xform.cpp | 110 ++++++++-------- src/core/ugen_osc.cpp | 14 +- src/core/ulib_ai.cpp | 264 ++++++++++++++++++------------------- src/core/ulib_doc.cpp | 6 +- src/core/ulib_machine.cpp | 2 +- src/core/ulib_math.cpp | 8 +- src/core/ulib_opsc.cpp | 14 +- src/core/ulib_std.cpp | 4 +- 20 files changed, 492 insertions(+), 471 deletions(-) diff --git a/src/core/chuck_dl.cpp b/src/core/chuck_dl.cpp index 678cf31fd..cc8cb2427 100644 --- a/src/core/chuck_dl.cpp +++ b/src/core/chuck_dl.cpp @@ -1406,16 +1406,6 @@ static t_CKUINT ck_srate( Chuck_VM * vm ) } -//----------------------------------------------------------------------------- -// name: ck_get_srate() | legacy as of 1.5.1.4 -// desc: host-side hook implementation for getting system srate -//----------------------------------------------------------------------------- -static t_CKUINT ck_get_srate( CK_DL_API api, Chuck_VM_Shred * shred ) -{ - return shred->vm_ref->srate(); -} - - //----------------------------------------------------------------------------- // name: create_event_buffer() | 1.5.1.4 (ge, andrew) added // desc: host-side hoook implemenation for @@ -1426,6 +1416,7 @@ static CBufferSimple * ck_create_event_buffer( Chuck_VM * vm ) return vm->create_event_buffer(); } + //----------------------------------------------------------------------------- // name: queue_event() | 1.5.1.4 (ge, andrew) added // desc: host-side hoook implemenation for queuing an event @@ -1441,9 +1432,9 @@ static t_CKBOOL ck_queue_event( Chuck_VM * vm, Chuck_Event * event, t_CKINT num_ // name: ck_get_type() // desc: host-side hook implementation for retrieving a type by name //----------------------------------------------------------------------------- -static Chuck_DL_Api::Type ck_get_type( CK_DL_API api, Chuck_VM_Shred * shred, const char * name ) +static Chuck_DL_Api::Type ck_get_type( CK_DL_API api, Chuck_VM * vm, const char * name ) { - Chuck_Env * env = shred->vm_ref->env(); + Chuck_Env * env = vm->env(); a_Id_List list = new_id_list( name, 0, 0 /*, NULL*/ ); // TODO: nested types Chuck_Type * t = type_engine_find_type( env, list ); delete_id_list( list ); @@ -1452,17 +1443,47 @@ static Chuck_DL_Api::Type ck_get_type( CK_DL_API api, Chuck_VM_Shred * shred, co //----------------------------------------------------------------------------- -// name: ck_create() +// name: ck_create_with_shred() +// desc: host-side hook implementation for instantiating and initializing +// a ChucK object by type, with reference to a parent shred; +// the shred reference is useful in certain scenarios: +// if 1) create a chuck-side class 2) with a member function that +// is then invoked from c++ (e.g., using ck_invoke_mfun_immediate_mode) +// and 3) that member function references global scope variables +//----------------------------------------------------------------------------- +static Chuck_DL_Api::Object ck_create_with_shred( CK_DL_API api, Chuck_VM_Shred * shred, Chuck_DL_Api::Type t ) +{ + // check | 1.5.0.1 (ge) changed; used to be assert t != NULL + if( t == NULL ) + { + // print error message + EM_error2( 0, "DL_Api:object:ck_create_with_shred: NULL object reference." ); + // done + return NULL; + } + + // type + Chuck_Type * type = (Chuck_Type *)t; + // instantiate and initialize + Chuck_Object * o = instantiate_and_initialize_object( type, shred, shred->vm_ref ); + // done + return (Chuck_DL_Api::Object)o; +} + + +//----------------------------------------------------------------------------- +// name: ck_create_no_shred() // desc: host-side hook implementation for instantiating and initializing -// a ChucK object by type +// a ChucK object by type, without a parent shred; see ck_create_with_shred() +// for more details //----------------------------------------------------------------------------- -static Chuck_DL_Api::Object ck_create( CK_DL_API api, Chuck_VM_Shred * shred, Chuck_DL_Api::Type t ) +static Chuck_DL_Api::Object ck_create_no_shred( CK_DL_API api, Chuck_VM * vm, Chuck_DL_Api::Type t ) { // check | 1.5.0.1 (ge) changed; used to be assert t != NULL if( t == NULL ) { // print error message - EM_error2( 0, "DL_Api:object:ck_create: NULL object reference." ); + EM_error2( 0, "DL_Api:object:ck_create_no_shred: NULL object reference." ); // done return NULL; } @@ -1470,7 +1491,7 @@ static Chuck_DL_Api::Object ck_create( CK_DL_API api, Chuck_VM_Shred * shred, Ch // type Chuck_Type * type = (Chuck_Type *)t; // instantiate and initialize - Chuck_Object * o = instantiate_and_initialize_object( type, shred->vm_ref ); + Chuck_Object * o = instantiate_and_initialize_object( type, vm ); // done return (Chuck_DL_Api::Object)o; } @@ -1480,10 +1501,10 @@ static Chuck_DL_Api::Object ck_create( CK_DL_API api, Chuck_VM_Shred * shred, Ch // name: ck_create_string() // desc: host-side hook implementation for creating a chuck string //----------------------------------------------------------------------------- -static Chuck_DL_Api::String ck_create_string( CK_DL_API api, Chuck_VM_Shred * shred, const char * cstr ) +static Chuck_DL_Api::String ck_create_string( CK_DL_API api, Chuck_VM * vm, const char * cstr ) { // instantiate and initalize object - Chuck_String * string = (Chuck_String *)instantiate_and_initialize_object( shred->vm_ref->env()->ckt_string, shred->vm_ref ); + Chuck_String * string = (Chuck_String *)instantiate_and_initialize_object( vm->env()->ckt_string, vm ); // set the value string->set( cstr ? cstr : "" ); // return reference @@ -1730,18 +1751,18 @@ static t_CKBOOL ck_set_string( CK_DL_API api, Chuck_DL_Api::String s, const char //----------------------------------------------------------------------------- -// name: ck_array4_size() +// name: ck_array_int_size() // desc: get size of an array | 1.5.1.3 (nshaheed) added //----------------------------------------------------------------------------- -static t_CKBOOL ck_array4_size( CK_DL_API api, Chuck_DL_Api::Array4 a, t_CKINT & value ) +static t_CKBOOL ck_array_int_size( CK_DL_API api, Chuck_DL_Api::ArrayInt a, t_CKINT & value ) { // default value value = 0; // check if( a == NULL ) return FALSE; - // cast to array4 - Chuck_Array4 * array = (Chuck_Array4 *)a; + // cast to array_int + Chuck_ArrayInt * array = (Chuck_ArrayInt *)a; value = array->size(); return TRUE; @@ -1749,15 +1770,15 @@ static t_CKBOOL ck_array4_size( CK_DL_API api, Chuck_DL_Api::Array4 a, t_CKINT & //----------------------------------------------------------------------------- -// name: ck_array4_push_back() +// name: ck_array_int_push_back() // desc: push back an element into an array | 1.5.0.1 (ge) added //----------------------------------------------------------------------------- -static t_CKBOOL ck_array4_push_back( CK_DL_API api, Chuck_DL_Api::Array4 a, t_CKUINT value ) +static t_CKBOOL ck_array_int_push_back( CK_DL_API api, Chuck_DL_Api::ArrayInt a, t_CKUINT value ) { // check if( a == NULL ) return FALSE; - // cast to array4 - Chuck_Array4 * array = (Chuck_Array4 *)a; + // cast to array_int + Chuck_ArrayInt * array = (Chuck_ArrayInt *)a; // action array->push_back( value ); // done @@ -1766,30 +1787,30 @@ static t_CKBOOL ck_array4_push_back( CK_DL_API api, Chuck_DL_Api::Array4 a, t_CK //----------------------------------------------------------------------------- -// name: ck_array4_get_idx() +// name: ck_array_int_get_idx() // desc: get an indexed element from an array | 1.5.1.3 (nshaheed) added //----------------------------------------------------------------------------- -static t_CKBOOL ck_array4_get_idx( CK_DL_API api, Chuck_DL_Api::Array4 a, t_CKINT idx, t_CKUINT & value ) +static t_CKBOOL ck_array_int_get_idx( CK_DL_API api, Chuck_DL_Api::ArrayInt a, t_CKINT idx, t_CKUINT & value ) { // check if( a == NULL ) return FALSE; - // cast to array4 - Chuck_Array4 * array = (Chuck_Array4 *)a; + // cast to array_int + Chuck_ArrayInt * array = (Chuck_ArrayInt *)a; // action return array->get( idx, &value ); } //----------------------------------------------------------------------------- -// name: ck_array4_get() +// name: ck_array_int_get() // desc: get a keyed element from an array | 1.5.1.3 (nshaheed) added //----------------------------------------------------------------------------- -static t_CKBOOL ck_array4_get_key( CK_DL_API api, Chuck_DL_Api::Array4 a, const std::string& key, t_CKUINT & value ) +static t_CKBOOL ck_array_int_get_key( CK_DL_API api, Chuck_DL_Api::ArrayInt a, const std::string& key, t_CKUINT & value ) { // check if( a == NULL ) return FALSE; - // cast to array4 - Chuck_Array4 * array = (Chuck_Array4 *)a; + // cast to array_int + Chuck_ArrayInt * array = (Chuck_ArrayInt *)a; // action return array->get( key, &value ); } @@ -1801,7 +1822,6 @@ static t_CKBOOL ck_array4_get_key( CK_DL_API api, Chuck_DL_Api::Array4 a, const // constructor for the VMApi; connects function pointers to host-side impl //----------------------------------------------------------------------------- Chuck_DL_Api::Api::VMApi::VMApi() : -get_srate(ck_get_srate), srate(ck_srate), create_event_buffer(ck_create_event_buffer), queue_event(ck_queue_event) @@ -1815,7 +1835,8 @@ queue_event(ck_queue_event) //----------------------------------------------------------------------------- Chuck_DL_Api::Api::ObjectApi::ObjectApi() : get_type(ck_get_type), -create(ck_create), +create_with_shred(ck_create_with_shred), +create_no_shred(ck_create_no_shred), create_string(ck_create_string), get_mvar_int(ck_get_mvar_int), get_mvar_float(ck_get_mvar_float), @@ -1824,10 +1845,10 @@ get_mvar_time(ck_get_mvar_time), get_mvar_string(ck_get_mvar_string), get_mvar_object(ck_get_mvar_object), set_string(ck_set_string), -array4_size(ck_array4_size), -array4_push_back(ck_array4_push_back), -array4_get_idx(ck_array4_get_idx), -array4_get_key(ck_array4_get_key) +array_int_size(ck_array_int_size), +array_int_push_back(ck_array_int_push_back), +array_int_get_idx(ck_array_int_get_idx), +array_int_get_key(ck_array_int_get_key) { } diff --git a/src/core/chuck_dl.h b/src/core/chuck_dl.h index 226d825fd..fcd7c65f6 100644 --- a/src/core/chuck_dl.h +++ b/src/core/chuck_dl.h @@ -49,7 +49,7 @@ // major version must be the same between chuck:chugin #define CK_DLL_VERSION_MAJOR (0x0008) // minor version of chugin must be less than or equal to chuck's -#define CK_DLL_VERSION_MINOR (0x0001) +#define CK_DLL_VERSION_MINOR (0x0002) #define CK_DLL_VERSION_MAKE(maj,min) ((t_CKUINT)(((maj) << 16) | (min))) #define CK_DLL_VERSION_GETMAJOR(v) (((v) >> 16) & 0xFFFF) #define CK_DLL_VERSION_GETMINOR(v) ((v) & 0xFFFF) @@ -824,7 +824,7 @@ namespace Chuck_DL_Api typedef void * Object; typedef void * Type; typedef void * String; -typedef void * Array4; // 1.5.0.1 (ge) added +typedef void * ArrayInt; // 1.5.0.1 (ge) added struct Api { @@ -835,8 +835,6 @@ struct Api struct VMApi { VMApi(); - // get sample rate (legacy as of 1.5.1.4) - t_CKUINT (* const get_srate)( CK_DL_API, Chuck_VM_Shred * ); // get sample rate | 1.5.1.4 t_CKUINT (* const srate)( Chuck_VM * vm ); // create a new lock-free one-producer, one-consumer buffer | 1.5.1.4 @@ -854,11 +852,13 @@ struct Api // intent: this allows for chugins to access member variables and create chuck strings public: // function pointer get_type() - Type (* const get_type)( CK_DL_API, Chuck_VM_Shred *, const char * name ); - // function pointer create() - Object (* const create)( CK_DL_API, Chuck_VM_Shred *, Type type ); + Type (* const get_type)( CK_DL_API, Chuck_VM *, const char * name ); + // function pointer create_with_shred() + Object (* const create_with_shred)( CK_DL_API, Chuck_VM_Shred *, Type type ); + // function pointer create_no_shred() + Object (* const create_no_shred)( CK_DL_API, Chuck_VM *, Type type ); // function pointer create_string() - String (* const create_string)( CK_DL_API, Chuck_VM_Shred *, const char * value ); + String (* const create_string)( CK_DL_API, Chuck_VM *, const char * value ); // function pointers for get_mvar_*() t_CKBOOL (* const get_mvar_int)( CK_DL_API, Object object, const char * name, t_CKINT & value ); t_CKBOOL (* const get_mvar_float)( CK_DL_API, Object object, const char * name, t_CKFLOAT & value ); @@ -868,11 +868,11 @@ struct Api t_CKBOOL (* const get_mvar_object)( CK_DL_API, Object object, const char * name, Object & value ); // function pointer for set_string() t_CKBOOL (* const set_string)( CK_DL_API, String string, const char * value ); - // array4 operations - t_CKBOOL (* const array4_size)( CK_DL_API, Array4 array, t_CKINT & value ); - t_CKBOOL (* const array4_push_back)( CK_DL_API, Array4 array, t_CKUINT value ); - t_CKBOOL (* const array4_get_idx)( CK_DL_API, Array4 array, t_CKINT idx, t_CKUINT & value ); - t_CKBOOL (* const array4_get_key)( CK_DL_API, Array4 array, const std::string & key, t_CKUINT & value ); + // array_int operations + t_CKBOOL (* const array_int_size)( CK_DL_API, ArrayInt array, t_CKINT & value ); + t_CKBOOL (* const array_int_push_back)( CK_DL_API, ArrayInt array, t_CKUINT value ); + t_CKBOOL (* const array_int_get_idx)( CK_DL_API, ArrayInt array, t_CKINT idx, t_CKUINT & value ); + t_CKBOOL (* const array_int_get_key)( CK_DL_API, ArrayInt array, const std::string & key, t_CKUINT & value ); } * const object; Api() : diff --git a/src/core/chuck_globals.cpp b/src/core/chuck_globals.cpp index 526c01d1d..9af6141be 100644 --- a/src/core/chuck_globals.cpp +++ b/src/core/chuck_globals.cpp @@ -2214,7 +2214,7 @@ t_CKINT Chuck_Globals_Manager::get_global_int_array_value( const std::string & n if( array != NULL && m_global_arrays[name]->array_type == te_globalInt ) { - Chuck_Array4 * intArray = (Chuck_Array4 *) array; + Chuck_ArrayInt * intArray = (Chuck_ArrayInt *) array; // TODO why is it unsigned int storage? intArray->get( index, &result ); } @@ -2236,7 +2236,7 @@ t_CKINT Chuck_Globals_Manager::get_global_associative_int_array_value( if( array != NULL && m_global_arrays[name]->array_type == te_globalInt ) { - Chuck_Array4 * intArray = (Chuck_Array4 *) array; + Chuck_ArrayInt * intArray = (Chuck_ArrayInt *) array; // TODO why is it unsigned int storage? intArray->get( key, &result ); } @@ -2258,7 +2258,7 @@ t_CKFLOAT Chuck_Globals_Manager::get_global_float_array_value( const std::string if( array != NULL && m_global_arrays[name]->array_type == te_globalFloat ) { - Chuck_Array8 * floatArray = (Chuck_Array8 *) array; + Chuck_ArrayFloat * floatArray = (Chuck_ArrayFloat *) array; floatArray->get( index, &result ); } return result; @@ -2279,7 +2279,7 @@ t_CKFLOAT Chuck_Globals_Manager::get_global_associative_float_array_value( if( array != NULL && m_global_arrays[name]->array_type == te_globalFloat ) { - Chuck_Array8 * floatArray = (Chuck_Array8 *) array; + Chuck_ArrayFloat * floatArray = (Chuck_ArrayFloat *) array; floatArray->get( key, &result ); } return result; @@ -2906,7 +2906,7 @@ void Chuck_Globals_Manager::handle_global_queue_messages() m_global_arrays[request->name]->array_type == te_globalInt ) { // it exists! get existing array, new size - Chuck_Array4 * intArray = (Chuck_Array4 *) array; + Chuck_ArrayInt * intArray = (Chuck_ArrayInt *) array; t_CKUINT newSize = request->arrayValues.size(); // resize and copy in @@ -2951,7 +2951,7 @@ void Chuck_Globals_Manager::handle_global_queue_messages() m_global_arrays[request->name]->array_type == te_globalInt && request->cb != NULL ) { - Chuck_Array4 * intArray = (Chuck_Array4 *) array; + Chuck_ArrayInt * intArray = (Chuck_ArrayInt *) array; // TODO: why is m_vector a vector of unsigned ints...?? switch( request->cb_type ) { @@ -3012,7 +3012,7 @@ void Chuck_Globals_Manager::handle_global_queue_messages() m_global_arrays[request->name]->array_type == te_globalInt ) { // it exists! get existing array - Chuck_Array4 * intArray = (Chuck_Array4 *) array; + Chuck_ArrayInt * intArray = (Chuck_ArrayInt *) array; // set! (if index within range) if( intArray->size() > request->index ) { @@ -3055,7 +3055,7 @@ void Chuck_Globals_Manager::handle_global_queue_messages() m_global_arrays[request->name]->array_type == te_globalInt && request->cb != NULL ) { - Chuck_Array4 * intArray = (Chuck_Array4 *) array; + Chuck_ArrayInt * intArray = (Chuck_ArrayInt *) array; // TODO why is it unsigned int storage? t_CKUINT result = 0; intArray->get( request->index, &result ); @@ -3107,7 +3107,7 @@ void Chuck_Globals_Manager::handle_global_queue_messages() m_global_arrays[request->name]->array_type == te_globalInt ) { // it exists! get existing array - Chuck_Array4 * intArray = (Chuck_Array4 *) array; + Chuck_ArrayInt * intArray = (Chuck_ArrayInt *) array; // set! intArray->set( request->key, request->value ); } @@ -3147,7 +3147,7 @@ void Chuck_Globals_Manager::handle_global_queue_messages() m_global_arrays[request->name]->array_type == te_globalInt && request->cb != NULL ) { - Chuck_Array4 * intArray = (Chuck_Array4 *) array; + Chuck_ArrayInt * intArray = (Chuck_ArrayInt *) array; // TODO why is it unsigned int storage? t_CKUINT result = 0; intArray->get( request->key, &result ); @@ -3199,7 +3199,7 @@ void Chuck_Globals_Manager::handle_global_queue_messages() m_global_arrays[request->name]->array_type == te_globalFloat ) { // it exists! get existing array, new size - Chuck_Array8 * floatArray = (Chuck_Array8 *) array; + Chuck_ArrayFloat * floatArray = (Chuck_ArrayFloat *) array; t_CKUINT newSize = request->arrayValues.size(); // resize and copy in @@ -3244,7 +3244,7 @@ void Chuck_Globals_Manager::handle_global_queue_messages() m_global_arrays[request->name]->array_type == te_globalFloat && request->cb != NULL ) { - Chuck_Array8 * floatArray = (Chuck_Array8 *) array; + Chuck_ArrayFloat * floatArray = (Chuck_ArrayFloat *) array; switch( request->cb_type ) { case ck_get_plain: @@ -3304,7 +3304,7 @@ void Chuck_Globals_Manager::handle_global_queue_messages() m_global_arrays[request->name]->array_type == te_globalFloat ) { // it exists! get existing array - Chuck_Array8 * floatArray = (Chuck_Array8 *) array; + Chuck_ArrayFloat * floatArray = (Chuck_ArrayFloat *) array; // set! (if index within range) if( floatArray->size() > request->index ) { @@ -3347,7 +3347,7 @@ void Chuck_Globals_Manager::handle_global_queue_messages() m_global_arrays[request->name]->array_type == te_globalFloat && request->cb != NULL ) { - Chuck_Array8 * floatArray = (Chuck_Array8 *) array; + Chuck_ArrayFloat * floatArray = (Chuck_ArrayFloat *) array; t_CKFLOAT result = 0; floatArray->get( request->index, &result ); switch( request->cb_type ) @@ -3398,7 +3398,7 @@ void Chuck_Globals_Manager::handle_global_queue_messages() m_global_arrays[request->name]->array_type == te_globalFloat ) { // it exists! get existing array - Chuck_Array8 * floatArray = (Chuck_Array8 *) array; + Chuck_ArrayFloat * floatArray = (Chuck_ArrayFloat *) array; // set! floatArray->set( request->key, request->value ); } @@ -3438,7 +3438,7 @@ void Chuck_Globals_Manager::handle_global_queue_messages() m_global_arrays[request->name]->array_type == te_globalFloat && request->cb != NULL ) { - Chuck_Array8 * floatArray = (Chuck_Array8 *) array; + Chuck_ArrayFloat * floatArray = (Chuck_ArrayFloat *) array; t_CKFLOAT result = 0; floatArray->get( request->key, &result ); switch( request->cb_type ) diff --git a/src/core/chuck_instr.cpp b/src/core/chuck_instr.cpp index 3c8f2144b..738a135cc 100644 --- a/src/core/chuck_instr.cpp +++ b/src/core/chuck_instr.cpp @@ -5568,11 +5568,11 @@ void Chuck_Instr_Array_Init_Literal::execute( Chuck_VM * vm, Chuck_VM_Shred * sh // 1.4.2.0 (ge) | added: check for float explicitly if( m_type_ref->size == sz_INT && !m_is_float ) // ISSUE: 64-bit (fixed 1.3.1.0) { - // TODO: look at size and treat Chuck_Array4 as ChuckArrayInt + // TODO: look at size and treat Chuck_ArrayInt as ChuckArrayInt // pop the values pop_( reg_sp, m_length ); // instantiate array - Chuck_Array4 * array = new Chuck_Array4( m_is_obj, m_length ); + Chuck_ArrayInt * array = new Chuck_ArrayInt( m_is_obj, m_length ); // problem if( !array ) goto out_of_memory; // initialize object @@ -5591,7 +5591,7 @@ void Chuck_Instr_Array_Init_Literal::execute( Chuck_VM * vm, Chuck_VM_Shred * sh // pop the values pop_( reg_sp, m_length * (sz_FLOAT / sz_INT) ); // 1.3.1.0 added size division // instantiate array - Chuck_Array8 * array = new Chuck_Array8( m_length ); + Chuck_ArrayFloat * array = new Chuck_ArrayFloat( m_length ); // problem if( !array ) goto out_of_memory; // fill array @@ -5767,7 +5767,7 @@ Chuck_Object * do_alloc_array( Chuck_VM * vm, // REFACTOR-2017: added Chuck_Type * type ) { // not top level - Chuck_Array4 * theBase = NULL; + Chuck_ArrayInt * theBase = NULL; Chuck_Object * next = NULL; Chuck_Type * typeNext = NULL; t_CKINT i = 0; @@ -5782,7 +5782,7 @@ Chuck_Object * do_alloc_array( Chuck_VM * vm, // REFACTOR-2017: added // 1.3.1.0: look at type to use kind instead of size if( kind == kindof_INT ) // ISSUE: 64-bit (fixed 1.3.1.0) { - Chuck_Array4 * baseX = new Chuck_Array4( is_obj, *capacity ); + Chuck_ArrayInt * baseX = new Chuck_ArrayInt( is_obj, *capacity ); if( !baseX ) goto out_of_memory; // if object @@ -5804,7 +5804,7 @@ Chuck_Object * do_alloc_array( Chuck_VM * vm, // REFACTOR-2017: added } else if( kind == kindof_FLOAT ) // ISSUE: 64-bit (fixed 1.3.1.0) { - Chuck_Array8 * baseX = new Chuck_Array8( *capacity ); + Chuck_ArrayFloat * baseX = new Chuck_ArrayFloat( *capacity ); if( !baseX ) goto out_of_memory; // initialize object | 1.5.0.0 (ge) use array type instead of base t_array @@ -5857,7 +5857,7 @@ Chuck_Object * do_alloc_array( Chuck_VM * vm, // REFACTOR-2017: added } // not top level - theBase = new Chuck_Array4( TRUE, *capacity ); + theBase = new Chuck_ArrayInt( TRUE, *capacity ); if( !theBase) goto out_of_memory; // construct type for next array level | 1.5.0.0 (ge) added @@ -6092,7 +6092,7 @@ void Chuck_Instr_Array_Access::execute( Chuck_VM * vm, Chuck_VM_Shred * shred ) if( m_kind == kindof_INT ) // ISSUE: 64-bit (fixed 1.3.1.0) { // get array - Chuck_Array4 * arr = (Chuck_Array4 *)(*sp); + Chuck_ArrayInt * arr = (Chuck_ArrayInt *)(*sp); // get index i = (t_CKINT)(*(sp+1)); // normalize index to allow for negative indexing | 1.5.0.0 (nshaheed) added @@ -6116,7 +6116,7 @@ void Chuck_Instr_Array_Access::execute( Chuck_VM * vm, Chuck_VM_Shred * shred ) else if( m_kind == kindof_FLOAT ) // ISSUE: 64-bit (1.3.1.0) { // get array - Chuck_Array8 * arr = (Chuck_Array8 *)(*sp); + Chuck_ArrayFloat * arr = (Chuck_ArrayFloat *)(*sp); // get index i = (t_CKINT)(*(sp+1)); // normalize index to allow for negative indexing @@ -6266,7 +6266,7 @@ void Chuck_Instr_Array_Map_Access::execute( Chuck_VM * vm, Chuck_VM_Shred * shre if( m_kind == kindof_INT ) // ISSUE: 64-bit (fixed 1.3.1.0) { // get array - Chuck_Array4 * arr = (Chuck_Array4 *)(*sp); + Chuck_ArrayInt * arr = (Chuck_ArrayInt *)(*sp); // get index key = (Chuck_String *)(*(sp+1)); // check if writing @@ -6288,7 +6288,7 @@ void Chuck_Instr_Array_Map_Access::execute( Chuck_VM * vm, Chuck_VM_Shred * shre else if( m_kind == kindof_FLOAT ) // ISSUE: 64-bit (fixed 1.3.1.0) { // get array - Chuck_Array8 * arr = (Chuck_Array8 *)(*sp); + Chuck_ArrayFloat * arr = (Chuck_ArrayFloat *)(*sp); // get index key = (Chuck_String *)(*(sp+1)); // check if writing @@ -6422,7 +6422,7 @@ void Chuck_Instr_Array_Access_Multi::execute( Chuck_VM * vm, Chuck_VM_Shred * sh pop_( sp, m_depth + 1 ); // get array - Chuck_Array4 * base = (Chuck_Array4 *)(*sp); + Chuck_ArrayInt * base = (Chuck_ArrayInt *)(*sp); ptr = (t_CKINT *)(sp+1); // check for null @@ -6452,7 +6452,7 @@ void Chuck_Instr_Array_Access_Multi::execute( Chuck_VM * vm, Chuck_VM_Shred * sh } // set the array - base = (Chuck_Array4 *)val; + base = (Chuck_ArrayInt *)val; // check for null if( !base ) { @@ -6467,7 +6467,7 @@ void Chuck_Instr_Array_Access_Multi::execute( Chuck_VM * vm, Chuck_VM_Shred * sh if( m_kind == kindof_INT ) // ISSUE: 64-bit (fixed 1.3.1.0) { // get arry - Chuck_Array4 * arr = base; + Chuck_ArrayInt * arr = base; // get index i = (t_CKINT)(*ptr); // check if writing @@ -6489,7 +6489,7 @@ void Chuck_Instr_Array_Access_Multi::execute( Chuck_VM * vm, Chuck_VM_Shred * sh else if( m_kind == kindof_FLOAT ) // ISSUE: 64-bit (fixed 1.3.1.0) { // get array - Chuck_Array8 * arr = (Chuck_Array8 *)(base); + Chuck_ArrayFloat * arr = (Chuck_ArrayFloat *)(base); // get index i = (t_CKINT)(*ptr); // check if writing @@ -6652,7 +6652,7 @@ void Chuck_Instr_Array_Append::execute( Chuck_VM * vm, Chuck_VM_Shred * shred ) if( m_val == kindof_INT ) // ISSUE: 64-bit (fixed 1.3.1.0) { // get array - Chuck_Array4 * arr = (Chuck_Array4 *)(*sp); + Chuck_ArrayInt * arr = (Chuck_ArrayInt *)(*sp); // get value val = (t_CKINT)(*(sp+1)); // append @@ -6661,7 +6661,7 @@ void Chuck_Instr_Array_Append::execute( Chuck_VM * vm, Chuck_VM_Shred * shred ) else if( m_val == kindof_FLOAT ) // ISSUE: 64-bit (fixed 1.3.1.0) { // get array - Chuck_Array8 * arr = (Chuck_Array8 *)(*sp); + Chuck_ArrayFloat * arr = (Chuck_ArrayFloat *)(*sp); // get value fval = (*(t_CKFLOAT *)(sp+1)); // append @@ -7785,7 +7785,7 @@ void Chuck_Instr_ForEach_Inc_And_Branch::execute( Chuck_VM * vm, Chuck_VM_Shred case kindof_INT: { // cast to specific array type - Chuck_Array4 * arr = (Chuck_Array4 *)array; + Chuck_ArrayInt * arr = (Chuck_ArrayInt *)array; // is object RELEASE if( arr->contains_objects() && *pVar) { @@ -7806,7 +7806,7 @@ void Chuck_Instr_ForEach_Inc_And_Branch::execute( Chuck_VM * vm, Chuck_VM_Shred case kindof_FLOAT: { // cast to specific array type - Chuck_Array8 * arr = (Chuck_Array8 *) array; + Chuck_ArrayFloat * arr = (Chuck_ArrayFloat *) array; // get element arr->get( *counter, (t_CKFLOAT *)pVar ); break; diff --git a/src/core/chuck_io.cpp b/src/core/chuck_io.cpp index a061b2b79..e02199eea 100644 --- a/src/core/chuck_io.cpp +++ b/src/core/chuck_io.cpp @@ -1633,7 +1633,7 @@ CK_DLL_MFUN( fileio_isdir ) CK_DLL_MFUN( fileio_dirlist ) { Chuck_IO_File * f = (Chuck_IO_File *)SELF; - Chuck_Array4 * a = f->dirList(); + Chuck_ArrayInt * a = f->dirList(); RETURN->v_object = a; } @@ -2602,7 +2602,7 @@ CK_DLL_SFUN( HidIn_read_tilt_sensor ) static HidIn * hi; static t_CKBOOL hi_good = TRUE; - Chuck_Array4 * array = new Chuck_Array4( FALSE, 3 ); + Chuck_ArrayInt * array = new Chuck_ArrayInt( FALSE, 3 ); initialize_object( array, VM->env()->ckt_array, SHRED, VM ); // 1.5.0.0 (ge) added array->set( 0, 0 ); array->set( 1, 0 ); @@ -3376,13 +3376,13 @@ t_CKINT Chuck_IO_File::isDir() // name: dirList() // desc: ... //----------------------------------------------------------------------------- -Chuck_Array4 * Chuck_IO_File::dirList() +Chuck_ArrayInt * Chuck_IO_File::dirList() { // sanity if( !m_dir ) { EM_error3( "[chuck](via FileIO): cannot get list: no directory open" ); - Chuck_Array4 * ret = new Chuck_Array4( TRUE, 0 ); + Chuck_ArrayInt * ret = new Chuck_ArrayInt( TRUE, 0 ); initialize_object( ret, m_vmRef->env()->ckt_array, NULL, m_vmRef ); return ret; } @@ -3409,7 +3409,7 @@ Chuck_Array4 * Chuck_IO_File::dirList() } // make array - Chuck_Array4 * array = new Chuck_Array4( true, entrylist.size() ); + Chuck_ArrayInt * array = new Chuck_ArrayInt( true, entrylist.size() ); initialize_object( array, m_vmRef->env()->ckt_array, NULL, m_vmRef ); for( int i = 0; i < entrylist.size(); i++ ) array->set( i, (t_CKUINT)entrylist[i] ); @@ -5519,7 +5519,7 @@ void Chuck_IO_Serial::write( const t_CKVEC4 & val, t_CKINT flags ) this->write( val.w, flags ); } -void Chuck_IO_Serial::writeBytes( Chuck_Array4 * arr ) +void Chuck_IO_Serial::writeBytes( Chuck_ArrayInt * arr ) { if( !good() ) { @@ -5924,7 +5924,7 @@ t_CKBOOL Chuck_IO_Serial::handle_float_ascii(Chuck_IO_Serial::Request & r) { t_CKFLOAT val = 0; int numRead = 0; - Chuck_Array8 * array = new Chuck_Array8(0); + Chuck_ArrayFloat * array = new Chuck_ArrayFloat(0); for(int i = 0; i < r.m_num && !m_do_exit; i++) { @@ -5976,7 +5976,7 @@ t_CKBOOL Chuck_IO_Serial::handle_int_ascii(Chuck_IO_Serial::Request & r) { t_CKINT val = 0; int numRead = 0; - Chuck_Array4 * array = new Chuck_Array4(FALSE, 0); + Chuck_ArrayInt * array = new Chuck_ArrayInt(FALSE, 0); initialize_object( array, m_vmRef->env()->ckt_array, NULL, m_vmRef ); // 1.5.0.0 (ge) added for(int i = 0; i < r.m_num; i++) { @@ -6049,7 +6049,7 @@ t_CKBOOL Chuck_IO_Serial::handle_byte(Chuck_IO_Serial::Request & r) val = m_tmp_buf[0]; else { - Chuck_Array4 * array = new Chuck_Array4(FALSE, r.m_num); + Chuck_ArrayInt * array = new Chuck_ArrayInt(FALSE, r.m_num); initialize_object( array, m_vmRef->env()->ckt_array, NULL, m_vmRef ); // 1.5.0.0 (ge) added for(int i = 0; i < r.m_num; i++) { @@ -6092,7 +6092,7 @@ t_CKBOOL Chuck_IO_Serial::handle_float_binary(Chuck_IO_Serial::Request & r) t_CKUINT val = 0; t_CKSINGLE * m_floats = (t_CKSINGLE *) m_tmp_buf; - Chuck_Array8 * array = new Chuck_Array8(r.m_num); + Chuck_ArrayFloat * array = new Chuck_ArrayFloat(r.m_num); for(int i = 0; i < r.m_num; i++) { array->set(i, m_floats[i]); @@ -6126,7 +6126,7 @@ t_CKBOOL Chuck_IO_Serial::handle_int_binary(Chuck_IO_Serial::Request & r) t_CKUINT val = 0; uint32_t * m_ints = (uint32_t *) m_tmp_buf; - Chuck_Array4 * array = new Chuck_Array4(FALSE, r.m_num); + Chuck_ArrayInt * array = new Chuck_ArrayInt(FALSE, r.m_num); initialize_object( array, m_vmRef->env()->ckt_array, NULL, m_vmRef ); // 1.5.0.0 (ge) added for(int i = 0; i < r.m_num; i++) { @@ -6611,7 +6611,7 @@ CK_DLL_SFUN( serialio_list ) vector devices = SerialIOManager::availableSerialDevices(); // ISSUE: 64-bit - Chuck_Array4 * array = new Chuck_Array4(TRUE, 0); + Chuck_ArrayInt * array = new Chuck_ArrayInt(TRUE, 0); initialize_object( array, SHRED->vm_ref->env()->ckt_array, SHRED, VM ); for(vector::iterator i = devices.begin(); i != devices.end(); i++) @@ -6788,7 +6788,7 @@ CK_DLL_MFUN( serialio_writeByte ) CK_DLL_MFUN( serialio_writeBytes ) { Chuck_IO_Serial * cereal = (Chuck_IO_Serial *) SELF; - Chuck_Array4 * arr = (Chuck_Array4 *) GET_NEXT_OBJECT(ARGS); + Chuck_ArrayInt * arr = (Chuck_ArrayInt *) GET_NEXT_OBJECT(ARGS); cereal->writeBytes(arr); } diff --git a/src/core/chuck_io.h b/src/core/chuck_io.h index 358859b77..b0540dcc2 100644 --- a/src/core/chuck_io.h +++ b/src/core/chuck_io.h @@ -190,7 +190,7 @@ struct Chuck_IO_File : public Chuck_IO // directories virtual t_CKINT isDir(); - virtual Chuck_Array4 * dirList(); + virtual Chuck_ArrayInt * dirList(); // reading // virtual Chuck_String * read( t_CKINT length ); @@ -616,7 +616,7 @@ struct Chuck_IO_Serial : public Chuck_IO virtual void write( const std::string & val ); virtual void write( t_CKINT val ); virtual void write( t_CKINT val, t_CKINT flags ); - virtual void writeBytes( Chuck_Array4 * arr ); + virtual void writeBytes( Chuck_ArrayInt * arr ); virtual void write( t_CKFLOAT val ); virtual void write( t_CKFLOAT val, t_CKINT flags ); virtual void write( const t_CKCOMPLEX & val ); diff --git a/src/core/chuck_lang.cpp b/src/core/chuck_lang.cpp index 1d1727a72..6e00b06c4 100644 --- a/src/core/chuck_lang.cpp +++ b/src/core/chuck_lang.cpp @@ -1855,7 +1855,7 @@ CK_DLL_MFUN( uana_fval ) t_CKINT i = GET_NEXT_INT(ARGS); // get the fvals array Chuck_UAnaBlobProxy * blob = (Chuck_UAnaBlobProxy *)OBJ_MEMBER_INT(SELF, uana_offset_blob); - Chuck_Array8 & fvals = blob->fvals(); + Chuck_ArrayFloat & fvals = blob->fvals(); // check caps if( i < 0 || fvals.size() <= i ) RETURN->v_float = 0; else @@ -1927,10 +1927,10 @@ t_CKTIME & Chuck_UAnaBlobProxy::when() return OBJ_MEMBER_TIME(m_blob, uanablob_offset_when); } -Chuck_Array8 & Chuck_UAnaBlobProxy::fvals() +Chuck_ArrayFloat & Chuck_UAnaBlobProxy::fvals() { // TODO: DANGER: is this actually returning correct reference?! - Chuck_Array8 * arr8 = (Chuck_Array8 *)OBJ_MEMBER_INT(m_blob, uanablob_offset_fvals); + Chuck_ArrayFloat * arr8 = (Chuck_ArrayFloat *)OBJ_MEMBER_INT(m_blob, uanablob_offset_fvals); assert( arr8 != NULL ); return *arr8; } @@ -1956,7 +1956,7 @@ CK_DLL_CTOR( uanablob_ctor ) OBJ_MEMBER_TIME(SELF, uanablob_offset_when) = 0; // fvals - Chuck_Array8 * arr8 = new Chuck_Array8( 8 ); + Chuck_ArrayFloat * arr8 = new Chuck_ArrayFloat( 8 ); initialize_object( arr8, SHRED->vm_ref->env()->ckt_array, SHRED, VM ); arr8->add_ref(); OBJ_MEMBER_INT(SELF, uanablob_offset_fvals) = (t_CKINT)arr8; @@ -1972,7 +1972,7 @@ CK_DLL_CTOR( uanablob_ctor ) CK_DLL_DTOR( uanablob_dtor ) { // get array - Chuck_Array8 * arr8 = (Chuck_Array8 *)OBJ_MEMBER_INT(SELF, uanablob_offset_fvals); + Chuck_ArrayFloat * arr8 = (Chuck_ArrayFloat *)OBJ_MEMBER_INT(SELF, uanablob_offset_fvals); // release it arr8->release(); OBJ_MEMBER_INT(SELF, uanablob_offset_fvals) = 0; @@ -1995,7 +1995,7 @@ CK_DLL_MFUN( uanablob_when ) CK_DLL_MFUN( uanablob_fvals ) { // set return - RETURN->v_object = (Chuck_Array8 *)OBJ_MEMBER_INT(SELF, uanablob_offset_fvals); + RETURN->v_object = (Chuck_ArrayFloat *)OBJ_MEMBER_INT(SELF, uanablob_offset_fvals); } CK_DLL_MFUN( uanablob_fval ) @@ -2003,7 +2003,7 @@ CK_DLL_MFUN( uanablob_fval ) // get index t_CKINT i = GET_NEXT_INT(ARGS); // get the fvals array - Chuck_Array8 * fvals = (Chuck_Array8 *)OBJ_MEMBER_INT(SELF, uanablob_offset_fvals); + Chuck_ArrayFloat * fvals = (Chuck_ArrayFloat *)OBJ_MEMBER_INT(SELF, uanablob_offset_fvals); // check caps if( i < 0 || fvals->size() <= i ) RETURN->v_float = 0; else @@ -3003,9 +3003,9 @@ CK_DLL_MFUN( array_push_back ) Chuck_Array * array = (Chuck_Array *)SELF; // ISSUE: 64-bit (fixed 1.3.1.0 using data kind) if( array->data_type_kind() == CHUCK_ARRAY4_DATAKIND ) - RETURN->v_int = ((Chuck_Array4 *)array)->push_back( GET_NEXT_UINT( ARGS ) ); + RETURN->v_int = ((Chuck_ArrayInt *)array)->push_back( GET_NEXT_UINT( ARGS ) ); else if( array->data_type_kind() == CHUCK_ARRAY8_DATAKIND ) - RETURN->v_int = ((Chuck_Array8 *)array)->push_back( GET_NEXT_FLOAT( ARGS ) ); + 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 ) ); else if( array->data_type_kind() == CHUCK_ARRAY24_DATAKIND ) @@ -3025,9 +3025,9 @@ CK_DLL_MFUN( array_insert ) // ISSUE: 64-bit (fixed 1.3.1.0 using data kind) if( array->data_type_kind() == CHUCK_ARRAY4_DATAKIND ) - RETURN->v_int = ((Chuck_Array4 *)array)->insert( position, GET_NEXT_UINT( ARGS ) ); + RETURN->v_int = ((Chuck_ArrayInt *)array)->insert( position, GET_NEXT_UINT( ARGS ) ); else if( array->data_type_kind() == CHUCK_ARRAY8_DATAKIND ) - RETURN->v_int = ((Chuck_Array8 *)array)->insert( position, GET_NEXT_FLOAT( ARGS ) ); + 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 ) ); else if( array->data_type_kind() == CHUCK_ARRAY24_DATAKIND ) @@ -3052,9 +3052,9 @@ CK_DLL_MFUN( array_push_front ) Chuck_Array * array = (Chuck_Array *)SELF; // ISSUE: 64-bit (fixed 1.3.1.0 using data kind) if( array->data_type_kind() == CHUCK_ARRAY4_DATAKIND ) - RETURN->v_int = ((Chuck_Array4 *)array)->push_front( GET_NEXT_UINT( ARGS ) ); + RETURN->v_int = ((Chuck_ArrayInt *)array)->push_front( GET_NEXT_UINT( ARGS ) ); else if( array->data_type_kind() == CHUCK_ARRAY8_DATAKIND ) - RETURN->v_int = ((Chuck_Array8 *)array)->push_front( GET_NEXT_FLOAT( ARGS ) ); + 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 ) ); else if( array->data_type_kind() == CHUCK_ARRAY24_DATAKIND ) @@ -3093,7 +3093,7 @@ CK_DLL_MFUN( array_erase2 ) CK_DLL_MFUN( array_get_keys ) { Chuck_Array * array = (Chuck_Array *)SELF; - Chuck_Array4 * returned_keys = (Chuck_Array4 *) GET_NEXT_OBJECT(ARGS); + Chuck_ArrayInt * returned_keys = (Chuck_ArrayInt *) GET_NEXT_OBJECT(ARGS); // clear return array returned_keys->set_size(0); @@ -3125,7 +3125,7 @@ CK_DLL_MFUN( array_reverse ) //----------------------------------------------------------------------------- static void typeGetTypes( Chuck_VM * vm, - Chuck_Array4 * ret, + Chuck_ArrayInt * ret, t_CKBOOL isObj, t_CKBOOL isPrim, t_CKBOOL isSpecial, @@ -3272,7 +3272,7 @@ CK_DLL_MFUN( type_children ) string name = me->base_name; // instantiate - Chuck_Array4 * ret = new Chuck_Array4( TRUE ); + Chuck_ArrayInt * ret = new Chuck_ArrayInt( TRUE ); initialize_object( ret, VM->env()->ckt_array, SHRED, VM ); // results @@ -3432,7 +3432,7 @@ CK_DLL_SFUN( type_typeOf_vec4 ) CK_DLL_SFUN( type_getTypes ) { // instantiate - Chuck_Array4 * array = new Chuck_Array4( TRUE ); + Chuck_ArrayInt * array = new Chuck_ArrayInt( TRUE ); initialize_object( array, VM->env()->ckt_array, SHRED, VM ); // get args @@ -3457,7 +3457,7 @@ CK_DLL_SFUN( type_getTypes ) CK_DLL_SFUN( type_getTypes2 ) { // instantiate - Chuck_Array4 * array = new Chuck_Array4( TRUE ); + Chuck_ArrayInt * array = new Chuck_ArrayInt( TRUE ); initialize_object( array, VM->env()->ckt_array, SHRED, VM ); // get args @@ -3478,7 +3478,7 @@ CK_DLL_SFUN( type_getTypes2 ) CK_DLL_SFUN( type_getTypesAll ) { // instantiate - Chuck_Array4 * array = new Chuck_Array4( TRUE ); + Chuck_ArrayInt * array = new Chuck_ArrayInt( TRUE ); initialize_object( array, VM->env()->ckt_array, SHRED, VM ); // get all types diff --git a/src/core/chuck_lang.h b/src/core/chuck_lang.h index deee7cf50..35fed14fe 100644 --- a/src/core/chuck_lang.h +++ b/src/core/chuck_lang.h @@ -137,7 +137,7 @@ struct Chuck_UAnaBlobProxy public: t_CKTIME & when(); - Chuck_Array8 & fvals(); + Chuck_ArrayFloat & fvals(); Chuck_Array16 & cvals(); public: diff --git a/src/core/chuck_oo.cpp b/src/core/chuck_oo.cpp index a60d874a1..32047723c 100644 --- a/src/core/chuck_oo.cpp +++ b/src/core/chuck_oo.cpp @@ -379,10 +379,10 @@ Chuck_Array::~Chuck_Array() { } //----------------------------------------------------------------------------- -// name: Chuck_Array4() +// name: Chuck_ArrayInt() // desc: constructor //----------------------------------------------------------------------------- -Chuck_Array4::Chuck_Array4( t_CKBOOL is_obj, t_CKINT capacity ) +Chuck_ArrayInt::Chuck_ArrayInt( t_CKBOOL is_obj, t_CKINT capacity ) { // sanity check assert( capacity >= 0 ); @@ -399,10 +399,10 @@ Chuck_Array4::Chuck_Array4( t_CKBOOL is_obj, t_CKINT capacity ) //----------------------------------------------------------------------------- -// name: ~Chuck_Array4() +// name: ~Chuck_ArrayInt() // desc: destructor //----------------------------------------------------------------------------- -Chuck_Array4::~Chuck_Array4() +Chuck_ArrayInt::~Chuck_ArrayInt() { // 1.4.2.0 (ge) | added, which should cascade to nested array objects clear(); @@ -415,7 +415,7 @@ Chuck_Array4::~Chuck_Array4() // name: addr() // desc: return address of element at position i, as an int //----------------------------------------------------------------------------- -t_CKUINT Chuck_Array4::addr( t_CKINT i ) +t_CKUINT Chuck_ArrayInt::addr( t_CKINT i ) { // bound check if( i < 0 || i >= m_vector.capacity() ) @@ -432,7 +432,7 @@ t_CKUINT Chuck_Array4::addr( t_CKINT i ) // name: addr() // desc: return address of element at key, as an int //----------------------------------------------------------------------------- -t_CKUINT Chuck_Array4::addr( const string & key ) +t_CKUINT Chuck_ArrayInt::addr( const string & key ) { // get the addr return (t_CKUINT)(&m_map[key]); @@ -445,7 +445,7 @@ t_CKUINT Chuck_Array4::addr( const string & key ) // name: get() // desc: get value of element at position i //----------------------------------------------------------------------------- -t_CKINT Chuck_Array4::get( t_CKINT i, t_CKUINT * val ) +t_CKINT Chuck_ArrayInt::get( t_CKINT i, t_CKUINT * val ) { // bound check if( i < 0 || i >= m_vector.capacity() ) @@ -465,7 +465,7 @@ t_CKINT Chuck_Array4::get( t_CKINT i, t_CKUINT * val ) // name: get() // desc: get value of element at key //----------------------------------------------------------------------------- -t_CKINT Chuck_Array4::get( const string & key, t_CKUINT * val ) +t_CKINT Chuck_ArrayInt::get( const string & key, t_CKUINT * val ) { // set to zero *val = 0; @@ -485,7 +485,7 @@ t_CKINT Chuck_Array4::get( const string & key, t_CKUINT * val ) // name: set() // desc: set element of array by position, with ref counting as applicable //----------------------------------------------------------------------------- -t_CKINT Chuck_Array4::set( t_CKINT i, t_CKUINT val ) +t_CKINT Chuck_ArrayInt::set( t_CKINT i, t_CKUINT val ) { // bound check if( i < 0 || i >= m_vector.capacity() ) @@ -514,7 +514,7 @@ t_CKINT Chuck_Array4::set( t_CKINT i, t_CKUINT val ) // name: set() // desc: set element of map by key, with ref counting as applicable //----------------------------------------------------------------------------- -t_CKINT Chuck_Array4::set( const string & key, t_CKUINT val ) +t_CKINT Chuck_ArrayInt::set( const string & key, t_CKUINT val ) { map::iterator iter = m_map.find( key ); @@ -539,7 +539,7 @@ t_CKINT Chuck_Array4::set( const string & key, t_CKUINT val ) // name: insert() | 1.5.0.8 (ge) added // desc: insert before position | O(n) running time //----------------------------------------------------------------------------- -t_CKINT Chuck_Array4::insert( t_CKINT i, t_CKUINT val ) +t_CKINT Chuck_ArrayInt::insert( t_CKINT i, t_CKUINT val ) { // bound check if( i < 0 || i >= m_vector.capacity() ) @@ -562,7 +562,7 @@ t_CKINT Chuck_Array4::insert( t_CKINT i, t_CKUINT val ) // name: map_find() // desc: (map only) test if key is in map //----------------------------------------------------------------------------- -t_CKINT Chuck_Array4::map_find( const string & key ) +t_CKINT Chuck_ArrayInt::map_find( const string & key ) { return m_map.find( key ) != m_map.end(); } @@ -574,7 +574,7 @@ t_CKINT Chuck_Array4::map_find( const string & key ) // name: erase() // desc: (map only) erase element by key //----------------------------------------------------------------------------- -t_CKINT Chuck_Array4::map_erase( const string & key ) +t_CKINT Chuck_ArrayInt::map_erase( const string & key ) { map::iterator iter = m_map.find( key ); t_CKINT v = iter != m_map.end(); @@ -596,7 +596,7 @@ t_CKINT Chuck_Array4::map_erase( const string & key ) // name: push_back() // desc: append element by value //----------------------------------------------------------------------------- -t_CKINT Chuck_Array4::push_back( t_CKUINT val ) +t_CKINT Chuck_ArrayInt::push_back( t_CKUINT val ) { // if obj, reference count it (added 1.3.0.0) if( m_is_obj && val ) ((Chuck_Object *)val)->add_ref(); @@ -614,7 +614,7 @@ t_CKINT Chuck_Array4::push_back( t_CKUINT val ) // name: pop_back() // desc: pop the last element in vector //----------------------------------------------------------------------------- -t_CKINT Chuck_Array4::pop_back() +t_CKINT Chuck_ArrayInt::pop_back() { // check if( m_vector.size() == 0 ) @@ -644,7 +644,7 @@ t_CKINT Chuck_Array4::pop_back() // name: push_front() | 1.5.0.8 (ge) added // desc: prepend element by value | O(n) running time //----------------------------------------------------------------------------- -t_CKINT Chuck_Array4::push_front( t_CKUINT val ) +t_CKINT Chuck_ArrayInt::push_front( t_CKUINT val ) { // if obj, reference count it (added 1.3.0.0) if( m_is_obj && val ) ((Chuck_Object *)val)->add_ref(); @@ -662,7 +662,7 @@ t_CKINT Chuck_Array4::push_front( t_CKUINT val ) // name: pop_front() | 1.5.0.8 (ge) added // desc: pop the last element in vector | O(n) running time //----------------------------------------------------------------------------- -t_CKINT Chuck_Array4::pop_front() +t_CKINT Chuck_ArrayInt::pop_front() { // check if( m_vector.size() == 0 ) @@ -690,7 +690,7 @@ t_CKINT Chuck_Array4::pop_front() // name: erase() // desc: erase element by position //----------------------------------------------------------------------------- -t_CKINT Chuck_Array4::erase( t_CKINT pos ) +t_CKINT Chuck_ArrayInt::erase( t_CKINT pos ) { // check if( m_vector.size() == 0 || pos < 0 || pos >= m_vector.size() ) @@ -717,7 +717,7 @@ t_CKINT Chuck_Array4::erase( t_CKINT pos ) // name: erase() // desc: erase a range of elements [begin,end) //----------------------------------------------------------------------------- -t_CKINT Chuck_Array4::erase( t_CKINT begin, t_CKINT end ) +t_CKINT Chuck_ArrayInt::erase( t_CKINT begin, t_CKINT end ) { // if needed swap the two if( begin > end ) { t_CKINT temp = begin; begin = end; end = temp; } @@ -756,7 +756,7 @@ t_CKINT Chuck_Array4::erase( t_CKINT begin, t_CKINT end ) // name: get_keys() | 1.4.1.1 nshaheed (added) // desc: return vector of keys from associative array //----------------------------------------------------------------------------- -void Chuck_Array4::get_keys( std::vector & keys ) +void Chuck_ArrayInt::get_keys( std::vector & keys ) { // clear the return array keys.clear(); @@ -792,7 +792,7 @@ static void my_random_shuffle( RandomIt first, RandomIt last ) // name: shuffle() | 1.5.0.0 nshaheed, azaday, kunwoo, ge (added) // desc: shuffle the contents of the array //----------------------------------------------------------------------------- -void Chuck_Array4::shuffle() +void Chuck_ArrayInt::shuffle() { my_random_shuffle( m_vector.begin(), m_vector.end() ); } @@ -804,7 +804,7 @@ void Chuck_Array4::shuffle() // name: reverse() // desc: reverses array in-place //----------------------------------------------------------------------------- -void Chuck_Array4::reverse() +void Chuck_ArrayInt::reverse() { std::reverse( m_vector.begin(), m_vector.end() ); } @@ -825,7 +825,7 @@ static bool ck_compare_sint( t_CKUINT lhs, t_CKUINT rhs ) // name: sort() // desc: sort the array in ascending order //----------------------------------------------------------------------------- -void Chuck_Array4::sort() +void Chuck_ArrayInt::sort() { // if object references sort as unsigned if( m_is_obj ) std::sort( m_vector.begin(), m_vector.end() ); @@ -840,7 +840,7 @@ void Chuck_Array4::sort() // name: back() // desc: ... //----------------------------------------------------------------------------- -t_CKINT Chuck_Array4::back( t_CKUINT * val ) const +t_CKINT Chuck_ArrayInt::back( t_CKUINT * val ) const { // check if( m_vector.size() == 0 ) @@ -859,7 +859,7 @@ t_CKINT Chuck_Array4::back( t_CKUINT * val ) const // name: clear() // desc: ... //----------------------------------------------------------------------------- -void Chuck_Array4::clear( ) +void Chuck_ArrayInt::clear( ) { // zero zero( 0, m_vector.size() ); @@ -875,7 +875,7 @@ void Chuck_Array4::clear( ) // name: set_capacity() // desc: ... //----------------------------------------------------------------------------- -t_CKINT Chuck_Array4::set_capacity( t_CKINT capacity ) +t_CKINT Chuck_ArrayInt::set_capacity( t_CKINT capacity ) { // sanity check assert( capacity >= 0 ); @@ -912,7 +912,7 @@ t_CKINT Chuck_Array4::set_capacity( t_CKINT capacity ) // name: set_size() // desc: ... //----------------------------------------------------------------------------- -t_CKINT Chuck_Array4::set_size( t_CKINT size ) +t_CKINT Chuck_ArrayInt::set_size( t_CKINT size ) { // sanity check assert( size >= 0 ); @@ -946,7 +946,7 @@ t_CKINT Chuck_Array4::set_size( t_CKINT size ) // name: zero() // desc: ... //----------------------------------------------------------------------------- -void Chuck_Array4::zero( t_CKUINT start, t_CKUINT end ) +void Chuck_ArrayInt::zero( t_CKUINT start, t_CKUINT end ) { // sanity check assert( start <= m_vector.capacity() && end <= m_vector.capacity() ); @@ -981,10 +981,10 @@ void Chuck_Array4::zero( t_CKUINT start, t_CKUINT end ) //----------------------------------------------------------------------------- -// name: Chuck_Array8() +// name: Chuck_ArrayFloat() // desc: constructor //----------------------------------------------------------------------------- -Chuck_Array8::Chuck_Array8( t_CKINT capacity ) +Chuck_ArrayFloat::Chuck_ArrayFloat( t_CKINT capacity ) { // sanity check assert( capacity >= 0 ); @@ -998,10 +998,10 @@ Chuck_Array8::Chuck_Array8( t_CKINT capacity ) //----------------------------------------------------------------------------- -// name: ~Chuck_Array8() +// name: ~Chuck_ArrayFloat() // desc: destructor //----------------------------------------------------------------------------- -Chuck_Array8::~Chuck_Array8() +Chuck_ArrayFloat::~Chuck_ArrayFloat() { // do nothing clear(); @@ -1014,7 +1014,7 @@ Chuck_Array8::~Chuck_Array8() // name: addr() // desc: ... //----------------------------------------------------------------------------- -t_CKUINT Chuck_Array8::addr( t_CKINT i ) +t_CKUINT Chuck_ArrayFloat::addr( t_CKINT i ) { // bound check if( i < 0 || i >= m_vector.capacity() ) @@ -1031,7 +1031,7 @@ t_CKUINT Chuck_Array8::addr( t_CKINT i ) // name: addr() // desc: ... //----------------------------------------------------------------------------- -t_CKUINT Chuck_Array8::addr( const string & key ) +t_CKUINT Chuck_ArrayFloat::addr( const string & key ) { // get the addr return (t_CKUINT)(&m_map[key]); @@ -1044,7 +1044,7 @@ t_CKUINT Chuck_Array8::addr( const string & key ) // name: get() // desc: ... //----------------------------------------------------------------------------- -t_CKINT Chuck_Array8::get( t_CKINT i, t_CKFLOAT * val ) +t_CKINT Chuck_ArrayFloat::get( t_CKINT i, t_CKFLOAT * val ) { // bound check if( i < 0 || i >= m_vector.capacity() ) @@ -1064,7 +1064,7 @@ t_CKINT Chuck_Array8::get( t_CKINT i, t_CKFLOAT * val ) // name: get() // desc: ... //----------------------------------------------------------------------------- -t_CKINT Chuck_Array8::get( const string & key, t_CKFLOAT * val ) +t_CKINT Chuck_ArrayFloat::get( const string & key, t_CKFLOAT * val ) { // set to zero *val = 0.0; @@ -1090,7 +1090,7 @@ t_CKINT Chuck_Array8::get( const string & key, t_CKFLOAT * val ) // name: set() // desc: ... //----------------------------------------------------------------------------- -t_CKINT Chuck_Array8::set( t_CKINT i, t_CKFLOAT val ) +t_CKINT Chuck_ArrayFloat::set( t_CKINT i, t_CKFLOAT val ) { // bound check if( i < 0 || i >= m_vector.capacity() ) @@ -1110,7 +1110,7 @@ t_CKINT Chuck_Array8::set( t_CKINT i, t_CKFLOAT val ) // name: set() // desc: ... //----------------------------------------------------------------------------- -t_CKINT Chuck_Array8::set( const string & key, t_CKFLOAT val ) +t_CKINT Chuck_ArrayFloat::set( const string & key, t_CKFLOAT val ) { // 1.3.1.1: removed this // map::iterator iter = m_map.find( key ); @@ -1132,7 +1132,7 @@ t_CKINT Chuck_Array8::set( const string & key, t_CKFLOAT val ) // name: insert() | 1.5.0.8 (ge) added // desc: insert before position | O(n) running time //----------------------------------------------------------------------------- -t_CKINT Chuck_Array8::insert( t_CKINT i, t_CKFLOAT val ) +t_CKINT Chuck_ArrayFloat::insert( t_CKINT i, t_CKFLOAT val ) { // bound check if( i < 0 || i >= m_vector.capacity() ) @@ -1152,7 +1152,7 @@ t_CKINT Chuck_Array8::insert( t_CKINT i, t_CKFLOAT val ) // name: map_find() // desc: ... //----------------------------------------------------------------------------- -t_CKINT Chuck_Array8::map_find( const string & key ) +t_CKINT Chuck_ArrayFloat::map_find( const string & key ) { return m_map.find( key ) != m_map.end(); } @@ -1163,7 +1163,7 @@ t_CKINT Chuck_Array8::map_find( const string & key ) // name: map_erase() // desc: ... //----------------------------------------------------------------------------- -t_CKINT Chuck_Array8::map_erase( const string & key ) +t_CKINT Chuck_ArrayFloat::map_erase( const string & key ) { return m_map.erase( key ); } @@ -1175,7 +1175,7 @@ t_CKINT Chuck_Array8::map_erase( const string & key ) // name: push_back() // desc: ... //----------------------------------------------------------------------------- -t_CKINT Chuck_Array8::push_back( t_CKFLOAT val ) +t_CKINT Chuck_ArrayFloat::push_back( t_CKFLOAT val ) { // add to vector m_vector.push_back( val ); @@ -1190,7 +1190,7 @@ t_CKINT Chuck_Array8::push_back( t_CKFLOAT val ) // name: pop_back() // desc: ... //----------------------------------------------------------------------------- -t_CKINT Chuck_Array8::pop_back( ) +t_CKINT Chuck_ArrayFloat::pop_back( ) { // check if( m_vector.size() == 0 ) @@ -1211,7 +1211,7 @@ t_CKINT Chuck_Array8::pop_back( ) // name: push_front() | 1.5.0.8 (ge) added // desc: prepend element by value | O(n) running time //----------------------------------------------------------------------------- -t_CKINT Chuck_Array8::push_front( t_CKFLOAT val ) +t_CKINT Chuck_ArrayFloat::push_front( t_CKFLOAT val ) { // add to vector m_vector.insert( m_vector.begin(), val ); @@ -1226,7 +1226,7 @@ t_CKINT Chuck_Array8::push_front( t_CKFLOAT val ) // name: pop_front() | 1.5.0.8 (ge) added // desc: pop the last element in vector | O(n) running time //----------------------------------------------------------------------------- -t_CKINT Chuck_Array8::pop_front() +t_CKINT Chuck_ArrayFloat::pop_front() { // check if( m_vector.size() == 0 ) @@ -1245,7 +1245,7 @@ t_CKINT Chuck_Array8::pop_front() // name: pop_out() // desc: ... //----------------------------------------------------------------------------- -t_CKINT Chuck_Array8::erase( t_CKINT pos ) +t_CKINT Chuck_ArrayFloat::erase( t_CKINT pos ) { // check if ( m_vector.size() == 0 || pos<0 || pos>=m_vector.size()) @@ -1263,7 +1263,7 @@ t_CKINT Chuck_Array8::erase( t_CKINT pos ) // name: erase() // desc: erase a range of elements [begin,end) //----------------------------------------------------------------------------- -t_CKINT Chuck_Array8::erase( t_CKINT begin, t_CKINT end ) +t_CKINT Chuck_ArrayFloat::erase( t_CKINT begin, t_CKINT end ) { // if needed swap the two if( begin > end ) { t_CKINT temp = begin; begin = end; end = temp; } @@ -1289,7 +1289,7 @@ t_CKINT Chuck_Array8::erase( t_CKINT begin, t_CKINT end ) // name: get_keys() | 1.4.1.1 nshaheed (added) // desc: return vector of keys from associative array //----------------------------------------------------------------------------- -void Chuck_Array8::get_keys( std::vector & keys ) +void Chuck_ArrayFloat::get_keys( std::vector & keys ) { // clear the return array keys.clear(); @@ -1308,7 +1308,7 @@ void Chuck_Array8::get_keys( std::vector & keys ) // name: reverse() // desc: reverses array in-place //----------------------------------------------------------------------------- -void Chuck_Array8::reverse( ) +void Chuck_ArrayFloat::reverse( ) { std::reverse(m_vector.begin(), m_vector.end()); } @@ -1319,7 +1319,7 @@ void Chuck_Array8::reverse( ) // name: shuffle() | 1.5.0.0 nshaheed, azaday, kunwoo, ge (added) // desc: shuffle the contents of the array //----------------------------------------------------------------------------- -void Chuck_Array8::shuffle() +void Chuck_ArrayFloat::shuffle() { my_random_shuffle( m_vector.begin(), m_vector.end() ); } @@ -1331,7 +1331,7 @@ void Chuck_Array8::shuffle() // name: sort() // desc: sort the array in ascending order //----------------------------------------------------------------------------- -void Chuck_Array8::sort() +void Chuck_ArrayFloat::sort() { std::sort( m_vector.begin(), m_vector.end() ); } @@ -1343,7 +1343,7 @@ void Chuck_Array8::sort() // name: back() // desc: ... //----------------------------------------------------------------------------- -t_CKINT Chuck_Array8::back( t_CKFLOAT * val ) const +t_CKINT Chuck_ArrayFloat::back( t_CKFLOAT * val ) const { // check if( m_vector.size() == 0 ) @@ -1362,7 +1362,7 @@ t_CKINT Chuck_Array8::back( t_CKFLOAT * val ) const // name: clear() // desc: ... //----------------------------------------------------------------------------- -void Chuck_Array8::clear( ) +void Chuck_ArrayFloat::clear( ) { // zero zero( 0, m_vector.size() ); @@ -1378,7 +1378,7 @@ void Chuck_Array8::clear( ) // name: set_capacity() // desc: ... //----------------------------------------------------------------------------- -t_CKINT Chuck_Array8::set_capacity( t_CKINT capacity ) +t_CKINT Chuck_ArrayFloat::set_capacity( t_CKINT capacity ) { // sanity check assert( capacity >= 0 ); @@ -1396,7 +1396,7 @@ t_CKINT Chuck_Array8::set_capacity( t_CKINT capacity ) // name: set_size() // desc: ... //----------------------------------------------------------------------------- -t_CKINT Chuck_Array8::set_size( t_CKINT size ) +t_CKINT Chuck_ArrayFloat::set_size( t_CKINT size ) { // sanity check assert( size >= 0 ); @@ -1430,7 +1430,7 @@ t_CKINT Chuck_Array8::set_size( t_CKINT size ) // name: zero() // desc: ... //----------------------------------------------------------------------------- -void Chuck_Array8::zero( t_CKUINT start, t_CKUINT end ) +void Chuck_ArrayFloat::zero( t_CKUINT start, t_CKUINT end ) { // sanity check assert( start <= m_vector.capacity() && end <= m_vector.capacity() ); diff --git a/src/core/chuck_oo.h b/src/core/chuck_oo.h index 7d12ae57e..e7a8e1f02 100644 --- a/src/core/chuck_oo.h +++ b/src/core/chuck_oo.h @@ -186,7 +186,7 @@ struct Chuck_Object : public Chuck_VM_Object //----------------------------------------------------------------------------- // name: struct Chuck_Array // desc: native ChucK array (virtual base class) -// NOTE due to certain specialized operations, e.g., Array4 is also +// NOTE due to certain specialized operations, e.g., ArrayInt is also // used to hold and manage Object references, this class is currently // not templated (and probably cannot be fully templated). For this // reason, some functionalities that requires type-specific arguments @@ -256,14 +256,14 @@ struct Chuck_Array : public Chuck_Object //----------------------------------------------------------------------------- -// name: struct Chuck_Array4 +// name: struct Chuck_ArrayInt // desc: native ChucK arrays (for 4-byte/8-byte int, and Object references) //----------------------------------------------------------------------------- -struct Chuck_Array4 : public Chuck_Array +struct Chuck_ArrayInt : public Chuck_Array { public: - Chuck_Array4( t_CKBOOL is_obj, t_CKINT capacity = 8 ); - virtual ~Chuck_Array4(); + Chuck_ArrayInt( t_CKBOOL is_obj, t_CKINT capacity = 8 ); + virtual ~Chuck_ArrayInt(); public: // specific to this class // get address @@ -351,14 +351,14 @@ struct Chuck_Array4 : public Chuck_Array //----------------------------------------------------------------------------- -// name: struct Chuck_Array8 +// name: struct Chuck_ArrayFloat // desc: native ChucK arrays (for 8-byte float) //----------------------------------------------------------------------------- -struct Chuck_Array8 : public Chuck_Array +struct Chuck_ArrayFloat : public Chuck_Array { public: - Chuck_Array8( t_CKINT capacity = 8 ); - virtual ~Chuck_Array8(); + Chuck_ArrayFloat( t_CKINT capacity = 8 ); + virtual ~Chuck_ArrayFloat(); public: // specific to this class // get address diff --git a/src/core/chuck_ugen.cpp b/src/core/chuck_ugen.cpp index a7666b83f..42f92b457 100644 --- a/src/core/chuck_ugen.cpp +++ b/src/core/chuck_ugen.cpp @@ -1578,7 +1578,7 @@ t_CKBOOL Chuck_UAna::system_tock( t_CKTIME now ) t_CKINT ugen_generic_num_in( Chuck_Object * obj, t_CKBOOL isArray ) { if(isArray) - return ((Chuck_Array4 *) obj)->size(); + return ((Chuck_ArrayInt *) obj)->size(); else return ((Chuck_UGen *) obj)->m_num_ins; } @@ -1593,7 +1593,7 @@ Chuck_UGen *ugen_generic_get_src( Chuck_Object * obj, t_CKINT chan, t_CKBOOL isA { if( isArray ) { - Chuck_Array4 *arr = (Chuck_Array4 *) obj; + Chuck_ArrayInt *arr = (Chuck_ArrayInt *) obj; Chuck_UGen *src = NULL; arr->get( chan%arr->size(), (t_CKUINT *) &src ); return src; @@ -1614,9 +1614,9 @@ Chuck_UGen *ugen_generic_get_dst( Chuck_Object * obj, t_CKINT chan, t_CKBOOL isA { if( isArray ) { - Chuck_Array4 *arr = (Chuck_Array4 *) obj; + Chuck_ArrayInt *arr = (Chuck_ArrayInt *) obj; Chuck_UGen *dst = NULL; - ( (Chuck_Array4 *) obj )->get( chan%arr->size(), (t_CKUINT *) &dst ); + ( (Chuck_ArrayInt *) obj )->get( chan%arr->size(), (t_CKUINT *) &dst ); return dst; } else diff --git a/src/core/uana_extract.cpp b/src/core/uana_extract.cpp index afe64e3b0..954a1487b 100644 --- a/src/core/uana_extract.cpp +++ b/src/core/uana_extract.cpp @@ -720,12 +720,12 @@ CK_DLL_TOCK( FeatureCollector_tock ) // sanity check assert( BLOB_IN != NULL ); // count number of features from this UAna - Chuck_Array8 & these_fvals = BLOB_IN->fvals(); + Chuck_ArrayFloat & these_fvals = BLOB_IN->fvals(); num_feats += these_fvals.size(); } // get fvals of output BLOB - Chuck_Array8 & fvals = BLOB->fvals(); + Chuck_ArrayFloat & fvals = BLOB->fvals(); if( fvals.size() != num_feats ) fvals.set_size( num_feats ); @@ -734,7 +734,7 @@ CK_DLL_TOCK( FeatureCollector_tock ) { // get next blob Chuck_UAnaBlobProxy * BLOB_IN = UANA->getIncomingBlob( i ); - Chuck_Array8 & these_fvals = BLOB_IN->fvals(); + Chuck_ArrayFloat & these_fvals = BLOB_IN->fvals(); t_CKINT num_these = these_fvals.size(); for( j = 0; j < num_these; j++ ) { @@ -760,7 +760,7 @@ CK_DLL_PMSG( FeatureCollector_pmsg ) return TRUE; } -static t_CKFLOAT compute_centroid( Chuck_Array8 & buffer, t_CKUINT size ) +static t_CKFLOAT compute_centroid( Chuck_ArrayFloat & buffer, t_CKUINT size ) { t_CKFLOAT m0 = 0.0; t_CKFLOAT m1 = 0.0; @@ -802,7 +802,7 @@ CK_DLL_TOCK( Centroid_tock ) // sanity check assert( BLOB_IN != NULL ); // get the array - Chuck_Array8 & mag = BLOB_IN->fvals(); + Chuck_ArrayFloat & mag = BLOB_IN->fvals(); // compute centroid result = compute_centroid( mag, mag.size() ); } @@ -814,7 +814,7 @@ CK_DLL_TOCK( Centroid_tock ) } // get fvals of output BLOB - Chuck_Array8 & fvals = BLOB->fvals(); + Chuck_ArrayFloat & fvals = BLOB->fvals(); // ensure size == resulting size if( fvals.size() != 1 ) fvals.set_size( 1 ); @@ -833,7 +833,7 @@ CK_DLL_PMSG( Centroid_pmsg ) CK_DLL_SFUN( Centroid_compute ) { // get array - Chuck_Array8 * array = (Chuck_Array8 *)GET_NEXT_OBJECT( ARGS ); + Chuck_ArrayFloat * array = (Chuck_ArrayFloat *)GET_NEXT_OBJECT( ARGS ); // sanity check if( !array ) { @@ -850,8 +850,8 @@ CK_DLL_SFUN( Centroid_compute ) // Flux state struct StateOfFlux { - Chuck_Array8 prev; - Chuck_Array8 norm; + Chuck_ArrayFloat prev; + Chuck_ArrayFloat norm; t_CKBOOL initialized; StateOfFlux() @@ -861,7 +861,7 @@ struct StateOfFlux }; // compute norm rms -static void compute_norm_rms( Chuck_Array8 & curr, Chuck_Array8 & norm ) +static void compute_norm_rms( Chuck_ArrayFloat & curr, Chuck_ArrayFloat & norm ) { t_CKUINT i; t_CKFLOAT energy = 0.0; @@ -899,7 +899,7 @@ static void compute_norm_rms( Chuck_Array8 & curr, Chuck_Array8 & norm ) } // compute flux -static t_CKFLOAT compute_flux( Chuck_Array8 & curr, Chuck_Array8 & prev, Chuck_Array8 * write ) +static t_CKFLOAT compute_flux( Chuck_ArrayFloat & curr, Chuck_ArrayFloat & prev, Chuck_ArrayFloat * write ) { // sanity check assert( curr.size() == prev.size() ); @@ -925,7 +925,7 @@ static t_CKFLOAT compute_flux( Chuck_Array8 & curr, Chuck_Array8 & prev, Chuck_A } // compute flux -static t_CKFLOAT compute_flux( Chuck_Array8 & curr, StateOfFlux & sof ) +static t_CKFLOAT compute_flux( Chuck_ArrayFloat & curr, StateOfFlux & sof ) { // flux t_CKFLOAT result = 0.0; @@ -1003,7 +1003,7 @@ CK_DLL_TOCK( Flux_tock ) // sanity check assert( BLOB_IN != NULL ); // get the array - Chuck_Array8 & mag = BLOB_IN->fvals(); + Chuck_ArrayFloat & mag = BLOB_IN->fvals(); // compute flux result = compute_flux( mag, *state ); } @@ -1015,7 +1015,7 @@ CK_DLL_TOCK( Flux_tock ) } // get fvals of output BLOB - Chuck_Array8 & fvals = BLOB->fvals(); + Chuck_ArrayFloat & fvals = BLOB->fvals(); // ensure size == resulting size if( fvals.size() != 1 ) fvals.set_size( 1 ); @@ -1042,8 +1042,8 @@ CK_DLL_MFUN( Flux_ctrl_reset ) CK_DLL_SFUN( Flux_compute ) { // get inputs - Chuck_Array8 * lhs = (Chuck_Array8 *)GET_NEXT_OBJECT( ARGS ); - Chuck_Array8 * rhs = (Chuck_Array8 *)GET_NEXT_OBJECT( ARGS ); + Chuck_ArrayFloat * lhs = (Chuck_ArrayFloat *)GET_NEXT_OBJECT( ARGS ); + Chuck_ArrayFloat * rhs = (Chuck_ArrayFloat *)GET_NEXT_OBJECT( ARGS ); // verify if( !lhs || !rhs ) @@ -1072,9 +1072,9 @@ CK_DLL_SFUN( Flux_compute ) CK_DLL_SFUN( Flux_compute2 ) { // get inputs - Chuck_Array8 * lhs = (Chuck_Array8 *)GET_NEXT_OBJECT( ARGS ); - Chuck_Array8 * rhs = (Chuck_Array8 *)GET_NEXT_OBJECT( ARGS ); - Chuck_Array8 * diff = (Chuck_Array8 *)GET_NEXT_OBJECT( ARGS ); + Chuck_ArrayFloat * lhs = (Chuck_ArrayFloat *)GET_NEXT_OBJECT( ARGS ); + Chuck_ArrayFloat * rhs = (Chuck_ArrayFloat *)GET_NEXT_OBJECT( ARGS ); + Chuck_ArrayFloat * diff = (Chuck_ArrayFloat *)GET_NEXT_OBJECT( ARGS ); // verify if( !lhs || !rhs ) @@ -1100,7 +1100,7 @@ CK_DLL_SFUN( Flux_compute2 ) } } -static t_CKFLOAT compute_rms( Chuck_Array8 & buffer, t_CKUINT size ) +static t_CKFLOAT compute_rms( Chuck_ArrayFloat & buffer, t_CKUINT size ) { t_CKFLOAT rms = 0.0; t_CKFLOAT v; @@ -1138,7 +1138,7 @@ CK_DLL_TOCK( RMS_tock ) // sanity check assert( BLOB_IN != NULL ); // get the array - Chuck_Array8 & mag = BLOB_IN->fvals(); + Chuck_ArrayFloat & mag = BLOB_IN->fvals(); // compute RMS result = compute_rms( mag, mag.size() ); } @@ -1150,7 +1150,7 @@ CK_DLL_TOCK( RMS_tock ) } // get fvals of output BLOB - Chuck_Array8 & fvals = BLOB->fvals(); + Chuck_ArrayFloat & fvals = BLOB->fvals(); // ensure size == resulting size if( fvals.size() != 1 ) fvals.set_size( 1 ); @@ -1169,7 +1169,7 @@ CK_DLL_PMSG( RMS_pmsg ) CK_DLL_SFUN( RMS_compute ) { // get array - Chuck_Array8 * array = (Chuck_Array8 *)GET_NEXT_OBJECT( ARGS ); + Chuck_ArrayFloat * array = (Chuck_ArrayFloat *)GET_NEXT_OBJECT( ARGS ); // sanity check if( !array ) { @@ -1411,7 +1411,7 @@ struct MFCC_Object MFCC_Object * MFCC_Object::ourMFCC = NULL; // compute mfcc -static void compute_mfcc( MFCC_Object * mfcc, Chuck_Array8 & f, t_CKUINT fs, Chuck_Array8 & buffy ) +static void compute_mfcc( MFCC_Object * mfcc, Chuck_ArrayFloat & f, t_CKUINT fs, Chuck_ArrayFloat & buffy ) { t_CKUINT i; t_CKFLOAT v; @@ -1472,9 +1472,9 @@ CK_DLL_TOCK( MFCC_tock ) // sanity check assert( BLOB_IN != NULL ); // get the array - Chuck_Array8 & mag = BLOB_IN->fvals(); + Chuck_ArrayFloat & mag = BLOB_IN->fvals(); // get fvals of output BLOB - Chuck_Array8 & fvals = BLOB->fvals(); + Chuck_ArrayFloat & fvals = BLOB->fvals(); // compute MFCC compute_mfcc( mfcc, mag, mag.size(), fvals ); } @@ -1482,7 +1482,7 @@ CK_DLL_TOCK( MFCC_tock ) else { // get fvals of output BLOB - Chuck_Array8 & fvals = BLOB->fvals(); + Chuck_ArrayFloat & fvals = BLOB->fvals(); // resize fvals.set_size( 0 ); } @@ -1555,14 +1555,14 @@ CK_DLL_MFUN( MFCC_compute ) // get object MFCC_Object * mfcc = (MFCC_Object *)OBJ_MEMBER_UINT( SELF, MFCC_offset_data ); // get input - Chuck_Array8 * input = (Chuck_Array8 *)GET_NEXT_OBJECT( ARGS ); + Chuck_ArrayFloat * input = (Chuck_ArrayFloat *)GET_NEXT_OBJECT( ARGS ); // get output - Chuck_Array8 * output = (Chuck_Array8 *)GET_NEXT_OBJECT( ARGS ); + Chuck_ArrayFloat * output = (Chuck_ArrayFloat *)GET_NEXT_OBJECT( ARGS ); // compute mfcc compute_mfcc( mfcc, *input, input->size(), *output ); } -static t_CKFLOAT compute_kurtosis( Chuck_Array8 & input ) +static t_CKFLOAT compute_kurtosis( Chuck_ArrayFloat & input ) { t_CKINT i; t_CKFLOAT z = 0.0, mean = 0.0, q = 0.0, b; @@ -1608,7 +1608,7 @@ CK_DLL_TOCK( Kurtosis_tock ) // sanity check assert( BLOB_IN != NULL ); // get the array - Chuck_Array8 & mag = BLOB_IN->fvals(); + Chuck_ArrayFloat & mag = BLOB_IN->fvals(); // compute Kurtosis result = compute_kurtosis( mag ); } @@ -1620,7 +1620,7 @@ CK_DLL_TOCK( Kurtosis_tock ) } // get fvals of output BLOB - Chuck_Array8 & fvals = BLOB->fvals(); + Chuck_ArrayFloat & fvals = BLOB->fvals(); // ensure size == resulting size if( fvals.size() != 1 ) fvals.set_size( 1 ); @@ -1639,7 +1639,7 @@ CK_DLL_PMSG( Kurtosis_pmsg ) CK_DLL_SFUN( Kurtosis_compute ) { // get array - Chuck_Array8 * array = (Chuck_Array8 *)GET_NEXT_OBJECT( ARGS ); + Chuck_ArrayFloat * array = (Chuck_ArrayFloat *)GET_NEXT_OBJECT( ARGS ); // sanity check if( !array ) { @@ -1772,7 +1772,7 @@ struct SFM_Object SFM_Object * SFM_Object::ourSFM = NULL; // compute sfm -static void compute_sfm( SFM_Object * sfm, Chuck_Array8 & input, Chuck_Array8 & output ) +static void compute_sfm( SFM_Object * sfm, Chuck_ArrayFloat & input, Chuck_ArrayFloat & output ) { // update sfm->update( input.size() ); @@ -1848,9 +1848,9 @@ CK_DLL_TOCK( SFM_tock ) // sanity check assert( BLOB_IN != NULL ); // get the array - Chuck_Array8 & mag = BLOB_IN->fvals(); + Chuck_ArrayFloat & mag = BLOB_IN->fvals(); // get fvals of output BLOB - Chuck_Array8 & fvals = BLOB->fvals(); + Chuck_ArrayFloat & fvals = BLOB->fvals(); // compute SFM compute_sfm( sfm, mag, fvals ); } @@ -1858,7 +1858,7 @@ CK_DLL_TOCK( SFM_tock ) else { // get fvals of output BLOB - Chuck_Array8 & fvals = BLOB->fvals(); + Chuck_ArrayFloat & fvals = BLOB->fvals(); // resize fvals.set_size( 0 ); } @@ -1895,9 +1895,9 @@ CK_DLL_MFUN( SFM_compute ) // get object SFM_Object * sfm = (SFM_Object *)OBJ_MEMBER_UINT( SELF, SFM_offset_data ); // get input - Chuck_Array8 * input = (Chuck_Array8 *)GET_NEXT_OBJECT( ARGS ); + Chuck_ArrayFloat * input = (Chuck_ArrayFloat *)GET_NEXT_OBJECT( ARGS ); // get output - Chuck_Array8 * output = (Chuck_Array8 *)GET_NEXT_OBJECT( ARGS ); + Chuck_ArrayFloat * output = (Chuck_ArrayFloat *)GET_NEXT_OBJECT( ARGS ); // compute sfm compute_sfm( sfm, *input, *output ); } @@ -2056,7 +2056,7 @@ struct Chroma_Object Chroma_Object * Chroma_Object::ourChroma = NULL; // compute chroma -static void compute_chroma( Chroma_Object * chroma, Chuck_Array8 & input, Chuck_Array8 & output ) +static void compute_chroma( Chroma_Object * chroma, Chuck_ArrayFloat & input, Chuck_ArrayFloat & output ) { // prepare chroma->update( input.size() ); @@ -2105,9 +2105,9 @@ CK_DLL_TOCK( Chroma_tock ) // sanity check assert( BLOB_IN != NULL ); // get the array - Chuck_Array8 & mag = BLOB_IN->fvals(); + Chuck_ArrayFloat & mag = BLOB_IN->fvals(); // get fvals of output BLOB - Chuck_Array8 & fvals = BLOB->fvals(); + Chuck_ArrayFloat & fvals = BLOB->fvals(); // compute Chroma compute_chroma( chroma, mag, fvals ); } @@ -2115,7 +2115,7 @@ CK_DLL_TOCK( Chroma_tock ) else { // get fvals of output BLOB - Chuck_Array8 & fvals = BLOB->fvals(); + Chuck_ArrayFloat & fvals = BLOB->fvals(); // resize fvals.set_size( 0 ); } @@ -2197,14 +2197,14 @@ CK_DLL_MFUN( Chroma_compute ) // get object Chroma_Object * chroma = (Chroma_Object *)OBJ_MEMBER_UINT( SELF, Chroma_offset_data ); // get input - Chuck_Array8 * input = (Chuck_Array8 *)GET_NEXT_OBJECT( ARGS ); + Chuck_ArrayFloat * input = (Chuck_ArrayFloat *)GET_NEXT_OBJECT( ARGS ); // get output - Chuck_Array8 * output = (Chuck_Array8 *)GET_NEXT_OBJECT( ARGS ); + Chuck_ArrayFloat * output = (Chuck_ArrayFloat *)GET_NEXT_OBJECT( ARGS ); // compute chroma compute_chroma( chroma, *input, *output ); } -static t_CKFLOAT compute_rolloff( Chuck_Array8 & buffer, t_CKUINT size, t_CKFLOAT percent ) +static t_CKFLOAT compute_rolloff( Chuck_ArrayFloat & buffer, t_CKUINT size, t_CKFLOAT percent ) { t_CKFLOAT sum = 0.0, v, target; t_CKINT i; @@ -2264,7 +2264,7 @@ CK_DLL_TOCK( RollOff_tock ) // sanity check assert( BLOB_IN != NULL ); // get the array - Chuck_Array8 & mag = BLOB_IN->fvals(); + Chuck_ArrayFloat & mag = BLOB_IN->fvals(); // compute rolloff result = compute_rolloff( mag, mag.size(), percent ); } @@ -2276,7 +2276,7 @@ CK_DLL_TOCK( RollOff_tock ) } // get fvals of output BLOB - Chuck_Array8 & fvals = BLOB->fvals(); + Chuck_ArrayFloat & fvals = BLOB->fvals(); // ensure size == resulting size if( fvals.size() != 1 ) fvals.set_size( 1 ); @@ -2314,7 +2314,7 @@ CK_DLL_CGET( RollOff_cget_percent ) CK_DLL_SFUN( RollOff_compute ) { // get array - Chuck_Array8 * array = (Chuck_Array8 *)GET_NEXT_OBJECT( ARGS ); + Chuck_ArrayFloat * array = (Chuck_ArrayFloat *)GET_NEXT_OBJECT( ARGS ); // get percent t_CKFLOAT percent = GET_NEXT_FLOAT( ARGS ); @@ -2452,8 +2452,8 @@ struct Corr_Object Corr_Object * Corr_Object::ourCorr = NULL; // compute correlation -static void compute_corr( Corr_Object * corr, Chuck_Array8 & f, t_CKINT fs, - Chuck_Array8 & g, t_CKINT gs, Chuck_Array8 & buffy ) +static void compute_corr( Corr_Object * corr, Chuck_ArrayFloat & f, t_CKINT fs, + Chuck_ArrayFloat & g, t_CKINT gs, Chuck_ArrayFloat & buffy ) { t_CKINT i; t_CKFLOAT v; @@ -2528,9 +2528,9 @@ CK_DLL_TOCK( AutoCorr_tock ) // sanity check assert( BLOB_IN != NULL ); // get the array - Chuck_Array8 & mag = BLOB_IN->fvals(); + Chuck_ArrayFloat & mag = BLOB_IN->fvals(); // get fvals of output BLOB - Chuck_Array8 & fvals = BLOB->fvals(); + Chuck_ArrayFloat & fvals = BLOB->fvals(); // compute autocorr compute_corr( ac, mag, mag.size(), mag, mag.size(), fvals ); } @@ -2538,7 +2538,7 @@ CK_DLL_TOCK( AutoCorr_tock ) else { // get fvals of output BLOB - Chuck_Array8 & fvals = BLOB->fvals(); + Chuck_ArrayFloat & fvals = BLOB->fvals(); // resize fvals.set_size( 0 ); } @@ -2573,11 +2573,11 @@ CK_DLL_CGET( AutoCorr_cget_normalize ) CK_DLL_SFUN( AutoCorr_compute ) { // get input - Chuck_Array8 * input = (Chuck_Array8 *)GET_NEXT_OBJECT( ARGS ); + Chuck_ArrayFloat * input = (Chuck_ArrayFloat *)GET_NEXT_OBJECT( ARGS ); // get normalize flag t_CKINT normalize = GET_NEXT_INT( ARGS ) != 0; // get input - Chuck_Array8 * output = (Chuck_Array8 *)GET_NEXT_OBJECT( ARGS ); + Chuck_ArrayFloat * output = (Chuck_ArrayFloat *)GET_NEXT_OBJECT( ARGS ); // set normalize Corr_Object::getOurObject()->normalize = normalize; @@ -2622,10 +2622,10 @@ CK_DLL_TOCK( XCorr_tock ) // sanity check assert( BLOB_F != NULL && BLOB_G != NULL ); // get the array - Chuck_Array8 & mag_f = BLOB_F->fvals(); - Chuck_Array8 & mag_g = BLOB_G->fvals(); + Chuck_ArrayFloat & mag_f = BLOB_F->fvals(); + Chuck_ArrayFloat & mag_g = BLOB_G->fvals(); // get fvals of output BLOB - Chuck_Array8 & fvals = BLOB->fvals(); + Chuck_ArrayFloat & fvals = BLOB->fvals(); // compute xcorr compute_corr( xc, mag_f, mag_f.size(), mag_g, mag_g.size(), fvals ); } @@ -2633,7 +2633,7 @@ CK_DLL_TOCK( XCorr_tock ) else { // get fvals of output BLOB - Chuck_Array8 & fvals = BLOB->fvals(); + Chuck_ArrayFloat & fvals = BLOB->fvals(); // resize fvals.set_size( 0 ); } @@ -2668,12 +2668,12 @@ CK_DLL_CGET( XCorr_cget_normalize ) CK_DLL_SFUN( XCorr_compute ) { // get input - Chuck_Array8 * f = (Chuck_Array8 *)GET_NEXT_OBJECT( ARGS ); - Chuck_Array8 * g = (Chuck_Array8 *)GET_NEXT_OBJECT( ARGS ); + Chuck_ArrayFloat * f = (Chuck_ArrayFloat *)GET_NEXT_OBJECT( ARGS ); + Chuck_ArrayFloat * g = (Chuck_ArrayFloat *)GET_NEXT_OBJECT( ARGS ); // get normalize flag t_CKINT normalize = GET_NEXT_INT( ARGS ) != 0; // get output - Chuck_Array8 * output = (Chuck_Array8 *)GET_NEXT_OBJECT( ARGS ); + Chuck_ArrayFloat * output = (Chuck_ArrayFloat *)GET_NEXT_OBJECT( ARGS ); // set normalize Corr_Object::getOurObject()->normalize = normalize; @@ -2738,7 +2738,7 @@ void xcorr_normalize( SAMPLE * buffy, t_CKINT size, SAMPLE * f, t_CKINT fs, SAMP // ZeroX #define __SGN( x ) (x >= 0.0f ? 1.0f : -1.0f ) -static t_CKINT compute_zerox( Chuck_Array8 & buffer, t_CKUINT size ) +static t_CKINT compute_zerox( Chuck_ArrayFloat & buffer, t_CKUINT size ) { t_CKUINT i, xings = 0; t_CKFLOAT v = 0, p = 0; @@ -2788,7 +2788,7 @@ CK_DLL_TOCK( ZeroX_tock ) // sanity check assert( BLOB_IN != NULL ); // get the array - Chuck_Array8 & mag = BLOB_IN->fvals(); + Chuck_ArrayFloat & mag = BLOB_IN->fvals(); // compute ZeroX result = (t_CKFLOAT)( compute_zerox( mag, mag.size() ) + .5 ); } @@ -2800,7 +2800,7 @@ CK_DLL_TOCK( ZeroX_tock ) } // get fvals of output BLOB - Chuck_Array8 & fvals = BLOB->fvals(); + Chuck_ArrayFloat & fvals = BLOB->fvals(); // ensure size == resulting size if( fvals.size() != 1 ) fvals.set_size( 1 ); @@ -2819,7 +2819,7 @@ CK_DLL_PMSG( ZeroX_pmsg ) CK_DLL_SFUN( ZeroX_compute ) { // get array - Chuck_Array8 * array = (Chuck_Array8 *)GET_NEXT_OBJECT( ARGS ); + Chuck_ArrayFloat * array = (Chuck_ArrayFloat *)GET_NEXT_OBJECT( ARGS ); // sanity check if( !array ) { diff --git a/src/core/uana_xform.cpp b/src/core/uana_xform.cpp index 8ca958b11..a204416ce 100644 --- a/src/core/uana_xform.cpp +++ b/src/core/uana_xform.cpp @@ -149,7 +149,7 @@ CK_DLL_SFUN( Windowing_blackmanHarris ); CK_DLL_SFUN( Windowing_rectangle ); CK_DLL_SFUN( Windowing_triangle ); // static array -static Chuck_Array8 * Windowing_array = NULL; +static Chuck_ArrayFloat * Windowing_array = NULL; static FLOAT_XFORM * float_array = NULL; static t_CKINT float_array_size = 0; @@ -324,7 +324,7 @@ DLL_QUERY xform_query( Chuck_DL_Query * QUERY ) QUERY->end_class( QUERY ); // initialize static data - Windowing_array = new Chuck_Array8(); + Windowing_array = new Chuck_ArrayFloat(); initialize_object( Windowing_array, QUERY->env()->ckt_array, NULL, QUERY->env()->vm() ); // TODO: yes? reference count Windowing_array->add_ref(); @@ -581,10 +581,10 @@ struct FFT_object public: t_CKBOOL resize( t_CKINT size ); - t_CKBOOL window( Chuck_Array8 * window, t_CKINT win_size ); + t_CKBOOL window( Chuck_ArrayFloat * window, t_CKINT win_size ); void transform( ); void transformFromAccum( ); - void transform( Chuck_Array8 * frame ); + void transform( Chuck_ArrayFloat * frame ); void copyTo( Chuck_Array16 * cmp ); public: @@ -702,7 +702,7 @@ t_CKBOOL FFT_object::resize( t_CKINT size ) // name: window() // desc: set window //----------------------------------------------------------------------------- -t_CKBOOL FFT_object::window( Chuck_Array8 * win, t_CKINT win_size ) +t_CKBOOL FFT_object::window( Chuck_ArrayFloat * win, t_CKINT win_size ) { // sanity check assert( win_size >= 0 ); @@ -820,7 +820,7 @@ void FFT_object::transformFromAccum() // name: transform() // desc: ... //----------------------------------------------------------------------------- -void FFT_object::transform( Chuck_Array8 * frame ) +void FFT_object::transform( Chuck_ArrayFloat * frame ) { // convert to right type t_CKINT amount = ck_min( frame->size(), m_size ); @@ -971,7 +971,7 @@ CK_DLL_TOCK( FFT_tock ) cvals.set( i, fft->m_spectrum[i] ); // get fvals of output BLOB; fill with magnitude spectrum - Chuck_Array8 & fvals = BLOB->fvals(); + Chuck_ArrayFloat & fvals = BLOB->fvals(); // ensure size == resulting size if( fvals.size() != fft->m_size/2 ) fvals.set_size( fft->m_size/2 ); @@ -992,7 +992,7 @@ CK_DLL_MFUN( FFT_transform ) // get object FFT_object * fft = (FFT_object *)OBJ_MEMBER_UINT(SELF, FFT_offset_data); // get array - Chuck_Array8 * arr = (Chuck_Array8 *)GET_NEXT_OBJECT(ARGS); + Chuck_ArrayFloat * arr = (Chuck_ArrayFloat *)GET_NEXT_OBJECT(ARGS); // do it fft->transform( arr ); } @@ -1007,7 +1007,7 @@ CK_DLL_CTRL( FFT_ctrl_window ) // get object FFT_object * fft = (FFT_object *)OBJ_MEMBER_UINT(SELF, FFT_offset_data); // get window (can be NULL) - Chuck_Array8 * arr = (Chuck_Array8 *)GET_NEXT_OBJECT(ARGS); + Chuck_ArrayFloat * arr = (Chuck_ArrayFloat *)GET_NEXT_OBJECT(ARGS); // set it fft->window( arr, arr != NULL ? arr->size() : 0 ); // return it through @@ -1126,10 +1126,10 @@ struct IFFT_object public: t_CKBOOL resize( t_CKINT size ); - t_CKBOOL window( Chuck_Array8 * window, t_CKINT win_size ); + t_CKBOOL window( Chuck_ArrayFloat * window, t_CKINT win_size ); void transform( ); void transform( Chuck_Array16 * cmp ); - void copyTo( Chuck_Array8 * samples ); + void copyTo( Chuck_ArrayFloat * samples ); public: // size of IFFT @@ -1244,7 +1244,7 @@ t_CKBOOL IFFT_object::resize( t_CKINT size ) // name: window() // desc: set window //----------------------------------------------------------------------------- -t_CKBOOL IFFT_object::window( Chuck_Array8 * win, t_CKINT win_size ) +t_CKBOOL IFFT_object::window( Chuck_ArrayFloat * win, t_CKINT win_size ) { // sanity check assert( win_size >= 0 ); @@ -1360,7 +1360,7 @@ void IFFT_object::transform( Chuck_Array16 * cmp ) // name: copyTo() // desc: ... //----------------------------------------------------------------------------- -void IFFT_object::copyTo( Chuck_Array8 * samples ) +void IFFT_object::copyTo( Chuck_ArrayFloat * samples ) { // buffer could be null if( m_buffer == NULL && m_inverse == NULL ) @@ -1483,7 +1483,7 @@ CK_DLL_TOCK( IFFT_tock ) } // get fvals of output BLOB - Chuck_Array8 & fvals = BLOB->fvals(); + Chuck_ArrayFloat & fvals = BLOB->fvals(); // ensure size == resulting size if( fvals.size() != ifft->m_size ) fvals.set_size( ifft->m_size ); @@ -1540,7 +1540,7 @@ CK_DLL_CTRL( IFFT_ctrl_window ) // get object IFFT_object * ifft = (IFFT_object *)OBJ_MEMBER_UINT(SELF, IFFT_offset_data ); // get win (can be NULL) - Chuck_Array8 * arr = (Chuck_Array8 *)GET_NEXT_OBJECT(ARGS); + Chuck_ArrayFloat * arr = (Chuck_ArrayFloat *)GET_NEXT_OBJECT(ARGS); // set it ifft->window( arr, arr != NULL ? arr->size() : 0 ); // return @@ -1631,7 +1631,7 @@ CK_DLL_MFUN( IFFT_inverse ) // get object IFFT_object * ifft = (IFFT_object *)OBJ_MEMBER_UINT(SELF, IFFT_offset_data); // get array - Chuck_Array8 * arr = (Chuck_Array8 *)GET_NEXT_OBJECT(ARGS); + Chuck_ArrayFloat * arr = (Chuck_ArrayFloat *)GET_NEXT_OBJECT(ARGS); // check for null if( !arr ) { @@ -1836,10 +1836,10 @@ struct Flip_object public: t_CKBOOL resize( t_CKINT size ); - t_CKBOOL window( Chuck_Array8 * window, t_CKINT win_size ); + t_CKBOOL window( Chuck_ArrayFloat * window, t_CKINT win_size ); void transform( ); - void transform( Chuck_Array8 * frame ); - void copyTo( Chuck_Array8 * val ); + void transform( Chuck_ArrayFloat * frame ); + void copyTo( Chuck_ArrayFloat * val ); public: // buffer @@ -1943,7 +1943,7 @@ t_CKBOOL Flip_object::resize( t_CKINT size ) // name: window() // desc: set window //----------------------------------------------------------------------------- -t_CKBOOL Flip_object::window( Chuck_Array8 * win, t_CKINT win_size ) +t_CKBOOL Flip_object::window( Chuck_ArrayFloat * win, t_CKINT win_size ) { // sanity check assert( win_size >= 0 ); @@ -2031,7 +2031,7 @@ void Flip_object::transform( ) // name: transform() // desc: ... //----------------------------------------------------------------------------- -void Flip_object::transform( Chuck_Array8 * frame ) +void Flip_object::transform( Chuck_ArrayFloat * frame ) { // convert to right type t_CKINT amount = ck_min( frame->size(), m_size ); @@ -2058,7 +2058,7 @@ void Flip_object::transform( Chuck_Array8 * frame ) // name: copyTo() // desc: ... //----------------------------------------------------------------------------- -void Flip_object::copyTo( Chuck_Array8 * val ) +void Flip_object::copyTo( Chuck_ArrayFloat * val ) { // buffer could be null if( m_buffer == NULL ) @@ -2146,7 +2146,7 @@ CK_DLL_TOCK( Flip_tock ) t_CKINT i; // get fvals of output BLOB - Chuck_Array8 & fvals = BLOB->fvals(); + Chuck_ArrayFloat & fvals = BLOB->fvals(); // ensure capacity == resulting size if( fvals.size() != flip->m_size ) fvals.set_size( flip->m_size ); @@ -2167,7 +2167,7 @@ CK_DLL_MFUN( Flip_take ) // get object Flip_object * flip = (Flip_object *)OBJ_MEMBER_UINT(SELF, Flip_offset_data); // get array - Chuck_Array8 * arr = (Chuck_Array8 *)GET_NEXT_OBJECT(ARGS); + Chuck_ArrayFloat * arr = (Chuck_ArrayFloat *)GET_NEXT_OBJECT(ARGS); // do it flip->transform( arr ); } @@ -2182,7 +2182,7 @@ CK_DLL_CTRL( Flip_ctrl_window ) // get object Flip_object * flip = (Flip_object *)OBJ_MEMBER_UINT(SELF, Flip_offset_data); // get window (can be NULL) - Chuck_Array8 * arr = (Chuck_Array8 *)GET_NEXT_OBJECT(ARGS); + Chuck_ArrayFloat * arr = (Chuck_ArrayFloat *)GET_NEXT_OBJECT(ARGS); // set it flip->window( arr, arr != NULL ? arr->size() : 0 ); // return it through @@ -2273,7 +2273,7 @@ CK_DLL_MFUN( Flip_output ) // get object Flip_object * flip = (Flip_object *)OBJ_MEMBER_UINT(SELF, Flip_offset_data); // get array - Chuck_Array8 * arr = (Chuck_Array8 *)GET_NEXT_OBJECT(ARGS); + Chuck_ArrayFloat * arr = (Chuck_ArrayFloat *)GET_NEXT_OBJECT(ARGS); // check for null if( !arr ) { @@ -2301,10 +2301,10 @@ struct UnFlip_object public: t_CKBOOL resize( t_CKINT size ); - t_CKBOOL window( Chuck_Array8 * window, t_CKINT win_size ); + t_CKBOOL window( Chuck_ArrayFloat * window, t_CKINT win_size ); void transform( ); - void transform( Chuck_Array8 * val ); - void copyTo( Chuck_Array8 * samples ); + void transform( Chuck_ArrayFloat * val ); + void copyTo( Chuck_ArrayFloat * samples ); public: // size of IFFT @@ -2406,7 +2406,7 @@ t_CKBOOL UnFlip_object::resize( t_CKINT size ) // name: window() // desc: set window //----------------------------------------------------------------------------- -t_CKBOOL UnFlip_object::window( Chuck_Array8 * win, t_CKINT win_size ) +t_CKBOOL UnFlip_object::window( Chuck_ArrayFloat * win, t_CKINT win_size ) { // sanity check assert( win_size >= 0 ); @@ -2490,7 +2490,7 @@ void UnFlip_object::transform( ) // name: transform() // desc: ... //----------------------------------------------------------------------------- -void UnFlip_object::transform( Chuck_Array8 * val ) +void UnFlip_object::transform( Chuck_ArrayFloat * val ) { // convert to right type t_CKINT amount = ck_min( val->size(), m_size ); @@ -2517,7 +2517,7 @@ void UnFlip_object::transform( Chuck_Array8 * val ) // name: copyTo() // desc: ... //----------------------------------------------------------------------------- -void UnFlip_object::copyTo( Chuck_Array8 * samples ) +void UnFlip_object::copyTo( Chuck_ArrayFloat * samples ) { // buffer could be null if( m_buffer == NULL ) @@ -2607,7 +2607,7 @@ CK_DLL_TOCK( UnFlip_tock ) // sanity check assert( BLOB_IN != NULL ); // get the array - Chuck_Array8 & val = BLOB_IN->fvals(); + Chuck_ArrayFloat & val = BLOB_IN->fvals(); // resize if necessary if( val.size() > unflip->m_size ) unflip->resize( val.size() ); @@ -2634,7 +2634,7 @@ CK_DLL_TOCK( UnFlip_tock ) } // get fvals of output BLOB - Chuck_Array8 & fvals = BLOB->fvals(); + Chuck_ArrayFloat & fvals = BLOB->fvals(); // ensure size == resulting size if( fvals.size() != unflip->m_size ) fvals.set_size( unflip->m_size ); @@ -2655,7 +2655,7 @@ CK_DLL_MFUN( UnFlip_take ) // get object UnFlip_object * unflip = (UnFlip_object *)OBJ_MEMBER_UINT(SELF, UnFlip_offset_data); // get complex array - Chuck_Array8 * val = (Chuck_Array8 *)GET_NEXT_OBJECT(ARGS); + Chuck_ArrayFloat * val = (Chuck_ArrayFloat *)GET_NEXT_OBJECT(ARGS); // sanity if( val == NULL ) goto null_pointer; // resize if bigger @@ -2691,7 +2691,7 @@ CK_DLL_CTRL( UnFlip_ctrl_window ) // get object UnFlip_object * unflip = (UnFlip_object *)OBJ_MEMBER_UINT(SELF, UnFlip_offset_data ); // get win (can be NULL) - Chuck_Array8 * arr = (Chuck_Array8 *)GET_NEXT_OBJECT(ARGS); + Chuck_ArrayFloat * arr = (Chuck_ArrayFloat *)GET_NEXT_OBJECT(ARGS); // set it unflip->window( arr, arr != NULL ? arr->size() : 0 ); // return @@ -2782,7 +2782,7 @@ CK_DLL_MFUN( UnFlip_output ) // get object UnFlip_object * unflip = (UnFlip_object *)OBJ_MEMBER_UINT(SELF, UnFlip_offset_data); // get array - Chuck_Array8 * arr = (Chuck_Array8 *)GET_NEXT_OBJECT(ARGS); + Chuck_ArrayFloat * arr = (Chuck_ArrayFloat *)GET_NEXT_OBJECT(ARGS); // check for null if( !arr ) { @@ -2810,10 +2810,10 @@ struct DCT_object public: t_CKBOOL resize( t_CKINT size ); - t_CKBOOL window( Chuck_Array8 * window, t_CKINT win_size ); + t_CKBOOL window( Chuck_ArrayFloat * window, t_CKINT win_size ); void transform( ); void transform( const t_CKFLOAT * in, t_CKCOMPLEX * out ); - void copyTo( Chuck_Array8 * frame ); + void copyTo( Chuck_ArrayFloat * frame ); public: // size of DCT @@ -2935,7 +2935,7 @@ t_CKBOOL DCT_object::resize( t_CKINT size ) // name: window() // desc: set window //----------------------------------------------------------------------------- -t_CKBOOL DCT_object::window( Chuck_Array8 * win, t_CKINT win_size ) +t_CKBOOL DCT_object::window( Chuck_ArrayFloat * win, t_CKINT win_size ) { // sanity check assert( win_size >= 0 ); @@ -3025,7 +3025,7 @@ void DCT_object::transform( ) // name: copyTo() // desc: ... //----------------------------------------------------------------------------- -void DCT_object::copyTo( Chuck_Array8 * frame ) +void DCT_object::copyTo( Chuck_ArrayFloat * frame ) { // buffer could be null if( m_buffer == NULL && m_spectrum == NULL ) @@ -3139,7 +3139,7 @@ CK_DLL_TOCK( DCT_tock ) t_CKINT i; // get cvals of output BLOB - Chuck_Array8 & fvals = BLOB->fvals(); + Chuck_ArrayFloat & fvals = BLOB->fvals(); // ensure capacity == resulting size if( fvals.size() != dct->m_size ) fvals.set_size( dct->m_size ); @@ -3160,7 +3160,7 @@ CK_DLL_MFUN( DCT_transform ) // get object // DCT_object * dct = (DCT_object *)OBJ_MEMBER_UINT(SELF, DCT_offset_data); // get array -// Chuck_Array8 * arr = (Chuck_Array8 *)GET_NEXT_OBJECT(ARGS); +// Chuck_ArrayFloat * arr = (Chuck_ArrayFloat *)GET_NEXT_OBJECT(ARGS); } @@ -3173,7 +3173,7 @@ CK_DLL_CTRL( DCT_ctrl_window ) // get object DCT_object * dct = (DCT_object *)OBJ_MEMBER_UINT(SELF, DCT_offset_data); // get window (can be NULL) - Chuck_Array8 * arr = (Chuck_Array8 *)GET_NEXT_OBJECT(ARGS); + Chuck_ArrayFloat * arr = (Chuck_ArrayFloat *)GET_NEXT_OBJECT(ARGS); // set it dct->window( arr, arr != NULL ? arr->size() : 0 ); } @@ -3260,7 +3260,7 @@ CK_DLL_MFUN( DCT_spectrum ) // get object DCT_object * dct = (DCT_object *)OBJ_MEMBER_UINT(SELF, DCT_offset_data); // get array - Chuck_Array8 * arr = (Chuck_Array8 *)GET_NEXT_OBJECT(ARGS); + Chuck_ArrayFloat * arr = (Chuck_ArrayFloat *)GET_NEXT_OBJECT(ARGS); // check for null if( !arr ) { @@ -3288,10 +3288,10 @@ struct IDCT_object public: t_CKBOOL resize( t_CKINT size ); - t_CKBOOL window( Chuck_Array8 * window, t_CKINT win_size ); + t_CKBOOL window( Chuck_ArrayFloat * window, t_CKINT win_size ); void transform( ); - void transform( Chuck_Array8 * frame ); - void copyTo( Chuck_Array8 * samples ); + void transform( Chuck_ArrayFloat * frame ); + void copyTo( Chuck_ArrayFloat * samples ); public: // size of IDCT @@ -3410,7 +3410,7 @@ t_CKBOOL IDCT_object::resize( t_CKINT size ) // name: window() // desc: set window //----------------------------------------------------------------------------- -t_CKBOOL IDCT_object::window( Chuck_Array8 * win, t_CKINT win_size ) +t_CKBOOL IDCT_object::window( Chuck_ArrayFloat * win, t_CKINT win_size ) { // sanity check assert( win_size >= 0 ); @@ -3496,7 +3496,7 @@ void IDCT_object::transform( ) // name: transform() // desc: ... //----------------------------------------------------------------------------- -void IDCT_object::transform( Chuck_Array8 * frame ) +void IDCT_object::transform( Chuck_ArrayFloat * frame ) { // convert to right type t_CKINT amount = ck_min( frame->size(), m_size ); @@ -3523,7 +3523,7 @@ void IDCT_object::transform( Chuck_Array8 * frame ) // name: copyTo() // desc: ... //----------------------------------------------------------------------------- -void IDCT_object::copyTo( Chuck_Array8 * samples ) +void IDCT_object::copyTo( Chuck_ArrayFloat * samples ) { // buffer could be null if( m_buffer == NULL && m_inverse == NULL ) @@ -3645,7 +3645,7 @@ CK_DLL_TOCK( IDCT_tock ) } // get fvals of output BLOB - Chuck_Array8 & fvals = BLOB->fvals(); + Chuck_ArrayFloat & fvals = BLOB->fvals(); // ensure size == resulting size if( fvals.size() != idct->m_size ) fvals.set_size( idct->m_size ); @@ -3666,7 +3666,7 @@ CK_DLL_MFUN( IDCT_transform ) // get object IDCT_object * idct = (IDCT_object *)OBJ_MEMBER_UINT(SELF, IDCT_offset_data); // get complex array - Chuck_Array8 * frame = (Chuck_Array8 *)GET_NEXT_OBJECT(ARGS); + Chuck_ArrayFloat * frame = (Chuck_ArrayFloat *)GET_NEXT_OBJECT(ARGS); // sanity if( frame == NULL ) goto null_pointer; // resize if bigger @@ -3702,7 +3702,7 @@ CK_DLL_CTRL( IDCT_ctrl_window ) // get object IDCT_object * idct = (IDCT_object *)OBJ_MEMBER_UINT(SELF, IDCT_offset_data ); // get win (can be NULL) - Chuck_Array8 * arr = (Chuck_Array8 *)GET_NEXT_OBJECT(ARGS); + Chuck_ArrayFloat * arr = (Chuck_ArrayFloat *)GET_NEXT_OBJECT(ARGS); // set it idct->window( arr, arr != NULL ? arr->size() : 0 ); } @@ -3789,7 +3789,7 @@ CK_DLL_MFUN( IDCT_inverse ) // get object IDCT_object * idct = (IDCT_object *)OBJ_MEMBER_UINT(SELF, IDCT_offset_data); // get array - Chuck_Array8 * arr = (Chuck_Array8 *)GET_NEXT_OBJECT(ARGS); + Chuck_ArrayFloat * arr = (Chuck_ArrayFloat *)GET_NEXT_OBJECT(ARGS); // check for null if( !arr ) { diff --git a/src/core/ugen_osc.cpp b/src/core/ugen_osc.cpp index 442395dfe..ee5908f39 100644 --- a/src/core/ugen_osc.cpp +++ b/src/core/ugen_osc.cpp @@ -1343,7 +1343,7 @@ CK_DLL_CTRL( gen5_coeffs ) t_CKINT i = 0, j, k, l, size; t_CKFLOAT wmax, xmax=0.0, c, amp2, amp1, coeffs[genX_MAX_COEFFS]; - Chuck_Array8 * in_args = (Chuck_Array8 *)GET_CK_OBJECT(ARGS); + Chuck_ArrayFloat * in_args = (Chuck_ArrayFloat *)GET_CK_OBJECT(ARGS); // CK_FPRINTF_STDOUT( "calling gen10coeffs, %d\n", weights ); if(in_args == 0) return; @@ -1398,7 +1398,7 @@ CK_DLL_CTRL( gen7_coeffs ) t_CKINT i=0, j, k, l, size; t_CKFLOAT wmax, xmax = 0.0, amp2, amp1, coeffs[genX_MAX_COEFFS]; - Chuck_Array8 * in_args = (Chuck_Array8 *)GET_CK_OBJECT(ARGS); + Chuck_ArrayFloat * in_args = (Chuck_ArrayFloat *)GET_CK_OBJECT(ARGS); // CK_FPRINTF_STDOUT( "calling gen10coeffs, %d\n", weights ); if(in_args == 0) return; @@ -1451,7 +1451,7 @@ CK_DLL_CTRL( gen9_coeffs ) t_CKDOUBLE wmax, xmax=0.0; t_CKFLOAT coeffs[genX_MAX_COEFFS]; - Chuck_Array8 * weights = (Chuck_Array8 *)GET_CK_OBJECT(ARGS); + Chuck_ArrayFloat * weights = (Chuck_ArrayFloat *)GET_CK_OBJECT(ARGS); // CK_FPRINTF_STDOUT( "calling gen10coeffs, %d\n", weights ); if(weights == 0) return; @@ -1501,7 +1501,7 @@ CK_DLL_CTRL( gen10_coeffs ) t_CKINT i, j, size; t_CKDOUBLE wmax, xmax=0.0; - Chuck_Array8 * weights = (Chuck_Array8 *)GET_CK_OBJECT(ARGS); + Chuck_ArrayFloat * weights = (Chuck_ArrayFloat *)GET_CK_OBJECT(ARGS); // CK_FPRINTF_STDOUT( "calling gen10coeffs, %d\n", weights ); if(weights==0) return; @@ -1560,7 +1560,7 @@ CK_DLL_CTRL( gen17_coeffs ) t_CKDOUBLE Tn, Tn1, Tn2, dg, x, wmax = 0.0, xmax = 0.0; t_CKFLOAT coeffs[genX_MAX_COEFFS]; - Chuck_Array8 * weights = (Chuck_Array8 *)GET_CK_OBJECT(ARGS); + Chuck_ArrayFloat * weights = (Chuck_ArrayFloat *)GET_CK_OBJECT(ARGS); // CK_FPRINTF_STDOUT( "calling gen17coeffs, %d\n", weights ); if(weights == 0) return; @@ -1621,7 +1621,7 @@ CK_DLL_CTRL( curve_coeffs ) t_CKUINT ii = 0; t_CKFLOAT v = 0.0; - Chuck_Array8 * weights = (Chuck_Array8 *)GET_CK_OBJECT(ARGS); + Chuck_ArrayFloat * weights = (Chuck_ArrayFloat *)GET_CK_OBJECT(ARGS); // CK_FPRINTF_STDOUT( "calling gen17coeffs, %d\n", weights ); if(weights==0) goto done; @@ -1724,7 +1724,7 @@ CK_DLL_CTRL( warp_coeffs ) t_CKFLOAT k_sym = 1.; // gewang: - Chuck_Array8 * weights = (Chuck_Array8 *)GET_CK_OBJECT(ARGS); + Chuck_ArrayFloat * weights = (Chuck_ArrayFloat *)GET_CK_OBJECT(ARGS); // check for size if( weights->size() != 2 ) { diff --git a/src/core/ulib_ai.cpp b/src/core/ulib_ai.cpp index 54f3687ad..8080f5f85 100644 --- a/src/core/ulib_ai.cpp +++ b/src/core/ulib_ai.cpp @@ -1170,15 +1170,15 @@ DLL_QUERY libai_query( Chuck_DL_Query * QUERY ) // name: chuck2chai() // desc: chuck array (assuming float[][]) conversion to new chai matrix //----------------------------------------------------------------------------- -ChaiMatrixFast * chuck2chai( Chuck_Array4 & array ) +ChaiMatrixFast * chuck2chai( Chuck_ArrayInt & array ) { t_CKINT rows = array.size(); - Chuck_Array8 * row = (Chuck_Array8 *)array.m_vector[0]; + Chuck_ArrayFloat * row = (Chuck_ArrayFloat *)array.m_vector[0]; t_CKINT cols = row->size(); ChaiMatrixFast * matrix = new ChaiMatrixFast( rows, cols ); for( t_CKINT i = 0; i < rows; i++ ) { - row = (Chuck_Array8 *)array.m_vector[i]; + row = (Chuck_ArrayFloat *)array.m_vector[i]; for( t_CKINT j = 0; j < cols; j++ ) { matrix->v( i, j ) = row->m_vector[j]; @@ -1191,7 +1191,7 @@ ChaiMatrixFast * chuck2chai( Chuck_Array4 & array ) // name: chuck2chai() // desc: chuck array (float []) conversion to new chai vector //----------------------------------------------------------------------------- -ChaiVectorFast * chuck2chai( Chuck_Array8 & array ) +ChaiVectorFast * chuck2chai( Chuck_ArrayFloat & array ) { t_CKINT size = array.size(); ChaiVectorFast * vector = new ChaiVectorFast( size ); @@ -1206,7 +1206,7 @@ ChaiVectorFast * chuck2chai( Chuck_Array8 & array ) // name: shuffle() // desc: shuffle training data //----------------------------------------------------------------------------- -void shuffle( Chuck_Array4 & X, Chuck_Array4 & Y ) +void shuffle( Chuck_ArrayInt & X, Chuck_ArrayInt & Y ) { t_CKUINT temp, j; for( t_CKINT i = X.size() - 1; i > 0; i-- ) @@ -1263,7 +1263,7 @@ struct SVM_Object } // train - t_CKINT train( Chuck_Array4 & x_, Chuck_Array4 & y_ ) + t_CKINT train( Chuck_ArrayInt & x_, Chuck_ArrayInt & y_ ) { ChaiMatrixFast * x = chuck2chai( x_ ); ChaiMatrixFast * y = chuck2chai( y_ ); @@ -1363,7 +1363,7 @@ struct SVM_Object } // predict - t_CKBOOL predict( Chuck_Array8 & x_, Chuck_Array8 & y_ ) + t_CKBOOL predict( Chuck_ArrayFloat & x_, Chuck_ArrayFloat & y_ ) { // init t_CKINT x_dim = x_.size(); @@ -1442,8 +1442,8 @@ CK_DLL_MFUN( SVM_train ) // get object SVM_Object * svm = (SVM_Object *)OBJ_MEMBER_UINT( SELF, SVM_offset_data ); // get args - Chuck_Array4 * x = (Chuck_Array4 *)GET_NEXT_OBJECT( ARGS ); - Chuck_Array4 * y = (Chuck_Array4 *)GET_NEXT_OBJECT( ARGS ); + Chuck_ArrayInt * x = (Chuck_ArrayInt *)GET_NEXT_OBJECT( ARGS ); + Chuck_ArrayInt * y = (Chuck_ArrayInt *)GET_NEXT_OBJECT( ARGS ); // add svm->train( *x, *y ); } @@ -1453,8 +1453,8 @@ CK_DLL_MFUN( SVM_predict ) // get object SVM_Object * svm = (SVM_Object *)OBJ_MEMBER_UINT( SELF, SVM_offset_data ); // get args - Chuck_Array8 * x = (Chuck_Array8 *)GET_NEXT_OBJECT( ARGS ); - Chuck_Array8 * y = (Chuck_Array8 *)GET_NEXT_OBJECT( ARGS ); + Chuck_ArrayFloat * x = (Chuck_ArrayFloat *)GET_NEXT_OBJECT( ARGS ); + Chuck_ArrayFloat * y = (Chuck_ArrayFloat *)GET_NEXT_OBJECT( ARGS ); // add RETURN->v_int = svm->predict( *x, *y ); } @@ -1489,14 +1489,14 @@ struct KNN_Object } // train - t_CKINT train( Chuck_Array4 & x_ ) + t_CKINT train( Chuck_ArrayInt & x_ ) { clear(); // init t_CKINT n_sample = x_.size(); t_CKUINT v; x_.get( 0, &v ); - Chuck_Array8 * x_i = (Chuck_Array8 *)v; + Chuck_ArrayFloat * x_i = (Chuck_ArrayFloat *)v; t_CKINT x_dim = x_i->size(); X = new ChaiMatrixFast( n_sample, x_dim ); weights = new ChaiVectorFast( x_dim ); @@ -1504,7 +1504,7 @@ struct KNN_Object for( t_CKINT i = 0; i < n_sample; i++ ) { x_.get( i, &v ); - x_i = (Chuck_Array8 *)v; + x_i = (Chuck_ArrayFloat *)v; for( t_CKINT j = 0; j < x_dim; j++ ) { x_i->get( j, &X->v( i, j ) ); @@ -1542,14 +1542,14 @@ struct KNN_Object } // train - t_CKINT train( Chuck_Array4 & x_, Chuck_Array4 & y_ ) + t_CKINT train( Chuck_ArrayInt & x_, Chuck_ArrayInt & y_ ) { clear(); // init t_CKINT n_sample = x_.size(); t_CKUINT v; x_.get( 0, &v ); - Chuck_Array8 * x_i = (Chuck_Array8 *)v; + Chuck_ArrayFloat * x_i = (Chuck_ArrayFloat *)v; t_CKUINT x_dim = x_i->size(); X = new ChaiMatrixFast( n_sample, x_dim ); Y = new ChaiVectorFast( n_sample ); @@ -1558,7 +1558,7 @@ struct KNN_Object for( t_CKINT i = 0; i < n_sample; i++ ) { x_.get( i, &v ); - x_i = (Chuck_Array8 *)v; + x_i = (Chuck_ArrayFloat *)v; for( t_CKINT j = 0; j < x_dim; j++ ) { x_i->get( j, &X->v( i, j ) ); @@ -1627,7 +1627,7 @@ struct KNN_Object } // search; returns indices - void search0( const vector & query, t_CKINT k, Chuck_Array4 & indices_ ) + void search0( const vector & query, t_CKINT k, Chuck_ArrayInt & indices_ ) { // init ChaiVectorFast indices( k ); @@ -1643,7 +1643,7 @@ struct KNN_Object } // search; returns labels - void search1( const vector & query, t_CKINT k, Chuck_Array4 & labels_ ) + void search1( const vector & query, t_CKINT k, Chuck_ArrayInt & labels_ ) { // init ChaiVectorFast indices( k ); @@ -1659,7 +1659,7 @@ struct KNN_Object } // search; returns labels and indices - void search2( const vector & query, t_CKINT k, Chuck_Array4 & labels_, Chuck_Array4 & indices_ ) + void search2( const vector & query, t_CKINT k, Chuck_ArrayInt & labels_, Chuck_ArrayInt & indices_ ) { // init ChaiVectorFast indices( k ); @@ -1678,9 +1678,9 @@ struct KNN_Object // search; returns labels, indices, and feature vectors void search3( const vector & query, t_CKINT k, - Chuck_Array4 & labels_, - Chuck_Array4 & indices_, - Chuck_Array4 & features_ ) + Chuck_ArrayInt & labels_, + Chuck_ArrayInt & indices_, + Chuck_ArrayInt & features_ ) { // init ChaiVectorFast indices( k ); @@ -1692,18 +1692,18 @@ struct KNN_Object // check dimensions if( features_.size() < k ) { - Chuck_Array8 * x_i = features_.size() ? (Chuck_Array8 *)features_.m_vector[0] : NULL; + Chuck_ArrayFloat * x_i = features_.size() ? (Chuck_ArrayFloat *)features_.m_vector[0] : NULL; EM_error3( "KNN2: insufficient 'features' matrix provided: %dx%d (expecting %dx%d)", features_.size(), x_i != NULL ? x_i->m_vector.size() : 0, k, this->X->xDim() ); return; } // copy - Chuck_Array8 * x_i; + Chuck_ArrayFloat * x_i; for( t_CKINT i = 0; i < k; i++ ) { labels_.m_vector[i] = Y->v( indices.v( i ) ); indices_.m_vector[i] = indices[i]; - x_i = (Chuck_Array8 *)features_.m_vector[i]; + x_i = (Chuck_ArrayFloat *)features_.m_vector[i]; for( t_CKINT j = 0; j < X->yDim(); j++ ) { x_i->m_vector[j] = X->v( indices.v( i ), j ); @@ -1714,8 +1714,8 @@ struct KNN_Object // search; returns labels, indices, and feature vectors void search3b( const vector & query, t_CKINT k, - Chuck_Array4 & indices_, - Chuck_Array4 & features_ ) + Chuck_ArrayInt & indices_, + Chuck_ArrayInt & features_ ) { // init ChaiVectorFast indices( k ); @@ -1726,17 +1726,17 @@ struct KNN_Object // check dimensions if( features_.size() < k ) { - Chuck_Array8 * x_i = features_.size() ? (Chuck_Array8 *)features_.m_vector[0] : NULL; + Chuck_ArrayFloat * x_i = features_.size() ? (Chuck_ArrayFloat *)features_.m_vector[0] : NULL; EM_error3( "KNN: insufficient 'features' matrix provided: %dx%d (expecting %dx%d)", features_.size(), x_i != NULL ? x_i->m_vector.size() : 0, k, this->X->xDim() ); return; } // copy - Chuck_Array8 * x_i; + Chuck_ArrayFloat * x_i; for( t_CKINT i = 0; i < k; i++ ) { indices_.m_vector[i] = indices[i]; - x_i = (Chuck_Array8 *)features_.m_vector[i]; + x_i = (Chuck_ArrayFloat *)features_.m_vector[i]; for( t_CKINT j = 0; j < X->yDim(); j++ ) { x_i->m_vector[j] = X->v( indices.v( i ), j ); @@ -1745,7 +1745,7 @@ struct KNN_Object } // predict - t_CKBOOL predict( const vector & query, t_CKINT k, Chuck_Array8 & prob_ ) + t_CKBOOL predict( const vector & query, t_CKINT k, Chuck_ArrayFloat & prob_ ) { // TODO: check if model initialized // init @@ -1819,7 +1819,7 @@ CK_DLL_MFUN( KNN_train ) // get object KNN_Object * knn = (KNN_Object *)OBJ_MEMBER_UINT( SELF, KNN_offset_data ); // get args - Chuck_Array4 * x = (Chuck_Array4 *)GET_NEXT_OBJECT( ARGS ); + Chuck_ArrayInt * x = (Chuck_ArrayInt *)GET_NEXT_OBJECT( ARGS ); // check for NULL if( x == NULL ) @@ -1837,9 +1837,9 @@ CK_DLL_MFUN( KNN_search ) // get object KNN_Object * knn = (KNN_Object *)OBJ_MEMBER_UINT( SELF, KNN_offset_data ); // get args - Chuck_Array8 * query = (Chuck_Array8 *)GET_NEXT_OBJECT( ARGS ); + Chuck_ArrayFloat * query = (Chuck_ArrayFloat *)GET_NEXT_OBJECT( ARGS ); t_CKINT k = GET_NEXT_INT( ARGS ); - Chuck_Array4 * indices = (Chuck_Array4 *)GET_NEXT_OBJECT( ARGS ); + Chuck_ArrayInt * indices = (Chuck_ArrayInt *)GET_NEXT_OBJECT( ARGS ); // check for NULL if( query == NULL || indices == NULL ) @@ -1857,10 +1857,10 @@ CK_DLL_MFUN( KNN_search2 ) // get object KNN_Object * knn = (KNN_Object *)OBJ_MEMBER_UINT( SELF, KNN2_offset_data ); // get args - Chuck_Array8 * query = (Chuck_Array8 *)GET_NEXT_OBJECT( ARGS ); + Chuck_ArrayFloat * query = (Chuck_ArrayFloat *)GET_NEXT_OBJECT( ARGS ); t_CKINT k = GET_NEXT_INT( ARGS ); - Chuck_Array4 * indices = (Chuck_Array4 *)GET_NEXT_OBJECT( ARGS ); - Chuck_Array4 * features = (Chuck_Array4 *)GET_NEXT_OBJECT( ARGS ); + Chuck_ArrayInt * indices = (Chuck_ArrayInt *)GET_NEXT_OBJECT( ARGS ); + Chuck_ArrayInt * features = (Chuck_ArrayInt *)GET_NEXT_OBJECT( ARGS ); // check for NULL if( query == NULL || indices == NULL || features == NULL ) @@ -1879,7 +1879,7 @@ CK_DLL_MFUN( KNN_weigh ) // get object KNN_Object * knn = (KNN_Object *)OBJ_MEMBER_UINT( SELF, KNN_offset_data ); // get args - Chuck_Array8 * weights = (Chuck_Array8 *)GET_NEXT_OBJECT( ARGS ); + Chuck_ArrayFloat * weights = (Chuck_ArrayFloat *)GET_NEXT_OBJECT( ARGS ); // weigh knn->weigh( weights->m_vector ); } @@ -1908,8 +1908,8 @@ CK_DLL_MFUN( KNN2_train ) // get object KNN_Object * knn = (KNN_Object *)OBJ_MEMBER_UINT( SELF, KNN2_offset_data ); // get args - Chuck_Array4 * x = (Chuck_Array4 *)GET_NEXT_OBJECT( ARGS ); - Chuck_Array4 * y = (Chuck_Array4 *)GET_NEXT_OBJECT( ARGS ); + Chuck_ArrayInt * x = (Chuck_ArrayInt *)GET_NEXT_OBJECT( ARGS ); + Chuck_ArrayInt * y = (Chuck_ArrayInt *)GET_NEXT_OBJECT( ARGS ); // check for NULL if( x == NULL || y == NULL ) @@ -1927,9 +1927,9 @@ CK_DLL_MFUN( KNN2_predict ) // get object KNN_Object * knn = (KNN_Object *)OBJ_MEMBER_UINT( SELF, KNN2_offset_data ); // get args - Chuck_Array8 * query = (Chuck_Array8 *)GET_NEXT_OBJECT( ARGS ); + Chuck_ArrayFloat * query = (Chuck_ArrayFloat *)GET_NEXT_OBJECT( ARGS ); t_CKINT k = GET_NEXT_INT( ARGS ); - Chuck_Array8 * prob = (Chuck_Array8 *)GET_NEXT_OBJECT( ARGS ); + Chuck_ArrayFloat * prob = (Chuck_ArrayFloat *)GET_NEXT_OBJECT( ARGS ); // check for NULL if( query == NULL || prob == NULL ) @@ -1947,9 +1947,9 @@ CK_DLL_MFUN( KNN2_search ) // get object KNN_Object * knn = (KNN_Object *)OBJ_MEMBER_UINT( SELF, KNN2_offset_data ); // get args - Chuck_Array8 * query = (Chuck_Array8 *)GET_NEXT_OBJECT( ARGS ); + Chuck_ArrayFloat * query = (Chuck_ArrayFloat *)GET_NEXT_OBJECT( ARGS ); t_CKINT k = GET_NEXT_INT( ARGS ); - Chuck_Array4 * labels = (Chuck_Array4 *)GET_NEXT_OBJECT( ARGS ); + Chuck_ArrayInt * labels = (Chuck_ArrayInt *)GET_NEXT_OBJECT( ARGS ); // check for NULL if( query == NULL || labels == NULL ) @@ -1967,10 +1967,10 @@ CK_DLL_MFUN( KNN2_search2 ) // get object KNN_Object * knn = (KNN_Object *)OBJ_MEMBER_UINT( SELF, KNN2_offset_data ); // get args - Chuck_Array8 * query = (Chuck_Array8 *)GET_NEXT_OBJECT( ARGS ); + Chuck_ArrayFloat * query = (Chuck_ArrayFloat *)GET_NEXT_OBJECT( ARGS ); t_CKINT k = GET_NEXT_INT( ARGS ); - Chuck_Array4 * labels = (Chuck_Array4 *)GET_NEXT_OBJECT( ARGS ); - Chuck_Array4 * indices = (Chuck_Array4 *)GET_NEXT_OBJECT( ARGS ); + Chuck_ArrayInt * labels = (Chuck_ArrayInt *)GET_NEXT_OBJECT( ARGS ); + Chuck_ArrayInt * indices = (Chuck_ArrayInt *)GET_NEXT_OBJECT( ARGS ); // check for NULL if( query == NULL || labels == NULL || indices == NULL ) @@ -1988,11 +1988,11 @@ CK_DLL_MFUN( KNN2_search3 ) // get object KNN_Object * knn = (KNN_Object *)OBJ_MEMBER_UINT( SELF, KNN2_offset_data ); // get args - Chuck_Array8 * query = (Chuck_Array8 *)GET_NEXT_OBJECT( ARGS ); + Chuck_ArrayFloat * query = (Chuck_ArrayFloat *)GET_NEXT_OBJECT( ARGS ); t_CKINT k = GET_NEXT_INT( ARGS ); - Chuck_Array4 * labels = (Chuck_Array4 *)GET_NEXT_OBJECT( ARGS ); - Chuck_Array4 * indices = (Chuck_Array4 *)GET_NEXT_OBJECT( ARGS ); - Chuck_Array4 * features = (Chuck_Array4 *)GET_NEXT_OBJECT( ARGS ); + Chuck_ArrayInt * labels = (Chuck_ArrayInt *)GET_NEXT_OBJECT( ARGS ); + Chuck_ArrayInt * indices = (Chuck_ArrayInt *)GET_NEXT_OBJECT( ARGS ); + Chuck_ArrayInt * features = (Chuck_ArrayInt *)GET_NEXT_OBJECT( ARGS ); // check for NULL if( query == NULL || labels == NULL || indices == NULL || features == NULL ) @@ -2010,7 +2010,7 @@ CK_DLL_MFUN( KNN2_weigh ) // get object KNN_Object * knn = (KNN_Object *)OBJ_MEMBER_UINT( SELF, KNN2_offset_data ); // get args - Chuck_Array8 * weights = (Chuck_Array8 *)GET_NEXT_OBJECT( ARGS ); + Chuck_ArrayFloat * weights = (Chuck_ArrayFloat *)GET_NEXT_OBJECT( ARGS ); // weigh knn->weigh( weights->m_vector ); } @@ -2041,7 +2041,7 @@ struct HMM_Object } // init - t_CKINT init( Chuck_Array8 & initial_, Chuck_Array4 & transition_, Chuck_Array4 & emission_ ) + t_CKINT init( Chuck_ArrayFloat & initial_, Chuck_ArrayInt & transition_, Chuck_ArrayInt & emission_ ) { clear(); initial = chuck2chai( initial_ ); @@ -2131,7 +2131,7 @@ struct HMM_Object } // train - t_CKINT train( t_CKINT n_state, t_CKINT n_emission, Chuck_Array4 & observations ) + t_CKINT train( t_CKINT n_state, t_CKINT n_emission, Chuck_ArrayInt & observations ) { clear(); // init @@ -2210,7 +2210,7 @@ struct HMM_Object } // generate - t_CKINT generate( t_CKINT length, Chuck_Array4 & output_ ) + t_CKINT generate( t_CKINT length, Chuck_ArrayInt & output_ ) { // compute t_CKINT state = 0; @@ -2289,9 +2289,9 @@ CK_DLL_MFUN( HMM_init ) // get object HMM_Object * hmm = (HMM_Object *)OBJ_MEMBER_UINT( SELF, HMM_offset_data ); // get args - Chuck_Array8 * initial = (Chuck_Array8 *)GET_NEXT_OBJECT( ARGS ); - Chuck_Array4 * transition = (Chuck_Array4 *)GET_NEXT_OBJECT( ARGS ); - Chuck_Array4 * emission = (Chuck_Array4 *)GET_NEXT_OBJECT( ARGS ); + Chuck_ArrayFloat * initial = (Chuck_ArrayFloat *)GET_NEXT_OBJECT( ARGS ); + Chuck_ArrayInt * transition = (Chuck_ArrayInt *)GET_NEXT_OBJECT( ARGS ); + Chuck_ArrayInt * emission = (Chuck_ArrayInt *)GET_NEXT_OBJECT( ARGS ); // init hmm->init( *initial, *transition, *emission ); } @@ -2303,7 +2303,7 @@ CK_DLL_MFUN( HMM_train ) // get args t_CKINT n_state = GET_NEXT_INT( ARGS ); t_CKINT n_emission = GET_NEXT_INT( ARGS ); - Chuck_Array4 * observations = (Chuck_Array4 *)GET_NEXT_OBJECT( ARGS ); + Chuck_ArrayInt * observations = (Chuck_ArrayInt *)GET_NEXT_OBJECT( ARGS ); // train hmm->train( n_state, n_emission, *observations ); } @@ -2314,7 +2314,7 @@ CK_DLL_MFUN( HMM_generate ) HMM_Object * hmm = (HMM_Object *)OBJ_MEMBER_UINT( SELF, HMM_offset_data ); // get args t_CKINT length = GET_NEXT_INT( ARGS ); - Chuck_Array4 * output = (Chuck_Array4 *)GET_NEXT_OBJECT( ARGS ); + Chuck_ArrayInt * output = (Chuck_ArrayInt *)GET_NEXT_OBJECT( ARGS ); // generate hmm->generate( length, *output ); } @@ -2405,7 +2405,7 @@ struct Word2Vec_Object } // get dim mins and maxs - void getDimMinMaxs( Chuck_Array8 * mins, Chuck_Array8 * maxs ) + void getDimMinMaxs( Chuck_ArrayFloat * mins, Chuck_ArrayFloat * maxs ) { // get dim t_CKINT dims = getDictionaryDim(); @@ -2669,7 +2669,7 @@ struct Word2Vec_Object } // getMostSimilar - t_CKBOOL getMostSimilarByWord( const string & word, t_CKINT topn, Chuck_Array4 & output_ ) + t_CKBOOL getMostSimilarByWord( const string & word, t_CKINT topn, Chuck_ArrayInt & output_ ) { // error flag t_CKBOOL hasError = FALSE; @@ -2737,7 +2737,7 @@ struct Word2Vec_Object } // getByVector - t_CKBOOL getMostSimilarByVector( Chuck_Array8 & vec_, t_CKINT topn, Chuck_Array4 & output_ ) + t_CKBOOL getMostSimilarByVector( Chuck_ArrayFloat & vec_, t_CKINT topn, Chuck_ArrayInt & output_ ) { // error flag t_CKBOOL hasError = FALSE; @@ -2789,7 +2789,7 @@ struct Word2Vec_Object } // getVector - t_CKBOOL getVector( const string & word, Chuck_Array8 & output_ ) + t_CKBOOL getVector( const string & word, Chuck_ArrayFloat & output_ ) { // check if( dictionary == NULL ) @@ -2884,7 +2884,7 @@ CK_DLL_MFUN( Word2Vec_getMostSimilarByWord ) // get args Chuck_String * word = GET_NEXT_STRING( ARGS ); t_CKINT topn = GET_NEXT_INT( ARGS ); - Chuck_Array4 * output = (Chuck_Array4 *)GET_NEXT_OBJECT( ARGS ); + Chuck_ArrayInt * output = (Chuck_ArrayInt *)GET_NEXT_OBJECT( ARGS ); // check for NULL if( word == NULL || output == NULL ) @@ -2902,9 +2902,9 @@ CK_DLL_MFUN( Word2Vec_getMostSimilarByVector ) // get object Word2Vec_Object * word2vec = (Word2Vec_Object *)OBJ_MEMBER_UINT( SELF, Word2Vec_offset_data ); // get args - Chuck_Array8 * vec = (Chuck_Array8 *)GET_NEXT_OBJECT( ARGS ); + Chuck_ArrayFloat * vec = (Chuck_ArrayFloat *)GET_NEXT_OBJECT( ARGS ); t_CKINT topn = GET_NEXT_INT( ARGS ); - Chuck_Array4 * output = (Chuck_Array4 *)GET_NEXT_OBJECT( ARGS ); + Chuck_ArrayInt * output = (Chuck_ArrayInt *)GET_NEXT_OBJECT( ARGS ); // check for NULL if( vec == NULL || output == NULL ) @@ -2923,7 +2923,7 @@ CK_DLL_MFUN( Word2Vec_getVector ) Word2Vec_Object * word2vec = (Word2Vec_Object *)OBJ_MEMBER_UINT( SELF, Word2Vec_offset_data ); // get args Chuck_String * word = GET_NEXT_STRING( ARGS ); - Chuck_Array8 * output = (Chuck_Array8 *)GET_NEXT_OBJECT( ARGS ); + Chuck_ArrayFloat * output = (Chuck_ArrayFloat *)GET_NEXT_OBJECT( ARGS ); // check for NULL if( word == NULL || output == NULL ) @@ -2975,8 +2975,8 @@ CK_DLL_MFUN( Word2Vec_getDimMinMax ) // get object Word2Vec_Object * word2vec = (Word2Vec_Object *)OBJ_MEMBER_UINT( SELF, Word2Vec_offset_data ); // get chuck arrays - Chuck_Array8 * mins = (Chuck_Array8 *)GET_NEXT_OBJECT( ARGS ); - Chuck_Array8 * maxs = (Chuck_Array8 *)GET_NEXT_OBJECT( ARGS ); + Chuck_ArrayFloat * mins = (Chuck_ArrayFloat *)GET_NEXT_OBJECT( ARGS ); + Chuck_ArrayFloat * maxs = (Chuck_ArrayFloat *)GET_NEXT_OBJECT( ARGS ); // get it word2vec->getDimMinMaxs( mins, maxs ); @@ -3167,7 +3167,7 @@ struct PCA_Object } // transform - static void transform( Chuck_Array4 & input_, t_CKINT npc, Chuck_Array4 & output_ ) + static void transform( Chuck_ArrayInt & input_, t_CKINT npc, Chuck_ArrayInt & output_ ) { ChaiMatrixFast * input = chuck2chai( input_ ); @@ -3248,10 +3248,10 @@ struct PCA_Object corr_matrix now contains the associated eigenvectors. */ /* Project row data onto the top "npc_" principal components. */ - Chuck_Array8 * vi; + Chuck_ArrayFloat * vi; for( t = 0; t < n; t++ ) { - vi = (Chuck_Array8 *)output_.m_vector[t]; + vi = (Chuck_ArrayFloat *)output_.m_vector[t]; for( o = 0; o < npc; o++ ) { vi->m_vector[o] = 0.0; @@ -3286,9 +3286,9 @@ CK_DLL_DTOR( PCA_dtor ) CK_DLL_SFUN( PCA_reduce ) { // get args - Chuck_Array4 * input = (Chuck_Array4 *)GET_NEXT_OBJECT( ARGS ); + Chuck_ArrayInt * input = (Chuck_ArrayInt *)GET_NEXT_OBJECT( ARGS ); t_CKINT n_components = GET_NEXT_INT( ARGS ); - Chuck_Array4 * output = (Chuck_Array4 *)GET_NEXT_OBJECT( ARGS ); + Chuck_ArrayInt * output = (Chuck_ArrayInt *)GET_NEXT_OBJECT( ARGS ); // transform PCA_Object::transform( *input, n_components, *output ); } @@ -3534,7 +3534,7 @@ struct MLP_Object } // // train -// void train( Chuck_Array4 & inputs_, Chuck_Array4 & outputs_ ) +// void train( Chuck_ArrayInt & inputs_, Chuck_ArrayInt & outputs_ ) // { // ChaiMatrixFast * X = chuck2chai( inputs_ ); // ChaiMatrixFast * Y = chuck2chai( outputs_ ); @@ -3544,7 +3544,7 @@ struct MLP_Object // } // train2 - void train( Chuck_Array4 & inputs_, Chuck_Array4 & outputs_, t_CKFLOAT learning_rate, t_CKINT max_iterations ) + void train( Chuck_ArrayInt & inputs_, Chuck_ArrayInt & outputs_, t_CKFLOAT learning_rate, t_CKINT max_iterations ) { ChaiMatrixFast * X = chuck2chai( inputs_ ); ChaiMatrixFast * Y = chuck2chai( outputs_ ); @@ -3554,7 +3554,7 @@ struct MLP_Object } // predict - t_CKBOOL predict( Chuck_Array8 & input_, Chuck_Array8 & output_ ) + t_CKBOOL predict( Chuck_ArrayFloat & input_, Chuck_ArrayFloat & output_ ) { // sanity check if( units_per_layer.size() == 0 ) @@ -3595,7 +3595,7 @@ struct MLP_Object } // get_weights - void get_weights( t_CKINT layer, Chuck_Array4 & weights_ ) + void get_weights( t_CKINT layer, Chuck_ArrayInt & weights_ ) { // sanity check if( units_per_layer.size() == 0 ) @@ -3603,27 +3603,27 @@ struct MLP_Object // error EM_error3( "MLP.getWeights(): network not initialized" ); // courtesy clear the array - Chuck_Array8 * wi = NULL; + Chuck_ArrayFloat * wi = NULL; for( t_CKINT i = 0; i < weights_.size(); i++ ) { - wi = (Chuck_Array8 *)weights_.m_vector[i]; + wi = (Chuck_ArrayFloat *)weights_.m_vector[i]; for( t_CKINT j = 0; j < wi->size(); j++ ) wi->m_vector[j] = 0.0; } return; } - Chuck_Array8 * wi = NULL; + Chuck_ArrayFloat * wi = NULL; for( t_CKINT i = 0; i < weights_.size(); i++ ) { - wi = (Chuck_Array8 *)weights_.m_vector[i]; + wi = (Chuck_ArrayFloat *)weights_.m_vector[i]; for( t_CKINT j = 0; j < wi->size(); j++ ) wi->m_vector[j] = weights[layer]->v( j, i ); } } // get_biases - void get_biases( t_CKINT layer, Chuck_Array8 & biases_ ) + void get_biases( t_CKINT layer, Chuck_ArrayFloat & biases_ ) { // sanity check if( units_per_layer.size() == 0 ) @@ -3642,7 +3642,7 @@ struct MLP_Object } // get_gradients - void get_gradients( t_CKINT layer, Chuck_Array8 & gradients_ ) + void get_gradients( t_CKINT layer, Chuck_ArrayFloat & gradients_ ) { // sanity check if( units_per_layer.size() == 0 ) @@ -3661,7 +3661,7 @@ struct MLP_Object } // get_activations - void get_activations( t_CKINT layer, Chuck_Array8 & activations_ ) + void get_activations( t_CKINT layer, Chuck_ArrayFloat & activations_ ) { // sanity check if( units_per_layer.size() == 0 ) @@ -3680,7 +3680,7 @@ struct MLP_Object } // forward - void forward( Chuck_Array8 & input_ ) + void forward( Chuck_ArrayFloat & input_ ) { ChaiVectorFast * input = chuck2chai( input_ ); forward( *input ); @@ -3688,7 +3688,7 @@ struct MLP_Object } // backprop - void backprop( Chuck_Array8 & output_, t_CKFLOAT learning_rate ) + void backprop( Chuck_ArrayFloat & output_, t_CKFLOAT learning_rate ) { ChaiVectorFast * output = chuck2chai( output_ ); backprop( *output, learning_rate ); @@ -3839,7 +3839,7 @@ CK_DLL_MFUN( MLP_init ) // get object MLP_Object * mlp = (MLP_Object *)OBJ_MEMBER_UINT( SELF, MLP_offset_data ); // get args - Chuck_Array4 * units_per_layer = (Chuck_Array4 *)GET_NEXT_OBJECT( ARGS ); + Chuck_ArrayInt * units_per_layer = (Chuck_ArrayInt *)GET_NEXT_OBJECT( ARGS ); // init mlp->init( units_per_layer->m_vector ); } @@ -3849,8 +3849,8 @@ CK_DLL_MFUN( MLP_init2 ) // get object MLP_Object * mlp = (MLP_Object *)OBJ_MEMBER_UINT( SELF, MLP_offset_data ); // get args - Chuck_Array4 * units_per_layer = (Chuck_Array4 *)GET_NEXT_OBJECT( ARGS ); - Chuck_Array4 * activation_per_layer = (Chuck_Array4 *)GET_NEXT_OBJECT( ARGS ); + Chuck_ArrayInt * units_per_layer = (Chuck_ArrayInt *)GET_NEXT_OBJECT( ARGS ); + Chuck_ArrayInt * activation_per_layer = (Chuck_ArrayInt *)GET_NEXT_OBJECT( ARGS ); // init mlp->init( units_per_layer->m_vector, activation_per_layer->m_vector ); } @@ -3860,7 +3860,7 @@ CK_DLL_MFUN( MLP_init3 ) // get object MLP_Object * mlp = (MLP_Object *)OBJ_MEMBER_UINT( SELF, MLP_offset_data ); // get args - Chuck_Array4 * units_per_layer = (Chuck_Array4 *)GET_NEXT_OBJECT( ARGS ); + Chuck_ArrayInt * units_per_layer = (Chuck_ArrayInt *)GET_NEXT_OBJECT( ARGS ); t_CKINT activation_function = GET_NEXT_INT( ARGS ); // init mlp->init( units_per_layer->m_vector, activation_function ); @@ -3871,8 +3871,8 @@ CK_DLL_MFUN( MLP_train ) // get object MLP_Object * mlp = (MLP_Object *)OBJ_MEMBER_UINT( SELF, MLP_offset_data ); // get args - Chuck_Array4 * inputs = (Chuck_Array4 *)GET_NEXT_OBJECT( ARGS ); - Chuck_Array4 * outputs = (Chuck_Array4 *)GET_NEXT_OBJECT( ARGS ); + Chuck_ArrayInt * inputs = (Chuck_ArrayInt *)GET_NEXT_OBJECT( ARGS ); + Chuck_ArrayInt * outputs = (Chuck_ArrayInt *)GET_NEXT_OBJECT( ARGS ); // train, with defaults mlp->train( *inputs, *outputs, .01, 100 ); } @@ -3882,8 +3882,8 @@ CK_DLL_MFUN( MLP_train2 ) // get object MLP_Object * mlp = (MLP_Object *)OBJ_MEMBER_UINT( SELF, MLP_offset_data ); // get args - Chuck_Array4 * inputs = (Chuck_Array4 *)GET_NEXT_OBJECT( ARGS ); - Chuck_Array4 * outputs = (Chuck_Array4 *)GET_NEXT_OBJECT( ARGS ); + Chuck_ArrayInt * inputs = (Chuck_ArrayInt *)GET_NEXT_OBJECT( ARGS ); + Chuck_ArrayInt * outputs = (Chuck_ArrayInt *)GET_NEXT_OBJECT( ARGS ); t_CKFLOAT learning_rate = GET_NEXT_FLOAT( ARGS ); t_CKINT max_iterations = GET_NEXT_INT( ARGS ); // train2 @@ -3895,8 +3895,8 @@ CK_DLL_MFUN( MLP_predict ) // get object MLP_Object * mlp = (MLP_Object *)OBJ_MEMBER_UINT( SELF, MLP_offset_data ); // get args - Chuck_Array8 * input = (Chuck_Array8 *)GET_NEXT_OBJECT( ARGS ); - Chuck_Array8 * output = (Chuck_Array8 *)GET_NEXT_OBJECT( ARGS ); + Chuck_ArrayFloat * input = (Chuck_ArrayFloat *)GET_NEXT_OBJECT( ARGS ); + Chuck_ArrayFloat * output = (Chuck_ArrayFloat *)GET_NEXT_OBJECT( ARGS ); // predict RETURN->v_int = mlp->predict( *input, *output ); } @@ -3907,7 +3907,7 @@ CK_DLL_MFUN( MLP_get_weights ) MLP_Object * mlp = (MLP_Object *)OBJ_MEMBER_UINT( SELF, MLP_offset_data ); // get args t_CKINT layer = GET_NEXT_INT( ARGS ); - Chuck_Array4 * weights = (Chuck_Array4 *)GET_NEXT_OBJECT( ARGS ); + Chuck_ArrayInt * weights = (Chuck_ArrayInt *)GET_NEXT_OBJECT( ARGS ); // get_weights mlp->get_weights( layer, *weights ); } @@ -3918,7 +3918,7 @@ CK_DLL_MFUN( MLP_get_biases ) MLP_Object * mlp = (MLP_Object *)OBJ_MEMBER_UINT( SELF, MLP_offset_data ); // get args t_CKINT layer = GET_NEXT_INT( ARGS ); - Chuck_Array8 * biases = (Chuck_Array8 *)GET_NEXT_OBJECT( ARGS ); + Chuck_ArrayFloat * biases = (Chuck_ArrayFloat *)GET_NEXT_OBJECT( ARGS ); // get_biases mlp->get_biases( layer, *biases ); } @@ -3929,7 +3929,7 @@ CK_DLL_MFUN( MLP_get_gradients ) MLP_Object * mlp = (MLP_Object *)OBJ_MEMBER_UINT( SELF, MLP_offset_data ); // get args t_CKINT layer = GET_NEXT_INT( ARGS ); - Chuck_Array8 * gradients = (Chuck_Array8 *)GET_NEXT_OBJECT( ARGS ); + Chuck_ArrayFloat * gradients = (Chuck_ArrayFloat *)GET_NEXT_OBJECT( ARGS ); // get_gradients mlp->get_gradients( layer, *gradients ); } @@ -3940,7 +3940,7 @@ CK_DLL_MFUN( MLP_get_activations ) MLP_Object * mlp = (MLP_Object *)OBJ_MEMBER_UINT( SELF, MLP_offset_data ); // get args t_CKINT layer = GET_NEXT_INT( ARGS ); - Chuck_Array8 * activations = (Chuck_Array8 *)GET_NEXT_OBJECT( ARGS ); + Chuck_ArrayFloat * activations = (Chuck_ArrayFloat *)GET_NEXT_OBJECT( ARGS ); // get_activations mlp->get_activations( layer, *activations ); } @@ -3950,7 +3950,7 @@ CK_DLL_MFUN( MLP_forward ) // get object MLP_Object * mlp = (MLP_Object *)OBJ_MEMBER_UINT( SELF, MLP_offset_data ); // get args - Chuck_Array8 * input = (Chuck_Array8 *)GET_NEXT_OBJECT( ARGS ); + Chuck_ArrayFloat * input = (Chuck_ArrayFloat *)GET_NEXT_OBJECT( ARGS ); // forward mlp->forward( *input ); } @@ -3960,7 +3960,7 @@ CK_DLL_MFUN( MLP_backprop ) // get object MLP_Object * mlp = (MLP_Object *)OBJ_MEMBER_UINT( SELF, MLP_offset_data ); // get args - Chuck_Array8 * output = (Chuck_Array8 *)GET_NEXT_OBJECT( ARGS ); + Chuck_ArrayFloat * output = (Chuck_ArrayFloat *)GET_NEXT_OBJECT( ARGS ); t_CKFLOAT learning_rate = GET_NEXT_FLOAT( ARGS ); // backprop mlp->backprop( *output, learning_rate ); @@ -3989,8 +3989,8 @@ CK_DLL_MFUN( MLP_load ) CK_DLL_SFUN( MLP_shuffle ) { // get args - Chuck_Array4 * X = (Chuck_Array4 *)GET_NEXT_OBJECT( ARGS ); - Chuck_Array4 * Y = (Chuck_Array4 *)GET_NEXT_OBJECT( ARGS ); + Chuck_ArrayInt * X = (Chuck_ArrayInt *)GET_NEXT_OBJECT( ARGS ); + Chuck_ArrayInt * Y = (Chuck_ArrayInt *)GET_NEXT_OBJECT( ARGS ); // shuffle shuffle( *X, *Y ); } @@ -4459,7 +4459,7 @@ struct Wekinator_Object } // set_inputs - void set_inputs( Chuck_Array8 & inputs_ ) + void set_inputs( Chuck_ArrayFloat & inputs_ ) { if( num_inputs == 0 ) set_num_inputs( inputs_.size() ); @@ -4472,7 +4472,7 @@ struct Wekinator_Object } // set_outputs - void set_outputs( Chuck_Array8 & outputs_ ) + void set_outputs( Chuck_ArrayFloat & outputs_ ) { if( num_outputs == 0 ) set_num_outputs( outputs_.size() ); @@ -5086,7 +5086,7 @@ struct Wekinator_Object } // set_output_property3 - void set_output_property( t_CKINT output_index, Chuck_String & property_name, Chuck_Array4 & property_value_ ) + void set_output_property( t_CKINT output_index, Chuck_String & property_name, Chuck_ArrayInt & property_value_ ) { // sanity check if( output_index < 0 || output_index >= num_outputs ) @@ -5121,7 +5121,7 @@ struct Wekinator_Object } // get_output_property - void get_output_property( t_CKINT output_index, Chuck_String & property_name, Chuck_Array4 & property_value_ ) + void get_output_property( t_CKINT output_index, Chuck_String & property_name, Chuck_ArrayInt & property_value_ ) { // sanity check if( output_index < 0 || output_index >= num_outputs ) @@ -5186,7 +5186,7 @@ struct Wekinator_Object } // predict - void predict( Chuck_Array8 & inputs_, Chuck_Array8 & outputs_ ) + void predict( Chuck_ArrayFloat & inputs_, Chuck_ArrayFloat & outputs_ ) { // sanity check if( inputs_.size() != num_inputs ) @@ -5342,7 +5342,7 @@ struct Wekinator_Object } // get_obs - void get_obs( Chuck_Array4 & obs_ ) + void get_obs( Chuck_ArrayInt & obs_ ) { // sanity check if( obs_.size() < dummy_model.example_ids.size() ) @@ -5350,19 +5350,19 @@ struct Wekinator_Object EM_error3( "Wekinator.get_obs: input array too small." ); return; } - Chuck_Array8 * row; + Chuck_ArrayFloat * row; t_CKINT dim = 3 + num_inputs + num_outputs; // copy for( t_CKINT i = 0; i < dummy_model.example_ids.size(); i++ ) { - row = (Chuck_Array8 *)obs_.m_vector[i]; + row = (Chuck_ArrayFloat *)obs_.m_vector[i]; row->set_size( dim ); row->m_vector = examples[dummy_model.example_ids[i]]; } } // get_obs1 - void get_obs1( t_CKINT output_index, Chuck_Array4 & obs_ ) + void get_obs1( t_CKINT output_index, Chuck_ArrayInt & obs_ ) { // sanity check if( output_index < 0 || output_index >= num_outputs ) @@ -5375,12 +5375,12 @@ struct Wekinator_Object EM_error3( "Wekinator.get_obs1: input array too small." ); return; } - Chuck_Array8 * row; + Chuck_ArrayFloat * row; t_CKINT dim = 3 + num_inputs + num_outputs; // copy for( t_CKINT i = 0; i < models[output_index].example_ids.size(); i++ ) { - row = (Chuck_Array8 *)obs_.m_vector[i]; + row = (Chuck_ArrayFloat *)obs_.m_vector[i]; row->set_size( dim ); row->m_vector = examples[models[output_index].example_ids[i]]; } @@ -5722,7 +5722,7 @@ struct Wekinator_Object } // add1 - void add1( Chuck_Array8 & inputs_, Chuck_Array8 & outputs_ ) + void add1( Chuck_ArrayFloat & inputs_, Chuck_ArrayFloat & outputs_ ) { // sanity check if( inputs_.size() != num_inputs ) @@ -5744,7 +5744,7 @@ struct Wekinator_Object } // add2 - void add2( t_CKINT output_index, Chuck_Array8 & inputs_, Chuck_Array8 & outputs_ ) + void add2( t_CKINT output_index, Chuck_ArrayFloat & inputs_, Chuck_ArrayFloat & outputs_ ) { // sanity check if( output_index < 0 || output_index >= num_outputs ) @@ -6058,7 +6058,7 @@ CK_DLL_MFUN( Wekinator_set_output_property3 ) // get args t_CKINT output_index = GET_NEXT_INT( ARGS ); Chuck_String * property_name = GET_NEXT_STRING( ARGS ); - Chuck_Array4 * property_value = (Chuck_Array4 *)GET_NEXT_OBJECT( ARGS ); + Chuck_ArrayInt * property_value = (Chuck_ArrayInt *)GET_NEXT_OBJECT( ARGS ); // set_output_property3 wekinator->set_output_property( output_index, *property_name, *property_value ); } @@ -6070,7 +6070,7 @@ CK_DLL_MFUN( Wekinator_get_output_property ) // get args t_CKINT output_index = GET_NEXT_INT( ARGS ); Chuck_String * property_name = GET_NEXT_STRING( ARGS ); - Chuck_Array4 * property_value = (Chuck_Array4 *)GET_NEXT_OBJECT( ARGS ); + Chuck_ArrayInt * property_value = (Chuck_ArrayInt *)GET_NEXT_OBJECT( ARGS ); // get_output_property wekinator->get_output_property( output_index, *property_name, *property_value ); } @@ -6080,7 +6080,7 @@ CK_DLL_MFUN( Wekinator_set_inputs ) // get object Wekinator_Object * wekinator = (Wekinator_Object *)OBJ_MEMBER_UINT( SELF, Wekinator_offset_data ); // get args - Chuck_Array8 * inputs = (Chuck_Array8 *)GET_NEXT_OBJECT( ARGS ); + Chuck_ArrayFloat * inputs = (Chuck_ArrayFloat *)GET_NEXT_OBJECT( ARGS ); // set_inputs wekinator->set_inputs( *inputs ); } @@ -6090,7 +6090,7 @@ CK_DLL_MFUN( Wekinator_set_outputs ) // get object Wekinator_Object * wekinator = (Wekinator_Object *)OBJ_MEMBER_UINT( SELF, Wekinator_offset_data ); // get args - Chuck_Array8 * outputs = (Chuck_Array8 *)GET_NEXT_OBJECT( ARGS ); + Chuck_ArrayFloat * outputs = (Chuck_ArrayFloat *)GET_NEXT_OBJECT( ARGS ); // set_outputs wekinator->set_outputs( *outputs ); } @@ -6126,7 +6126,7 @@ CK_DLL_MFUN( Wekinator_get_obs ) // get object Wekinator_Object * wekinator = (Wekinator_Object *)OBJ_MEMBER_UINT( SELF, Wekinator_offset_data ); // get args - Chuck_Array4 * obs = (Chuck_Array4 *)GET_NEXT_OBJECT( ARGS ); + Chuck_ArrayInt * obs = (Chuck_ArrayInt *)GET_NEXT_OBJECT( ARGS ); // get_obs wekinator->get_obs( *obs ); } @@ -6137,7 +6137,7 @@ CK_DLL_MFUN( Wekinator_get_obs1 ) Wekinator_Object * wekinator = (Wekinator_Object *)OBJ_MEMBER_UINT( SELF, Wekinator_offset_data ); // get args t_CKINT output_index = GET_NEXT_INT( ARGS ); - Chuck_Array4 * obs = (Chuck_Array4 *)GET_NEXT_OBJECT( ARGS ); + Chuck_ArrayInt * obs = (Chuck_ArrayInt *)GET_NEXT_OBJECT( ARGS ); // get_obs1 wekinator->get_obs1( output_index, *obs ); } @@ -6309,8 +6309,8 @@ CK_DLL_MFUN( Wekinator_add1 ) // get object Wekinator_Object * wekinator = (Wekinator_Object *)OBJ_MEMBER_UINT( SELF, Wekinator_offset_data ); // get args - Chuck_Array8 * inputs = (Chuck_Array8 *)GET_NEXT_OBJECT( ARGS ); - Chuck_Array8 * outputs = (Chuck_Array8 *)GET_NEXT_OBJECT( ARGS ); + Chuck_ArrayFloat * inputs = (Chuck_ArrayFloat *)GET_NEXT_OBJECT( ARGS ); + Chuck_ArrayFloat * outputs = (Chuck_ArrayFloat *)GET_NEXT_OBJECT( ARGS ); // add1 wekinator->add1( *inputs, *outputs ); } @@ -6321,8 +6321,8 @@ CK_DLL_MFUN( Wekinator_add2 ) Wekinator_Object * wekinator = (Wekinator_Object *)OBJ_MEMBER_UINT( SELF, Wekinator_offset_data ); // get args t_CKINT output_index = GET_NEXT_INT( ARGS ); - Chuck_Array8 * inputs = (Chuck_Array8 *)GET_NEXT_OBJECT( ARGS ); - Chuck_Array8 * outputs = (Chuck_Array8 *)GET_NEXT_OBJECT( ARGS ); + Chuck_ArrayFloat * inputs = (Chuck_ArrayFloat *)GET_NEXT_OBJECT( ARGS ); + Chuck_ArrayFloat * outputs = (Chuck_ArrayFloat *)GET_NEXT_OBJECT( ARGS ); // add2 wekinator->add2( output_index, *inputs, *outputs ); } @@ -6348,8 +6348,8 @@ CK_DLL_MFUN( Wekinator_predict ) // get object Wekinator_Object * wekinator = (Wekinator_Object *)OBJ_MEMBER_UINT( SELF, Wekinator_offset_data ); // get args - Chuck_Array8 * inputs = (Chuck_Array8 *)GET_NEXT_OBJECT( ARGS ); - Chuck_Array8 * outputs = (Chuck_Array8 *)GET_NEXT_OBJECT( ARGS ); + Chuck_ArrayFloat * inputs = (Chuck_ArrayFloat *)GET_NEXT_OBJECT( ARGS ); + Chuck_ArrayFloat * outputs = (Chuck_ArrayFloat *)GET_NEXT_OBJECT( ARGS ); // predict wekinator->predict( *inputs, *outputs ); } diff --git a/src/core/ulib_doc.cpp b/src/core/ulib_doc.cpp index 2d798294f..c1d9d6438 100644 --- a/src/core/ulib_doc.cpp +++ b/src/core/ulib_doc.cpp @@ -1377,7 +1377,7 @@ CK_DLL_DTOR( CKDoc_dtor ) CK_DLL_MFUN( CKDoc_addGroup_type ) { CKDoc * ckdoc = (CKDoc *)OBJ_MEMBER_UINT(SELF, CKDoc_offset_data); - Chuck_Array4 * typeArray = (Chuck_Array4 *)GET_NEXT_OBJECT(ARGS); + Chuck_ArrayInt * typeArray = (Chuck_ArrayInt *)GET_NEXT_OBJECT(ARGS); Chuck_String * groupName = GET_NEXT_STRING(ARGS); Chuck_String * shortName = GET_NEXT_STRING(ARGS); Chuck_String * description = GET_NEXT_STRING(ARGS); @@ -1430,7 +1430,7 @@ CK_DLL_MFUN( CKDoc_addGroup_type ) CK_DLL_MFUN( CKDoc_addGroup_str ) { CKDoc * ckdoc = (CKDoc *)OBJ_MEMBER_UINT(SELF, CKDoc_offset_data); - Chuck_Array4 * strArray = (Chuck_Array4 *)GET_NEXT_OBJECT(ARGS); + Chuck_ArrayInt * strArray = (Chuck_ArrayInt *)GET_NEXT_OBJECT(ARGS); Chuck_String * groupName = GET_NEXT_STRING(ARGS); Chuck_String * shortName = GET_NEXT_STRING(ARGS); Chuck_String * desc = GET_NEXT_STRING(ARGS); @@ -1560,7 +1560,7 @@ CK_DLL_MFUN( CKDoc_genGroups ) { CKDoc * ckdoc = (CKDoc *)OBJ_MEMBER_UINT(SELF, CKDoc_offset_data); // the return array - Chuck_Array4 * strArray = (Chuck_Array4 *)GET_NEXT_OBJECT(ARGS); + Chuck_ArrayInt * strArray = (Chuck_ArrayInt *)GET_NEXT_OBJECT(ARGS); // the c++ return vector vector results; // gen the groups diff --git a/src/core/ulib_machine.cpp b/src/core/ulib_machine.cpp index a9beb1f2f..ca0b4a350 100644 --- a/src/core/ulib_machine.cpp +++ b/src/core/ulib_machine.cpp @@ -512,7 +512,7 @@ CK_DLL_SFUN( machine_silent_impl ) CK_DLL_SFUN( machine_shreds_impl ) { - Chuck_Array4 *array = new Chuck_Array4(FALSE); + Chuck_ArrayInt *array = new Chuck_ArrayInt(FALSE); initialize_object(array, SHRED->vm_ref->env()->ckt_array, SHRED, VM); array->clear(); diff --git a/src/core/ulib_math.cpp b/src/core/ulib_math.cpp index 140b6312e..06b7d9a57 100644 --- a/src/core/ulib_math.cpp +++ b/src/core/ulib_math.cpp @@ -983,8 +983,8 @@ CK_DLL_SFUN( gauss_impl ) // cossim (ge) | added 1.5.0.0 CK_DLL_SFUN( cossim_impl ) { - Chuck_Array8 * a = (Chuck_Array8 *)GET_NEXT_OBJECT( ARGS ); - Chuck_Array8 * b = (Chuck_Array8 *)GET_NEXT_OBJECT( ARGS ); + Chuck_ArrayFloat * a = (Chuck_ArrayFloat *)GET_NEXT_OBJECT( ARGS ); + Chuck_ArrayFloat * b = (Chuck_ArrayFloat *)GET_NEXT_OBJECT( ARGS ); t_CKINT size = 0; // in case of error @@ -1111,8 +1111,8 @@ CK_DLL_SFUN( cossim4d_impl ) // euclidean (ge) | added 1.5.0.0 CK_DLL_SFUN( euclidean_impl ) { - Chuck_Array8 * a = (Chuck_Array8 *)GET_NEXT_OBJECT( ARGS ); - Chuck_Array8 * b = (Chuck_Array8 *)GET_NEXT_OBJECT( ARGS ); + Chuck_ArrayFloat * a = (Chuck_ArrayFloat *)GET_NEXT_OBJECT( ARGS ); + Chuck_ArrayFloat * b = (Chuck_ArrayFloat *)GET_NEXT_OBJECT( ARGS ); t_CKINT size = 0; // in case of error diff --git a/src/core/ulib_opsc.cpp b/src/core/ulib_opsc.cpp index c71b611d7..1fb75583d 100644 --- a/src/core/ulib_opsc.cpp +++ b/src/core/ulib_opsc.cpp @@ -1481,7 +1481,7 @@ CK_DLL_MFUN( oscin_recv ) OscMsg msg; // some local for later - Chuck_Array4 * args_obj = NULL; + Chuck_ArrayInt * args_obj = NULL; Chuck_Type * oscarg_type = NULL; int i; @@ -1499,7 +1499,7 @@ CK_DLL_MFUN( oscin_recv ) OBJ_MEMBER_STRING( msg_obj, oscmsg_offset_address )->set( msg.path ); OBJ_MEMBER_STRING( msg_obj, oscmsg_offset_typetag )->set( msg.type ); // get the array at OscMsg.args - args_obj = (Chuck_Array4 *)OBJ_MEMBER_OBJECT( msg_obj, oscmsg_offset_args ); + args_obj = (Chuck_ArrayInt *)OBJ_MEMBER_OBJECT( msg_obj, oscmsg_offset_args ); // clear it (which will also memory-manage existing contents) args_obj->clear(); // find the type corresponding to chuck-side OscArg @@ -1557,7 +1557,7 @@ CK_DLL_CTOR( oscmsg_ctor ) CK_SAFE_ADD_REF( typetag ); OBJ_MEMBER_STRING( SELF, oscmsg_offset_typetag ) = typetag; - Chuck_Array4 * args = new Chuck_Array4( TRUE ); + Chuck_ArrayInt * args = new Chuck_ArrayInt( TRUE ); initialize_object( args, SHRED->vm_ref->env()->ckt_array, SHRED, VM ); args->clear(); CK_SAFE_ADD_REF( args ); @@ -1578,14 +1578,14 @@ CK_DLL_DTOR( oscmsg_dtor ) CK_DLL_MFUN( oscmsg_numArgs ) { - Chuck_Array4 * args_obj = (Chuck_Array4 *)OBJ_MEMBER_OBJECT( SELF, oscmsg_offset_args ); + Chuck_ArrayInt * args_obj = (Chuck_ArrayInt *)OBJ_MEMBER_OBJECT( SELF, oscmsg_offset_args ); RETURN->v_int = args_obj->size(); } CK_DLL_MFUN( oscmsg_getInt ) { int i = GET_NEXT_INT( ARGS ); - Chuck_Array4 * args_obj = (Chuck_Array4 *)OBJ_MEMBER_OBJECT( SELF, oscmsg_offset_args ); + Chuck_ArrayInt * args_obj = (Chuck_ArrayInt *)OBJ_MEMBER_OBJECT( SELF, oscmsg_offset_args ); Chuck_Object * arg_obj; // check bounds @@ -1603,7 +1603,7 @@ CK_DLL_MFUN( oscmsg_getInt ) CK_DLL_MFUN( oscmsg_getFloat ) { int i = GET_NEXT_INT( ARGS ); - Chuck_Array4 * args_obj = (Chuck_Array4 *)OBJ_MEMBER_OBJECT( SELF, oscmsg_offset_args ); + Chuck_ArrayInt * args_obj = (Chuck_ArrayInt *)OBJ_MEMBER_OBJECT( SELF, oscmsg_offset_args ); Chuck_Object * arg_obj; if( i >= 0 && i < args_obj->size() ) { @@ -1617,7 +1617,7 @@ CK_DLL_MFUN( oscmsg_getFloat ) CK_DLL_MFUN( oscmsg_getString ) { int i = GET_NEXT_INT( ARGS ); - Chuck_Array4 * args_obj = (Chuck_Array4 *)OBJ_MEMBER_OBJECT( SELF, oscmsg_offset_args ); + Chuck_ArrayInt * args_obj = (Chuck_ArrayInt *)OBJ_MEMBER_OBJECT( SELF, oscmsg_offset_args ); Chuck_Object * arg_obj; if( i >= 0 && i < args_obj->size() ) diff --git a/src/core/ulib_std.cpp b/src/core/ulib_std.cpp index b073fce79..123c90b34 100644 --- a/src/core/ulib_std.cpp +++ b/src/core/ulib_std.cpp @@ -964,7 +964,7 @@ CK_DLL_SFUN( scalef_impl ) } // common internal function for range() | 1.5.1.1 (nshaheed) -static Chuck_Array4 * ck_range( t_CKINT start, t_CKINT stop, t_CKINT step, Chuck_VM_Shred * SHRED ) +static Chuck_ArrayInt * ck_range( t_CKINT start, t_CKINT stop, t_CKINT step, Chuck_VM_Shred * SHRED ) { // size t_CKINT size = 0; @@ -973,7 +973,7 @@ static Chuck_Array4 * ck_range( t_CKINT start, t_CKINT stop, t_CKINT step, Chuck else if( start > stop && step < 0 ) size = (start-stop)/(-step) + ((start-stop)%(-step) ? 1 : 0); // allocate array object - Chuck_Array4 * range = new Chuck_Array4(FALSE, size); + Chuck_ArrayInt * range = new Chuck_ArrayInt(FALSE, size); // initialize with trappings of Object initialize_object(range, SHRED->vm_ref->env()->ckt_array, SHRED, SHRED->vm_ref); From 2f0e4d673ef4bdcb9bbd91e1a24eac8b9c955073 Mon Sep 17 00:00:00 2001 From: Ge Wang Date: Tue, 3 Oct 2023 01:16:24 -0700 Subject: [PATCH 07/26] move invoke_mfun_immediate_mode to VM DL API --- src/core/chuck_dl.cpp | 4 ++-- src/core/chuck_dl.h | 13 +++++++------ 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/src/core/chuck_dl.cpp b/src/core/chuck_dl.cpp index cc8cb2427..853363d7d 100644 --- a/src/core/chuck_dl.cpp +++ b/src/core/chuck_dl.cpp @@ -1251,7 +1251,6 @@ Chuck_DL_Query::Chuck_DL_Query( Chuck_Carrier * carrier, Chuck_DLL * dll ) create_main_thread_hook = ck_create_main_thread_hook; register_shreds_watcher = ck_register_shreds_watcher; // 1.5.1.4 (ge & andrew) unregister_shreds_watcher = ck_unregister_shreds_watcher; // 1.5.1.4 (ge & andrew) - invoke_mfun_immediate_mode = ck_invoke_mfun_immediate_mode; // 1.5.1.4 (ge & andrew) m_carrier = carrier; dll_ref = dll; // 1.5.1.3 (ge) added @@ -1824,7 +1823,8 @@ static t_CKBOOL ck_array_int_get_key( CK_DL_API api, Chuck_DL_Api::ArrayInt a, c Chuck_DL_Api::Api::VMApi::VMApi() : srate(ck_srate), create_event_buffer(ck_create_event_buffer), -queue_event(ck_queue_event) +queue_event(ck_queue_event), +invoke_mfun_immediate_mode(ck_invoke_mfun_immediate_mode) { } diff --git a/src/core/chuck_dl.h b/src/core/chuck_dl.h index fcd7c65f6..2d784025d 100644 --- a/src/core/chuck_dl.h +++ b/src/core/chuck_dl.h @@ -498,12 +498,6 @@ struct Chuck_DL_Query // un-register shred notifcations | 1.5.1.4 (ge & andrew) f_unregister_shreds_watcher unregister_shreds_watcher; - // invoke a member function (defined either in chuck or c++) - // NOTE this will call the member function in IMMEDIATE MODE, - // marking it as a time-critical function when called in this manner; - // any time/event operations therein will throw an exception - f_invoke_mfun invoke_mfun_immediate_mode; - public: //------------------------------------------------------------------------- // NOTE: everything below std::anything cannot be reliably accessed @@ -841,6 +835,13 @@ struct Api CBufferSimple * (* const create_event_buffer)( Chuck_VM * vm ); // queue an event; num_msg must be 1; buffer should be created using create_event_buffer() above | 1.5.1.4 t_CKBOOL (* const queue_event)( Chuck_VM * vm, Chuck_Event * event, t_CKINT num_msg, CBufferSimple * buffer ); + // invoke Chuck_Object member function (defined either in chuck or c++) | 1.5.1.4 (ge & andrew) + // NOTE this will call the member function in IMMEDIATE MODE, + // marking it as a time-critical function when called in this manner; + // any time/event operations therein will throw an exception + // Chuck_DL_Return (CK_DLL_CALL * invoke_mfun_immediate_mode) + // ( Chuck_Object * obj, t_CKUINT func_vt_offset, Chuck_VM * vm, Chuck_VM_Shred * shred, Chuck_DL_Arg * ARGS, t_CKUINT numArgs ); + f_invoke_mfun invoke_mfun_immediate_mode; } * const vm; struct ObjectApi From 4b6bd53eedf01d7f506622d1d2d0cd9b3d392bd0 Mon Sep 17 00:00:00 2001 From: Ge Wang Date: Tue, 3 Oct 2023 02:34:07 -0700 Subject: [PATCH 08/26] add DL func get_vtable_offset() --- src/core/chuck_dl.cpp | 24 ++++++++++++++++++++++++ src/core/chuck_dl.h | 2 ++ 2 files changed, 26 insertions(+) diff --git a/src/core/chuck_dl.cpp b/src/core/chuck_dl.cpp index 853363d7d..66ad66ba5 100644 --- a/src/core/chuck_dl.cpp +++ b/src/core/chuck_dl.cpp @@ -1441,6 +1441,29 @@ static Chuck_DL_Api::Type ck_get_type( CK_DL_API api, Chuck_VM * vm, const char } +//----------------------------------------------------------------------------- +// name: ck_get_vtable_offset() +// desc: function pointer get_type() +//----------------------------------------------------------------------------- +t_CKINT ck_get_vtable_offset( CK_DL_API, Chuck_VM * vm, const char * typeName, const char * valueName ) +{ + // get the type + Chuck_Env * env = vm->env(); + a_Id_List list = new_id_list( typeName, 0, 0 /*, NULL*/ ); // TODO: nested types + Chuck_Type * t = type_engine_find_type( env, list ); + delete_id_list( list ); + // type not found + if( !t ) return -1; + + // find the offset for value by name + Chuck_Value * value = type_engine_find_value( t, valueName ); + // value not found + if( !value || !value->func_ref ) return -1; + // return it + return value->func_ref->vt_index; +} + + //----------------------------------------------------------------------------- // name: ck_create_with_shred() // desc: host-side hook implementation for instantiating and initializing @@ -1835,6 +1858,7 @@ invoke_mfun_immediate_mode(ck_invoke_mfun_immediate_mode) //----------------------------------------------------------------------------- Chuck_DL_Api::Api::ObjectApi::ObjectApi() : get_type(ck_get_type), +get_vtable_offset(ck_get_vtable_offset), create_with_shred(ck_create_with_shred), create_no_shred(ck_create_no_shred), create_string(ck_create_string), diff --git a/src/core/chuck_dl.h b/src/core/chuck_dl.h index 2d784025d..73bbdfd75 100644 --- a/src/core/chuck_dl.h +++ b/src/core/chuck_dl.h @@ -854,6 +854,8 @@ struct Api public: // function pointer get_type() Type (* const get_type)( CK_DL_API, Chuck_VM *, const char * name ); + // function pointer for get_vtable_offset(); returns < 0 if not found + t_CKINT (* const get_vtable_offset)( CK_DL_API, Chuck_VM *, const char * typee, const char * value ); // function pointer create_with_shred() Object (* const create_with_shred)( CK_DL_API, Chuck_VM_Shred *, Type type ); // function pointer create_no_shred() From 01978cf6fc04d976bd4365d9ef8c0e5ca12f1344 Mon Sep 17 00:00:00 2001 From: Ge Wang Date: Tue, 3 Oct 2023 18:59:36 -0700 Subject: [PATCH 09/26] DL api funcs update; exception and em_log --- src/core/chuck_dl.cpp | 86 ++++++++++++++++++++++++++++++++----------- src/core/chuck_dl.h | 40 ++++++++++++-------- 2 files changed, 89 insertions(+), 37 deletions(-) diff --git a/src/core/chuck_dl.cpp b/src/core/chuck_dl.cpp index 66ad66ba5..149f0e100 100644 --- a/src/core/chuck_dl.cpp +++ b/src/core/chuck_dl.cpp @@ -64,8 +64,8 @@ char g_chugin_path_envvar[] = "CHUCK_CHUGIN_PATH"; // function prototypes //----------------------------------------------------------------------------- void CK_DLL_CALL ck_add_arg( Chuck_DL_Query * query, const char * type, const char * name ); - - +void CK_DLL_CALL ck_throw_exception( const char * exception, const char * desc, Chuck_VM_Shred * shred ); +void CK_DLL_CALL ck_em_log( t_CKINT level, const char * text ); //----------------------------------------------------------------------------- @@ -1431,7 +1431,7 @@ static t_CKBOOL ck_queue_event( Chuck_VM * vm, Chuck_Event * event, t_CKINT num_ // name: ck_get_type() // desc: host-side hook implementation for retrieving a type by name //----------------------------------------------------------------------------- -static Chuck_DL_Api::Type ck_get_type( CK_DL_API api, Chuck_VM * vm, const char * name ) +static Chuck_DL_Api::Type ck_get_type( Chuck_VM * vm, const char * name ) { Chuck_Env * env = vm->env(); a_Id_List list = new_id_list( name, 0, 0 /*, NULL*/ ); // TODO: nested types @@ -1445,7 +1445,7 @@ static Chuck_DL_Api::Type ck_get_type( CK_DL_API api, Chuck_VM * vm, const char // name: ck_get_vtable_offset() // desc: function pointer get_type() //----------------------------------------------------------------------------- -t_CKINT ck_get_vtable_offset( CK_DL_API, Chuck_VM * vm, const char * typeName, const char * valueName ) +t_CKINT ck_get_vtable_offset( Chuck_VM * vm, const char * typeName, const char * valueName ) { // get the type Chuck_Env * env = vm->env(); @@ -1473,7 +1473,7 @@ t_CKINT ck_get_vtable_offset( CK_DL_API, Chuck_VM * vm, const char * typeName, c // is then invoked from c++ (e.g., using ck_invoke_mfun_immediate_mode) // and 3) that member function references global scope variables //----------------------------------------------------------------------------- -static Chuck_DL_Api::Object ck_create_with_shred( CK_DL_API api, Chuck_VM_Shred * shred, Chuck_DL_Api::Type t ) +static Chuck_DL_Api::Object ck_create_with_shred( Chuck_VM_Shred * shred, Chuck_DL_Api::Type t ) { // check | 1.5.0.1 (ge) changed; used to be assert t != NULL if( t == NULL ) @@ -1494,12 +1494,12 @@ static Chuck_DL_Api::Object ck_create_with_shred( CK_DL_API api, Chuck_VM_Shred //----------------------------------------------------------------------------- -// name: ck_create_no_shred() +// name: ck_create_without_shred() // desc: host-side hook implementation for instantiating and initializing // a ChucK object by type, without a parent shred; see ck_create_with_shred() // for more details //----------------------------------------------------------------------------- -static Chuck_DL_Api::Object ck_create_no_shred( CK_DL_API api, Chuck_VM * vm, Chuck_DL_Api::Type t ) +static Chuck_DL_Api::Object ck_create_without_shred( Chuck_VM * vm, Chuck_DL_Api::Type t ) { // check | 1.5.0.1 (ge) changed; used to be assert t != NULL if( t == NULL ) @@ -1523,7 +1523,7 @@ static Chuck_DL_Api::Object ck_create_no_shred( CK_DL_API api, Chuck_VM * vm, Ch // name: ck_create_string() // desc: host-side hook implementation for creating a chuck string //----------------------------------------------------------------------------- -static Chuck_DL_Api::String ck_create_string( CK_DL_API api, Chuck_VM * vm, const char * cstr ) +static Chuck_DL_Api::String ck_create_string( Chuck_VM * vm, const char * cstr ) { // instantiate and initalize object Chuck_String * string = (Chuck_String *)instantiate_and_initialize_object( vm->env()->ckt_string, vm ); @@ -1599,7 +1599,7 @@ static t_CKBOOL ck_get_mvar(Chuck_DL_Api::Object o, const char * name, te_Type b // name: ck_get_mvar_int() // desc: retrieve a class's member variable of type int //----------------------------------------------------------------------------- -static t_CKBOOL ck_get_mvar_int(CK_DL_API api, Chuck_DL_Api::Object obj, const char* name, t_CKINT & value) +static t_CKBOOL ck_get_mvar_int( Chuck_DL_Api::Object obj, const char * name, t_CKINT & value ) { // default value value = 0; @@ -1625,7 +1625,7 @@ static t_CKBOOL ck_get_mvar_int(CK_DL_API api, Chuck_DL_Api::Object obj, const c // name: ck_get_mvar_float() // desc: retrieve a class's member variable of type float //----------------------------------------------------------------------------- -static t_CKBOOL ck_get_mvar_float( CK_DL_API api, Chuck_DL_Api::Object obj, const char* name, t_CKFLOAT & value ) +static t_CKBOOL ck_get_mvar_float( Chuck_DL_Api::Object obj, const char* name, t_CKFLOAT & value ) { // default value value = 0.0; @@ -1648,11 +1648,13 @@ static t_CKBOOL ck_get_mvar_float( CK_DL_API api, Chuck_DL_Api::Object obj, cons } + + //----------------------------------------------------------------------------- // name: ck_get_mvar_dur() // desc: retrieve a class's member variable of type dur //----------------------------------------------------------------------------- -static t_CKBOOL ck_get_mvar_dur( CK_DL_API api, Chuck_DL_Api::Object obj, const char * name, t_CKDUR & value ) +static t_CKBOOL ck_get_mvar_dur( Chuck_DL_Api::Object obj, const char * name, t_CKDUR & value ) { // default value value = 0.0; @@ -1679,7 +1681,7 @@ static t_CKBOOL ck_get_mvar_dur( CK_DL_API api, Chuck_DL_Api::Object obj, const // name: ck_get_mvar_time() // desc: retrieve a class's member variable of type time //----------------------------------------------------------------------------- -static t_CKBOOL ck_get_mvar_time( CK_DL_API api, Chuck_DL_Api::Object obj, const char * name, t_CKTIME & value ) +static t_CKBOOL ck_get_mvar_time( Chuck_DL_Api::Object obj, const char * name, t_CKTIME & value ) { // default value value = 0.0; @@ -1706,7 +1708,7 @@ static t_CKBOOL ck_get_mvar_time( CK_DL_API api, Chuck_DL_Api::Object obj, const // name: ck_get_mvar_string() // desc: retrieve a class's member variable of type string //----------------------------------------------------------------------------- -static t_CKBOOL ck_get_mvar_string( CK_DL_API api, Chuck_DL_Api::Object obj, const char * name, Chuck_DL_Api::String & str ) +static t_CKBOOL ck_get_mvar_string( Chuck_DL_Api::Object obj, const char * name, Chuck_DL_Api::String & str ) { // default value str = NULL; @@ -1732,7 +1734,7 @@ static t_CKBOOL ck_get_mvar_string( CK_DL_API api, Chuck_DL_Api::Object obj, con // name: ck_get_mvar_object() // desc: retrieve a class's member variable of type object //----------------------------------------------------------------------------- -static t_CKBOOL ck_get_mvar_object( CK_DL_API api, Chuck_DL_Api::Object obj, const char * name, Chuck_DL_Api::Object & object ) +static t_CKBOOL ck_get_mvar_object( Chuck_DL_Api::Object obj, const char * name, Chuck_DL_Api::Object & object ) { // default object = NULL; @@ -1759,7 +1761,7 @@ static t_CKBOOL ck_get_mvar_object( CK_DL_API api, Chuck_DL_Api::Object obj, con // name: ck_set_string() // desc: set a chuck string //----------------------------------------------------------------------------- -static t_CKBOOL ck_set_string( CK_DL_API api, Chuck_DL_Api::String s, const char * str ) +static t_CKBOOL ck_set_string( Chuck_DL_Api::String s, const char * str ) { // check | 1.5.0.1 (ge) changed from assert s != NULL if( s == NULL ) return FALSE; @@ -1776,7 +1778,7 @@ static t_CKBOOL ck_set_string( CK_DL_API api, Chuck_DL_Api::String s, const char // name: ck_array_int_size() // desc: get size of an array | 1.5.1.3 (nshaheed) added //----------------------------------------------------------------------------- -static t_CKBOOL ck_array_int_size( CK_DL_API api, Chuck_DL_Api::ArrayInt a, t_CKINT & value ) +static t_CKBOOL ck_array_int_size( Chuck_DL_Api::ArrayInt a, t_CKINT & value ) { // default value value = 0; @@ -1795,7 +1797,7 @@ static t_CKBOOL ck_array_int_size( CK_DL_API api, Chuck_DL_Api::ArrayInt a, t_CK // name: ck_array_int_push_back() // desc: push back an element into an array | 1.5.0.1 (ge) added //----------------------------------------------------------------------------- -static t_CKBOOL ck_array_int_push_back( CK_DL_API api, Chuck_DL_Api::ArrayInt a, t_CKUINT value ) +static t_CKBOOL ck_array_int_push_back( Chuck_DL_Api::ArrayInt a, t_CKUINT value ) { // check if( a == NULL ) return FALSE; @@ -1812,7 +1814,7 @@ static t_CKBOOL ck_array_int_push_back( CK_DL_API api, Chuck_DL_Api::ArrayInt a, // name: ck_array_int_get_idx() // desc: get an indexed element from an array | 1.5.1.3 (nshaheed) added //----------------------------------------------------------------------------- -static t_CKBOOL ck_array_int_get_idx( CK_DL_API api, Chuck_DL_Api::ArrayInt a, t_CKINT idx, t_CKUINT & value ) +static t_CKBOOL ck_array_int_get_idx( Chuck_DL_Api::ArrayInt a, t_CKINT idx, t_CKUINT & value ) { // check if( a == NULL ) return FALSE; @@ -1827,7 +1829,7 @@ static t_CKBOOL ck_array_int_get_idx( CK_DL_API api, Chuck_DL_Api::ArrayInt a, t // name: ck_array_int_get() // desc: get a keyed element from an array | 1.5.1.3 (nshaheed) added //----------------------------------------------------------------------------- -static t_CKBOOL ck_array_int_get_key( CK_DL_API api, Chuck_DL_Api::ArrayInt a, const std::string& key, t_CKUINT & value ) +static t_CKBOOL ck_array_int_get_key( Chuck_DL_Api::ArrayInt a, const std::string& key, t_CKUINT & value ) { // check if( a == NULL ) return FALSE; @@ -1847,7 +1849,9 @@ Chuck_DL_Api::Api::VMApi::VMApi() : srate(ck_srate), create_event_buffer(ck_create_event_buffer), queue_event(ck_queue_event), -invoke_mfun_immediate_mode(ck_invoke_mfun_immediate_mode) +invoke_mfun_immediate_mode(ck_invoke_mfun_immediate_mode), +throw_exception(ck_throw_exception), +em_log(ck_em_log) { } @@ -1860,7 +1864,7 @@ Chuck_DL_Api::Api::ObjectApi::ObjectApi() : get_type(ck_get_type), get_vtable_offset(ck_get_vtable_offset), create_with_shred(ck_create_with_shred), -create_no_shred(ck_create_no_shred), +create_without_shred(ck_create_without_shred), create_string(ck_create_string), get_mvar_int(ck_get_mvar_int), get_mvar_float(ck_get_mvar_float), @@ -1934,6 +1938,46 @@ Chuck_DL_Return ck_invoke_mfun_immediate_mode( Chuck_Object * obj, t_CKUINT func +//----------------------------------------------------------------------------- +// name: ck_throw_exception() +// desc: throw an exception, if shred is passed it, it will be halted +//----------------------------------------------------------------------------- +void CK_DLL_CALL ck_throw_exception( const char * exception, const char * desc, + Chuck_VM_Shred * shred ) +{ + // constructor string + string e = exception ? string(exception) : "[unnamed]"; + if( desc ) e += ": " + string(desc); + + // display + EM_exception( e.c_str() ); + // if shred passed in + if( shred ) + { + // halt shred + shred->is_running = FALSE; + // mark as done + shred->is_done = TRUE; + } +} + + + + +//----------------------------------------------------------------------------- +// name: ck_throw_exception() +// desc: throw an exception +//----------------------------------------------------------------------------- +void CK_DLL_CALL ck_em_log( t_CKINT level, const char * text ) +{ + // check + if( !text ) return; + // display + EM_log( level, text ); +} + + + //----------------------------------------------------------------------------- // windows translation diff --git a/src/core/chuck_dl.h b/src/core/chuck_dl.h index 73bbdfd75..de0003712 100644 --- a/src/core/chuck_dl.h +++ b/src/core/chuck_dl.h @@ -397,6 +397,10 @@ typedef void (CK_DLL_CALL * f_register_shreds_watcher)( Chuck_DL_Query * query, typedef void (CK_DLL_CALL * f_unregister_shreds_watcher)( Chuck_DL_Query * query, f_shreds_watcher cb ); // call a Chuck_Object member function (defined in chuck or in c++) in IMMEDIATE MODE typedef Chuck_DL_Return (CK_DLL_CALL * f_invoke_mfun)( Chuck_Object * obj, t_CKUINT func_vt_offset, Chuck_VM * vm, Chuck_VM_Shred * shred, Chuck_DL_Arg * ARGS, t_CKUINT numArgs ); +// throw an exception +typedef void (CK_DLL_CALL * f_throw_exception)( const char * exception, const char * desc, Chuck_VM_Shred * shred ); +// log a message +typedef void (CK_DLL_CALL * f_em_log)( t_CKINT level, const char * text ); // documentation // set current class documentation @@ -842,6 +846,10 @@ struct Api // Chuck_DL_Return (CK_DLL_CALL * invoke_mfun_immediate_mode) // ( Chuck_Object * obj, t_CKUINT func_vt_offset, Chuck_VM * vm, Chuck_VM_Shred * shred, Chuck_DL_Arg * ARGS, t_CKUINT numArgs ); f_invoke_mfun invoke_mfun_immediate_mode; + // throw an exception; if shred is passed in, it will be halted + f_throw_exception throw_exception; + // log a message in the chuck logging system + f_em_log em_log; } * const vm; struct ObjectApi @@ -853,29 +861,29 @@ struct Api // intent: this allows for chugins to access member variables and create chuck strings public: // function pointer get_type() - Type (* const get_type)( CK_DL_API, Chuck_VM *, const char * name ); + Type (* const get_type)( Chuck_VM *, const char * name ); // function pointer for get_vtable_offset(); returns < 0 if not found - t_CKINT (* const get_vtable_offset)( CK_DL_API, Chuck_VM *, const char * typee, const char * value ); + t_CKINT (* const get_vtable_offset)( Chuck_VM *, const char * typee, const char * value ); // function pointer create_with_shred() - Object (* const create_with_shred)( CK_DL_API, Chuck_VM_Shred *, Type type ); + Object (* const create_with_shred)( Chuck_VM_Shred *, Type type ); // function pointer create_no_shred() - Object (* const create_no_shred)( CK_DL_API, Chuck_VM *, Type type ); + Object (* const create_without_shred)( Chuck_VM *, Type type ); // function pointer create_string() - String (* const create_string)( CK_DL_API, Chuck_VM *, const char * value ); + String (* const create_string)( Chuck_VM *, const char * value ); // function pointers for get_mvar_*() - t_CKBOOL (* const get_mvar_int)( CK_DL_API, Object object, const char * name, t_CKINT & value ); - t_CKBOOL (* const get_mvar_float)( CK_DL_API, Object object, const char * name, t_CKFLOAT & value ); - t_CKBOOL (* const get_mvar_dur)( CK_DL_API, Object object, const char * name, t_CKDUR & value ); - t_CKBOOL (* const get_mvar_time)( CK_DL_API, Object object, const char * name, t_CKTIME & value ); - t_CKBOOL (* const get_mvar_string)( CK_DL_API, Object object, const char * name, String & value ); - t_CKBOOL (* const get_mvar_object)( CK_DL_API, Object object, const char * name, Object & value ); + t_CKBOOL (* const get_mvar_int)( Object object, const char * name, t_CKINT & value ); + t_CKBOOL (* const get_mvar_float)( Object object, const char * name, t_CKFLOAT & value ); + t_CKBOOL (* const get_mvar_dur)( Object object, const char * name, t_CKDUR & value ); + t_CKBOOL (* const get_mvar_time)( Object object, const char * name, t_CKTIME & value ); + t_CKBOOL (* const get_mvar_string)( Object object, const char * name, String & value ); + t_CKBOOL (* const get_mvar_object)( Object object, const char * name, Object & value ); // function pointer for set_string() - t_CKBOOL (* const set_string)( CK_DL_API, String string, const char * value ); + t_CKBOOL (* const set_string)( String string, const char * value ); // array_int operations - t_CKBOOL (* const array_int_size)( CK_DL_API, ArrayInt array, t_CKINT & value ); - t_CKBOOL (* const array_int_push_back)( CK_DL_API, ArrayInt array, t_CKUINT value ); - t_CKBOOL (* const array_int_get_idx)( CK_DL_API, ArrayInt array, t_CKINT idx, t_CKUINT & value ); - t_CKBOOL (* const array_int_get_key)( CK_DL_API, ArrayInt array, const std::string & key, t_CKUINT & value ); + t_CKBOOL (* const array_int_size)( ArrayInt array, t_CKINT & value ); + t_CKBOOL (* const array_int_push_back)( ArrayInt array, t_CKUINT value ); + t_CKBOOL (* const array_int_get_idx)( ArrayInt array, t_CKINT idx, t_CKUINT & value ); + t_CKBOOL (* const array_int_get_key)( ArrayInt array, const std::string & key, t_CKUINT & value ); } * const object; Api() : From 4b4139043543997f3fb60e966de2c0e70ae8981b Mon Sep 17 00:00:00 2001 From: Ge Wang Date: Tue, 3 Oct 2023 19:46:50 -0700 Subject: [PATCH 10/26] DL api func for ref count --- src/core/chuck_dl.cpp | 34 ++++++++++++++++++++++++++++++++++ src/core/chuck_dl.h | 19 ++++++++++--------- 2 files changed, 44 insertions(+), 9 deletions(-) diff --git a/src/core/chuck_dl.cpp b/src/core/chuck_dl.cpp index 149f0e100..f775670c6 100644 --- a/src/core/chuck_dl.cpp +++ b/src/core/chuck_dl.cpp @@ -1519,6 +1519,37 @@ static Chuck_DL_Api::Object ck_create_without_shred( Chuck_VM * vm, Chuck_DL_Api } +//----------------------------------------------------------------------------- +// add reference count +//----------------------------------------------------------------------------- +void ck_add_ref( Chuck_DL_Api::Object object ) +{ + Chuck_Object * obj = (Chuck_Object *)object; + CK_SAFE_ADD_REF(obj); +} + + +//----------------------------------------------------------------------------- +// release reference count +//----------------------------------------------------------------------------- +void ck_release( Chuck_DL_Api::Object object ) +{ + Chuck_Object * obj = (Chuck_Object *)object; + CK_SAFE_RELEASE(obj); +} + + +//----------------------------------------------------------------------------- +// get reference count +//----------------------------------------------------------------------------- +t_CKUINT ck_refcount( Chuck_DL_Api::Object object ) +{ + Chuck_Object * obj = (Chuck_Object *)object; + if( !obj ) return 0; + return obj->refcount(); +} + + //----------------------------------------------------------------------------- // name: ck_create_string() // desc: host-side hook implementation for creating a chuck string @@ -1865,6 +1896,9 @@ get_type(ck_get_type), get_vtable_offset(ck_get_vtable_offset), create_with_shred(ck_create_with_shred), create_without_shred(ck_create_without_shred), +add_ref(ck_add_ref), +release(ck_release), +refcount(ck_refcount), create_string(ck_create_string), get_mvar_int(ck_get_mvar_int), get_mvar_float(ck_get_mvar_float), diff --git a/src/core/chuck_dl.h b/src/core/chuck_dl.h index de0003712..a058036e8 100644 --- a/src/core/chuck_dl.h +++ b/src/core/chuck_dl.h @@ -395,12 +395,6 @@ typedef Chuck_DL_MainThreadHook * (CK_DLL_CALL * f_create_main_thread_hook)( Chu typedef void (CK_DLL_CALL * f_register_shreds_watcher)( Chuck_DL_Query * query, f_shreds_watcher cb, t_CKUINT options, void * bindle ); // unregister a shreds notification callback typedef void (CK_DLL_CALL * f_unregister_shreds_watcher)( Chuck_DL_Query * query, f_shreds_watcher cb ); -// call a Chuck_Object member function (defined in chuck or in c++) in IMMEDIATE MODE -typedef Chuck_DL_Return (CK_DLL_CALL * f_invoke_mfun)( Chuck_Object * obj, t_CKUINT func_vt_offset, Chuck_VM * vm, Chuck_VM_Shred * shred, Chuck_DL_Arg * ARGS, t_CKUINT numArgs ); -// throw an exception -typedef void (CK_DLL_CALL * f_throw_exception)( const char * exception, const char * desc, Chuck_VM_Shred * shred ); -// log a message -typedef void (CK_DLL_CALL * f_em_log)( t_CKINT level, const char * text ); // documentation // set current class documentation @@ -845,11 +839,12 @@ struct Api // any time/event operations therein will throw an exception // Chuck_DL_Return (CK_DLL_CALL * invoke_mfun_immediate_mode) // ( Chuck_Object * obj, t_CKUINT func_vt_offset, Chuck_VM * vm, Chuck_VM_Shred * shred, Chuck_DL_Arg * ARGS, t_CKUINT numArgs ); - f_invoke_mfun invoke_mfun_immediate_mode; + Chuck_DL_Return (CK_DLL_CALL * const invoke_mfun_immediate_mode)( Chuck_Object * obj, t_CKUINT func_vt_offset, + Chuck_VM * vm, Chuck_VM_Shred * shred, Chuck_DL_Arg * ARGS, t_CKUINT numArgs ); // throw an exception; if shred is passed in, it will be halted - f_throw_exception throw_exception; + void (CK_DLL_CALL * const throw_exception)( const char * exception, const char * desc, Chuck_VM_Shred * shred ); // log a message in the chuck logging system - f_em_log em_log; + void (CK_DLL_CALL * const em_log)( t_CKINT level, const char * text ); } * const vm; struct ObjectApi @@ -868,6 +863,12 @@ struct Api Object (* const create_with_shred)( Chuck_VM_Shred *, Type type ); // function pointer create_no_shred() Object (* const create_without_shred)( Chuck_VM *, Type type ); + // add reference count + void (* const add_ref)( Object object ); + // release reference count + void (* const release)( Object object ); + // get reference count + t_CKUINT (* const refcount)( Object object ); // function pointer create_string() String (* const create_string)( Chuck_VM *, const char * value ); // function pointers for get_mvar_*() From 71f6e46ea2bca6ea28cfe22b94b980caee17e4ac Mon Sep 17 00:00:00 2001 From: Ge Wang Date: Tue, 3 Oct 2023 20:03:27 -0700 Subject: [PATCH 11/26] add addRef option for DL api create --- src/core/chuck_dl.cpp | 85 ++++++++++++++++++++++++------------------- src/core/chuck_dl.h | 17 ++++++--- 2 files changed, 59 insertions(+), 43 deletions(-) diff --git a/src/core/chuck_dl.cpp b/src/core/chuck_dl.cpp index f775670c6..21585602e 100644 --- a/src/core/chuck_dl.cpp +++ b/src/core/chuck_dl.cpp @@ -1464,6 +1464,37 @@ t_CKINT ck_get_vtable_offset( Chuck_VM * vm, const char * typeName, const char * } +//----------------------------------------------------------------------------- +// add reference count +//----------------------------------------------------------------------------- +void ck_add_ref( Chuck_DL_Api::Object object ) +{ + Chuck_Object * obj = (Chuck_Object *)object; + CK_SAFE_ADD_REF(obj); +} + + +//----------------------------------------------------------------------------- +// release reference count +//----------------------------------------------------------------------------- +void ck_release( Chuck_DL_Api::Object object ) +{ + Chuck_Object * obj = (Chuck_Object *)object; + CK_SAFE_RELEASE(obj); +} + + +//----------------------------------------------------------------------------- +// get reference count +//----------------------------------------------------------------------------- +t_CKUINT ck_refcount( Chuck_DL_Api::Object object ) +{ + Chuck_Object * obj = (Chuck_Object *)object; + if( !obj ) return 0; + return obj->refcount(); +} + + //----------------------------------------------------------------------------- // name: ck_create_with_shred() // desc: host-side hook implementation for instantiating and initializing @@ -1473,7 +1504,7 @@ t_CKINT ck_get_vtable_offset( Chuck_VM * vm, const char * typeName, const char * // is then invoked from c++ (e.g., using ck_invoke_mfun_immediate_mode) // and 3) that member function references global scope variables //----------------------------------------------------------------------------- -static Chuck_DL_Api::Object ck_create_with_shred( Chuck_VM_Shred * shred, Chuck_DL_Api::Type t ) +static Chuck_DL_Api::Object ck_create_with_shred( Chuck_VM_Shred * shred, Chuck_DL_Api::Type t, t_CKBOOL addRef ) { // check | 1.5.0.1 (ge) changed; used to be assert t != NULL if( t == NULL ) @@ -1488,6 +1519,8 @@ static Chuck_DL_Api::Object ck_create_with_shred( Chuck_VM_Shred * shred, Chuck_ Chuck_Type * type = (Chuck_Type *)t; // instantiate and initialize Chuck_Object * o = instantiate_and_initialize_object( type, shred, shred->vm_ref ); + // if requested to add ref + if( o && addRef ) CK_SAFE_ADD_REF(o); // done return (Chuck_DL_Api::Object)o; } @@ -1499,7 +1532,7 @@ static Chuck_DL_Api::Object ck_create_with_shred( Chuck_VM_Shred * shred, Chuck_ // a ChucK object by type, without a parent shred; see ck_create_with_shred() // for more details //----------------------------------------------------------------------------- -static Chuck_DL_Api::Object ck_create_without_shred( Chuck_VM * vm, Chuck_DL_Api::Type t ) +static Chuck_DL_Api::Object ck_create_without_shred( Chuck_VM * vm, Chuck_DL_Api::Type t, t_CKBOOL addRef ) { // check | 1.5.0.1 (ge) changed; used to be assert t != NULL if( t == NULL ) @@ -1514,54 +1547,32 @@ static Chuck_DL_Api::Object ck_create_without_shred( Chuck_VM * vm, Chuck_DL_Api Chuck_Type * type = (Chuck_Type *)t; // instantiate and initialize Chuck_Object * o = instantiate_and_initialize_object( type, vm ); + // if requested to add ref + if( o && addRef ) CK_SAFE_ADD_REF(o); // done return (Chuck_DL_Api::Object)o; } -//----------------------------------------------------------------------------- -// add reference count -//----------------------------------------------------------------------------- -void ck_add_ref( Chuck_DL_Api::Object object ) -{ - Chuck_Object * obj = (Chuck_Object *)object; - CK_SAFE_ADD_REF(obj); -} - - -//----------------------------------------------------------------------------- -// release reference count -//----------------------------------------------------------------------------- -void ck_release( Chuck_DL_Api::Object object ) -{ - Chuck_Object * obj = (Chuck_Object *)object; - CK_SAFE_RELEASE(obj); -} - - -//----------------------------------------------------------------------------- -// get reference count -//----------------------------------------------------------------------------- -t_CKUINT ck_refcount( Chuck_DL_Api::Object object ) -{ - Chuck_Object * obj = (Chuck_Object *)object; - if( !obj ) return 0; - return obj->refcount(); -} - //----------------------------------------------------------------------------- // name: ck_create_string() // desc: host-side hook implementation for creating a chuck string //----------------------------------------------------------------------------- -static Chuck_DL_Api::String ck_create_string( Chuck_VM * vm, const char * cstr ) +static Chuck_DL_Api::String ck_create_string( Chuck_VM * vm, const char * cstr, t_CKBOOL addRef ) { // instantiate and initalize object - Chuck_String * string = (Chuck_String *)instantiate_and_initialize_object( vm->env()->ckt_string, vm ); - // set the value - string->set( cstr ? cstr : "" ); + Chuck_String * ckstr = (Chuck_String *)instantiate_and_initialize_object( vm->env()->ckt_string, vm ); + // if successfully instantiated + if( ckstr ) + { + // set the value + ckstr->set( cstr ? cstr : "" ); + // if requested to add ref + if( addRef ) CK_SAFE_ADD_REF(ckstr); + } // return reference - return (Chuck_DL_Api::String)string; + return (Chuck_DL_Api::String)ckstr; } diff --git a/src/core/chuck_dl.h b/src/core/chuck_dl.h index a058036e8..805bf91be 100644 --- a/src/core/chuck_dl.h +++ b/src/core/chuck_dl.h @@ -859,18 +859,23 @@ struct Api Type (* const get_type)( Chuck_VM *, const char * name ); // function pointer for get_vtable_offset(); returns < 0 if not found t_CKINT (* const get_vtable_offset)( Chuck_VM *, const char * typee, const char * value ); - // function pointer create_with_shred() - Object (* const create_with_shred)( Chuck_VM_Shred *, Type type ); - // function pointer create_no_shred() - Object (* const create_without_shred)( Chuck_VM *, Type type ); // add reference count void (* const add_ref)( Object object ); // release reference count void (* const release)( Object object ); // get reference count t_CKUINT (* const refcount)( Object object ); - // function pointer create_string() - String (* const create_string)( Chuck_VM *, const char * value ); + // instantiating and initializing a ChucK object by type, with reference to a parent shred + // if addRef == TRUE the newly created object will have a reference count of 1; otherwise 0 + // NOTE set addRef to TRUE if you intend to keep a reference of the newly created object around (e.g., in the chugin) + // NOTE set addref to FALSE if the created object is to be returned without keeping a reference around + Object (* const create_with_shred)( Chuck_VM_Shred *, Type type, t_CKBOOL addRef ); + // instantiating and initializing a ChucK object by type, with no reference to a parent shred + // if addRef == TRUE the newly created object will have a reference count of 1; otherwise 0 + Object (* const create_without_shred)( Chuck_VM *, Type type, t_CKBOOL addRef ); + // instantiate and initialize a ChucK string by type + // if addRef == TRUE the newly created object will have a reference count of 1; otherwise 0 + String (* const create_string)( Chuck_VM *, const char * value, t_CKBOOL addRef ); // function pointers for get_mvar_*() t_CKBOOL (* const get_mvar_int)( Object object, const char * name, t_CKINT & value ); t_CKBOOL (* const get_mvar_float)( Object object, const char * name, t_CKFLOAT & value ); From 15e80dd766b801e37be87befb46318117dbad74d Mon Sep 17 00:00:00 2001 From: Ge Wang Date: Wed, 4 Oct 2023 20:38:23 -0700 Subject: [PATCH 12/26] add DL Api funcs type->isa type-is_equal --- src/core/chuck_dl.cpp | 52 +++++++++++++++++++++++++++++++++++++++++++ src/core/chuck_dl.h | 32 ++++++++++++++++++++------ src/core/chuck_vm.cpp | 4 +++- 3 files changed, 80 insertions(+), 8 deletions(-) diff --git a/src/core/chuck_dl.cpp b/src/core/chuck_dl.cpp index 21585602e..f0872c2c3 100644 --- a/src/core/chuck_dl.cpp +++ b/src/core/chuck_dl.cpp @@ -66,6 +66,10 @@ char g_chugin_path_envvar[] = "CHUCK_CHUGIN_PATH"; void CK_DLL_CALL ck_add_arg( Chuck_DL_Query * query, const char * type, const char * name ); void CK_DLL_CALL ck_throw_exception( const char * exception, const char * desc, Chuck_VM_Shred * shred ); void CK_DLL_CALL ck_em_log( t_CKINT level, const char * text ); +t_CKBOOL CK_DLL_CALL ck_type_isequal( Chuck_Type * lhs, Chuck_Type * rhs ); +t_CKBOOL CK_DLL_CALL ck_type_isa( Chuck_Type * lhs, Chuck_Type * rhs ); + + //----------------------------------------------------------------------------- @@ -1405,6 +1409,16 @@ static t_CKUINT ck_srate( Chuck_VM * vm ) } +//----------------------------------------------------------------------------- +// name: ck_now() | add 1.5.1.4 +// desc: host-side hook implementation for getting chuck system now +//----------------------------------------------------------------------------- +static t_CKTIME ck_now( Chuck_VM * vm ) +{ + return vm->now(); +} + + //----------------------------------------------------------------------------- // name: create_event_buffer() | 1.5.1.4 (ge, andrew) added // desc: host-side hoook implemenation for @@ -1889,6 +1903,7 @@ static t_CKBOOL ck_array_int_get_key( Chuck_DL_Api::ArrayInt a, const std::strin //----------------------------------------------------------------------------- Chuck_DL_Api::Api::VMApi::VMApi() : srate(ck_srate), +now(ck_now), create_event_buffer(ck_create_event_buffer), queue_event(ck_queue_event), invoke_mfun_immediate_mode(ck_invoke_mfun_immediate_mode), @@ -1927,6 +1942,17 @@ array_int_get_key(ck_array_int_get_key) +//----------------------------------------------------------------------------- +// constructor for the TypeApi; connects function pointers to host-side impl +//----------------------------------------------------------------------------- +Chuck_DL_Api::Api::TypeApi::TypeApi() : +is_equal(ck_type_isequal), +isa(ck_type_isa) +{ } + + + + //----------------------------------------------------------------------------- // name: ck_invoke_mfun_immediate_mode() // desc: directly call a chuck member function @@ -2024,6 +2050,32 @@ void CK_DLL_CALL ck_em_log( t_CKINT level, const char * text ) +//----------------------------------------------------------------------------- +// name: ck_type_isequal() +// desc: test if two types are equivalent +//----------------------------------------------------------------------------- +t_CKBOOL CK_DLL_CALL ck_type_isequal( Chuck_Type * lhs, Chuck_Type * rhs ) +{ + if( !lhs || !rhs ) return FALSE; + return *lhs == *rhs; +} + + + + +//----------------------------------------------------------------------------- +// name: ck_type_isa() +// desc: test if lhs is a type of rhs +//----------------------------------------------------------------------------- +t_CKBOOL CK_DLL_CALL ck_type_isa( Chuck_Type * lhs, Chuck_Type * rhs ) +{ + if( !lhs || !rhs ) return FALSE; + return ::isa( lhs, rhs ); +} + + + + //----------------------------------------------------------------------------- // windows translation //----------------------------------------------------------------------------- diff --git a/src/core/chuck_dl.h b/src/core/chuck_dl.h index 805bf91be..e2af52fe3 100644 --- a/src/core/chuck_dl.h +++ b/src/core/chuck_dl.h @@ -813,10 +813,10 @@ Chuck_DL_Return ck_invoke_mfun_immediate_mode( Chuck_Object * obj, t_CKUINT func //----------------------------------------------------------------------------- namespace Chuck_DL_Api { -typedef void * Object; -typedef void * Type; -typedef void * String; -typedef void * ArrayInt; // 1.5.0.1 (ge) added +typedef Chuck_Object * Object; +typedef Chuck_Type * Type; +typedef Chuck_String * String; +typedef Chuck_ArrayInt * ArrayInt; // 1.5.0.1 (ge) added struct Api { @@ -824,11 +824,14 @@ struct Api static Api g_api; static inline const Api * instance() { return &g_api; } + // api to access host-side ChucK virtual machine struct VMApi { VMApi(); // get sample rate | 1.5.1.4 t_CKUINT (* const srate)( Chuck_VM * vm ); + // get chuck now | 1.5.1.4 + t_CKTIME (* const now)( Chuck_VM * vm ); // create a new lock-free one-producer, one-consumer buffer | 1.5.1.4 CBufferSimple * (* const create_event_buffer)( Chuck_VM * vm ); // queue an event; num_msg must be 1; buffer should be created using create_event_buffer() above | 1.5.1.4 @@ -847,6 +850,7 @@ struct Api void (CK_DLL_CALL * const em_log)( t_CKINT level, const char * text ); } * const vm; + // api to access host-side ChucK objects struct ObjectApi { ObjectApi(); @@ -892,17 +896,31 @@ struct Api t_CKBOOL (* const array_int_get_key)( ArrayInt array, const std::string & key, t_CKUINT & value ); } * const object; + // access to host-side chuck types + struct TypeApi + { + TypeApi(); + // test if two chuck types are equal + t_CKBOOL (* const is_equal)(Type lhs, Type rhs); + // test if lhs is a type of rhs (e.g., SinOsc is a type of UGen) + t_CKBOOL (* const isa)(Type lhs, Type rhs); + } * const type; + + // constructor Api() : vm(new VMApi), - object(new ObjectApi) + object(new ObjectApi), + type(new TypeApi) { } private: + // make this object un-copy-able Api( Api & a ) : vm(a.vm), - object(a.object) + object(a.object), + type(a.type) { assert(0); }; - + // make this object un-copy-able, part 2 Api & operator=( Api & a ) { assert(0); return a; } }; } diff --git a/src/core/chuck_vm.cpp b/src/core/chuck_vm.cpp index 5e2bbf24f..c8c0de24a 100644 --- a/src/core/chuck_vm.cpp +++ b/src/core/chuck_vm.cpp @@ -3496,8 +3496,10 @@ Chuck_DL_Return Chuck_VM_MFunInvoker::invoke( Chuck_Object * obj, const vectoris_abort = FALSE; // set the instr shred->instr = shred->code->instr; - // zero out the id + // zero out the id (shred is in immediate mode and cannot be shreduled) shred->xid = 0; + // inherit now from vm + shred->now = shred->vm_ref->now(); // run shred on VM shred->run( shred->vm_ref ); From 835a83c85b93eb317f3a29ba6fca08362086ec0d Mon Sep 17 00:00:00 2001 From: Ge Wang Date: Wed, 4 Oct 2023 21:31:33 -0700 Subject: [PATCH 13/26] update obj->get_type and type->lookup --- src/core/chuck_dl.cpp | 37 +++++++++++++++++++++++++++++++------ src/core/chuck_dl.h | 4 +++- 2 files changed, 34 insertions(+), 7 deletions(-) diff --git a/src/core/chuck_dl.cpp b/src/core/chuck_dl.cpp index f0872c2c3..4624dd7cc 100644 --- a/src/core/chuck_dl.cpp +++ b/src/core/chuck_dl.cpp @@ -66,6 +66,7 @@ char g_chugin_path_envvar[] = "CHUCK_CHUGIN_PATH"; void CK_DLL_CALL ck_add_arg( Chuck_DL_Query * query, const char * type, const char * name ); void CK_DLL_CALL ck_throw_exception( const char * exception, const char * desc, Chuck_VM_Shred * shred ); void CK_DLL_CALL ck_em_log( t_CKINT level, const char * text ); +Chuck_DL_Api::Type CK_DLL_CALL ck_type_lookup( Chuck_VM * vm, const char * name ); t_CKBOOL CK_DLL_CALL ck_type_isequal( Chuck_Type * lhs, Chuck_Type * rhs ); t_CKBOOL CK_DLL_CALL ck_type_isa( Chuck_Type * lhs, Chuck_Type * rhs ); @@ -1445,13 +1446,9 @@ static t_CKBOOL ck_queue_event( Chuck_VM * vm, Chuck_Event * event, t_CKINT num_ // name: ck_get_type() // desc: host-side hook implementation for retrieving a type by name //----------------------------------------------------------------------------- -static Chuck_DL_Api::Type ck_get_type( Chuck_VM * vm, const char * name ) +static Chuck_DL_Api::Type ck_get_type( Chuck_Object * object ) { - Chuck_Env * env = vm->env(); - a_Id_List list = new_id_list( name, 0, 0 /*, NULL*/ ); // TODO: nested types - Chuck_Type * t = type_engine_find_type( env, list ); - delete_id_list( list ); - return (Chuck_DL_Api::Type)t; + return object->type_ref; } @@ -1733,6 +1730,7 @@ static t_CKBOOL ck_get_mvar_dur( Chuck_DL_Api::Object obj, const char * name, t_ } + //----------------------------------------------------------------------------- // name: ck_get_mvar_time() // desc: retrieve a class's member variable of type time @@ -1760,6 +1758,8 @@ static t_CKBOOL ck_get_mvar_time( Chuck_DL_Api::Object obj, const char * name, t } + + //----------------------------------------------------------------------------- // name: ck_get_mvar_string() // desc: retrieve a class's member variable of type string @@ -1813,6 +1813,7 @@ static t_CKBOOL ck_get_mvar_object( Chuck_DL_Api::Object obj, const char * name, } + //----------------------------------------------------------------------------- // name: ck_set_string() // desc: set a chuck string @@ -1830,6 +1831,7 @@ static t_CKBOOL ck_set_string( Chuck_DL_Api::String s, const char * str ) } + //----------------------------------------------------------------------------- // name: ck_array_int_size() // desc: get size of an array | 1.5.1.3 (nshaheed) added @@ -1849,6 +1851,8 @@ static t_CKBOOL ck_array_int_size( Chuck_DL_Api::ArrayInt a, t_CKINT & value ) } + + //----------------------------------------------------------------------------- // name: ck_array_int_push_back() // desc: push back an element into an array | 1.5.0.1 (ge) added @@ -1866,6 +1870,8 @@ static t_CKBOOL ck_array_int_push_back( Chuck_DL_Api::ArrayInt a, t_CKUINT value } + + //----------------------------------------------------------------------------- // name: ck_array_int_get_idx() // desc: get an indexed element from an array | 1.5.1.3 (nshaheed) added @@ -1881,6 +1887,8 @@ static t_CKBOOL ck_array_int_get_idx( Chuck_DL_Api::ArrayInt a, t_CKINT idx, t_C } + + //----------------------------------------------------------------------------- // name: ck_array_int_get() // desc: get a keyed element from an array | 1.5.1.3 (nshaheed) added @@ -1946,6 +1954,7 @@ array_int_get_key(ck_array_int_get_key) // constructor for the TypeApi; connects function pointers to host-side impl //----------------------------------------------------------------------------- Chuck_DL_Api::Api::TypeApi::TypeApi() : +lookup(ck_type_lookup), is_equal(ck_type_isequal), isa(ck_type_isa) { } @@ -2050,6 +2059,22 @@ void CK_DLL_CALL ck_em_log( t_CKINT level, const char * text ) +//----------------------------------------------------------------------------- +// name: ck_type_lookup() +// desc: host-side hook implementation for retrieving a type by name +//----------------------------------------------------------------------------- +Chuck_DL_Api::Type ck_type_lookup( Chuck_VM * vm, const char * name ) +{ + Chuck_Env * env = vm->env(); + a_Id_List list = new_id_list( name, 0, 0 /*, NULL*/ ); // TODO: nested types + Chuck_Type * t = type_engine_find_type( env, list ); + delete_id_list( list ); + return (Chuck_DL_Api::Type)t; +} + + + + //----------------------------------------------------------------------------- // name: ck_type_isequal() // desc: test if two types are equivalent diff --git a/src/core/chuck_dl.h b/src/core/chuck_dl.h index e2af52fe3..3d7f4bbff 100644 --- a/src/core/chuck_dl.h +++ b/src/core/chuck_dl.h @@ -860,7 +860,7 @@ struct Api // intent: this allows for chugins to access member variables and create chuck strings public: // function pointer get_type() - Type (* const get_type)( Chuck_VM *, const char * name ); + Type (* const get_type)( Object object ); // function pointer for get_vtable_offset(); returns < 0 if not found t_CKINT (* const get_vtable_offset)( Chuck_VM *, const char * typee, const char * value ); // add reference count @@ -900,6 +900,8 @@ struct Api struct TypeApi { TypeApi(); + // function pointer get_type() + Type (* const lookup)( Chuck_VM *, const char * name ); // test if two chuck types are equal t_CKBOOL (* const is_equal)(Type lhs, Type rhs); // test if lhs is a type of rhs (e.g., SinOsc is a type of UGen) From 11a08e901eeb2e018eab035d687cfdfa6828bd59 Mon Sep 17 00:00:00 2001 From: Ge Wang Date: Thu, 5 Oct 2023 11:26:20 -0700 Subject: [PATCH 14/26] add mfun-inoke and cast-to-child unit tests --- src/test/01-Basic/210-mfun-invoke.ck | 20 +++++++++++++++++++ src/test/01-Basic/211-cast-to-child.ck | 11 ++++++++++ src/test/06-Errors/error-cast-to-nonchild.ck | 11 ++++++++++ src/test/06-Errors/error-cast-to-nonchild.txt | 3 +++ 4 files changed, 45 insertions(+) create mode 100644 src/test/01-Basic/210-mfun-invoke.ck create mode 100644 src/test/01-Basic/211-cast-to-child.ck create mode 100644 src/test/06-Errors/error-cast-to-nonchild.ck create mode 100644 src/test/06-Errors/error-cast-to-nonchild.txt diff --git a/src/test/01-Basic/210-mfun-invoke.ck b/src/test/01-Basic/210-mfun-invoke.ck new file mode 100644 index 000000000..d4a56f138 --- /dev/null +++ b/src/test/01-Basic/210-mfun-invoke.ck @@ -0,0 +1,20 @@ +// test calling chuck-side member functions from c++ + +// instance of our event +TheEvent e; + +// custom Event class +class TheEvent extends Event +{ + // override the waiting_on() function, which is called by the VM + // when a shred has begun to wait on an Event + fun void waiting_on() + { + <<< "success" >>>; + e.broadcast(); + } +} + +// this shred will wait on event +e => now; + diff --git a/src/test/01-Basic/211-cast-to-child.ck b/src/test/01-Basic/211-cast-to-child.ck new file mode 100644 index 000000000..25ed0792e --- /dev/null +++ b/src/test/01-Basic/211-cast-to-child.ck @@ -0,0 +1,11 @@ +// a subclass of Event +class Foo extends Event { } + +// an Event +Event e; + +// cast to subclass +e $ Foo @=> Foo @ f; + +// if we got here then ok +<<< "success" >>>; diff --git a/src/test/06-Errors/error-cast-to-nonchild.ck b/src/test/06-Errors/error-cast-to-nonchild.ck new file mode 100644 index 000000000..56bf0e4a4 --- /dev/null +++ b/src/test/06-Errors/error-cast-to-nonchild.ck @@ -0,0 +1,11 @@ +// error case: verify error when casting to a non-subclass +// related:: 01-Basic/211-cast-to-child.ck + +// a class (not subclass of Event) +class Foo { } + +// an Event +Event e; + +// cast to not subclass +e $ Foo @=> Foo @ f; diff --git a/src/test/06-Errors/error-cast-to-nonchild.txt b/src/test/06-Errors/error-cast-to-nonchild.txt new file mode 100644 index 000000000..7a5f0611e --- /dev/null +++ b/src/test/06-Errors/error-cast-to-nonchild.txt @@ -0,0 +1,3 @@ +error-cast-to-nonchild.ck:11:3: error: invalid cast from 'Event' to 'Foo' +[11] e $ Foo @=> Foo @ f; + ^ From 32bcff1a5b9bf5eab121499306764c725a89e579 Mon Sep 17 00:00:00 2001 From: Ge Wang Date: Thu, 5 Oct 2023 11:40:28 -0700 Subject: [PATCH 15/26] add static access member unit test --- src/test/06-Errors/error-static-access-member.ck | 14 ++++++++++++++ src/test/06-Errors/error-static-access-member.txt | 4 ++++ 2 files changed, 18 insertions(+) create mode 100644 src/test/06-Errors/error-static-access-member.ck create mode 100644 src/test/06-Errors/error-static-access-member.txt diff --git a/src/test/06-Errors/error-static-access-member.ck b/src/test/06-Errors/error-static-access-member.ck new file mode 100644 index 000000000..1a8cbaba1 --- /dev/null +++ b/src/test/06-Errors/error-static-access-member.ck @@ -0,0 +1,14 @@ +class Foo +{ + 5 => int x; +} + +class Bar +{ + Foo foo; + fun static Foo getFoo() { return foo; } +} + +Bar bar; + +bar.getFoo(); diff --git a/src/test/06-Errors/error-static-access-member.txt b/src/test/06-Errors/error-static-access-member.txt new file mode 100644 index 000000000..9e2179d98 --- /dev/null +++ b/src/test/06-Errors/error-static-access-member.txt @@ -0,0 +1,4 @@ +error-static-access-member.ck:9:38: error: non-static member 'foo' used from static function +[9] fun static Foo getFoo() { return foo; } + ^ +error-static-access-member.ck: ...in function 'Foo Bar.getFoo()' From 5638514a19baa0c60dc5ef685977fee95c4f2adf Mon Sep 17 00:00:00 2001 From: Ge Wang Date: Thu, 5 Oct 2023 21:59:48 -0700 Subject: [PATCH 16/26] update DL API create, get_vtable_offset --- src/core/chuck_dl.cpp | 16 ++++------- src/core/chuck_dl.h | 62 +++++++++++++++++++++---------------------- 2 files changed, 35 insertions(+), 43 deletions(-) diff --git a/src/core/chuck_dl.cpp b/src/core/chuck_dl.cpp index 4624dd7cc..f38bba89f 100644 --- a/src/core/chuck_dl.cpp +++ b/src/core/chuck_dl.cpp @@ -1456,16 +1456,8 @@ static Chuck_DL_Api::Type ck_get_type( Chuck_Object * object ) // name: ck_get_vtable_offset() // desc: function pointer get_type() //----------------------------------------------------------------------------- -t_CKINT ck_get_vtable_offset( Chuck_VM * vm, const char * typeName, const char * valueName ) +t_CKINT ck_get_vtable_offset( Chuck_VM * vm, Chuck_Type * t, const char * valueName ) { - // get the type - Chuck_Env * env = vm->env(); - a_Id_List list = new_id_list( typeName, 0, 0 /*, NULL*/ ); // TODO: nested types - Chuck_Type * t = type_engine_find_type( env, list ); - delete_id_list( list ); - // type not found - if( !t ) return -1; - // find the offset for value by name Chuck_Value * value = type_engine_find_value( t, valueName ); // value not found @@ -1927,8 +1919,7 @@ em_log(ck_em_log) //----------------------------------------------------------------------------- Chuck_DL_Api::Api::ObjectApi::ObjectApi() : get_type(ck_get_type), -get_vtable_offset(ck_get_vtable_offset), -create_with_shred(ck_create_with_shred), +create(ck_create_with_shred), create_without_shred(ck_create_without_shred), add_ref(ck_add_ref), release(ck_release), @@ -1955,6 +1946,7 @@ array_int_get_key(ck_array_int_get_key) //----------------------------------------------------------------------------- Chuck_DL_Api::Api::TypeApi::TypeApi() : lookup(ck_type_lookup), +get_vtable_offset(ck_get_vtable_offset), is_equal(ck_type_isequal), isa(ck_type_isa) { } @@ -2065,10 +2057,12 @@ void CK_DLL_CALL ck_em_log( t_CKINT level, const char * text ) //----------------------------------------------------------------------------- Chuck_DL_Api::Type ck_type_lookup( Chuck_VM * vm, const char * name ) { + // get the type Chuck_Env * env = vm->env(); a_Id_List list = new_id_list( name, 0, 0 /*, NULL*/ ); // TODO: nested types Chuck_Type * t = type_engine_find_type( env, list ); delete_id_list( list ); + // return return (Chuck_DL_Api::Type)t; } diff --git a/src/core/chuck_dl.h b/src/core/chuck_dl.h index 3d7f4bbff..b2e9c844e 100644 --- a/src/core/chuck_dl.h +++ b/src/core/chuck_dl.h @@ -780,8 +780,8 @@ struct Chuck_DL_MainThreadHook public: Chuck_DL_MainThreadHook(f_mainthreadhook hook, f_mainthreadquit quit, void * bindle, Chuck_Carrier * carrier); - t_CKBOOL (* const activate)(Chuck_DL_MainThreadHook *); - t_CKBOOL (* const deactivate)(Chuck_DL_MainThreadHook *); + t_CKBOOL (CK_DLL_CALL * const activate)(Chuck_DL_MainThreadHook *); + t_CKBOOL (CK_DLL_CALL * const deactivate)(Chuck_DL_MainThreadHook *); Chuck_Carrier * const m_carrier; f_mainthreadhook const m_hook; @@ -829,19 +829,17 @@ struct Api { VMApi(); // get sample rate | 1.5.1.4 - t_CKUINT (* const srate)( Chuck_VM * vm ); + t_CKUINT (CK_DLL_CALL * const srate)( Chuck_VM * vm ); // get chuck now | 1.5.1.4 - t_CKTIME (* const now)( Chuck_VM * vm ); + t_CKTIME (CK_DLL_CALL * const now)( Chuck_VM * vm ); // create a new lock-free one-producer, one-consumer buffer | 1.5.1.4 - CBufferSimple * (* const create_event_buffer)( Chuck_VM * vm ); + CBufferSimple * (CK_DLL_CALL * const create_event_buffer)( Chuck_VM * vm ); // queue an event; num_msg must be 1; buffer should be created using create_event_buffer() above | 1.5.1.4 - t_CKBOOL (* const queue_event)( Chuck_VM * vm, Chuck_Event * event, t_CKINT num_msg, CBufferSimple * buffer ); + t_CKBOOL (CK_DLL_CALL * const queue_event)( Chuck_VM * vm, Chuck_Event * event, t_CKINT num_msg, CBufferSimple * buffer ); // invoke Chuck_Object member function (defined either in chuck or c++) | 1.5.1.4 (ge & andrew) // NOTE this will call the member function in IMMEDIATE MODE, // marking it as a time-critical function when called in this manner; // any time/event operations therein will throw an exception - // Chuck_DL_Return (CK_DLL_CALL * invoke_mfun_immediate_mode) - // ( Chuck_Object * obj, t_CKUINT func_vt_offset, Chuck_VM * vm, Chuck_VM_Shred * shred, Chuck_DL_Arg * ARGS, t_CKUINT numArgs ); Chuck_DL_Return (CK_DLL_CALL * const invoke_mfun_immediate_mode)( Chuck_Object * obj, t_CKUINT func_vt_offset, Chuck_VM * vm, Chuck_VM_Shred * shred, Chuck_DL_Arg * ARGS, t_CKUINT numArgs ); // throw an exception; if shred is passed in, it will be halted @@ -860,40 +858,38 @@ struct Api // intent: this allows for chugins to access member variables and create chuck strings public: // function pointer get_type() - Type (* const get_type)( Object object ); - // function pointer for get_vtable_offset(); returns < 0 if not found - t_CKINT (* const get_vtable_offset)( Chuck_VM *, const char * typee, const char * value ); + Type (CK_DLL_CALL * const get_type)( Object object ); // add reference count - void (* const add_ref)( Object object ); + void (CK_DLL_CALL * const add_ref)( Object object ); // release reference count - void (* const release)( Object object ); + void (CK_DLL_CALL * const release)( Object object ); // get reference count - t_CKUINT (* const refcount)( Object object ); + t_CKUINT (CK_DLL_CALL * const refcount)( Object object ); // instantiating and initializing a ChucK object by type, with reference to a parent shred // if addRef == TRUE the newly created object will have a reference count of 1; otherwise 0 // NOTE set addRef to TRUE if you intend to keep a reference of the newly created object around (e.g., in the chugin) - // NOTE set addref to FALSE if the created object is to be returned without keeping a reference around - Object (* const create_with_shred)( Chuck_VM_Shred *, Type type, t_CKBOOL addRef ); + // NOTE set addRef to FALSE if the created object is to be returned without keeping a reference around + Object (CK_DLL_CALL * const create)( Chuck_VM_Shred *, Type type, t_CKBOOL addRef ); // instantiating and initializing a ChucK object by type, with no reference to a parent shred // if addRef == TRUE the newly created object will have a reference count of 1; otherwise 0 - Object (* const create_without_shred)( Chuck_VM *, Type type, t_CKBOOL addRef ); + Object (CK_DLL_CALL * const create_without_shred)( Chuck_VM *, Type type, t_CKBOOL addRef ); // instantiate and initialize a ChucK string by type // if addRef == TRUE the newly created object will have a reference count of 1; otherwise 0 - String (* const create_string)( Chuck_VM *, const char * value, t_CKBOOL addRef ); + String (CK_DLL_CALL * const create_string)( Chuck_VM *, const char * value, t_CKBOOL addRef ); // function pointers for get_mvar_*() - t_CKBOOL (* const get_mvar_int)( Object object, const char * name, t_CKINT & value ); - t_CKBOOL (* const get_mvar_float)( Object object, const char * name, t_CKFLOAT & value ); - t_CKBOOL (* const get_mvar_dur)( Object object, const char * name, t_CKDUR & value ); - t_CKBOOL (* const get_mvar_time)( Object object, const char * name, t_CKTIME & value ); - t_CKBOOL (* const get_mvar_string)( Object object, const char * name, String & value ); - t_CKBOOL (* const get_mvar_object)( Object object, const char * name, Object & value ); + t_CKBOOL (CK_DLL_CALL * const get_mvar_int)( Object object, const char * name, t_CKINT & value ); + t_CKBOOL (CK_DLL_CALL * const get_mvar_float)( Object object, const char * name, t_CKFLOAT & value ); + t_CKBOOL (CK_DLL_CALL * const get_mvar_dur)( Object object, const char * name, t_CKDUR & value ); + t_CKBOOL (CK_DLL_CALL * const get_mvar_time)( Object object, const char * name, t_CKTIME & value ); + t_CKBOOL (CK_DLL_CALL * const get_mvar_string)( Object object, const char * name, String & value ); + t_CKBOOL (CK_DLL_CALL * const get_mvar_object)( Object object, const char * name, Object & value ); // function pointer for set_string() - t_CKBOOL (* const set_string)( String string, const char * value ); + t_CKBOOL (CK_DLL_CALL * const set_string)( String string, const char * value ); // array_int operations - t_CKBOOL (* const array_int_size)( ArrayInt array, t_CKINT & value ); - t_CKBOOL (* const array_int_push_back)( ArrayInt array, t_CKUINT value ); - t_CKBOOL (* const array_int_get_idx)( ArrayInt array, t_CKINT idx, t_CKUINT & value ); - t_CKBOOL (* const array_int_get_key)( ArrayInt array, const std::string & key, t_CKUINT & value ); + t_CKBOOL (CK_DLL_CALL * const array_int_size)( ArrayInt array, t_CKINT & value ); + t_CKBOOL (CK_DLL_CALL * const array_int_push_back)( ArrayInt array, t_CKUINT value ); + t_CKBOOL (CK_DLL_CALL * const array_int_get_idx)( ArrayInt array, t_CKINT idx, t_CKUINT & value ); + t_CKBOOL (CK_DLL_CALL * const array_int_get_key)( ArrayInt array, const std::string & key, t_CKUINT & value ); } * const object; // access to host-side chuck types @@ -901,11 +897,13 @@ struct Api { TypeApi(); // function pointer get_type() - Type (* const lookup)( Chuck_VM *, const char * name ); + Type (CK_DLL_CALL * const lookup)( Chuck_VM *, const char * name ); + // function pointer for get_vtable_offset(); returns < 0 if not found + t_CKINT (CK_DLL_CALL * const get_vtable_offset)( Chuck_VM *, Type type, const char * value ); // test if two chuck types are equal - t_CKBOOL (* const is_equal)(Type lhs, Type rhs); + t_CKBOOL (CK_DLL_CALL * const is_equal)(Type lhs, Type rhs); // test if lhs is a type of rhs (e.g., SinOsc is a type of UGen) - t_CKBOOL (* const isa)(Type lhs, Type rhs); + t_CKBOOL (CK_DLL_CALL * const isa)(Type lhs, Type rhs); } * const type; // constructor From 8985455177a23468658014058c97e32c28968802 Mon Sep 17 00:00:00 2001 From: Ge Wang Date: Fri, 6 Oct 2023 00:07:44 -0700 Subject: [PATCH 17/26] update release notes --- VERSIONS | 48 ++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 38 insertions(+), 10 deletions(-) diff --git a/VERSIONS b/VERSIONS index 0906319b6..d81fc7df0 100644 --- a/VERSIONS +++ b/VERSIONS @@ -2,24 +2,25 @@ ChucK VERSIONS log ------------------ -1.5.1.4 (October 2023) +1.5.1.5 (October 2023) "operator overloading" ======= -- (added) operator overloading; - most operator can be overloaded, within their respective existing +- (added) operator overloading in language; + most operator can now be overloaded, within their respective existing forms in the language (e.g., binary operators such as '+' and '=>' can be overloaded as binary operators, but not as unary operators); - also please note, like public class definitions, operator overloads - are local in scope unless declared with 'public' instead of 'fun', - global operator overloading will persists until 1) the VM stops or - 2) the VM is cleared/reset + also please note, similar to class definitions, operator overloads + are local in scope unless declared with 'public', the latter operator + overloading will persists until 1) the VM stops or 2) the VM is + cleared/reset //----------------------------------------------------------- // the general format for overload an operator is as follows: //----------------------------------------------------------- // let's say we define a custom class... public class Foo { int num; } - // persistent operator overloading (trascends contexts) - // NOTE the use of 'public' instead of 'fun' -- it's fun for all! + // PUBLIC operator overloading (trascends contexts and files; + // will persist until stop VM or clear VM. NOTE the use of 'public' + // instead of 'fun' (fun for all!) public Foo @operator =^( Foo lhs, Foo rhs ) { /* do stuff for Foo =^ Foo */ return rhs; } @@ -55,6 +56,11 @@ ChucK VERSIONS log // should print 7 <<< c.num >>>; //----------------------------------------------------------- +- (added) new examples showing basic operator overloading usage + examples/oper/overload_overview.ck + examples/oper/overload_pre_post.ck + examples/oper/overload_public.ck + examples/oper/overload_gru.ck - (added) the "gruck operator" --> (graphical chuck operator) as part of ChuGL (ChucK Graphics Library), which will be part of the ChucK language @@ -116,7 +122,29 @@ ChucK VERSIONS log up file descriptors and leading to instability - (updated) ConsoleInput.prompt( text ) now no longer prints an extra space (" ") after prompt text -- (added; chugins development) new dyanmic linking API for VM operations +- (added; chugins development) ability to overload operators from chugin + query functions in C++: + // add binary operator overload; args included + f_add_op_overload_binary add_op_overload_binary; + // add unary (prefix) operator overload; arg included + f_add_op_overload_prefix add_op_overload_prefix; + // add unary (postfix) operator overload; arg included + f_add_op_overload_postfix add_op_overload_postfix; +- (added; chugins development) capability to invoke chuck language-side + member functions (in chuck) from chugins (in C++) + // invoke Object member function (defined either in chuck or c++) + // NOTE this will call the member function in IMMEDIATE MODE, + // marking it as a time-critical function when called in this + // manner; any time/event operations therein will throw an exception + Chuck_DL_Return API->vm->invoke_mfun_immediate_mode( + Chuck_Object * obj, t_CKUINT func_vt_offset, Chuck_VM * vm, + Chuck_VM_Shred * shred, Chuck_DL_Arg * ARGS, t_CKUINT numArgs ); +- (added; chugins development) overhauled dyanmic linking API to access + chuck host-side operations; this greatly expands chugins capabilities + but will unfortunately require API changes that will break chugin + builds that uses the existing API. + (check out chuck_dl.h: `namespace Chuck_DL_Api`) +- (updated) chugins headers version incremented to 9.0 1.5.1.3 (September 2023) "ChucK to School" From 16c0b83116aad08164ddd065f5c41bb38d2b9148 Mon Sep 17 00:00:00 2001 From: Ge Wang Date: Fri, 6 Oct 2023 00:35:49 -0700 Subject: [PATCH 18/26] rename remaining array4 array8 macro names --- src/core/chuck_lang.cpp | 14 +++++++------- src/core/chuck_oo.h | 21 ++++++++++++--------- 2 files changed, 19 insertions(+), 16 deletions(-) diff --git a/src/core/chuck_lang.cpp b/src/core/chuck_lang.cpp index 6e00b06c4..b7d6635ba 100644 --- a/src/core/chuck_lang.cpp +++ b/src/core/chuck_lang.cpp @@ -135,7 +135,7 @@ t_CKBOOL init_class_ugen( Chuck_Env * env, Chuck_Type * type ) type->ugen_info->tick = __ugen_tick; type->ugen_info->num_ins = 1; type->ugen_info->num_outs = 1; - + // documentation text const char * doc = "base class for all unit generator (UGen) types."; // init as base class @@ -3002,9 +3002,9 @@ CK_DLL_MFUN( array_push_back ) { Chuck_Array * array = (Chuck_Array *)SELF; // ISSUE: 64-bit (fixed 1.3.1.0 using data kind) - if( array->data_type_kind() == CHUCK_ARRAY4_DATAKIND ) + if( array->data_type_kind() == CHUCK_ARRAYINT_DATAKIND ) RETURN->v_int = ((Chuck_ArrayInt *)array)->push_back( GET_NEXT_UINT( ARGS ) ); - else if( array->data_type_kind() == CHUCK_ARRAY8_DATAKIND ) + 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 ) ); @@ -3024,9 +3024,9 @@ CK_DLL_MFUN( array_insert ) t_CKINT position = GET_NEXT_INT( ARGS ); // ISSUE: 64-bit (fixed 1.3.1.0 using data kind) - if( array->data_type_kind() == CHUCK_ARRAY4_DATAKIND ) + if( array->data_type_kind() == CHUCK_ARRAYINT_DATAKIND ) RETURN->v_int = ((Chuck_ArrayInt *)array)->insert( position, GET_NEXT_UINT( ARGS ) ); - else if( array->data_type_kind() == CHUCK_ARRAY8_DATAKIND ) + 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 ) ); @@ -3051,9 +3051,9 @@ CK_DLL_MFUN( array_push_front ) { Chuck_Array * array = (Chuck_Array *)SELF; // ISSUE: 64-bit (fixed 1.3.1.0 using data kind) - if( array->data_type_kind() == CHUCK_ARRAY4_DATAKIND ) + if( array->data_type_kind() == CHUCK_ARRAYINT_DATAKIND ) RETURN->v_int = ((Chuck_ArrayInt *)array)->push_front( GET_NEXT_UINT( ARGS ) ); - else if( array->data_type_kind() == CHUCK_ARRAY8_DATAKIND ) + 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 ) ); diff --git a/src/core/chuck_oo.h b/src/core/chuck_oo.h index e7a8e1f02..ea5aed906 100644 --- a/src/core/chuck_oo.h +++ b/src/core/chuck_oo.h @@ -173,13 +173,13 @@ struct Chuck_Object : public Chuck_VM_Object // ISSUE: 64-bit (fixed 1.3.1.0) -#define CHUCK_ARRAY4_DATASIZE sz_INT -#define CHUCK_ARRAY8_DATASIZE sz_FLOAT +#define CHUCK_ARRAYINT_DATASIZE sz_INT +#define CHUCK_ARRAYFLOAT_DATASIZE sz_FLOAT #define CHUCK_ARRAY16_DATASIZE sz_COMPLEX #define CHUCK_ARRAY24_DATASIZE sz_VEC3 // 1.3.5.3 #define CHUCK_ARRAY32_DATASIZE sz_VEC4 // 1.3.5.3 -#define CHUCK_ARRAY4_DATAKIND kindof_INT -#define CHUCK_ARRAY8_DATAKIND kindof_FLOAT +#define CHUCK_ARRAYINT_DATAKIND kindof_INT +#define CHUCK_ARRAYFLOAT_DATAKIND kindof_FLOAT #define CHUCK_ARRAY16_DATAKIND kindof_COMPLEX #define CHUCK_ARRAY24_DATAKIND kindof_VEC3 // 1.3.5.3 #define CHUCK_ARRAY32_DATAKIND kindof_VEC4 // 1.3.5.3 @@ -257,7 +257,9 @@ struct Chuck_Array : public Chuck_Object //----------------------------------------------------------------------------- // name: struct Chuck_ArrayInt -// desc: native ChucK arrays (for 4-byte/8-byte int, and Object references) +// desc: native ChucK arrays +// (for 4-byte/8-byte int, depending on 32-bit vs 64-bit & Object refs) +// 1.5.1.4 (ge) renamed from Chuck_Array4 to Chuck_ArrayInt //----------------------------------------------------------------------------- struct Chuck_ArrayInt : public Chuck_Array { @@ -299,9 +301,9 @@ struct Chuck_ArrayInt : public Chuck_Array // set array capacity virtual t_CKINT set_capacity( t_CKINT capacity ); // size of stored type (from type_ref) - virtual t_CKINT data_type_size() { return CHUCK_ARRAY4_DATASIZE; } + virtual t_CKINT data_type_size() { return CHUCK_ARRAYINT_DATASIZE; } // kind of stored type (from kindof) - virtual t_CKINT data_type_kind() { return CHUCK_ARRAY4_DATAKIND; } + virtual t_CKINT data_type_kind() { return CHUCK_ARRAYINT_DATAKIND; } // clear virtual void clear(); // zero out the array by range [start,end) @@ -353,6 +355,7 @@ struct Chuck_ArrayInt : public Chuck_Array //----------------------------------------------------------------------------- // name: struct Chuck_ArrayFloat // desc: native ChucK arrays (for 8-byte float) +// 1.5.1.4 (ge) renamed from Chuck_Array8 to Chuck_ArrayFloat //----------------------------------------------------------------------------- struct Chuck_ArrayFloat : public Chuck_Array { @@ -394,9 +397,9 @@ struct Chuck_ArrayFloat : public Chuck_Array // set array capacity virtual t_CKINT set_capacity( t_CKINT capacity ); // size of stored type (from type_ref) - virtual t_CKINT data_type_size() { return CHUCK_ARRAY8_DATASIZE; } + virtual t_CKINT data_type_size() { return CHUCK_ARRAYFLOAT_DATASIZE; } // kind of stored type (from kindof) - virtual t_CKINT data_type_kind() { return CHUCK_ARRAY8_DATAKIND; } + virtual t_CKINT data_type_kind() { return CHUCK_ARRAYFLOAT_DATAKIND; } // clear virtual void clear(); // zero out the array by range [start,end) From baead5fa171ae1b6ffc30e01d0c97ec11ceea960 Mon Sep 17 00:00:00 2001 From: Ge Wang Date: Fri, 6 Oct 2023 01:09:24 -0700 Subject: [PATCH 19/26] renumber unit test 215 to 212 --- .../{215-use-before-extend.ck => 212-use-before-extend.ck} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename src/test/01-Basic/{215-use-before-extend.ck => 212-use-before-extend.ck} (100%) diff --git a/src/test/01-Basic/215-use-before-extend.ck b/src/test/01-Basic/212-use-before-extend.ck similarity index 100% rename from src/test/01-Basic/215-use-before-extend.ck rename to src/test/01-Basic/212-use-before-extend.ck From 8bd473daf75fe5bde1d5f4873bda20bdd3cbd01a Mon Sep 17 00:00:00 2001 From: Ge Wang Date: Fri, 6 Oct 2023 13:31:06 -0700 Subject: [PATCH 20/26] incrementing to version 1.5.1.5 --- src/core/chuck.cpp | 4 +-- src/core/chuck.h | 2 +- src/core/chuck.lex | 2 +- src/core/chuck.y | 2 +- src/core/chuck_absyn.cpp | 6 ++-- src/core/chuck_absyn.h | 4 +-- src/core/chuck_compile.cpp | 10 +++--- src/core/chuck_dl.cpp | 20 ++++++------ src/core/chuck_dl.h | 36 +++++++++++----------- src/core/chuck_emit.cpp | 32 ++++++++++---------- src/core/chuck_instr.cpp | 40 ++++++++++++------------ src/core/chuck_instr.h | 4 +-- src/core/chuck_io.cpp | 2 +- src/core/chuck_lang.cpp | 18 +++++------ src/core/chuck_lang.h | 8 ++--- src/core/chuck_oo.cpp | 6 ++-- src/core/chuck_oo.h | 18 +++++------ src/core/chuck_otf.cpp | 12 ++++---- src/core/chuck_otf.h | 2 +- src/core/chuck_scan.cpp | 4 +-- src/core/chuck_type.cpp | 44 +++++++++++++-------------- src/core/chuck_type.h | 22 +++++++------- src/core/chuck_vm.cpp | 62 +++++++++++++++++++------------------- src/core/chuck_vm.h | 22 +++++++------- src/core/ugen_xxx.cpp | 6 ++-- src/core/util_buffers.h | 2 +- src/makefile | 2 +- 27 files changed, 196 insertions(+), 196 deletions(-) diff --git a/src/core/chuck.cpp b/src/core/chuck.cpp index bf2290fb5..3bfc0d531 100644 --- a/src/core/chuck.cpp +++ b/src/core/chuck.cpp @@ -760,7 +760,7 @@ t_CKBOOL ChucK::initChugins() // parse, type-check, and emit if( compiler()->go( filename, full_path ) ) { - // preserve op overloads | 1.5.1.4 + // preserve op overloads | 1.5.1.5 compiler()->env()->op_registry.preserve(); // get the code code = compiler()->output(); @@ -772,7 +772,7 @@ t_CKBOOL ChucK::initChugins() } else // did not compile { - // undo any op overloads | 1.5.1.4 + // undo any op overloads | 1.5.1.5 compiler()->env()->op_registry.reset2local(); } diff --git a/src/core/chuck.h b/src/core/chuck.h index be78514ff..d64f2262e 100644 --- a/src/core/chuck.h +++ b/src/core/chuck.h @@ -74,7 +74,7 @@ // ChucK version string -- retrieve using ChucK::version() // 1.5.0.0 (ge) | moved here for at-a-glance visibility (e.g., for chugins) -#define CHUCK_VERSION_STRING "1.5.1.4-dev (chai)" +#define CHUCK_VERSION_STRING "1.5.1.5-dev (chai)" // ChucK param names -- used in setParam(...) and getParam*(...) #define CHUCK_PARAM_VERSION "VERSION" diff --git a/src/core/chuck.lex b/src/core/chuck.lex index 9fe3a0327..d28edb380 100644 --- a/src/core/chuck.lex +++ b/src/core/chuck.lex @@ -247,7 +247,7 @@ long htol( c_str str ) will test using isatty()) */ %option never-interactive -/* 1.5.1.4 (ge) reentrant lexer */ +/* 1.5.1.5 (ge) reentrant lexer */ /* %option reentrant */ /* float exponent | 1.5.0.5 (ge) */ diff --git a/src/core/chuck.y b/src/core/chuck.y index 92fdf64ce..53f757422 100644 --- a/src/core/chuck.y +++ b/src/core/chuck.y @@ -604,7 +604,7 @@ unary_operator // | S_AND { $$ = ae_op_s_and; } ; -// 1.5.1.4 +// 1.5.1.5 overloadable_operator : CHUCK { $$ = ae_op_chuck; } | PLUS { $$ = ae_op_plus; } diff --git a/src/core/chuck_absyn.cpp b/src/core/chuck_absyn.cpp index 13c88564a..7673f7187 100644 --- a/src/core/chuck_absyn.cpp +++ b/src/core/chuck_absyn.cpp @@ -34,7 +34,7 @@ #include "chuck_errmsg.h" #include #include -#include // 1.5.1.4 for string concat +#include // 1.5.1.5 for string concat // 1.5.0.5 (ge) option to include in case we need something from flex/bison @@ -801,7 +801,7 @@ a_Func_Def new_func_def( ae_Keyword func_decl, ae_Keyword static_decl, return a; } -// @operator overload | 1.5.1.4 +// @operator overload | 1.5.1.5 a_Func_Def new_op_overload( ae_Keyword func_decl, ae_Keyword static_decl, a_Type_Decl type_decl, ae_Operator oper, a_Arg_List arg_list, a_Stmt code, @@ -821,7 +821,7 @@ a_Func_Def new_op_overload( ae_Keyword func_decl, ae_Keyword static_decl, a->s_type = ae_func_user; a->code = code; a->ast_owned = is_from_ast != 0; // 1.5.0.5 (ge) added - a->overload_post = overload_post; // 1.5.1.4 (ge) added + a->overload_post = overload_post; // 1.5.1.5 (ge) added a->line = lineNum; a->where = posNum; a->operWhere = operPos; return a; diff --git a/src/core/chuck_absyn.h b/src/core/chuck_absyn.h index 9309e470c..2a98240d1 100644 --- a/src/core/chuck_absyn.h +++ b/src/core/chuck_absyn.h @@ -481,7 +481,7 @@ struct a_Func_Def_ { a_Type_Decl type_decl; t_CKTYPE ret_type; S_Symbol name; - ae_Operator op2overload; // 1.5.1.4 (ge) added + ae_Operator op2overload; // 1.5.1.5 (ge) added a_Arg_List arg_list; a_Stmt code; t_CKFUNC ck_func; @@ -490,7 +490,7 @@ struct a_Func_Def_ { unsigned int stack_depth; void * dl_func_ptr; // should be not NULL iff s_type == ae_func_builtin uint32_t ast_owned; // 1.5.0.5 (ge) maintained by AST? - uint32_t overload_post; // 1.5.1.4 (ge) overload as post? e.g., @operator(args) ++ (unary only) + uint32_t overload_post; // 1.5.1.5 (ge) overload as post? e.g., @operator(args) ++ (unary only) uint32_t vm_refs; // 1.5.0.5 (ge) # of VM references uint32_t line; uint32_t where; uint32_t operWhere; }; diff --git a/src/core/chuck_compile.cpp b/src/core/chuck_compile.cpp index 9226e0896..b54da266d 100644 --- a/src/core/chuck_compile.cpp +++ b/src/core/chuck_compile.cpp @@ -765,7 +765,7 @@ t_CKBOOL load_internal_modules( Chuck_Compiler * compiler ) // commit what is in the type checker at this point env->global()->commit(); - // preserve all operator overloads currently in registry | 1.5.1.4 + // preserve all operator overloads currently in registry | 1.5.1.5 env->op_registry.preserve(); // pop indent level @@ -777,7 +777,7 @@ t_CKBOOL load_internal_modules( Chuck_Compiler * compiler ) // probably dangerous: rollback env->global()->rollback(); - // undo op registry entries | 1.5.1.4 + // undo op registry entries | 1.5.1.5 env->op_registry.reset2local(); // clear context @@ -1037,7 +1037,7 @@ t_CKBOOL load_external_module_at_path( Chuck_Compiler * compiler, EM_log( CK_LOG_SEVERE, "[%s] chugin %s (%d.%d)", TC::green("OK",true).c_str(), name, dll->versionMajor(), dll->versionMinor() ); // add to compiler compiler->m_dlls.push_back(dll); - // commit operator overloads | 1.5.1.4 + // commit operator overloads | 1.5.1.5 compiler->env()->op_registry.preserve(); // return home successful return TRUE; @@ -1045,7 +1045,7 @@ t_CKBOOL load_external_module_at_path( Chuck_Compiler * compiler, error: // clean up CK_SAFE_DELETE( dll ); - // rollback operator overloads | 1.5.1.4 + // rollback operator overloads | 1.5.1.5 compiler->env()->op_registry.reset2local(); return FALSE; @@ -1174,7 +1174,7 @@ t_CKBOOL Chuck_Compiler::load_external_modules( const char * extension, type_engine_unload_context( env ); // commit what is in the type checker at this point env->global()->commit(); - // preserve all operator overloads currently in registry | 1.5.1.4 + // preserve all operator overloads currently in registry | 1.5.1.5 env->op_registry.preserve(); return TRUE; diff --git a/src/core/chuck_dl.cpp b/src/core/chuck_dl.cpp index f38bba89f..f09389f19 100644 --- a/src/core/chuck_dl.cpp +++ b/src/core/chuck_dl.cpp @@ -1017,7 +1017,7 @@ const Chuck_DL_Query * Chuck_DLL::query() // set flag m_done_query = TRUE; - // process any operator overloads | 1.5.1.4 (ge & andrew) chaos^2 + // process any operator overloads | 1.5.1.5 (ge & andrew) chaos^2 if( m_query.op_overloads.size() ) { // log @@ -1254,8 +1254,8 @@ Chuck_DL_Query::Chuck_DL_Query( Chuck_Carrier * carrier, Chuck_DLL * dll ) doc_var = ck_doc_var; add_ex = ck_add_example; // 1.5.0.0 (ge) added create_main_thread_hook = ck_create_main_thread_hook; - register_shreds_watcher = ck_register_shreds_watcher; // 1.5.1.4 (ge & andrew) - unregister_shreds_watcher = ck_unregister_shreds_watcher; // 1.5.1.4 (ge & andrew) + register_shreds_watcher = ck_register_shreds_watcher; // 1.5.1.5 (ge & andrew) + unregister_shreds_watcher = ck_unregister_shreds_watcher; // 1.5.1.5 (ge & andrew) m_carrier = carrier; dll_ref = dll; // 1.5.1.3 (ge) added @@ -1278,7 +1278,7 @@ Chuck_DL_Query::Chuck_DL_Query( Chuck_Carrier * carrier, Chuck_DLL * dll ) srate = 0; } - // get DL API reference | 1.5.1.4 + // get DL API reference | 1.5.1.5 m_api = Chuck_DL_Api::Api::instance(); linepos = 0; @@ -1401,7 +1401,7 @@ namespace Chuck_DL_Api //----------------------------------------------------------------------------- -// name: ck_srate() | add 1.5.1.4 +// name: ck_srate() | add 1.5.1.5 // desc: host-side hook implementation for getting system srate //----------------------------------------------------------------------------- static t_CKUINT ck_srate( Chuck_VM * vm ) @@ -1411,7 +1411,7 @@ static t_CKUINT ck_srate( Chuck_VM * vm ) //----------------------------------------------------------------------------- -// name: ck_now() | add 1.5.1.4 +// name: ck_now() | add 1.5.1.5 // desc: host-side hook implementation for getting chuck system now //----------------------------------------------------------------------------- static t_CKTIME ck_now( Chuck_VM * vm ) @@ -1421,7 +1421,7 @@ static t_CKTIME ck_now( Chuck_VM * vm ) //----------------------------------------------------------------------------- -// name: create_event_buffer() | 1.5.1.4 (ge, andrew) added +// name: create_event_buffer() | 1.5.1.5 (ge, andrew) added // desc: host-side hoook implemenation for // creatinga new lock-free one-producer, one-consumer buffer //----------------------------------------------------------------------------- @@ -1432,7 +1432,7 @@ static CBufferSimple * ck_create_event_buffer( Chuck_VM * vm ) //----------------------------------------------------------------------------- -// name: queue_event() | 1.5.1.4 (ge, andrew) added +// name: queue_event() | 1.5.1.5 (ge, andrew) added // desc: host-side hoook implemenation for queuing an event // NOTE num_msg must be 1; buffer created using create_event_buffer() //----------------------------------------------------------------------------- @@ -2099,7 +2099,7 @@ t_CKBOOL CK_DLL_CALL ck_type_isa( Chuck_Type * lhs, Chuck_Type * rhs ) // windows translation //----------------------------------------------------------------------------- #if defined(__PLATFORM_WINDOWS__) -#include // std::system_category() | 1.5.1.4 +#include // std::system_category() | 1.5.1.5 extern "C" { @@ -2139,7 +2139,7 @@ const char * dlerror( void ) int error = GetLastError(); // no error if( error == 0 ) return NULL; - // 1.5.1.4 (azaday) convert error code to system message + // 1.5.1.5 (azaday) convert error code to system message std::string error_msg = std::system_category().message( error ); // 1.4.2.0 (ge) changed to snprintf snprintf( dlerror_buffer, DLERROR_BUFFER_LENGTH, "(%i) %s", error, error_msg.c_str() ); diff --git a/src/core/chuck_dl.h b/src/core/chuck_dl.h index b2e9c844e..131e4f1f3 100644 --- a/src/core/chuck_dl.h +++ b/src/core/chuck_dl.h @@ -201,7 +201,7 @@ union Chuck_DL_Return //------------------------------------------------------------------------------ // name: struct Chuck_DL_Arg -// desc: import / dynamic link function argument | 1.5.1.4 +// desc: import / dynamic link function argument | 1.5.1.5 //------------------------------------------------------------------------------ struct Chuck_DL_Arg { @@ -265,7 +265,7 @@ struct Chuck_DL_Arg // macro for defining ChucK DLL export static functions // example: CK_DLL_SFUN(foo) | 1.4.1.0 (ge) added TYPE to static prototype #define CK_DLL_SFUN(name) CK_DLL_EXPORT(void) name( Chuck_Type * TYPE, void * ARGS, Chuck_DL_Return * RETURN, Chuck_VM * VM, Chuck_VM_Shred * SHRED, CK_DL_API API ) -// example: CK_DLL_GFUN(foo) | 1.5.1.4 (ge & andrew) added for global-scope function, e.g., for op overloads +// example: CK_DLL_GFUN(foo) | 1.5.1.5 (ge & andrew) added for global-scope function, e.g., for op overloads #define CK_DLL_GFUN(name) CK_DLL_EXPORT(void) name( void * ARGS, Chuck_DL_Return * RETURN, Chuck_VM * VM, Chuck_VM_Shred * SHRED, CK_DL_API API ) // macro for defining ChucK DLL export ugen tick functions // example: CK_DLL_TICK(foo) @@ -318,7 +318,7 @@ typedef t_CKVOID (CK_DLL_CALL * f_dtor)( Chuck_Object * SELF, Chuck_VM * VM, Chu typedef t_CKVOID (CK_DLL_CALL * f_mfun)( Chuck_Object * SELF, void * ARGS, Chuck_DL_Return * RETURN, Chuck_VM * VM, Chuck_VM_Shred * SHRED, CK_DL_API API ); // 1.4.1.0 (ge) added TYPE to static prototype typedef t_CKVOID (CK_DLL_CALL * f_sfun)( Chuck_Type * TYPE, void * ARGS, Chuck_DL_Return * RETURN, Chuck_VM * VM, Chuck_VM_Shred * SHRED, CK_DL_API API ); -// 1.5.1.4 (ge & andrew) added for global-scope function, e.g., for op overloads +// 1.5.1.5 (ge & andrew) added for global-scope function, e.g., for op overloads typedef t_CKVOID (CK_DLL_CALL * f_gfun)( void * ARGS, Chuck_DL_Return * RETURN, Chuck_VM * VM, Chuck_VM_Shred * SHRED, CK_DL_API API ); // ugen specific typedef t_CKBOOL (CK_DLL_CALL * f_tick)( Chuck_Object * SELF, SAMPLE in, SAMPLE * out, CK_DL_API API ); @@ -439,7 +439,7 @@ struct Chuck_DL_Query Chuck_VM * vm() const { return m_carrier->vm; } Chuck_Env * env() const { return m_carrier->env; } Chuck_Carrier * carrier() const { return m_carrier; } - CK_DL_API api() const { return m_api; } // 1.5.1.4 + CK_DL_API api() const { return m_api; } // 1.5.1.5 public: // function pointers - to be called from client module @@ -484,16 +484,16 @@ struct Chuck_DL_Query // re-added 1.4.0.1 f_create_main_thread_hook create_main_thread_hook; - // add binary operator overload; args included | 1.5.1.4 (ge & andrew) + // add binary operator overload; args included | 1.5.1.5 (ge & andrew) f_add_op_overload_binary add_op_overload_binary; // add unary (prefix) operator overload; arg included f_add_op_overload_prefix add_op_overload_prefix; // add unary (postfix) operator overload; arg included f_add_op_overload_postfix add_op_overload_postfix; - // register shred notifcations | 1.5.1.4 (ge & andrew) + // register shred notifcations | 1.5.1.5 (ge & andrew) f_register_shreds_watcher register_shreds_watcher; - // un-register shred notifcations | 1.5.1.4 (ge & andrew) + // un-register shred notifcations | 1.5.1.5 (ge & andrew) f_unregister_shreds_watcher unregister_shreds_watcher; public: @@ -529,7 +529,7 @@ struct Chuck_DL_Query // flag any error encountered during the query | 1.5.0.5 (ge) added t_CKBOOL errorEncountered; - // DL API reference | 1.5.1.4 + // DL API reference | 1.5.1.5 CK_DL_API m_api; // collection of operator overloads @@ -627,7 +627,7 @@ struct Chuck_DL_Value //----------------------------------------------------------------------------- -// name: enum te_Op_OverloadKind | 1.5.1.4 (ge) added +// name: enum te_Op_OverloadKind | 1.5.1.5 (ge) added // desc: enumeration for kinds of operator overload //----------------------------------------------------------------------------- enum te_Op_OverloadKind @@ -657,9 +657,9 @@ struct Chuck_DL_Func std::vector args; // description std::string doc; - // is this an operator overload? if so, which kind? | 1.5.1.4 + // is this an operator overload? if so, which kind? | 1.5.1.5 te_Op_OverloadKind opOverloadKind; - // operator to overload | 1.5.1.4 + // operator to overload | 1.5.1.5 ae_Operator op2overload; // constructor @@ -797,7 +797,7 @@ struct Chuck_DL_MainThreadHook // invoking chuck functions from c++ //----------------------------------------------------------------------------- // directly invoke a chuck member function's native implementation from c++ -// using object + vtable offset | 1.5.1.4 (ge & andrew) +// using object + vtable offset | 1.5.1.5 (ge & andrew) // NOTE this will call the member function in IMMEDIATE MODE, // marking it as a time-critical function when called in this manner; // any time/event operations therein will throw an exception @@ -828,15 +828,15 @@ struct Api struct VMApi { VMApi(); - // get sample rate | 1.5.1.4 + // get sample rate | 1.5.1.5 t_CKUINT (CK_DLL_CALL * const srate)( Chuck_VM * vm ); - // get chuck now | 1.5.1.4 + // get chuck now | 1.5.1.5 t_CKTIME (CK_DLL_CALL * const now)( Chuck_VM * vm ); - // create a new lock-free one-producer, one-consumer buffer | 1.5.1.4 + // create a new lock-free one-producer, one-consumer buffer | 1.5.1.5 CBufferSimple * (CK_DLL_CALL * const create_event_buffer)( Chuck_VM * vm ); - // queue an event; num_msg must be 1; buffer should be created using create_event_buffer() above | 1.5.1.4 + // queue an event; num_msg must be 1; buffer should be created using create_event_buffer() above | 1.5.1.5 t_CKBOOL (CK_DLL_CALL * const queue_event)( Chuck_VM * vm, Chuck_Event * event, t_CKINT num_msg, CBufferSimple * buffer ); - // invoke Chuck_Object member function (defined either in chuck or c++) | 1.5.1.4 (ge & andrew) + // invoke Chuck_Object member function (defined either in chuck or c++) | 1.5.1.5 (ge & andrew) // NOTE this will call the member function in IMMEDIATE MODE, // marking it as a time-critical function when called in this manner; // any time/event operations therein will throw an exception @@ -958,7 +958,7 @@ struct Api const char * dlerror( void ); int dlclose( void * handle ); // 1.4.2.0 (ge) added DLERROR_BUFFER_LENGTH - // 1.5.1.4 (ge) increased DLERROR_BUFFER_LENGTH from 128 to 512 + // 1.5.1.5 (ge) increased DLERROR_BUFFER_LENGTH from 128 to 512 #define DLERROR_BUFFER_LENGTH 512 static char dlerror_buffer[DLERROR_BUFFER_LENGTH]; diff --git a/src/core/chuck_emit.cpp b/src/core/chuck_emit.cpp index 734f742ab..0176b291b 100644 --- a/src/core/chuck_emit.cpp +++ b/src/core/chuck_emit.cpp @@ -69,9 +69,9 @@ t_CKBOOL emit_engine_emit_op_chuck( Chuck_Emitter * emit, a_Exp lhs, a_Exp rhs, t_CKBOOL emit_engine_emit_op_unchuck( Chuck_Emitter * emit, a_Exp lhs, a_Exp rhs ); t_CKBOOL emit_engine_emit_op_upchuck( Chuck_Emitter * emit, a_Exp lhs, a_Exp rhs ); t_CKBOOL emit_engine_emit_op_at_chuck( Chuck_Emitter * emit, a_Exp lhs, a_Exp rhs ); -t_CKBOOL emit_engine_emit_op_overload_binary( Chuck_Emitter * emit, a_Exp_Binary binary ); // 1.5.1.4 -t_CKBOOL emit_engine_emit_op_overload_unary( Chuck_Emitter * emit, a_Exp_Unary unary ); // 1.5.1.4 -t_CKBOOL emit_engine_emit_op_overload_postfix( Chuck_Emitter * emit, a_Exp_Postfix postfix ); // 1.5.1.4 +t_CKBOOL emit_engine_emit_op_overload_binary( Chuck_Emitter * emit, a_Exp_Binary binary ); // 1.5.1.5 +t_CKBOOL emit_engine_emit_op_overload_unary( Chuck_Emitter * emit, a_Exp_Unary unary ); // 1.5.1.5 +t_CKBOOL emit_engine_emit_op_overload_postfix( Chuck_Emitter * emit, a_Exp_Postfix postfix ); // 1.5.1.5 t_CKBOOL emit_engine_emit_exp_unary( Chuck_Emitter * emit, a_Exp_Unary unary ); t_CKBOOL emit_engine_emit_exp_primary( Chuck_Emitter * emit, a_Exp_Primary exp ); t_CKBOOL emit_engine_emit_exp_cast( Chuck_Emitter * emit, a_Exp_Cast cast ); @@ -1925,7 +1925,7 @@ t_CKBOOL emit_engine_emit_exp_binary( Chuck_Emitter * emit, a_Exp_Binary binary // take care of objects in terms of reference counting doRefLeft = TRUE; } - // check operator overload | 1.5.1.4 (ge) + // check operator overload | 1.5.1.5 (ge) t_CKBOOL op_overload = (binary->ck_overload_func != NULL); if( op_overload && isobj( emit->env, binary->lhs->type ) ) { @@ -1976,7 +1976,7 @@ t_CKBOOL emit_engine_emit_op( Chuck_Emitter * emit, ae_Operator op, a_Exp lhs, a // whether an operator should be using an explicit overloading if( binary->ck_overload_func ) { - // emit operator overload | 1.5.1.4 (ge) added + // emit operator overload | 1.5.1.5 (ge) added return emit_engine_emit_op_overload_binary( emit, binary ); } @@ -2904,7 +2904,7 @@ t_CKBOOL emit_engine_emit_op( Chuck_Emitter * emit, ae_Operator op, a_Exp lhs, a //----------------------------------------------------------------------------- -// name: emit_engine_emit_op_overload_binary() | 1.5.1.4 (ge) added +// name: emit_engine_emit_op_overload_binary() | 1.5.1.5 (ge) added // desc: emit binary operator overload //----------------------------------------------------------------------------- t_CKBOOL emit_engine_emit_op_overload_binary( Chuck_Emitter * emit, a_Exp_Binary binary ) @@ -2920,7 +2920,7 @@ t_CKBOOL emit_engine_emit_op_overload_binary( Chuck_Emitter * emit, a_Exp_Binary //----------------------------------------------------------------------------- -// name: emit_engine_emit_op_overload_unary() | 1.5.1.4 (ge) added +// name: emit_engine_emit_op_overload_unary() | 1.5.1.5 (ge) added // desc: emit unary (prefix) operator overload //----------------------------------------------------------------------------- t_CKBOOL emit_engine_emit_op_overload_unary( Chuck_Emitter * emit, a_Exp_Unary unary ) @@ -2936,7 +2936,7 @@ t_CKBOOL emit_engine_emit_op_overload_unary( Chuck_Emitter * emit, a_Exp_Unary u //----------------------------------------------------------------------------- -// name: emit_engine_emit_op_overload_postfix() | 1.5.1.4 (ge) added +// name: emit_engine_emit_op_overload_postfix() | 1.5.1.5 (ge) added // desc: emit unary (postfix) operator overload //----------------------------------------------------------------------------- t_CKBOOL emit_engine_emit_op_overload_postfix( Chuck_Emitter * emit, a_Exp_Postfix postfix ) @@ -3226,7 +3226,7 @@ t_CKBOOL emit_engine_emit_op_at_chuck( Chuck_Emitter * emit, a_Exp lhs, a_Exp rh //----------------------------------------------------------------------------- t_CKBOOL emit_engine_emit_exp_unary( Chuck_Emitter * emit, a_Exp_Unary unary ) { - // check operator overload | 1.5.1.4 (ge) + // check operator overload | 1.5.1.5 (ge) t_CKBOOL op_overload = (unary->ck_overload_func != NULL); t_CKBOOL doRef = FALSE; if( op_overload && isobj( emit->env, unary->exp->type ) ) @@ -3243,7 +3243,7 @@ t_CKBOOL emit_engine_emit_exp_unary( Chuck_Emitter * emit, a_Exp_Unary unary ) Chuck_Type * t = unary->self->type; assert( t != NULL ); - // check overloading | 1.5.1.4 (ge) added + // check overloading | 1.5.1.5 (ge) added if( unary->ck_overload_func ) { // emit overloading | FYI spork can't be overloaded for now @@ -3781,7 +3781,7 @@ t_CKBOOL emit_engine_emit_cast( Chuck_Emitter * emit, //----------------------------------------------------------------------------- t_CKBOOL emit_engine_emit_exp_postfix( Chuck_Emitter * emit, a_Exp_Postfix postfix ) { - // check operator overload | 1.5.1.4 (ge) + // check operator overload | 1.5.1.5 (ge) t_CKBOOL op_overload = (postfix->ck_overload_func != NULL); t_CKBOOL doRef = FALSE; if( op_overload && isobj( emit->env, postfix->exp->type ) ) @@ -3794,7 +3794,7 @@ t_CKBOOL emit_engine_emit_exp_postfix( Chuck_Emitter * emit, a_Exp_Postfix postf if( !emit_engine_emit_exp( emit, postfix->exp, doRef ) ) return FALSE; - // check overloading | 1.5.1.4 (ge) added + // check overloading | 1.5.1.5 (ge) added if( postfix->ck_overload_func ) { // emit overloading @@ -4038,7 +4038,7 @@ t_CKBOOL emit_engine_emit_exp_func_call( Chuck_Emitter * emit, emit->append( instr = new Chuck_Instr_Func_Call_Member( kind, func ) ); else if( is_static ) emit->append( instr = new Chuck_Instr_Func_Call_Static( kind, func ) ); - else // 1.5.1.4 (ge & andrew) new planes of existence --> this is in global-scope (not global variable) + else // 1.5.1.5 (ge & andrew) new planes of existence --> this is in global-scope (not global variable) emit->append( instr = new Chuck_Instr_Func_Call_Global( kind, func ) ); } else @@ -5164,7 +5164,7 @@ t_CKBOOL emit_engine_emit_func_def( Chuck_Emitter * emit, a_Func_Def func_def ) emit->stack.push_back( emit->code ); // make a new one emit->code = new Chuck_Code; - // name the code | 1.5.1.4 use signature() + // name the code | 1.5.1.5 use signature() emit->code->name += func->signature(); // name the code (older code) // emit->code->name = emit->env->class_def ? emit->env->class_def->base_name + "." : ""; @@ -5398,7 +5398,7 @@ t_CKBOOL emit_engine_emit_class_def( Chuck_Emitter * emit, a_Class_Def class_def // *** ... could result in extra ref count // type->info->pre_ctor->add_ref(); // ---------------------- - // use CK_SAFE_REF_ASSIGN to add_ref RHS then releae LHS | 1.5.1.4 + // use CK_SAFE_REF_ASSIGN to add_ref RHS then releae LHS | 1.5.1.5 // maintain refcount integrity whether type->info->pre_ctor==NULL or not // ---------------------- CK_SAFE_REF_ASSIGN( type->info->pre_ctor, @@ -5425,7 +5425,7 @@ t_CKBOOL emit_engine_emit_class_def( Chuck_Emitter * emit, a_Class_Def class_def // check again if( !ret ) { - // release | 1.5.1.4 (ge) changed from DELETE to RELEASE + // release | 1.5.1.5 (ge) changed from DELETE to RELEASE CK_SAFE_RELEASE( type->info->pre_ctor ); } diff --git a/src/core/chuck_instr.cpp b/src/core/chuck_instr.cpp index 738a135cc..608e8d754 100644 --- a/src/core/chuck_instr.cpp +++ b/src/core/chuck_instr.cpp @@ -30,7 +30,7 @@ // date: Autumn 2002 //----------------------------------------------------------------------------- #include "chuck_instr.h" -#include "chuck_absyn.h" // for op2str | 1.5.1.4 +#include "chuck_absyn.h" // for op2str | 1.5.1.5 #include "chuck_type.h" #include "chuck_lang.h" #include "chuck_vm.h" @@ -3553,7 +3553,7 @@ void Chuck_Instr_Alloc_Word::execute( Chuck_VM * vm, Chuck_VM_Shred * shred ) t_CKBYTE *& mem_sp = (t_CKBYTE *&)shred->mem->sp; t_CKUINT *& reg_sp = (t_CKUINT *&)shred->reg->sp; - // overflow detection | 1.5.1.4 (ge) added + // overflow detection | 1.5.1.5 (ge) added if( would_overflow_( mem_sp+m_val, shred->mem ) ) goto overflow; // zero out the memory stack @@ -3581,7 +3581,7 @@ void Chuck_Instr_Alloc_Word2::execute( Chuck_VM * vm, Chuck_VM_Shred * shred ) t_CKBYTE *& mem_sp = (t_CKBYTE *&)shred->mem->sp; t_CKUINT *& reg_sp = (t_CKUINT *&)shred->reg->sp; - // overflow detection | 1.5.1.4 (ge) added + // overflow detection | 1.5.1.5 (ge) added if( would_overflow_( mem_sp+m_val, shred->mem ) ) goto overflow; // zero out the memory stack @@ -3609,7 +3609,7 @@ void Chuck_Instr_Alloc_Word4::execute( Chuck_VM * vm, Chuck_VM_Shred * shred ) t_CKBYTE *& mem_sp = (t_CKBYTE *&)shred->mem->sp; t_CKUINT *& reg_sp = (t_CKUINT *&)shred->reg->sp; - // overflow detection | 1.5.1.4 (ge) added + // overflow detection | 1.5.1.5 (ge) added if( would_overflow_( mem_sp+m_val, shred->mem ) ) goto overflow; // zero out the memory stack @@ -3638,7 +3638,7 @@ void Chuck_Instr_Alloc_Vec3::execute( Chuck_VM * vm, Chuck_VM_Shred * shred ) t_CKBYTE *& mem_sp = (t_CKBYTE *&)shred->mem->sp; t_CKUINT *& reg_sp = (t_CKUINT *&)shred->reg->sp; - // overflow detection | 1.5.1.4 (ge) added + // overflow detection | 1.5.1.5 (ge) added if( would_overflow_( mem_sp+m_val, shred->mem ) ) goto overflow; // zero out the memory stack @@ -3668,7 +3668,7 @@ void Chuck_Instr_Alloc_Vec4::execute( Chuck_VM * vm, Chuck_VM_Shred * shred ) t_CKBYTE *& mem_sp = (t_CKBYTE *&)shred->mem->sp; t_CKUINT *& reg_sp = (t_CKUINT *&)shred->reg->sp; - // overflow detection | 1.5.1.4 (ge) added + // overflow detection | 1.5.1.5 (ge) added if( would_overflow_( mem_sp+m_val, shred->mem ) ) goto overflow; // zero out the memory stack @@ -3993,16 +3993,16 @@ void Chuck_Instr_Pre_Constructor::execute( Chuck_VM * vm, Chuck_VM_Shred * shred //----------------------------------------------------------------------------- t_CKBOOL initialize_object( Chuck_Object * object, Chuck_Type * type, Chuck_VM_Shred * shred, Chuck_VM * vm ) { - // check if already initialized | 1.5.1.4 + // check if already initialized | 1.5.1.5 if( object->vtable != NULL ) return TRUE; // sanity assert( type != NULL ); assert( type->info != NULL ); - // set origin shred | 1.5.1.4 (ge) was: ugen->shred = shred; + // set origin shred | 1.5.1.5 (ge) was: ugen->shred = shred; if( shred ) object->setOriginShred( shred ); - // REFACTOR-2017: added | 1.5.1.4 (ge & andrew) moved here from instantiate_... + // REFACTOR-2017: added | 1.5.1.5 (ge & andrew) moved here from instantiate_... object->setOriginVM( vm ); // allocate virtual table @@ -4032,7 +4032,7 @@ t_CKBOOL initialize_object( Chuck_Object * object, Chuck_Type * type, Chuck_VM_S { // ugen Chuck_UGen * ugen = (Chuck_UGen *)object; - // add ugen to shred | 1.5.1.4 (ge & andrew) moved from instantiate_and_initialize_object() + // add ugen to shred | 1.5.1.5 (ge & andrew) moved from instantiate_and_initialize_object() if( shred ) shred->add( ugen ); // set tick if( type->ugen_info->tick ) ugen->tick = type->ugen_info->tick; @@ -4143,10 +4143,10 @@ Chuck_Object * instantiate_and_initialize_object( Chuck_Type * type, Chuck_VM_Sh // copy to object reference (in case of error, object will be deleted) object = newShred; - // get stack size hints | 1.5.1.4 + // get stack size hints | 1.5.1.5 t_CKINT mems = shred ? shred->childGetMemSize() : 0; t_CKINT regs = shred ? shred->childGetRegSize() : 0; - // initialize shred | 1.5.1.4 (ge) added, along with child mem and reg stack size hints + // initialize shred | 1.5.1.5 (ge) added, along with child mem and reg stack size hints if( !newShred->initialize( NULL, mems, regs ) ) goto error; } // 1.5.0.0 (ge) added -- here my feeble brain starts leaking out of my eyeballs @@ -4840,7 +4840,7 @@ void Chuck_Instr_Func_Call::execute( Chuck_VM * vm, Chuck_VM_Shred * shred ) t_CKUINT * mem_sp2 = (t_CKUINT *)mem_sp; t_CKUINT * reg_sp2 = (t_CKUINT *)reg_sp; - // detect would-be overflow | 1.5.1.4 (ge) added + // detect would-be overflow | 1.5.1.5 (ge) added if( would_overflow_( mem_sp2+stack_depth_ints, shred->mem ) ) goto error_overflow; // need this @@ -4917,7 +4917,7 @@ void Chuck_Instr_Func_Call_Member::execute( Chuck_VM * vm, Chuck_VM_Shred * shre t_CKUINT * reg_sp2 = reg_sp; t_CKUINT * mem_sp2 = mem_sp; - // detect would-be overflow | 1.5.1.4 (ge) added + // detect would-be overflow | 1.5.1.5 (ge) added if( would_overflow_( mem_sp2+stack_depth, shred->mem ) ) goto error_overflow; // need this @@ -5064,7 +5064,7 @@ void Chuck_Instr_Func_Call_Static::execute( Chuck_VM * vm, Chuck_VM_Shred * shre t_CKUINT * reg_sp2 = reg_sp; t_CKUINT * mem_sp2 = mem_sp; - // detect would-be overflow | 1.5.1.4 (ge) added + // detect would-be overflow | 1.5.1.5 (ge) added if( would_overflow_( mem_sp2+stack_depth, shred->mem ) ) goto error_overflow; // need type @@ -5159,7 +5159,7 @@ void Chuck_Instr_Func_Call_Static::execute( Chuck_VM * vm, Chuck_VM_Shred * shre //----------------------------------------------------------------------------- -// name: execute() | 1.5.1.4 +// name: execute() | 1.5.1.5 // desc: imported global function call with return //----------------------------------------------------------------------------- void Chuck_Instr_Func_Call_Global::execute( Chuck_VM * vm, Chuck_VM_Shred * shred ) @@ -5200,7 +5200,7 @@ void Chuck_Instr_Func_Call_Global::execute( Chuck_VM * vm, Chuck_VM_Shred * shre t_CKUINT * reg_sp2 = reg_sp; t_CKUINT * mem_sp2 = mem_sp; - // detect would-be overflow | 1.5.1.4 (ge) added + // detect would-be overflow | 1.5.1.5 (ge) added if( would_overflow_( mem_sp2+stack_depth, shred->mem ) ) goto error_overflow; // copy to args @@ -5419,7 +5419,7 @@ void Chuck_Instr_Time_Advance::execute( Chuck_VM * vm, Chuck_VM_Shred * shred ) // pop word from reg stack pop_( sp, 1 ); - // check for immediate mode exception | 1.5.1.4 (ge) + // check for immediate mode exception | 1.5.1.5 (ge) if( shred->checkImmediatModeException(m_linepos) ) { // do something! @@ -5472,7 +5472,7 @@ void Chuck_Instr_Event_Wait::execute( Chuck_VM * vm, Chuck_VM_Shred * shred ) // check for null if( !event ) goto null_pointer; - // check for immediate mode exception | 1.5.1.4 (ge) added + // check for immediate mode exception | 1.5.1.5 (ge) added if( shred->checkImmediatModeException(m_linepos) ) goto done; // wait @@ -5760,7 +5760,7 @@ Chuck_Instr_Array_Alloc::~Chuck_Instr_Array_Alloc() // desc: 1.3.1.0 -- changed size to kind //----------------------------------------------------------------------------- Chuck_Object * do_alloc_array( Chuck_VM * vm, // REFACTOR-2017: added - Chuck_VM_Shred * shred, // 1.5.1.4 added + Chuck_VM_Shred * shred, // 1.5.1.5 added t_CKINT * capacity, const t_CKINT * top, t_CKUINT kind, t_CKBOOL is_obj, t_CKUINT * objs, t_CKINT & index, diff --git a/src/core/chuck_instr.h b/src/core/chuck_instr.h index 58181b51d..aedf4b67a 100644 --- a/src/core/chuck_instr.h +++ b/src/core/chuck_instr.h @@ -1940,7 +1940,7 @@ struct Chuck_Instr_Reg_Pop_Complex : public Chuck_Instr //----------------------------------------------------------------------------- // name: struct Chuck_Instr_Reg_Pop_Vec3 -// desc: pop a vec3 value from reg stack | 1.5.1.4 +// desc: pop a vec3 value from reg stack | 1.5.1.5 //----------------------------------------------------------------------------- struct Chuck_Instr_Reg_Pop_Vec3 : public Chuck_Instr { @@ -1953,7 +1953,7 @@ struct Chuck_Instr_Reg_Pop_Vec3 : public Chuck_Instr //----------------------------------------------------------------------------- // name: struct Chuck_Instr_Reg_Pop_Vec4 -// desc: pop a vec4 value from reg stack | 1.5.1.4 +// desc: pop a vec4 value from reg stack | 1.5.1.5 //----------------------------------------------------------------------------- struct Chuck_Instr_Reg_Pop_Vec4 : public Chuck_Instr { diff --git a/src/core/chuck_io.cpp b/src/core/chuck_io.cpp index e02199eea..27b54e8f7 100644 --- a/src/core/chuck_io.cpp +++ b/src/core/chuck_io.cpp @@ -79,7 +79,7 @@ typedef DWORD uint32_t; #endif #endif -// for legacy use of disable fileio | 1.5.1.4 +// for legacy use of disable fileio | 1.5.1.5 #ifdef __DISABLE_FILEIO__ // auto define new, more granular macro #ifndef __DISABLE_ASYNCH_IO__ diff --git a/src/core/chuck_lang.cpp b/src/core/chuck_lang.cpp index b7d6635ba..76560381d 100644 --- a/src/core/chuck_lang.cpp +++ b/src/core/chuck_lang.cpp @@ -578,24 +578,24 @@ t_CKBOOL init_class_shred( Chuck_Env * env, Chuck_Type * type ) func->doc = "get the enclosing directory, the specified number of parent directories up."; if( !type_engine_import_mfun( env, func ) ) goto error; - // add childMemSize() | 1.5.1.4 + // add childMemSize() | 1.5.1.5 func = make_new_mfun( "int", "childMemSize", shred_ctrl_hintChildMemSize ); func->add_arg( "int", "sizeInBytes" ); func->doc = "set size hint of per-shred call stack (\"mem\") for children shreds subsequently sporked from the calling shred (NOTE this size hint does not affect the calling shred--only its descendants); if sizeInBytes <= 0, the size hint is set to the VM default. (FYI This is an arcane functionality that most programmers never need to worry about. Advanced usage: set size hint to small values (e.g., 1K) to support A LOT (e.g., >10000) of simultaneous shreds; set size hint to large values (e.g., >65K) to spork functions with extremely deep recursion, or to support A LOT (>10000) of declared local variables. Use with care.)"; if( !type_engine_import_mfun( env, func ) ) goto error; - // add childMemSize() | 1.5.1.4 + // add childMemSize() | 1.5.1.5 func = make_new_mfun( "int", "childMemSize", shred_cget_hintChildMemSize ); func->doc = "get the memory stack size hint (in bytes) for shreds sporked from this one."; if( !type_engine_import_mfun( env, func ) ) goto error; - // add childRegSize() | 1.5.1.4 + // add childRegSize() | 1.5.1.5 func = make_new_mfun( "int", "childRegSize", shred_ctrl_hintChildRegSize ); func->add_arg( "int", "sizeInBytes" ); func->doc = "set size hint of per-shred operand stack (\"reg\") for children shreds subsequently sporked from the calling shred (NOTE this size hint does not affect the calling shred--only its descendants); if sizeInBytes <= 0, the size hint is set to the VM default. (FYI This is an arcane functionality that most programmers never need to worry about. Advanced usage: set size hint to small values (e.g., 256 bytes) to support A LOT (>10000) of simultaneous shreds; set size hint to large values (e.g., >20K) to spork functions with extremely lengthy (>10000) statements, including array initializer lists. Use with care.)"; if( !type_engine_import_mfun( env, func ) ) goto error; - // add childRegSize() | 1.5.1.4 + // add childRegSize() | 1.5.1.5 func = make_new_mfun( "int", "childRegSize", shred_cget_hintChildRegSize ); 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; @@ -2077,7 +2077,7 @@ CK_DLL_MFUN( event_can_wait ) RETURN->v_int = TRUE; } -// 1.5.1.4 (ge/andrew) added; default implementation +// 1.5.1.5 (ge/andrew) added; default implementation CK_DLL_MFUN( event_waiting_on ) { // do nothing here; this function could be overridden as needed @@ -2395,7 +2395,7 @@ CK_DLL_SFUN( shred_fromId ) // added 1.3.2.0 } -CK_DLL_MFUN( shred_ctrl_hintChildMemSize ) // 1.5.1.4 +CK_DLL_MFUN( shred_ctrl_hintChildMemSize ) // 1.5.1.5 { // get arg t_CKINT sizeInBytes = GET_NEXT_INT(ARGS); @@ -2404,14 +2404,14 @@ CK_DLL_MFUN( shred_ctrl_hintChildMemSize ) // 1.5.1.4 } -CK_DLL_MFUN( shred_cget_hintChildMemSize ) // 1.5.1.4 +CK_DLL_MFUN( shred_cget_hintChildMemSize ) // 1.5.1.5 { // set RETURN->v_int = SHRED->childGetMemSize(); } -CK_DLL_MFUN( shred_ctrl_hintChildRegSize ) // 1.5.1.4 +CK_DLL_MFUN( shred_ctrl_hintChildRegSize ) // 1.5.1.5 { // get arg t_CKINT sizeInBytes = GET_NEXT_INT(ARGS); @@ -2420,7 +2420,7 @@ CK_DLL_MFUN( shred_ctrl_hintChildRegSize ) // 1.5.1.4 } -CK_DLL_MFUN( shred_cget_hintChildRegSize ) // 1.5.1.4 +CK_DLL_MFUN( shred_cget_hintChildRegSize ) // 1.5.1.5 { // set RETURN->v_int = SHRED->childGetRegSize(); diff --git a/src/core/chuck_lang.h b/src/core/chuck_lang.h index 35fed14fe..000552cfe 100644 --- a/src/core/chuck_lang.h +++ b/src/core/chuck_lang.h @@ -168,10 +168,10 @@ 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_MFUN( shred_ctrl_hintChildMemSize ); // added 1.5.1.4 -CK_DLL_MFUN( shred_cget_hintChildMemSize ); // added 1.5.1.4 -CK_DLL_MFUN( shred_ctrl_hintChildRegSize ); // added 1.5.1.4 -CK_DLL_MFUN( shred_cget_hintChildRegSize ); // added 1.5.1.4 +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 //----------------------------------------------------------------------------- diff --git a/src/core/chuck_oo.cpp b/src/core/chuck_oo.cpp index 32047723c..690f98110 100644 --- a/src/core/chuck_oo.cpp +++ b/src/core/chuck_oo.cpp @@ -239,7 +239,7 @@ t_CKUINT Chuck_VM_Object::refcount() const -// static instantiation | 1.5.1.4 +// static instantiation | 1.5.1.5 t_CKUINT Chuck_Object::our_vt_toString = 0; //----------------------------------------------------------------------------- @@ -3446,7 +3446,7 @@ void Chuck_Event::wait( Chuck_VM_Shred * shred, Chuck_VM * vm ) // make sure the shred info matches the vm assert( shred->vm_ref == vm ); - // invoke virtual function our_can_wait | 1.5.1.4 + // invoke virtual function our_can_wait | 1.5.1.5 Chuck_DL_Return RETURN = ck_invoke_mfun_immediate_mode( this, our_can_wait, vm, shred, NULL, 0 ); // see if we can wait if( RETURN.v_int ) @@ -3475,7 +3475,7 @@ void Chuck_Event::wait( Chuck_VM_Shred * shred, Chuck_VM * vm ) // add shred to shreduler vm->shreduler()->add_blocked( shred ); - // invoke virtual function our_waiting_on | 1.5.1.4 (ge & andrew) + // invoke virtual function our_waiting_on | 1.5.1.5 (ge & andrew) // this is called at the point when a shred has completed the actions // needed to wait on an Event, and can be notified/broadcasted from // a different thread diff --git a/src/core/chuck_oo.h b/src/core/chuck_oo.h index ea5aed906..c7d6953e9 100644 --- a/src/core/chuck_oo.h +++ b/src/core/chuck_oo.h @@ -149,19 +149,19 @@ struct Chuck_Object : public Chuck_VM_Object t_CKUINT data_size; public: - // set VM on which this object was instantiated | 1.5.1.4 + // set VM on which this object was instantiated | 1.5.1.5 void setOriginVM( Chuck_VM * vm ); - // set shred on which this object was instantiated | 1.5.1.4 + // set shred on which this object was instantiated | 1.5.1.5 void setOriginShred( Chuck_VM_Shred * shred ); - // get VM on which this object was instantiated | 1.5.1.4 + // get VM on which this object was instantiated | 1.5.1.5 Chuck_VM * originVM() const { return origin_vm; } - // get shred on which this object was instantiated | 1.5.1.4 + // get shred on which this object was instantiated | 1.5.1.5 Chuck_VM_Shred * originShred() const { return origin_shred; } protected: - // the shred on which this object was instantiated | 1.5.1.4 + // the shred on which this object was instantiated | 1.5.1.5 Chuck_VM_Shred * origin_shred; - // the VM on which this object was instantiated | 1.5.1.4 + // the VM on which this object was instantiated | 1.5.1.5 Chuck_VM * origin_vm; public: // static @@ -259,7 +259,7 @@ struct Chuck_Array : public Chuck_Object // name: struct Chuck_ArrayInt // desc: native ChucK arrays // (for 4-byte/8-byte int, depending on 32-bit vs 64-bit & Object refs) -// 1.5.1.4 (ge) renamed from Chuck_Array4 to Chuck_ArrayInt +// 1.5.1.5 (ge) renamed from Chuck_Array4 to Chuck_ArrayInt //----------------------------------------------------------------------------- struct Chuck_ArrayInt : public Chuck_Array { @@ -355,7 +355,7 @@ struct Chuck_ArrayInt : public Chuck_Array //----------------------------------------------------------------------------- // name: struct Chuck_ArrayFloat // desc: native ChucK arrays (for 8-byte float) -// 1.5.1.4 (ge) renamed from Chuck_Array8 to Chuck_ArrayFloat +// 1.5.1.5 (ge) renamed from Chuck_Array8 to Chuck_ArrayFloat //----------------------------------------------------------------------------- struct Chuck_ArrayFloat : public Chuck_Array { @@ -773,7 +773,7 @@ struct Chuck_Event : public Chuck_Object public: // virtual table offset for can_wait() static t_CKUINT our_can_wait; - // virtual table offset for waiting_on() | 1.5.1.4 (ge/andrew) added + // virtual table offset for waiting_on() | 1.5.1.5 (ge/andrew) added static t_CKUINT our_waiting_on; protected: diff --git a/src/core/chuck_otf.cpp b/src/core/chuck_otf.cpp index 462cd59c4..7d7142bf5 100644 --- a/src/core/chuck_otf.cpp +++ b/src/core/chuck_otf.cpp @@ -47,7 +47,7 @@ #ifndef __PLATFORM_WINDOWS__ #include - // linux 64-bit byte ordering | 1.5.1.4 + // linux 64-bit byte ordering | 1.5.1.5 #if defined(__PLATFORM_LINUX__) #include #ifndef htonll @@ -233,7 +233,7 @@ t_CKUINT otf_process_msg( Chuck_VM * vm, Chuck_Compiler * compiler, if( cmd->type == CK_MSG_REPLACE ) cmd->param = msg->param; - // interpret param3 | 1.5.1.4 (nshaheed & ge) + // interpret param3 | 1.5.1.5 (nshaheed & ge) if( msg->param3 ) { // flag this for always-add replace @@ -309,7 +309,7 @@ t_CKINT otf_send_file( const char * fname, OTF_Net_Msg & msg, const char * op, string buf; t_CKUINT amountRead = 0; - // use this to send | 1.5.1.4 + // use this to send | 1.5.1.5 OTF_Net_Msg msg2send; // parse out command line arguments @@ -338,13 +338,13 @@ t_CKINT otf_send_file( const char * fname, OTF_Net_Msg & msg, const char * op, { // error message EM_error2( 0, "(parse error) skipping file '%s' for [%s]...", filename.c_str(), op ); - // reset parser (clean up) | 1.5.1.4 + // reset parser (clean up) | 1.5.1.5 reset_parse(); // close file descriptor fclose( fd ); return FALSE; } - // reset parser (clean up) | 1.5.1.4 + // reset parser (clean up) | 1.5.1.5 reset_parse(); // stat it @@ -542,7 +542,7 @@ t_CKINT otf_send_cmd( t_CKINT argc, const char ** argv, t_CKINT & i, { // arg as c++ string string arg = trim(argv[i]); - // check for '%' | 1.5.1.4 (nshaheed & ge) + // check for '%' | 1.5.1.5 (nshaheed & ge) if( arg.length() && arg[0] == '%' ) { // convert into number diff --git a/src/core/chuck_otf.h b/src/core/chuck_otf.h index b37cb2563..c6c689d2a 100644 --- a/src/core/chuck_otf.h +++ b/src/core/chuck_otf.h @@ -66,7 +66,7 @@ struct OTF_Net_Msg void clear() { header = CK_NET_HEADER; type = param = param2 = param3 = length = 0; memset( buffer, 0, sizeof(buffer) ); } - // copy constructor | 1.5.1.4 + // copy constructor | 1.5.1.5 OTF_Net_Msg( const OTF_Net_Msg & rhs ) { header = rhs.header; diff --git a/src/core/chuck_scan.cpp b/src/core/chuck_scan.cpp index 92688cf1d..9665cd312 100644 --- a/src/core/chuck_scan.cpp +++ b/src/core/chuck_scan.cpp @@ -2640,7 +2640,7 @@ t_CKBOOL type_engine_scan2_class_def( Chuck_Env * env, a_Class_Def class_def ) env->curr = env->nspc_stack.back(); env->nspc_stack.pop_back(); - // the parent class | 1.5.1.4 (ge) moved from chuck_type module for earlier info + // the parent class | 1.5.1.5 (ge) moved from chuck_type module for earlier info t_CKTYPE t_parent = NULL; // make sure inheritance @@ -3048,7 +3048,7 @@ t_CKBOOL type_engine_scan2_func_def( Chuck_Env * env, a_Func_Def f ) } } - // operator overload | 1.5.1.4 (ge) added + // operator overload | 1.5.1.5 (ge) added if( op_overload ) { // scan operator overload diff --git a/src/core/chuck_type.cpp b/src/core/chuck_type.cpp index fc3cf975a..1817a81fe 100644 --- a/src/core/chuck_type.cpp +++ b/src/core/chuck_type.cpp @@ -73,9 +73,9 @@ t_CKTYPE type_engine_check_op_unchuck( Chuck_Env * env, a_Exp lhs, a_Exp rhs, a_ t_CKTYPE type_engine_check_op_upchuck( Chuck_Env * env, a_Exp lhs, a_Exp rhs, a_Exp_Binary binary ); t_CKTYPE type_engine_check_op_at_chuck( Chuck_Env * env, a_Exp lhs, a_Exp rhs, a_Exp_Binary binary ); t_CKTYPE type_engine_check_exp_unary( Chuck_Env * env, a_Exp_Unary unary ); -t_CKTYPE type_engine_check_op_overload_binary( Chuck_Env * env, ae_Operator op, Chuck_Type * lhs, Chuck_Type * rhs, a_Exp_Binary binary ); // 1.5.1.4 -t_CKTYPE type_engine_check_op_overload_unary( Chuck_Env * env, ae_Operator op, Chuck_Type * rhs, a_Exp_Unary unary ); // 1.5.1.4 -t_CKTYPE type_engine_check_op_overload_postfix( Chuck_Env * env, Chuck_Type * lhs, ae_Operator op, a_Exp_Postfix post ); // 1.5.1.4 +t_CKTYPE type_engine_check_op_overload_binary( Chuck_Env * env, ae_Operator op, Chuck_Type * lhs, Chuck_Type * rhs, a_Exp_Binary binary ); // 1.5.1.5 +t_CKTYPE type_engine_check_op_overload_unary( Chuck_Env * env, ae_Operator op, Chuck_Type * rhs, a_Exp_Unary unary ); // 1.5.1.5 +t_CKTYPE type_engine_check_op_overload_postfix( Chuck_Env * env, Chuck_Type * lhs, ae_Operator op, a_Exp_Postfix post ); // 1.5.1.5 t_CKTYPE type_engine_check_exp_primary( Chuck_Env * env, a_Exp_Primary exp ); t_CKTYPE type_engine_check_exp_array_lit( Chuck_Env * env, a_Exp_Primary exp ); t_CKTYPE type_engine_check_exp_complex_lit( Chuck_Env * env, a_Exp_Primary exp ); @@ -2077,7 +2077,7 @@ t_CKTYPE type_engine_check_op( Chuck_Env * env, ae_Operator op, a_Exp lhs, a_Exp case ae_op_divide_chuck: case ae_op_percent_chuck: { - // check overload | 1.5.1.4 (ge) added + // check overload | 1.5.1.5 (ge) added Chuck_Type * ret = type_engine_check_op_overload_binary( env, op, left, right, binary ); // if we have a hit if( ret ) return ret; @@ -2374,7 +2374,7 @@ t_CKTYPE type_engine_check_op( Chuck_Env * env, ae_Operator op, a_Exp lhs, a_Exp default: break; } - // check overload | 1.5.1.4 (ge) added + // check overload | 1.5.1.5 (ge) added Chuck_Type * ret = type_engine_check_op_overload_binary( env, op, left, right, binary ); // if we have a hit if( ret ) return ret; @@ -2753,7 +2753,7 @@ t_CKTYPE type_engine_check_op_chuck( Chuck_Env * env, a_Exp lhs, a_Exp rhs, // aggregate types else { - // check overloading of => | 1.5.1.4 (ge) added + // check overloading of => | 1.5.1.5 (ge) added Chuck_Type * ret = type_engine_check_op_overload_binary( env, ae_op_chuck, left, right, binary ); // if we have a hit if( ret ) return ret; @@ -2768,7 +2768,7 @@ t_CKTYPE type_engine_check_op_chuck( Chuck_Env * env, a_Exp lhs, a_Exp rhs, } } - // check overloading of => | 1.5.1.4 (ge) added + // check overloading of => | 1.5.1.5 (ge) added Chuck_Type * ret = type_engine_check_op_overload_binary( env, ae_op_chuck, left, right, binary ); // if we have a hit if( ret ) return ret; @@ -2795,7 +2795,7 @@ t_CKTYPE type_engine_check_op_unchuck( Chuck_Env * env, a_Exp lhs, a_Exp rhs, a_ // ugen =< ugen if( isa( left, env->ckt_ugen ) && isa( right, env->ckt_ugen ) ) return right; - // check overloading of =< | 1.5.1.4 (ge) added + // check overloading of =< | 1.5.1.5 (ge) added Chuck_Type * ret = type_engine_check_op_overload_binary( env, ae_op_unchuck, left, right, binary ); // if we have a hit if( ret ) return ret; @@ -2822,7 +2822,7 @@ t_CKTYPE type_engine_check_op_upchuck( Chuck_Env * env, a_Exp lhs, a_Exp rhs, a_ // uana =^ uana if( isa( left, env->ckt_uana ) && isa( right, env->ckt_uana ) ) return right; - // check overloading of =^ | 1.5.1.4 (ge) added + // check overloading of =^ | 1.5.1.5 (ge) added Chuck_Type * ret = type_engine_check_op_overload_binary( env, ae_op_upchuck, left, right, binary ); // if we have a hit if( ret ) return ret; @@ -2912,7 +2912,7 @@ t_CKTYPE type_engine_check_op_at_chuck( Chuck_Env * env, a_Exp lhs, a_Exp rhs, a return NULL; } - // check overloading of @=> (disallowed for now) | 1.5.1.4 (ge) added + // check overloading of @=> (disallowed for now) | 1.5.1.5 (ge) added Chuck_Type * ret = type_engine_check_op_overload_binary( env, ae_op_at_chuck, left, right, binary ); // if we have a hit if( ret ) return ret; @@ -3092,7 +3092,7 @@ t_CKTYPE type_engine_check_exp_unary( Chuck_Env * env, a_Exp_Unary unary ) default: break; } - // check overloading of unary operator | 1.5.1.4 (ge) added + // check overloading of unary operator | 1.5.1.5 (ge) added Chuck_Type * ret = type_engine_check_op_overload_unary( env, unary->op, t, unary ); // if we have a hit if( ret ) return ret; @@ -3835,7 +3835,7 @@ t_CKTYPE type_engine_check_exp_postfix( Chuck_Env * env, a_Exp_Postfix postfix ) return NULL; } - // check overloading of postfix operator | 1.5.1.4 (ge) added + // check overloading of postfix operator | 1.5.1.5 (ge) added Chuck_Type * ret = type_engine_check_op_overload_postfix( env, t, postfix->op, postfix ); // if we have a hit if( ret ) return ret; @@ -6666,7 +6666,7 @@ t_CKBOOL type_engine_import_op_overload( Chuck_Env * env, Chuck_DL_Func * sfun ) //----------------------------------------------------------------------------- -// name: type_engine_init_op_overload_builtin() | 1.5.1.4 (ge) added +// name: type_engine_init_op_overload_builtin() | 1.5.1.5 (ge) added // desc: reserve builtin default operator overloads; this disallows certain // overloadings, e.g., int + int //----------------------------------------------------------------------------- @@ -6937,7 +6937,7 @@ void type_engine_init_op_overload_builtin( Chuck_Env * env ) //----------------------------------------------------------------------------- -// name: type_engine_init_op_overload() | 1.5.1.4 (ge) added +// name: type_engine_init_op_overload() | 1.5.1.5 (ge) added // desc: initialize operator overload // NOTE this is typically called from init_type_system() //----------------------------------------------------------------------------- @@ -7011,7 +7011,7 @@ t_CKBOOL type_engine_init_op_overload( Chuck_Env * env ) //----------------------------------------------------------------------------- -// name: type_engine_scan_func_op_overload() | 1.5.1.4 (ge) added +// name: type_engine_scan_func_op_overload() | 1.5.1.5 (ge) added // desc: verify an operator overload // NOTE this is typically called from scan2_func_def() //----------------------------------------------------------------------------- @@ -7119,7 +7119,7 @@ t_CKBOOL type_engine_scan_func_op_overload( Chuck_Env * env, a_Func_Def f ) //----------------------------------------------------------------------------- // name: type_engine_check_func_op_overload() -// desc: type-check an operator overload | 1.5.1.4 (ge) added +// desc: type-check an operator overload | 1.5.1.5 (ge) added // NOTE this is typically called from check_func_def() //----------------------------------------------------------------------------- t_CKBOOL type_engine_check_func_op_overload( Chuck_Env * env, ae_Operator op, a_Func_Def func_def ) @@ -7677,9 +7677,9 @@ a_Func_Def make_dll_as_fun( Chuck_DL_Func * dl_fun, // copy the function pointer - the type doesn't matter here // ...since we copying into a void * - so mfun is used func_def->dl_func_ptr = (void *)dl_fun->mfun; - // copy the operator overload info | 1.5.1.4 + // copy the operator overload info | 1.5.1.5 func_def->op2overload = dl_fun->op2overload; - // set if unary postfix overload | 1.5.1.4 + // set if unary postfix overload | 1.5.1.5 func_def->overload_post = (dl_fun->opOverloadKind == te_op_overload_unary_post); return func_def; @@ -8326,11 +8326,11 @@ Chuck_Func::~Chuck_Func() CK_SAFE_RELEASE( this->code ); CK_SAFE_RELEASE( this->value_ref ); - // release args cache | 1.5.1.4 + // release args cache | 1.5.1.5 CK_SAFE_DELETE_ARRAY( this->args_cache ); this->args_cache_size = 0; - // release invoker(s) | 1.5.1.4 + // release invoker(s) | 1.5.1.5 CK_SAFE_DELETE( this->invoker_mfun ); // TODO: check if more references to release, e.g., up and next? @@ -8503,7 +8503,7 @@ void Chuck_Func::funcdef_cleanup() //----------------------------------------------------------------------------- -// name: pack_cache() | 1.5.1.4 +// name: pack_cache() | 1.5.1.5 // desc: pack c-style array of DL_Args into args cache //----------------------------------------------------------------------------- t_CKBOOL Chuck_Func::pack_cache( Chuck_DL_Arg * dlargs, t_CKUINT numArgs ) @@ -8553,7 +8553,7 @@ t_CKBOOL Chuck_Func::pack_cache( Chuck_DL_Arg * dlargs, t_CKUINT numArgs ) //----------------------------------------------------------------------------- -// name: setup_invoker() | 1.5.1.4 +// name: setup_invoker() | 1.5.1.5 // desc: setup invoker for this fun (for calling chuck function from c++) //----------------------------------------------------------------------------- t_CKBOOL Chuck_Func::setup_invoker( t_CKUINT func_vt_offset, Chuck_VM * vm, Chuck_VM_Shred * shred ) diff --git a/src/core/chuck_type.h b/src/core/chuck_type.h index 1889e1181..d78b1fa62 100644 --- a/src/core/chuck_type.h +++ b/src/core/chuck_type.h @@ -291,7 +291,7 @@ struct Chuck_VM; struct Chuck_VM_Code; struct Chuck_VM_MFunInvoker; struct Chuck_DLL; -// operator loading structs | 1.5.1.4 +// operator loading structs | 1.5.1.5 struct Chuck_Op_Registry; struct Chuck_Op_Semantics; struct Chuck_Op_Overload; @@ -430,7 +430,7 @@ struct Chuck_Context : public Chuck_VM_Object //----------------------------------------------------------------------------- -// name: struct Chuck_Op_Registry | 1.5.1.4 (ge) added +// name: struct Chuck_Op_Registry | 1.5.1.5 (ge) added // desc: operator overloading registry //----------------------------------------------------------------------------- struct Chuck_Op_Registry @@ -516,7 +516,7 @@ struct Chuck_Op_Registry //----------------------------------------------------------------------------- -// name: struct Chuck_TypePair | 1.5.1.4 (ge) added +// name: struct Chuck_TypePair | 1.5.1.5 (ge) added // desc: a type pair, used as key in operator overload map //----------------------------------------------------------------------------- struct Chuck_TypePair @@ -538,7 +538,7 @@ struct Chuck_TypePair //----------------------------------------------------------------------------- -// name: struct Chuck_Op_Semantics | 1.5.1.4 (ge) added +// name: struct Chuck_Op_Semantics | 1.5.1.5 (ge) added // desc: all overloading information for a particualr operator //----------------------------------------------------------------------------- struct Chuck_Op_Semantics @@ -586,7 +586,7 @@ struct Chuck_Op_Semantics //----------------------------------------------------------------------------- -// name: struct Chuck_Op_Overload | 1.5.1.4 (ge) added +// name: struct Chuck_Op_Overload | 1.5.1.5 (ge) added // desc: a particular overloading //----------------------------------------------------------------------------- struct Chuck_Op_Overload @@ -747,7 +747,7 @@ struct Chuck_Env : public Chuck_VM_Object std::map key_types; std::map key_values; - // operators mapping registry | 1.5.1.4 + // operators mapping registry | 1.5.1.5 Chuck_Op_Registry op_registry; // deprecated types @@ -1109,7 +1109,7 @@ struct Chuck_Func : public Chuck_VM_Object public: // pack c-style array of DL_Args into args cache t_CKBOOL pack_cache( Chuck_DL_Arg * dlargs, t_CKUINT numArgs ); - // args cache (used by c++ to chuck function calls) | 1.5.1.4 + // args cache (used by c++ to chuck function calls) | 1.5.1.5 t_CKBYTE * args_cache; // size of args cache t_CKUINT args_cache_size; @@ -1252,7 +1252,7 @@ t_CKBOOL type_engine_import_ugen_ctrl( Chuck_Env * env, const char * type, const f_ctrl ctrl, t_CKBOOL write, t_CKBOOL read ); t_CKBOOL type_engine_import_add_ex( Chuck_Env * env, const char * ex ); t_CKBOOL type_engine_import_class_end( Chuck_Env * env ); -// add global operator overload | 1.5.1.4 (ge & andrew) chaos +// add global operator overload | 1.5.1.5 (ge & andrew) chaos t_CKBOOL type_engine_import_op_overload( Chuck_Env * env, Chuck_DL_Func * func ); t_CKBOOL type_engine_register_deprecate( Chuck_Env * env, const std::string & former, const std::string & latter ); @@ -1281,11 +1281,11 @@ Chuck_Namespace * type_engine_find_nspc( Chuck_Env * env, a_Id_List path ); void type_engine_names2types( Chuck_Env * env, const std::vector & typeNames, std::vector & types ); // check and process auto types | 1.5.0.8 (ge) added t_CKBOOL type_engine_infer_auto( Chuck_Env * env, a_Exp_Decl decl, Chuck_Type * type ); -// initialize operator overload subsystem | 1.5.1.4 (ge) added +// initialize operator overload subsystem | 1.5.1.5 (ge) added t_CKBOOL type_engine_init_op_overload( Chuck_Env * env ); -// verify an operator overload | 1.5.1.4 (ge) added +// verify an operator overload | 1.5.1.5 (ge) added t_CKBOOL type_engine_scan_func_op_overload( Chuck_Env * env, a_Func_Def func_def ); -// type-check an operator overload func def | 1.5.1.4 (ge) added +// type-check an operator overload func def | 1.5.1.5 (ge) added t_CKBOOL type_engine_check_func_op_overload( Chuck_Env * env, a_Func_Def func_def ); diff --git a/src/core/chuck_vm.cpp b/src/core/chuck_vm.cpp index c8c0de24a..a762894d9 100644 --- a/src/core/chuck_vm.cpp +++ b/src/core/chuck_vm.cpp @@ -54,7 +54,7 @@ #include "midiio_rtmidi.h" // 1.4.1.0 #endif -#include // 1.5.1.4 | for ULONG_MAX +#include // 1.5.1.5 | for ULONG_MAX #include #include #include @@ -197,7 +197,7 @@ Chuck_VM::Chuck_VM() m_reply_buffer = NULL; m_event_buffer = NULL; m_shred_id = 0; - m_shred_check4dupes = FALSE; // 1.5.1.4 (ge) + m_shred_check4dupes = FALSE; // 1.5.1.5 (ge) // audio hookups m_dac = NULL; @@ -801,7 +801,7 @@ t_CKUINT Chuck_VM::process_msg( Chuck_Msg * & msg ) if( msg->args ) shred->args = *(msg->args); // check for different scenarios of replace - // replace-target absent | 1.5.1.4 (nshaheed) added + // replace-target absent | 1.5.1.5 (nshaheed) added if( !out ) { // spork it @@ -818,7 +818,7 @@ t_CKUINT Chuck_VM::process_msg( Chuck_Msg * & msg ) goto done; } // replace-target present - // modified shredule(shred) -> spork(shred) | 1.5.1.4 (ge) + // modified shredule(shred) -> spork(shred) | 1.5.1.5 (ge) else if( m_shreduler->remove( out ) && this->spork( shred ) ) { EM_print2blue( "(VM) replacing shred %lu (%s) with %lu (%s)...", @@ -905,7 +905,7 @@ t_CKUINT Chuck_VM::process_msg( Chuck_Msg * & msg ) { // clear user namespace env()->clear_user_namespace(); - // reset operload overloading to default | 1.5.1.4 + // reset operload overloading to default | 1.5.1.5 // not needed; this is implicit in clear_user_namespace() which calls reset() // env()->op_registry.reset(); } @@ -1045,7 +1045,7 @@ t_CKUINT Chuck_VM::next_id( const Chuck_VM_Shred * shred ) // NOTE if check4dupes is enabled, m_shred_id may no longer be the // highest ID but instead is a counter for possible next shred IDs, // which will repeatedly increment+check for duplicates until an - // available ID is found | 1.5.1.4 (ge and nshaheed) added + // available ID is found | 1.5.1.5 (ge and nshaheed) added if( !m_shred_check4dupes && shred->xid > m_shred_id ) { // update as highest ID so far @@ -1067,10 +1067,10 @@ t_CKUINT Chuck_VM::next_id( const Chuck_VM_Shred * shred ) m_shred_check4dupes = TRUE; } - // check for dupes (after shred id wraps from MAX_ID) | 1.5.1.4 + // check for dupes (after shred id wraps from MAX_ID) | 1.5.1.5 if( !m_shred_check4dupes ) return ++m_shred_id; - // find next unused shred ID | 1.5.1.4 + // find next unused shred ID | 1.5.1.5 while( m_shreduler->lookup( ++m_shred_id ) ); // return it @@ -1154,7 +1154,7 @@ Chuck_VM_Shred * Chuck_VM::spork( Chuck_VM_Code * code, Chuck_VM_Shred * parent, Chuck_VM_Shred * shred = new Chuck_VM_Shred; // set the vm shred->vm_ref = this; - // get stack size hints | 1.5.1.4 + // get stack size hints | 1.5.1.5 t_CKINT mems = parent ? parent->childGetMemSize() : 0; t_CKINT regs = parent ? parent->childGetRegSize() : 0; // initialize the shred (default stack size) @@ -1213,7 +1213,7 @@ Chuck_VM_Shred * Chuck_VM::spork( Chuck_VM_Shred * shred ) // set the now shred->now = shred->wake_time = m_shreduler->now_system; // set the id, if one hasn't been assigned yet | 1.5.0.8 (ge) add check - // pass in the shred into next_id() instead of checking here | 1.5.1.4 + // pass in the shred into next_id() instead of checking here | 1.5.1.5 shred->xid = next_id( shred ); // add ref CK_SAFE_ADD_REF( shred ); @@ -1225,7 +1225,7 @@ Chuck_VM_Shred * Chuck_VM::spork( Chuck_VM_Shred * shred ) // count m_num_shreds++; - // notify watcher | 1.5.1.4 + // notify watcher | 1.5.1.5 notify_watchers( CKVM_SHREDS_WATCH_SPORK, shred, m_shreds_watchers_spork ); return shred; @@ -1268,7 +1268,7 @@ void Chuck_VM::removeAll() m_shred_id = 0; m_num_shreds = 0; - // can safely reset this as well | 1.5.1.4 + // can safely reset this as well | 1.5.1.5 m_shred_check4dupes = FALSE; } @@ -1377,7 +1377,7 @@ t_CKBOOL Chuck_VM::abort_current_shred() //----------------------------------------------------------------------------- // name: notify_watchers() -// desc: notify watchers for a particular subscription | 1.5.1.4 +// desc: notify watchers for a particular subscription | 1.5.1.5 //----------------------------------------------------------------------------- void Chuck_VM::notify_watchers( ckvmShredsWatcherFlag which, Chuck_VM_Shred * shred, @@ -1476,7 +1476,7 @@ static void ckvm_process_watcher( t_CKBOOL add, list & //----------------------------------------------------------------------------- -// name: subscribe_watcher() | 1.5.1.4 +// name: subscribe_watcher() | 1.5.1.5 // desc: subscribe shreds watcher callback //----------------------------------------------------------------------------- void Chuck_VM::subscribe_watcher( f_shreds_watcher cb, t_CKUINT options, void * data ) @@ -1496,7 +1496,7 @@ void Chuck_VM::subscribe_watcher( f_shreds_watcher cb, t_CKUINT options, void * //----------------------------------------------------------------------------- -// name: remove_watcher() | 1.5.1.4 +// name: remove_watcher() | 1.5.1.5 // desc: remove shreds watcher callback //----------------------------------------------------------------------------- void Chuck_VM::remove_watcher( f_shreds_watcher cb ) @@ -1575,7 +1575,7 @@ Chuck_VM_Code::~Chuck_VM_Code() -// minimum stack size | 1.5.1.4 (ge) added +// minimum stack size | 1.5.1.5 (ge) added #define VM_STACK_MINIMUM_SIZE 2048 // offset in bytes at the beginning of a stack for initializing data #define VM_STACK_OFFSET 16 @@ -1590,7 +1590,7 @@ t_CKBOOL Chuck_VM_Stack::initialize( t_CKUINT size ) // check if already initialized if( m_is_init ) return FALSE; - // ensure stack size >= minimum size | 1.5.1.4 + // ensure stack size >= minimum size | 1.5.1.5 if( size < VM_STACK_MINIMUM_SIZE ) size = VM_STACK_MINIMUM_SIZE; // actual size in bytes to allocate; stack header + size + overflow pad t_CKUINT alloc_size = VM_STACK_OFFSET + size + VM_STACK_OVERFLOW_PADDING; @@ -1646,7 +1646,7 @@ t_CKBOOL Chuck_VM_Stack::shutdown() // set the flag to false m_is_init = FALSE; - // set size to 0 | 1.5.1.4 + // set size to 0 | 1.5.1.5 m_size = 0; return TRUE; @@ -1682,11 +1682,11 @@ Chuck_VM_Shred::Chuck_VM_Shred() start = 0; wake_time = 0; - // set children stack size hints to default | 1.5.1.4 + // set children stack size hints to default | 1.5.1.5 childSetMemSize( 0 ); childSetRegSize( 0 ); - // immediate mode | 1.5.1.4 + // immediate mode | 1.5.1.5 is_immediate_mode = FALSE; is_immediate_mode_violation = FALSE; @@ -1721,7 +1721,7 @@ t_CKBOOL Chuck_VM_Shred::initialize( Chuck_VM_Code * c, t_CKUINT mem_stack_size, t_CKUINT reg_stack_size ) { - // ensure we don't multi-initialize the shred | 1.5.1.4 + // ensure we don't multi-initialize the shred | 1.5.1.5 // FYI explicitly call shutdown() before re-initializing shred if( mem ) return FALSE; @@ -1732,7 +1732,7 @@ t_CKBOOL Chuck_VM_Shred::initialize( Chuck_VM_Code * c, mem = new Chuck_VM_Stack; reg = new Chuck_VM_Stack; - // check for default | 1.5.1.4 + // check for default | 1.5.1.5 if( mem_stack_size == 0 ) mem_stack_size = CKVM_MEM_STACK_SIZE; if( reg_stack_size == 0 ) reg_stack_size = CKVM_REG_STACK_SIZE; @@ -1763,7 +1763,7 @@ t_CKBOOL Chuck_VM_Shred::initialize( Chuck_VM_Code * c, // initialize if( !initialize_object( this, vm_ref->env()->ckt_shred, this, vm_ref ) ) goto error; - // inherit size hints for shreds sporked from this shred | 1.5.1.4 + // inherit size hints for shreds sporked from this shred | 1.5.1.5 childSetMemSize( mem_stack_size ); childSetRegSize( reg_stack_size ); @@ -1850,7 +1850,7 @@ t_CKBOOL Chuck_VM_Shred::shutdown() // clear it code_orig = code = NULL; - // set children stack size hints to default | 1.5.1.4 + // set children stack size hints to default | 1.5.1.5 childSetMemSize( 0 ); childSetRegSize( 0 ); @@ -1993,7 +1993,7 @@ t_CKINT Chuck_VM_Shred::childGetRegSize() // mechanism to observe the growth of maximum stacks depth (reg and mem) across // all shreds; when enabled, this is called every instruction in the VM; // used to gauge stack utilization and to assess default shred stacks sizes -// 1.5.1.4 (ge) added +// 1.5.1.5 (ge) added //----------------------------------------------------------------------------- static t_CKUINT g_mem_stack_depth_reached = 0; static t_CKUINT g_reg_stack_depth_reached = 0; @@ -2060,10 +2060,10 @@ CK_VM_STACK_DEBUG( CK_FPRINTF_STDERR( "CK_VM_DEBUG mem sp in: 0x%08lx out: 0x%08 CK_VM_STACK_DEBUG( CK_FPRINTF_STDERR( "CK_VM_DEBUG reg sp in: 0x%08lx out: 0x%08lx\n", (unsigned long)t_reg_sp, (unsigned long)this->reg->sp ) ); //----------------------------------------------------------------------------- - // detect operand stack overflow | 1.5.1.4 + // detect operand stack overflow | 1.5.1.5 if( overflow_( this->reg ) ) { ck_handle_overflow( this, vm_ref, "shred operand stack exceeded" ); break; } - // detect mem stack overflow ("catch all") | 1.5.1.4 + // detect mem stack overflow ("catch all") | 1.5.1.5 // NOTE func-call & alloc instrucions already detect if( overflow_( this->mem ) && is_running ) // <- is_running==FALSE if already detected { ck_handle_overflow( this, vm_ref, "shred memory stack exceeded" ); break; } @@ -2075,7 +2075,7 @@ CK_VM_STACK_DEBUG( CK_FPRINTF_STDERR( "CK_VM_DEBUG reg sp in: 0x%08lx out: 0x%08 // track number of cycles CK_TRACK( this->stat->cycles++ ); - // if enabled, update shred stacks depth observation | 1.5.1.4 + // if enabled, update shred stacks depth observation | 1.5.1.5 CK_VM_STACK_OBSERVE( ckvm_observe_stackdepth_across_all_shreds( this ) ); } @@ -2106,7 +2106,7 @@ t_CKBOOL Chuck_VM_Shred::yield() // need a VM to yield on if( !this->vm_ref ) return FALSE; - // check for immediate mode exception | 1.5.1.4 (ge) + // check for immediate mode exception | 1.5.1.5 (ge) if( this->checkImmediatModeException() ) return FALSE; // suspend this shred @@ -2210,7 +2210,7 @@ bool Chuck_VM_Shred::popLoopCounter() //----------------------------------------------------------------------------- -// name: checkImmediatModeException() | 1.5.1.4 (ge) added +// name: checkImmediatModeException() | 1.5.1.5 (ge) added // desc: check for immediate mode exception, if detected print and set state //----------------------------------------------------------------------------- t_CKBOOL Chuck_VM_Shred::checkImmediatModeException( t_CKUINT linepos ) @@ -2410,7 +2410,7 @@ t_CKBOOL Chuck_VM_Shreduler::shredule( Chuck_VM_Shred * shred, return FALSE; } - // check for immediate mode and report exception | 1.5.1.4 (ge) + // check for immediate mode and report exception | 1.5.1.5 (ge) if( shred->checkImmediatModeException() ) { // let's not shredule! diff --git a/src/core/chuck_vm.h b/src/core/chuck_vm.h index acfdc2566..5afc97bfb 100644 --- a/src/core/chuck_vm.h +++ b/src/core/chuck_vm.h @@ -64,7 +64,7 @@ struct Chuck_VM_Func; struct Chuck_VM_FTable; struct Chuck_Msg; struct Chuck_Globals_Manager; // added 1.4.1.0 (jack) -struct Chuck_Instr_Reg_Push_Imm; // 1.5.1.4 (ge) +struct Chuck_Instr_Reg_Push_Imm; // 1.5.1.5 (ge) class CBufferSimple; #ifndef __DISABLE_SERIAL__ // hack: spencer? @@ -109,7 +109,7 @@ struct Chuck_VM_Stack public: // state t_CKBOOL m_is_init; - t_CKUINT m_size; // 1.5.1.4 + t_CKUINT m_size; // 1.5.1.5 }; @@ -231,7 +231,7 @@ struct Chuck_VM_Shred : public Chuck_Object // children shreds std::map children; - // child stack size hints | 1.5.1.4 + // child stack size hints | 1.5.1.5 t_CKINT memStackSize; t_CKINT regStackSize; @@ -284,7 +284,7 @@ struct Chuck_VM_Shred : public Chuck_Object // loop counter pointer stack std::vector m_loopCounters; -public: // immediate mode temporal restriction | 1.5.1.4 (ge) +public: // immediate mode temporal restriction | 1.5.1.5 (ge) // while in this mode, exception will be thrown on any time ops: // 1) if shred advances time (even by 0 duration) // 2) if shred waits on event @@ -632,12 +632,12 @@ struct Chuck_VM : public Chuck_Object Chuck_Globals_Manager * globals_manager() const { return m_globals_manager; } public: - // subscribe shreds watcher callback | 1.5.1.4 + // subscribe shreds watcher callback | 1.5.1.5 void subscribe_watcher( f_shreds_watcher cb, t_CKUINT options, void * data = NULL ); - // notify watchers | 1.5.1.4 + // notify watchers | 1.5.1.5 void notify_watchers( ckvmShredsWatcherFlag which, Chuck_VM_Shred * shred, std::list & v ); - // remove shreds watcher callback | 1.5.1.4 + // remove shreds watcher callback | 1.5.1.5 void remove_watcher( f_shreds_watcher cb ); //----------------------------------------------------------------------------- @@ -692,7 +692,7 @@ struct Chuck_VM : public Chuck_Object Chuck_VM_Shred * m_shreds; t_CKUINT m_num_shreds; t_CKUINT m_shred_id; - t_CKBOOL m_shred_check4dupes; // 1.5.1.4 + t_CKBOOL m_shred_check4dupes; // 1.5.1.5 Chuck_VM_Shreduler * m_shreduler; // place to put dumped shreds std::vector m_shred_dump; @@ -711,7 +711,7 @@ struct Chuck_VM : public Chuck_Object Chuck_Globals_Manager * m_globals_manager; protected: - // 1.5.1.4 (ge & andrew) shreds watchers + // 1.5.1.5 (ge & andrew) shreds watchers std::list m_shreds_watchers_spork; std::list m_shreds_watchers_remove; std::list m_shreds_watchers_suspend; @@ -769,7 +769,7 @@ struct Chuck_Msg t_CKTIME when; // pointer to status struct, as applicable Chuck_VM_Status * status; - // whether to always add | 1.5.1.4 + // whether to always add | 1.5.1.5 t_CKBOOL alwaysAdd; // reply callback @@ -820,7 +820,7 @@ struct Chuck_Msg //----------------------------------------------------------------------------- -// name: struct Chuck_VM_MFunInvoker | 1.5.1.4 (ge) +// name: struct Chuck_VM_MFunInvoker | 1.5.1.5 (ge) // desc: construct for calling chuck-defined member functions from c++, // either from VM execution or outside the VM execution context //----------------------------------------------------------------------------- diff --git a/src/core/ugen_xxx.cpp b/src/core/ugen_xxx.cpp index 35611b5bb..8a011cc6f 100644 --- a/src/core/ugen_xxx.cpp +++ b/src/core/ugen_xxx.cpp @@ -1584,7 +1584,7 @@ CK_DLL_CTOR( foogen_ctor ) // func to code instrs.push_back(new Chuck_Instr_Func_To_Code); // push stack depth for args (this, float input) - instrs.push_back(new Chuck_Instr_Reg_Push_Imm(sz_VOIDPTR+sz_FLOAT)); // 1.5.1.4: changed to sz_+sz_; was: 12 + instrs.push_back(new Chuck_Instr_Reg_Push_Imm(sz_VOIDPTR+sz_FLOAT)); // 1.5.1.5: changed to sz_+sz_; was: 12 // func call instrs.push_back(new Chuck_Instr_Func_Call()); // push immediate @@ -1606,7 +1606,7 @@ CK_DLL_CTOR( foogen_ctor ) data->shred = new Chuck_VM_Shred; data->shred->vm_ref = SHRED->vm_ref; - // initialize with stack size hints | 1.5.1.4 + // initialize with stack size hints | 1.5.1.5 data->shred->initialize( code, SHRED->childGetMemSize(), SHRED->childGetRegSize() ); } else @@ -2450,7 +2450,7 @@ CK_DLL_TICK( delayp_tick ) if ( !d->buffer ) return FALSE; // area - d->now = ((Chuck_UGen*)SELF)->originVM()->shreduler()->now_system; // 1.5.1.4 + d->now = ((Chuck_UGen*)SELF)->originVM()->shreduler()->now_system; // 1.5.1.5 // d->now = ((Chuck_UGen*)SELF)->originShred()->vm_ref->shreduler()->now_system; //calculate new write-offset position ( we interpolate if we've been assigned a new write-offset ) diff --git a/src/core/util_buffers.h b/src/core/util_buffers.h index cd8e9072f..40a7270b7 100644 --- a/src/core/util_buffers.h +++ b/src/core/util_buffers.h @@ -137,7 +137,7 @@ class CBufferSimple UINT__ m_max_elem; #ifndef __DISABLE_THREADS__ - // added | 1.5.1.4 (ge & andrew) twilight zone + // added | 1.5.1.5 (ge & andrew) twilight zone XMutex m_mutex; #endif }; diff --git a/src/makefile b/src/makefile index 4416d38fb..48f663c64 100644 --- a/src/makefile +++ b/src/makefile @@ -16,7 +16,7 @@ CK_HOST_DIR=host # where to find RtAudio RTAUDIO_DIR=RtAudio # chuck version -CK_VERSION=1.5.1.4-dev +CK_VERSION=1.5.1.5-dev ########################## DEFAULT MAKE TARGET ################################ From 2f717ce8aa603e37ef1ade163eed816c7b321885 Mon Sep 17 00:00:00 2001 From: Ge Wang Date: Fri, 6 Oct 2023 13:39:27 -0700 Subject: [PATCH 21/26] increment chugin compatibility version to 9.0 --- src/core/chuck_dl.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/core/chuck_dl.h b/src/core/chuck_dl.h index 131e4f1f3..795660757 100644 --- a/src/core/chuck_dl.h +++ b/src/core/chuck_dl.h @@ -47,9 +47,9 @@ // major version must be the same between chuck:chugin -#define CK_DLL_VERSION_MAJOR (0x0008) +#define CK_DLL_VERSION_MAJOR (0x0009) // minor version of chugin must be less than or equal to chuck's -#define CK_DLL_VERSION_MINOR (0x0002) +#define CK_DLL_VERSION_MINOR (0x0000) #define CK_DLL_VERSION_MAKE(maj,min) ((t_CKUINT)(((maj) << 16) | (min))) #define CK_DLL_VERSION_GETMAJOR(v) (((v) >> 16) & 0xFFFF) #define CK_DLL_VERSION_GETMINOR(v) ((v) & 0xFFFF) From 543277959c29b4abace668f4c8e9f75e19e768f6 Mon Sep 17 00:00:00 2001 From: Ge Wang Date: Fri, 6 Oct 2023 15:54:01 -0700 Subject: [PATCH 22/26] add HID open suppressErrMsg option --- src/core/chuck_io.cpp | 17 ++++++++++++++++- src/core/chuck_io.h | 1 + src/core/hidio_sdl.cpp | 28 +++++++++++++++++----------- src/core/hidio_sdl.h | 8 ++++---- 4 files changed, 38 insertions(+), 16 deletions(-) diff --git a/src/core/chuck_io.cpp b/src/core/chuck_io.cpp index 27b54e8f7..834e5fbb2 100644 --- a/src/core/chuck_io.cpp +++ b/src/core/chuck_io.cpp @@ -1161,6 +1161,13 @@ t_CKBOOL init_class_HID( Chuck_Env * env ) func->doc = "Open a keyboard by device number."; if( !type_engine_import_mfun( env, func ) ) goto error; + // add openKeyboard() | 1.5.1.5 (ge & andrew) + func = make_new_mfun( "int", "openKeyboard", HidIn_open_keyboard_2 ); + func->add_arg( "int", "num" ); + func->add_arg( "int", "suppressErrorMessages" ); + func->doc = "Open a keyboard by device number, with option to suppress error messages."; + if( !type_engine_import_mfun( env, func ) ) goto error; + // add openTiltSensor() func = make_new_mfun( "int", "openTiltSensor", HidIn_open_tiltsensor ); func->doc = "Open a tilt-sensor by device number."; @@ -2419,7 +2426,8 @@ CK_DLL_MFUN( HidIn_open_named ) HidIn * min = (HidIn *)OBJ_MEMBER_INT(SELF, HidIn_offset_data); Chuck_String * name = GET_NEXT_STRING(ARGS); std::string s = name->str(); - RETURN->v_int = min->open( SHRED->vm_ref, s ); + // set CK_HID_DEV_COUNT as a special flag + RETURN->v_int = min->open( SHRED->vm_ref, CK_HID_DEV_COUNT, s ); } CK_DLL_MFUN( HidIn_open_joystick ) @@ -2443,6 +2451,13 @@ CK_DLL_MFUN( HidIn_open_keyboard ) RETURN->v_int = min->open( SHRED->vm_ref, CK_HID_DEV_KEYBOARD, num ); } +CK_DLL_MFUN( HidIn_open_keyboard_2 ) +{ + HidIn * min = (HidIn *)OBJ_MEMBER_INT(SELF, HidIn_offset_data); + t_CKINT num = GET_NEXT_INT(ARGS); + RETURN->v_int = min->open( SHRED->vm_ref, CK_HID_DEV_KEYBOARD, num, TRUE ); +} + CK_DLL_MFUN( HidIn_open_tiltsensor ) { HidIn * min = (HidIn *)OBJ_MEMBER_INT(SELF, HidIn_offset_data); diff --git a/src/core/chuck_io.h b/src/core/chuck_io.h index b0540dcc2..f40a9634d 100644 --- a/src/core/chuck_io.h +++ b/src/core/chuck_io.h @@ -547,6 +547,7 @@ CK_DLL_MFUN( HidIn_open_named_i ); // added 1.3.0.0 CK_DLL_MFUN( HidIn_open_joystick ); CK_DLL_MFUN( HidIn_open_mouse ); CK_DLL_MFUN( HidIn_open_keyboard ); +CK_DLL_MFUN( HidIn_open_keyboard_2 ); CK_DLL_MFUN( HidIn_open_tiltsensor ); CK_DLL_MFUN( HidIn_good ); CK_DLL_MFUN( HidIn_num ); diff --git a/src/core/hidio_sdl.cpp b/src/core/hidio_sdl.cpp index a70562ce9..f8a1bde1e 100644 --- a/src/core/hidio_sdl.cpp +++ b/src/core/hidio_sdl.cpp @@ -481,14 +481,14 @@ HidIn::~HidIn( ) // name: open() // desc: open //----------------------------------------------------------------------------- -t_CKBOOL HidIn::open( Chuck_VM * vm, t_CKINT device_type, t_CKINT device_num ) +t_CKBOOL HidIn::open( Chuck_VM * vm, t_CKINT device_type, t_CKINT device_num, t_CKBOOL suppressErrMsg ) { // close if already opened if( m_valid ) this->close(); // open - return m_valid = HidInManager::open( this, vm, device_type, device_num ); + return m_valid = HidInManager::open( this, vm, device_type, device_num, suppressErrMsg ); } @@ -498,14 +498,14 @@ t_CKBOOL HidIn::open( Chuck_VM * vm, t_CKINT device_type, t_CKINT device_num ) // name: open() // desc: open //----------------------------------------------------------------------------- -t_CKBOOL HidIn::open( Chuck_VM * vm, std::string & name, t_CKUINT device_type ) +t_CKBOOL HidIn::open( Chuck_VM * vm, t_CKINT device_type, std::string & name, t_CKBOOL suppressErrMsg ) { // close if already opened if( m_valid ) this->close(); // open - return m_valid = HidInManager::open( this, vm, device_type, name ); + return m_valid = HidInManager::open( this, vm, device_type, name, suppressErrMsg ); } @@ -684,7 +684,7 @@ void HidInManager::cleanup( t_CKUINT msWait ) } -t_CKBOOL HidInManager::open( HidIn * hin, Chuck_VM * vm, t_CKINT device_type, t_CKINT device_num ) +t_CKBOOL HidInManager::open( HidIn * hin, Chuck_VM * vm, t_CKINT device_type, t_CKINT device_num, t_CKBOOL suppressErrMsg ) { // init? if( has_init == FALSE ) @@ -730,7 +730,7 @@ t_CKBOOL HidInManager::open( HidIn * hin, Chuck_VM * vm, t_CKINT device_type, t_ { // log // should this use EM_log instead, with a higher log level? - EM_error2( 0, "HidIn: couldn't open %s %d...", + if( !suppressErrMsg ) EM_error2( 0, "HidIn: couldn't open %s %d...", default_drivers[device_type].driver_name, device_num ); CK_SAFE_DELETE( phin ); return FALSE; @@ -768,7 +768,7 @@ t_CKBOOL HidInManager::open( HidIn * hin, Chuck_VM * vm, t_CKINT device_type, t_ -t_CKBOOL HidInManager::open( HidIn * hin, Chuck_VM * vm, t_CKINT device_type, std::string & device_name ) +t_CKBOOL HidInManager::open( HidIn * hin, Chuck_VM * vm, t_CKINT device_type, std::string & device_name, t_CKBOOL suppressErrMsg ) { // init? if( has_init == FALSE ) @@ -789,9 +789,12 @@ t_CKBOOL HidInManager::open( HidIn * hin, Chuck_VM * vm, t_CKINT device_type, st // check type if( device_type < 1 || device_type >= CK_HID_DEV_COUNT ) { + // should this use EM_log instead, with a higher log level? + if( !suppressErrMsg ) + EM_error2( 0, "HidInManager: open() failed -> invalid type '%d'...", device_type ); // log - EM_log( CK_LOG_WARNING, "HidInManager: open() failed -> invalid type '%d'...", - device_type ); + // EM_log( CK_LOG_WARNING, "HidInManager: open() failed -> invalid type '%d'...", + // device_type ); return FALSE; } @@ -830,8 +833,11 @@ t_CKBOOL HidInManager::open( HidIn * hin, Chuck_VM * vm, t_CKINT device_type, st } } - EM_log( CK_LOG_WARNING, "HidInManager: open() failed -> no device named '%s'...", - device_name.c_str() ); + // should this use EM_log instead, with a higher log level? + if( !suppressErrMsg ) EM_error2( 0, "HidInManager: open() failed -> no device named '%s'...", + device_name.c_str()); + // EM_log( CK_LOG_WARNING, "HidInManager: open() failed -> no device named '%s'...", + // device_name.c_str() ); return FALSE; } diff --git a/src/core/hidio_sdl.h b/src/core/hidio_sdl.h index a629c55ce..1be4e2118 100644 --- a/src/core/hidio_sdl.h +++ b/src/core/hidio_sdl.h @@ -92,8 +92,8 @@ struct HidIn : public Chuck_Event ~HidIn(); public: - t_CKBOOL open( Chuck_VM * vm, t_CKINT device_type, t_CKINT device_num ); - t_CKBOOL open( Chuck_VM * vm, std::string & name, t_CKUINT device_type = CK_HID_DEV_COUNT ); + t_CKBOOL open( Chuck_VM * vm, t_CKINT device_type, t_CKINT device_num, t_CKBOOL suppressErrMsg = FALSE ); + t_CKBOOL open( Chuck_VM * vm, t_CKINT device_type /*= CK_HID_DEV_COUNT*/, std::string & name, t_CKBOOL suppressErrMsg = FALSE ); t_CKBOOL close(); t_CKBOOL read( t_CKINT type, t_CKINT num, HidMsg * msg ); t_CKBOOL send( const HidMsg * msg ); @@ -127,8 +127,8 @@ class HidInManager static void init(); static void init_default_drivers(); static void cleanup( t_CKUINT msWait = 0 ); - static t_CKBOOL open( HidIn * hin, Chuck_VM * vm, t_CKINT device_type, t_CKINT device_num ); - static t_CKBOOL open( HidIn * hin, Chuck_VM * vm, t_CKINT device_type, std::string & device_name ); + static t_CKBOOL open( HidIn * hin, Chuck_VM * vm, t_CKINT device_type, t_CKINT device_num, t_CKBOOL suppressErrMsg = FALSE ); + static t_CKBOOL open( HidIn * hin, Chuck_VM * vm, t_CKINT device_type, std::string & device_name, t_CKBOOL suppressErrMsg = FALSE ); static t_CKBOOL close( HidIn * hin ); static void cleanup_buffer( Chuck_VM * vm ); From 5dc38beed82d6446652b7c4f4996f987d66b08f4 Mon Sep 17 00:00:00 2001 From: Ge Wang Date: Fri, 6 Oct 2023 17:12:53 -0700 Subject: [PATCH 23/26] add suppressErrMsg option to joystick and mouse HID; fixed keyboard to account for option --- src/core/chuck_io.cpp | 37 ++++++++++++++++++++++++++++++++++--- src/core/chuck_io.h | 2 ++ 2 files changed, 36 insertions(+), 3 deletions(-) diff --git a/src/core/chuck_io.cpp b/src/core/chuck_io.cpp index 834e5fbb2..d055063b5 100644 --- a/src/core/chuck_io.cpp +++ b/src/core/chuck_io.cpp @@ -1149,12 +1149,26 @@ t_CKBOOL init_class_HID( Chuck_Env * env ) func->doc = "Open a joystick/gamepad by device number."; if( !type_engine_import_mfun( env, func ) ) goto error; + // add openJoystick() + func = make_new_mfun( "int", "openJoystick", HidIn_open_joystick_2 ); + func->add_arg( "int", "num" ); + func->add_arg( "int", "suppressErrMsg" ); + func->doc = "Open a joystick/gamepad by device number, with option (true/false) to suppress error messages."; + if( !type_engine_import_mfun( env, func ) ) goto error; + // add openMouse() func = make_new_mfun( "int", "openMouse", HidIn_open_mouse ); func->add_arg( "int", "num" ); func->doc = "Open a mouse/trackpad by device number."; if( !type_engine_import_mfun( env, func ) ) goto error; + // add openMouse() + func = make_new_mfun( "int", "openMouse", HidIn_open_mouse_2 ); + func->add_arg( "int", "num" ); + func->add_arg( "int", "suppressErrMsg" ); + func->doc = "Open a mouse/trackpad by device number, with option (true/false) to suppress error messages."; + if( !type_engine_import_mfun( env, func ) ) goto error; + // add openKeyboard() func = make_new_mfun( "int", "openKeyboard", HidIn_open_keyboard ); func->add_arg( "int", "num" ); @@ -1164,8 +1178,8 @@ t_CKBOOL init_class_HID( Chuck_Env * env ) // add openKeyboard() | 1.5.1.5 (ge & andrew) func = make_new_mfun( "int", "openKeyboard", HidIn_open_keyboard_2 ); func->add_arg( "int", "num" ); - func->add_arg( "int", "suppressErrorMessages" ); - func->doc = "Open a keyboard by device number, with option to suppress error messages."; + func->add_arg( "int", "suppressErrMsg" ); + func->doc = "Open a keyboard by device number, with option (true/false) to suppress error messages."; if( !type_engine_import_mfun( env, func ) ) goto error; // add openTiltSensor() @@ -2437,6 +2451,14 @@ CK_DLL_MFUN( HidIn_open_joystick ) RETURN->v_int = min->open( SHRED->vm_ref, CK_HID_DEV_JOYSTICK, num ); } +CK_DLL_MFUN( HidIn_open_joystick_2 ) +{ + HidIn * min = (HidIn *)OBJ_MEMBER_INT(SELF, HidIn_offset_data); + t_CKINT num = GET_NEXT_INT(ARGS); + t_CKINT suppressErrMsg = GET_NEXT_INT(ARGS); + RETURN->v_int = min->open( SHRED->vm_ref, CK_HID_DEV_JOYSTICK, num, suppressErrMsg ); +} + CK_DLL_MFUN( HidIn_open_mouse ) { HidIn * min = (HidIn *)OBJ_MEMBER_INT(SELF, HidIn_offset_data); @@ -2444,6 +2466,14 @@ CK_DLL_MFUN( HidIn_open_mouse ) RETURN->v_int = min->open( SHRED->vm_ref, CK_HID_DEV_MOUSE, num ); } +CK_DLL_MFUN( HidIn_open_mouse_2 ) +{ + HidIn * min = (HidIn *)OBJ_MEMBER_INT(SELF, HidIn_offset_data); + t_CKINT num = GET_NEXT_INT(ARGS); + t_CKINT suppressErrMsg = GET_NEXT_INT(ARGS); + RETURN->v_int = min->open( SHRED->vm_ref, CK_HID_DEV_MOUSE, num, suppressErrMsg ); +} + CK_DLL_MFUN( HidIn_open_keyboard ) { HidIn * min = (HidIn *)OBJ_MEMBER_INT(SELF, HidIn_offset_data); @@ -2455,7 +2485,8 @@ CK_DLL_MFUN( HidIn_open_keyboard_2 ) { HidIn * min = (HidIn *)OBJ_MEMBER_INT(SELF, HidIn_offset_data); t_CKINT num = GET_NEXT_INT(ARGS); - RETURN->v_int = min->open( SHRED->vm_ref, CK_HID_DEV_KEYBOARD, num, TRUE ); + t_CKINT suppressErrMsg = GET_NEXT_INT(ARGS); + RETURN->v_int = min->open( SHRED->vm_ref, CK_HID_DEV_KEYBOARD, num, suppressErrMsg ); } CK_DLL_MFUN( HidIn_open_tiltsensor ) diff --git a/src/core/chuck_io.h b/src/core/chuck_io.h index f40a9634d..9271cde3b 100644 --- a/src/core/chuck_io.h +++ b/src/core/chuck_io.h @@ -545,7 +545,9 @@ CK_DLL_MFUN( HidIn_open ); CK_DLL_MFUN( HidIn_open_named ); CK_DLL_MFUN( HidIn_open_named_i ); // added 1.3.0.0 CK_DLL_MFUN( HidIn_open_joystick ); +CK_DLL_MFUN( HidIn_open_joystick_2 ); CK_DLL_MFUN( HidIn_open_mouse ); +CK_DLL_MFUN( HidIn_open_mouse_2 ); CK_DLL_MFUN( HidIn_open_keyboard ); CK_DLL_MFUN( HidIn_open_keyboard_2 ); CK_DLL_MFUN( HidIn_open_tiltsensor ); From 0926eba07016564490ca1701386746059ffeff25 Mon Sep 17 00:00:00 2001 From: Ge Wang Date: Fri, 6 Oct 2023 21:31:58 -0700 Subject: [PATCH 24/26] add DL API func system_remove_all_shreds() --- src/core/chuck_dl.cpp | 25 ++++++++++++++++++++++--- src/core/chuck_dl.h | 2 ++ 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/src/core/chuck_dl.cpp b/src/core/chuck_dl.cpp index f09389f19..62c23116c 100644 --- a/src/core/chuck_dl.cpp +++ b/src/core/chuck_dl.cpp @@ -66,6 +66,7 @@ char g_chugin_path_envvar[] = "CHUCK_CHUGIN_PATH"; void CK_DLL_CALL ck_add_arg( Chuck_DL_Query * query, const char * type, const char * name ); void CK_DLL_CALL ck_throw_exception( const char * exception, const char * desc, Chuck_VM_Shred * shred ); void CK_DLL_CALL ck_em_log( t_CKINT level, const char * text ); +void CK_DLL_CALL ck_system_remove_all_shreds( Chuck_VM * vm ); Chuck_DL_Api::Type CK_DLL_CALL ck_type_lookup( Chuck_VM * vm, const char * name ); t_CKBOOL CK_DLL_CALL ck_type_isequal( Chuck_Type * lhs, Chuck_Type * rhs ); t_CKBOOL CK_DLL_CALL ck_type_isa( Chuck_Type * lhs, Chuck_Type * rhs ); @@ -1908,7 +1909,8 @@ create_event_buffer(ck_create_event_buffer), queue_event(ck_queue_event), invoke_mfun_immediate_mode(ck_invoke_mfun_immediate_mode), throw_exception(ck_throw_exception), -em_log(ck_em_log) +em_log(ck_em_log), +system_remove_all_shreds(ck_system_remove_all_shreds) { } @@ -2037,8 +2039,8 @@ void CK_DLL_CALL ck_throw_exception( const char * exception, const char * desc, //----------------------------------------------------------------------------- -// name: ck_throw_exception() -// desc: throw an exception +// name: ck_em_log() +// desc: host impl: print to chuck logger //----------------------------------------------------------------------------- void CK_DLL_CALL ck_em_log( t_CKINT level, const char * text ) { @@ -2051,6 +2053,23 @@ void CK_DLL_CALL ck_em_log( t_CKINT level, const char * text ) +//----------------------------------------------------------------------------- +// name: ck_system_remove_all_shreds() +// desc: host impl for system function: remove all shreds in VM; use with care +//----------------------------------------------------------------------------- +void CK_DLL_CALL ck_system_remove_all_shreds( Chuck_VM * vm ) +{ + // construct chuck msg (must allocate on heap, as VM will clean up) + Chuck_Msg * msg = new Chuck_Msg(); + // set type + msg->type = CK_MSG_REMOVEALL; + // remove all shreds + vm->queue_msg( msg ); +} + + + + //----------------------------------------------------------------------------- // name: ck_type_lookup() // desc: host-side hook implementation for retrieving a type by name diff --git a/src/core/chuck_dl.h b/src/core/chuck_dl.h index 795660757..faa3f8f5d 100644 --- a/src/core/chuck_dl.h +++ b/src/core/chuck_dl.h @@ -846,6 +846,8 @@ struct Api void (CK_DLL_CALL * const throw_exception)( const char * exception, const char * desc, Chuck_VM_Shred * shred ); // log a message in the chuck logging system void (CK_DLL_CALL * const em_log)( t_CKINT level, const char * text ); + // system function: remove all shreds in VM; use with care + void (CK_DLL_CALL * const system_remove_all_shreds)( Chuck_VM * vm ); } * const vm; // api to access host-side ChucK objects From 23a397c4dc7bdc12c47a9c44f0f869316db411d8 Mon Sep 17 00:00:00 2001 From: Ge Wang Date: Fri, 6 Oct 2023 23:47:25 -0700 Subject: [PATCH 25/26] add special:auto for FileIO output --- examples/io/write-auto.ck | 28 +++++++++++ src/core/chuck_dl.cpp | 6 ++- src/core/chuck_dl.h | 2 + src/core/chuck_io.cpp | 97 ++++++++++++++++++++++++++++++++---- src/core/chuck_io.h | 13 +++++ src/core/ugen_stk.cpp | 27 ++-------- src/core/util_string.cpp | 23 +++++++++ src/core/util_string.h | 3 ++ src/scripts/ckdoc/gen-all.ck | 2 +- 9 files changed, 165 insertions(+), 36 deletions(-) create mode 100644 examples/io/write-auto.ck diff --git a/examples/io/write-auto.ck b/examples/io/write-auto.ck new file mode 100644 index 000000000..db8d546f5 --- /dev/null +++ b/examples/io/write-auto.ck @@ -0,0 +1,28 @@ +// example showing auto-naming for file writing + +// instantiate a file IO object +FileIO fout; + +// optional: set prefix and extension +// (defaults prefix: "chuck-file" ext: "txt") +fout.autoPrefixExtension( "chuck-file", "txt" ); + +// open for write (default mode: ASCII) +fout.open( "special:auto", FileIO.WRITE ); + +// test +if( !fout.good() ) +{ + cherr <= "can't open file for writing..." <= IO.newline(); + me.exit(); +} + +// write some stuff +fout <= 1 <= " " <= 2 <= " " <= "foo" <= IO.newline(); + +// print the file that was written +// FYI before we close it as that clears the filename +<<< "file written:", fout.filename() >>>; + +// close the thing +fout.close(); diff --git a/src/core/chuck_dl.cpp b/src/core/chuck_dl.cpp index 62c23116c..0f3514f60 100644 --- a/src/core/chuck_dl.cpp +++ b/src/core/chuck_dl.cpp @@ -1563,7 +1563,7 @@ static Chuck_DL_Api::Object ck_create_without_shred( Chuck_VM * vm, Chuck_DL_Api // name: ck_create_string() // desc: host-side hook implementation for creating a chuck string //----------------------------------------------------------------------------- -static Chuck_DL_Api::String ck_create_string( Chuck_VM * vm, const char * cstr, t_CKBOOL addRef ) +Chuck_String * ck_create_string( Chuck_VM * vm, const char * cstr, t_CKBOOL addRef ) { // instantiate and initalize object Chuck_String * ckstr = (Chuck_String *)instantiate_and_initialize_object( vm->env()->ckt_string, vm ); @@ -1576,10 +1576,12 @@ static Chuck_DL_Api::String ck_create_string( Chuck_VM * vm, const char * cstr, if( addRef ) CK_SAFE_ADD_REF(ckstr); } // return reference - return (Chuck_DL_Api::String)ckstr; + return ckstr; } + + //----------------------------------------------------------------------------- // name: ck_get_mvar() // desc: retrieve a class's member variable offset diff --git a/src/core/chuck_dl.h b/src/core/chuck_dl.h index faa3f8f5d..af567b406 100644 --- a/src/core/chuck_dl.h +++ b/src/core/chuck_dl.h @@ -793,6 +793,8 @@ struct Chuck_DL_MainThreadHook +// instantiating a chuck string +Chuck_String * ck_create_string( Chuck_VM * vm, const char * cstr, t_CKBOOL addRef ); //----------------------------------------------------------------------------- // invoking chuck functions from c++ //----------------------------------------------------------------------------- diff --git a/src/core/chuck_io.cpp b/src/core/chuck_io.cpp index d055063b5..73dcd1e9d 100644 --- a/src/core/chuck_io.cpp +++ b/src/core/chuck_io.cpp @@ -457,6 +457,28 @@ t_CKBOOL init_class_fileio( Chuck_Env * env, Chuck_Type * type ) func->doc = "Write floating point value to file; binary mode: flags indicate float size (IO.FLOAT32 or IO.FLOAT64)."; if( !type_engine_import_mfun( env, func ) ) goto error; + // add autoPrefixAndExt() | 1.5.1.5 (ge) + func = make_new_mfun( "void", "autoPrefixExtension", file_ctrl_autoPrefixAndExtension ); //! set auto prefix and extension string + func->add_arg( "string", "prefix" ); + func->add_arg( "string", "extension" ); + func->doc = "set auto prefix and extension for \"special:auto\" filename generation (applicable to file writing only)."; + if( !type_engine_import_mfun( env, func ) ) goto error; + + // add autoPrefix() + func = make_new_mfun( "string", "autoPrefix", file_cget_autoPrefix ); //! get auto prefix string + func->doc = "get auto prefix for \"special:auto\" filename generation (applicable to file writing only)."; + if( !type_engine_import_mfun( env, func ) ) goto error; + + // add autoExtension() + func = make_new_mfun( "string", "autoExtension", file_cget_autoExtension ); //! get auto extension string + func->doc = "get auto extension for \"special:auto\" filename generation (applicable to file writing only)."; + if( !type_engine_import_mfun( env, func ) ) goto error; + + // add filename() + func = make_new_mfun( "string", "filename", file_cget_filename ); //! get auto extension string + func->doc = "get current filename."; + if( !type_engine_import_mfun( env, func ) ) goto error; + // add expandPath | 1.5.1.3 func = make_new_sfun( "string", "expandPath", fileio_expandpath_impl ); func->add_arg( "string", "path" ); @@ -473,6 +495,7 @@ t_CKBOOL init_class_fileio( Chuck_Env * env, Chuck_Type * type ) if( !type_engine_import_add_ex( env, "io/seek.ck" ) ) goto error; if( !type_engine_import_add_ex( env, "io/write.ck" ) ) goto error; if( !type_engine_import_add_ex( env, "io/write2.ck" ) ) goto error; + if( !type_engine_import_add_ex( env, "io/write-auto.ck" ) ) goto error; if( !type_engine_import_add_ex( env, "io/read-byte.ck" ) ) goto error; if( !type_engine_import_add_ex( env, "io/write-byte.ck" ) ) goto error; @@ -1658,6 +1681,39 @@ CK_DLL_MFUN( fileio_dirlist ) RETURN->v_object = a; } +CK_DLL_MFUN( file_ctrl_autoPrefixAndExtension ) +{ + Chuck_IO_File * f = (Chuck_IO_File *)SELF; + Chuck_String * prefix = GET_NEXT_STRING(ARGS); + Chuck_String * extension = GET_NEXT_STRING(ARGS); + + f->m_autoPrefix = prefix ? prefix->str() : ""; + f->m_autoExtension = extension ? extension->str() : ""; +} + +CK_DLL_MFUN( file_cget_autoPrefix ) +{ + // get this + Chuck_IO_File * f = (Chuck_IO_File *)SELF; + // create string, no ref count here, as we are not holding on to it + RETURN->v_object = ck_create_string( VM, f->m_autoPrefix.c_str(), FALSE ); +} + +CK_DLL_MFUN( file_cget_autoExtension ) +{ + // get this + Chuck_IO_File * f = (Chuck_IO_File *)SELF; + // create string, no ref count here, as we are not holding on to it + RETURN->v_object = ck_create_string( VM, f->m_autoExtension.c_str(), FALSE ); +} + +CK_DLL_MFUN( file_cget_filename ) +{ + // get this + Chuck_IO_File * f = (Chuck_IO_File *)SELF; + // create string, no ref count here, as we are not holding on to it + RETURN->v_object = ck_create_string( VM, f->filename().c_str(), FALSE ); +} // expandPath | 1.5.1.3 CK_DLL_SFUN( fileio_expandpath_impl ) @@ -3045,6 +3101,10 @@ Chuck_IO_File::Chuck_IO_File( Chuck_VM * vm ) #ifndef __DISABLE_THREADS__ m_thread = new XThread; #endif + + // initialize prefix and extensions for auto | 1.5.1.5 + m_autoPrefix = "chuck-file"; + m_autoExtension = "txt"; } @@ -3073,9 +3133,12 @@ Chuck_IO_File::~Chuck_IO_File() //----------------------------------------------------------------------------- t_CKBOOL Chuck_IO_File::open( const string & path, t_CKINT flags ) { + // the filename + string theFilename = path; + // log EM_log( CK_LOG_INFO, "FileIO: opening file from disk..." ); - EM_log( CK_LOG_INFO, "FileIO: path: %s", path.c_str() ); + EM_log( CK_LOG_INFO, "FileIO: path: %s", theFilename.c_str() ); EM_pushlog(); // if no flag specified, make it READ by default @@ -3157,8 +3220,24 @@ t_CKBOOL Chuck_IO_File::open( const string & path, t_CKINT flags ) if( m_io.is_open() ) this->close(); + // special + if( strstr( theFilename.c_str(), "special:auto" ) ) + { + // check output + if( theMode & ios_base::out ) + { + // generate auto name + theFilename = autoFilename( this->m_autoPrefix, this->m_autoExtension ); + } + else + { + EM_error3( "[chuck](via FileIO): \"special:auto\" can only be used for output" ); + goto error; + } + } + // try to open as a dir first (fixed 1.3.0.0 removed warning) - m_dir = opendir( path.c_str() ); + m_dir = opendir( theFilename.c_str() ); if( m_dir ) { EM_poplog(); @@ -3169,11 +3248,11 @@ t_CKBOOL Chuck_IO_File::open( const string & path, t_CKINT flags ) // readonly if( !(flags & FLAG_READONLY) ) { - m_io.open( path.c_str(), ios_base::in ); + m_io.open( theFilename.c_str(), ios_base::in ); if( m_io.fail() ) { m_io.clear(); - m_io.open( path.c_str(), ios_base::out | ios_base::trunc ); + m_io.open( theFilename.c_str(), ios_base::out | ios_base::trunc ); m_io.close(); } else @@ -3181,7 +3260,7 @@ t_CKBOOL Chuck_IO_File::open( const string & path, t_CKINT flags ) } //open file - m_io.open( path.c_str(), theMode ); + m_io.open( theFilename.c_str(), theMode ); // seek to beginning if necessary if( flags & FLAG_READ_WRITE ) @@ -3194,21 +3273,21 @@ t_CKBOOL Chuck_IO_File::open( const string & path, t_CKINT flags ) // windows sucks for being creative in the wrong places #ifdef __PLATFORM_WINDOWS__ // if( flags ^ Chuck_IO::TRUNCATE && flags | Chuck_IO::READ ) nMode |= ios::nocreate; - m_io.open( path.c_str(), nMode ); + m_io.open( theFilename.c_str(), nMode ); #else - m_io.open( path.c_str(), (_Ios_Openmode)nMode ); + m_io.open( theFilename.c_str(), (_Ios_Openmode)nMode ); #endif */ // check for error if( !(m_io.is_open()) ) { - // EM_error3( "[chuck](via FileIO): cannot open file: '%s'", path.c_str() ); + // EM_error3( "[chuck](via FileIO): cannot open file: '%s'", theFilename.c_str() ); goto error; } // set path - m_path = path; + m_path = theFilename; // set flags m_flags = flags; if( !(flags & TYPE_BINARY) ) diff --git a/src/core/chuck_io.h b/src/core/chuck_io.h index 9271cde3b..c51dee282 100644 --- a/src/core/chuck_io.h +++ b/src/core/chuck_io.h @@ -231,6 +231,9 @@ struct Chuck_IO_File : public Chuck_IO static THREAD_RETURN( THREAD_TYPE writeFloat_thread ) (void * data); #endif + // get filename + std::string filename() const { return m_path; } + protected: // open flags t_CKINT m_flags; @@ -246,6 +249,12 @@ struct Chuck_IO_File : public Chuck_IO std::string m_path; // vm and shred Chuck_VM * m_vmRef; + +public: + // auto prefix | 1.5.1.5 + std::string m_autoPrefix; + // auto extension | 1.5.1.5 + std::string m_autoExtension; }; @@ -405,6 +414,10 @@ CK_DLL_MFUN( fileio_writeint ); CK_DLL_MFUN( fileio_writeintflags ); CK_DLL_MFUN( fileio_writefloat ); CK_DLL_MFUN( fileio_writefloatflags ); +CK_DLL_MFUN( file_ctrl_autoPrefixAndExtension ); +CK_DLL_MFUN( file_cget_autoPrefix ); +CK_DLL_MFUN( file_cget_autoExtension ); +CK_DLL_MFUN( file_cget_filename ); CK_DLL_SFUN( fileio_expandpath_impl ); diff --git a/src/core/ugen_stk.cpp b/src/core/ugen_stk.cpp index a6160bc4e..32afc19e4 100644 --- a/src/core/ugen_stk.cpp +++ b/src/core/ugen_stk.cpp @@ -47,6 +47,7 @@ #include "chuck_oo.h" #include "util_math.h" #include "util_platforms.h" +#include "util_string.h" #include #include #include @@ -4819,11 +4820,11 @@ by Perry R. Cook and Gary P. Scavone, 1995 - 2002."; func = make_new_mfun( "string", "autoPrefix", WvOut_ctrl_autoPrefix ); //! set/get auto prefix string func->add_arg( "string", "value" ); - func->doc = "set auto prefix string."; + func->doc = "set auto prefix string for \"special:auto\" filename generation."; if( !type_engine_import_mfun( env, func ) ) goto error; func = make_new_mfun( "string", "autoPrefix", WvOut_cget_autoPrefix ); //! set/get auto prefix string - func->doc = "get auto prefix string."; + func->doc = "get auto prefix string for \"special:auto\" filename generation."; if( !type_engine_import_mfun( env, func ) ) goto error; func = make_new_mfun( "float", "fileGain", WvOut_ctrl_fileGain ); //! set/get auto prefix string @@ -28007,28 +28008,6 @@ CK_DLL_PMSG( WvOut_pmsg ) -//----------------------------------------------------------------------------- -// name: autoFilename() -// desc: generate auto filename | 1.5.0.0 (ge) refactored into this function -//----------------------------------------------------------------------------- -static std::string autoFilename( const std::string & prefix, const std::string & fileExt ) -{ - char buffer[1024]; - time_t t; time(&t); - strcpy( buffer, prefix.c_str() ); - strcat( buffer, "(" ); - strncat( buffer, ctime(&t), 24 ); - buffer[strlen(prefix.c_str())+14] = 'h'; - buffer[strlen(prefix.c_str())+17] = 'm'; - strcat( buffer, ")." ); - strcat( buffer, fileExt.c_str() ); - // return - return buffer; -} - - - - //----------------------------------------------------------------------------- // name: fileType2fileExt() | 1.5.0.1 (ge) added // desc: helper function for converting WvOut type enum to file extension diff --git a/src/core/util_string.cpp b/src/core/util_string.cpp index 9e2118012..abe0ae30e 100644 --- a/src/core/util_string.cpp +++ b/src/core/util_string.cpp @@ -1072,6 +1072,29 @@ std::string timestamp_formatted() + +//----------------------------------------------------------------------------- +// name: autoFilename() +// desc: generate auto filename | 1.5.0.0 (ge) refactored into this function +//----------------------------------------------------------------------------- +std::string autoFilename( const std::string & prefix, const std::string & fileExt ) +{ + char buffer[1024]; + time_t t; time(&t); + strcpy( buffer, prefix.c_str() ); + strcat( buffer, "(" ); + strncat( buffer, ctime(&t), 24 ); + buffer[strlen(prefix.c_str())+14] = 'h'; + buffer[strlen(prefix.c_str())+17] = 'm'; + strcat( buffer, ")." ); + strcat( buffer, fileExt.c_str() ); + // return + return buffer; +} + + + + static t_CKBOOL str_contains( const string & s, char c ) { return s.find( c ) != string::npos; } diff --git a/src/core/util_string.h b/src/core/util_string.h index 22d4145b9..cc37a06c2 100644 --- a/src/core/util_string.h +++ b/src/core/util_string.h @@ -106,6 +106,9 @@ t_CKBOOL is_absolute_path( const std::string & path ); // split "x:y:z"-style path list into {"x","y","z"} void parse_path_list( std::string & str, std::list & lst ); +// generate auto filename (usually with date-time) with file prefix and extension +std::string autoFilename( const std::string & prefix, const std::string & extension ); + // test whether a filename ends in a particular extension t_CKBOOL extension_matches( const std::string & filename, const std::string & extension, diff --git a/src/scripts/ckdoc/gen-all.ck b/src/scripts/ckdoc/gen-all.ck index 373778e51..6b95c6f0d 100644 --- a/src/scripts/ckdoc/gen-all.ck +++ b/src/scripts/ckdoc/gen-all.ck @@ -102,7 +102,7 @@ doc.addGroup( // add group doc.addGroup( [ "UAna", "UAnaBlob", "Centroid", "Chroma", "Flux", "Kurtosis", "MFCC", "RMS", "RollOff", "SFM", "ZeroX", - "AutoCorr", "DCT", "FeatureCollector", "FFT", "Flip", "IDCT", "IFFT", "UnFlip", "XCorr" ], + "AutoCorr", "DCT", "FeatureCollector", "FFT", "Flip", "IDCT", "IFFT", "UnFlip", "XCorr", "Windowing" ], // group name "Unit Analyzers", // file name From 758d1945504f1408d3c7be8664e27973b4d5e3a9 Mon Sep 17 00:00:00 2001 From: Ge Wang Date: Sat, 7 Oct 2023 13:41:17 -0700 Subject: [PATCH 26/26] release notes; rename API->vm->remove_all_shreds --- VERSIONS | 105 +++++++++++++++++++++++++++++++++++++++--- src/core/chuck_dl.cpp | 8 ++-- src/core/chuck_dl.h | 2 +- 3 files changed, 103 insertions(+), 12 deletions(-) diff --git a/VERSIONS b/VERSIONS index d81fc7df0..addcdf003 100644 --- a/VERSIONS +++ b/VERSIONS @@ -2,7 +2,7 @@ ChucK VERSIONS log ------------------ -1.5.1.5 (October 2023) "operator overloading" +1.5.1.5 (October 2023) "operator overloading + chugins API 9.0" ======= - (added) operator overloading in language; most operator can now be overloaded, within their respective existing @@ -108,6 +108,24 @@ ChucK VERSIONS log Get the operand stack size hint (in bytes) for shreds sporked from this one. ---- +- (added) FileIO.open() now takes "special:auto" as the filename (output + only) to write to a new file with auto-generated filename in the + current directory (based on the current system time, precise to + second;NOTE files created into way at the same system time will have + the same auto-generated filename and may conflict or fail to open). + The "auto" prefix and extension can be set and retrieved using the + following new functions to FileIO: + --- + string autoExtension(); + Get auto extension for "special:auto" filename generation + (applicable to file writing only). + string autoPrefix(); + Get auto prefix for "special:auto" filename generation + (applicable to file writing only). + void autoPrefixExtension( string prefix, string extension ); + Set auto prefix and extension for "special:auto" filename + generation (applicable to file writing only). + --- - (fixed) float *=> vec4 now works as intended (instead of producing a a compilation error) - (fixed) on Windows and --verbose level SYSTEM or higher, when a chugin @@ -122,6 +140,12 @@ ChucK VERSIONS log up file descriptors and leading to instability - (updated) ConsoleInput.prompt( text ) now no longer prints an extra space (" ") after prompt text +- (updated) chugins headers version incremented to 9.0 +- (added; chugins development) overhauled dyanmic linking API to access + chuck host-side operations; this greatly expands chugins capabilities + but will unfortunately require API changes that will break chugin + builds that uses the existing API. + (check out chuck_dl.h: `namespace Chuck_DL_Api`) - (added; chugins development) ability to overload operators from chugin query functions in C++: // add binary operator overload; args included @@ -139,12 +163,79 @@ ChucK VERSIONS log Chuck_DL_Return API->vm->invoke_mfun_immediate_mode( Chuck_Object * obj, t_CKUINT func_vt_offset, Chuck_VM * vm, Chuck_VM_Shred * shred, Chuck_DL_Arg * ARGS, t_CKUINT numArgs ); -- (added; chugins development) overhauled dyanmic linking API to access - chuck host-side operations; this greatly expands chugins capabilities - but will unfortunately require API changes that will break chugin - builds that uses the existing API. - (check out chuck_dl.h: `namespace Chuck_DL_Api`) -- (updated) chugins headers version incremented to 9.0 +- (added; chugins development) new API->type API for C++/chugins to + lookup types in the type system, virtual function offsets (useful + for API->vm->invoke_mfun_immediate_mode() above) +- (added and updated; chugins development) across all existing + chugins DL API and many additions; the chugins runtime API 9.0 + ============================= + // C++ chugins runtime API for VM access (access from chugins using API->vm->...) + // get sample rate | 1.5.1.4 + t_CKUINT srate( Chuck_VM * vm ); + // get chuck now | 1.5.1.4 + t_CKTIME now( Chuck_VM * vm ); + // create a new lock-free one-producer, one-consumer buffer | 1.5.1.4 + CBufferSimple * create_event_buffer( Chuck_VM * vm ); + // queue an event; num_msg must be 1; buffer should be created using create_event_buffer() above | 1.5.1.4 + t_CKBOOL queue_event( Chuck_VM * vm, Chuck_Event * event, t_CKINT num_msg, CBufferSimple * buffer ); + // invoke Chuck_Object member function (defined either in chuck or c++) | 1.5.1.4 (ge & andrew) + // NOTE this will call the member function in IMMEDIATE MODE, + // marking it as a time-critical function when called in this manner; + // any time/event operations therein will throw an exception + Chuck_DL_Return invoke_mfun_immediate_mode( Chuck_Object * obj, t_CKUINT func_vt_offset, + Chuck_VM * vm, Chuck_VM_Shred * shred, Chuck_DL_Arg * ARGS, t_CKUINT numArgs ); + // throw an exception; if shred is passed in, it will be halted + void throw_exception( const char * exception, const char * desc, Chuck_VM_Shred * shred ); + // log a message in the chuck logging system + void em_log( t_CKINT level, const char * text ); + // system function: remove all shreds in VM; use with care + void remove_all_shreds( Chuck_VM * vm ); + -------------------------------- + // C++ chugins runtime API for object access (access using API->object->...) + // function pointer get_type() + Type get_type( Object object ); + // add reference count + void add_ref( Object object ); + // release reference count + void release( Object object ); + // get reference count + t_CKUINT refcount( Object object ); + // instantiating and initializing a ChucK object by type, with reference to a parent shred + // if addRef == TRUE the newly created object will have a reference count of 1; otherwise 0 + // NOTE set addRef to TRUE if you intend to keep a reference of the newly created object around + // NOTE set addRref to FALSE if the created object is to be returned without keeping a reference around + Object create( Chuck_VM_Shred *, Type type, t_CKBOOL addRef ); + // instantiating and initializing a ChucK object by type, with no reference to a parent shred + // if addRef == TRUE the newly created object will have a reference count of 1; otherwise 0 + Object create_without_shred( Chuck_VM *, Type type, t_CKBOOL addRef ); + // instantiate and initialize a ChucK string by type + // if addRef == TRUE the newly created object will have a reference count of 1; otherwise 0 + String create_string( Chuck_VM *, const char * value, t_CKBOOL addRef ); + // function pointers for get_mvar_*() + t_CKBOOL get_mvar_int( Object object, const char * name, t_CKINT & value ); + t_CKBOOL get_mvar_float( Object object, const char * name, t_CKFLOAT & value ); + t_CKBOOL get_mvar_dur( Object object, const char * name, t_CKDUR & value ); + t_CKBOOL get_mvar_time( Object object, const char * name, t_CKTIME & value ); + t_CKBOOL get_mvar_string( Object object, const char * name, String & value ); + t_CKBOOL get_mvar_object( Object object, const char * name, Object & value ); + // function pointer for set_string() + t_CKBOOL set_string( String string, const char * value ); + // array_int operations + t_CKBOOL array_int_size( ArrayInt array, t_CKINT & value ); + t_CKBOOL array_int_push_back( ArrayInt array, t_CKUINT value ); + t_CKBOOL array_int_get_idx( ArrayInt array, t_CKINT idx, t_CKUINT & value ); + t_CKBOOL array_int_get_key( ArrayInt array, const std::string & key, t_CKUINT & value ); + -------------------------------- + // C++ chugins runtime API for type access (new; access using API->type->...) + // function pointer get_type() + Type lookup( Chuck_VM *, const char * name ); + // function pointer for get_vtable_offset(); returns < 0 if not found + t_CKINT get_vtable_offset( Chuck_VM *, Type type, const char * value ); + // test if two chuck types are equal + t_CKBOOL is_equal(Type lhs, Type rhs); + // test if lhs is a type of rhs (e.g., SinOsc is a type of UGen) + t_CKBOOL isa(Type lhs, Type rhs); + ============================= 1.5.1.3 (September 2023) "ChucK to School" diff --git a/src/core/chuck_dl.cpp b/src/core/chuck_dl.cpp index 0f3514f60..2846c3b84 100644 --- a/src/core/chuck_dl.cpp +++ b/src/core/chuck_dl.cpp @@ -66,7 +66,7 @@ char g_chugin_path_envvar[] = "CHUCK_CHUGIN_PATH"; void CK_DLL_CALL ck_add_arg( Chuck_DL_Query * query, const char * type, const char * name ); void CK_DLL_CALL ck_throw_exception( const char * exception, const char * desc, Chuck_VM_Shred * shred ); void CK_DLL_CALL ck_em_log( t_CKINT level, const char * text ); -void CK_DLL_CALL ck_system_remove_all_shreds( Chuck_VM * vm ); +void CK_DLL_CALL ck_remove_all_shreds( Chuck_VM * vm ); Chuck_DL_Api::Type CK_DLL_CALL ck_type_lookup( Chuck_VM * vm, const char * name ); t_CKBOOL CK_DLL_CALL ck_type_isequal( Chuck_Type * lhs, Chuck_Type * rhs ); t_CKBOOL CK_DLL_CALL ck_type_isa( Chuck_Type * lhs, Chuck_Type * rhs ); @@ -1912,7 +1912,7 @@ queue_event(ck_queue_event), invoke_mfun_immediate_mode(ck_invoke_mfun_immediate_mode), throw_exception(ck_throw_exception), em_log(ck_em_log), -system_remove_all_shreds(ck_system_remove_all_shreds) +remove_all_shreds(ck_remove_all_shreds) { } @@ -2056,10 +2056,10 @@ void CK_DLL_CALL ck_em_log( t_CKINT level, const char * text ) //----------------------------------------------------------------------------- -// name: ck_system_remove_all_shreds() +// name: ck_remove_all_shreds() // desc: host impl for system function: remove all shreds in VM; use with care //----------------------------------------------------------------------------- -void CK_DLL_CALL ck_system_remove_all_shreds( Chuck_VM * vm ) +void CK_DLL_CALL ck_remove_all_shreds( Chuck_VM * vm ) { // construct chuck msg (must allocate on heap, as VM will clean up) Chuck_Msg * msg = new Chuck_Msg(); diff --git a/src/core/chuck_dl.h b/src/core/chuck_dl.h index af567b406..f16671ea4 100644 --- a/src/core/chuck_dl.h +++ b/src/core/chuck_dl.h @@ -849,7 +849,7 @@ struct Api // log a message in the chuck logging system void (CK_DLL_CALL * const em_log)( t_CKINT level, const char * text ); // system function: remove all shreds in VM; use with care - void (CK_DLL_CALL * const system_remove_all_shreds)( Chuck_VM * vm ); + void (CK_DLL_CALL * const remove_all_shreds)( Chuck_VM * vm ); } * const vm; // api to access host-side ChucK objects