wardite 1.0.0 → 1.2.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 (64) hide show
  1. checksums.yaml +4 -4
  2. data/Makefile +9 -1
  3. data/README.md +65 -7
  4. data/Steepfile +1 -0
  5. data/assets/wardite.svg +12 -0
  6. data/benchmark/count_ruby_wasm_functions.rb +37 -0
  7. data/benchmark/measure_mir_cache_restore.rb +59 -0
  8. data/benchmark/measure_mir_cache_verify.rb +58 -0
  9. data/benchmark/measure_ruby_wasm_cache_hit.rb +59 -0
  10. data/benchmark/measure_ruby_wasm_startup.rb +43 -0
  11. data/benchmark/results/efflorescence-mir2-cache-integrity.json +390 -0
  12. data/benchmark/results/efflorescence-mir2-function-restore.json +480 -0
  13. data/benchmark/results/efflorescence-unboxed-globals.json +3451 -0
  14. data/docs/adr/0007-efflorescence-ruby-wasm-phase1.md +75 -0
  15. data/docs/adr/0008-efflorescence-ruby-wasm-phase2.md +75 -0
  16. data/docs/adr/0009-efflorescence-mir2-cache-integrity-modes.md +77 -0
  17. data/docs/adr/0010-efflorescence-mir2-cache-function-restore.md +80 -0
  18. data/docs/adr/0011-efflorescence-unboxed-globals.md +89 -0
  19. data/docs/adr/0012-efflorescence-startup-snapshot.md +173 -0
  20. data/docs/adr/0013-efflorescence-frame-acquisition.md +114 -0
  21. data/docs/efflorescence-generated-c-guards.md +5 -0
  22. data/docs/efflorescence-mir2-cache.md +152 -0
  23. data/docs/efflorescence-ruby-wasm-phase1.md +90 -0
  24. data/docs/efflorescence-spinel-linear-memory.md +74 -0
  25. data/docs/efflorescence-startup-snapshot.md +60 -0
  26. data/docs/efflorescence-unboxed-globals.md +61 -0
  27. data/lib/wardite/alu_f32.generated.rb +10 -2
  28. data/lib/wardite/alu_f64.generated.rb +10 -2
  29. data/lib/wardite/alu_i32.generated.rb +40 -8
  30. data/lib/wardite/alu_i64.generated.rb +55 -11
  31. data/lib/wardite/cli/cli.rb +58 -6
  32. data/lib/wardite/efflorescence/ir.rb +26 -4
  33. data/lib/wardite/efflorescence/mir_cache.rb +749 -0
  34. data/lib/wardite/efflorescence/register_validation.rb +128 -56
  35. data/lib/wardite/efflorescence/snapshot.rb +232 -0
  36. data/lib/wardite/efflorescence/store_access.rb +103 -8
  37. data/lib/wardite/efflorescence/translator.rb +10 -3
  38. data/lib/wardite/efflorescence/vm.rb +203 -38
  39. data/lib/wardite/efflorescence/wasi.rb +0 -56
  40. data/lib/wardite/efflorescence.rb +6 -0
  41. data/lib/wardite/load.rb +109 -24
  42. data/lib/wardite/version.rb +1 -1
  43. data/lib/wardite/wasi/spinel.rb +41 -0
  44. data/lib/wardite/wasi.rb +483 -268
  45. data/lib/wardite.rb +218 -70
  46. data/scripts/build_spinel_zig.rb +121 -0
  47. data/scripts/gen_alu.rb +55 -11
  48. data/scripts/verify_ruby_wasm.rb +70 -0
  49. data/sig/generated/wardite/cli/cli.rbs +15 -0
  50. data/sig/generated/wardite/efflorescence/ir.rbs +12 -2
  51. data/sig/generated/wardite/efflorescence/mir_cache.rbs +263 -0
  52. data/sig/generated/wardite/efflorescence/register_validation.rbs +31 -3
  53. data/sig/generated/wardite/efflorescence/snapshot.rbs +84 -0
  54. data/sig/generated/wardite/efflorescence/store_access.rbs +13 -2
  55. data/sig/generated/wardite/efflorescence/translator.rbs +5 -1
  56. data/sig/generated/wardite/efflorescence/vm.rbs +68 -7
  57. data/sig/generated/wardite/efflorescence/wasi.rbs +0 -13
  58. data/sig/generated/wardite/load.rbs +33 -5
  59. data/sig/generated/wardite/wasi/spinel.rbs +15 -0
  60. data/sig/generated/wardite/wasi.rbs +111 -4
  61. data/sig/generated/wardite.rbs +67 -3
  62. data/sig/io_buffer.rbs +7 -0
  63. data/sig/mir_cache_stdlib.rbs +5 -0
  64. metadata +32 -1
