Skip to content

Commit c810d6c

Browse files
Re-bindgen by rake check:bindgen
1 parent 7d338c2 commit c810d6c

File tree

7 files changed

+232
-377
lines changed

7 files changed

+232
-377
lines changed

ext/js/bindgen/rb-js-abi-host.c

Lines changed: 52 additions & 60 deletions
Large diffs are not rendered by default.

ext/witapi/bindgen/rb-abi-guest.c

Lines changed: 45 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
#include <stdlib.h>
22
#include <rb-abi-guest.h>
33

4-
__attribute__((weak, export_name("canonical_abi_realloc")))
5-
void *canonical_abi_realloc(
4+
__attribute__((weak, export_name("cabi_realloc")))
5+
void *cabi_realloc(
66
void *ptr,
77
size_t orig_size,
88
size_t org_align,
@@ -14,15 +14,6 @@ size_t new_size
1414
return ret;
1515
}
1616

17-
__attribute__((weak, export_name("canonical_abi_free")))
18-
void canonical_abi_free(
19-
void *ptr,
20-
size_t size,
21-
size_t align
22-
) {
23-
free(ptr);
24-
}
25-
2617
__attribute__((import_module("canonical_abi"), import_name("resource_drop_rb-iseq")))
2718
void __resource_rb_iseq_drop(uint32_t idx);
2819

@@ -99,103 +90,114 @@ void rb_abi_guest_string_set(rb_abi_guest_string_t *ret, const char *s) {
9990

10091
void rb_abi_guest_string_dup(rb_abi_guest_string_t *ret, const char *s) {
10192
ret->len = strlen(s);
102-
ret->ptr = canonical_abi_realloc(NULL, 0, 1, ret->len);
93+
ret->ptr = cabi_realloc(NULL, 0, 1, ret->len);
10394
memcpy(ret->ptr, s, ret->len);
10495
}
10596

10697
void rb_abi_guest_string_free(rb_abi_guest_string_t *ret) {
107-
canonical_abi_free(ret->ptr, ret->len, 1);
98+
if (ret->len > 0) {
99+
free(ret->ptr);
100+
}
108101
ret->ptr = NULL;
109102
ret->len = 0;
110103
}
111104
void rb_abi_guest_list_string_free(rb_abi_guest_list_string_t *ptr) {
112105
for (size_t i = 0; i < ptr->len; i++) {
113106
rb_abi_guest_string_free(&ptr->ptr[i]);
114107
}
115-
canonical_abi_free(ptr->ptr, ptr->len * 8, 4);
108+
if (ptr->len > 0) {
109+
free(ptr->ptr);
110+
}
111+
}
112+
void rb_abi_guest_tuple2_rb_abi_value_s32_free(rb_abi_guest_tuple2_rb_abi_value_s32_t *ptr) {
113+
rb_abi_guest_rb_abi_value_free(&ptr->f0);
116114
}
117-
typedef struct {
118-
rb_abi_guest_rb_abi_value_t f0;
119-
int32_t f1;
120-
} rb_abi_guest_tuple2_rb_abi_value_s32_t;
121115
void rb_abi_guest_list_rb_abi_value_free(rb_abi_guest_list_rb_abi_value_t *ptr) {
122116
for (size_t i = 0; i < ptr->len; i++) {
123117
rb_abi_guest_rb_abi_value_free(&ptr->ptr[i]);
124118
}
125-
canonical_abi_free(ptr->ptr, ptr->len * 4, 4);
119+
if (ptr->len > 0) {
120+
free(ptr->ptr);
121+
}
126122
}
127-
static int64_t RET_AREA[2];
128-
__attribute__((export_name("ruby-show-version")))
123+
124+
__attribute__((aligned(4)))
125+
static uint8_t RET_AREA[8];
126+
__attribute__((export_name("ruby-show-version: func() -> ()")))
129127
void __wasm_export_rb_abi_guest_ruby_show_version(void) {
130128
rb_abi_guest_ruby_show_version();
131129
}
132-
__attribute__((export_name("ruby-init")))
130+
__attribute__((export_name("ruby-init: func() -> ()")))
133131
void __wasm_export_rb_abi_guest_ruby_init(void) {
134132
rb_abi_guest_ruby_init();
135133
}
136-
__attribute__((export_name("ruby-sysinit")))
134+
__attribute__((export_name("ruby-sysinit: func(args: list<string>) -> ()")))
137135
void __wasm_export_rb_abi_guest_ruby_sysinit(int32_t arg, int32_t arg0) {
138136
rb_abi_guest_list_string_t arg1 = (rb_abi_guest_list_string_t) { (rb_abi_guest_string_t*)(arg), (size_t)(arg0) };
139137
rb_abi_guest_ruby_sysinit(&arg1);
140138
}
141-
__attribute__((export_name("ruby-options")))
139+
__attribute__((export_name("ruby-options: func(args: list<string>) -> handle<rb-iseq>")))
142140
int32_t __wasm_export_rb_abi_guest_ruby_options(int32_t arg, int32_t arg0) {
143141
rb_abi_guest_list_string_t arg1 = (rb_abi_guest_list_string_t) { (rb_abi_guest_string_t*)(arg), (size_t)(arg0) };
144142
rb_abi_guest_rb_iseq_t ret = rb_abi_guest_ruby_options(&arg1);
145143
return (ret).idx;
146144
}
147-
__attribute__((export_name("ruby-script")))
145+
__attribute__((export_name("ruby-script: func(name: string) -> ()")))
148146
void __wasm_export_rb_abi_guest_ruby_script(int32_t arg, int32_t arg0) {
149147
rb_abi_guest_string_t arg1 = (rb_abi_guest_string_t) { (char*)(arg), (size_t)(arg0) };
150148
rb_abi_guest_ruby_script(&arg1);
151149
}
152-
__attribute__((export_name("ruby-init-loadpath")))
150+
__attribute__((export_name("ruby-init-loadpath: func() -> ()")))
153151
void __wasm_export_rb_abi_guest_ruby_init_loadpath(void) {
154152
rb_abi_guest_ruby_init_loadpath();
155153
}
156-
__attribute__((export_name("rb-eval-string-protect")))
154+
__attribute__((export_name("rb-eval-string-protect: func(str: string) -> tuple<handle<rb-abi-value>, s32>")))
157155
int32_t __wasm_export_rb_abi_guest_rb_eval_string_protect(int32_t arg, int32_t arg0) {
158156
rb_abi_guest_string_t arg1 = (rb_abi_guest_string_t) { (char*)(arg), (size_t)(arg0) };
159-
rb_abi_guest_rb_abi_value_t ret;
160-
int32_t ret2;
161-
rb_abi_guest_rb_eval_string_protect(&arg1, &ret, &ret2);
157+
rb_abi_guest_tuple2_rb_abi_value_s32_t ret;
158+
rb_abi_guest_rb_eval_string_protect(&arg1, &ret);
162159
int32_t ptr = (int32_t) &RET_AREA;
163-
*((int32_t*)(ptr + 8)) = ((rb_abi_guest_tuple2_rb_abi_value_s32_t){ ret, ret2 }).f1;
164-
*((int32_t*)(ptr + 0)) = (((rb_abi_guest_tuple2_rb_abi_value_s32_t){ ret, ret2 }).f0).idx;
160+
*((int32_t*)(ptr + 0)) = ((ret).f0).idx;
161+
*((int32_t*)(ptr + 4)) = (ret).f1;
165162
return ptr;
166163
}
167-
__attribute__((export_name("rb-funcallv-protect")))
164+
__attribute__((export_name("rb-funcallv-protect: func(recv: handle<rb-abi-value>, mid: u32, args: list<handle<rb-abi-value>>) -> tuple<handle<rb-abi-value>, s32>")))
168165
int32_t __wasm_export_rb_abi_guest_rb_funcallv_protect(int32_t arg, int32_t arg0, int32_t arg1, int32_t arg2) {
169166
rb_abi_guest_list_rb_abi_value_t arg3 = (rb_abi_guest_list_rb_abi_value_t) { (rb_abi_guest_rb_abi_value_t*)(arg1), (size_t)(arg2) };
170-
rb_abi_guest_rb_abi_value_t ret;
171-
int32_t ret4;
172-
rb_abi_guest_rb_funcallv_protect((rb_abi_guest_rb_abi_value_t){ arg }, (uint32_t) (arg0), &arg3, &ret, &ret4);
167+
rb_abi_guest_tuple2_rb_abi_value_s32_t ret;
168+
rb_abi_guest_rb_funcallv_protect((rb_abi_guest_rb_abi_value_t){ arg }, (uint32_t) (arg0), &arg3, &ret);
173169
int32_t ptr = (int32_t) &RET_AREA;
174-
*((int32_t*)(ptr + 8)) = ((rb_abi_guest_tuple2_rb_abi_value_s32_t){ ret, ret4 }).f1;
175-
*((int32_t*)(ptr + 0)) = (((rb_abi_guest_tuple2_rb_abi_value_s32_t){ ret, ret4 }).f0).idx;
170+
*((int32_t*)(ptr + 0)) = ((ret).f0).idx;
171+
*((int32_t*)(ptr + 4)) = (ret).f1;
176172
return ptr;
177173
}
178-
__attribute__((export_name("rb-intern")))
174+
__attribute__((export_name("rb-intern: func(name: string) -> u32")))
179175
int32_t __wasm_export_rb_abi_guest_rb_intern(int32_t arg, int32_t arg0) {
180176
rb_abi_guest_string_t arg1 = (rb_abi_guest_string_t) { (char*)(arg), (size_t)(arg0) };
181177
rb_abi_guest_rb_id_t ret = rb_abi_guest_rb_intern(&arg1);
182178
return (int32_t) (ret);
183179
}
184-
__attribute__((export_name("rb-errinfo")))
180+
__attribute__((export_name("rb-errinfo: func() -> handle<rb-abi-value>")))
185181
int32_t __wasm_export_rb_abi_guest_rb_errinfo(void) {
186182
rb_abi_guest_rb_abi_value_t ret = rb_abi_guest_rb_errinfo();
187183
return (ret).idx;
188184
}
189-
__attribute__((export_name("rb-clear-errinfo")))
185+
__attribute__((export_name("rb-clear-errinfo: func() -> ()")))
190186
void __wasm_export_rb_abi_guest_rb_clear_errinfo(void) {
191187
rb_abi_guest_rb_clear_errinfo();
192188
}
193-
__attribute__((export_name("rstring-ptr")))
189+
__attribute__((export_name("rstring-ptr: func(value: handle<rb-abi-value>) -> string")))
194190
int32_t __wasm_export_rb_abi_guest_rstring_ptr(int32_t arg) {
195191
rb_abi_guest_string_t ret;
196192
rb_abi_guest_rstring_ptr((rb_abi_guest_rb_abi_value_t){ arg }, &ret);
197193
int32_t ptr = (int32_t) &RET_AREA;
198-
*((int32_t*)(ptr + 8)) = (int32_t) (ret).len;
194+
*((int32_t*)(ptr + 4)) = (int32_t) (ret).len;
199195
*((int32_t*)(ptr + 0)) = (int32_t) (ret).ptr;
200196
return ptr;
201197
}
198+
__attribute__((export_name("cabi_post_rstring-ptr")))
199+
void __wasm_export_rb_abi_guest_rstring_ptr_post_return(int32_t arg0) {
200+
if ((*((int32_t*) (arg0 + 4))) > 0) {
201+
free((void*) (*((int32_t*) (arg0 + 0))));
202+
}
203+
}

ext/witapi/bindgen/rb-abi-guest.h

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,11 @@ extern "C"
4545
size_t len;
4646
} rb_abi_guest_list_string_t;
4747
void rb_abi_guest_list_string_free(rb_abi_guest_list_string_t *ptr);
48+
typedef struct {
49+
rb_abi_guest_rb_abi_value_t f0;
50+
int32_t f1;
51+
} rb_abi_guest_tuple2_rb_abi_value_s32_t;
52+
void rb_abi_guest_tuple2_rb_abi_value_s32_free(rb_abi_guest_tuple2_rb_abi_value_s32_t *ptr);
4853
typedef struct {
4954
rb_abi_guest_rb_abi_value_t *ptr;
5055
size_t len;
@@ -56,8 +61,8 @@ extern "C"
5661
rb_abi_guest_rb_iseq_t rb_abi_guest_ruby_options(rb_abi_guest_list_string_t *args);
5762
void rb_abi_guest_ruby_script(rb_abi_guest_string_t *name);
5863
void rb_abi_guest_ruby_init_loadpath(void);
59-
void rb_abi_guest_rb_eval_string_protect(rb_abi_guest_string_t *str, rb_abi_guest_rb_abi_value_t *ret0, int32_t *ret1);
60-
void rb_abi_guest_rb_funcallv_protect(rb_abi_guest_rb_abi_value_t recv, rb_abi_guest_rb_id_t mid, rb_abi_guest_list_rb_abi_value_t *args, rb_abi_guest_rb_abi_value_t *ret0, int32_t *ret1);
64+
void rb_abi_guest_rb_eval_string_protect(rb_abi_guest_string_t *str, rb_abi_guest_tuple2_rb_abi_value_s32_t *ret0);
65+
void rb_abi_guest_rb_funcallv_protect(rb_abi_guest_rb_abi_value_t recv, rb_abi_guest_rb_id_t mid, rb_abi_guest_list_rb_abi_value_t *args, rb_abi_guest_tuple2_rb_abi_value_s32_t *ret0);
6166
rb_abi_guest_rb_id_t rb_abi_guest_rb_intern(rb_abi_guest_string_t *name);
6267
rb_abi_guest_rb_abi_value_t rb_abi_guest_rb_errinfo(void);
6368
void rb_abi_guest_rb_clear_errinfo(void);

packages/npm-packages/ruby-wasm-wasi/src/bindgen/intrinsics.js

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,14 @@
11

2-
export function clamp_host(i, min, max) {
3-
if (!Number.isInteger(i)) throw new TypeError(`must be an integer`);
4-
if (i < min || i > max) throw new RangeError(`must be between ${min} and ${max}`);
5-
return i;
6-
}
7-
82
let DATA_VIEW = new DataView(new ArrayBuffer());
93

104
export function data_view(mem) {
115
if (DATA_VIEW.buffer !== mem.buffer) DATA_VIEW = new DataView(mem.buffer);
126
return DATA_VIEW;
137
}
8+
9+
export function to_uint32(val) {
10+
return val >>> 0;
11+
}
1412
export const UTF8_DECODER = new TextDecoder('utf-8');
1513

1614
const UTF8_ENCODER = new TextEncoder('utf-8');
@@ -82,3 +80,7 @@ export class Slab {
8280
return ret;
8381
}
8482
}
83+
84+
export function throw_invalid_bool() {
85+
throw new RangeError("invalid variant discriminant for bool");
86+
}

packages/npm-packages/ruby-wasm-wasi/src/bindgen/rb-abi-guest.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ export class RbAbiGuest {
1919
*/
2020
constructor();
2121

22-
/**
22+
/**
2323
* This is a low-level method which can be used to add any
2424
* intrinsics necessary for this instance to operate to an
2525
* import object.

packages/npm-packages/ruby-wasm-wasi/src/bindgen/rb-abi-guest.js

Lines changed: 25 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { clamp_host, data_view, UTF8_DECODER, utf8_encode, UTF8_ENCODED_LEN, Slab } from './intrinsics.js';
1+
import { data_view, to_uint32, UTF8_DECODER, utf8_encode, UTF8_ENCODED_LEN, Slab } from './intrinsics.js';
22
export class RbAbiGuest {
33
constructor() {
44
this._resource0_slab = new Slab();
@@ -58,14 +58,14 @@ export class RbAbiGuest {
5858
this._registry1 = new FinalizationRegistry(this._exports['canonical_abi_drop_rb-abi-value']);
5959
}
6060
rubyShowVersion() {
61-
this._exports['ruby-show-version']();
61+
this._exports['ruby-show-version: func() -> ()']();
6262
}
6363
rubyInit() {
64-
this._exports['ruby-init']();
64+
this._exports['ruby-init: func() -> ()']();
6565
}
6666
rubySysinit(arg0) {
6767
const memory = this._exports.memory;
68-
const realloc = this._exports["canonical_abi_realloc"];
68+
const realloc = this._exports["cabi_realloc"];
6969
const vec1 = arg0;
7070
const len1 = vec1.length;
7171
const result1 = realloc(0, 0, 4, len1 * 8);
@@ -77,11 +77,11 @@ export class RbAbiGuest {
7777
data_view(memory).setInt32(base + 4, len0, true);
7878
data_view(memory).setInt32(base + 0, ptr0, true);
7979
}
80-
this._exports['ruby-sysinit'](result1, len1);
80+
this._exports['ruby-sysinit: func(args: list<string>) -> ()'](result1, len1);
8181
}
8282
rubyOptions(arg0) {
8383
const memory = this._exports.memory;
84-
const realloc = this._exports["canonical_abi_realloc"];
84+
const realloc = this._exports["cabi_realloc"];
8585
const vec1 = arg0;
8686
const len1 = vec1.length;
8787
const result1 = realloc(0, 0, 4, len1 * 8);
@@ -93,30 +93,30 @@ export class RbAbiGuest {
9393
data_view(memory).setInt32(base + 4, len0, true);
9494
data_view(memory).setInt32(base + 0, ptr0, true);
9595
}
96-
const ret = this._exports['ruby-options'](result1, len1);
96+
const ret = this._exports['ruby-options: func(args: list<string>) -> handle<rb-iseq>'](result1, len1);
9797
return this._resource0_slab.remove(ret);
9898
}
9999
rubyScript(arg0) {
100100
const memory = this._exports.memory;
101-
const realloc = this._exports["canonical_abi_realloc"];
101+
const realloc = this._exports["cabi_realloc"];
102102
const ptr0 = utf8_encode(arg0, realloc, memory);
103103
const len0 = UTF8_ENCODED_LEN;
104-
this._exports['ruby-script'](ptr0, len0);
104+
this._exports['ruby-script: func(name: string) -> ()'](ptr0, len0);
105105
}
106106
rubyInitLoadpath() {
107-
this._exports['ruby-init-loadpath']();
107+
this._exports['ruby-init-loadpath: func() -> ()']();
108108
}
109109
rbEvalStringProtect(arg0) {
110110
const memory = this._exports.memory;
111-
const realloc = this._exports["canonical_abi_realloc"];
111+
const realloc = this._exports["cabi_realloc"];
112112
const ptr0 = utf8_encode(arg0, realloc, memory);
113113
const len0 = UTF8_ENCODED_LEN;
114-
const ret = this._exports['rb-eval-string-protect'](ptr0, len0);
115-
return [this._resource1_slab.remove(data_view(memory).getInt32(ret + 0, true)), data_view(memory).getInt32(ret + 8, true)];
114+
const ret = this._exports['rb-eval-string-protect: func(str: string) -> tuple<handle<rb-abi-value>, s32>'](ptr0, len0);
115+
return [this._resource1_slab.remove(data_view(memory).getInt32(ret + 0, true)), data_view(memory).getInt32(ret + 4, true)];
116116
}
117117
rbFuncallvProtect(arg0, arg1, arg2) {
118118
const memory = this._exports.memory;
119-
const realloc = this._exports["canonical_abi_realloc"];
119+
const realloc = this._exports["cabi_realloc"];
120120
const obj0 = arg0;
121121
if (!(obj0 instanceof RbAbiValue)) throw new TypeError('expected instance of RbAbiValue');
122122
const vec2 = arg2;
@@ -129,35 +129,34 @@ export class RbAbiGuest {
129129
if (!(obj1 instanceof RbAbiValue)) throw new TypeError('expected instance of RbAbiValue');
130130
data_view(memory).setInt32(base + 0, this._resource1_slab.insert(obj1.clone()), true);
131131
}
132-
const ret = this._exports['rb-funcallv-protect'](this._resource1_slab.insert(obj0.clone()), clamp_host(arg1, 0, 4294967295), result2, len2);
133-
return [this._resource1_slab.remove(data_view(memory).getInt32(ret + 0, true)), data_view(memory).getInt32(ret + 8, true)];
132+
const ret = this._exports['rb-funcallv-protect: func(recv: handle<rb-abi-value>, mid: u32, args: list<handle<rb-abi-value>>) -> tuple<handle<rb-abi-value>, s32>'](this._resource1_slab.insert(obj0.clone()), to_uint32(arg1), result2, len2);
133+
return [this._resource1_slab.remove(data_view(memory).getInt32(ret + 0, true)), data_view(memory).getInt32(ret + 4, true)];
134134
}
135135
rbIntern(arg0) {
136136
const memory = this._exports.memory;
137-
const realloc = this._exports["canonical_abi_realloc"];
137+
const realloc = this._exports["cabi_realloc"];
138138
const ptr0 = utf8_encode(arg0, realloc, memory);
139139
const len0 = UTF8_ENCODED_LEN;
140-
const ret = this._exports['rb-intern'](ptr0, len0);
140+
const ret = this._exports['rb-intern: func(name: string) -> u32'](ptr0, len0);
141141
return ret >>> 0;
142142
}
143143
rbErrinfo() {
144-
const ret = this._exports['rb-errinfo']();
144+
const ret = this._exports['rb-errinfo: func() -> handle<rb-abi-value>']();
145145
return this._resource1_slab.remove(ret);
146146
}
147147
rbClearErrinfo() {
148-
this._exports['rb-clear-errinfo']();
148+
this._exports['rb-clear-errinfo: func() -> ()']();
149149
}
150150
rstringPtr(arg0) {
151151
const memory = this._exports.memory;
152-
const free = this._exports["canonical_abi_free"];
153152
const obj0 = arg0;
154153
if (!(obj0 instanceof RbAbiValue)) throw new TypeError('expected instance of RbAbiValue');
155-
const ret = this._exports['rstring-ptr'](this._resource1_slab.insert(obj0.clone()));
154+
const ret = this._exports['rstring-ptr: func(value: handle<rb-abi-value>) -> string'](this._resource1_slab.insert(obj0.clone()));
156155
const ptr1 = data_view(memory).getInt32(ret + 0, true);
157-
const len1 = data_view(memory).getInt32(ret + 8, true);
158-
const list1 = UTF8_DECODER.decode(new Uint8Array(memory.buffer, ptr1, len1));
159-
free(ptr1, len1, 1);
160-
return list1;
156+
const len1 = data_view(memory).getInt32(ret + 4, true);
157+
const result1 = UTF8_DECODER.decode(new Uint8Array(memory.buffer, ptr1, len1));
158+
this._exports["cabi_post_rstring-ptr"](ret);
159+
return result1;
161160
}
162161
}
163162

0 commit comments

Comments
 (0)