wardite 0.9.0 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (184) hide show
  1. checksums.yaml +4 -4
  2. data/LICENSE +191 -0
  3. data/Makefile +14 -0
  4. data/README.md +107 -2
  5. data/Rakefile +5 -0
  6. data/Steepfile +1 -0
  7. data/assets/wardite.svg +12 -0
  8. data/benchmark/README.md +500 -0
  9. data/benchmark/build_call_profile.rb +42 -0
  10. data/benchmark/call_cost_worker.rb +27 -0
  11. data/benchmark/compare.rb +93 -0
  12. data/benchmark/compare_call_types.rb +212 -0
  13. data/benchmark/compare_dispatch.rb +123 -0
  14. data/benchmark/compare_engines.rb +119 -0
  15. data/benchmark/compare_optimizations.rb +139 -0
  16. data/benchmark/engine_phases.rb +30 -0
  17. data/benchmark/figures/README.md +35 -0
  18. data/benchmark/figures/plot_spinel_comparison.py +137 -0
  19. data/benchmark/figures/spinel_new_vm_candlestick.png +0 -0
  20. data/benchmark/figures/spinel_new_vm_candlestick.svg +7615 -0
  21. data/benchmark/figures/spinel_new_vm_summary.csv +9 -0
  22. data/benchmark/figures/spinel_new_vm_summary.json +82 -0
  23. data/benchmark/float_m5.wat +42 -0
  24. data/benchmark/i32_call_arities.wat +89 -0
  25. data/benchmark/i32_calls.wat +174 -0
  26. data/benchmark/i32_memory.wat +58 -0
  27. data/benchmark/i32_mix.wat +80 -0
  28. data/benchmark/i64_m4.wat +55 -0
  29. data/benchmark/investigate_calls.rb +231 -0
  30. data/benchmark/investigate_generated_guards.rb +218 -0
  31. data/benchmark/m3_call_worker.rb +38 -0
  32. data/benchmark/measure_m1.rb +51 -0
  33. data/benchmark/measure_m2.rb +55 -0
  34. data/benchmark/measure_m3_calls.rb +89 -0
  35. data/benchmark/measure_m4.rb +134 -0
  36. data/benchmark/measure_m5_boundary.rb +41 -0
  37. data/benchmark/measure_mir_cache_verify.rb +58 -0
  38. data/benchmark/measure_ruby_wasm_cache_hit.rb +59 -0
  39. data/benchmark/measure_ruby_wasm_startup.rb +43 -0
  40. data/benchmark/measure_wasi_write.rb +75 -0
  41. data/benchmark/optimization_worker.rb +23 -0
  42. data/benchmark/results/call_arities_exploratory_2026-11-04.json +4320 -0
  43. data/benchmark/results/call_arities_spinel_2026-11-04.json +1200 -0
  44. data/benchmark/results/call_cost_spinel_2026-11-04.json +2392 -0
  45. data/benchmark/results/call_protocol_exploratory_2026-11-04.json +3947 -0
  46. data/benchmark/results/call_protocol_profile_2026-11-04.json +383 -0
  47. data/benchmark/results/call_protocol_ruby_2026-11-04.json +1213 -0
  48. data/benchmark/results/call_protocol_spinel_2026-11-04.json +913 -0
  49. data/benchmark/results/call_types_ruby_2026-11-04.json +1212 -0
  50. data/benchmark/results/call_types_spinel_2026-11-04.json +923 -0
  51. data/benchmark/results/efflorescence-m1-cruby.json +799 -0
  52. data/benchmark/results/efflorescence-m1-spinel.json +799 -0
  53. data/benchmark/results/efflorescence-m2-bulk-loop.json +820 -0
  54. data/benchmark/results/efflorescence-m2-i32-cruby.json +799 -0
  55. data/benchmark/results/efflorescence-m2-i32-spinel.json +799 -0
  56. data/benchmark/results/efflorescence-m2-memory.json +408 -0
  57. data/benchmark/results/efflorescence-mir2-cache-integrity.json +390 -0
  58. data/benchmark/results/efflorescence-unboxed-globals.json +3451 -0
  59. data/benchmark/results/generated_guards_exploratory_2026-11-04.json +1225 -0
  60. data/benchmark/results/generated_guards_profile_2026-11-04.json +592 -0
  61. data/benchmark/results/generated_guards_spinel_2026-11-04.json +1650 -0
  62. data/benchmark/results/generated_guards_validation_2026-11-04.json +256 -0
  63. data/benchmark/results/inlining_engines_2026-11-04.json +241 -0
  64. data/benchmark/results/inlining_ruby_2026-11-04.json +1213 -0
  65. data/benchmark/results/inlining_spinel_2026-11-04.json +893 -0
  66. data/benchmark/results/operand_decode_exploratory_2026-11-04.json +1319 -0
  67. data/benchmark/results/operand_decode_ruby_2026-11-04.json +1213 -0
  68. data/benchmark/results/operand_decode_spinel_2026-11-04.json +924 -0
  69. data/benchmark/results/selective_reset_spinel_2026-11-04.json +454 -0
  70. data/benchmark/results/selective_reset_spinel_2026-11-04_exploratory.json +2679 -0
  71. data/benchmark/results/spinel_fetch_root_patch_2026-11-04.json +4523 -0
  72. data/benchmark/results/while_final_compiler_comparison_2026-11-04.json +324 -0
  73. data/benchmark/results/while_patched_external_2026-11-04.json +220 -0
  74. data/benchmark/results/while_user_unpatched_2026-11-04.json +230 -0
  75. data/benchmark/summarize_call_profile.py +54 -0
  76. data/benchmark/validate_m1_eh.rb +34 -0
  77. data/benchmark/validate_m2.rb +119 -0
  78. data/benchmark/validate_m3.rb +44 -0
  79. data/benchmark/validate_m4.rb +95 -0
  80. data/benchmark/validate_m5.rb +108 -0
  81. data/docs/adr/0001-efflorescence-m1-control-and-eh.md +319 -0
  82. data/docs/adr/0002-efflorescence-m2-memory-and-globals.md +185 -0
  83. data/docs/adr/0003-efflorescence-m3-host-and-indirect-calls.md +228 -0
  84. data/docs/adr/0004-efflorescence-m4-i64.md +202 -0
  85. data/docs/adr/0005-efflorescence-m5-floating-point.md +127 -0
  86. data/docs/adr/0006-efflorescence-m6-coverage-parity.md +101 -0
  87. data/docs/adr/0007-efflorescence-ruby-wasm-phase1.md +75 -0
  88. data/docs/adr/0008-efflorescence-ruby-wasm-phase2.md +75 -0
  89. data/docs/adr/0009-efflorescence-mir2-cache-integrity-modes.md +77 -0
  90. data/docs/adr/0010-efflorescence-mir2-cache-function-restore.md +80 -0
  91. data/docs/adr/0011-efflorescence-unboxed-globals.md +89 -0
  92. data/docs/adr/0012-efflorescence-startup-snapshot.md +173 -0
  93. data/docs/adr/0013-efflorescence-frame-acquisition.md +114 -0
  94. data/docs/efflorescence-call-arities.md +115 -0
  95. data/docs/efflorescence-call-investigation.md +155 -0
  96. data/docs/efflorescence-call-transfer.md +128 -0
  97. data/docs/efflorescence-call-types.md +102 -0
  98. data/docs/efflorescence-coverage-ja.md +351 -0
  99. data/docs/efflorescence-generated-c-guards.md +410 -0
  100. data/docs/efflorescence-inlining.md +165 -0
  101. data/docs/efflorescence-ja.md +155 -0
  102. data/docs/efflorescence-m1.md +160 -0
  103. data/docs/efflorescence-m2.md +233 -0
  104. data/docs/efflorescence-m3.md +131 -0
  105. data/docs/efflorescence-m4.md +88 -0
  106. data/docs/efflorescence-m5.md +82 -0
  107. data/docs/efflorescence-m6.md +95 -0
  108. data/docs/efflorescence-mir2-cache.md +123 -0
  109. data/docs/efflorescence-operand-decoding.md +105 -0
  110. data/docs/efflorescence-phase2-ja.md +225 -0
  111. data/docs/efflorescence-phase2.md +240 -0
  112. data/docs/efflorescence-register-initialization.md +75 -0
  113. data/docs/efflorescence-ruby-wasm-phase1.md +90 -0
  114. data/docs/efflorescence-spinel-linear-memory.md +72 -0
  115. data/docs/efflorescence-startup-snapshot.md +60 -0
  116. data/docs/efflorescence-unboxed-globals.md +61 -0
  117. data/docs/efflorescence.md +144 -0
  118. data/docs/spinel-string-aset-inplace-proposal.md +200 -0
  119. data/lib/wardite/alu_f32.generated.rb +11 -2
  120. data/lib/wardite/alu_f64.generated.rb +11 -2
  121. data/lib/wardite/alu_i32.generated.rb +54 -17
  122. data/lib/wardite/alu_i64.generated.rb +73 -31
  123. data/lib/wardite/cli/cli.rb +112 -29
  124. data/lib/wardite/const.rb +1 -0
  125. data/lib/wardite/efflorescence/float_arithmetic.rb +216 -0
  126. data/lib/wardite/efflorescence/i64_arithmetic.rb +257 -0
  127. data/lib/wardite/efflorescence/inspection.rb +165 -0
  128. data/lib/wardite/efflorescence/ir.rb +1164 -0
  129. data/lib/wardite/efflorescence/mir_cache.rb +657 -0
  130. data/lib/wardite/efflorescence/optimizer.rb +580 -0
  131. data/lib/wardite/efflorescence/register_validation.rb +362 -0
  132. data/lib/wardite/efflorescence/snapshot.rb +229 -0
  133. data/lib/wardite/efflorescence/store_access.rb +366 -0
  134. data/lib/wardite/efflorescence/translator.rb +866 -0
  135. data/lib/wardite/efflorescence/vm.rb +1170 -0
  136. data/lib/wardite/efflorescence/wasi.rb +52 -0
  137. data/lib/wardite/efflorescence.rb +17 -0
  138. data/lib/wardite/errors.rb +20 -0
  139. data/lib/wardite/float_bits.rb +46 -0
  140. data/lib/wardite/instruction.rb +35 -4
  141. data/lib/wardite/leb128.rb +33 -12
  142. data/lib/wardite/load.rb +292 -143
  143. data/lib/wardite/value.rb +169 -175
  144. data/lib/wardite/version.rb +1 -1
  145. data/lib/wardite/wasi/consts.rb +1 -0
  146. data/lib/wardite/wasi/spinel.rb +41 -0
  147. data/lib/wardite/wasi.rb +483 -268
  148. data/lib/wardite/wasm_module.rb +6 -3
  149. data/lib/wardite.rb +360 -98
  150. data/rbs_collection.lock.yaml +36 -96
  151. data/scripts/gen_alu.rb +121 -21
  152. data/scripts/verify_ruby_wasm.rb +70 -0
  153. data/sig/generated/wardite/cli/cli.rbs +23 -6
  154. data/sig/generated/wardite/const.rbs +2 -0
  155. data/sig/generated/wardite/efflorescence/float_arithmetic.rbs +65 -0
  156. data/sig/generated/wardite/efflorescence/i64_arithmetic.rbs +99 -0
  157. data/sig/generated/wardite/efflorescence/inspection.rbs +64 -0
  158. data/sig/generated/wardite/efflorescence/ir.rbs +888 -0
  159. data/sig/generated/wardite/efflorescence/mir_cache.rbs +236 -0
  160. data/sig/generated/wardite/efflorescence/optimizer.rbs +189 -0
  161. data/sig/generated/wardite/efflorescence/register_validation.rbs +104 -0
  162. data/sig/generated/wardite/efflorescence/snapshot.rbs +83 -0
  163. data/sig/generated/wardite/efflorescence/store_access.rbs +145 -0
  164. data/sig/generated/wardite/efflorescence/translator.rbs +218 -0
  165. data/sig/generated/wardite/efflorescence/vm.rbs +240 -0
  166. data/sig/generated/wardite/efflorescence/wasi.rbs +34 -0
  167. data/sig/generated/wardite/errors.rbs +12 -0
  168. data/sig/generated/wardite/float_bits.rbs +30 -0
  169. data/sig/generated/wardite/instruction.rbs +22 -1
  170. data/sig/generated/wardite/leb128.rbs +3 -1
  171. data/sig/generated/wardite/load.rbs +59 -7
  172. data/sig/generated/wardite/value.rbs +70 -11
  173. data/sig/generated/wardite/wasi/consts.rbs +2 -0
  174. data/sig/generated/wardite/wasi/spinel.rbs +15 -0
  175. data/sig/generated/wardite/wasi.rbs +111 -4
  176. data/sig/generated/wardite.rbs +114 -13
  177. data/sig/mir_cache_stdlib.rbs +5 -0
  178. data/sig/vernier.rbs +2 -2
  179. data/spinel/README.md +30 -0
  180. data/spinel/bin/wardite.rb +6 -0
  181. data/spinel/patches/0001-io-buffer-string-view.patch +699 -0
  182. data/spinel/patches/0002-io-buffer-allocation-error.patch +47 -0
  183. data/spinel/spin.toml +7 -0
  184. metadata +154 -3
