History

will it compile?

Ge Wang committed 9 years ago

Commit bb2ec141 parent a61578a5 files · +242 −302Browse files

Showing the changes to src/core/chuck.cpp (1 of 5 files). Show all

Unified · Split

src/core/chuck.cpp+156−5
@@ -38,8 +38,19 @@ · 37 unmodified lines
3838 #include "chuck_errmsg.h"
3939 #include "chuck_otf.h"
4040 #include "ulib_machine.h"
41+#include "util_network.h"
4142 #include "util_string.h"
4243
44+#ifndef __PLATFORM_WIN32__
45+#include <unistd.h>
46+#include <netinet/in.h>
47+#include <arpa/inet.h>
48+#include <sys/param.h> // added 1.3.0.0
49+#else
50+#include <direct.h> // added 1.3.0.0
51+#define MAXPATHLEN (255) // addec 1.3.0.0
52+#endif // #ifndef __PLATFORM_WIN32__
53+
4354
4455
4556
@@ -49,10 +60,12 @@ · 3 unmodified lines
4960 #define CHUCK_PARAM_OUTPUT_CHANNELS_DEFAULT "2"
5061 #define CHUCK_PARAM_VM_ADAPTIVE_DEFAULT "0"
5162 #define CHUCK_PARAM_VM_HALT_DEFAULT "0"
63+#define CHUCK_PARAM_OTF_ENABLE_DEFAULT "0"
5264 #define CHUCK_PARAM_OTF_PORT_DEFAULT "8888"
5365 #define CHUCK_PARAM_DUMP_INSTRUCTIONS_DEFAULT "0"
5466 #define CHUCK_PARAM_DEPRECATE_LEVEL_DEFAULT "1"
5567 #define CHUCK_PARAM_WORKING_DIRECTORY_DEFAULT ""
68+#define CHUCK_PARAM_CHUGIN_ENABLE_DEFAULT "1"
5669 #define CHUCK_PARAM_CHUGIN_DIRECTORY_DEFAULT ""
5770
5871
@@ -155,22 +168,26 @@ void ChucK::initDefaultParams() · 96 unmodified lines
155168 m_params[CHUCK_PARAM_OUTPUT_CHANNELS] = CHUCK_PARAM_OUTPUT_CHANNELS_DEFAULT;
156169 m_params[CHUCK_PARAM_VM_ADAPTIVE] = CHUCK_PARAM_VM_ADAPTIVE_DEFAULT;
157170 m_params[CHUCK_PARAM_VM_HALT] = CHUCK_PARAM_VM_HALT_DEFAULT;
171+ m_params[CHUCK_PARAM_OTF_ENABLE] = CHUCK_PARAM_OTF_ENABLE_DEFAULT;
158172 m_params[CHUCK_PARAM_OTF_PORT] = CHUCK_PARAM_OTF_PORT_DEFAULT;
159173 m_params[CHUCK_PARAM_DUMP_INSTRUCTIONS] = CHUCK_PARAM_DUMP_INSTRUCTIONS_DEFAULT;
160174 m_params[CHUCK_PARAM_DEPRECATE_LEVEL] = CHUCK_PARAM_DEPRECATE_LEVEL_DEFAULT;
161175 m_params[CHUCK_PARAM_WORKING_DIRECTORY] = CHUCK_PARAM_WORKING_DIRECTORY_DEFAULT;
162176 m_params[CHUCK_PARAM_CHUGIN_DIRECTORY] = CHUCK_PARAM_CHUGIN_DIRECTORY_DEFAULT;
177+ m_params[CHUCK_PARAM_CHUGIN_ENABLE] = CHUCK_PARAM_CHUGIN_ENABLE_DEFAULT;
163178
164179 ck_param_types[CHUCK_PARAM_SAMPLE_RATE] = ck_param_int;
165180 ck_param_types[CHUCK_PARAM_INPUT_CHANNELS] = ck_param_int;
166181 ck_param_types[CHUCK_PARAM_OUTPUT_CHANNELS] = ck_param_int;
167182 ck_param_types[CHUCK_PARAM_VM_ADAPTIVE] = ck_param_int;
168183 ck_param_types[CHUCK_PARAM_VM_HALT] = ck_param_int;
184+ ck_param_types[CHUCK_PARAM_OTF_ENABLE] = ck_param_int;
169185 ck_param_types[CHUCK_PARAM_OTF_PORT] = ck_param_int;
170186 ck_param_types[CHUCK_PARAM_DUMP_INSTRUCTIONS] = ck_param_int;
171187 ck_param_types[CHUCK_PARAM_DEPRECATE_LEVEL] = ck_param_int;
172188 ck_param_types[CHUCK_PARAM_WORKING_DIRECTORY] = ck_param_string;
173189 ck_param_types[CHUCK_PARAM_CHUGIN_DIRECTORY] = ck_param_string;
190+ ck_param_types[CHUCK_PARAM_CHUGIN_ENABLE] = ck_param_int;
174191 }
175192
176193
@@ -300,6 +317,11 @@ std::string ChucK::getParamString( const std::string & key ) · 123 unmodified lines
300317 //-----------------------------------------------------------------------------
301318 bool ChucK::init()
302319 {
320+ Chuck_VM_Code * code = NULL;
321+ Chuck_VM_Shred * shred = NULL;
322+ std::string cwd;
323+ char cstr_cwd[MAXPATHLEN];
324+
303325 // sanity check
304326 if( m_carrier->vm != NULL )
305327 {
@@ -320,7 +342,7 @@ bool ChucK::init() · 14 unmodified lines
320342 string workingDir = getParamString( CHUCK_PARAM_WORKING_DIRECTORY );
321343 string chuginDir = getParamString( CHUCK_PARAM_CHUGIN_DIRECTORY );
322344 t_CKUINT deprecate = getParamInt( CHUCK_PARAM_DEPRECATE_LEVEL );
323− // TODO: chugin load option
345+
324346 // list of search pathes (added 1.3.0.0)
325347 std::list<std::string> dl_search_path;
326348 if( workingDir != std::string("") )
@@ -333,8 +355,7 @@ bool ChucK::init() · 6 unmodified lines
333355 }
334356 // list of individually named chug-ins (added 1.3.0.0)
335357 std::list<std::string> named_dls;
336−
337−
358+
338359 // instantiate VM
339360 m_carrier->vm = new Chuck_VM();
340361 // reference back to carrier
@@ -345,6 +366,14 @@ bool ChucK::init() · 4 unmodified lines
345366 CK_FPRINTF_STDERR( "[chuck]: %s\n", m_carrier->vm->last_error() );
346367 goto cleanup;
347368 }
369+
370+ // if chugin load is off, then clear the lists (added 1.3.0.0 -- TODO: refactor)
371+ if( getParamInt( CHUCK_PARAM_CHUGIN_ENABLE ) == 0 )
372+ {
373+ // turn off chugin load
374+ dl_search_path.clear();
375+ named_dls.clear();
376+ }
348377
349378 // instantiate compiler
350379 m_carrier->compiler = new Chuck_Compiler();
@@ -371,11 +400,105 @@ bool ChucK::init() · 20 unmodified lines
371400 goto cleanup;
372401 }
373402
374− // TODO: load chugins
403+ // figure out current working directory (added 1.3.0.0)
404+ // is this needed for current path to work correctly?!
405+ if( getcwd(cstr_cwd, MAXPATHLEN) == NULL )
406+ {
407+ // uh...
408+ EM_log( CK_LOG_SEVERE, "error: unable to determine current working directory!" );
409+ }
410+ else
411+ {
412+ cwd = std::string(cstr_cwd);
413+ cwd = normalize_directory_separator(cwd) + "/";
414+ }
415+
416+ // whether or not chug should be enabled (added 1.3.0.0)
417+ if( getParamInt( CHUCK_PARAM_CHUGIN_ENABLE ) != 0 )
418+ {
419+ // log
420+ EM_log( CK_LOG_SEVERE, "pre-loading ChucK libs..." );
421+ EM_pushlog();
422+
423+ // iterate over list of ck files that the compiler found
424+ for( std::list<std::string>::iterator j =
425+ compiler()->m_cklibs_to_preload.begin();
426+ j != compiler()->m_cklibs_to_preload.end(); j++)
427+ {
428+ // the filename
429+ std::string filename = *j;
430+
431+ // log
432+ EM_log( CK_LOG_SEVERE, "preloading '%s'...", filename.c_str() );
433+ // push indent
434+ EM_pushlog();
435+
436+ // SPENCERTODO: what to do for full path
437+ std::string full_path = filename;
438+
439+ // parse, type-check, and emit
440+ if( compiler()->go( filename, NULL, NULL, full_path ) )
441+ {
442+ // TODO: how to compilation handle?
443+ //return 1;
444+
445+ // get the code
446+ code = compiler()->output();
447+ // name it - TODO?
448+ // code->name += string(argv[i]);
449+
450+ // spork it
451+ shred = vm()->spork( code, NULL, TRUE );
452+ }
453+
454+ // pop indent
455+ EM_poplog();
456+ }
457+
458+ // clear the list of chuck files to preload
459+ compiler()->m_cklibs_to_preload.clear();
460+
461+ // pop log
462+ EM_poplog();
463+ }
375464
376465 // load user namespace
377466 m_carrier->env->load_user_namespace();
378467
468+ // server
469+ if( getParamInt( CHUCK_PARAM_OTF_ENABLE ) != 0 )
470+ {
471+ m_carrier->otf_port = getParamInt( CHUCK_PARAM_OTF_PORT );
472+ // log
473+ EM_log( CK_LOG_SYSTEM, "starting listener on port: %d...",
474+ m_carrier->otf_port );
475+
476+ // start tcp server
477+ m_carrier->otf_socket = ck_tcp_create( 1 );
478+ if( !m_carrier->otf_socket ||
479+ !ck_bind( m_carrier->otf_socket, m_carrier->otf_port ) ||
480+ !ck_listen( m_carrier->otf_socket, 10 ) )
481+ {
482+ CK_FPRINTF_STDERR( "[chuck]: cannot bind to tcp port %li...\n", m_carrier->otf_port );
483+ ck_close( m_carrier->otf_socket );
484+ m_carrier->otf_socket = NULL;
485+ }
486+ else
487+ {
488+#if !defined(__PLATFORM_WIN32__) || defined(__WINDOWS_PTHREAD__)
489+ pthread_create( &m_carrier->otf_thread, NULL, otf_cb, NULL );
490+#else
491+ m_carrier->otf_thread = CreateThread( NULL, 0,
492+ (LPTHREAD_START_ROUTINE)otf_cb, NULL, 0, 0 );
493+#endif
494+ }
495+ }
496+ else
497+ {
498+ // log
499+ EM_log( CK_LOG_SYSTEM, "OTF server/listener: OFF" );
500+ }
501+
379502 // did user init?
380503 m_init = TRUE;
381504
@@ -495,6 +618,9 @@ bool ChucK::compileFile( const std::string & path, const std::string & argsToget · 113 unmodified lines
495618 // pop indent
496619 EM_poplog();
497620
621+ // reset the parser
622+ reset_parse();
623+
498624 return true;
499625 }
500626
@@ -567,7 +693,10 @@ bool ChucK::compileCode( const std::string & code, const std::string & argsToget · 66 unmodified lines
567693
568694 // pop indent
569695 EM_poplog();
570−
696+
697+ // reset the parser
698+ reset_parse();
699+
571700 return true;
572701 }
573702
@@ -758,6 +887,28 @@ void ChucK::finalCleanup() · 184 unmodified lines
758887
759888
760889
890+//-----------------------------------------------------------------------------
891+// set log level -- this should eventually be per-VM?
892+//-----------------------------------------------------------------------------
893+void ChucK::setLogLevel( t_CKINT level )
894+{
895+ EM_setlog( level );
896+}
897+
898+
899+
900+
901+//-----------------------------------------------------------------------------
902+// get log level -- also per-VM?
903+//-----------------------------------------------------------------------------
904+t_CKINT ChucK::getLogLevel()
905+{
906+ return g_loglevel;
907+}
908+
909+
910+
911+
761912 //-----------------------------------------------------------------------------
762913 // name: poop()
763914 // desc: --poop

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