@@ -0,0 +1,70 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "digest"
4
+ require "open3"
5
+ require "rbconfig"
6
+ require "tmpdir"
7
+
8
+ wasm = File.expand_path(ARGV.fetch(0) { abort "Usage: ruby #{$PROGRAM_NAME} RUBY.wasm" })
9
+ root = File.expand_path("..", __dir__)
10
+ wardite = [RbConfig.ruby, "-I#{root}/lib", "#{root}/exe/wardite", "--new-engine"]
11
+ spinel = ENV["WARDITE_SPINEL_BIN"]
12
+ native = [File.expand_path(spinel), "--new-engine"] if spinel
13
+
14
+ puts "Ruby WASM SHA-256 #{Digest::SHA256.file(wasm).hexdigest}"
15
+ Dir.mktmpdir("wardite-ruby-wasm") do |workdir|
16
+ app_dir = File.join(workdir, "app")
17
+ Dir.mkdir(app_dir)
18
+ File.write(File.join(app_dir, "main.rb"), "require_relative 'answer'\nputs ANSWER\n")
19
+ File.write(File.join(app_dir, "answer.rb"), "ANSWER = 42\n")
20
+ cases = [
21
+ ["-e", [], [], ["-e", "puts RUBY_VERSION; puts 6*7"], "4.0.9\n42\n", 0],
22
+ ["require_relative", ["--dir", "#{app_dir}::/app"], ["--mapdir", "#{app_dir}:/app"], ["/app/main.rb"], "42\n", 0],
23
+ ["exit 7", [], [], ["-e", "exit 7"], "", 7],
24
+ ]
25
+ cases.each_with_index do |(name, reference_options, wardite_options, arguments, expected, expected_exit), index|
26
+ guest_args = [wasm, "--disable-gems", *arguments]
27
+ commands = [
28
+ ["Wasmtime", ["wasmtime", "run", *reference_options, *guest_args]],
29
+ ["Efflorescence", [*wardite, *wardite_options, "--", *guest_args]],
30
+ ]
31
+ commands << ["Spinel Efflorescence", [*native, *wardite_options, "--", *guest_args]] if native
32
+ if ENV["WARDITE_VERIFY_MIR_CACHE"] == "1"
33
+ engines = [["Efflorescence", wardite, "cruby-cache"]]
34
+ engines << ["Spinel Efflorescence", native, "spinel-cache"] if native
35
+ engines.each do |name, engine, cache|
36
+ cached = [*engine, "--mir-cache", File.join(workdir, cache)]
37
+ invocation = [*wardite_options, "--", *guest_args]
38
+ commands << ["#{name} (cache miss)", [*cached, *invocation], "MIR2 cache miss:"] if index.zero?
39
+ %w[checksum sha256].each do |mode|
40
+ commands << ["#{name} (#{mode} cache hit)", [*cached, "--mir-cache-verify", mode, *invocation], "MIR2 cache hit:"]
41
+ end
42
+ end
43
+ end
44
+ if ENV["WARDITE_VERIFY_SNAPSHOT"] == "1"
45
+ engines = [["Efflorescence", wardite, "cruby"]]
46
+ engines << ["Spinel Efflorescence", native, "spinel"] if native
47
+ engines.each do |name, engine, host|
48
+ snapshot = [*engine, "--mir-cache", File.join(workdir, "#{host}-snapshot-cache"),
49
+ "--snapshot", File.join(workdir, "#{host}-snapshot"), *wardite_options, "--", *guest_args]
50
+ commands << ["#{name} (snapshot save)", snapshot, "snapshot saved:"]
51
+ commands << ["#{name} (snapshot restore)", snapshot, "snapshot restored:"]
52
+ end
53
+ end
54
+ commands.each do |runtime, command, trace|
55
+ env = trace ? {"WARDITE_TRACE" => "1"} : {}
56
+ stdout, stderr, status = if defined?(Bundler)
57
+ Bundler.with_original_env { Open3.capture3(env, *command) }
58
+ else
59
+ Open3.capture3(env, *command)
60
+ end
61
+ unless stdout == expected && status.exitstatus == expected_exit
62
+ abort "#{runtime} #{name}: #{status.inspect}, stdout=#{stdout.inspect}\n#{stderr}"
63
+ end
64
+ if trace && !stderr.include?(trace)
65
+ abort "#{runtime} #{name}: expected #{trace}\n#{stderr}"
66
+ end
67
+ end
68
+ puts "#{name} matched Wasmtime (exit #{expected_exit})"
69
+ end
70
+ end
@@ -2,6 +2,12 @@
2
2
 