@@ -1,7 +1,28 @@
1
1
  # Generated from lib/wardite/instruction.rb with RBS::Inline
2
2
 
3
3
  module Wardite
4
- type operandItem = Integer | Array[Integer] | Float | Block
4
+ type operandItem = Integer | Float | Block | OperandVector | FloatImmediate
5
+
6
+ # Give br_table and try_table vectors a concrete type in the mixed operand list.
7
+ class FloatImmediate
8
+ attr_reader bits: Integer
9
+
10
+ attr_reader type: Symbol
11
+
12
+ # @rbs type: Symbol
13
+ # @rbs bits: Integer
14
+ def initialize: (Symbol type, Integer bits) -> untyped
15
+
16
+ # @rbs return: Float
17
+ def value: () -> Float
18
+ end
19
+
20
+ class OperandVector
21
+ attr_reader entries: Array[Integer]
22
+
23
+ # @rbs entries: Array[Integer]
24
+ def initialize: (Array[Integer] entries) -> untyped
25
+ end
5
26
 
6
27
  class Op
7
28
  # @see https://pengowray.github.io/wasm-ops/
@@ -10,6 +10,8 @@ module Wardite
10
10
 
11
11
  # @rbs buf: File|StringIO
12
12
  # @rbs return: Integer
13
- def fetch_sleb128: (File | StringIO buf, ?max_level: untyped) -> Integer
13
+ # @rbs max_level: Integer
14
+ # @rbs width: Integer?
15
+ def fetch_sleb128: (File | StringIO buf, ?max_level: Integer, ?width: Integer?) -> Integer
14
16
  end
