From 2ce048e35d222ef36a5d95e7b4c4867bfe020ffe Mon Sep 17 00:00:00 2001 From: Ge Wang Date: Sat, 25 Nov 2023 00:58:30 -0800 Subject: [PATCH] DL query API cleanup; add query set/get info; bump API version to 10.1 --- VERSIONS | 4 +- src/core/chuck.cpp | 6 +- src/core/chuck_dl.cpp | 192 ++++++++++++++++++++++----------- src/core/chuck_dl.h | 229 +++++++++++++++++++++++++--------------- src/core/chuck_type.cpp | 40 +++---- src/core/chuck_type.h | 4 +- src/core/ulib_std.cpp | 4 - 7 files changed, 303 insertions(+), 176 deletions(-) diff --git a/VERSIONS b/VERSIONS index 6aa3eb528..d64d17e7b 100644 --- a/VERSIONS +++ b/VERSIONS @@ -48,13 +48,15 @@ new Foo(10,11,12) @=> Foo @ f4; ================== chugins API update ================== -- (updated) chugin API version updated to 10.0 +- (updated) chugin API version updated to 10.x -- complete decoupling of chugins interface and chuck core implementation details -- new chugins runtime API functions to provide access to chuck core operations that is safe across the shared/dynamic library boudaries between chugins and a chuck host (see Chuck_DL_Api in chuck_dl.h for details) +- (updated) chugin AND host API version must now match + (previously only the major version must match) - (updated) all chugins can now include a single header `chugin.h` with no additional header dependencies [see: https://github.com/ccrma/cheaders/tree/main/include] diff --git a/src/core/chuck.cpp b/src/core/chuck.cpp index a6533b5ba..39ee997b5 100644 --- a/src/core/chuck.cpp +++ b/src/core/chuck.cpp @@ -837,8 +837,10 @@ void ChucK::probeChugins() // push EM_pushlog(); // print host version - EM_log( CK_LOG_SYSTEM, "chugin major version must == host major version" ); - EM_log( CK_LOG_SYSTEM, "chugin minor version must <= host major version" ); + EM_log( CK_LOG_SYSTEM, "note: chugin API version must match that of host" ); // 1.5.2.0 + // previously: + // EM_log( CK_LOG_SYSTEM, "chugin major version must == host major version" ); + // EM_log( CK_LOG_SYSTEM, "chugin minor version must <= host major version" ); // pop EM_poplog(); diff --git a/src/core/chuck_dl.cpp b/src/core/chuck_dl.cpp index db37a1f2e..46ccd0a08 100644 --- a/src/core/chuck_dl.cpp +++ b/src/core/chuck_dl.cpp @@ -72,6 +72,9 @@ CK_DL_API CK_DLL_CALL ck_get_api( Chuck_DL_Query * query ); Chuck_Env * CK_DLL_CALL ck_get_env( Chuck_DL_Query * query ); Chuck_Compiler * CK_DLL_CALL ck_get_compiler( Chuck_DL_Query * query ); Chuck_Carrier * CK_DLL_CALL ck_get_carrier( Chuck_DL_Query * query ); +void CK_DLL_CALL ck_setname( Chuck_DL_Query * query, const char * name, t_CKBOOL attendSpecial ); +void CK_DLL_CALL ck_setinfo( Chuck_DL_Query * query, const char * key, const char * value, t_CKBOOL attendSpecial ); +const char * CK_DLL_CALL ck_getinfo( Chuck_DL_Query * query, const char * key ); 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 ); @@ -101,12 +104,72 @@ t_CKUINT CK_DLL_CALL ck_builtin_declversion() { return CK_DLL_VERSION; } //----------------------------------------------------------------------------- // name: ck_setname() -// desc: set the name of the module +// desc: set the name of the module/chugin //----------------------------------------------------------------------------- -void CK_DLL_CALL ck_setname( Chuck_DL_Query * query, const char * name ) +void CK_DLL_CALL ck_setname( Chuck_DL_Query * query, const char * name, t_CKBOOL attendSpecial ) { // set the name - query->dll_name = name; + query->dll_name = name ? name : "[no name]"; + // also set in info, but attendSpecial=FALSE to avoid infinite recursion + if( attendSpecial ) ck_setinfo( query, CHUGIN_INFO_NAME, name, FALSE ); +} +// overload to get around function pointer business for f_setname +void CK_DLL_CALL ck_setname( Chuck_DL_Query * query, const char * name ) +{ ck_setname( query, name, TRUE ); } + + + +//----------------------------------------------------------------------------- +// name: ck_setinfo() | 1.5.2.0 +// desc: set info (by key) of the module/chugin +//----------------------------------------------------------------------------- +void CK_DLL_CALL ck_setinfo( Chuck_DL_Query * query, const char * key, const char * value, t_CKBOOL attendSpecial ) +{ + // check for null key + if( !key ) return; + + // check for null value + if( !value ) + { + // check for presence of entry + if( query->dll_info.find( key ) != query->dll_info.end() ) + { + // erase the entry + query->dll_info.erase( key ); + } + } + else + { + // add or update it + query->dll_info[key] = value; + } + + // check for special keys + if( attendSpecial ) + { + // also set name, but attendSpecial=FALSE to avoid infinite recursion + if( string(key) == CHUGIN_INFO_NAME ) ck_setname( query, value, FALSE ); + } +} +// overload to get around function pointer business for f_setinfo +void CK_DLL_CALL ck_setinfo( Chuck_DL_Query * query, const char * key, const char * value ) +{ ck_setinfo( query, key, value, TRUE ); } + + + + +//----------------------------------------------------------------------------- +// name: ck_geinfo() | 1.5.2.0 +// desc: get info (by key) of the module/chugin +//----------------------------------------------------------------------------- +const char * CK_DLL_CALL ck_getinfo( Chuck_DL_Query * query, const char * key ) +{ + // check for null key + if( !key ) return ""; + // check for presence of entry + if( query->dll_info.find( key ) == query->dll_info.end() ) return ""; + // return + return query->dll_info[key].c_str(); } @@ -179,6 +242,7 @@ void CK_DLL_CALL ck_begin_class( Chuck_DL_Query * query, const char * name, cons // curr query->curr_class = c; query->curr_func = NULL; + query->curr_var = NULL; // 1.5.2.0 } @@ -208,6 +272,7 @@ void CK_DLL_CALL ck_add_ctor( Chuck_DL_Query * query, f_ctor ctor ) // add query->curr_class->ctors.push_back( f ); query->curr_func = f; + query->curr_var = NULL; // 1.5.2.0 } @@ -244,8 +309,8 @@ void CK_DLL_CALL ck_add_dtor( Chuck_DL_Query * query, f_dtor dtor ) // add query->curr_class->dtor = f; - // set query->curr_func = NULL; + query->curr_var = NULL; // 1.5.2.0 } @@ -276,6 +341,7 @@ void CK_DLL_CALL ck_add_mfun( Chuck_DL_Query * query, f_mfun addr, // add query->curr_class->mfuns.push_back( f ); query->curr_func = f; + query->curr_var = NULL; // 1.5.2.0 } @@ -306,6 +372,7 @@ void CK_DLL_CALL ck_add_sfun( Chuck_DL_Query * query, f_sfun addr, // add query->curr_class->sfuns.push_back( f ); query->curr_func = f; + query->curr_var = NULL; // 1.5.2.0 } @@ -335,7 +402,7 @@ void CK_DLL_CALL ck_add_op_overload_binary( Chuck_DL_Query * query, f_gfun addr, f->type = type; f->gfun = addr; f->fpKind = ae_fp_gfun; // 1.5.2.0 - f->opOverloadKind = te_op_overload_binary; + f->opOverloadKind = ckte_op_overload_BINARY; f->op2overload = op; // add @@ -379,7 +446,7 @@ void CK_DLL_CALL ck_add_op_overload_prefix( Chuck_DL_Query * query, f_gfun addr, f->type = type; f->gfun = addr; f->fpKind = ae_fp_gfun; // 1.5.2.0 - f->opOverloadKind = te_op_overload_unary_pre; + f->opOverloadKind = ckte_op_overload_UNARY_PRE; f->op2overload = op; // add @@ -418,7 +485,7 @@ void CK_DLL_CALL ck_add_op_overload_postfix( Chuck_DL_Query * query, f_gfun addr f->type = type; f->gfun = addr; f->fpKind = ae_fp_gfun; // 1.5.2.0 - f->opOverloadKind = te_op_overload_unary_post; + f->opOverloadKind = ckte_op_overload_UNARY_POST; f->op2overload = op; // add @@ -480,7 +547,7 @@ t_CKUINT CK_DLL_CALL ck_add_mvar( Chuck_DL_Query * query, // add query->curr_class->mvars.push_back( v ); query->curr_func = NULL; - query->last_var = v; + query->curr_var = v; t_CKUINT offset = query->curr_class->current_mvar_offset; query->curr_class->current_mvar_offset = type_engine_next_offset( query->curr_class->current_mvar_offset, @@ -517,8 +584,7 @@ void CK_DLL_CALL ck_add_svar( Chuck_DL_Query * query, const char * type, const c // add query->curr_class->svars.push_back( v ); query->curr_func = NULL; - - query->last_var = v; + query->curr_var = v; } @@ -774,13 +840,11 @@ void CK_DLL_CALL ck_unregister_shreds_watcher( Chuck_DL_Query * query, f_shreds_ //----------------------------------------------------------------------------- t_CKBOOL CK_DLL_CALL ck_doc_class( Chuck_DL_Query * query, const char * doc ) { -// #ifdef CK_DOC // disable unless CK_DOC - if(query->curr_class) - query->curr_class->doc = doc; - else - return FALSE; -// #endif // CK_DOC - + // if no current class + if( !query->curr_class ) return FALSE; + // set it + query->curr_class->doc = doc; + // done return TRUE; } @@ -791,13 +855,11 @@ t_CKBOOL CK_DLL_CALL ck_doc_class( Chuck_DL_Query * query, const char * doc ) //----------------------------------------------------------------------------- t_CKBOOL CK_DLL_CALL ck_add_example( Chuck_DL_Query * query, const char * ex ) { -// #ifdef CK_DOC // disable unless CK_DOC - if(query->curr_class) - query->curr_class->examples.push_back(ex); - else - return FALSE; -// #endif // CK_DOC - + // if no current class + if( !query->curr_class ) return FALSE; + // append it + query->curr_class->examples.push_back(ex); + // done return TRUE; } @@ -805,11 +867,11 @@ t_CKBOOL CK_DLL_CALL ck_add_example( Chuck_DL_Query * query, const char * ex ) // set current function documentation t_CKBOOL CK_DLL_CALL ck_doc_func( Chuck_DL_Query * query, const char * doc ) { - if(query->curr_func) - query->curr_func->doc = doc; - else - return FALSE; - + // if no current function + if( !query->curr_func ) return FALSE; + // set it + query->curr_func->doc = doc; + // done return TRUE; } @@ -817,18 +879,17 @@ t_CKBOOL CK_DLL_CALL ck_doc_func( Chuck_DL_Query * query, const char * doc ) // set last mvar documentation t_CKBOOL CK_DLL_CALL ck_doc_var( Chuck_DL_Query * query, const char * doc ) { -// #ifdef CK_DOC // disable unless CK_DOC - if(query->last_var) - query->last_var->doc = doc; - else - return FALSE; -// #endif // CK_DOC - + // if no current var + if( !query->curr_var ) return FALSE; + // set it + query->curr_var->doc = doc; + // done return TRUE; } + //------------------------------------------------------------------------------ // alternative functions to make stuff //------------------------------------------------------------------------------ @@ -968,8 +1029,10 @@ const Chuck_DL_Query * Chuck_DLL::query() m_apiVersionMinor = CK_DLL_VERSION_GETMINOR(dll_version); // is version ok t_CKBOOL version_ok = FALSE; - // major version must be same; minor version must less than or equal - if( m_apiVersionMajor == CK_DLL_VERSION_MAJOR && m_apiVersionMinor <= CK_DLL_VERSION_MINOR) + // major AND minor version must match | 1.5.2.0 (ge) + // (was: major version must be same; minor version must less than or equal) + if( m_apiVersionMajor == CK_DLL_VERSION_MAJOR && + m_apiVersionMinor == CK_DLL_VERSION_MINOR) version_ok = TRUE; // if version not okay @@ -1258,18 +1321,20 @@ t_CKBOOL Chuck_DLL::compatible() { // probe dll if( !this->probe() ) return FALSE; - // major version must be same between chugin and host - // chugin minor version must less than or equal host minor version - if( m_apiVersionMajor == CK_DLL_VERSION_MAJOR && m_apiVersionMinor <= CK_DLL_VERSION_MINOR ) - { return TRUE; } - else { - m_last_error = string("incompatible API version: chugin (") - + ck_itoa(m_apiVersionMajor) + "." + ck_itoa(m_apiVersionMinor) - + string(") vs. host (") - + ck_itoa(CK_DLL_VERSION_MAJOR) + "." + ck_itoa(CK_DLL_VERSION_MINOR) - + ")"; - return FALSE; - } + // major AND minor version must match | 1.5.2.0 (ge) + // (was: major version must be same between chugin and host, and + // chugin minor version must less than or equal host minor version) + if( m_apiVersionMajor == CK_DLL_VERSION_MAJOR && + m_apiVersionMinor == CK_DLL_VERSION_MINOR ) return TRUE; + + // error string + m_last_error = string("incompatible API version: chugin (") + + ck_itoa(m_apiVersionMajor) + "." + ck_itoa(m_apiVersionMinor) + + string(") vs. host (") + + ck_itoa(CK_DLL_VERSION_MAJOR) + "." + ck_itoa(CK_DLL_VERSION_MINOR) + + ")"; + // done + return FALSE; } @@ -1282,12 +1347,10 @@ t_CKBOOL Chuck_DLL::compatible() Chuck_DL_Query::Chuck_DL_Query( Chuck_Carrier * carrier, Chuck_DLL * dll ) { // set the pointers to functions so the module can call - get_vm = ck_get_vm; - get_api = ck_get_api; - get_env = ck_get_env; - get_compiler = ck_get_compiler; - get_carrier = ck_get_carrier; + ck_vm = ck_get_vm; + ck_api = ck_get_api; setname = ck_setname; + setinfo = ck_setinfo; begin_class = ck_begin_class; add_ctor = ck_add_ctor; add_dtor = ck_add_dtor; @@ -1314,8 +1377,7 @@ Chuck_DL_Query::Chuck_DL_Query( Chuck_Carrier * carrier, Chuck_DLL * dll ) m_carrier = carrier; dll_ref = dll; // 1.5.1.3 (ge) added - dll_name = "[noname]"; - reserved = NULL; + dll_name = "[no name]"; curr_class = NULL; curr_func = NULL; // memset(reserved2, NULL, sizeof(void*)*RESERVED_SIZE); @@ -1332,11 +1394,10 @@ Chuck_DL_Query::Chuck_DL_Query( Chuck_Carrier * carrier, Chuck_DLL * dll ) // (instead of default sample rate, which could be harder to notice / debug) srate = 0; } - // get DL API reference | 1.5.1.5 m_api = Chuck_DL_Api::instance(); - linepos = 0; + // clear error flag errorEncountered = FALSE; } @@ -1349,14 +1410,17 @@ Chuck_DL_Query::Chuck_DL_Query( Chuck_Carrier * carrier, Chuck_DLL * dll ) //----------------------------------------------------------------------------- void Chuck_DL_Query::clear() { - // set to 0 - dll_name = "[noname]"; - // line pos - linepos = 0; + // set to no name + dll_name = "[no name]"; + // delete classes for( t_CKUINT i = 0; i < classes.size(); i++ ) CK_SAFE_DELETE( classes[i] ); + // delete operator overloads + for( t_CKUINT i = 0; i < op_overloads.size(); i++ ) CK_SAFE_DELETE( op_overloads[i] ); + // clear classes.clear(); + op_overloads.clear(); } @@ -1397,7 +1461,7 @@ Chuck_DL_Func::~Chuck_DL_Func() // clear args.clear(); // zero - opOverloadKind = te_op_overload_none; + opOverloadKind = ckte_op_overload_NONE; op2overload = ae_op_none; } diff --git a/src/core/chuck_dl.h b/src/core/chuck_dl.h index 79b413235..b3c3a72d4 100644 --- a/src/core/chuck_dl.h +++ b/src/core/chuck_dl.h @@ -37,13 +37,15 @@ // authors: Ge Wang (ge@ccrma.stanford.edu | gewang@cs.princeton.edu) // Ari Lazier (alazier@cs.princeton.edu) // Spencer Salazar (spencer@ccrma.stanford.edu) +// macOS code based on apple's open source // -// macOS code based on apple's open source -// -// date: spring 2004 - 1.1 +// date: spring 2004 - 1.1 - internal modules interface // spring 2005 - 1.2 // ... +// circa 2013 - support for chugins +// ... // summer 2023 - chugins DL api v9 +// fall 2023 - transition to single-header `chugin.h` | 1.5.2.0 // fall 2023 - chugins DL api v10 //----------------------------------------------------------------------------- #ifndef __CHUCK_DL_H__ @@ -53,13 +55,14 @@ #include "chuck_absyn.h" #include #include +#include -// major version must be the same between chuck:chugin -// v10.0 -- transition to single-header `chugin.h` | 1.5.2.0 +// major and minor must be the same between chuck:chugin +// major version: significant semantic and/or API update #define CK_DLL_VERSION_MAJOR (10) -// minor version of chugin must be less than or equal to chuck's -#define CK_DLL_VERSION_MINOR (0) +// minor version: revisions +#define CK_DLL_VERSION_MINOR (1) #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) @@ -360,8 +363,12 @@ typedef Chuck_Env * (CK_DLL_CALL * f_get_env)( Chuck_DL_Query * query ); typedef Chuck_Compiler * (CK_DLL_CALL * f_get_compiler)( Chuck_DL_Query * query ); typedef Chuck_Carrier * (CK_DLL_CALL * f_get_carrier)( Chuck_DL_Query * query ); -// set name of ckx +// set name of module / chugin typedef void (CK_DLL_CALL * f_setname)( Chuck_DL_Query * query, const char * name ); +// set info of module / chugin by (key,value) +typedef void (CK_DLL_CALL * f_setinfo)( Chuck_DL_Query * query, const char * key, const char * value ); +// set info of module / chugin by (key,value) +typedef const char * (CK_DLL_CALL * f_getinfo)( Chuck_DL_Query * query, const char * key ); // begin class/namespace, can be nested typedef void (CK_DLL_CALL * f_begin_class)( Chuck_DL_Query * query, const char * name, const char * parent ); @@ -417,9 +424,15 @@ typedef t_CKBOOL (CK_DLL_CALL * f_doc_func)( Chuck_DL_Query * query, const char // set last mvar documentation typedef t_CKBOOL (CK_DLL_CALL * f_doc_var)( Chuck_DL_Query * query, const char * doc ); +} // end extern "C" + + + + //----------------------------------------------------------------------------- -// shreds watcher flags; meant to bitwise-OR together in options -// these will also be passed back to the callback... +// name: enum ckvm_ShredsWatcherFlag | 1.5.1.5 (ge & andrew) added +// desc: 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, @@ -443,37 +456,77 @@ typedef enum { ckte_origin_GENERATED // generated (e.g., array types like int[][][][]) } ckte_Origin; -} // end extern "C" +//----------------------------------------------------------------------------- +// name: enum ckte_Op_OverloadKind | 1.5.1.5 (ge) added +// desc: enumeration for kinds of operator overload +//----------------------------------------------------------------------------- +typedef enum +{ + ckte_op_overload_NONE, + ckte_op_overload_BINARY, // LHS op RHS + ckte_op_overload_UNARY_PRE, // op RHS + ckte_op_overload_UNARY_POST // LHS op +} ckte_Op_OverloadKind; + +//----------------------------------------------------------------------------- +// key strings for QUERY->setname(...) and QUERY->getinfo(...) +//----------------------------------------------------------------------------- +#define CHUGIN_INFO_NAME "CHUGIN_INFO_NAME" // same as QUERY->setname() +#define CHUGIN_INFO_AUTHORS "CHUGIN_INFO_AUTHORS" +#define CHUGIN_INFO_CHUGIN_VERSION "CHUGIN_INFO_CHUGIN_VERSION" +#define CHUGIN_INFO_DESCRIPTION "CHUGIN_INFO_DESCRIPTION" +#define CHUGIN_INFO_URL "CHUGIN_INFO_URL" +#define CHUGIN_INFO_ID "CHUGIN_INFO_ID" +#define CHUGIN_INFO_EXTRA "CHUGIN_INFO_EXTRA" //----------------------------------------------------------------------------- // name: struct Chuck_DL_Query -// desc: passed to module +// desc: data structure passed from chuck host to chugin to query its contents: +// include 1) chugin/module info; 2) classes and operator-overloadings +// to add to chuck's type system; 3) the chugin can also use the query +// to get data from from the host, including VM / host sample rate, and +// a Chuck_DL_Api handle for accessing the chugin-to-host runtime DL API //----------------------------------------------------------------------------- struct Chuck_DL_Query { +//------------------------------------------------------------------------- +// function pointers: to be called from CHUGIN / module +//------------------------------------------------------------------------- public: - // function pointers - to be called from client module - // Chuck_VM * vm = QUERY->get_vm( QUERY ); - // Chuck_VM * api = QUERY->get_api( QUERY ); - // - // get_vm(), get_api(), etc. - // REFACTOR-2017: get compiler, vm, etc. asoociated with the QUERY - f_get_vm get_vm; - f_get_api get_api; - f_get_env get_env; - f_get_compiler get_compiler; - f_get_carrier get_carrier; + // ------------- + // functions for accessing useful host-side objects + // ------------- + // get Chuck_DL_Api for accessing chugin DL runtime API + // CK_DL_API api = QUERY->ck_api( QUERY ); + f_get_api ck_api; + // get a handle to host's VM + // Chuck_VM * vm = QUERY->ck_vm( QUERY ); + f_get_vm ck_vm; public: - // function pointers - to be called from client module - // QUERY->setname( QUERY, ... ); - // - // set the name of the module + // ------------- + // functions for registering chugin info such as name, author, URL, etc. + // ------------- + // set the name of the module, typically the name of the Chugin + // QUERY->setname( QUERY, "TheChuginName" ); f_setname setname; - // begin class/namespace, can be nexted + // set additional info by key | 1.5.2.0 (ge) added + // see CHUGIN_INFO_* above for info keys + // QUERY->setinfo( QUERY, key_cstring, value_cstring ); + f_setinfo setinfo; + // get info by key (do not keep returned pointer; always make a copy): + // see CHUGIN_INFO_* above for info keys + // std::string str = QUERY->setinfo( QUERY, key_cstring, value_cstring ); + f_getinfo getinfo; + +public: + // ------------- + // functions for creating new types in chuck's type system, from a chugin + // ------------- + // begin class/namespace, can be nested f_begin_class begin_class; // add constructor, can be followed by add_arg f_add_ctor add_ctor; @@ -497,19 +550,13 @@ struct Chuck_DL_Query f_add_ugen_funcf_auto_num_channels add_ugen_funcf_auto_num_channels; // (ugen only) add ctrl parameters // f_add_ugen_ctrl add_ugen_ctrl; // not used but needed for import for now - // end class/namespace, compile it + // end class/namespace; compile it f_end_class end_class; - // added 1.3.5 - Chuck_DL_Value * last_var; - f_doc_class doc_class; - f_doc_func doc_func; - f_doc_var doc_var; - f_add_example add_ex; - - // re-added 1.4.0.1 - f_create_main_thread_hook create_main_thread_hook; - +public: + // ------------- + // functions for overloading operators in the type system, from a chugin + // ------------- // 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 @@ -517,47 +564,70 @@ struct Chuck_DL_Query // add unary (postfix) operator overload; arg included f_add_op_overload_postfix add_op_overload_postfix; - // register shred notifcations | 1.5.1.5 (ge & andrew) +public: + // ------------- + // these are used to document functions and variables added above + // the are used for ckdoc generations and .help runtime help + // ------------- + f_doc_class doc_class; + f_doc_func doc_func; + f_doc_var doc_var; + f_add_example add_ex; + +public: + // ------------- + // register a function to be run on the main thread of chuck host + // * no more than ONE main thread hooks can be active + // * typically used by special chugins such as ChuGL or MAUI that + // deals with graphics or windowing | re-added 1.4.0.1 + // ------------- + f_create_main_thread_hook create_main_thread_hook; + +public: + // ------------- + // register callback to be invoked by chuck host at various + // stages of a shred's operation | 1.5.1.5 (ge & andrew) added + // * see `ckvm_ShredsWatcherFlag` enums + // ------------- + // register shred notifcations f_register_shreds_watcher register_shreds_watcher; - // un-register shred notifcations | 1.5.1.5 (ge & andrew) + // un-register shred notifcations f_unregister_shreds_watcher unregister_shreds_watcher; + +//------------------------------------------------------------------------- +// HOST ONLY beyond this point... +//------------------------------------------------------------------------- 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 + // NOTE: everything below std::anything cannot be reliably accessed by + // offset across DLL/shared-library boundaries, since std::anything could + // be variable size; + //------------------------------------------------------------------------- + // *** put everything to be accessed from chugins ABOVE this point! *** + //------------------------------------------------------------------------- + // * discovered by the vigilant and forever traumatized Jack Atherton, + // * fixed during REFACTOR-2017; warning by guilt-ridden Ge Wang //------------------------------------------------------------------------- - // dll + // DLL reference Chuck_DLL * dll_ref; - // reserved - void * reserved; - // sample rate - t_CKUINT srate; - // line pos - int linepos; // name of dll std::string dll_name; + // DL API reference | 1.5.1.5 + CK_DL_API m_api; + // info map | 1.5.2.0 + std::map dll_info; // current class Chuck_DL_Class * curr_class; // current function Chuck_DL_Func * curr_func; - // name - std::string name; - // collection of class + // current variable | added 1.3.5.0 + Chuck_DL_Value * curr_var; + // collection of classes std::vector classes; - // stack + // stack of classes std::vector stack; - - // flag any error encountered during the query | 1.5.0.5 (ge) added - t_CKBOOL errorEncountered; - - // DL API reference | 1.5.1.5 - CK_DL_API m_api; - // collection of operator overloads std::vector op_overloads; @@ -568,13 +638,21 @@ struct Chuck_DL_Query ~Chuck_DL_Query() { this->clear(); } // clear void clear(); - // access to various functions + +public: + // access to various functions: called from host Chuck_VM * vm() const; CK_DL_API api() const; Chuck_Env * env() const; Chuck_Compiler * compiler() const; Chuck_Carrier * carrier() const; +public: + // flag any error encountered during the query | 1.5.0.5 (ge) added + t_CKBOOL errorEncountered; + // host sample rate + t_CKUINT srate; + protected: // REFACTOR-2017: carrier ref Chuck_Carrier * m_carrier; @@ -663,21 +741,6 @@ struct Chuck_DL_Value -//----------------------------------------------------------------------------- -// name: enum te_Op_OverloadKind | 1.5.1.5 (ge) added -// desc: enumeration for kinds of operator overload -//----------------------------------------------------------------------------- -enum te_Op_OverloadKind -{ - te_op_overload_none, - te_op_overload_binary, // LHS op RHS - te_op_overload_unary_pre, // op RHS - te_op_overload_unary_post // LHS op -}; - - - - //----------------------------------------------------------------------------- // name: struct Chuck_DL_Func // desc: function from module @@ -697,14 +760,14 @@ struct Chuck_DL_Func // description std::string doc; // is this an operator overload? if so, which kind? | 1.5.1.5 - te_Op_OverloadKind opOverloadKind; + ckte_Op_OverloadKind opOverloadKind; // operator to overload | 1.5.1.5 ae_Operator op2overload; // constructor - Chuck_DL_Func() { ctor = NULL; fpKind = ae_fp_unknown; opOverloadKind = te_op_overload_none; op2overload = ae_op_none; } + Chuck_DL_Func() { ctor = NULL; fpKind = ae_fp_unknown; opOverloadKind = ckte_op_overload_NONE; op2overload = ae_op_none; } Chuck_DL_Func( const char * t, const char * n, t_CKUINT a, ae_FuncPointerKind kind ) - { name = n?n:""; type = t?t:""; addr = a; fpKind = kind; opOverloadKind = te_op_overload_none; op2overload = ae_op_none; } + { name = n?n:""; type = t?t:""; addr = a; fpKind = kind; opOverloadKind = ckte_op_overload_NONE; op2overload = ae_op_none; } // destructor ~Chuck_DL_Func(); // add arg diff --git a/src/core/chuck_type.cpp b/src/core/chuck_type.cpp index a86c3ba49..a974b4dad 100644 --- a/src/core/chuck_type.cpp +++ b/src/core/chuck_type.cpp @@ -8169,7 +8169,7 @@ a_Func_Def make_dll_as_fun( Chuck_DL_Func * dl_fun, // copy the operator overload info | 1.5.1.5 func_def->op2overload = dl_fun->op2overload; // set if unary postfix overload | 1.5.1.5 - func_def->overload_post = (dl_fun->opOverloadKind == te_op_overload_unary_post); + func_def->overload_post = (dl_fun->opOverloadKind == ckte_op_overload_UNARY_POST); return func_def; @@ -10473,11 +10473,11 @@ void Chuck_Op_Registry::reserve( Chuck_Type * lhs, ae_Operator op, Chuck_Type * if( overload ) { // check which kind - if( overload->kind() == te_op_overload_binary ) + if( overload->kind() == ckte_op_overload_BINARY ) EM_error3( "binary operator '%s' already overloaded on types '%s' and '%s' (or their parents)...", op2str(op), lhs->c_name(), rhs->c_name() ); - else if( overload->kind() == te_op_overload_unary_pre ) + else if( overload->kind() == ckte_op_overload_UNARY_PRE ) EM_error3( "unary (prefix) operator '%s' already overloaded on type '%s' (or its parent)...", op2str(op), rhs->c_name() ); - else if( overload->kind() == te_op_overload_unary_post ) + else if( overload->kind() == ckte_op_overload_UNARY_POST ) EM_error3( "unary (postfix) operator '%s' already overloaded on type '%s' (or its parent)...", op2str(op), lhs->c_name() ); else EM_error3( "(internal error) operator '%s' already overloaded...", op2str(op) ); @@ -10547,11 +10547,11 @@ t_CKBOOL Chuck_Op_Registry::add_overload( if( overload ) { // check which kind - if( overload->kind() == te_op_overload_binary ) + if( overload->kind() == ckte_op_overload_BINARY ) EM_error2( originWhere, "binary operator '%s' already overloaded on types '%s' and '%s' (or their parents)...", op2str(op), lhs->c_name(), rhs->c_name() ); - else if( overload->kind() == te_op_overload_unary_pre ) + else if( overload->kind() == ckte_op_overload_UNARY_PRE ) EM_error2( originWhere, "unary (prefix) operator '%s' already overloaded on type '%s' (or its parent)...", op2str(op), rhs->c_name() ); - else if( overload->kind() == te_op_overload_unary_post ) + else if( overload->kind() == ckte_op_overload_UNARY_POST ) EM_error2( originWhere, "unary (postfix) operator '%s' already overloaded on type '%s' (or its parent)...", op2str(op), lhs->c_name() ); else EM_error2( originWhere, "(internal error) operator '%s' already overloaded...", op2str(op) ); @@ -10827,10 +10827,10 @@ void Chuck_Op_Semantics::getOverloads( std::vector & Chuck_Op_Overload * Chuck_Op_Semantics::getOverload( Chuck_Type * lhs, Chuck_Type * rhs ) { // check which kind we are looking for - te_Op_OverloadKind kind = te_op_overload_none; - if( lhs && rhs ) kind = te_op_overload_binary; - else if( !lhs && rhs ) kind = te_op_overload_unary_pre; - else if( lhs && !rhs ) kind = te_op_overload_unary_post; + ckte_Op_OverloadKind kind = ckte_op_overload_NONE; + if( lhs && rhs ) kind = ckte_op_overload_BINARY; + else if( !lhs && rhs ) kind = ckte_op_overload_UNARY_PRE; + else if( lhs && !rhs ) kind = ckte_op_overload_UNARY_POST; else return NULL; // key @@ -10849,7 +10849,7 @@ Chuck_Op_Overload * Chuck_Op_Semantics::getOverload( Chuck_Type * lhs, Chuck_Typ if( overload->kind() != kind ) continue; // check - if( overload->kind() == te_op_overload_binary ) + if( overload->kind() == ckte_op_overload_BINARY ) { // verify assert( overload->lhs() != NULL ); @@ -10858,7 +10858,7 @@ Chuck_Op_Overload * Chuck_Op_Semantics::getOverload( Chuck_Type * lhs, Chuck_Typ if( isa(lhs,overload->lhs()) && isa(rhs,overload->rhs()) ) return overload; } - else if( overload->kind() == te_op_overload_unary_pre ) + else if( overload->kind() == ckte_op_overload_UNARY_PRE ) { // verify assert( it->second->rhs() != NULL ); @@ -10866,7 +10866,7 @@ Chuck_Op_Overload * Chuck_Op_Semantics::getOverload( Chuck_Type * lhs, Chuck_Typ if( isa(rhs,it->second->rhs()) ) return it->second; } - else if( overload->kind() == te_op_overload_unary_post ) + else if( overload->kind() == ckte_op_overload_UNARY_POST ) { // verify assert( it->second->lhs() != NULL ); @@ -10901,9 +10901,9 @@ Chuck_Op_Overload::Chuck_Op_Overload( Chuck_Type * LHS, ae_Operator op, Chuck_Ty // set op m_op = op; // set kind - if( LHS && RHS ) m_kind = te_op_overload_binary; - else if( !LHS && RHS ) m_kind = te_op_overload_unary_pre; - else if( LHS && !RHS ) m_kind = te_op_overload_unary_post; + if( LHS && RHS ) m_kind = ckte_op_overload_BINARY; + else if( !LHS && RHS ) m_kind = ckte_op_overload_UNARY_PRE; + else if( LHS && !RHS ) m_kind = ckte_op_overload_UNARY_POST; else { // error EM_error3( "(internal error) NULL lhs and rhs in Chuck_Op_Overload constructor..." ); @@ -10932,7 +10932,7 @@ Chuck_Op_Overload::Chuck_Op_Overload( Chuck_Type * LHS, ae_Operator op, Chuck_Fu // set op m_op = op; // set as postfix - m_kind = te_op_overload_unary_post; + m_kind = ckte_op_overload_UNARY_POST; // set func CK_SAFE_REF_ASSIGN( m_func, func ); // set lhs @@ -10954,7 +10954,7 @@ Chuck_Op_Overload::Chuck_Op_Overload( ae_Operator op, Chuck_Type * RHS, Chuck_Fu // set op m_op = op; // set as prefix - m_kind = te_op_overload_unary_pre; + m_kind = ckte_op_overload_UNARY_PRE; // set func CK_SAFE_REF_ASSIGN( m_func, func ); // set rhs @@ -11047,7 +11047,7 @@ t_CKBOOL Chuck_Op_Overload::isNative() const void Chuck_Op_Overload::zero() { m_op = ae_op_none; - m_kind = te_op_overload_none; + m_kind = ckte_op_overload_NONE; m_func = NULL; m_origin = ckte_origin_UNKNOWN; m_originWhere = 0; diff --git a/src/core/chuck_type.h b/src/core/chuck_type.h index c43bda167..75e8d0c25 100644 --- a/src/core/chuck_type.h +++ b/src/core/chuck_type.h @@ -582,7 +582,7 @@ struct Chuck_Op_Overload // the operator ae_Operator m_op; // which kind of overload? - te_Op_OverloadKind m_kind; + ckte_Op_OverloadKind m_kind; // the function to call Chuck_Func * m_func; // left hand side @@ -628,7 +628,7 @@ struct Chuck_Op_Overload // get op ae_Operator op() const { return m_op; } // get the kind of overload - te_Op_OverloadKind kind() const { return m_kind; } + ckte_Op_OverloadKind kind() const { return m_kind; } // get func Chuck_Func * func() const { return m_func; } // get left hand side type diff --git a/src/core/ulib_std.cpp b/src/core/ulib_std.cpp index 1b15b6495..bc0eb026f 100644 --- a/src/core/ulib_std.cpp +++ b/src/core/ulib_std.cpp @@ -170,10 +170,6 @@ DLL_QUERY libstd_query( Chuck_DL_Query * QUERY ) // set name QUERY->setname( QUERY, "Std" ); - /*! \example - std.rand2f( 100.0, 1000.0 ) => stdout; - */ - // register deprecate type_engine_register_deprecate( env, "std", "Std" );