3
3
  module Wardite
4
4
  module Cli
5
+ # Keep the summary accumulator's type consistent in native builds.
6
+ class SpinelOptions < OptionParser
7
+ # @rbs return: String
8
+ def help: () -> String
9
+ end
10
+
5
11
  class Cli
6
12
  @args: Array[String]
7
13
 
@@ -25,6 +31,10 @@ module Wardite
25
31
 
26
32
  attr_reader mir_profile: bool
27
33
 
34
+ attr_reader mir_cache: String?
35
+
36
+ attr_reader snapshot: String?
37
+
28
38
  attr_reader profile_file_path: String?
29
39
 
30
40
  # @rbs args: Array[String]
@@ -49,6 +59,11 @@ module Wardite
49
59
  # @rbs return: void
50
60
  def invoke_wasi: () -> void
51
61
 
62
+ # The snapshot key reads the environment, so build it where _start runs.
63
+ # @rbs instance: ::Wardite::Instance
64
+ # @rbs return: void
65
+ def start_wasi: (::Wardite::Instance instance) -> void
66
+
52
67
  # @rbs return: String?
53
68
  def mount_src: () -> String?
54
69
 
@@ -590,7 +590,9 @@ module Wardite
590
590
 
591
591
  attr_reader result_types: Array[Symbol]
592
592
 
593
- attr_reader local_count: Integer
593
+ attr_accessor local_count: Integer
594
+
595
+ attr_accessor cache_pending: bool
594
596
 
595
597
  attr_reader instructions: Array[Wardite::Efflorescence::Instruction]
596
598
 
@@ -667,6 +669,13 @@ module Wardite
667
669
  # @rbs return: Wardite::Efflorescence::CallSite
668
670
  def call_site: (Integer index) -> Wardite::Efflorescence::CallSite
669
671
 
672
+ # @rbs return: Integer
673
+ def call_site_count: () -> Integer
674
+
675
+ # @rbs site: Wardite::Efflorescence::CallSite
676
+ # @rbs return: void
677
+ def add_call_site: (Wardite::Efflorescence::CallSite site) -> void
678
+
670
679
  # @rbs index: Integer
671
680
  # @rbs return: Wardite::Efflorescence::MemorySite
672
681
  def memory_site: (Integer index) -> Wardite::Efflorescence::MemorySite
@@ -867,7 +876,8 @@ module Wardite
867
876
 
868
877
  # @rbs function: Wardite::Efflorescence::Function
869
878
  # @rbs reuse: bool
870
- def initialize: (Wardite::Efflorescence::Function function, bool reuse) -> untyped
879
+ # @rbs cache: Wardite::Efflorescence::MIRCache?
880
+ def initialize: (Wardite::Efflorescence::Function function, bool reuse, ?Wardite::Efflorescence::MIRCache? cache) -> untyped
871
881
 
872
882
  # @rbs destination: Integer
873
883
  # @rbs return: Wardite::Efflorescence::Frame
