History

will it compile?

Ge Wang committed 9 years ago

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

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

Unified · Split

src/host/chuck_main.cpp+71−288
@@ -53,7 +53,7 @@ void cb( t_CKSAMPLE * in, t_CKSAMPLE * out, t_CKUINT numFrames, · 52 unmodified lines
5353
5454 // C functions
5555 extern "C" void signal_int( int sig_num );
56−
56+extern "C" void signal_pipe( int sig_num );
5757
5858
5959
@@ -67,7 +67,7 @@ CHUCK_THREAD g_tid_shell = 0; · 7 unmodified lines
6767 // default destination host name
6868 char g_otf_dest[256] = "127.0.0.1";
6969 // otf listener port
70−t_CKUINT g_otf_port = 8888;
70+t_CKINT g_otf_port = 8888;
7171
7272 // the shell
7373 Chuck_Shell * g_shell = NULL;
@@ -254,6 +254,27 @@ extern "C" void signal_int( int sig_num ) · 180 unmodified lines
254254
255255
256256
257+
258+
259+
260+
261+//-----------------------------------------------------------------------------
262+// name: signal_pipe()
263+// desc: ...
264+//-----------------------------------------------------------------------------
265+extern "C" void signal_pipe( int sig_num )
266+{
267+ fprintf( stderr, "[chuck]: sigpipe handled - broken pipe (no connection)...\n" );
268+ if( g_sigpipe_mode )
269+ {
270+ all_detach();
271+ // exit( 2 );
272+ }
273+}
274+
275+
276+
277+
257278 //-----------------------------------------------------------------------------
258279 // name: global_cleanup()
259280 // desc: ...
@@ -364,6 +385,8 @@ bool go( int argc, const char ** argv ) · 104 unmodified lines
364385 t_CKBOOL update_otf_vm = TRUE;
365386 string filename = "";
366387 vector<string> args;
388+ Chuck_VM_Code * code = NULL;
389+ Chuck_VM_Shred * shred = NULL;
367390
368391 // list of search pathes (added 1.3.0.0)
369392 std::list<std::string> dl_search_path;
@@ -791,132 +814,52 @@ bool go( int argc, const char ** argv ) · 421 unmodified lines
791814 the_chuck->setParam( CHUCK_PARAM_VM_ADAPTIVE, adaptive_size );
792815 the_chuck->setParam( CHUCK_PARAM_VM_HALT, (t_CKINT)(vm_halt) );
793816 the_chuck->setParam( CHUCK_PARAM_OTF_PORT, g_otf_port );
794− the_chuck->setParam( CHUCK_PARAM_LOG_LEVEL, g_loglevel );
795− the_chuck->setParam( CHUCK_PARAM_, );
796− the_chuck->setParam( CHUCK_PARAM_, );
797− the_chuck->setParam( CHUCK_PARAM_, );
798− the_chuck->setParam( CHUCK_PARAM_, );
817+ the_chuck->setParam( CHUCK_PARAM_DUMP_INSTRUCTIONS, (t_CKINT)dump );
818+ the_chuck->setParam( CHUCK_PARAM_AUTO_DEPEND, (t_CKINT)auto_depend );
819+ the_chuck->setParam( CHUCK_PARAM_DEPRECATE_LEVEL, deprecate_level );
820+ the_chuck->setLogLevel( log_level );
799821
800822 // initialize
801−
802−
803−
804− //------------------------- VIRTUAL MACHINE SETUP -----------------------------
805−
806− // allocate the vm - needs the type system
807− vm = m_carrier.vm = m_vmRef = new Chuck_VM;
808− m_carrier.vm->setCarrier( &m_carrier );
809−
810− // ge: refactor 2015: initialize VM
811− if( !vm->initialize( srate, dac_chans, adc_chans, adaptive_size, vm_halt ) )
812− {
813− CK_FPRINTF_STDERR( "[chuck]: %s\n", vm->last_error() );
814− exit( 1 );
815− }
816−
817− if( update_otf_vm )
818− {
819− set_otf_vm( vm );
820− }
821−
823+ the_chuck->init();
822824
823825 //--------------------------- AUDIO I/O SETUP ---------------------------------
826+ // log
827+ EM_log( CK_LOG_SYSTEM, "initializing audio I/O..." );
828+ // push
829+ EM_pushlog();
830+ // log
831+ EM_log( CK_LOG_SYSTEM, "probing '%s' audio subsystem...", g_enable_realtime_audio ? "real-time" : "fake-time" );
832+
824833 // initialize audio system
825− t_CKBOOL retval = ChuckAudio::initialize( numInChannels, numOutChannels,
826− srate, bufferSize, numBuffers, cb, NULL, FALSE );
834+ t_CKBOOL retval = ChuckAudio::initialize( adc_chans, dac_chans,
835+ srate, buffer_size, num_buffers, cb, (void *)the_chuck, force_srate );
827836 // check
828837 if( !retval )
829838 {
830− // BADDDD
831− }
832−
833− // ge: 1.3.5.3
834− if( g_bbq == NULL ) {
835− bbq = g_bbq = new BBQ;
836− // set some parameters
837− bbq->set_srate( srate );
838− bbq->set_bufsize( buffer_size );
839− bbq->set_numbufs( num_buffers );
840− bbq->set_inouts( adc, dac );
841− bbq->set_chans( adc_chans, dac_chans );
842−
843− // log
844− EM_log( CK_LOG_SYSTEM, "initializing audio I/O..." );
845− // push
846− EM_pushlog();
847− // log
848− EM_log( CK_LOG_SYSTEM, "probing '%s' audio subsystem...", g_enable_realtime_audio ? "real-time" : "fake-time" );
849−
850− // probe / init (this shouldn't start audio yet...
851− // moved here 1.3.1.2; to main ge: 1.3.5.3)
852− if( !bbq->initialize( dac_chans, adc_chans, srate, 16, buffer_size, num_buffers,
853− dac, adc, block, vm, g_enable_realtime_audio, NULL, NULL, force_srate ) )
854− {
855− EM_log( CK_LOG_SYSTEM,
856− "cannot initialize audio device (use --silent/-s for non-realtime)" );
857− // pop
858− EM_poplog();
859− // done
860− exit( 1 );
861− }
862−
863− // log
864− EM_log( CK_LOG_SYSTEM, "real-time audio: %s", g_enable_realtime_audio ? "YES" : "NO" );
865− EM_log( CK_LOG_SYSTEM, "mode: %s", block ? "BLOCKING" : "CALLBACK" );
866− EM_log( CK_LOG_SYSTEM, "sample rate: %ld", srate );
867− EM_log( CK_LOG_SYSTEM, "buffer size: %ld", buffer_size );
868− if( g_enable_realtime_audio )
869− {
870− EM_log( CK_LOG_SYSTEM, "num buffers: %ld", num_buffers );
871− EM_log( CK_LOG_SYSTEM, "adc: %ld dac: %d", adc, dac );
872− EM_log( CK_LOG_SYSTEM, "adaptive block processing: %ld", adaptive_size > 1 ? adaptive_size : 0 );
873− }
874− EM_log( CK_LOG_SYSTEM, "channels in: %ld out: %ld", adc_chans, dac_chans );
875−
839+ EM_log( CK_LOG_SYSTEM,
840+ "cannot initialize audio device (use --silent/-s for non-realtime)" );
876841 // pop
877842 EM_poplog();
878− } else {
879− bbq = g_bbq;
880− }
881−
882− //------------------------- CHUCK COMPILER SETUP -----------------------------
883−
884− // if chugin load is off, then clear the lists (added 1.3.0.0 -- TODO: refactor)
885− if( chugin_load == 0 )
886− {
887− // turn off chugin load
888− dl_search_path.clear();
889− named_dls.clear();
890− }
891−
892− // allocate the compiler
893− compiler = m_carrier.compiler = m_compilerRef = new Chuck_Compiler;
894− m_carrier.compiler->setCarrier( &m_carrier );
895−
896− // initialize the compiler (search_apth and named_dls added 1.3.0.0 -- TODO: refactor)
897− if( !compiler->initialize( dl_search_path, named_dls ) )
898− {
899− CK_FPRINTF_STDERR( "[chuck]: error initializing compiler...\n" );
843+ // done
900844 exit( 1 );
901845 }
902− // enable dump
903− compiler->emitter->dump = dump;
904− // set auto depend
905− compiler->set_auto_depend( auto_depend );
906846
907− if( update_otf_vm )
908− {
909− // also update otf compiler
910− set_otf_compiler( compiler );
911− }
912−
913− // vm synthesis subsystem - needs the type system
914− if( !vm->initialize_synthesis( ) )
847+ // log
848+ EM_log( CK_LOG_SYSTEM, "real-time audio: %s", g_enable_realtime_audio ? "YES" : "NO" );
849+ EM_log( CK_LOG_SYSTEM, "mode: %s", block ? "BLOCKING" : "CALLBACK" );
850+ EM_log( CK_LOG_SYSTEM, "sample rate: %ld", srate );
851+ EM_log( CK_LOG_SYSTEM, "buffer size: %ld", buffer_size );
852+ if( g_enable_realtime_audio )
915853 {
916− CK_FPRINTF_STDERR( "[chuck]: %s\n", vm->last_error() );
917− exit( 1 );
854+ EM_log( CK_LOG_SYSTEM, "num buffers: %ld", num_buffers );
855+ EM_log( CK_LOG_SYSTEM, "adc: %ld dac: %d", adc, dac );
856+ EM_log( CK_LOG_SYSTEM, "adaptive block processing: %ld", adaptive_size > 1 ? adaptive_size : 0 );
918857 }
858+ EM_log( CK_LOG_SYSTEM, "channels in: %ld out: %ld", adc_chans, dac_chans );
919859
860+ // pop
861+ EM_poplog();
862+
920863 #ifndef __ALTER_HID__
921864 // pre-load hid
922865 if( load_hid ) HidInManager::init();
@@ -935,82 +878,13 @@ bool go( int argc, const char ** argv ) · 12 unmodified lines
935878 // instantiate
936879 g_shell = new Chuck_Shell;
937880 // initialize
938− if( !init_shell( g_shell, new Chuck_Console, vm ) )
881+ if( !init_shell( g_shell, new Chuck_Console(), the_chuck->vm() ) )
939882 exit( 1 );
940883 }
941−
942− // set deprecate
943− compiler->env()->deprecate_level = deprecate_level;
944−
884+
945885 // reset count
946886 count = 1;
947887
948− // figure out current working directory (added 1.3.0.0)
949− std::string cwd;
950− {
951− char cstr_cwd[MAXPATHLEN];
952− if( getcwd(cstr_cwd, MAXPATHLEN) == NULL )
953− {
954− // uh...
955− EM_log( CK_LOG_SEVERE, "error: unable to determine current working directory!" );
956− }
957− else
958− {
959− cwd = std::string(cstr_cwd);
960− cwd = normalize_directory_separator(cwd) + "/";
961− }
962− }
963−
964− // whether or not chug should be enabled (added 1.3.0.0)
965− if( chugin_load )
966− {
967− // log
968− EM_log( CK_LOG_SEVERE, "pre-loading ChucK libs..." );
969− EM_pushlog();
970−
971− // iterate over list of ck files that the compiler found
972− for( std::list<std::string>::iterator j = compiler->m_cklibs_to_preload.begin();
973− j != compiler->m_cklibs_to_preload.end(); j++)
974− {
975− // the filename
976− std::string filename = *j;
977−
978− // log
979− EM_log( CK_LOG_SEVERE, "preloading '%s'...", filename.c_str() );
980− // push indent
981− EM_pushlog();
982−
983− // SPENCERTODO: what to do for full path
984− std::string full_path = filename;
985−
986− // parse, type-check, and emit
987− if( compiler->go( filename, NULL, NULL, full_path ) )
988− {
989− // TODO: how to compilation handle?
990− //return 1;
991−
992− // get the code
993− code = compiler->output();
994− // name it - TODO?
995− // code->name += string(argv[i]);
996−
997− // spork it
998− shred = vm->spork( code, NULL, TRUE );
999− }
1000−
1001− // pop indent
1002− EM_poplog();
1003− }
1004−
1005− // clear the list of chuck files to preload
1006− compiler->m_cklibs_to_preload.clear();
1007−
1008− // pop log
1009− EM_poplog();
1010− }
1011−
1012− compiler->env()->load_user_namespace();
1013−
1014888 // log
1015889 EM_log( CK_LOG_SEVERE, "starting compilation..." );
1016890 // push indent
@@ -1026,9 +900,9 @@ bool go( int argc, const char ** argv ) · 9 unmodified lines
1026900 if( argv[i][0] == '-' || argv[i][0] == '+' )
1027901 {
1028902 if( !strcmp(argv[i], "--dump") || !strcmp(argv[i], "+d" ) )
1029− compiler->emitter->dump = TRUE;
903+ the_chuck->compiler()->emitter->dump = TRUE;
1030904 else if( !strcmp(argv[i], "--nodump") || !strcmp(argv[i], "-d" ) )
1031− compiler->emitter->dump = FALSE;
905+ the_chuck->compiler()->emitter->dump = FALSE;
1032906 else
1033907 get_count( argv[i], &count );
1034908
@@ -1036,7 +910,7 @@ bool go( int argc, const char ** argv ) · 1 unmodified line
1036910 }
1037911
1038912 // compile it!
1039− compileFile( argv[i], "", count );
913+ the_chuck->compileFile( argv[i], "", count );
1040914
1041915 // reset count
1042916 count = 1;
@@ -1045,56 +919,22 @@ bool go( int argc, const char ** argv ) · 2 unmodified lines
1045919 // pop indent
1046920 EM_poplog();
1047921
1048− // reset the parser
1049− reset_parse();
1050−
1051922 // boost priority
1052− if( Chuck_VM::our_priority != 0x7fffffff )
923+ if( XThreadUtil::our_priority != 0x7fffffff )
1053924 {
1054925 // try
1055− if( !Chuck_VM::set_priority( Chuck_VM::our_priority, vm ) )
926+ if( !XThreadUtil::set_priority( XThreadUtil::our_priority ) )
1056927 {
1057928 // error
1058− CK_FPRINTF_STDERR( "[chuck]: %s\n", vm->last_error() );
929+ CK_FPRINTF_STDERR( "[chuck]: error setting thread priority...\n" );
1059930 exit( 1 );
1060931 }
1061932 }
1062933
1063934
1064− //----------------------- ON-THE-FLY SERVER SETUP -----------------------------
1065−
1066− // server
1067− if( enable_server )
1068− {
1069−#ifndef __DISABLE_OTF_SERVER__
1070− // log
1071− EM_log( CK_LOG_SYSTEM, "starting listener on port: %d...", g_port );
1072−
1073− // start tcp server
1074− g_sock = ck_tcp_create( 1 );
1075− if( !g_sock || !ck_bind( g_sock, g_port ) || !ck_listen( g_sock, 10 ) )
1076− {
1077− CK_FPRINTF_STDERR( "[chuck]: cannot bind to tcp port %li...\n", g_port );
1078− ck_close( g_sock );
1079− g_sock = NULL;
1080− }
1081− else
1082− {
1083−#if !defined(__PLATFORM_WIN32__) || defined(__WINDOWS_PTHREAD__)
1084− pthread_create( &g_tid_otf, NULL, otf_cb, NULL );
1085−#else
1086− g_tid_otf = CreateThread( NULL, 0, (LPTHREAD_START_ROUTINE)otf_cb, NULL, 0, 0 );
1087−#endif
1088− }
1089−#endif // __DISABLE_OTF_SERVER__
1090− }
1091− else
1092− {
1093− // log
1094− EM_log( CK_LOG_SYSTEM, "OTF server/listener: OFF" );
1095− }
935+ //----------------------- SHELL SETUP -----------------------------
1096936
1097− // start shell on separate thread
937+ // start shell on separate thread | REFACTOR-2017: per-VM?!?
1098938 if( g_enable_shell )
1099939 {
1100940 #if !defined(__PLATFORM_WIN32__) || defined(__WINDOWS_PTHREAD__)
@@ -1104,7 +944,6 @@ bool go( int argc, const char ** argv ) · 3 unmodified lines
1104944 #endif
1105945 }
1106946
1107−
1108947 //-------------------------- MAIN CHUCK LOOP!!! -----------------------------
1109948
1110949 // log
@@ -1112,65 +951,14 @@ bool go( int argc, const char ** argv ) · 1 unmodified line
1112951 // push indent
1113952 EM_pushlog();
1114953
1115− // set run state
1116− vm->start();
1117−
1118− EM_log( CK_LOG_SEVERE, "initializing audio buffers..." );
1119− if( !bbq->digi_out()->initialize( ) )
1120− {
1121− EM_log( CK_LOG_SYSTEM,
1122− "cannot open audio output (use --silent/-s)" );
1123− exit(1);
1124− }
1125−
1126− // initialize input
1127− bbq->digi_in()->initialize( );
954+ // start it!
955+ the_chuck->start();
1128956
1129957 // log
1130958 EM_log( CK_LOG_SEVERE, "virtual machine running..." );
1131959 // pop indent
1132960 EM_poplog();
1133961
1134− // NOTE: non-blocking callback only, ge: 1.3.5.3
1135−
1136− // compute shreds before first sample
1137− if( !vm->compute() )
1138− {
1139− // done, 1.3.5.3
1140− vm->stop();
1141− // log
1142− EM_log( CK_LOG_SYSTEM, "virtual machine stopped..." );
1143− }
1144−
1145− // check client mode
1146− if( clientMode )
1147− {
1148− // done!
1149− return TRUE;
1150− }
1151−
1152− // start audio
1153− if( !audio_started )
1154− {
1155− // audio
1156− if( !audio_started && g_enable_realtime_audio )
1157− {
1158− EM_log( CK_LOG_SEVERE, "starting real-time audio..." );
1159− bbq->digi_out()->start();
1160− bbq->digi_in()->start();
1161− }
1162−
1163− // set the flag to true to avoid entering this function
1164− audio_started = TRUE;
1165− }
1166−
1167−
1168− // Don't run audio callback and shut down if we only wanted to init here
1169− if( m_initOnly ) {
1170− return TRUE;
1171− }
1172−
1173−
1174962 // silent mode buffers
1175963 SAMPLE * input = new SAMPLE[buffer_size*adc_chans];
1176964 SAMPLE * output = new SAMPLE[buffer_size*dac_chans];
@@ -1179,25 +967,20 @@ bool go( int argc, const char ** argv ) · 2 unmodified lines
1179967 memset( output, 0, sizeof(SAMPLE)*buffer_size*dac_chans );
1180968
1181969 // wait
1182− while( vm->running() )
970+ while( the_chuck->vm()->running() )
1183971 {
1184972 // real-time audio
1185973 if( g_enable_realtime_audio )
1186974 {
1187− if( g_main_thread_hook && g_main_thread_quit )
1188− g_main_thread_hook( g_main_thread_bindle );
1189− else
1190− usleep( 1000 );
975+ usleep( 10000 );
1191976 }
1192977 else // silent mode
1193978 {
1194979 // keep running as fast as possible
1195− this->run( input, output, buffer_size );
980+ the_chuck->run( input, output, buffer_size );
1196981 }
1197982 }
1198983
1199− // shutdown
1200− clientShutdown();
1201−
1202984 return TRUE;
1203985 }
986+

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