Showing the changes to src/host_web/chuck_emscripten.cpp (1 of 5 files). Show all
Unified · Split
| @@ -24,7 +24,7 @@ extern "C" · 23 unmodified lines | ||
| 24 | 24 | |
| 25 | 25 | |
| 26 | 26 | // 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 ) | |
| 28 | 28 | { |
| 29 | 29 | if( chuck_instances.count( chuckID ) == 0 ) { return -1; } |
| 30 | 30 | |
| @@ -36,18 +36,17 @@ extern "C" · 5 unmodified lines | ||
| 36 | 36 | if( chuck_instances[chuckID]->compileCode( |
| 37 | 37 | std::string( code ), std::string("") ) ) |
| 38 | 38 | { |
| 39 | − // id is a UINT so will never be -1 (unless you spork something | |
| 40 | − // every sample for 26 hours) | |
| 39 | + // last shred shredded | |
| 41 | 40 | return chuck_instances[chuckID]->vm()->last_id(); |
| 42 | 41 | |
| 43 | 42 | } |
| 44 | 43 | // failure to compile |
| 45 | − return -1; | |
| 44 | + return 0; | |
| 46 | 45 | } |
| 47 | 46 | |
| 48 | 47 | |
| 49 | 48 | |
| 50 | − t_CKINT EMSCRIPTEN_KEEPALIVE runChuckCodeWithReplacementDac( | |
| 49 | + t_CKUINT EMSCRIPTEN_KEEPALIVE runChuckCodeWithReplacementDac( | |
| 51 | 50 | unsigned int chuckID, const char * code, const char * replacement_dac ) |
| 52 | 51 | { |
| 53 | 52 | if( chuck_instances.count( chuckID ) == 0 ) { return -1; } |
| @@ -65,18 +64,16 @@ extern "C" · 11 unmodified lines | ||
| 65 | 64 | |
| 66 | 65 | if( result ) |
| 67 | 66 | { |
| 68 | − // id is a UINT so will never be -1 (unless you spork something | |
| 69 | − // every sample for 26 hours) | |
| 67 | + // last shred shredded | |
| 70 | 68 | return chuck_instances[chuckID]->vm()->last_id(); |
| 71 | − | |
| 72 | 69 | } |
| 73 | 70 | // failure to compile |
| 74 | − return -1; | |
| 71 | + return 0; | |
| 75 | 72 | } |
| 76 | 73 | |
| 77 | 74 | |
| 78 | 75 | |
| 79 | − t_CKINT EMSCRIPTEN_KEEPALIVE runChuckFile( unsigned int chuckID, | |
| 76 | + t_CKUINT EMSCRIPTEN_KEEPALIVE runChuckFile( unsigned int chuckID, | |
| 80 | 77 | const char * filename ) |
| 81 | 78 | { |
| 82 | 79 | // run with empty args |
| @@ -85,7 +82,7 @@ extern "C" · 2 unmodified lines | ||
| 85 | 82 | |
| 86 | 83 | |
| 87 | 84 | |
| 88 | − t_CKINT EMSCRIPTEN_KEEPALIVE runChuckFileWithArgs( unsigned int chuckID, | |
| 85 | + t_CKUINT EMSCRIPTEN_KEEPALIVE runChuckFileWithArgs( unsigned int chuckID, | |
| 89 | 86 | const char * filename, const char * args ) |
| 90 | 87 | { |
| 91 | 88 | if( chuck_instances.count( chuckID ) == 0 ) { return -1; } |
| @@ -98,18 +95,17 @@ extern "C" · 6 unmodified lines | ||
| 98 | 95 | if( chuck_instances[chuckID]->compileFile( |
| 99 | 96 | std::string( filename ), std::string( args ) ) ) |
| 100 | 97 | { |
| 101 | − // id is a UINT so will never be -1 (unless you spork something | |
| 102 | − // every sample for 26 hours) | |
| 98 | + // last shred shredded | |
| 103 | 99 | return chuck_instances[chuckID]->vm()->last_id(); |
| 104 | 100 | |
| 105 | 101 | } |
| 106 | 102 | // failure to compile |
| 107 | − return -1; | |
| 103 | + return 0; | |
| 108 | 104 | } |
| 109 | 105 | |
| 110 | 106 | |
| 111 | 107 | |
| 112 | − t_CKINT EMSCRIPTEN_KEEPALIVE runChuckFileWithReplacementDac( | |
| 108 | + t_CKUINT EMSCRIPTEN_KEEPALIVE runChuckFileWithReplacementDac( | |
| 113 | 109 | unsigned int chuckID, const char * filename, |
| 114 | 110 | const char * replacement_dac ) |
| 115 | 111 | { |
| @@ -121,7 +117,7 @@ extern "C" · 5 unmodified lines | ||
| 121 | 117 | |
| 122 | 118 | |
| 123 | 119 | |
| 124 | − t_CKINT EMSCRIPTEN_KEEPALIVE runChuckFileWithArgsWithReplacementDac( | |
| 120 | + t_CKUINT EMSCRIPTEN_KEEPALIVE runChuckFileWithArgsWithReplacementDac( | |
| 125 | 121 | unsigned int chuckID, const char * filename, const char * args, |
| 126 | 122 | const char * replacement_dac ) |
| 127 | 123 | { |
| @@ -141,13 +137,173 @@ extern "C" · 13 unmodified lines | ||
| 141 | 137 | |
| 142 | 138 | if( result ) |
| 143 | 139 | { |
| 144 | − // id is a UINT so will never be -1 (unless you spork something | |
| 145 | − // every sample for 26 hours) | |
| 140 | + // last shred shredded | |
| 146 | 141 | return chuck_instances[chuckID]->vm()->last_id(); |
| 147 | 142 | |
| 148 | 143 | } |
| 149 | 144 | // 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; | |
| 151 | 307 | } |
| 152 | 308 | |
| 153 | 309 | |