@@ -0,0 +1,263 @@
1
+ # Generated from lib/wardite/efflorescence/mir_cache.rb with RBS::Inline
2
+
3
+ module Wardite
4
+ module Efflorescence
5
+ # Local, opt-in cache of the verified output of Lowerer. Bump CODE_VERSION
6
+ # when the generated code or its interpretation changes, including opcodes,
7
+ # optimizer/validator fixes, and changes to the metadata used by the VM.
8
+ class MIRCache
9
+ MAGIC: untyped
10
+
11
+ FORMAT_VERSION: ::Integer
12
+
13
+ CODE_VERSION: ::Integer
14
+
15
+ DIGEST_SIZE: ::Integer
16
+
17
+ LENGTH_SIZE: ::Integer
18
+
19
+ INTEGRITY_SIZE: untyped
20
+
21
+ SAMPLE_EDGE: untyped
22
+
23
+ SAMPLE_STEP: untyped
24
+
25
+ SAMPLE_BLOCK: untyped
26
+
27
+ MAX_BYTES: untyped
28
+
29
+ TYPES: untyped
30
+
31
+ TYPE_IDS: untyped
32
+
33
+ USES_I64: ::Integer
34
+
35
+ USES_FLOAT: ::Integer
36
+
37
+ USES_EH: ::Integer
38
+
39
+ USES_STORE: ::Integer
40
+
41
+ USES_DYNAMIC_CALLS: ::Integer
42
+
43
+ FUNCTION_FLAGS: untyped
44
+
45
+ class Invalid < StandardError
46
+ end
47
+
48
+ # Identifies the module, the generated code, and the host build.
49
+ attr_reader key: String
50
+
51
+ # All records are little-endian. Vectors carry a nonnegative 32-bit element count.
52
+ # A record count is bounded by the bytes still available to decode it.
53
+ class Reader
54
+ attr_reader offset: Integer
55
+
56
+ # @rbs bytes: String
57
+ # @rbs offset: Integer
58
+ # @rbs length: Integer?
59
+ def initialize: (String bytes, ?offset: Integer, ?length: Integer?) -> untyped
60
+
61
+ # @rbs length: Integer
62
+ # @rbs return: String
63
+ def bytes: (Integer length) -> String
64
+
65
+ # @rbs return: Integer
66
+ def integer: () -> Integer
67
+
68
+ # @rbs width: Integer
69
+ # @rbs return: Integer
70
+ def count: (Integer width) -> Integer
71
+
72
+ # @rbs format: String
73
+ # @rbs width: Integer
74
+ # @rbs return: Array[Integer]
75
+ def vector: (String format, Integer width) -> Array[Integer]
76
+
77
+ # @rbs target: Array[Integer]
78
+ # @rbs format: String
79
+ # @rbs width: Integer
80
+ # @rbs return: void
81
+ def read_into: (Array[Integer] target, String format, Integer width) -> void
82
+
83
+ # @rbs return: Array[Symbol]
84
+ def types: () -> Array[Symbol]
85
+
86
+ # @rbs return: void
87
+ def finish: () -> void
88
+
89
+ private
90
+
91
+ # @rbs length: Integer
92
+ # @rbs return: void
93
+ def ensure_bytes: (Integer length) -> void
94
+ end
95
+
96
+ class Writer
97
+ attr_reader bytes: String
98
+
99
+ def initialize: () -> untyped
100
+
101
+ # @rbs *values: Integer
102
+ # @rbs return: void
103
+ def integers: (*Integer values) -> void
104
+
105
+ # @rbs values: Array[Integer]
106
+ # @rbs format: String
107
+ # @rbs return: void
108
+ def vector: (Array[Integer] values, ?String format) -> void
109
+
110
+ # @rbs types: Array[Symbol]
111
+ # @rbs return: void
112
+ def types: (Array[Symbol] types) -> void
113
+
114
+ # @rbs function: Function
115
+ # @rbs return: void
116
+ def function: (Function function) -> void
117
+ end
118
+
119
+ class Decoder
120
+ include Opcode
121
+
122
+ attr_reader functions: Array[Function]
123
+
124
+ # Reuse the semantic register roles for fixed operands. Lowering
125
+ # moves direct call arguments into a side table and leaves optional
126
+ # destinations and return operands to be checked against signatures.
127
+ REGISTER_MASKS: Array[Integer]
128
+
129
+ EXTRA_OPERANDS: Array[Symbol?]
130
+
131
+ # @rbs payload: String
132
+ # @rbs instance: Wardite::Instance
133
+ # @rbs entries: Array[FunctionEntry]
134
+ def initialize: (String payload, Wardite::Instance instance, Array[FunctionEntry] entries) -> untyped
135
+
136
+ # @rbs layout: String
137
+ # @rbs return: void
138
+ def declare: (String layout) -> void
139
+
140
+ # A failed decode must never expose a partially filled function. Keep
141
+ # the slot unavailable even if a Ruby caller catches the error.
142
+ # @rbs function: Function
143
+ # @rbs return: void
144
+ def restore: (Function function) -> void
145
+
146
+ private
147
+
148
+ # @rbs body: Wardite::CodeSection::CodeBody
149
+ # @rbs function: Function
150
+ # @rbs return: void
151
+ def read_function: (Wardite::CodeSection::CodeBody body, Function function) -> void
152
+
153
+ # @rbs function: Function
154
+ # @rbs functions: Array[Function]
155
+ # @rbs return: void
156
+ def read_sites: (Function function, Array[Function] functions) -> void
157
+
158
+ # @rbs function: Function
159
+ # @rbs return: DynamicCallSite
160
+ def read_dynamic_site: (Function function) -> DynamicCallSite
161
+
162
+ # @rbs function: Function
163
+ # @rbs return: MemorySite
164
+ def read_memory_site: (Function function) -> MemorySite
165
+
166
+ # @rbs function: Function
167
+ # @rbs handler_count: Integer
168
+ # @rbs return: CatchTarget
169
+ def read_catch: (Function function, Integer handler_count) -> CatchTarget
170
+
171
+ # @rbs function: Function
172
+ # @rbs return: void
173
+ def check_code: (Function function) -> void
174
+
175
+ # @rbs tag: Integer
176
+ # @rbs return: Array[Symbol]
177
+ def tag_types: (Integer tag) -> Array[Symbol]
178
+
179
+ # @rbs function: Function
180
+ # @rbs registers: Array[Integer]
181
+ # @rbs types: Array[Symbol]
182
+ # @rbs return: void
183
+ def check_arguments: (Function function, Array[Integer] registers, Array[Symbol] types) -> void
184
+
185
+ # @rbs function: Function
186
+ # @rbs slot: Integer
187
+ # @rbs types: Array[Symbol]
188
+ # @rbs return: void
189
+ def check_result: (Function function, Integer slot, Array[Symbol] types) -> void
190
+
191
+ # @rbs target: Integer
192
+ # @rbs limit: Integer
193
+ # @rbs return: void
194
+ def check_target: (Integer target, Integer limit) -> void
195
+
196
+ # @rbs [T] (Array[T] values, Integer index) -> T
197
+ def at: [T] (Array[T] values, Integer index) -> T
198
+ end
199
+
200
+ # @rbs directory: String
201
+ # @rbs wasm: String
202
+ # @rbs configuration: Configuration
203
+ # @rbs verify: Symbol
204
+ # @rbs eager: bool
205
+ def initialize: (String directory, String wasm, Configuration configuration, ?verify: Symbol, ?eager: bool) -> untyped
206
+
207
+ # Restore against module declarations so a miss can decode and check the
208
+ # Wasm bodies before Store initialization or any host lookup.
209
+ # @rbs instance: Wardite::Instance
210
+ # @rbs return: Array[Function]?
211
+ def read_functions: (Wardite::Instance instance) -> Array[Function]?
212
+
213
+ # @rbs function: Function
214
+ # @rbs return: void
215
+ def restore_function: (Function function) -> void
216
+
217
+ # @rbs return: void
218
+ def restore_all: () -> void
219
+
220
+ # @rbs instance: Wardite::Instance
221
+ # @rbs ir: IR
222
+ # @rbs return: void
223
+ def write_ir: (Wardite::Instance instance, IR ir) -> void
224
+
225
+ private
226
+
227
+ # @rbs instance: Wardite::Instance
228
+ # @rbs return: Array[FunctionEntry]
229
+ def module_entries: (Wardite::Instance instance) -> Array[FunctionEntry]
230
+
231
+ # @rbs return: String
232
+ def read_verified_payload: () -> String
233
+
234
+ # @rbs payload: String
235
+ # @rbs length: String
236
+ # @rbs return: String
237
+ def self.sample_checksum: (String payload, String length) -> String
238
+
239
+ # Opening without blocking keeps a FIFO from stalling the start of a run.
240
+ # @rbs path: String
241
+ # @rbs header: String
242
+ # @rbs prefix_size: Integer
243
+ # @rbs return: String
244
+ def self.read_contents: (String path, String header, Integer prefix_size) -> String
245
+
246
+ # Exclusive creation protects a concurrent writer's temporary file.
247
+ # Close the file before publishing it under the cache key.
248
+ # @rbs directory: String
249
+ # @rbs destination: String
250
+ # @rbs prefix: String
251
+ # @rbs payload: String
252
+ # @rbs return: void
253
+ def self.publish: (String directory, String destination, String prefix, String payload) -> void
254
+
255
+ # Include the module's import identities, and every function's signature
256
+ # and index mapping. The live entries and hosts are always linked afresh.
257
+ # @rbs instance: Wardite::Instance
258
+ # @rbs entries: Array[FunctionEntry]
259
+ # @rbs return: String
260
+ def encode_layout: (Wardite::Instance instance, Array[FunctionEntry] entries) -> String
261
+ end
262
+ end
263
+ end
@@ -6,6 +6,13 @@ module Wardite
6
6
  # This makes stale temporary slots harmless when a frame is reused. Keep
