History

apopros functions and apis

gewang committed 5 years ago

Commit 449ef401 parent 9967a047 files · +312 −76Browse files

Unified · Split

7 files
  1. src/core/chuck_dl.cpp +8 −8
  2. src/core/chuck_dl.h +12 −13
  3. src/core/chuck_lang.cpp +6 −6
  4. src/core/chuck_type.cpp +263 −41
  5. src/core/chuck_type.h +13 −3
  6. src/core/ugen_stk.cpp +0 −1
  7. src/core/ulib_machine.cpp +10 −4
src/core/chuck_dl.cpp+8−8
@@ -576,12 +576,12 @@ Chuck_DL_MainThreadHook * CK_DLL_CALL ck_create_main_thread_hook( Chuck_DL_Query · 575 unmodified lines
576576 //-----------------------------------------------------------------------------
577577 t_CKBOOL CK_DLL_CALL ck_doc_class( Chuck_DL_Query * query, const char * doc )
578578 {
579−#ifdef CK_DOC // disable unless CK_DOC
579+// #ifdef CK_DOC // disable unless CK_DOC
580580 if(query->curr_class)
581581 query->curr_class->doc = doc;
582582 else
583583 return FALSE;
584−#endif // CK_DOC
584+// #endif // CK_DOC
585585
586586 return TRUE;
587587 }
@@ -592,12 +592,12 @@ t_CKBOOL CK_DLL_CALL ck_doc_class( Chuck_DL_Query * query, const char * doc ) · 4 unmodified lines
592592 //-----------------------------------------------------------------------------
593593 t_CKBOOL CK_DLL_CALL ck_add_example( Chuck_DL_Query * query, const char * ex )
594594 {
595−#ifdef CK_DOC // disable unless CK_DOC
595+// #ifdef CK_DOC // disable unless CK_DOC
596596 if(query->curr_class)
597597 query->curr_class->examples.push_back(ex);
598598 else
599599 return FALSE;
600−#endif // CK_DOC
600+// #endif // CK_DOC
601601
602602 return TRUE;
603603 }
@@ -605,12 +605,12 @@ t_CKBOOL CK_DLL_CALL ck_add_example( Chuck_DL_Query * query, const char * ex ) · 1 unmodified line
605605 // set current function documentation
606606 t_CKBOOL CK_DLL_CALL ck_doc_func( Chuck_DL_Query * query, const char * doc )
607607 {
608−#ifdef CK_DOC // disable unless CK_DOC
608+// #ifdef CK_DOC // disable unless CK_DOC
609609 if(query->curr_func)
610610 query->curr_func->doc = doc;
611611 else
612612 return FALSE;
613−#endif // CK_DOC
613+// #endif // CK_DOC
614614
615615 return TRUE;
616616 }
@@ -618,12 +618,12 @@ t_CKBOOL CK_DLL_CALL ck_doc_func( Chuck_DL_Query * query, const char * doc ) · 1 unmodified line
618618 // set last mvar documentation
619619 t_CKBOOL CK_DLL_CALL ck_doc_var( Chuck_DL_Query * query, const char * doc )
620620 {
621−#ifdef CK_DOC // disable unless CK_DOC
621+// #ifdef CK_DOC // disable unless CK_DOC
622622 if(query->last_var)
623623 query->last_var->doc = doc;
624624 else
625625 return FALSE;
626−#endif // CK_DOC
626+// #endif // CK_DOC
627627
628628 return TRUE;
629629 }
src/core/chuck_dl.h+12−13
@@ -674,37 +674,36 @@ public: · 673 unmodified lines
674674 struct ObjectApi
675675 {
676676 ObjectApi();
677−
678677 private:
678+ // function pointer get_type()
679679 Type (* const get_type)( CK_DL_API, Chuck_VM_Shred *, std::string &name );
680−
680+ // function pointer create()
681681 Object (* const create)( CK_DL_API, Chuck_VM_Shred *, Type type );
682−
682+ // function pointer create_string()
683683 String (* const create_string)( CK_DL_API, Chuck_VM_Shred *, std::string &value );
684−
684+ // function pointers for get_mvar_*()
685685 t_CKBOOL (* const get_mvar_int)( CK_DL_API, Object object, std::string &name, t_CKINT &value );
686686 t_CKBOOL (* const get_mvar_float)( CK_DL_API, Object object, std::string &name, t_CKFLOAT &value );
687687 t_CKBOOL (* const get_mvar_dur)( CK_DL_API, Object object, std::string &name, t_CKDUR &value );
688688 t_CKBOOL (* const get_mvar_time)( CK_DL_API, Object object, std::string &name, t_CKTIME &value );
689689 t_CKBOOL (* const get_mvar_string)( CK_DL_API, Object object, std::string &name, String &value );
690690 t_CKBOOL (* const get_mvar_object)( CK_DL_API, Object object, std::string &name, Object &value );
691−
691+ // function pointer for set_string()
692692 t_CKBOOL (* const set_string)( CK_DL_API, String string, std::string &value );
693−
694693 } * const object;
695694
696695 Api() :
697− vm(new VMApi),
698− object(new ObjectApi)
699− {}
696+ vm(new VMApi),
697+ object(new ObjectApi)
698+ { }
700699
701700 private:
702− Api(Api &a) :
703− vm(a.vm),
704− object(a.object)
701+ Api( Api & a ) :
702+ vm(a.vm),
703+ object(a.object)
705704 { assert(0); };
706705
707− Api &operator=(Api &a) { assert(0); return a; }
706+ Api & operator=( Api & a ) { assert(0); return a; }
708707 };
709708 }
710709
src/core/chuck_lang.cpp+6−6
@@ -399,11 +399,11 @@ t_CKBOOL init_class_event( Chuck_Env * env, Chuck_Type * type ) · 398 unmodified lines
399399 func->doc = "signal all shreds that are waiting on this event.";
400400 if( !type_engine_import_mfun( env, func ) ) goto error;
401401
402− // add wait()
403− func = make_new_mfun( "void", "wait", event_wait );
404− func->add_arg( "Shred", "me" );
405− func->doc = "(currently unsupported)";
406− if( !type_engine_import_mfun( env, func ) ) goto error;
402+ // add wait() | commented out 1.4.0.2 (ge) -- it doesn't DO anything!!!
403+ // func = make_new_mfun( "void", "wait", event_wait );
404+ // func->add_arg( "Shred", "me" );
405+ // func->doc = "(currently unsupported; use Event => now to wait on event)";
406+ // if( !type_engine_import_mfun( env, func ) ) goto error;
407407
408408 // add can_wait()
409409 func = make_new_mfun( "int", "can_wait", event_can_wait );
@@ -954,7 +954,7 @@ t_CKBOOL init_class_array( Chuck_Env * env, Chuck_Type * type ) · 544 unmodified lines
954954 // ---------
955955 // add cap()
956956 func = make_new_mfun( "int", "cap", array_get_capacity_hack );
957− func->doc = "for historical/compatibilty reasons, this is the same as .size(); it is recommended to explicitly use .size() or .capacity().";
957+ func->doc = "(deprecated) For historical/compatibilty reasons, .cap() is always equal to .size(); instead of using .cap(), it is recommended to explicitly use .size() or .capacity().";
958958 if( !type_engine_import_mfun( env, func ) ) goto error;
959959
960960 // add capacity() // 1.4.0.2
src/core/chuck_type.cpp+263−41
@@ -37,6 +37,7 @@ · 36 unmodified lines
3737 #include "chuck_errmsg.h"
3838 #include "chuck_lang.h"
3939 #include "chuck_io.h"
40+#include "chuck_symbol.h"
4041 #include "util_string.h"
4142 #include "ugen_xxx.h"
4243
@@ -6649,19 +6650,105 @@ const char * Chuck_Type::c_name() · 6606 unmodified lines
66496650
66506651 //-----------------------------------------------------------------------------
66516652 // name: apropos()
6652−// desc: dump info to string
6653+// desc: dump info to string; added 1.4.0.2 (ge)
6654+// portions of this adapted from ckdoc -- thanks be to Spencer Salazar
66536655 //-----------------------------------------------------------------------------
66546656 void Chuck_Type::apropos( std::string & output )
66556657 {
66566658 // reset
66576659 output = "";
6660+ // line prefix
6661+ string PREFIX = ""; // [chuck]: ";
6662+
6663+ //-------------------------------------------------------------------------
6664+ // top level info: name, inheritane, description
6665+ //-------------------------------------------------------------------------
6666+ string outputTop;
6667+ // generate string
6668+ apropos_top( outputTop, PREFIX );
6669+
6670+ //-------------------------------------------------------------------------
6671+ // functions
6672+ //-------------------------------------------------------------------------
6673+ string outputFuncs;
6674+ // generate string
6675+ apropos_funcs( outputFuncs, PREFIX, TRUE );
6676+
6677+ //-------------------------------------------------------------------------
6678+ // variables
6679+ //-------------------------------------------------------------------------
6680+ string outputVars;
6681+ // generate string
6682+ // apropos_vars( outputVars, PREFIX, TRUE );
6683+
6684+ //-------------------------------------------------------------------------
6685+ // examples
6686+ //-------------------------------------------------------------------------
6687+ string outputExamples;
6688+ // generate string
6689+ // apropos_examples( outputExamples, PREFIX );
6690+
6691+ // done
6692+ output = outputTop + outputFuncs + outputVars + outputExamples;
6693+}
6694+
6695+
6696+
6697+
6698+//-----------------------------------------------------------------------------
6699+// name: apropos()
6700+// desc: dump info to console
6701+//-----------------------------------------------------------------------------
6702+void Chuck_Type::apropos()
6703+{
6704+ // the info
6705+ string output;
6706+ // get it
6707+ this->apropos( output );
6708+ // print it
6709+ CK_STDCERR << output << CK_STDENDL;
6710+}
6711+
6712+
6713+
6714+
6715+// comparer
6716+static bool comp_func( Chuck_Func * a, Chuck_Func * b )
6717+{ return a->name < b->name; }
6718+
6719+// comparer
6720+static bool comp_value( Chuck_Value * a, Chuck_Value * b )
6721+{ return a->name < b->name; }
6722+
6723+// capitalize first character
6724+static string capitalize( const string & s )
6725+{
6726+ // copy
6727+ string retval = s;
6728+ // if not empty and first character is a lower-case letter
6729+ if( retval.length() > 0 && retval[0] >= 'a' && retval[0] <= 'z' )
6730+ retval[0] -= 32;
6731+ // done
6732+ return retval;
6733+}
6734+
6735+
6736+
6737+
6738+//-----------------------------------------------------------------------------
6739+// name: apropos_top()
6740+// desc: dump top level info; added 1.4.0.2 (ge)
6741+//-----------------------------------------------------------------------------
6742+void Chuck_Type::apropos_top( std::string & output, const std::string & PREFIX )
6743+{
66586744 // make a string output stream
66596745 ostringstream sout;
66606746 // type
66616747 Chuck_Type * type = this;
6662− // line prefix
6663− string PREFIX = ""; // [chuck]: ";
66646748
6749+ //-------------------------------------------------------------------------
6750+ // top level info: name, inheritane, description
6751+ //-------------------------------------------------------------------------
66656752 // delimiter
66666753 sout << PREFIX;
66676754 for( int i = 0; i < str().length(); i++ ) sout << "-";
@@ -6672,10 +6759,13 @@ void Chuck_Type::apropos( std::string & output ) · 4 unmodified lines
66726759 sout << PREFIX;
66736760 for( int i = 0; i < str().length(); i++ ) sout << "-";
66746761 sout << endl;
6762+ // description
6763+ if( this->doc != "" )
6764+ sout << PREFIX << " |- " << capitalize(this->doc) << "" << endl;
66756765 // inheritance
66766766 if( type->parent != NULL )
66776767 {
6678− sout << PREFIX << " |- inherits";
6768+ sout << PREFIX << " |- inheritance: " << str();
66796769 while( type->parent != NULL )
66806770 {
66816771 // move up
@@ -6687,37 +6777,11 @@ void Chuck_Type::apropos( std::string & output ) · 5 unmodified lines
66876777 // set back to this
66886778 type = this;
66896779 }
6690− // description
6691− if( this->doc != "" )
6692− sout << PREFIX << " |- description: " << this->doc << "" << endl;
6693−
6694−// // storage for functions in type
6695−// vector<Chuck_Func *> funcs;
6696−// // get functions from type info
6697−// type->parent->parent->info->get_funcs( funcs );
6698−// // print functions
6699−// for( t_CKUINT i = 0; i < funcs.size(); i++ )
6700−// {
6701−// // sout << funcs[i]->base_name << endl;
6702−// }
6703−
6704− // // storage for values in type
6705− // vector<Chuck_Value *> values;
6706− // // get values from type info
6707− // type->parent->parent->parent->info->get_values( values );
6708− // // print values
6709− // for( t_CKUINT i = 0; i < values.size(); i++ )
6710− // {
6711− // CK_STDCERR << values[i]->name << CK_STDENDL;
6712− // }
6713− //
6714− // CK_STDCERR << funcs.size() << " " << values.size() << CK_STDENDL;
6715−
6780+ // delimiter
67166781 sout << PREFIX;
67176782 for( int i = 0; i < str().length(); i++ ) sout << "-";
67186783 sout << endl;
6719−
6720− // done
6784+ // store
67216785 output = sout.str();
67226786 }
67236787
@@ -6725,15 +6789,173 @@ void Chuck_Type::apropos( std::string & output ) · 1 unmodified line
67256789
67266790
67276791 //-----------------------------------------------------------------------------
6728−// name: apropos()
6729−// desc: dump info to console
6792+// name: apropos_func_arg()
6793+// desc: helper function for outputing function arguments
67306794 //-----------------------------------------------------------------------------
6731−void Chuck_Type::apropos()
6795+void apropos_func_arg( std::ostringstream & sout, a_Arg_List arg )
67326796 {
6733− // the info
6734− string output;
6735− // get it
6736− this->apropos( output );
6737− // print it
6738− CK_STDCERR << output << CK_STDENDL;
6797+ // argument type
6798+ sout << arg->type->name.c_str();
6799+ // is type an array?
6800+ if( arg->type->array_depth )
6801+ {
6802+ for( int i = 0; i < arg->type->array_depth; i++ )
6803+ sout << "[]";
6804+ }
6805+ // space
6806+ sout << " ";
6807+ // argument name
6808+ sout << S_name(arg->var_decl->xid);
6809+ // print comma, if there are more arguments after this
6810+ if( arg->next != NULL )
6811+ sout << ", ";
6812+}
6813+
6814+
6815+
6816+
6817+//-----------------------------------------------------------------------------
6818+// name: apropos_func()
6819+// desc: helper function for outputing function
6820+//-----------------------------------------------------------------------------
6821+void apropos_func( std::ostringstream & sout, Chuck_Func * func, const std::string & PREFIX )
6822+{
6823+ // output return type
6824+ sout << func->def->ret_type->c_name();
6825+ // if return type is an array
6826+ if( func->def->ret_type->array_depth )
6827+ {
6828+ // output "[]" for each dimension of the array
6829+ for( int i = 0; i < func->def->ret_type->array_depth; i++ )
6830+ sout << "[]";
6831+ }
6832+ // space
6833+ sout << " ";
6834+ // output function name
6835+ sout << S_name(func->def->name);
6836+ // open paren
6837+ sout << "(";
6838+ // extra space, if we have args
6839+ if( func->def->arg_list != NULL ) sout << " ";
6840+
6841+ // argument list
6842+ a_Arg_List args = func->def->arg_list;
6843+ while( args != NULL )
6844+ {
6845+ // output arg
6846+ apropos_func_arg( sout, args );
6847+ // move to next
6848+ args = args->next;
6849+ }
6850+
6851+ // extra space, if we are args
6852+ if( func->def->arg_list != NULL ) sout << " ";
6853+
6854+ // close paren
6855+ sout << ");" << endl;
6856+ // output doc
6857+ sout << PREFIX << " " << capitalize(func->doc) << endl;
6858+}
6859+
6860+
6861+
6862+
6863+//-----------------------------------------------------------------------------
6864+// name: apropos_funcs()
6865+// desc: dump info about funcs; added 1.4.0.2 (ge)
6866+//-----------------------------------------------------------------------------
6867+void Chuck_Type::apropos_funcs( std::string & output, const std::string & PREFIX, t_CKBOOL includeParents )
6868+{
6869+ // make a string output stream
6870+ ostringstream sout;
6871+
6872+ // check type info
6873+ if( this->info )
6874+ {
6875+ // retrieve functions in this type
6876+ vector<Chuck_Func *> funcs;
6877+ this->info->get_funcs(funcs);
6878+ // retrieve variables in this type
6879+ vector<Chuck_Value *> vars;
6880+ this->info->get_values(vars);
6881+
6882+ // member functions
6883+ vector<Chuck_Func *> mfuncs;
6884+ // static functions
6885+ vector<Chuck_Func *> sfuncs;
6886+ // member variables
6887+ vector<Chuck_Value *> mvars;
6888+ // static variables
6889+ vector<Chuck_Value *> svars;
6890+ // counter by name
6891+ map<string, int> func_names;
6892+
6893+ // iterate over retrieved functions
6894+ for( vector<Chuck_Func *>::iterator f = funcs.begin(); f != funcs.end(); f++ )
6895+ {
6896+ // get pointer to chuck func
6897+ Chuck_Func * func = *f;
6898+ // check for NULL
6899+ if( func == NULL ) continue;
6900+ // see if name appeared before
6901+ if( func_names.count(func->name) )
6902+ {
6903+ // increment count associated with name
6904+ func_names[func->name]++;
6905+ // done for now
6906+ continue;
6907+ }
6908+
6909+ // create entry for name
6910+ func_names[func->name] = 1;
6911+
6912+ // check for static declaration
6913+ if( func->def->static_decl == ae_key_static ) {
6914+ // append to static funcs list
6915+ sfuncs.push_back(func);
6916+ } else {
6917+ // append to static funcs list
6918+ mfuncs.push_back(func);
6919+ }
6920+ }
6921+
6922+ // sort
6923+ sort( mfuncs.begin(), mfuncs.end(), comp_func );
6924+ sort( sfuncs.begin(), sfuncs.end(), comp_func );
6925+
6926+ // one or more static functions?
6927+ if( mfuncs.size() )
6928+ {
6929+ // iterate over static functions
6930+ for( vector<Chuck_Func *>::iterator f = mfuncs.begin(); f != mfuncs.end(); f++ )
6931+ {
6932+ // pointer to chuck func
6933+ Chuck_Func * func = *f;
6934+ // print line prefix, if any
6935+ sout << PREFIX;
6936+ // output function content
6937+ apropos_func( sout, func, PREFIX );
6938+ }
6939+ }
6940+
6941+ // one or more static functions?
6942+ if( sfuncs.size() )
6943+ {
6944+ // iterate over static functions
6945+ for( vector<Chuck_Func *>::iterator f = sfuncs.begin(); f != sfuncs.end(); f++ )
6946+ {
6947+ // pointer to chuck func
6948+ Chuck_Func * func = *f;
6949+ // print line prefix, if any
6950+ sout << PREFIX;
6951+ // print static
6952+ sout << "static ";
6953+ // output function content
6954+ apropos_func( sout, func, PREFIX );
6955+ }
6956+ }
6957+ }
6958+
6959+ // output to string
6960+ output = sout.str();
67396961 }
src/core/chuck_type.h+13−3
@@ -655,11 +655,21 @@ protected: · 654 unmodified lines
655655 // this for str() and c_name() use only
656656 std::string ret;
657657
658−public:
659− // dump info to string
660− void apropos( std::string & output );
658+public: // apropos | 1.4.0.2 (ge)
661659 // dump info to console
662660 void apropos();
661+ // dump info to string
662+ void apropos( std::string & output );
663+
664+protected: // apropos-related helper function
665+ // dump top level info
666+ void apropos_top( std::string & output, const std::string & prefix );
667+ // dump info about functions
668+ void apropos_funcs( std::string & output, const std::string & prefix, t_CKBOOL includeParent );
669+ // dump info about vars
670+ void apropos_vars( std::string & output, const std::string & prefix, t_CKBOOL includeParent );
671+ // dump info about examples
672+ void apropos_examples( std::string & output, const std::string & prefix );
663673 };
664674
665675
src/core/ugen_stk.cpp+0−1
@@ -1238,7 +1238,6 @@ CK_DLL_MFUN( MidiFileIn_rewind ); · 1237 unmodified lines
12381238 //-----------------------------------------------------------------------------
12391239 DLL_QUERY stk_query( Chuck_DL_Query * QUERY )
12401240 {
1241−
12421241 Chuck_Env * env = QUERY->env();
12431242 Chuck_DL_Func * func = NULL;
12441243
src/core/ulib_machine.cpp+10−4
@@ -70,6 +70,7 @@ DLL_QUERY machine_query( Chuck_DL_Query * QUERY ) · 69 unmodified lines
7070 //! returns the shred ID
7171 //! (see example/machine.ck)
7272 QUERY->add_sfun( QUERY, machine_add_impl, "int", "add" );
73+ QUERY->doc_func( QUERY, "add/run a new shred from file at 'path'." );
7374 QUERY->add_arg( QUERY, "string", "path" );
7475
7576 // add spork
@@ -80,32 +81,37 @@ DLL_QUERY machine_query( Chuck_DL_Query * QUERY ) · 4 unmodified lines
8081 // add remove
8182 //! remove shred from VM by shred ID (returned by add/spork)
8283 QUERY->add_sfun( QUERY, machine_remove_impl, "int", "remove" );
84+ QUERY->doc_func( QUERY, "remove a running shred by 'id'." );
8385 QUERY->add_arg( QUERY, "int", "id" );
8486
8587 // add replace
8688 //! replace shred with new shred from file
8789 //! returns shred ID , or 0 on error
8890 QUERY->add_sfun( QUERY, machine_replace_impl, "int", "replace" );
91+ QUERY->doc_func( QUERY, "replace running shred by 'id' with new shred at 'path'." );
8992 QUERY->add_arg( QUERY, "int", "id" );
9093 QUERY->add_arg( QUERY, "string", "path" );
9194
92− // add replace
93− //! replace shred with new shred from file
94− //! returns shred ID , or 0 on error
95+ // add crash
96+ //! explicitly crash the virtual machine
9597 QUERY->add_sfun( QUERY, machine_crash_impl, "void", "crash" );
98+ QUERY->doc_func( QUERY, "explicitly crash the virtual machine." );
9699
97100 // add status
98101 //! display current status of VM
99102 //! (see example/status.ck)
100103 QUERY->add_sfun( QUERY, machine_status_impl, "int", "status" );
101−
104+ QUERY->doc_func( QUERY, "display current status of virtual machine." );
105+
102106 // add get intsize (width)
103107 //! get the intsize in bits (e.g., 32 or 64)
104108 QUERY->add_sfun( QUERY, machine_intsize_impl, "int", "intsize" );
109+ QUERY->doc_func( QUERY, "get size of int in bits (e.g., 32 or 64)." );
105110
106111 // add shreds
107112 //! get list of active shreds by id
108113 QUERY->add_sfun( QUERY, machine_shreds_impl, "int[]", "shreds" );
114+ QUERY->doc_func( QUERY, "get list of active shred ids." );
109115
110116 // end class
111117 QUERY->end_class( QUERY );

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t