History

implement replace and reset buttons

Jack Atherton committed 7 years ago

Commit d93656a1 parent 83d1ae85 files · +340 −38Browse files

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

Unified · Split

src/host_web/chuck_emscripten.cpp+175−19
@@ -24,7 +24,7 @@ extern "C" · 23 unmodified lines
2424
2525
2626 // C# "string" corresponds to passing char *
27− t_CKINT EMSCRIPTEN_KEEPALIVE runChuckCode( unsigned int chuckID, const char * code )
27+ t_CKUINT EMSCRIPTEN_KEEPALIVE runChuckCode( unsigned int chuckID, const char * code )
2828 {
2929 if( chuck_instances.count( chuckID ) == 0 ) { return -1; }
3030
@@ -36,18 +36,17 @@ extern "C" · 5 unmodified lines
3636 if( chuck_instances[chuckID]->compileCode(
3737 std::string( code ), std::string("") ) )
3838 {
39− // id is a UINT so will never be -1 (unless you spork something
40− // every sample for 26 hours)
39+ // last shred shredded
4140 return chuck_instances[chuckID]->vm()->last_id();
4241
4342 }
4443 // failure to compile
45− return -1;
44+ return 0;
4645 }
4746
4847
4948
50− t_CKINT EMSCRIPTEN_KEEPALIVE runChuckCodeWithReplacementDac(
49+ t_CKUINT EMSCRIPTEN_KEEPALIVE runChuckCodeWithReplacementDac(
5150 unsigned int chuckID, const char * code, const char * replacement_dac )
5251 {
5352 if( chuck_instances.count( chuckID ) == 0 ) { return -1; }
@@ -65,18 +64,16 @@ extern "C" · 11 unmodified lines
6564
6665 if( result )
6766 {
68− // id is a UINT so will never be -1 (unless you spork something
69− // every sample for 26 hours)
67+ // last shred shredded
7068 return chuck_instances[chuckID]->vm()->last_id();
71−
7269 }
7370 // failure to compile
74− return -1;
71+ return 0;
7572 }
7673
7774
7875
79− t_CKINT EMSCRIPTEN_KEEPALIVE runChuckFile( unsigned int chuckID,
76+ t_CKUINT EMSCRIPTEN_KEEPALIVE runChuckFile( unsigned int chuckID,
8077 const char * filename )
8178 {
8279 // run with empty args
@@ -85,7 +82,7 @@ extern "C" · 2 unmodified lines
8582
8683
8784
88− t_CKINT EMSCRIPTEN_KEEPALIVE runChuckFileWithArgs( unsigned int chuckID,
85+ t_CKUINT EMSCRIPTEN_KEEPALIVE runChuckFileWithArgs( unsigned int chuckID,
8986 const char * filename, const char * args )
9087 {
9188 if( chuck_instances.count( chuckID ) == 0 ) { return -1; }
@@ -98,18 +95,17 @@ extern "C" · 6 unmodified lines
9895 if( chuck_instances[chuckID]->compileFile(
9996 std::string( filename ), std::string( args ) ) )
10097 {
101− // id is a UINT so will never be -1 (unless you spork something
102− // every sample for 26 hours)
98+ // last shred shredded
10399 return chuck_instances[chuckID]->vm()->last_id();
104100
105101 }
106102 // failure to compile
107− return -1;
103+ return 0;
108104 }
109105
110106
111107
112− t_CKINT EMSCRIPTEN_KEEPALIVE runChuckFileWithReplacementDac(
108+ t_CKUINT EMSCRIPTEN_KEEPALIVE runChuckFileWithReplacementDac(
113109 unsigned int chuckID, const char * filename,
114110 const char * replacement_dac )
115111 {
@@ -121,7 +117,7 @@ extern "C" · 5 unmodified lines
121117
122118
123119
124− t_CKINT EMSCRIPTEN_KEEPALIVE runChuckFileWithArgsWithReplacementDac(
120+ t_CKUINT EMSCRIPTEN_KEEPALIVE runChuckFileWithArgsWithReplacementDac(
125121 unsigned int chuckID, const char * filename, const char * args,
126122 const char * replacement_dac )
127123 {
@@ -141,13 +137,173 @@ extern "C" · 13 unmodified lines
141137
142138 if( result )
143139 {
144− // id is a UINT so will never be -1 (unless you spork something
145− // every sample for 26 hours)
140+ // last shred shredded
146141 return chuck_instances[chuckID]->vm()->last_id();
147142
148143 }
149144 // failure to compile
150− return -1;
145+ return 0;
146+ }
147+
148+
149+
150+ t_CKUINT replaceCode( ChucK * chuck, t_CKUINT shredID,
151+ std::vector<std::string> * args )
152+ {
153+ Chuck_Msg * msg = new Chuck_Msg;
154+ msg->type = MSG_REPLACE;
155+ msg->code = chuck->compiler()->output();
156+ msg->param = shredID;
157+ // null reply so that VM will delete for us when it's done
158+ msg->reply = ( ck_msg_func )NULL;
159+ msg->args = args;
160+
161+ // call the process_msg directly: we need to know the shred ID
162+ // and it's JS so we won't be pre-empted
163+ // also: return value is the shred ID!
164+ return chuck->vm()->process_msg( msg );
165+ }
166+
167+
168+
169+ t_CKUINT EMSCRIPTEN_KEEPALIVE replaceChuckCode( unsigned int chuckID, unsigned int shredID, const char * code )
170+ {
171+ if( chuck_instances.count( chuckID ) == 0 ) { return -1; }
172+
173+ // don't want to replace dac
174+ // (a safeguard in case compiler got interrupted while replacing dac)
175+ chuck_instances[chuckID]->compiler()->setReplaceDac( FALSE, "" );
176+
177+ // compile it! and spork 0 times. (ONLY compile)
178+ if( chuck_instances[chuckID]->compileCode(
179+ std::string( code ), std::string(""), 0 ) )
180+ {
181+ // replace code
182+ return replaceCode( chuck_instances[chuckID], shredID, NULL );
183+ }
184+ // failure to compile
185+ return 0;
186+ }
187+
188+
189+
190+ t_CKUINT EMSCRIPTEN_KEEPALIVE replaceChuckCodeWithReplacementDac( unsigned int chuckID, unsigned int shredID, const char * code, const char * replacement_dac )
191+ {
192+ if( chuck_instances.count( chuckID ) == 0 ) { return -1; }
193+
194+ // replace dac
195+ chuck_instances[chuckID]->compiler()->setReplaceDac( TRUE,
196+ std::string( replacement_dac ) );
197+
198+ // compile it! and spork 0 times. (ONLY compile)
199+ bool result = chuck_instances[chuckID]->compileCode(
200+ std::string( code ), std::string(""), 0 );
201+
202+ // don't replace dac for future compilations
203+ chuck_instances[chuckID]->compiler()->setReplaceDac( FALSE, "" );
204+
205+ if( result )
206+ {
207+ // replace code
208+ return replaceCode( chuck_instances[chuckID], shredID, NULL );
209+ }
210+ // failure to compile
211+ return 0;
212+ }
213+
214+
215+
216+ t_CKUINT EMSCRIPTEN_KEEPALIVE replaceChuckFile( unsigned int chuckID, unsigned int shredID, const char * filename )
217+ {
218+ // replace with empty args
219+ return replaceChuckFileWithArgs( chuckID, shredID, filename, "" );
220+ }
221+
222+
223+
224+ t_CKUINT EMSCRIPTEN_KEEPALIVE replaceChuckFileWithReplacementDac( unsigned int chuckID, unsigned int shredID, const char * filename, const char * replacement_dac )
225+ {
226+ // replace with empty args
227+ return replaceChuckFileWithArgsWithReplacementDac( chuckID, shredID,
228+ filename, "", replacement_dac );
229+ }
230+
231+
232+
233+ t_CKUINT EMSCRIPTEN_KEEPALIVE replaceChuckFileWithArgs( unsigned int chuckID, unsigned int shredID, const char * filename, const char * args )
234+ {
235+ if( chuck_instances.count( chuckID ) == 0 ) { return -1; }
236+
237+ // don't want to replace dac
238+ // (a safeguard in case compiler got interrupted while replacing dac)
239+ chuck_instances[chuckID]->compiler()->setReplaceDac( FALSE, "" );
240+
241+ std::string filenameS( filename );
242+ std::string argsS( args );
243+
244+ // compile it! and spork 0 times. (ONLY compile)
245+ if( chuck_instances[chuckID]->compileFile( filenameS, argsS, 0 ) )
246+ {
247+ // find args
248+ std::string found_filename;
249+ std::vector<std::string> found_args;
250+ std::string together = filenameS + ":" + argsS;
251+ // parse out command line arguments
252+ if( !extract_args( together, found_filename, found_args ) )
253+ {
254+ // error
255+ CK_FPRINTF_STDERR( "[chuck]: malformed filename with argument list...\n" );
256+ CK_FPRINTF_STDERR( " --> '%s'", together.c_str() );
257+ return 0;
258+ }
259+
260+ // replace code
261+ return replaceCode( chuck_instances[chuckID], shredID, & found_args );
262+ }
263+ // failure to compile
264+ return 0;
265+ }
266+
267+
268+
269+ t_CKUINT EMSCRIPTEN_KEEPALIVE replaceChuckFileWithArgsWithReplacementDac( unsigned int chuckID, unsigned int shredID, const char * filename, const char * args, const char * replacement_dac )
270+ {
271+ if( chuck_instances.count( chuckID ) == 0 ) { return -1; }
272+
273+ // replace dac
274+ chuck_instances[chuckID]->compiler()->setReplaceDac( TRUE,
275+ std::string( replacement_dac ) );
276+
277+ std::string filenameS( filename );
278+ std::string argsS( args );
279+
280+ // compile it! and spork 0 times. (ONLY compile)
281+ bool result = chuck_instances[chuckID]->compileFile( filenameS, argsS, 0 );
282+
283+ // don't replace dac for future compilations
284+ chuck_instances[chuckID]->compiler()->setReplaceDac( FALSE, "" );
285+
286+ if( result )
287+ {
288+ // find args
289+ std::string found_filename;
290+ std::vector<std::string> found_args;
291+ std::string together = filenameS + ":" + argsS;
292+ // parse out command line arguments
293+ if( !extract_args( together, found_filename, found_args ) )
294+ {
295+ // error
296+ CK_FPRINTF_STDERR( "[chuck]: malformed filename with argument list...\n" );
297+ CK_FPRINTF_STDERR( " --> '%s'", together.c_str() );
298+ return 0;
299+ }
300+
301+ // replace code
302+ return replaceCode( chuck_instances[chuckID], shredID, & found_args );
303+
304+ }
305+ // failure to compile
306+ return 0;
151307 }
152308
153309

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