15
17
  end
@@ -18,6 +18,12 @@ module Wardite
18
18
  def initialize: () -> void
19
19
  end
20
20
 
21
+ class TagSection < Section
22
+ attr_reader type_indices: Array[Integer]
23
+
24
+ def initialize: () -> untyped
25
+ end
26
+
21
27
  class FunctionSection < Section
22
28
  attr_accessor func_indices: Array[Integer]
23
29
 
@@ -71,11 +77,15 @@ module Wardite
71
77
  end
72
78
 
73
79
  class ElemSection < Section
80
+ type indexVector = Array[Integer]
81
+
74
82
  attr_accessor table_indices: Array[Integer]
75
83
 
76
84
  attr_accessor table_offsets: Array[Integer]
77
85
 
78
- attr_accessor element_indices: Array[Array[Integer]]
86
+ # Rows are also shared with Store#elements. Keep the precise RBS type via
87
+ # an alias rather than pinning Spinel's specialized nested-array layout.
88
+ attr_accessor element_indices: Array[indexVector]
79
89
 
80
90
  # @rbs return: void
81
91
  def initialize: () -> void
@@ -87,11 +97,33 @@ module Wardite
87
97
 
88
98
  attr_accessor locals_type: Array[Symbol]
89
99
 
90
- attr_accessor body: Array[[ Symbol, Symbol, Array[operandItem], Integer?, Integer? ]]
100
+ attr_writer instruction_bytes: String?
101
+
102
+ attr_writer type_section: TypeSection?
91
103
 
