@@ -73,7 +73,9 @@ using namespace std;
7373
7474
7575
76+ // -----------------------------------------------------------------------------
7677// function prototypes
78+ // -----------------------------------------------------------------------------
7779t_CKBOOL load_internal_modules ( Chuck_Compiler * compiler );
7880t_CKBOOL load_external_modules ( Chuck_Compiler * compiler,
7981 const char * extension,
@@ -207,85 +209,79 @@ void Chuck_Compiler::shutdown()
207209
208210
209211
210-
211212// -----------------------------------------------------------------------------
212- // name: bind ()
213- // desc: bind a new type system module, via query function
213+ // name: compileFile ()
214+ // desc: parse, type-check, and emit a program from file
214215// -----------------------------------------------------------------------------
215- t_CKBOOL Chuck_Compiler::bind ( f_ck_query query_func, const string & name,
216- const string & nspc )
216+ t_CKBOOL Chuck_Compiler::compileFile ( const string & filename )
217217{
218- // log
219- EM_log ( CK_LOG_SYSTEM , " on-demand binding compiler module '%s'..." ,
220- name.c_str () );
221- // push indent level
222- EM_pushlog ();
218+ // call internal compile file with option
219+ return this ->compile_file_opt ( filename, te_do_all );
220+ }
223221
224- // get env
225- Chuck_Env * env = this ->env ();
226- // make context
227- Chuck_Context * context = type_engine_make_context (
228- NULL , string (" @[bind:" ) + name + string (" ]" ) );
229- // reset env - not needed since we just created the env
230- env->reset ();
231- // load it
232- type_engine_load_context ( env, context );
233222
234- // do it
235- if ( !load_module ( this , env, query_func, name.c_str (), nspc.c_str () ) ) goto error;
236223
237- // clear context
238- type_engine_unload_context ( env );
239224
240- // commit what is in the type checker at this point
241- env->global ()->commit ();
225+ // -----------------------------------------------------------------------------
226+ // name: compileCode()
227+ // desc: parse, type-check, and emit a program from code
228+ // -----------------------------------------------------------------------------
229+ t_CKBOOL Chuck_Compiler::compileCode ( const string & codeLiteral )
230+ {
231+ // call internal compile file with option
232+ return this ->compile_code_opt ( codeLiteral, te_do_all );
233+ }
242234
243- // pop indent level
244- EM_poplog ();
245235
246- return TRUE ;
247236
248- error:
249237
250- // probably dangerous: rollback
251- env->global ()->rollback ();
238+ // -----------------------------------------------------------------------------
239+ // name: importFile()
240+ // desc: import a CK file, observing the semantics of chuck @import
241+ // -----------------------------------------------------------------------------
242+ t_CKBOOL Chuck_Compiler::importFile ( const string & filename )
243+ {
244+ // call internal compile file with option
245+ return this ->compile_file_opt ( filename, te_do_import_only );
246+ }
252247
253- // clear context
254- type_engine_unload_context ( env );
255248
256- // pop indent level
257- EM_poplog ();
258249
259- return FALSE ;
250+
251+ // -----------------------------------------------------------------------------
252+ // name: importCode()
253+ // desc: import from code, observing the semantics of chuck @import
254+ // -----------------------------------------------------------------------------
255+ t_CKBOOL Chuck_Compiler::importCode ( const string & codeLiteral )
256+ {
257+ // call internal compile file with option
258+ return this ->compile_code_opt ( codeLiteral, te_do_import_only );
260259}
261260
262261
263262
264263
265264// -----------------------------------------------------------------------------
266- // name: set_auto_depend ()
267- // desc: auto dependency resolve for types
265+ // name: importChugin ()
266+ // desc: import a chugin by path (and optional short-hand name)
268267// -----------------------------------------------------------------------------
269- void Chuck_Compiler::set_auto_depend ( t_CKBOOL v )
268+ t_CKBOOL Chuck_Compiler::importChugin ( const string & path, const string & name )
270269{
271- // log
272- EM_log ( CK_LOG_SYSTEM , " type dependency resolution: %s" ,
273- v ? " AUTO" : " MANUAL" );
274- m_auto_depend = v;
270+ // call internal import chugin with option
271+ return this ->import_chugin_opt ( path, name );
275272}
276273
277274
278275
279276
280277// -----------------------------------------------------------------------------
281- // name: compileFile ()
282- // desc: parse, type-check, and emit a program
278+ // name: compile_file_opt ()
279+ // desc: parse, type-check, and emit a program, with option for how much to compile
283280// -----------------------------------------------------------------------------
284- t_CKBOOL Chuck_Compiler::compileFile ( const string & filename )
281+ t_CKBOOL Chuck_Compiler::compile_file_opt ( const string & filename, te_HowMuch extent )
285282{
286283 // create a compile target
287- Chuck_CompileTarget * target = new Chuck_CompileTarget ( te_do_all );
288-
284+ Chuck_CompileTarget * target = new Chuck_CompileTarget ( extent );
289285 // resolve filename locally
290286 if ( !target->resolveFilename ( filename, NULL , FALSE ) )
291287 {
@@ -301,15 +297,15 @@ t_CKBOOL Chuck_Compiler::compileFile( const string & filename )
301297
302298
303299
300+
304301// -----------------------------------------------------------------------------
305- // name: compileCode ()
306- // desc: parse, type-check, and emit a program
302+ // name: compile_code_opt ()
303+ // desc: parse, type-check, and emit a program, with option for how much to compile
307304// -----------------------------------------------------------------------------
308- t_CKBOOL Chuck_Compiler::compileCode ( const string & codeLiteral )
305+ t_CKBOOL Chuck_Compiler::compile_code_opt ( const string & codeLiteral, te_HowMuch extent )
309306{
310307 // create a compile target
311- Chuck_CompileTarget * target = new Chuck_CompileTarget ( te_do_all );
312-
308+ Chuck_CompileTarget * target = new Chuck_CompileTarget ( extent );
313309 // set filename to code literal constant
314310 target->filename = CHUCK_CODE_LITERAL_SIGNIFIER ;
315311 // get working directory
@@ -506,41 +502,6 @@ t_CKBOOL Chuck_Compiler::visit( ImportTargetNode * node,
506502
507503
508504
509- // -----------------------------------------------------------------------------
510- // name: resolve()
511- // desc: resolve type automatically - if auto_depend is off, return FALSE
512- // -----------------------------------------------------------------------------
513- t_CKBOOL Chuck_Compiler::resolve ( const string & type )
514- {
515- t_CKBOOL ret = TRUE ;
516-
517- // check auto_depend
518- if ( !m_auto_depend )
519- return FALSE ;
520-
521- // look up if name is already parsed
522-
523- return ret;
524- }
525-
526-
527-
528-
529- // -----------------------------------------------------------------------------
530- // name: setReplaceDac()
531- // desc: tell the compiler whether dac should be replaced in scripts
532- // with the name of an external UGen, and if so which one
533- // -----------------------------------------------------------------------------
534- void Chuck_Compiler::setReplaceDac ( t_CKBOOL shouldReplaceDac,
535- const string & replacement )
536- {
537- emitter->should_replace_dac = shouldReplaceDac;
538- emitter->dac_replacement = replacement;
539- }
540-
541-
542-
543-
544505// -----------------------------------------------------------------------------
545506// name: compile_entire_file()
546507// desc: scan, type-check, and emit a program
@@ -921,6 +882,74 @@ Chuck_VM_Code * Chuck_Compiler::output()
921882
922883
923884
885+ // -----------------------------------------------------------------------------
886+ // name: setReplaceDac()
887+ // desc: tell the compiler whether dac should be replaced in scripts
888+ // with the name of an external UGen, and if so which one
889+ // -----------------------------------------------------------------------------
890+ void Chuck_Compiler::setReplaceDac ( t_CKBOOL shouldReplaceDac,
891+ const string & replacement )
892+ {
893+ emitter->should_replace_dac = shouldReplaceDac;
894+ emitter->dac_replacement = replacement;
895+ }
896+
897+
898+
899+ // -----------------------------------------------------------------------------
900+ // name: bind()
901+ // desc: bind a new type system module, via query function
902+ // -----------------------------------------------------------------------------
903+ t_CKBOOL Chuck_Compiler::bind ( f_ck_query query_func, const string & name,
904+ const string & nspc )
905+ {
906+ // log
907+ EM_log ( CK_LOG_SYSTEM , " on-demand binding compiler module '%s'..." ,
908+ name.c_str () );
909+ // push indent level
910+ EM_pushlog ();
911+
912+ // get env
913+ Chuck_Env * env = this ->env ();
914+ // make context
915+ Chuck_Context * context = type_engine_make_context (
916+ NULL , string (" @[bind:" ) + name + string (" ]" ) );
917+ // reset env - not needed since we just created the env
918+ env->reset ();
919+ // load it
920+ type_engine_load_context ( env, context );
921+
922+ // do it
923+ if ( !load_module ( this , env, query_func, name.c_str (), nspc.c_str () ) ) goto error;
924+
925+ // clear context
926+ type_engine_unload_context ( env );
927+
928+ // commit what is in the type checker at this point
929+ env->global ()->commit ();
930+
931+ // pop indent level
932+ EM_poplog ();
933+
934+ return TRUE ;
935+
936+ error:
937+
938+ // probably dangerous: rollback
939+ env->global ()->rollback ();
940+
941+ // clear context
942+ type_engine_unload_context ( env );
943+
944+ // pop indent level
945+ EM_poplog ();
946+
947+ return FALSE ;
948+ }
949+
950+
951+
952+
924953// -----------------------------------------------------------------------------
925954// name: load_module()
926955// desc: load a dll and add it
@@ -1247,10 +1276,10 @@ static void logChuginLoad( const string & name, t_CKINT logLevel )
12471276
12481277
12491278// -----------------------------------------------------------------------------
1250- // name: load_external_chugin ()
1251- // desc: load chugin module by path
1279+ // name: import_chugin_opt ()
1280+ // desc: load chugin module by path, with options
12521281// -----------------------------------------------------------------------------
1253- t_CKBOOL Chuck_Compiler::load_external_chugin ( const string & path, const string & name )
1282+ t_CKBOOL Chuck_Compiler::import_chugin_opt ( const string & path, const string & name )
12541283{
12551284 // get env
12561285 Chuck_Env * env = this ->env ();
@@ -1381,8 +1410,7 @@ t_CKBOOL Chuck_Compiler::load_external_modules_in_directory(
13811410 for ( t_CKINT i = 0 ; i < chugins2load.size (); i++ )
13821411 {
13831412 // load module
1384- t_CKBOOL loaded = this ->load_external_chugin (
1385- chugins2load[i].path , chugins2load[i].filename );
1413+ t_CKBOOL loaded = this ->importChugin ( chugins2load[i].path , chugins2load[i].filename );
13861414 // if no error
13871415 if ( chugins2load[i].isBundle && loaded) {
13881416 // log
@@ -1448,7 +1476,7 @@ t_CKBOOL Chuck_Compiler::load_external_modules( const string & extension,
14481476 if ( !extension_matches (dl_path, extension) )
14491477 dl_path += extension;
14501478 // load the module
1451- load_external_chugin ( dl_path );
1479+ this -> importChugin ( dl_path );
14521480 }
14531481
14541482 // now recurse through search paths and load any DLs or .ck files found
@@ -1693,6 +1721,41 @@ t_CKBOOL Chuck_Compiler::probe_external_modules( const string & extension,
16931721
16941722
16951723
1724+ // -----------------------------------------------------------------------------
1725+ // name: setAutoDepend()
1726+ // desc: auto dependency resolve for types
1727+ // -----------------------------------------------------------------------------
1728+ void Chuck_Compiler::setAutoDepend ( t_CKBOOL v )
1729+ {
1730+ // log
1731+ EM_log ( CK_LOG_SYSTEM , " type dependency resolution: %s" ,
1732+ v ? " AUTO" : " MANUAL" );
1733+ m_auto_depend = v;
1734+ }
1735+
1736+
1737+
1738+
1739+ // -----------------------------------------------------------------------------
1740+ // name: resolve()
1741+ // desc: resolve type automatically - if auto_depend is off, return FALSE
1742+ // -----------------------------------------------------------------------------
1743+ t_CKBOOL Chuck_Compiler::resolve ( const string & type )
1744+ {
1745+ t_CKBOOL ret = TRUE ;
1746+
1747+ // check auto_depend
1748+ if ( !m_auto_depend )
1749+ return FALSE ;
1750+
1751+ // look up if name is already parsed
1752+
1753+ return ret;
1754+ }
1755+
1756+
1757+
1758+
16961759// -----------------------------------------------------------------------------
16971760// name: Chuck_ImportRegistry()
16981761// desc: constructor
0 commit comments