@@ -73,7 +73,9 @@ using namespace std;
73
73
74
74
75
75
76
+ // -----------------------------------------------------------------------------
76
77
// function prototypes
78
+ // -----------------------------------------------------------------------------
77
79
t_CKBOOL load_internal_modules ( Chuck_Compiler * compiler );
78
80
t_CKBOOL load_external_modules ( Chuck_Compiler * compiler,
79
81
const char * extension,
@@ -207,85 +209,79 @@ void Chuck_Compiler::shutdown()
207
209
208
210
209
211
210
-
211
212
// -----------------------------------------------------------------------------
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
214
215
// -----------------------------------------------------------------------------
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 )
217
217
{
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
+ }
223
221
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 );
233
222
234
- // do it
235
- if ( !load_module ( this , env, query_func, name.c_str (), nspc.c_str () ) ) goto error;
236
223
237
- // clear context
238
- type_engine_unload_context ( env );
239
224
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
+ }
242
234
243
- // pop indent level
244
- EM_poplog ();
245
235
246
- return TRUE ;
247
236
248
- error:
249
237
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
+ }
252
247
253
- // clear context
254
- type_engine_unload_context ( env );
255
248
256
- // pop indent level
257
- EM_poplog ();
258
249
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 );
260
259
}
261
260
262
261
263
262
264
263
265
264
// -----------------------------------------------------------------------------
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)
268
267
// -----------------------------------------------------------------------------
269
- void Chuck_Compiler::set_auto_depend ( t_CKBOOL v )
268
+ t_CKBOOL Chuck_Compiler::importChugin ( const string & path, const string & name )
270
269
{
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 );
275
272
}
276
273
277
274
278
275
279
276
280
277
// -----------------------------------------------------------------------------
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
283
280
// -----------------------------------------------------------------------------
284
- t_CKBOOL Chuck_Compiler::compileFile ( const string & filename )
281
+ t_CKBOOL Chuck_Compiler::compile_file_opt ( const string & filename, te_HowMuch extent )
285
282
{
286
283
// create a compile target
287
- Chuck_CompileTarget * target = new Chuck_CompileTarget ( te_do_all );
288
-
284
+ Chuck_CompileTarget * target = new Chuck_CompileTarget ( extent );
289
285
// resolve filename locally
290
286
if ( !target->resolveFilename ( filename, NULL , FALSE ) )
291
287
{
@@ -301,15 +297,15 @@ t_CKBOOL Chuck_Compiler::compileFile( const string & filename )
301
297
302
298
303
299
300
+
304
301
// -----------------------------------------------------------------------------
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
307
304
// -----------------------------------------------------------------------------
308
- t_CKBOOL Chuck_Compiler::compileCode ( const string & codeLiteral )
305
+ t_CKBOOL Chuck_Compiler::compile_code_opt ( const string & codeLiteral, te_HowMuch extent )
309
306
{
310
307
// create a compile target
311
- Chuck_CompileTarget * target = new Chuck_CompileTarget ( te_do_all );
312
-
308
+ Chuck_CompileTarget * target = new Chuck_CompileTarget ( extent );
313
309
// set filename to code literal constant
314
310
target->filename = CHUCK_CODE_LITERAL_SIGNIFIER;
315
311
// get working directory
@@ -506,41 +502,6 @@ t_CKBOOL Chuck_Compiler::visit( ImportTargetNode * node,
506
502
507
503
508
504
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
-
544
505
// -----------------------------------------------------------------------------
545
506
// name: compile_entire_file()
546
507
// desc: scan, type-check, and emit a program
@@ -921,6 +882,74 @@ Chuck_VM_Code * Chuck_Compiler::output()
921
882
922
883
923
884
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
+
924
953
// -----------------------------------------------------------------------------
925
954
// name: load_module()
926
955
// desc: load a dll and add it
@@ -1247,10 +1276,10 @@ static void logChuginLoad( const string & name, t_CKINT logLevel )
1247
1276
1248
1277
1249
1278
// -----------------------------------------------------------------------------
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
1252
1281
// -----------------------------------------------------------------------------
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 )
1254
1283
{
1255
1284
// get env
1256
1285
Chuck_Env * env = this ->env ();
@@ -1381,8 +1410,7 @@ t_CKBOOL Chuck_Compiler::load_external_modules_in_directory(
1381
1410
for ( t_CKINT i = 0 ; i < chugins2load.size (); i++ )
1382
1411
{
1383
1412
// 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 );
1386
1414
// if no error
1387
1415
if ( chugins2load[i].isBundle && loaded) {
1388
1416
// log
@@ -1448,7 +1476,7 @@ t_CKBOOL Chuck_Compiler::load_external_modules( const string & extension,
1448
1476
if ( !extension_matches (dl_path, extension) )
1449
1477
dl_path += extension;
1450
1478
// load the module
1451
- load_external_chugin ( dl_path );
1479
+ this -> importChugin ( dl_path );
1452
1480
}
1453
1481
1454
1482
// 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,
1693
1721
1694
1722
1695
1723
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
+
1696
1759
// -----------------------------------------------------------------------------
1697
1760
// name: Chuck_ImportRegistry()
1698
1761
// desc: constructor
0 commit comments