92
104
  # @rbs &blk: (CodeBody) -> void
93
105
  # @rbs return: void
94
106
  def initialize: () { (CodeBody) -> void } -> void
107
+
108
+ # @rbs return: Array[[Symbol, Symbol, Array[operandItem], Integer?, Integer?]]
109
+ def body: () -> Array[[ Symbol, Symbol, Array[operandItem], Integer?, Integer? ]]
110
+
111
+ # @rbs instructions: Array[[Symbol, Symbol, Array[operandItem], Integer?, Integer?]]
112
+ # @rbs return: void
113
+ def body=: (Array[[ Symbol, Symbol, Array[operandItem], Integer?, Integer? ]] instructions) -> void
114
+
115
+ # @rbs types: TypeSection?
116
+ # @rbs stack: bool
117
+ # @rbs return: void
118
+ def check_features: (TypeSection? types, bool stack) -> void
119
+
120
+ private
121
+
122
+ # @rbs instructions: Array[[Symbol, Symbol, Array[operandItem], Integer?, Integer?]]
123
+ # @rbs types: TypeSection?
124
+ # @rbs stack: bool
125
+ # @rbs return: void
126
+ def check_instructions: (Array[[ Symbol, Symbol, Array[operandItem], Integer?, Integer? ]] instructions, TypeSection? types, bool stack) -> void
95
127
  end
