@@ -2299,113 +2299,97 @@ hook_before_rewind(rb_execution_context_t *ec, const rb_control_frame_t *cfp,
2299
2299
static inline VALUE
2300
2300
vm_exec_handle_exception (rb_execution_context_t * ec , enum ruby_tag_type state , VALUE errinfo );
2301
2301
2302
- // for non-Emscripten Wasm build, use vm_exec with optimized setjmp for runtime performance
2303
- #if defined(__wasm__ ) && !defined(__EMSCRIPTEN__ )
2304
-
2305
- struct rb_vm_exec_context {
2306
- rb_execution_context_t * ec ;
2307
- struct rb_vm_tag * tag ;
2308
- VALUE result ;
2309
- enum ruby_tag_type state ;
2310
- };
2311
-
2312
- static void
2313
- vm_exec_enter_vm_loop (rb_execution_context_t * ec , struct rb_vm_exec_context * ctx ,
2314
- struct rb_vm_tag * _tag , bool skip_first_ex_handle )
2302
+ static VALUE
2303
+ vm_exec_loop (rb_execution_context_t * ec , enum ruby_tag_type state ,
2304
+ struct rb_vm_tag * _tag , VALUE result )
2315
2305
{
2316
- if (skip_first_ex_handle ) {
2306
+ if (state == TAG_NONE ) { /* no jumps, result is discarded */
2317
2307
goto vm_loop_start ;
2318
2308
}
2319
2309
2320
- ctx -> result = ec -> errinfo ;
2321
2310
rb_ec_raised_reset (ec , RAISED_STACKOVERFLOW | RAISED_NOMEMORY );
2322
- while (UNDEF_P (ctx -> result = vm_exec_handle_exception (ec , ctx -> state , ctx -> result ))) {
2311
+ while (UNDEF_P (result = vm_exec_handle_exception (ec , state , result ))) {
2323
2312
/* caught a jump, exec the handler */
2324
- ctx -> result = vm_exec_core (ec );
2325
- vm_loop_start :
2313
+ result = vm_exec_core (ec );
2314
+ vm_loop_start :
2326
2315
VM_ASSERT (ec -> tag == _tag );
2327
2316
/* when caught `throw`, `tag.state` is set. */
2328
- if ((ctx -> state = _tag -> state ) == TAG_NONE ) break ;
2317
+ if ((state = _tag -> state ) == TAG_NONE ) break ;
2329
2318
_tag -> state = TAG_NONE ;
2330
2319
}
2320
+
2321
+ return result ;
2331
2322
}
2332
2323
2324
+ struct rb_vm_exec_context {
2325
+ rb_execution_context_t * const ec ;
2326
+ struct rb_vm_tag * const tag ;
2327
+
2328
+ VALUE result ;
2329
+ };
2330
+
2331
+ // for non-Emscripten Wasm build, use vm_exec with optimized setjmp for runtime performance
2332
+ #if defined(__wasm__ ) && !defined(__EMSCRIPTEN__ )
2333
+
2333
2334
static void
2334
2335
vm_exec_bottom_main (void * context )
2335
2336
{
2336
- struct rb_vm_exec_context * ctx = (struct rb_vm_exec_context * )context ;
2337
+ struct rb_vm_exec_context * ctx = context ;
2338
+ rb_execution_context_t * ec = ctx -> ec ;
2337
2339
2338
- ctx -> state = TAG_NONE ;
2339
- ctx -> result = vm_exec_core (ctx -> ec );
2340
- vm_exec_enter_vm_loop (ctx -> ec , ctx , ctx -> tag , true);
2340
+ ctx -> result = vm_exec_loop (ec , TAG_NONE , ctx -> tag , vm_exec_core (ec ));
2341
2341
}
2342
2342
2343
2343
static void
2344
2344
vm_exec_bottom_rescue (void * context )
2345
2345
{
2346
- struct rb_vm_exec_context * ctx = (struct rb_vm_exec_context * )context ;
2347
- ctx -> state = rb_ec_tag_state (ctx -> ec );
2348
- vm_exec_enter_vm_loop (ctx -> ec , ctx , ctx -> tag , false);
2346
+ struct rb_vm_exec_context * ctx = context ;
2347
+ rb_execution_context_t * ec = ctx -> ec ;
2348
+
2349
+ ctx -> result = vm_exec_loop (ec , rb_ec_tag_state (ec ), ctx -> tag , ec -> errinfo );
2349
2350
}
2351
+ #endif
2350
2352
2351
2353
VALUE
2352
2354
vm_exec (rb_execution_context_t * ec )
2353
2355
{
2354
- struct rb_vm_exec_context ctx = {
2355
- .ec = ec ,
2356
- .result = Qundef ,
2357
- };
2358
- struct rb_wasm_try_catch try_catch ;
2356
+ VALUE result = Qundef ;
2359
2357
2360
2358
EC_PUSH_TAG (ec );
2361
2359
2362
2360
_tag .retval = Qnil ;
2363
- ctx .tag = & _tag ;
2361
+
2362
+ #if defined(__wasm__ ) && !defined(__EMSCRIPTEN__ )
2363
+ struct rb_vm_exec_context ctx = {
2364
+ .ec = ec ,
2365
+ .tag = & _tag ,
2366
+ };
2367
+ struct rb_wasm_try_catch try_catch ;
2364
2368
2365
2369
EC_REPUSH_TAG ();
2366
2370
2367
2371
rb_wasm_try_catch_init (& try_catch , vm_exec_bottom_main , vm_exec_bottom_rescue , & ctx );
2368
2372
2369
2373
rb_wasm_try_catch_loop_run (& try_catch , & _tag .buf );
2370
2374
2371
- EC_POP_TAG ();
2372
- return ctx .result ;
2373
- }
2374
-
2375
+ result = ctx .result ;
2375
2376
#else
2376
-
2377
- VALUE
2378
- vm_exec (rb_execution_context_t * ec )
2379
- {
2380
2377
enum ruby_tag_type state ;
2381
- VALUE result = Qundef ;
2382
-
2383
- EC_PUSH_TAG (ec );
2384
-
2385
- _tag .retval = Qnil ;
2386
2378
if ((state = EC_EXEC_TAG ()) == TAG_NONE ) {
2387
2379
if (UNDEF_P (result = jit_exec (ec ))) {
2388
2380
result = vm_exec_core (ec );
2389
2381
}
2390
- goto vm_loop_start ; /* fallback to the VM */
2382
+ /* fallback to the VM */
2383
+ result = vm_exec_loop (ec , TAG_NONE , & _tag , result );
2391
2384
}
2392
2385
else {
2393
- result = ec -> errinfo ;
2394
- rb_ec_raised_reset (ec , RAISED_STACKOVERFLOW | RAISED_NOMEMORY );
2395
- while (UNDEF_P (result = vm_exec_handle_exception (ec , state , result ))) {
2396
- /* caught a jump, exec the handler */
2397
- result = vm_exec_core (ec );
2398
- vm_loop_start :
2399
- VM_ASSERT (ec -> tag == & _tag );
2400
- /* when caught `throw`, `tag.state` is set. */
2401
- if ((state = _tag .state ) == TAG_NONE ) break ;
2402
- _tag .state = TAG_NONE ;
2403
- }
2386
+ result = vm_exec_loop (ec , state , & _tag , ec -> errinfo );
2404
2387
}
2388
+ #endif
2389
+
2405
2390
EC_POP_TAG ();
2406
2391
return result ;
2407
2392
}
2408
- #endif
2409
2393
2410
2394
static inline VALUE
2411
2395
vm_exec_handle_exception (rb_execution_context_t * ec , enum ruby_tag_type state , VALUE errinfo )
0 commit comments