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
@@ -0,0 +1,145 @@
1
+ # Generated from lib/wardite/efflorescence/store_access.rb with RBS::Inline
2
+
3
+ module Wardite
4
+ module Efflorescence
5
+ # Checked byte operations and global synchronization live off the integer
6
+ # dispatch path. Never retain a Memory#data buffer across a call.
7
+ class StoreAccess
8
+ PAGE_SIZE: ::Integer
9
+
10
+ MAX_PAGES: ::Integer
11
+
12
+ # @rbs start: Integer
13
+ # @rbs length: Integer
14
+ # @rbs size: Integer
15
+ # @rbs return: void
16
+ def self.check_range: (Integer start, Integer length, Integer size) -> void
17
+
18
+ # @rbs store: Wardite::Store
19
+ def initialize: (Wardite::Store store) -> untyped
20
+
21
+ # @rbs index: Integer
22
+ # @rbs return: Wardite::Global
23
+ def global_at: (Integer index) -> Wardite::Global
24
+
25
+ # @rbs index: Integer
26
+ # @rbs return: Integer
27
+ def global_get: (Integer index) -> Integer
28
+
29
+ # @rbs index: Integer
30
+ # @rbs return: Integer
31
+ def global_get_i64: (Integer index) -> Integer
32
+
33
+ # @rbs index: Integer
34
+ # @rbs type: Symbol
35
+ # @rbs return: Integer
36
+ def global_get_float: (Integer index, Symbol type) -> Integer
37
+
38
+ # @rbs index: Integer
39
+ # @rbs type: Symbol
40
+ # @rbs value: Integer
41
+ # @rbs return: void
42
+ def global_set_float: (Integer index, Symbol type, Integer value) -> void
43
+
44
+ # Boxing is confined to the shared Store boundary. Existing register
45
+ # snapshots contain independent integers, never a mutable Global object.
46
+ # @rbs index: Integer
47
+ # @rbs value: Integer
48
+ # @rbs return: void
49
+ def global_set: (Integer index, Integer value) -> void
50
+
51
+ # @rbs index: Integer
52
+ # @rbs value: Integer
53
+ # @rbs return: void
54
+ def global_set_i64: (Integer index, Integer value) -> void
55
+
56
+ # @rbs index: Integer
57
+ # @rbs type: Symbol
58
+ # @rbs return: Integer
59
+ def global_bits_at: (Integer index, Symbol type) -> Integer
60
+
61
+ # @rbs index: Integer
62
+ # @rbs type: Symbol
63
+ # @rbs value: Integer
64
+ # @rbs return: void
65
+ def write_global_bits: (Integer index, Symbol type, Integer value) -> void
66
+
67
+ # @rbs address: Integer
68
+ # @rbs offset: Integer
69
+ # @rbs width: Integer
70
+ # @rbs signed: bool
71
+ # @rbs return: Integer
72
+ def load: (Integer address, Integer offset, Integer width, bool signed) -> Integer
73
+
74
+ # @rbs address: Integer
75
+ # @rbs offset: Integer
76
+ # @rbs width: Integer
77
+ # @rbs signed: bool
78
+ # @rbs return: Integer
79
+ def load_i64: (Integer address, Integer offset, Integer width, bool signed) -> Integer
80
+
81
+ # Check the whole access before the first write. Effective addresses are
82
+ # wide integers; the static offset never wraps back into memory32.
83
+ # @rbs address: Integer
84
+ # @rbs offset: Integer
85
+ # @rbs width: Integer
86
+ # @rbs value: Integer
87
+ # @rbs return: void
88
+ def store: (Integer address, Integer offset, Integer width, Integer value) -> void
89
+
90
+ # @rbs return: Integer
91
+ def size: () -> Integer
92
+
93
+ # Only the buffer preparation boundary handles allocation failure. Ruby
94
+ # implementation errors and traps must propagate rather than look like a
95
+ # successful Wasm instruction returning -1.
96
+ # @rbs delta: Integer
97
+ # @rbs return: Integer
98
+ def grow: (Integer delta) -> Integer
99
+
100
+ # Kept separate so tests can inject allocation failure without requesting
101
+ # gigabytes or depending on the process's available resources.
102
+ # @rbs target: Wardite::Memory
103
+ # @rbs delta: Integer
104
+ # @rbs return: String
105
+ def grown_buffer: (Wardite::Memory target, Integer delta) -> String
106
+
107
+ # Resolve table operands off the hot dispatch path. In particular do not
108
+ # widen its b/c integer-word locals with nullable array reads.
109
+ # @rbs opcode: Integer
110
+ # @rbs site: Wardite::Efflorescence::MemorySite
111
+ # @rbs registers: Array[Integer]
112
+ # @rbs return: void
113
+ def bulk: (Integer opcode, Wardite::Efflorescence::MemorySite site, Array[Integer] registers) -> void
114
+
115
+ # @rbs destination: Integer
116
+ # @rbs source: Integer
117
+ # @rbs length: Integer
118
+ # @rbs return: void
119
+ def copy: (Integer destination, Integer source, Integer length) -> void
120
+
121
+ # @rbs destination: Integer
122
+ # @rbs value: Integer
123
+ # @rbs length: Integer
124
+ # @rbs return: void
125
+ def fill: (Integer destination, Integer value, Integer length) -> void
126
+
127
+ # @rbs index: Integer
128
+ # @rbs destination: Integer
129
+ # @rbs source: Integer
130
+ # @rbs length: Integer
131
+ # @rbs return: void
132
+ def init: (Integer index, Integer destination, Integer source, Integer length) -> void
133
+
134
+ # Read up to four checked little-endian bytes as an unsigned limb.
135
+ # @rbs data: String
136
+ # @rbs start: Integer
137
+ # @rbs width: Integer
138
+ # @rbs return: Integer
139
+ def read_word: (String data, Integer start, Integer width) -> Integer
140
+
141
+ # @rbs return: Wardite::Memory
142
+ def memory: () -> Wardite::Memory
143
+ end
144
+ end
145
+ end
@@ -0,0 +1,218 @@
1
+ # Generated from lib/wardite/efflorescence/translator.rb with RBS::Inline
2
+
3
+ module Wardite
4
+ module Efflorescence
5
+ # The operand/control stacks exist only during translation. Execution uses
6
+ # typed register banks, absolute PCs and explicit per-frame handler stacks.
7
+ class Translator
8
+ class Control
9
+ attr_reader kind: Symbol
10
+
11
+ attr_reader entry_stack: Array[Integer]
12
+
13
+ attr_reader start_pc: Integer
14
+
15
+ attr_reader result_types: Array[Symbol]
16
+
17
+ attr_reader result_registers: Array[Integer]
18
+
19
+ attr_reader patches: Array[Integer]
20
+
21
+ attr_reader catch_patches: Array[Wardite::Efflorescence::CatchTarget]
22
+
23
+ attr_reader handler_depth: Integer
24
+
25
+ attr_reader entry_reachable: bool
26
+
27
+ attr_accessor polymorphic: bool
28
+
29
+ attr_accessor has_branch: bool
30
+
31
+ attr_accessor false_patch: Integer
32
+
33
+ attr_accessor else_seen: bool
34
+
35
+ attr_accessor then_reachable: bool
36
+
37
+ # @rbs kind: Symbol
38
+ # @rbs entry_stack: Array[Integer]
39
+ # @rbs start_pc: Integer
40
+ # @rbs result_types: Array[Symbol]
41
+ # @rbs result_registers: Array[Integer]
42
+ # @rbs handler_depth: Integer
43
+ # @rbs reachable: bool
44
+ def initialize: (Symbol kind, Array[Integer] entry_stack, Integer start_pc, Array[Symbol] result_types, Array[Integer] result_registers, Integer handler_depth, bool reachable) -> untyped
45
+ end
46
+
47
+ BINARY: untyped
48
+
49
+ UNARY: untyped
50
+
51
+ I64_ALU: untyped
52
+
53
+ # Natural alignment exponents; alignment is a hint, not an address rule.
54
+ FLOAT_ALU: Hash[Symbol, Integer]
55
+
56
+ MEMORY_WIDTHS: untyped
57
+
58
+ MEMORY_OPCODES: untyped
59
+
60
+ STORE_CODES: untyped
61
+
62
+ @instance: Wardite::Instance
63
+
64
+ @entries: Array[Wardite::Efflorescence::FunctionEntry]
65
+
66
+ @stack: Array[Integer]
67
+
68
+ @controls: Array[Wardite::Efflorescence::Translator::Control]
69
+
70
+ @constants: Hash[Integer, Integer]
71
+
72
+ @i64_constants: Hash[Integer, Integer]?
73
+
74
+ @f32_constants: Hash[Integer, Integer]?
75
+
76
+ @f64_constants: Hash[Integer, Integer]?
77
+
78
+ @function: Wardite::Efflorescence::Function
79
+
80
+ @reachable: bool
81
+
82
+ @wasm_pc: Integer
83
+
84
+ @handler_depth: Integer
85
+
86
+ # @rbs instance: Wardite::Instance
87
+ def initialize: (Wardite::Instance instance) -> untyped
88
+
89
+ # @rbs return: Wardite::Efflorescence::IR
90
+ def link: () -> Wardite::Efflorescence::IR
91
+
92
+ # @rbs linked: Wardite::Efflorescence::IR
93
+ # @rbs return: Wardite::Efflorescence::IR
94
+ def translate: (?Wardite::Efflorescence::IR linked) -> Wardite::Efflorescence::IR
95
+
96
+ # @rbs wasm: Wardite::WasmFunction
97
+ # @rbs index: Integer
98
+ # @rbs pool_index: Integer
99
+ # @rbs return: Wardite::Efflorescence::Function
100
+ def translate_function: (Wardite::WasmFunction wasm, Integer index, Integer pool_index) -> Wardite::Efflorescence::Function
101
+
102
+ private
103
+
104
+ # Validate even dead instructions before deciding whether to emit MIR.
105
+ # @rbs code: Symbol
106
+ # @rbs operands: Array[Wardite::operandItem]
107
+ # @rbs return: void
108
+ def validate_store_instruction: (Symbol code, Array[Wardite::operandItem] operands) -> void
109
+
110
+ # @rbs index: Integer
111
+ # @rbs return: void
112
+ def check_memory_index: (Integer index) -> void
113
+
114
+ # @rbs value: Wardite::operandItem?
115
+ # @rbs return: Integer
116
+ def integer_operand: (Wardite::operandItem? value) -> Integer
117
+
118
+ # @rbs type: Symbol
119
+ # @rbs return: Integer
120
+ def register: (?Symbol type) -> Integer
121
+
122
+ # @rbs value: Integer
123
+ # @rbs return: Integer
124
+ # @rbs type: Symbol
125
+ def constant: (Integer value, ?Symbol type) -> Integer
126
+
127
+ # @rbs kind: Symbol
128
+ # @rbs types: Array[Symbol]
129
+ # @rbs return: Wardite::Efflorescence::Translator::Control
130
+ def new_control: (Symbol kind, Array[Symbol] types) -> Wardite::Efflorescence::Translator::Control
131
+
132
+ # @rbs instruction: Array[Integer]
133
+ # @rbs return: Integer
134
+ def emit: (Array[Integer] instruction) -> Integer
135
+
136
+ # @rbs pc: Integer
137
+ # @rbs target: Integer
138
+ # @rbs return: void
139
+ def patch: (Integer pc, Integer target) -> void
140
+
141
+ # @rbs return: Integer
142
+ def pop_value: () -> Integer
143
+
144
+ # @rbs register: Integer
145
+ # @rbs return: Symbol
146
+ def type_of: (Integer register) -> Symbol
147
+
148
+ # @rbs type: Symbol
149
+ # @rbs return: Integer
150
+ def pop_typed: (Symbol type) -> Integer
151
+
152
+ # @rbs destination: Integer
153
+ # @rbs source: Integer
154
+ # @rbs return: void
155
+ def copy_value: (Integer destination, Integer source) -> void
156
+
157
+ # @rbs destinations: Array[Integer]
158
+ # @rbs sources: Array[Integer]
159
+ # @rbs return: void
160
+ def parallel_copy: (Array[Integer] destinations, Array[Integer] sources) -> void
161
+
162
+ # @rbs local: Integer
163
+ # @rbs return: void
164
+ def preserve_local: (Integer local) -> void
165
+
166
+ # @rbs return: void
167
+ def snapshot_locals: () -> void
168
+
169
+ # @rbs depth: Integer
170
+ # @rbs return: Wardite::Efflorescence::Translator::Control
171
+ def label: (Integer depth) -> Wardite::Efflorescence::Translator::Control
172
+
173
+ # @rbs target: Wardite::Efflorescence::Translator::Control
174
+ # @rbs return: Array[Symbol]
175
+ def label_types: (Wardite::Efflorescence::Translator::Control target) -> Array[Symbol]
176
+
177
+ # @rbs types: Array[Symbol]
178
+ # @rbs return: Array[Integer]
179
+ def top_values: (Array[Symbol] types) -> Array[Integer]
180
+
181
+ # @rbs target: Wardite::Efflorescence::Translator::Control
182
+ # @rbs sources: Array[Integer]
183
+ # @rbs condition: Integer
184
+ # @rbs return: void
185
+ def branch: (Wardite::Efflorescence::Translator::Control target, Array[Integer] sources, ?Integer condition) -> void
186
+
187
+ # @rbs index: Integer
188
+ # @rbs return: Wardite::Efflorescence::Tag
189
+ def tag_at: (Integer index) -> Wardite::Efflorescence::Tag
190
+
191
+ # Catch labels resolve before pushing the try_table's own label.
192
+ # @rbs clauses: Array[Integer]
193
+ # @rbs return: Wardite::Efflorescence::HandlerDescriptor
194
+ def make_handler: (Array[Integer] clauses) -> Wardite::Efflorescence::HandlerDescriptor
195
+
196
+ # @rbs control: Wardite::Efflorescence::Translator::Control
197
+ # @rbs return: void
198
+ def finish_arm: (Wardite::Efflorescence::Translator::Control control) -> void
199
+
200
+ # @rbs return: void
201
+ def else_control: () -> void
202
+
203
+ # @rbs return: void
204
+ def end_control: () -> void
205
+
206
+ # @rbs return: void
207
+ def mark_unreachable: () -> void
208
+
209
+ # @rbs message: String
210
+ # @rbs return: String
211
+ def context: (String message) -> String
212
+
213
+ # @rbs message: String
214
+ # @rbs return: bot
215
+ def fail_translation: (String message) -> bot
216
+ end
217
+ end
218
+ end
@@ -0,0 +1,240 @@
1
+ # Generated from lib/wardite/efflorescence/vm.rb with RBS::Inline
2
+
3
+ module Wardite
4
+ module Efflorescence
5
+ class VM
6
+ attr_reader instance: Wardite::Instance
7
+
8
+ attr_reader ir: Wardite::Efflorescence::IR
9
+
10
+ attr_reader metrics: Wardite::Efflorescence::Metrics
11
+
12
+ attr_reader mir_cache_hit: bool
13
+
14
+ attr_reader mir_cache: Wardite::Efflorescence::MIRCache?
15
+
16
+ # Records a startup snapshot before the first WASI call outside its allowlist.
17
+ attr_accessor snapshot: Wardite::Efflorescence::Snapshot?
18
+
19
+ @global_bits: Array[Integer]
20
+
21
+ @optimized_ir: Wardite::Efflorescence::IR?
22
+
23
+ @semantic_ir: Wardite::Efflorescence::IR?
24
+
25
+ # @rbs instance: Wardite::Instance
26
+ # @rbs disabled_optimizations: Array[Symbol]
27
+ # @rbs profile: bool
28
+ # @rbs mir_cache: Wardite::Efflorescence::MIRCache?
29
+ # @rbs cached_functions: Array[Function]?
30
+ # @rbs cache_checked: bool
31
+ def initialize: (Wardite::Instance instance, ?disabled_optimizations: Array[Symbol], ?profile: bool, ?mir_cache: Wardite::Efflorescence::MIRCache?, ?cached_functions: Array[Function]?, ?cache_checked: bool) -> untyped
32
+
33
+ # A caller explicitly inspecting a cache hit can still request the
34
+ # intermediate forms. Execution continues to use the restored MIR2.
35
+ # @rbs return: Wardite::Efflorescence::IR
36
+ def semantic_ir: () -> Wardite::Efflorescence::IR
37
+
38
+ # @rbs return: Wardite::Efflorescence::IR
39
+ def optimized_ir: () -> Wardite::Efflorescence::IR
40
+
41
+ # @rbs name: String|Symbol
42
+ # @rbs return: bool
43
+ def callable?: (String | Symbol name) -> bool
44
+
45
+ # Compatible with Runtime.call: boxing happens once, at the Ruby boundary.
46
+ # @rbs name: String|Symbol
47
+ # @rbs arguments: Array[Object]
48
+ # @rbs return: Wardite::wasmValue?
49
+ def call: (String | Symbol name, Array[Object] arguments) -> Wardite::wasmValue?
50
+
51
+ # Integers retain their register representation. Floats cross as Ruby Float.
52
+ # @rbs name: String|Symbol
53
+ # @rbs arguments: Array[Object]
54
+ # @rbs return: (Integer | Float)?
55
+ def call_unboxed: (String | Symbol name, Array[Object] arguments) -> (Integer | Float)?
56
+
57
+ # @rbs name: Symbol
58
+ # @rbs *arguments: Object
59
+ # @rbs return: Wardite::wasmValue?
60
+ def method_missing: (Symbol name, *Object arguments) -> Wardite::wasmValue?
61
+
62
+ # @rbs name: String|Symbol
63
+ # @rbs include_private: bool
64
+ # @rbs return: bool
65
+ def respond_to_missing?: (String | Symbol name, ?bool include_private) -> bool
66
+
67
+ # @rbs return: String
68
+ def dump_mir: () -> String
69
+
70
+ # Continue a public call restored from a startup snapshot. Each frame
71
+ # resumes at its saved pc: the host call for the top, a return for others.
72
+ # @rbs saved: Array[Wardite::Efflorescence::SavedFrame]
73
+ # @rbs return: void
74
+ def resume: (Array[Wardite::Efflorescence::SavedFrame] saved) -> void
75
+
76
+ private
77
+
78
+ # @rbs translator: Wardite::Efflorescence::Translator
79
+ # @rbs linked: Wardite::Efflorescence::IR
80
+ # @rbs profile: bool
81
+ # @rbs return: Wardite::Efflorescence::IR
82
+ def build_mir: (Wardite::Efflorescence::Translator translator, Wardite::Efflorescence::IR linked, bool profile) -> Wardite::Efflorescence::IR
83
+
84
+ # @rbs return: void
85
+ def restore_inspection_ir: () -> void
86
+
87
+ # @rbs name: String|Symbol
88
+ # @rbs return: Wardite::Efflorescence::FunctionEntry
89
+ def export_entry: (String | Symbol name) -> Wardite::Efflorescence::FunctionEntry
90
+
91
+ # @rbs entry: Wardite::Efflorescence::FunctionEntry
92
+ # @rbs arguments: Array[Object]
93
+ # @rbs return: Integer?
94
+ def execute_public: (Wardite::Efflorescence::FunctionEntry entry, Array[Object] arguments) -> Integer?
95
+
96
+ # @rbs type: Symbol
97
+ # @rbs value: Object?
98
+ # @rbs return: Integer?
99
+ def float_argument: (Symbol type, Object? value) -> Integer?
100
+
101
+ # @rbs type: Symbol
102
+ # @rbs bits: Integer
103
+ # @rbs return: Integer | Float
104
+ def unbox_result: (Symbol type, Integer bits) -> (Integer | Float)
105
+
106
+ # @rbs type: Symbol
107
+ # @rbs bits: Integer
108
+ # @rbs return: Wardite::wasmValue
109
+ def box_result: (Symbol type, Integer bits) -> Wardite::wasmValue
110
+
111
+ # A concrete return type breaks the inference cycle between the current
112
+ # frame and the array it is restored from after every internal RETURN.
113
+ # @rbs return: Wardite::Efflorescence::Frame
114
+ def current_frame: (untyped frames) -> Wardite::Efflorescence::Frame
115
+
116
+ # @rbs value: Integer
117
+ # @rbs return: Integer
118
+ def signed: (Integer value) -> Integer
119
+
120
+ # Cold/new ALU paths stay outside the established hot-loop operations.
121
+ # @rbs opcode: Integer
122
+ # @rbs left: Integer
123
+ # @rbs right: Integer
124
+ # @rbs return: Integer
125
+ def calculate: (Integer opcode, Integer left, Integer right) -> Integer
126
+
127
+ # The pending value owns its payload before any frame is released. No
128
+ # Ruby raise/rescue is used to unwind the explicit Wasm call stack.
129
+ # @rbs value: Wardite::Efflorescence::ExceptionValue
130
+ # @rbs frames: Array[Wardite::Efflorescence::Frame]
131
+ # @rbs pools: Array[Wardite::Efflorescence::FramePool]
132
+ # @rbs return: Wardite::Efflorescence::Frame
133
+ def propagate: (Wardite::Efflorescence::ExceptionValue value, Array[Wardite::Efflorescence::Frame] frames, Array[Wardite::Efflorescence::FramePool] pools) -> Wardite::Efflorescence::Frame
134
+
135
+ # @rbs frame: Wardite::Efflorescence::Frame
136
+ # @rbs id: Integer
137
+ # @rbs return: Wardite::Efflorescence::ExceptionValue
138
+ def exception_at: (Wardite::Efflorescence::Frame frame, Integer id) -> Wardite::Efflorescence::ExceptionValue
139
+
140
+ # @rbs pools: Array[Wardite::Efflorescence::FramePool]
141
+ # @rbs index: Integer
142
+ # @rbs return: Wardite::Efflorescence::FramePool
143
+ def pool_at: (Array[Wardite::Efflorescence::FramePool] pools, Integer index) -> Wardite::Efflorescence::FramePool
144
+
145
+ # Update in place so a suspended execute_flat retains the same array
146
+ # across a host call, including a reentrant call on this VM.
147
+ # @rbs return: void
148
+ def read_globals: () -> void
149
+
150
+ # @rbs return: void
151
+ def write_globals: () -> void
152
+
153
+ # @rbs host_index: Integer
154
+ # @rbs arguments: Array[Integer]
155
+ # @rbs metrics: Wardite::Efflorescence::Metrics
156
+ # @rbs sources: Array[Integer]?
157
+ # @rbs return: Integer?
158
+ def invoke_host_with_globals: (Integer host_index, Array[Integer] arguments, Wardite::Efflorescence::Metrics metrics, Array[Integer]? sources) -> Integer?
159
+
160
+ # @rbs host_index: Integer
161
+ # @rbs arguments: Array[Integer]
162
+ # @rbs metrics: Wardite::Efflorescence::Metrics
163
+ # @rbs sources: Array[Integer]?
164
+ # @rbs return: Integer?
165
+ def invoke_host: (Integer host_index, Array[Integer] arguments, Wardite::Efflorescence::Metrics metrics, Array[Integer]? sources) -> Integer?
166
+
167
+ # @rbs host: Wardite::Efflorescence::HostFunction
168
+ # @rbs arguments: Array[Integer]
169
+ # @rbs sources: Array[Integer]?
170
+ # @rbs return: Integer?
171
+ def invoke_typed_host: (Wardite::Efflorescence::HostFunction host, Array[Integer] arguments, Array[Integer]? sources) -> Integer?
172
+
173
+ # Each public or start entry owns its frames, pools and counters. Host
174
+ # calls synchronize globals before a callback can re-enter the VM.
175
+ # @rbs entry: Wardite::Efflorescence::FunctionEntry
176
+ # @rbs arguments: Array[Integer]
177
+ # @rbs return: Integer?
178
+ def execute: (Wardite::Efflorescence::FunctionEntry entry, Array[Integer] arguments) -> Integer?
179
+
180
+ # @rbs return: Array[Wardite::Efflorescence::FramePool]
181
+ def new_pools: () -> Array[Wardite::Efflorescence::FramePool]
182
+
183
+ # Globals live in @global_bits while frames run. A restored snapshot
184
+ # writes the Store first, so both public calls and resume read it here.
185
+ # @rbs pools: Array[Wardite::Efflorescence::FramePool]
186
+ # @rbs active_frames: Array[Wardite::Efflorescence::Frame]
187
+ # @rbs root_entries: Integer
188
+ # @rbs return: Integer
189
+ def run_frames: (Array[Wardite::Efflorescence::FramePool] pools, Array[Wardite::Efflorescence::Frame] active_frames, Integer root_entries) -> Integer
190
+
191
+ # @rbs frame: Wardite::Efflorescence::Frame
192
+ # @rbs site: Wardite::Efflorescence::DynamicCallSite
193
+ # @rbs host_index: Integer
194
+ # @rbs destination: Integer
195
+ # @rbs metrics: Wardite::Efflorescence::Metrics
196
+ # @rbs return: void
197
+ def execute_host_site: (Wardite::Efflorescence::Frame frame, Wardite::Efflorescence::DynamicCallSite site, Integer host_index, Integer destination, Wardite::Efflorescence::Metrics metrics) -> void
198
+
199
+ # @rbs site: Wardite::Efflorescence::DynamicCallSite
200
+ # @rbs selector: Integer
201
+ # @rbs return: Wardite::Efflorescence::FunctionEntry
202
+ def indirect_entry: (Wardite::Efflorescence::DynamicCallSite site, Integer selector) -> Wardite::Efflorescence::FunctionEntry
203
+
204
+ # @rbs frame: Wardite::Efflorescence::Frame
205
+ # @rbs site_id: Integer
206
+ # @rbs destination: Integer
207
+ # @rbs metrics: Wardite::Efflorescence::Metrics
208
+ # @rbs return: void
209
+ def execute_direct_host: (Wardite::Efflorescence::Frame frame, Integer site_id, Integer destination, Wardite::Efflorescence::Metrics metrics) -> void
210
+
211
+ # Keep table resolution and the additional call locals off the hot path.
212
+ # @rbs frame: Wardite::Efflorescence::Frame
213
+ # @rbs pools: Array[Wardite::Efflorescence::FramePool]
214
+ # @rbs frames: Array[Wardite::Efflorescence::Frame]
215
+ # @rbs destination: Integer
216
+ # @rbs site_id: Integer
217
+ # @rbs selector: Integer
218
+ # @rbs metrics: Wardite::Efflorescence::Metrics
219
+ # @rbs return: Wardite::Efflorescence::Frame
220
+ def execute_indirect: (Wardite::Efflorescence::Frame frame, Array[Wardite::Efflorescence::FramePool] pools, Array[Wardite::Efflorescence::Frame] frames, Integer destination, Integer site_id, Integer selector, Wardite::Efflorescence::Metrics metrics) -> Wardite::Efflorescence::Frame
221
+
222
+ # Float instructions use the same flat words and integer registers.
223
+ # Their dispatch stays outside the main integer switch.
224
+ # @rbs opcode: Integer
225
+ # @rbs instructions: Array[Integer]
226
+ # @rbs pc: Integer
227
+ # @rbs a: Integer
228
+ # @rbs registers: Array[Integer]
229
+ # @rbs return: void
230
+ def execute_float: (Integer opcode, Array[Integer] instructions, Integer pc, Integer a, Array[Integer] registers) -> void
231
+
232
+ # @rbs frame: Wardite::Efflorescence::Frame
233
+ # @rbs pools: Array[Wardite::Efflorescence::FramePool]
234
+ # @rbs active_frames: Array[Wardite::Efflorescence::Frame]
235
+ # @rbs return: Integer
236
+ # @rbs metrics: Wardite::Efflorescence::Metrics
237
+ def execute_flat: (Wardite::Efflorescence::Frame frame, Array[Wardite::Efflorescence::FramePool] pools, Array[Wardite::Efflorescence::Frame] active_frames, Wardite::Efflorescence::Metrics metrics) -> Integer
238
+ end
239
+ end
240
+ end
@@ -0,0 +1,34 @@
1
+ # Generated from lib/wardite/efflorescence/wasi.rb with RBS::Inline
2
+
3
+ module Wardite
4
+ module Efflorescence
5
+ class WasiSnapshotPreview1 < Wardite::WasiSnapshotPreview1
6
+ FD_WRITE_ARGUMENTS: untyped
7
+
8
+ PROC_EXIT_ARGUMENTS: untyped
9
+
10
+ # @rbs fnname: Symbol
11
+ # @rbs return: Wardite::_WasmCallable
12
+ def callable: (Symbol fnname) -> Wardite::_WasmCallable
13
+
14
+ # @rbs environment: Wardite::Efflorescence::WasiSnapshotPreview1
15
+ # @rbs function: Wardite::ExternalFunction
16
+ # @rbs return: Wardite::Efflorescence::_WasiCallable?
17
+ def self.unboxed_callable: (Wardite::Efflorescence::WasiSnapshotPreview1 environment, Wardite::ExternalFunction function) -> Wardite::Efflorescence::_WasiCallable?
18
+
19
+ private
20
+
21
+ # @rbs store: Wardite::Store
22
+ # @rbs values: Array[Integer]
23
+ # @rbs sources: Array[Integer]?
24
+ # @rbs return: Integer
25
+ def fd_write_from_registers: (Wardite::Store store, Array[Integer] values, Array[Integer]? sources) -> Integer
26
+
27
+ # @rbs _store: Wardite::Store
28
+ # @rbs values: Array[Integer]
29
+ # @rbs sources: Array[Integer]?
30
+ # @rbs return: bot
31
+ def proc_exit_from_registers: (untyped _store, Array[Integer] values, Array[Integer]? sources) -> bot
32
+ end
33
+ end
34
+ end
@@ -7,6 +7,18 @@ module Wardite
7
7
  class WebAssemblyError < StandardError
