3
3
#include "ruby.h"
4
4
#include "ruby/version.h"
5
5
6
- static VALUE rb_eval_string_value_protect_thunk (VALUE str ) {
6
+ #include "types.h"
7
+
8
+ static VALUE rb_eval_string_value_protect_thunk (VALUE ctx ) {
9
+ const rb_abi_guest_string_t * cabi_str = (const rb_abi_guest_string_t * )ctx ;
10
+ VALUE str = rb_utf8_str_new ((const char * )cabi_str -> ptr , cabi_str -> len );
7
11
const ID id_eval = rb_intern ("eval" );
8
12
VALUE binding = rb_const_get (rb_cObject , rb_intern ("TOPLEVEL_BINDING" ));
9
13
const VALUE file = rb_utf8_str_new ("eval" , 4 );
10
14
VALUE args [3 ] = {str , binding , file };
11
15
return rb_funcallv (rb_mKernel , id_eval , 3 , args );
12
16
}
13
17
14
- static VALUE rb_eval_string_value_protect (VALUE str , int * pstate ) {
15
- return rb_protect (rb_eval_string_value_protect_thunk , str , pstate );
18
+ static VALUE rb_eval_string_value_protect (const rb_abi_guest_string_t * str ,
19
+ int * pstate ) {
20
+ return rb_protect (rb_eval_string_value_protect_thunk , (VALUE )str , pstate );
16
21
}
17
22
18
23
#define TAG_NONE 0
19
24
20
- #include "types.h"
21
-
22
25
__attribute__((import_module ("asyncify" ), import_name ("start_unwind" ))) void
23
26
asyncify_start_unwind (void * buf );
24
27
#define asyncify_start_unwind (buf ) \
@@ -200,15 +203,17 @@ void exports_ruby_js_ruby_runtime_rb_abi_value_destructor(
200
203
201
204
void rb_abi_guest_ruby_show_version (void ) { ruby_show_version (); }
202
205
203
- void rb_abi_guest_ruby_init (void ) {
204
- RB_WASM_LIB_RT (ruby_init ())
205
-
206
+ __attribute__((noinline )) static void rb_abi_guest_ruby_init_thunk (void ) {
207
+ ruby_init ();
206
208
rb_abi_guest_arena_hash = rb_hash_new ();
207
209
rb_abi_guest_refcount_hash = rb_hash_new ();
208
210
209
211
rb_gc_register_mark_object (rb_abi_guest_arena_hash );
210
212
rb_gc_register_mark_object (rb_abi_guest_refcount_hash );
211
213
}
214
+ void rb_abi_guest_ruby_init (void ) {
215
+ RB_WASM_LIB_RT (rb_abi_guest_ruby_init_thunk ())
216
+ }
212
217
213
218
void rb_abi_guest_ruby_sysinit (rb_abi_guest_list_string_t * args ) {
214
219
char * * c_args ;
@@ -234,12 +239,11 @@ void rb_abi_guest_ruby_init_loadpath(void) {
234
239
RB_WASM_LIB_RT (ruby_init_loadpath ())
235
240
}
236
241
237
- void rb_abi_guest_rb_eval_string_protect (
242
+ __attribute__(( noinline )) static void rb_abi_guest_rb_eval_string_protect_thunk (
238
243
rb_abi_guest_string_t * str , rb_abi_guest_tuple2_rb_abi_value_s32_t * ret0 ) {
239
244
VALUE retval ;
240
245
RB_WASM_DEBUG_LOG ("rb_eval_string_protect: str = %s\n" , str -> ptr );
241
- VALUE utf8_str = rb_utf8_str_new ((const char * )str -> ptr , str -> len );
242
- RB_WASM_LIB_RT (retval = rb_eval_string_value_protect (utf8_str , & ret0 -> f1 ));
246
+ retval = rb_eval_string_value_protect (str , & ret0 -> f1 );
243
247
RB_WASM_DEBUG_LOG ("rb_eval_string_protect: retval = %p, state = %d\n" ,
244
248
(void * )retval , ret0 -> f1 );
245
249
@@ -248,6 +252,10 @@ void rb_abi_guest_rb_eval_string_protect(
248
252
}
249
253
ret0 -> f0 = rb_abi_guest_rb_abi_value_new ((void * )retval );
250
254
}
255
+ void rb_abi_guest_rb_eval_string_protect (
256
+ rb_abi_guest_string_t * str , rb_abi_guest_tuple2_rb_abi_value_s32_t * ret0 ) {
257
+ RB_WASM_LIB_RT (rb_abi_guest_rb_eval_string_protect_thunk (str , ret0 ));
258
+ }
251
259
252
260
struct rb_funcallv_thunk_ctx {
253
261
VALUE recv ;
@@ -284,7 +292,9 @@ void rb_abi_guest_rb_funcallv_protect(
284
292
}
285
293
286
294
rb_abi_guest_rb_id_t rb_abi_guest_rb_intern (rb_abi_guest_string_t * name ) {
287
- return rb_intern ((const char * )name -> ptr );
295
+ VALUE retval ;
296
+ RB_WASM_LIB_RT (retval = rb_intern ((const char * )name -> ptr ));
297
+ return (rb_abi_guest_rb_id_t )retval ;
288
298
}
289
299
290
300
rb_abi_guest_own_rb_abi_value_t rb_abi_guest_rb_errinfo (void ) {
@@ -294,16 +304,24 @@ rb_abi_guest_own_rb_abi_value_t rb_abi_guest_rb_errinfo(void) {
294
304
return rb_abi_guest_rb_abi_value_new ((void * )retval );
295
305
}
296
306
297
- void rb_abi_guest_rb_clear_errinfo (void ) { rb_set_errinfo (Qnil ); }
307
+ void rb_abi_guest_rb_clear_errinfo (void ) {
308
+ RB_WASM_LIB_RT (rb_set_errinfo (Qnil ));
309
+ }
298
310
299
- void rb_abi_guest_rstring_ptr (rb_abi_guest_rb_abi_value_t value ,
300
- rb_abi_guest_string_t * ret0 ) {
311
+ __attribute__((noinline )) static void
312
+ rb_abi_guest_rstring_ptr_thunk (rb_abi_guest_rb_abi_value_t value ,
313
+ rb_abi_guest_string_t * ret0 ) {
301
314
VALUE r_str = (VALUE )rb_abi_guest_rb_abi_value_get (& value );
302
315
ret0 -> len = RSTRING_LEN (r_str );
303
316
ret0 -> ptr = xmalloc (ret0 -> len );
304
317
memcpy (ret0 -> ptr , RSTRING_PTR (r_str ), ret0 -> len );
305
318
}
306
319
320
+ void rb_abi_guest_rstring_ptr (rb_abi_guest_rb_abi_value_t value ,
321
+ rb_abi_guest_string_t * ret0 ) {
322
+ RB_WASM_LIB_RT (rb_abi_guest_rstring_ptr_thunk (value , ret0 ));
323
+ }
324
+
307
325
uint32_t rb_abi_guest_rb_abi_value_data_ptr (rb_abi_guest_rb_abi_value_t self ) {
308
326
VALUE obj = (VALUE )rb_abi_guest_rb_abi_value_get (& self );
309
327
return (uint32_t )DATA_PTR (obj );
@@ -340,6 +358,8 @@ bool rb_abi_guest_rb_set_should_prohibit_rewind(bool value) {
340
358
return old ;
341
359
}
342
360
361
+ #ifdef JS_ENABLE_COMPONENT_MODEL
362
+
343
363
static VALUE rb_abi_export_stage = Qnil ;
344
364
static rb_abi_guest_own_rb_abi_value_t rb_abi_export_rb_value_to_js (void ) {
345
365
VALUE staged = rb_abi_export_stage ;
@@ -354,8 +374,6 @@ void rb_abi_stage_rb_value_to_js(VALUE value) {
354
374
rb_abi_export_stage = value ;
355
375
}
356
376
357
- #ifdef JS_ENABLE_COMPONENT_MODEL
358
-
359
377
extern void __wasm_call_ctors (void );
360
378
static inline void __wasm_call_ctors_if_needed (void ) {
361
379
static bool __wasm_call_ctors_done = false;
0 commit comments