96
128
 
97
129
  attr_accessor func_codes: Array[CodeBody]
@@ -175,18 +207,27 @@ module Wardite
175
207
  # @rbs buf: File|StringIO
176
208
  # @rbs import_object: Hash[Symbol, wasmModuleSrc]
177
209
  # @rbs enable_wasi: boolish
210
+ # @rbs engine: Symbol
211
+ # @rbs disabled_optimizations: Array[Symbol]
212
+ # @rbs mir_profile: bool
213
+ # @rbs mir_cache: String?
214
+ # @rbs mir_cache_verify: Symbol
178
215
  # @rbs return: Instance
179
- def self.load_from_buffer: (File | StringIO buf, ?import_object: Hash[Symbol, wasmModuleSrc], ?enable_wasi: boolish) -> Instance
216
+ def self.load_from_buffer: (File | StringIO buf, ?import_object: Hash[Symbol, wasmModuleSrc], ?enable_wasi: boolish, ?engine: Symbol, ?disabled_optimizations: Array[Symbol], ?mir_profile: bool, ?mir_cache: String?, ?mir_cache_verify: Symbol) -> Instance
180
217
 
181
218
  # @rbs return: Integer
182
219
  def self.preamble: () -> Integer
183
220
 
221
+ # @rbs defer_code: bool
184
222
  # @rbs return: Array[Section]
185
- def self.sections: () -> Array[Section]
223
+ def self.sections: (?bool defer_code) -> Array[Section]
186
224
 
187
225
  # @rbs return: TypeSection
188
226
  def self.type_section: () -> TypeSection
189
227
 
228
+ # @rbs return: TagSection
229
+ def self.tag_section: () -> TagSection
230
+
190
231
  # @rbs return: ImportSection
191
232
  def self.import_section: () -> ImportSection
192
233
 
@@ -208,13 +249,24 @@ module Wardite
208
249
  # @rbs return: TableSection
209
250
  def self.table_section: () -> TableSection
210
251
 
252
+ # @rbs defer_code: bool
211
253
  # @rbs return: CodeSection
212
- def self.code_section: () -> CodeSection
254
+ def self.code_section: (?bool defer_code) -> CodeSection
255
+
256
+ # @rbs sbuf: StringIO
257
+ # @rbs defer_code: bool
258
+ # @rbs return: CodeSection::CodeBody
259
+ def self.read_function_body: (StringIO sbuf, ?bool defer_code) -> CodeSection::CodeBody
213
260
 
214
261
  # @rbs buf: StringIO
215
262
  # @rbs return: Array[[Symbol, Symbol, Array[operandItem], Integer?, Integer?]]
216
263
  def self.code_body: (StringIO buf) -> Array[[ Symbol, Symbol, Array[operandItem], Integer?, Integer? ]]
217
264
 
265
+ # Decode s33, distinguishing the one-byte value/void forms from indices.
266
+ # @rbs buf: StringIO
267
+ # @rbs return: Block
268
+ def self.read_blocktype: (StringIO buf) -> Block
269
+
218
270
  # @rbs c: String
219
271
  # @rbs buf: StringIO
220
272
  # @rbs return: [Symbol, Symbol, Array[Symbol]]
@@ -245,9 +297,9 @@ module Wardite
245
297
  # @rbs return: nil
246
298
  def self.unimplemented_skip_section: (Integer code) -> nil
247
299
 
248
- # @rbs sbuf: StringIO
300
+ # @rbs sbuf: File|StringIO
249
301
  # @rbs n: Integer
250
302
  # @rbs return: String
251
- def self.assert_read: (StringIO sbuf, Integer n) -> String
303
+ def self.assert_read: (File | StringIO sbuf, Integer n) -> String
252
304
  end