8
8
  end
9
9
 
10
+ class UncaughtWasmException < WebAssemblyError
11
+ attr_reader exception_value: Wardite::Efflorescence::ExceptionValue
12
+
13
+ attr_reader tag: Wardite::Efflorescence::Tag
14
+
15
+ # Public payloads follow tag order, with floats decoded at the boundary.
16
+ attr_reader payload: Array[Integer | Float]
17
+
18
+ # @rbs value: Wardite::Efflorescence::ExceptionValue
19
+ def initialize: (Wardite::Efflorescence::ExceptionValue value) -> untyped
20
+ end
21
+
10
22
  class IntegerOverflow < WebAssemblyError
11
23
  end
12
24
  end
@@ -0,0 +1,30 @@
1
+ # Generated from lib/wardite/float_bits.rb with RBS::Inline
2
+
3
+ module Wardite
4
+ module FloatBits
5
+ # @rbs type: Symbol
6
+ # @rbs return: bool
7
+ def self.float_type?: (Symbol type) -> bool
8
+
9
+ # f32 carriers are unsigned, f64 carriers are signed.
10
+ # @rbs type: Symbol
11
+ # @rbs bytes: String
12
+ # @rbs return: Integer
13
+ def self.read: (Symbol type, String bytes) -> Integer
14
+
15
+ # @rbs type: Symbol
16
+ # @rbs bits: Integer
17
+ # @rbs return: String
18
+ def self.write: (Symbol type, Integer bits) -> String
19
+
20
+ # @rbs type: Symbol
21
+ # @rbs bits: Integer
22
+ # @rbs return: Float
23
+ def self.to_float: (Symbol type, Integer bits) -> Float
24
+
25
+ # @rbs type: Symbol
26
+ # @rbs value: Float
27
+ # @rbs return: Integer
28
+ def self.from_float: (Symbol type, Float value) -> Integer
29
+ end
30
+ end