7
7
  # states per basic block, rather than per instruction, to bound their size.
8
8
  class RegisterValidation
9
+ # Keep each word within Spinel's fixed-width Integer.
10
+ WORD_SHIFT: ::Integer
11
+
12
+ WORD_BITS: untyped
13
+
14
+ WORD_MASK: untyped
15
+
9
16
  class Block
10
17
  attr_reader first: Integer
11
18
 
@@ -13,13 +20,16 @@ module Wardite
13
20
 
14
21
  attr_reader defined: Array[Integer]
15
22
 
23
+ attr_reader successors: Array[Integer]
24
+
25
+ attr_accessor pending: bool
26
+
16
27
  # @rbs first: Integer
17
28
  # @rbs limit: Integer
18
- # @rbs register_count: Integer
19
- def initialize: (Integer first, Integer limit, Integer register_count) -> untyped
29
+ def initialize: (Integer first, Integer limit) -> untyped
20
30
 
21
31
  # Incoming facts only lose definitions after the first reachable edge.
22
- # A backedge cannot establish a definition missing on initial entry.
32
+ # Return true when a changed block needs to enter the worklist.
23
33
  # @rbs incoming: Array[Integer]
24
34
  # @rbs return: bool
25
35
  def merge: (Array[Integer] incoming) -> bool