253
305
  end
@@ -19,6 +19,14 @@ module Wardite
19
19
  # @rbs value: Float
20
20
  # @rbs return: F64
21
21
  def F64: (Float value) -> F64
22
+
23
+ # Check the range before Float#to_i, whose result may exceed a native word.
24
+ # @rbs value: Float
25
+ # @rbs to: Symbol
26
+ # @rbs signed: bool
27
+ # @rbs saturating: bool
28
+ # @rbs return: I32 | I64
29
+ def truncate_float: (Float value, to: Symbol, signed: bool, saturating: bool) -> (I32 | I64)
22
30
  end
23
31
 
24
32
  extend ValueHelper
@@ -54,6 +62,12 @@ module Wardite
54
62
  # @rbs return: Integer
55
63
  def value_s: () -> Integer
56
64
 
65
+ # Keep intermediate products below 2**49, even for 0xffffffff operands.
66
+ # The omitted high bits do not contribute to the low 32-bit result.
67
+ # @rbs other: I32
68
+ # @rbs return: I32
69
+ def multiply: (I32 other) -> I32
70
+
57
71
  # TODO: eliminate use of pack, to support mruby - in this file!
58
72
  # @rbs size: Integer|nil
59
73
  # @rbs return: String
@@ -121,12 +135,15 @@ module Wardite
121
135
  class I64
122
136
  include ValueHelper
123
137
 
138
+ type bits = Integer
139
+
124
140
  I64_MAX: Integer
125
141
 
126
- attr_accessor value: Integer
142
+ # Leave the representation inferred so Spinel can hold unsigned 64-bit values.
143
+ attr_accessor value: bits
127
144
 
128
- # @rbs value: Integer
129
- def initialize: (?Integer value) -> untyped
145
+ # @rbs value: bits
146
+ def initialize: (?bits value) -> untyped
130
147
 
131
148
  # @rbs str: String
132
149
  # @rbs size: Integer|nil
@@ -141,6 +158,20 @@ module Wardite
141
158
  # @rbs return: Integer
142
159
  def value_s: () -> Integer
143
160
 
161
+ # @rbs other: I64
162
+ # @rbs return: I64
163
+ def add: (I64 other) -> I64
164
+
165
+ # @rbs count: Integer
166
+ # @rbs return: I64
167
+ def shift_left: (Integer count) -> I64
168
+
169
+ # Multiply in base 2**16; only the low four words contribute modulo 2**64.
170
+ # Every intermediate product and carry fits in a signed 64-bit integer.
171
+ # @rbs other: I64
172
+ # @rbs return: I64
173
+ def multiply: (I64 other) -> I64
174
+
144
175
  # @rbs size: Integer|nil
145
176
  # @rbs return: String
146
177
  def packed: (?size: Integer | nil) -> String
@@ -207,7 +238,24 @@ module Wardite
207
238
  class F32
208
239
  include ValueHelper
209
240
 
210
- attr_accessor value: Float
241
+ # A wrapper holds a Ruby-origin value or raw Wasm bits. Reassignment
242
+ # discards the raw representation so existing value= callers stay current.
243
+ # @rbs bits: Integer?
244
+ def initialize: (?bits: Integer?) -> untyped
245
+
246
+ # @rbs return: Float
247
+ def value: () -> Float
248
+
249
+ # @rbs value: Float
250
+ # @rbs return: Float
251
+ def value=: (Float value) -> Float
252
+
253
+ # @rbs return: Integer
254
+ def raw_bits: () -> Integer
255
+
256
+ # @rbs bits: Integer
257
+ # @rbs return: F32
258
+ def self.from_bits: (Integer bits) -> F32
211
259
 
212
260
  # @rbs str: String
213
261
  # @rbs return: F32
@@ -235,16 +283,11 @@ module Wardite
235
283
  # @rbs return: wasmValue
236
284
  def extend_u: (to: Symbol) -> wasmValue
237
285
 
238
- # @todo need more testcase...
239
- # @see https://webassembly.github.io/spec/core/exec/numerics.html#xref-exec-numerics-op-trunc-s-mathrm-trunc-mathsf-s-m-n-z
240
- # @see copy this impl to F64 when changed
241
286
  # @rbs to: Symbol
242
287
  # @rbs saturating: bool
243
288
  # @rbs return: wasmValue
