wardite 0.9.0 → 1.0.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.
- checksums.yaml +4 -4
- data/LICENSE +191 -0
- data/Makefile +14 -0
- data/README.md +80 -1
- data/Rakefile +5 -0
- data/benchmark/README.md +500 -0
- data/benchmark/build_call_profile.rb +42 -0
- data/benchmark/call_cost_worker.rb +27 -0
- data/benchmark/compare.rb +93 -0
- data/benchmark/compare_call_types.rb +212 -0
- data/benchmark/compare_dispatch.rb +123 -0
- data/benchmark/compare_engines.rb +119 -0
- data/benchmark/compare_optimizations.rb +139 -0
- data/benchmark/engine_phases.rb +30 -0
- data/benchmark/figures/README.md +35 -0
- data/benchmark/figures/plot_spinel_comparison.py +137 -0
- data/benchmark/figures/spinel_new_vm_candlestick.png +0 -0
- data/benchmark/figures/spinel_new_vm_candlestick.svg +7615 -0
- data/benchmark/figures/spinel_new_vm_summary.csv +9 -0
- data/benchmark/figures/spinel_new_vm_summary.json +82 -0
- data/benchmark/float_m5.wat +42 -0
- data/benchmark/i32_call_arities.wat +89 -0
- data/benchmark/i32_calls.wat +174 -0
- data/benchmark/i32_memory.wat +58 -0
- data/benchmark/i32_mix.wat +80 -0
- data/benchmark/i64_m4.wat +55 -0
- data/benchmark/investigate_calls.rb +231 -0
- data/benchmark/investigate_generated_guards.rb +218 -0
- data/benchmark/m3_call_worker.rb +38 -0
- data/benchmark/measure_m1.rb +51 -0
- data/benchmark/measure_m2.rb +55 -0
- data/benchmark/measure_m3_calls.rb +89 -0
- data/benchmark/measure_m4.rb +134 -0
- data/benchmark/measure_m5_boundary.rb +41 -0
- data/benchmark/measure_wasi_write.rb +75 -0
- data/benchmark/optimization_worker.rb +23 -0
- data/benchmark/results/call_arities_exploratory_2026-11-04.json +4320 -0
- data/benchmark/results/call_arities_spinel_2026-11-04.json +1200 -0
- data/benchmark/results/call_cost_spinel_2026-11-04.json +2392 -0
- data/benchmark/results/call_protocol_exploratory_2026-11-04.json +3947 -0
- data/benchmark/results/call_protocol_profile_2026-11-04.json +383 -0
- data/benchmark/results/call_protocol_ruby_2026-11-04.json +1213 -0
- data/benchmark/results/call_protocol_spinel_2026-11-04.json +913 -0
- data/benchmark/results/call_types_ruby_2026-11-04.json +1212 -0
- data/benchmark/results/call_types_spinel_2026-11-04.json +923 -0
- data/benchmark/results/efflorescence-m1-cruby.json +799 -0
- data/benchmark/results/efflorescence-m1-spinel.json +799 -0
- data/benchmark/results/efflorescence-m2-bulk-loop.json +820 -0
- data/benchmark/results/efflorescence-m2-i32-cruby.json +799 -0
- data/benchmark/results/efflorescence-m2-i32-spinel.json +799 -0
- data/benchmark/results/efflorescence-m2-memory.json +408 -0
- data/benchmark/results/generated_guards_exploratory_2026-11-04.json +1225 -0
- data/benchmark/results/generated_guards_profile_2026-11-04.json +592 -0
- data/benchmark/results/generated_guards_spinel_2026-11-04.json +1650 -0
- data/benchmark/results/generated_guards_validation_2026-11-04.json +256 -0
- data/benchmark/results/inlining_engines_2026-11-04.json +241 -0
- data/benchmark/results/inlining_ruby_2026-11-04.json +1213 -0
- data/benchmark/results/inlining_spinel_2026-11-04.json +893 -0
- data/benchmark/results/operand_decode_exploratory_2026-11-04.json +1319 -0
- data/benchmark/results/operand_decode_ruby_2026-11-04.json +1213 -0
- data/benchmark/results/operand_decode_spinel_2026-11-04.json +924 -0
- data/benchmark/results/selective_reset_spinel_2026-11-04.json +454 -0
- data/benchmark/results/selective_reset_spinel_2026-11-04_exploratory.json +2679 -0
- data/benchmark/results/spinel_fetch_root_patch_2026-11-04.json +4523 -0
- data/benchmark/results/while_final_compiler_comparison_2026-11-04.json +324 -0
- data/benchmark/results/while_patched_external_2026-11-04.json +220 -0
- data/benchmark/results/while_user_unpatched_2026-11-04.json +230 -0
- data/benchmark/summarize_call_profile.py +54 -0
- data/benchmark/validate_m1_eh.rb +34 -0
- data/benchmark/validate_m2.rb +119 -0
- data/benchmark/validate_m3.rb +44 -0
- data/benchmark/validate_m4.rb +95 -0
- data/benchmark/validate_m5.rb +108 -0
- data/docs/adr/0001-efflorescence-m1-control-and-eh.md +319 -0
- data/docs/adr/0002-efflorescence-m2-memory-and-globals.md +185 -0
- data/docs/adr/0003-efflorescence-m3-host-and-indirect-calls.md +228 -0
- data/docs/adr/0004-efflorescence-m4-i64.md +202 -0
- data/docs/adr/0005-efflorescence-m5-floating-point.md +127 -0
- data/docs/adr/0006-efflorescence-m6-coverage-parity.md +101 -0
- data/docs/efflorescence-call-arities.md +115 -0
- data/docs/efflorescence-call-investigation.md +155 -0
- data/docs/efflorescence-call-transfer.md +128 -0
- data/docs/efflorescence-call-types.md +102 -0
- data/docs/efflorescence-coverage-ja.md +351 -0
- data/docs/efflorescence-generated-c-guards.md +405 -0
- data/docs/efflorescence-inlining.md +165 -0
- data/docs/efflorescence-ja.md +155 -0
- data/docs/efflorescence-m1.md +160 -0
- data/docs/efflorescence-m2.md +233 -0
- data/docs/efflorescence-m3.md +131 -0
- data/docs/efflorescence-m4.md +88 -0
- data/docs/efflorescence-m5.md +82 -0
- data/docs/efflorescence-m6.md +95 -0
- data/docs/efflorescence-operand-decoding.md +105 -0
- data/docs/efflorescence-phase2-ja.md +225 -0
- data/docs/efflorescence-phase2.md +240 -0
- data/docs/efflorescence-register-initialization.md +75 -0
- data/docs/efflorescence.md +144 -0
- data/docs/spinel-string-aset-inplace-proposal.md +200 -0
- data/lib/wardite/alu_f32.generated.rb +1 -0
- data/lib/wardite/alu_f64.generated.rb +1 -0
- data/lib/wardite/alu_i32.generated.rb +14 -9
- data/lib/wardite/alu_i64.generated.rb +18 -20
- data/lib/wardite/cli/cli.rb +61 -28
- data/lib/wardite/const.rb +1 -0
- data/lib/wardite/efflorescence/float_arithmetic.rb +216 -0
- data/lib/wardite/efflorescence/i64_arithmetic.rb +257 -0
- data/lib/wardite/efflorescence/inspection.rb +165 -0
- data/lib/wardite/efflorescence/ir.rb +1151 -0
- data/lib/wardite/efflorescence/optimizer.rb +580 -0
- data/lib/wardite/efflorescence/register_validation.rb +290 -0
- data/lib/wardite/efflorescence/store_access.rb +271 -0
- data/lib/wardite/efflorescence/translator.rb +859 -0
- data/lib/wardite/efflorescence/vm.rb +1006 -0
- data/lib/wardite/efflorescence/wasi.rb +108 -0
- data/lib/wardite/efflorescence.rb +11 -0
- data/lib/wardite/errors.rb +20 -0
- data/lib/wardite/float_bits.rb +46 -0
- data/lib/wardite/instruction.rb +35 -4
- data/lib/wardite/leb128.rb +33 -12
- data/lib/wardite/load.rb +203 -138
- data/lib/wardite/value.rb +169 -175
- data/lib/wardite/version.rb +1 -1
- data/lib/wardite/wasi/consts.rb +1 -0
- data/lib/wardite/wasm_module.rb +6 -3
- data/lib/wardite.rb +184 -70
- data/rbs_collection.lock.yaml +36 -96
- data/scripts/gen_alu.rb +66 -10
- data/sig/generated/wardite/cli/cli.rbs +8 -6
- data/sig/generated/wardite/const.rbs +2 -0
- data/sig/generated/wardite/efflorescence/float_arithmetic.rbs +65 -0
- data/sig/generated/wardite/efflorescence/i64_arithmetic.rbs +99 -0
- data/sig/generated/wardite/efflorescence/inspection.rbs +64 -0
- data/sig/generated/wardite/efflorescence/ir.rbs +881 -0
- data/sig/generated/wardite/efflorescence/optimizer.rbs +189 -0
- data/sig/generated/wardite/efflorescence/register_validation.rbs +76 -0
- data/sig/generated/wardite/efflorescence/store_access.rbs +134 -0
- data/sig/generated/wardite/efflorescence/translator.rbs +214 -0
- data/sig/generated/wardite/efflorescence/vm.rbs +179 -0
- data/sig/generated/wardite/efflorescence/wasi.rbs +47 -0
- data/sig/generated/wardite/errors.rbs +12 -0
- data/sig/generated/wardite/float_bits.rbs +30 -0
- data/sig/generated/wardite/instruction.rbs +22 -1
- data/sig/generated/wardite/leb128.rbs +3 -1
- data/sig/generated/wardite/load.rbs +29 -4
- data/sig/generated/wardite/value.rbs +70 -11
- data/sig/generated/wardite/wasi/consts.rbs +2 -0
- data/sig/generated/wardite.rbs +49 -12
- data/sig/vernier.rbs +2 -2
- data/spinel/README.md +30 -0
- data/spinel/bin/wardite.rb +6 -0
- data/spinel/spin.toml +7 -0
- metadata +126 -3
data/lib/wardite.rb
CHANGED
|
@@ -4,8 +4,10 @@
|
|
|
4
4
|
require_relative "wardite/version"
|
|
5
5
|
require_relative "wardite/leb128"
|
|
6
6
|
require_relative "wardite/const"
|
|
7
|
+
require_relative "wardite/float_bits"
|
|
7
8
|
require_relative "wardite/instruction"
|
|
8
9
|
require_relative "wardite/value"
|
|
10
|
+
require_relative "wardite/wasm_module"
|
|
9
11
|
require_relative "wardite/load"
|
|
10
12
|
require_relative "wardite/errors"
|
|
11
13
|
|
|
@@ -28,7 +30,7 @@ module Wardite
|
|
|
28
30
|
|
|
29
31
|
attr_accessor :sections #: Array[Section]
|
|
30
32
|
|
|
31
|
-
attr_accessor :runtime #: Runtime
|
|
33
|
+
attr_accessor :runtime #: Runtime | Efflorescence::VM
|
|
32
34
|
|
|
33
35
|
attr_accessor :types #: Array[Type]
|
|
34
36
|
|
|
@@ -36,13 +38,18 @@ module Wardite
|
|
|
36
38
|
|
|
37
39
|
attr_accessor :exports #: Exports
|
|
38
40
|
|
|
41
|
+
attr_reader :tags #: Array[Wardite::Efflorescence::Tag]
|
|
42
|
+
|
|
39
43
|
attr_reader :import_object #: Hash[Symbol, wasmModule]
|
|
40
44
|
|
|
41
45
|
attr_accessor :wasi #: ::Wardite::WasiSnapshotPreview1?
|
|
42
46
|
|
|
43
47
|
# @rbs import_object: Hash[Symbol, wasmModuleSrc]
|
|
48
|
+
# @rbs engine: Symbol
|
|
49
|
+
# @rbs disabled_optimizations: Array[Symbol]
|
|
50
|
+
# @rbs mir_profile: bool
|
|
44
51
|
# @rbs &blk: (Instance) -> void
|
|
45
|
-
def initialize(import_object, &blk)
|
|
52
|
+
def initialize(import_object, engine: :stack, disabled_optimizations: [], mir_profile: false, &blk)
|
|
46
53
|
@wasi = nil
|
|
47
54
|
|
|
48
55
|
blk.call(self)
|
|
@@ -54,9 +61,11 @@ module Wardite
|
|
|
54
61
|
|
|
55
62
|
@import_object = import_object #: Hash[Symbol, wasmModule]
|
|
56
63
|
|
|
64
|
+
@tags = []
|
|
65
|
+
check_engine_features(engine)
|
|
66
|
+
check_data_count
|
|
57
67
|
@store = Store.new(self)
|
|
58
68
|
@exports = Exports.new(self.export_section, store)
|
|
59
|
-
@runtime = Runtime.new(self)
|
|
60
69
|
|
|
61
70
|
@types = []
|
|
62
71
|
type_section = self.type_section
|
|
@@ -67,17 +76,95 @@ module Wardite
|
|
|
67
76
|
end
|
|
68
77
|
end
|
|
69
78
|
|
|
70
|
-
|
|
79
|
+
@runtime = case engine
|
|
80
|
+
when :stack then Runtime.new(self)
|
|
81
|
+
when :efflorescence then Efflorescence::VM.new(self, disabled_optimizations: disabled_optimizations, profile: mir_profile)
|
|
82
|
+
else raise LoadError, "unknown engine: #{engine}"
|
|
83
|
+
end
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
# Run before allocating Store/Exports or executing a start function.
|
|
87
|
+
# @rbs engine: Symbol
|
|
88
|
+
# @rbs return: void
|
|
89
|
+
def check_engine_features(engine)
|
|
90
|
+
check_memory_initialization if engine == :efflorescence
|
|
91
|
+
types = type_section
|
|
92
|
+
if engine == :efflorescence
|
|
93
|
+
import_section.imports.each do |import|
|
|
94
|
+
params = types&.defined_types&.[](import.sig_index)
|
|
95
|
+
results = types&.defined_results&.[](import.sig_index)
|
|
96
|
+
raise LoadError, "invalid import type index #{import.sig_index}" unless params && results
|
|
97
|
+
Efflorescence::FunctionEntry.check_signature(params, results, "#{import.module_name}.#{import.name}")
|
|
98
|
+
end
|
|
99
|
+
end
|
|
100
|
+
tag_section = @sections.find { |section| section.is_a?(TagSection) }
|
|
101
|
+
if tag_section.is_a?(TagSection)
|
|
102
|
+
raise LoadError, "stack engine does not support tags/EH" unless engine == :efflorescence
|
|
103
|
+
tag_section.type_indices.each do |index|
|
|
104
|
+
params = types&.defined_types&.[](index)
|
|
105
|
+
results = types&.defined_results&.[](index)
|
|
106
|
+
raise LoadError, "invalid tag type index #{index}" unless params && results
|
|
107
|
+
unless params.all? { |type| Efflorescence::FunctionEntry.numeric_type?(type) } && results.empty?
|
|
108
|
+
raise LoadError, "only numeric tag payloads with no results are supported"
|
|
109
|
+
end
|
|
110
|
+
@tags << Efflorescence::Tag.new(params)
|
|
111
|
+
end
|
|
112
|
+
end
|
|
113
|
+
if engine == :stack && types && (types.defined_types + types.defined_results).any? { |list| list.include?(:exnref) }
|
|
114
|
+
raise LoadError, "stack engine does not support exnref"
|
|
115
|
+
end
|
|
116
|
+
codes = code_section
|
|
117
|
+
return unless codes
|
|
118
|
+
codes.func_codes.each do |body|
|
|
119
|
+
if engine == :stack && body.locals_type.include?(:exnref)
|
|
120
|
+
raise LoadError, "stack engine does not support exnref"
|
|
121
|
+
end
|
|
122
|
+
body.body.each do |instruction|
|
|
123
|
+
code = instruction[1]
|
|
124
|
+
if engine == :stack && [:try_table, :throw, :throw_ref].include?(code)
|
|
125
|
+
raise LoadError, "stack engine does not support EH"
|
|
126
|
+
end
|
|
127
|
+
instruction[2].each do |operand|
|
|
128
|
+
next unless operand.is_a?(Block)
|
|
129
|
+
index = operand.type_index
|
|
130
|
+
if index >= 0
|
|
131
|
+
params = types&.defined_types&.[](index)
|
|
132
|
+
results = types&.defined_results&.[](index)
|
|
133
|
+
raise LoadError, "invalid block type index #{index}" unless params && results
|
|
134
|
+
operand.resolve(params, results)
|
|
135
|
+
end
|
|
136
|
+
if engine == :stack && (index >= 0 || operand.result_types.include?(:exnref))
|
|
137
|
+
raise LoadError, "stack engine does not support indexed/reference block signatures"
|
|
138
|
+
end
|
|
139
|
+
end
|
|
140
|
+
end
|
|
141
|
+
end
|
|
142
|
+
end
|
|
143
|
+
|
|
144
|
+
# Validate active segments before shared initialization can mutate memory.
|
|
145
|
+
# @rbs return: void
|
|
146
|
+
def check_memory_initialization
|
|
147
|
+
segments = data_section&.segments
|
|
148
|
+
return unless segments
|
|
149
|
+
limits = memory_section&.limits
|
|
150
|
+
segments.each do |segment|
|
|
151
|
+
next unless segment.mode == :active
|
|
152
|
+
unless limits && limits.size == 1 && segment.mem_index == 0
|
|
153
|
+
raise LoadError, "active data segment requires memory 0"
|
|
154
|
+
end
|
|
155
|
+
size = limits.fetch(0).fetch(0) * 65536
|
|
156
|
+
start = segment.offset
|
|
157
|
+
unless start >= 0 && start <= size && segment.data.bytesize <= size - start
|
|
158
|
+
raise LoadError, "active data segment out of bounds"
|
|
159
|
+
end
|
|
160
|
+
end
|
|
71
161
|
end
|
|
72
162
|
|
|
73
163
|
# @rbs return: void
|
|
74
164
|
def check_data_count
|
|
75
165
|
data_count = self.data_count_section&.count
|
|
76
166
|
if data_count
|
|
77
|
-
actual_count = self.data_section&.segments&.size
|
|
78
|
-
if !actual_count
|
|
79
|
-
raise LoadError, "invalid data segment count"
|
|
80
|
-
end
|
|
167
|
+
actual_count = self.data_section&.segments&.size || 0
|
|
81
168
|
if (data_count != actual_count)
|
|
82
169
|
raise LoadError, "invalid data segment count"
|
|
83
170
|
end
|
|
@@ -476,8 +563,9 @@ module Wardite
|
|
|
476
563
|
frame.pc = pc
|
|
477
564
|
|
|
478
565
|
when :br_table
|
|
479
|
-
|
|
480
|
-
raise EvalError, "no level vector"
|
|
566
|
+
levels = operand[0]
|
|
567
|
+
raise EvalError, "no level vector" unless levels.is_a?(OperandVector)
|
|
568
|
+
level_vec = levels.entries
|
|
481
569
|
default = operand[1]
|
|
482
570
|
raise EvalError, "no default specified" if !default.is_a?(Integer)
|
|
483
571
|
idx = stack.pop
|
|
@@ -828,8 +916,9 @@ module Wardite
|
|
|
828
916
|
end
|
|
829
917
|
|
|
830
918
|
# @rbs name: String|Symbol
|
|
919
|
+
# @rbs include_private: bool
|
|
831
920
|
# @rbs return: bool
|
|
832
|
-
def respond_to?
|
|
921
|
+
def respond_to?(name, include_private = false)
|
|
833
922
|
callable?(name) || super
|
|
834
923
|
end
|
|
835
924
|
|
|
@@ -847,7 +936,7 @@ module Wardite
|
|
|
847
936
|
|
|
848
937
|
# @rbs callsig: Array[Symbol]
|
|
849
938
|
# @rbs retsig: Array[Symbol]
|
|
850
|
-
# @rbs
|
|
939
|
+
# @rbs return: void
|
|
851
940
|
def initialize(callsig, retsig)
|
|
852
941
|
@callsig = callsig
|
|
853
942
|
@retsig = retsig
|
|
@@ -873,7 +962,7 @@ module Wardite
|
|
|
873
962
|
# @rbs body: Array[[Symbol, Symbol, Array[Wardite::operandItem], Integer?, Integer?]]
|
|
874
963
|
# @rbs arity: Integer
|
|
875
964
|
# @rbs locals: Array[wasmValue]
|
|
876
|
-
# @rbs
|
|
965
|
+
# @rbs return: void
|
|
877
966
|
def initialize(pc, sp, body, arity, locals)
|
|
878
967
|
@pc = pc
|
|
879
968
|
@sp = sp
|
|
@@ -918,6 +1007,8 @@ module Wardite
|
|
|
918
1007
|
|
|
919
1008
|
attr_accessor :memories #: Array[Memory]
|
|
920
1009
|
|
|
1010
|
+
attr_reader :data_segments #: Array[String]
|
|
1011
|
+
|
|
921
1012
|
attr_accessor :globals #: Array[Global]
|
|
922
1013
|
|
|
923
1014
|
attr_accessor :tables #: Array[Table]
|
|
@@ -935,27 +1026,30 @@ module Wardite
|
|
|
935
1026
|
@funcs = []
|
|
936
1027
|
@modules = inst.import_object
|
|
937
1028
|
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
target_module = self.modules[desc.module_name.to_sym]
|
|
943
|
-
if target_module.nil?
|
|
944
|
-
raise ::NameError, "module #{desc.module_name} not found"
|
|
945
|
-
end
|
|
946
|
-
target_name = desc.name.to_sym
|
|
947
|
-
|
|
948
|
-
ext_function = ExternalFunction.new(target_module, target_name, callsig, retsig)
|
|
949
|
-
self.funcs << ext_function
|
|
950
|
-
end
|
|
1029
|
+
import_section.imports.each do |desc|
|
|
1030
|
+
callsig = type_section&.defined_types&.[](desc.sig_index)
|
|
1031
|
+
retsig = type_section&.defined_results&.[](desc.sig_index)
|
|
1032
|
+
raise LoadError, "invalid import type index #{desc.sig_index}" unless callsig && retsig
|
|
951
1033
|
|
|
1034
|
+
module_name = desc.module_name.to_sym
|
|
1035
|
+
target_module = self.modules.fetch(module_name) { self.modules.default(module_name) }
|
|
1036
|
+
raise ::NameError, "module #{desc.module_name} not found" unless target_module
|
|
1037
|
+
|
|
1038
|
+
self.funcs << ExternalFunction.new(target_module, desc.name.to_sym, callsig, retsig)
|
|
1039
|
+
end
|
|
1040
|
+
|
|
1041
|
+
if (func_section&.func_indices&.size || 0) != (code_section&.func_codes&.size || 0)
|
|
1042
|
+
raise LoadError, "function and code section lengths differ"
|
|
1043
|
+
end
|
|
1044
|
+
if func_section && code_section
|
|
952
1045
|
func_section.func_indices.each_with_index do |sigindex, findex|
|
|
953
|
-
callsig = type_section
|
|
954
|
-
retsig = type_section
|
|
955
|
-
|
|
1046
|
+
callsig = type_section&.defined_types&.[](sigindex)
|
|
1047
|
+
retsig = type_section&.defined_results&.[](sigindex)
|
|
1048
|
+
raise LoadError, "invalid function type index #{sigindex}" unless callsig && retsig
|
|
1049
|
+
|
|
1050
|
+
codes = code_section.func_codes.fetch(findex)
|
|
956
1051
|
wasm_function = WasmFunction.new(callsig, retsig, codes)
|
|
957
|
-
|
|
958
|
-
wasm_function.findex = idx
|
|
1052
|
+
wasm_function.findex = self.funcs.size
|
|
959
1053
|
self.funcs << wasm_function
|
|
960
1054
|
end
|
|
961
1055
|
end
|
|
@@ -979,8 +1073,8 @@ module Wardite
|
|
|
979
1073
|
end
|
|
980
1074
|
|
|
981
1075
|
data_start = segment.offset
|
|
982
|
-
data_end = segment.offset + segment.data.
|
|
983
|
-
if data_end > memory.data.
|
|
1076
|
+
data_end = segment.offset + segment.data.bytesize
|
|
1077
|
+
if data_start < 0 || data_end > memory.data.bytesize
|
|
984
1078
|
raise GenericError, "data too large for memory"
|
|
985
1079
|
end
|
|
986
1080
|
|
|
@@ -989,6 +1083,16 @@ module Wardite
|
|
|
989
1083
|
end
|
|
990
1084
|
end
|
|
991
1085
|
|
|
1086
|
+
# Runtime segment instances differ from their syntax declarations: active
|
|
1087
|
+
# segments have already been consumed by initialization.
|
|
1088
|
+
@data_segments = []
|
|
1089
|
+
data_section = inst.data_section
|
|
1090
|
+
if data_section
|
|
1091
|
+
data_section.segments.each do |segment|
|
|
1092
|
+
@data_segments << (segment.mode == :passive ? segment.data.dup.b : "".b)
|
|
1093
|
+
end
|
|
1094
|
+
end
|
|
1095
|
+
|
|
992
1096
|
@globals = []
|
|
993
1097
|
global_section = inst.global_section
|
|
994
1098
|
if global_section
|
|
@@ -1019,36 +1123,19 @@ module Wardite
|
|
|
1019
1123
|
elem_section = inst.elem_section
|
|
1020
1124
|
if elem_section
|
|
1021
1125
|
elem_section.table_indices.each_with_index do |tidx, idx|
|
|
1022
|
-
table = @tables[tidx]
|
|
1023
|
-
|
|
1024
|
-
|
|
1126
|
+
table = @tables[tidx] || raise(LoadError, "invalid table index #{tidx}")
|
|
1127
|
+
offset = elem_section.table_offsets.fetch(idx)
|
|
1128
|
+
indices = elem_section.element_indices.fetch(idx)
|
|
1129
|
+
raise LoadError, "element segment requires a funcref table" unless table.type == :funcref
|
|
1130
|
+
if offset < 0 || offset > table.current || indices.size > table.current - offset
|
|
1131
|
+
raise LoadError, "active element segment out of bounds"
|
|
1025
1132
|
end
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
end
|
|
1031
|
-
indices = elem_section.element_indices[idx]
|
|
1032
|
-
if !indices
|
|
1033
|
-
raise LoadError, "invalid element index #{idx}"
|
|
1034
|
-
end
|
|
1035
|
-
elms = [typ, offset, indices] #: [Symbol, Integer, Array[Integer]]
|
|
1036
|
-
@elements << elms
|
|
1037
|
-
end
|
|
1038
|
-
end
|
|
1039
|
-
|
|
1040
|
-
@elements.each_with_index do |(typ, offset, indices), idx|
|
|
1041
|
-
table = @tables[idx]
|
|
1042
|
-
if !table
|
|
1043
|
-
raise LoadError, "invalid table index #{idx}"
|
|
1044
|
-
end
|
|
1045
|
-
indices.each_with_index do |eidx, tidx|
|
|
1046
|
-
case typ
|
|
1047
|
-
when :funcref
|
|
1048
|
-
table.set(offset + tidx, @funcs[eidx])
|
|
1049
|
-
when :externref
|
|
1050
|
-
raise NotImplementedError, "no support :externref"
|
|
1133
|
+
indices.each_with_index do |function_index, position|
|
|
1134
|
+
function = @funcs[function_index] if function_index >= 0
|
|
1135
|
+
raise LoadError, "invalid element function index #{function_index}" unless function
|
|
1136
|
+
table.set(offset + position, function)
|
|
1051
1137
|
end
|
|
1138
|
+
@elements << [table.type, offset, indices]
|
|
1052
1139
|
end
|
|
1053
1140
|
end
|
|
1054
1141
|
end
|
|
@@ -1070,7 +1157,7 @@ module Wardite
|
|
|
1070
1157
|
# @rbs max: Integer|nil
|
|
1071
1158
|
# @rbs return: void
|
|
1072
1159
|
def initialize(min, max)
|
|
1073
|
-
@data = String.new("\0" * (min * 64 * 1024))
|
|
1160
|
+
@data = String.new("\0" * (min * 64 * 1024)).b
|
|
1074
1161
|
@current = min
|
|
1075
1162
|
@max = max
|
|
1076
1163
|
end
|
|
@@ -1119,8 +1206,8 @@ module Wardite
|
|
|
1119
1206
|
# @rbs elem: WasmFunction|ExternalFunction|nil
|
|
1120
1207
|
# @rbs return: void
|
|
1121
1208
|
def set(idx, elem)
|
|
1122
|
-
if idx >= @current
|
|
1123
|
-
raise GenericError, "
|
|
1209
|
+
if idx < 0 || idx >= @current
|
|
1210
|
+
raise GenericError, "table index out of bounds"
|
|
1124
1211
|
end
|
|
1125
1212
|
@refs[idx] = elem
|
|
1126
1213
|
end
|
|
@@ -1164,6 +1251,9 @@ module Wardite
|
|
|
1164
1251
|
VOID = nil #: nil
|
|
1165
1252
|
|
|
1166
1253
|
attr_accessor :block_types #: nil|Array[Integer]
|
|
1254
|
+
attr_reader :type_index #: Integer
|
|
1255
|
+
attr_reader :parameter_types #: Array[Symbol]
|
|
1256
|
+
attr_reader :result_types #: Array[Symbol]
|
|
1167
1257
|
|
|
1168
1258
|
# @rbs return: Block
|
|
1169
1259
|
def self.void
|
|
@@ -1171,9 +1261,21 @@ module Wardite
|
|
|
1171
1261
|
end
|
|
1172
1262
|
|
|
1173
1263
|
# @rbs block_types: nil|Array[Integer]
|
|
1264
|
+
# @rbs type_index: Integer
|
|
1174
1265
|
# @rbs return: void
|
|
1175
|
-
def initialize(block_types=VOID)
|
|
1266
|
+
def initialize(block_types=VOID, type_index: -1)
|
|
1176
1267
|
@block_types = block_types
|
|
1268
|
+
@type_index = type_index
|
|
1269
|
+
@parameter_types = []
|
|
1270
|
+
@result_types = (block_types || []).map { |code| Op.i2type(code) }
|
|
1271
|
+
end
|
|
1272
|
+
|
|
1273
|
+
# @rbs params: Array[Symbol]
|
|
1274
|
+
# @rbs results: Array[Symbol]
|
|
1275
|
+
# @rbs return: void
|
|
1276
|
+
def resolve(params, results)
|
|
1277
|
+
@parameter_types = params.dup
|
|
1278
|
+
@result_types = results.dup
|
|
1177
1279
|
end
|
|
1178
1280
|
|
|
1179
1281
|
# @rbs return: bool
|
|
@@ -1223,7 +1325,10 @@ module Wardite
|
|
|
1223
1325
|
@mappings[name]&.[](1)
|
|
1224
1326
|
end
|
|
1225
1327
|
|
|
1226
|
-
|
|
1328
|
+
# @rbs name: String|Symbol
|
|
1329
|
+
# @rbs include_private: bool
|
|
1330
|
+
# @rbs return: bool
|
|
1331
|
+
def respond_to?(name, include_private = false)
|
|
1227
1332
|
!!self[name.to_s] || super
|
|
1228
1333
|
end
|
|
1229
1334
|
|
|
@@ -1249,7 +1354,7 @@ module Wardite
|
|
|
1249
1354
|
|
|
1250
1355
|
attr_accessor :findex #: Integer
|
|
1251
1356
|
|
|
1252
|
-
|
|
1357
|
+
# @rbs @default_locals: Array[wasmValue]?
|
|
1253
1358
|
|
|
1254
1359
|
# @rbs callsig: Array[Symbol]
|
|
1255
1360
|
# @rbs retsig: Array[Symbol]
|
|
@@ -1261,7 +1366,7 @@ module Wardite
|
|
|
1261
1366
|
|
|
1262
1367
|
@code_body = code_body
|
|
1263
1368
|
@findex = 0 # for debug
|
|
1264
|
-
@default_locals =
|
|
1369
|
+
@default_locals = nil
|
|
1265
1370
|
end
|
|
1266
1371
|
|
|
1267
1372
|
# @rbs return: Array[[Symbol, Symbol, Array[operandItem], Integer?, Integer?]]
|
|
@@ -1279,6 +1384,12 @@ module Wardite
|
|
|
1279
1384
|
code_body.locals_count
|
|
1280
1385
|
end
|
|
1281
1386
|
|
|
1387
|
+
# Stack-engine values are boxed lazily; Efflorescence uses type metadata.
|
|
1388
|
+
# @rbs return: Array[wasmValue]
|
|
1389
|
+
def default_locals
|
|
1390
|
+
@default_locals ||= construct_default_locals
|
|
1391
|
+
end
|
|
1392
|
+
|
|
1282
1393
|
# @rbs return: Array[wasmValue]
|
|
1283
1394
|
def construct_default_locals
|
|
1284
1395
|
locals = [] #: Array[wasmValue]
|
|
@@ -1331,7 +1442,8 @@ module Wardite
|
|
|
1331
1442
|
|
|
1332
1443
|
# @rbs callsig: Array[Symbol]
|
|
1333
1444
|
# @rbs retsig: Array[Symbol]
|
|
1334
|
-
# @rbs
|
|
1445
|
+
# @rbs target_module: wasmModule
|
|
1446
|
+
# @rbs name: Symbol
|
|
1335
1447
|
# @rbs return: void
|
|
1336
1448
|
def initialize(target_module, name, callsig, retsig)
|
|
1337
1449
|
@target_module = target_module
|
|
@@ -1371,9 +1483,11 @@ module Wardite
|
|
|
1371
1483
|
if path
|
|
1372
1484
|
buffer = File.open(path)
|
|
1373
1485
|
end
|
|
1374
|
-
if
|
|
1486
|
+
if buffer.nil?
|
|
1375
1487
|
raise ::ArgumentError, "nil buffer passed"
|
|
1376
1488
|
end
|
|
1377
1489
|
Wardite::BinaryLoader::load_from_buffer(buffer, **options);
|
|
1378
1490
|
end
|
|
1379
1491
|
end
|
|
1492
|
+
|
|
1493
|
+
require_relative "wardite/efflorescence"
|
data/rbs_collection.lock.yaml
CHANGED
|
@@ -1,36 +1,12 @@
|
|
|
1
1
|
---
|
|
2
2
|
path: ".gem_rbs_collection"
|
|
3
3
|
gems:
|
|
4
|
-
- name: activesupport
|
|
5
|
-
version: '7.0'
|
|
6
|
-
source:
|
|
7
|
-
type: git
|
|
8
|
-
name: ruby/gem_rbs_collection
|
|
9
|
-
revision: 4873ad046b4ea8931591626cd547becae6d1e84e
|
|
10
|
-
remote: https://github.com/ruby/gem_rbs_collection.git
|
|
11
|
-
repo_dir: gems
|
|
12
4
|
- name: ast
|
|
13
5
|
version: '2.4'
|
|
14
6
|
source:
|
|
15
7
|
type: git
|
|
16
8
|
name: ruby/gem_rbs_collection
|
|
17
|
-
revision:
|
|
18
|
-
remote: https://github.com/ruby/gem_rbs_collection.git
|
|
19
|
-
repo_dir: gems
|
|
20
|
-
- name: base64
|
|
21
|
-
version: '0.1'
|
|
22
|
-
source:
|
|
23
|
-
type: git
|
|
24
|
-
name: ruby/gem_rbs_collection
|
|
25
|
-
revision: 4873ad046b4ea8931591626cd547becae6d1e84e
|
|
26
|
-
remote: https://github.com/ruby/gem_rbs_collection.git
|
|
27
|
-
repo_dir: gems
|
|
28
|
-
- name: bigdecimal
|
|
29
|
-
version: '3.1'
|
|
30
|
-
source:
|
|
31
|
-
type: git
|
|
32
|
-
name: ruby/gem_rbs_collection
|
|
33
|
-
revision: 4873ad046b4ea8931591626cd547becae6d1e84e
|
|
9
|
+
revision: 904dc25dace6f10aac76ca29dd0ee6ed299a7282
|
|
34
10
|
remote: https://github.com/ruby/gem_rbs_collection.git
|
|
35
11
|
repo_dir: gems
|
|
36
12
|
- name: concurrent-ruby
|
|
@@ -38,15 +14,7 @@ gems:
|
|
|
38
14
|
source:
|
|
39
15
|
type: git
|
|
40
16
|
name: ruby/gem_rbs_collection
|
|
41
|
-
revision:
|
|
42
|
-
remote: https://github.com/ruby/gem_rbs_collection.git
|
|
43
|
-
repo_dir: gems
|
|
44
|
-
- name: connection_pool
|
|
45
|
-
version: '2.4'
|
|
46
|
-
source:
|
|
47
|
-
type: git
|
|
48
|
-
name: ruby/gem_rbs_collection
|
|
49
|
-
revision: 4873ad046b4ea8931591626cd547becae6d1e84e
|
|
17
|
+
revision: 904dc25dace6f10aac76ca29dd0ee6ed299a7282
|
|
50
18
|
remote: https://github.com/ruby/gem_rbs_collection.git
|
|
51
19
|
repo_dir: gems
|
|
52
20
|
- name: csv
|
|
@@ -54,23 +22,11 @@ gems:
|
|
|
54
22
|
source:
|
|
55
23
|
type: git
|
|
56
24
|
name: ruby/gem_rbs_collection
|
|
57
|
-
revision:
|
|
25
|
+
revision: 904dc25dace6f10aac76ca29dd0ee6ed299a7282
|
|
58
26
|
remote: https://github.com/ruby/gem_rbs_collection.git
|
|
59
27
|
repo_dir: gems
|
|
60
|
-
- name: date
|
|
61
|
-
version: '0'
|
|
62
|
-
source:
|
|
63
|
-
type: stdlib
|
|
64
|
-
- name: digest
|
|
65
|
-
version: '0'
|
|
66
|
-
source:
|
|
67
|
-
type: stdlib
|
|
68
|
-
- name: erb
|
|
69
|
-
version: '0'
|
|
70
|
-
source:
|
|
71
|
-
type: stdlib
|
|
72
28
|
- name: ffi
|
|
73
|
-
version: 1.17.
|
|
29
|
+
version: 1.17.4
|
|
74
30
|
source:
|
|
75
31
|
type: rubygems
|
|
76
32
|
- name: fileutils
|
|
@@ -81,46 +37,34 @@ gems:
|
|
|
81
37
|
version: '0'
|
|
82
38
|
source:
|
|
83
39
|
type: stdlib
|
|
84
|
-
- name: i18n
|
|
85
|
-
version: '1.10'
|
|
86
|
-
source:
|
|
87
|
-
type: git
|
|
88
|
-
name: ruby/gem_rbs_collection
|
|
89
|
-
revision: 4873ad046b4ea8931591626cd547becae6d1e84e
|
|
90
|
-
remote: https://github.com/ruby/gem_rbs_collection.git
|
|
91
|
-
repo_dir: gems
|
|
92
40
|
- name: json
|
|
93
41
|
version: '0'
|
|
94
42
|
source:
|
|
95
43
|
type: stdlib
|
|
44
|
+
- name: language_server-protocol
|
|
45
|
+
version: 3.17.0.6
|
|
46
|
+
source:
|
|
47
|
+
type: rubygems
|
|
96
48
|
- name: listen
|
|
97
49
|
version: '3.9'
|
|
98
50
|
source:
|
|
99
51
|
type: git
|
|
100
52
|
name: ruby/gem_rbs_collection
|
|
101
|
-
revision:
|
|
53
|
+
revision: 904dc25dace6f10aac76ca29dd0ee6ed299a7282
|
|
102
54
|
remote: https://github.com/ruby/gem_rbs_collection.git
|
|
103
55
|
repo_dir: gems
|
|
104
56
|
- name: logger
|
|
105
|
-
version: '
|
|
106
|
-
source:
|
|
107
|
-
type: stdlib
|
|
108
|
-
- name: minitest
|
|
109
|
-
version: '5.25'
|
|
57
|
+
version: '1.7'
|
|
110
58
|
source:
|
|
111
59
|
type: git
|
|
112
60
|
name: ruby/gem_rbs_collection
|
|
113
|
-
revision:
|
|
61
|
+
revision: 904dc25dace6f10aac76ca29dd0ee6ed299a7282
|
|
114
62
|
remote: https://github.com/ruby/gem_rbs_collection.git
|
|
115
63
|
repo_dir: gems
|
|
116
64
|
- name: monitor
|
|
117
65
|
version: '0'
|
|
118
66
|
source:
|
|
119
67
|
type: stdlib
|
|
120
|
-
- name: openssl
|
|
121
|
-
version: '0'
|
|
122
|
-
source:
|
|
123
|
-
type: stdlib
|
|
124
68
|
- name: optparse
|
|
125
69
|
version: '0'
|
|
126
70
|
source:
|
|
@@ -130,19 +74,35 @@ gems:
|
|
|
130
74
|
source:
|
|
131
75
|
type: git
|
|
132
76
|
name: ruby/gem_rbs_collection
|
|
133
|
-
revision:
|
|
77
|
+
revision: 904dc25dace6f10aac76ca29dd0ee6ed299a7282
|
|
134
78
|
remote: https://github.com/ruby/gem_rbs_collection.git
|
|
135
79
|
repo_dir: gems
|
|
136
|
-
- name:
|
|
80
|
+
- name: pp
|
|
81
|
+
version: '0'
|
|
82
|
+
source:
|
|
83
|
+
type: stdlib
|
|
84
|
+
- name: prettyprint
|
|
137
85
|
version: '0'
|
|
138
86
|
source:
|
|
139
87
|
type: stdlib
|
|
88
|
+
- name: prism
|
|
89
|
+
version: 2.1.0
|
|
90
|
+
source:
|
|
91
|
+
type: rubygems
|
|
92
|
+
- name: racc
|
|
93
|
+
version: '1.8'
|
|
94
|
+
source:
|
|
95
|
+
type: git
|
|
96
|
+
name: ruby/gem_rbs_collection
|
|
97
|
+
revision: 904dc25dace6f10aac76ca29dd0ee6ed299a7282
|
|
98
|
+
remote: https://github.com/ruby/gem_rbs_collection.git
|
|
99
|
+
repo_dir: gems
|
|
140
100
|
- name: rainbow
|
|
141
101
|
version: '3.0'
|
|
142
102
|
source:
|
|
143
103
|
type: git
|
|
144
104
|
name: ruby/gem_rbs_collection
|
|
145
|
-
revision:
|
|
105
|
+
revision: 904dc25dace6f10aac76ca29dd0ee6ed299a7282
|
|
146
106
|
remote: https://github.com/ruby/gem_rbs_collection.git
|
|
147
107
|
repo_dir: gems
|
|
148
108
|
- name: rake
|
|
@@ -150,11 +110,15 @@ gems:
|
|
|
150
110
|
source:
|
|
151
111
|
type: git
|
|
152
112
|
name: ruby/gem_rbs_collection
|
|
153
|
-
revision:
|
|
113
|
+
revision: 904dc25dace6f10aac76ca29dd0ee6ed299a7282
|
|
154
114
|
remote: https://github.com/ruby/gem_rbs_collection.git
|
|
155
115
|
repo_dir: gems
|
|
116
|
+
- name: random-formatter
|
|
117
|
+
version: '0'
|
|
118
|
+
source:
|
|
119
|
+
type: stdlib
|
|
156
120
|
- name: rbs
|
|
157
|
-
version:
|
|
121
|
+
version: 4.2.0
|
|
158
122
|
source:
|
|
159
123
|
type: rubygems
|
|
160
124
|
- name: rdoc
|
|
@@ -165,14 +129,6 @@ gems:
|
|
|
165
129
|
version: '0'
|
|
166
130
|
source:
|
|
167
131
|
type: stdlib
|
|
168
|
-
- name: singleton
|
|
169
|
-
version: '0'
|
|
170
|
-
source:
|
|
171
|
-
type: stdlib
|
|
172
|
-
- name: socket
|
|
173
|
-
version: '0'
|
|
174
|
-
source:
|
|
175
|
-
type: stdlib
|
|
176
132
|
- name: stringio
|
|
177
133
|
version: '0'
|
|
178
134
|
source:
|
|
@@ -181,26 +137,10 @@ gems:
|
|
|
181
137
|
version: '0'
|
|
182
138
|
source:
|
|
183
139
|
type: stdlib
|
|
184
|
-
- name: time
|
|
185
|
-
version: '0'
|
|
186
|
-
source:
|
|
187
|
-
type: stdlib
|
|
188
|
-
- name: timeout
|
|
189
|
-
version: '0'
|
|
190
|
-
source:
|
|
191
|
-
type: stdlib
|
|
192
140
|
- name: tsort
|
|
193
141
|
version: '0'
|
|
194
142
|
source:
|
|
195
143
|
type: stdlib
|
|
196
|
-
- name: tzinfo
|
|
197
|
-
version: '2.0'
|
|
198
|
-
source:
|
|
199
|
-
type: git
|
|
200
|
-
name: ruby/gem_rbs_collection
|
|
201
|
-
revision: 4873ad046b4ea8931591626cd547becae6d1e84e
|
|
202
|
-
remote: https://github.com/ruby/gem_rbs_collection.git
|
|
203
|
-
repo_dir: gems
|
|
204
144
|
- name: uri
|
|
205
145
|
version: '0'
|
|
206
146
|
source:
|