@@ -33,6 +43,24 @@ module Wardite
33
43
 
34
44
  private
35
45
 
46
+ # Visit predecessors before joins where possible, then revisit changed
47
+ # states across backedges until the worklist is empty.
48
+ # @rbs blocks: Array[Wardite::Efflorescence::RegisterValidation::Block]
49
+ # @rbs block_for_pc: Array[Integer]
50
+ # @rbs flow: Wardite::Efflorescence::FlowGraph
51
+ # @rbs return: Array[Integer]
52
+ def reverse_postorder: (Array[Wardite::Efflorescence::RegisterValidation::Block] blocks, Array[Integer] block_for_pc, Wardite::Efflorescence::FlowGraph flow) -> Array[Integer]
53
+
54
+ # @rbs words: Array[Integer]
55
+ # @rbs register: Integer
56
+ # @rbs return: void
57
+ def mark: (Array[Integer] words, Integer register) -> void
58
+
59
+ # @rbs words: Array[Integer]
60
+ # @rbs register: Integer
61
+ # @rbs return: bool
62
+ def marked?: (Array[Integer] words, Integer register) -> bool
63
+
36
64
  # Validate all registers, including unreachable instructions and table-only
37
65
  # operands. Numeric registers are checked before flat execution.
38
66
  # @rbs function: Wardite::Efflorescence::Function