244
289
  def trunc_s: (to: Symbol, ?saturating: bool) -> wasmValue
245
290
 
246
- # @see https://webassembly.github.io/spec/core/exec/numerics.html#xref-exec-numerics-op-trunc-u-mathrm-trunc-mathsf-u-m-n-z
247
- # @see copy this impl to F64 when changed
248
291
  # @rbs to: Symbol
249
292
  # @rbs sturating: bool
250
293
  # @rbs return: wasmValue
@@ -291,7 +334,24 @@ module Wardite
291
334
  class F64
292
335
  include ValueHelper
293
336
 
294
- attr_accessor value: Float
337
+ # A wrapper holds a Ruby-origin value or raw Wasm bits. Reassignment
338
+ # discards the raw representation so existing value= callers stay current.
339
+ # @rbs bits: Integer?
340
+ def initialize: (?bits: Integer?) -> untyped
341
+
342
+ # @rbs return: Float
343
+ def value: () -> Float
344
+
345
+ # @rbs value: Float
346
+ # @rbs return: Float
347
+ def value=: (Float value) -> Float
348
+
349
+ # @rbs return: Integer
350
+ def raw_bits: () -> Integer
351
+
352
+ # @rbs bits: Integer
353
+ # @rbs return: F64
354
+ def self.from_bits: (Integer bits) -> F64
295
355
 
296
356
  # @rbs str: String
297
357
  # @rbs return: F64
@@ -325,7 +385,6 @@ module Wardite
325
385
  # @rbs return: wasmValue
326
386
  def trunc_s: (to: Symbol, ?saturating: bool) -> wasmValue
327
387
 
328
- # @see the same as F32
329
388
  # @rbs to: Symbol
330
389
  # @rbs saturating: bool
331
390
  # @rbs return: wasmValue
@@ -38,6 +38,8 @@ module Wardite
38
38
 
39
39
  ENOTSUP: ::Integer
40
40
 
41
+ EOVERFLOW: ::Integer
42
+
41
43
  EPERM: ::Integer
42
44
 
43
45
  EROFS: ::Integer
@@ -0,0 +1,15 @@
1
+ # Generated from lib/wardite/wasi/spinel.rb with RBS::Inline
2
+
3
+ module Wardite
4
+ module Wasi
5
+ module Native
6
+ def self.ffi_source: (String) -> void
7
+
8
+ def self.ffi_func: (Symbol, Array[Symbol], Symbol) -> void
9
+
10
+ def self.wardite_wasi_getfl: (Integer) -> Integer
11
+
12
+ def self.wardite_wasi_errno: (Integer) -> Integer
13
+ end
14
+ end
15
+ end
@@ -6,6 +6,19 @@ module Wardite
6
6
 
7
7
  include WasmModule
8
8
 
9
+ # Preview 1 imports return errno (i32), except for proc_exit.
10
+ IMPORT_PARAMETERS: Hash[Symbol, Array[Symbol]]
11
+
12
+ # @rbs name: Symbol
13
+ # @rbs parameters: Array[Symbol]
14
+ # @rbs results: Array[Symbol]
15
+ # @rbs return: void
16
+ def validate_import: (Symbol name, Array[Symbol] parameters, Array[Symbol] results) -> void
17
+
18
+ # @rbs name: Symbol
19
+ # @rbs return: _WasmCallable
20
+ def callable: (Symbol name) -> _WasmCallable
21
+
9
22
  attr_accessor fd_table: Hash[Integer, IO | File | ::Wardite::Wasi::PreopenedDir]
10
23
 
11
24
  attr_accessor fd_count: Integer
@@ -67,8 +80,35 @@ module Wardite
67
80
 
68
81
  # @rbs store: Store
69
82
  # @rbs args: Array[wasmValue]
70
- # @rbs return: Object
71
- def clock_time_get: (Store store, Array[wasmValue] args) -> Object
83
+ # @rbs return: Integer
84
+ def clock_res_get: (Store store, Array[wasmValue] args) -> Integer
85
+
86
+ # @rbs store: Store
87
+ # @rbs args: Array[wasmValue]
88
+ # @rbs return: Integer
89
+ def clock_time_get: (Store store, Array[wasmValue] args) -> Integer
90
+
91
+ # These imports can be linked, but their operations are not implemented.
92
+ # @rbs (Store, Array[wasmValue]) -> Integer
93
+ def fd_advise: (Store, Array[wasmValue]) -> Integer
94
+
95
+ alias fd_datasync fd_advise
96
+
97
+ alias fd_fdstat_set_flags fd_advise
98
+
99
+ alias fd_filestat_set_size fd_advise
100
+
101
+ alias fd_pread fd_advise
102
+
103
+ alias fd_pwrite fd_advise
104
+
105
+ alias fd_renumber fd_advise
106
+
107
+ alias fd_seek fd_advise
108
+
109
+ alias fd_sync fd_advise
110
+
111
+ alias poll_oneoff fd_advise
72
112
 
