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 | // C# "string" corresponds to passing char * | 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 | if( chuck_instances.count( chuckID ) == 0 ) { return -1; } | 29 | if( chuck_instances.count( chuckID ) == 0 ) { return -1; } |
| 30 | 30 | ||
| @@ -36,18 +36,17 @@ extern "C" · 5 unmodified lines | |||
| 36 | if( chuck_instances[chuckID]->compileCode( | 36 | if( chuck_instances[chuckID]->compileCode( |
| 37 | std::string( code ), std::string("") ) ) | 37 | std::string( code ), std::string("") ) ) |
| 38 | { | 38 | { |
| 39 | // id is a UINT so will never be -1 (unless you spork something | 39 | // last shred shredded |
| 40 | // every sample for 26 hours) | ||
| 41 | return chuck_instances[chuckID]->vm()->last_id(); | 40 | return chuck_instances[chuckID]->vm()->last_id(); |
| 42 | 41 | ||
| 43 | } | 42 | } |
| 44 | // failure to compile | 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 | unsigned int chuckID, const char * code, const char * replacement_dac ) | 50 | unsigned int chuckID, const char * code, const char * replacement_dac ) |
| 52 | { | 51 | { |
| 53 | if( chuck_instances.count( chuckID ) == 0 ) { return -1; } | 52 | if( chuck_instances.count( chuckID ) == 0 ) { return -1; } |
| @@ -65,18 +64,16 @@ extern "C" · 11 unmodified lines | |||
| 65 | 64 | ||
| 66 | if( result ) | 65 | if( result ) |
| 67 | { | 66 | { |
| 68 | // id is a UINT so will never be -1 (unless you spork something | 67 | // last shred shredded |
| 69 | // every sample for 26 hours) | ||
| 70 | return chuck_instances[chuckID]->vm()->last_id(); | 68 | return chuck_instances[chuckID]->vm()->last_id(); |
| 71 | |||
| 72 | } | 69 | } |
| 73 | // failure to compile | 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 | const char * filename ) | 77 | const char * filename ) |
| 81 | { | 78 | { |
| 82 | // run with empty args | 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 | const char * filename, const char * args ) | 86 | const char * filename, const char * args ) |
| 90 | { | 87 | { |
| 91 | if( chuck_instances.count( chuckID ) == 0 ) { return -1; } | 88 | if( chuck_instances.count( chuckID ) == 0 ) { return -1; } |
| @@ -98,18 +95,17 @@ extern "C" · 6 unmodified lines | |||
| 98 | if( chuck_instances[chuckID]->compileFile( | 95 | if( chuck_instances[chuckID]->compileFile( |
| 99 | std::string( filename ), std::string( args ) ) ) | 96 | std::string( filename ), std::string( args ) ) ) |
| 100 | { | 97 | { |
| 101 | // id is a UINT so will never be -1 (unless you spork something | 98 | // last shred shredded |
| 102 | // every sample for 26 hours) | ||
| 103 | return chuck_instances[chuckID]->vm()->last_id(); | 99 | return chuck_instances[chuckID]->vm()->last_id(); |
| 104 | 100 | ||
| 105 | } | 101 | } |
| 106 | // failure to compile | 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 | unsigned int chuckID, const char * filename, | 109 | unsigned int chuckID, const char * filename, |
| 114 | const char * replacement_dac ) | 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 | unsigned int chuckID, const char * filename, const char * args, | 121 | unsigned int chuckID, const char * filename, const char * args, |
| 126 | const char * replacement_dac ) | 122 | const char * replacement_dac ) |
| 127 | { | 123 | { |
| @@ -141,13 +137,173 @@ extern "C" · 13 unmodified lines | |||
| 141 | 137 | ||
| 142 | if( result ) | 138 | if( result ) |
| 143 | { | 139 | { |
| 144 | // id is a UINT so will never be -1 (unless you spork something | 140 | // last shred shredded |
| 145 | // every sample for 26 hours) | ||
| 146 | return chuck_instances[chuckID]->vm()->last_id(); | 141 | return chuck_instances[chuckID]->vm()->last_id(); |
| 147 | 142 | ||
| 148 | } | 143 | } |
| 149 | // failure to compile | 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 | ||