@@ -0,0 +1,84 @@
1
+ # Generated from lib/wardite/efflorescence/snapshot.rb with RBS::Inline
2
+
3
+ module Wardite
4
+ module Efflorescence
5
+ class SavedFrame
6
+ attr_reader pool_index: Integer
7
+
8
+ attr_reader pc: Integer
9
+
10
+ attr_reader return_register: Integer
11
+
12
+ attr_reader registers: Array[Integer]
13
+
14
+ attr_reader handlers: Array[Integer]
15
+
16
+ # @rbs pool_index: Integer
17
+ # @rbs pc: Integer
18
+ # @rbs return_register: Integer
19
+ # @rbs registers: Array[Integer]
20
+ # @rbs handlers: Array[Integer]
21
+ def initialize: (Integer pool_index, Integer pc, Integer return_register, Array[Integer] registers, Array[Integer] handlers) -> untyped
22
+ end
23
+
24
+ # Startup snapshot of a WASI command (ADR 0012). The state is saved just
25
+ # before the first WASI call whose result is not fixed by the key, and a
26
+ # later run with the same key resumes from there.
27
+ class Snapshot
28
+ MAGIC: untyped
29
+
30
+ FORMAT_VERSION: ::Integer
31
+
32
+ PAGE_SIZE: ::Integer
33
+
34
+ ZERO_PAGE: untyped
35
+
36
+ # Their results depend only on values in the key, or are frozen into the
37
+ # snapshot (clocks and random bytes). fd_filestat_get is allowed for
38
+ # stdio only: CRuby probes fds 0-2 before anything else.
39
+ ALLOWED: untyped
40
+
41
+ attr_reader path: String
42
+
43
+ # @rbs directory: String
44
+ # @rbs instance: Wardite::Instance
45
+ # @rbs mir_cache: Wardite::Efflorescence::MIRCache
46
+ def initialize: (String directory, Wardite::Instance instance, Wardite::Efflorescence::MIRCache mir_cache) -> untyped
47
+
48
+ # Does this host call end the deterministic prefix of the run?
49
+ # @rbs host: Wardite::Efflorescence::HostFunction
50
+ # @rbs registers: Array[Integer]
51
+ # @rbs sources: Array[Integer]
52
+ # @rbs return: bool
53
+ def checkpoint?: (Wardite::Efflorescence::HostFunction host, Array[Integer] registers, Array[Integer] sources) -> bool
54
+
55
+ # Saving is best effort: any refusal or I/O error leaves the run as is.
56
+ # @rbs instance: Wardite::Instance
57
+ # @rbs frames: Array[Wardite::Efflorescence::Frame]
58
+ # @rbs return: void
59
+ def save: (Wardite::Instance instance, Array[Wardite::Efflorescence::Frame] frames) -> void
60
+
61
+ # Validate everything before touching the Store, so a rejected file
62
+ # leaves a fresh instance for the normal start.
63
+ # @rbs vm: Wardite::Efflorescence::VM
64
+ # @rbs return: Array[Wardite::Efflorescence::SavedFrame]?
65
+ def restore: (Wardite::Efflorescence::VM vm) -> Array[Wardite::Efflorescence::SavedFrame]?
66
+
67
+ private
68
+
69
+ # The top frame resumes at its host call. Callers resume after the call
70
+ # that created the frame above them, which writes its return register.
71
+ # @rbs functions: Array[Wardite::Efflorescence::Function]
72
+ # @rbs frames: Array[Wardite::Efflorescence::SavedFrame]
73
+ # @rbs index: Integer
74
+ # @rbs cache: Wardite::Efflorescence::MIRCache
75
+ # @rbs return: void
76
+ def check_frame: (Array[Wardite::Efflorescence::Function] functions, Array[Wardite::Efflorescence::SavedFrame] frames, Integer index, Wardite::Efflorescence::MIRCache cache) -> void
77
+
78
+ # @rbs message: String
79
+ # @rbs started: Float
80
+ # @rbs return: void
81
+ def trace: (String message, ?Float started) -> void
82
+ end
83
+ end
84
+ end
@@ -2,8 +2,8 @@
2
2
 
3
3
  module Wardite
4
4
  module Efflorescence
5
- # Checked byte operations live off the integer dispatch path. Store remains
6
- # the owner of all state; never retain a Memory#data buffer across a call.
5
+ # Checked byte operations and global synchronization live off the integer
6
+ # dispatch path. Never retain a Memory#data buffer across a call.
7
7
  class StoreAccess
8
8
  PAGE_SIZE: ::Integer
9
9
 
@@ -53,6 +53,17 @@ module Wardite
53
53
  # @rbs return: void
54
54
  def global_set_i64: (Integer index, Integer value) -> void
55
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
+
56
67
  # @rbs address: Integer
57
68
  # @rbs offset: Integer
58
69
  # @rbs width: Integer
@@ -87,7 +87,11 @@ module Wardite
87
87
  def initialize: (Wardite::Instance instance) -> untyped
88
88
 
89
89
  # @rbs return: Wardite::Efflorescence::IR
90
- def translate: () -> 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
91
95
 
92
96
  # @rbs wasm: Wardite::WasmFunction
93
97
  # @rbs index: Integer