73
113
  # @rbs store: Store
74
114
  # @rbs args: Array[wasmValue]
@@ -174,10 +214,77 @@ module Wardite
174
214
  # @rbs return: Object
175
215
  def random_get: (Store store, Array[wasmValue] args) -> Object
176
216
 
217
+ # Everything an allowed call before a startup snapshot can observe:
218
+ # arguments, environment, and the kind of every open descriptor.
219
+ # @rbs return: String
220
+ def snapshot_identity: () -> String
221
+
222
+ # @rbs file: IO|File|::Wardite::Wasi::PreopenedDir
223
+ # @rbs return: [Integer, Integer]?
224
+ def fd_kind: (IO | File | ::Wardite::Wasi::PreopenedDir file) -> [ Integer, Integer ]?
225
+
177
226
  private
178
227
 
179
- # @rbs buf: String|nil
228
+ # @rbs store: Wardite::Store
229
+ # @rbs fd: Integer
230
+ # @rbs iovs: Integer
231
+ # @rbs count: Integer
232
+ # @rbs written_at: Integer
233
+ # @rbs return: Integer
234
+ def fd_write_i32: (Wardite::Store store, Integer fd, Integer iovs, Integer count, Integer written_at) -> Integer
235
+
236
+ # @rbs memory: Wardite::Memory
237
+ # @rbs iov: Integer
238
+ # @rbs return: String?
239
+ def iovec_payload: (Wardite::Memory memory, Integer iov) -> String?
240
+
241
+ # Bind the boxed host call to known methods when compiling with Spinel.
242
+ # @rbs name: Symbol
243
+ # @rbs store: Store
244
+ # @rbs args: Array[wasmValue]
245
+ # @rbs return: wasmFuncReturn
246
+ def dispatch_native_import: (Symbol name, Store store, Array[wasmValue] args) -> wasmFuncReturn
247
+
248
+ # @rbs fd: Integer
249
+ # @rbs path: String
250
+ # @rbs return: String | Integer
251
+ def directory_path: (Integer fd, String path) -> (String | Integer)
252
+
253
+ # @rbs error: SystemCallError
254
+ # @rbs return: Integer
255
+ def filesystem_errno: (SystemCallError error) -> Integer
256
+
257
+ # @rbs stat: File::Stat
258
+ # @rbs return: String
259
+ def filestat_bytes: (File::Stat stat) -> String
260
+
261
+ # @rbs return: Array[String]
262
+ def environment_entries: () -> Array[String]
263
+
264
+ # @rbs store: Store
265
+ # @rbs args: Array[wasmValue]
266
+ # @rbs count: Integer
267
+ # @rbs length: Integer
268
+ # @rbs return: Integer
269
+ def write_guest_sizes: (Store store, Array[wasmValue] args, Integer count, Integer length) -> Integer
270
+
271
+ # @rbs store: Store
272
+ # @rbs args: Array[wasmValue]
273
+ # @rbs entries: Array[String]
274
+ # @rbs return: Integer
275
+ def write_guest_strings: (Store store, Array[wasmValue] args, Array[String] entries) -> Integer
276
+
277
+ # @rbs store: Store
278
+ # @rbs offset: Integer
279
+ # @rbs length: Integer
280
+ # @rbs return: String?
281
+ def guest_path: (Store store, Integer offset, Integer length) -> String?
282
+
283
+ # @rbs store: Store
284
+ # @rbs clock_id: Integer
285
+ # @rbs offset: Integer
286
+ # @rbs resolution: bool
180
287
  # @rbs return: Integer
181
- def unpack_le_int: (String | nil buf) -> Integer
288
+ def write_clock: (Store store, Integer clock_id, Integer offset, resolution: bool) -> Integer
182
289
  end
183
290
  end