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
38#include "chuck_errmsg.h"38#include "chuck_errmsg.h"
39#include "chuck_otf.h"39#include "chuck_otf.h"
40#include "ulib_machine.h"40#include "ulib_machine.h"
41#include "util_network.h"
41#include "util_string.h"42#include "util_string.h"
42 43
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
43 54
44 55
45 56
@@ -49,10 +60,12 @@ · 3 unmodified lines
49#define CHUCK_PARAM_OUTPUT_CHANNELS_DEFAULT "2"60#define CHUCK_PARAM_OUTPUT_CHANNELS_DEFAULT "2"
50#define CHUCK_PARAM_VM_ADAPTIVE_DEFAULT "0"61#define CHUCK_PARAM_VM_ADAPTIVE_DEFAULT "0"
51#define CHUCK_PARAM_VM_HALT_DEFAULT "0"62#define CHUCK_PARAM_VM_HALT_DEFAULT "0"
63#define CHUCK_PARAM_OTF_ENABLE_DEFAULT "0"
52#define CHUCK_PARAM_OTF_PORT_DEFAULT "8888"64#define CHUCK_PARAM_OTF_PORT_DEFAULT "8888"
53#define CHUCK_PARAM_DUMP_INSTRUCTIONS_DEFAULT "0"65#define CHUCK_PARAM_DUMP_INSTRUCTIONS_DEFAULT "0"
54#define CHUCK_PARAM_DEPRECATE_LEVEL_DEFAULT "1"66#define CHUCK_PARAM_DEPRECATE_LEVEL_DEFAULT "1"
55#define CHUCK_PARAM_WORKING_DIRECTORY_DEFAULT ""67#define CHUCK_PARAM_WORKING_DIRECTORY_DEFAULT ""
68#define CHUCK_PARAM_CHUGIN_ENABLE_DEFAULT "1"
56#define CHUCK_PARAM_CHUGIN_DIRECTORY_DEFAULT ""69#define CHUCK_PARAM_CHUGIN_DIRECTORY_DEFAULT ""
57 70
58 71
@@ -155,22 +168,26 @@ void ChucK::initDefaultParams() · 96 unmodified lines
155 m_params[CHUCK_PARAM_OUTPUT_CHANNELS] = CHUCK_PARAM_OUTPUT_CHANNELS_DEFAULT;168 m_params[CHUCK_PARAM_OUTPUT_CHANNELS] = CHUCK_PARAM_OUTPUT_CHANNELS_DEFAULT;
156 m_params[CHUCK_PARAM_VM_ADAPTIVE] = CHUCK_PARAM_VM_ADAPTIVE_DEFAULT;169 m_params[CHUCK_PARAM_VM_ADAPTIVE] = CHUCK_PARAM_VM_ADAPTIVE_DEFAULT;
157 m_params[CHUCK_PARAM_VM_HALT] = CHUCK_PARAM_VM_HALT_DEFAULT;170 m_params[CHUCK_PARAM_VM_HALT] = CHUCK_PARAM_VM_HALT_DEFAULT;
171 m_params[CHUCK_PARAM_OTF_ENABLE] = CHUCK_PARAM_OTF_ENABLE_DEFAULT;
158 m_params[CHUCK_PARAM_OTF_PORT] = CHUCK_PARAM_OTF_PORT_DEFAULT;172 m_params[CHUCK_PARAM_OTF_PORT] = CHUCK_PARAM_OTF_PORT_DEFAULT;
159 m_params[CHUCK_PARAM_DUMP_INSTRUCTIONS] = CHUCK_PARAM_DUMP_INSTRUCTIONS_DEFAULT;173 m_params[CHUCK_PARAM_DUMP_INSTRUCTIONS] = CHUCK_PARAM_DUMP_INSTRUCTIONS_DEFAULT;
160 m_params[CHUCK_PARAM_DEPRECATE_LEVEL] = CHUCK_PARAM_DEPRECATE_LEVEL_DEFAULT;174 m_params[CHUCK_PARAM_DEPRECATE_LEVEL] = CHUCK_PARAM_DEPRECATE_LEVEL_DEFAULT;
161 m_params[CHUCK_PARAM_WORKING_DIRECTORY] = CHUCK_PARAM_WORKING_DIRECTORY_DEFAULT;175 m_params[CHUCK_PARAM_WORKING_DIRECTORY] = CHUCK_PARAM_WORKING_DIRECTORY_DEFAULT;
162 m_params[CHUCK_PARAM_CHUGIN_DIRECTORY] = CHUCK_PARAM_CHUGIN_DIRECTORY_DEFAULT;176 m_params[CHUCK_PARAM_CHUGIN_DIRECTORY] = CHUCK_PARAM_CHUGIN_DIRECTORY_DEFAULT;
177 m_params[CHUCK_PARAM_CHUGIN_ENABLE] = CHUCK_PARAM_CHUGIN_ENABLE_DEFAULT;
163 178
164 ck_param_types[CHUCK_PARAM_SAMPLE_RATE] = ck_param_int;179 ck_param_types[CHUCK_PARAM_SAMPLE_RATE] = ck_param_int;
165 ck_param_types[CHUCK_PARAM_INPUT_CHANNELS] = ck_param_int;180 ck_param_types[CHUCK_PARAM_INPUT_CHANNELS] = ck_param_int;
166 ck_param_types[CHUCK_PARAM_OUTPUT_CHANNELS] = ck_param_int;181 ck_param_types[CHUCK_PARAM_OUTPUT_CHANNELS] = ck_param_int;
167 ck_param_types[CHUCK_PARAM_VM_ADAPTIVE] = ck_param_int;182 ck_param_types[CHUCK_PARAM_VM_ADAPTIVE] = ck_param_int;
168 ck_param_types[CHUCK_PARAM_VM_HALT] = ck_param_int;183 ck_param_types[CHUCK_PARAM_VM_HALT] = ck_param_int;
184 ck_param_types[CHUCK_PARAM_OTF_ENABLE] = ck_param_int;
169 ck_param_types[CHUCK_PARAM_OTF_PORT] = ck_param_int;185 ck_param_types[CHUCK_PARAM_OTF_PORT] = ck_param_int;
170 ck_param_types[CHUCK_PARAM_DUMP_INSTRUCTIONS] = ck_param_int;186 ck_param_types[CHUCK_PARAM_DUMP_INSTRUCTIONS] = ck_param_int;
171 ck_param_types[CHUCK_PARAM_DEPRECATE_LEVEL] = ck_param_int;187 ck_param_types[CHUCK_PARAM_DEPRECATE_LEVEL] = ck_param_int;
172 ck_param_types[CHUCK_PARAM_WORKING_DIRECTORY] = ck_param_string;188 ck_param_types[CHUCK_PARAM_WORKING_DIRECTORY] = ck_param_string;
173 ck_param_types[CHUCK_PARAM_CHUGIN_DIRECTORY] = ck_param_string;189 ck_param_types[CHUCK_PARAM_CHUGIN_DIRECTORY] = ck_param_string;
190 ck_param_types[CHUCK_PARAM_CHUGIN_ENABLE] = ck_param_int;
174}191}
175 192
176 193
@@ -300,6 +317,11 @@ std::string ChucK::getParamString( const std::string & key ) · 123 unmodified lines
300//-----------------------------------------------------------------------------317//-----------------------------------------------------------------------------
301bool ChucK::init()318bool ChucK::init()
302{319{
320 Chuck_VM_Code * code = NULL;
321 Chuck_VM_Shred * shred = NULL;
322 std::string cwd;
323 char cstr_cwd[MAXPATHLEN];
324
303 // sanity check325 // sanity check
304 if( m_carrier->vm != NULL )326 if( m_carrier->vm != NULL )
305 {327 {
@@ -320,7 +342,7 @@ bool ChucK::init() · 14 unmodified lines
320 string workingDir = getParamString( CHUCK_PARAM_WORKING_DIRECTORY );342 string workingDir = getParamString( CHUCK_PARAM_WORKING_DIRECTORY );
321 string chuginDir = getParamString( CHUCK_PARAM_CHUGIN_DIRECTORY );343 string chuginDir = getParamString( CHUCK_PARAM_CHUGIN_DIRECTORY );
322 t_CKUINT deprecate = getParamInt( CHUCK_PARAM_DEPRECATE_LEVEL );344 t_CKUINT deprecate = getParamInt( CHUCK_PARAM_DEPRECATE_LEVEL );
323 // TODO: chugin load option345
324 // list of search pathes (added 1.3.0.0)346 // list of search pathes (added 1.3.0.0)
325 std::list<std::string> dl_search_path;347 std::list<std::string> dl_search_path;
326 if( workingDir != std::string("") )348 if( workingDir != std::string("") )
@@ -333,8 +355,7 @@ bool ChucK::init() · 6 unmodified lines
333 }355 }
334 // list of individually named chug-ins (added 1.3.0.0)356 // list of individually named chug-ins (added 1.3.0.0)
335 std::list<std::string> named_dls;357 std::list<std::string> named_dls;
336 358
337
338 // instantiate VM359 // instantiate VM
339 m_carrier->vm = new Chuck_VM();360 m_carrier->vm = new Chuck_VM();
340 // reference back to carrier361 // reference back to carrier
@@ -345,6 +366,14 @@ bool ChucK::init() · 4 unmodified lines
345 CK_FPRINTF_STDERR( "[chuck]: %s\n", m_carrier->vm->last_error() );366 CK_FPRINTF_STDERR( "[chuck]: %s\n", m_carrier->vm->last_error() );
346 goto cleanup;367 goto cleanup;
347 }368 }
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 }
348 377
349 // instantiate compiler378 // instantiate compiler
350 m_carrier->compiler = new Chuck_Compiler();379 m_carrier->compiler = new Chuck_Compiler();
@@ -371,11 +400,105 @@ bool ChucK::init() · 20 unmodified lines
371 goto cleanup;400 goto cleanup;
372 }401 }
373 402
374 // TODO: load chugins403 // 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 }
375 464
376 // load user namespace465 // load user namespace
377 m_carrier->env->load_user_namespace();466 m_carrier->env->load_user_namespace();
378 467
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
379 // did user init?502 // did user init?
380 m_init = TRUE;503 m_init = TRUE;
381 504
@@ -495,6 +618,9 @@ bool ChucK::compileFile( const std::string & path, const std::string & argsToget · 113 unmodified lines
495 // pop indent618 // pop indent
496 EM_poplog();619 EM_poplog();
497 620
621 // reset the parser
622 reset_parse();
623
498 return true;624 return true;
499}625}
500 626
@@ -567,7 +693,10 @@ bool ChucK::compileCode( const std::string & code, const std::string & argsToget · 66 unmodified lines
567 693
568 // pop indent694 // pop indent
569 EM_poplog();695 EM_poplog();
570 696
697 // reset the parser
698 reset_parse();
699
571 return true;700 return true;
572}701}
573 702
@@ -758,6 +887,28 @@ void ChucK::finalCleanup() · 184 unmodified lines
758 887
759 888
760 889
890//-----------------------------------------------------------------------------
891// set log level -- this should eventually be per-VM?
892//-----------------------------------------------------------------------------
893void ChucK::setLogLevel( t_CKINT level )
894{
895 EM_setlog( level );
896}
897
898
899
900
901//-----------------------------------------------------------------------------
902// get log level -- also per-VM?
903//-----------------------------------------------------------------------------
904t_CKINT ChucK::getLogLevel()
905{
906 return g_loglevel;
907}
908
909
910
911
761//-----------------------------------------------------------------------------912//-----------------------------------------------------------------------------
762// name: poop()913// name: poop()
763// desc: --poop914// 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