wardite 1.2.1 → 1.3.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/README.md +17 -16
- data/Rakefile +0 -177
- data/benchmark/README.md +11 -37
- data/benchmark/call_cost_worker.rb +3 -2
- data/benchmark/compare.rb +1 -2
- data/benchmark/compare_linear_memory_loads.py +144 -0
- data/benchmark/i32_memory.wat +5 -1
- data/benchmark/investigate_calls.rb +3 -3
- data/benchmark/linear_memory_loads.wat +52 -0
- data/benchmark/optimization_worker.rb +3 -2
- data/benchmark/patches/adr0017-spinel-signed64.patch +190 -0
- data/benchmark/patches/adr0017-wardite-split-load64.patch +70 -0
- data/benchmark/results/adr0019-startup.json +1687 -0
- data/benchmark/results/adr0020-i64.json +2034 -0
- data/benchmark/results/adr0021-optimizer.json +5798 -0
- data/benchmark/results/adr0022-lazy-mir.json +3057 -0
- data/benchmark/results/crc8-stream-repeat.csv +89 -0
- data/benchmark/results/crc8-stream.csv +89 -0
- data/benchmark/results/linear-memory-loads-a2aa05227.csv +793 -0
- data/benchmark/results/linear-memory-loads-stage-b.csv +353 -0
- data/benchmark/results/linear-memory-loads.csv +1057 -0
- data/benchmark/results/real-workloads-baseline-2026-11-18.json +1741 -0
- data/benchmark/results/stack-vm-removal.json +334 -0
- data/benchmark/validate_m4.rb +0 -2
- data/docs/adr/0017-efflorescence-linear-memory-loads.md +90 -0
- data/docs/adr/0018-efflorescence-real-workload-measurement.md +126 -0
- data/docs/adr/0019-efflorescence-startup-quick-wins.md +85 -0
- data/docs/adr/0020-efflorescence-inline-i64-bit-operations.md +89 -0
- data/docs/adr/0021-efflorescence-optimize-real-functions.md +133 -0
- data/docs/adr/0022-efflorescence-lazy-function-build.md +111 -0
- data/docs/adr/0023-efflorescence-byte-sequences-and-copy-coalescing.md +56 -0
- data/docs/efflorescence-ja.md +6 -9
- data/docs/efflorescence-linear-memory-loads.md +134 -0
- data/docs/efflorescence-m6.md +1 -1
- data/docs/efflorescence-mir2-cache.md +7 -0
- data/docs/efflorescence-real-workloads.md +312 -0
- data/docs/efflorescence-spinel-linear-memory.md +2 -2
- data/docs/efflorescence.md +7 -8
- data/docs/stack-vm-removal.md +49 -0
- data/lib/wardite/cli/cli.rb +24 -21
- data/lib/wardite/efflorescence/byte_sequences.rb +80 -0
- data/lib/wardite/efflorescence/function_preparer.rb +64 -0
- data/lib/wardite/efflorescence/i64_arithmetic.rb +31 -0
- data/lib/wardite/efflorescence/inspection.rb +44 -12
- data/lib/wardite/efflorescence/ir.rb +33 -10
- data/lib/wardite/efflorescence/mir_cache.rb +10 -1
- data/lib/wardite/efflorescence/optimizer.rb +151 -42
- data/lib/wardite/efflorescence/store_access.rb +17 -0
- data/lib/wardite/efflorescence/translation_source.rb +50 -0
- data/lib/wardite/efflorescence/translator.rb +43 -13
- data/lib/wardite/efflorescence/vm.rb +116 -48
- data/lib/wardite/efflorescence.rb +3 -0
- data/lib/wardite/load.rb +47 -63
- data/lib/wardite/version.rb +1 -1
- data/lib/wardite.rb +21 -757
- data/scripts/build_spinel_zig.rb +1 -1
- data/sig/generated/wardite/cli/cli.rbs +4 -2
- data/sig/generated/wardite/efflorescence/byte_sequences.rbs +33 -0
- data/sig/generated/wardite/efflorescence/function_preparer.rbs +25 -0
- data/sig/generated/wardite/efflorescence/i64_arithmetic.rbs +19 -0
- data/sig/generated/wardite/efflorescence/inspection.rbs +8 -0
- data/sig/generated/wardite/efflorescence/ir.rbs +18 -2
- data/sig/generated/wardite/efflorescence/optimizer.rbs +41 -3
- data/sig/generated/wardite/efflorescence/store_access.rbs +5 -0
- data/sig/generated/wardite/efflorescence/translation_source.rbs +34 -0
- data/sig/generated/wardite/efflorescence/translator.rbs +11 -1
- data/sig/generated/wardite/efflorescence/vm.rbs +19 -9
- data/sig/generated/wardite/load.rbs +18 -18
- data/sig/generated/wardite.rbs +4 -155
- metadata +32 -17
- data/benchmark/compare_engines.rb +0 -119
- data/benchmark/engine_phases.rb +0 -30
- data/lib/wardite/alu_f32.generated.rb +0 -261
- data/lib/wardite/alu_f64.generated.rb +0 -261
- data/lib/wardite/alu_i32.generated.rb +0 -510
- data/lib/wardite/alu_i64.generated.rb +0 -572
- data/lib/wardite/convert.generated.rb +0 -340
- data/scripts/gen_alu.rb +0 -864
- data/scripts/gen_conv.rb +0 -86
- data/scripts/templates/alu_module.rb.tmpl +0 -20
- data/scripts/templates/conv_module.rb.tmpl +0 -20
- data/sig/generated/wardite/alu_f32.generated.rbs +0 -12
- data/sig/generated/wardite/alu_f64.generated.rbs +0 -12
- data/sig/generated/wardite/alu_i32.generated.rbs +0 -12
- data/sig/generated/wardite/alu_i64.generated.rbs +0 -12
- data/sig/generated/wardite/convert.generated.rbs +0 -12
|
@@ -1,261 +0,0 @@
|
|
|
1
|
-
# rbs_inline: enabled
|
|
2
|
-
require_relative "value"
|
|
3
|
-
|
|
4
|
-
module Wardite
|
|
5
|
-
module Evaluator
|
|
6
|
-
# @rbs runtime: Runtime
|
|
7
|
-
# @rbs frame: Frame
|
|
8
|
-
# @rbs code: Symbol
|
|
9
|
-
# @rbs operand: Array[operandItem]
|
|
10
|
-
# @rbs return: bool?
|
|
11
|
-
def self.f32_eval_insn(runtime, frame, code, operand)
|
|
12
|
-
case code
|
|
13
|
-
|
|
14
|
-
when :f32_load
|
|
15
|
-
_align = operand[0] # TODO: alignment support?
|
|
16
|
-
offset = operand[1]
|
|
17
|
-
raise EvalError, "[BUG] invalid type of operand" if !offset.is_a?(Integer)
|
|
18
|
-
|
|
19
|
-
addr = runtime.stack.pop
|
|
20
|
-
if !addr.is_a?(I32)
|
|
21
|
-
raise EvalError, "maybe stack too short"
|
|
22
|
-
end
|
|
23
|
-
|
|
24
|
-
at = addr.value + offset
|
|
25
|
-
data_end = at + F32.new.memsize / 8
|
|
26
|
-
memory = runtime.instance.store.memories[0] || raise("[BUG] no memory")
|
|
27
|
-
buf = if RUBY_ENGINE == "spinel"
|
|
28
|
-
memory.read_bytes(at, data_end - at)
|
|
29
|
-
else
|
|
30
|
-
memory.data[at...data_end]
|
|
31
|
-
end
|
|
32
|
-
if !buf
|
|
33
|
-
raise EvalError, "invalid memory range"
|
|
34
|
-
end
|
|
35
|
-
runtime.stack.push(F32.from_bytes(buf))
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
when :f32_store
|
|
39
|
-
_align = operand[0] # TODO: alignment support?
|
|
40
|
-
offset = operand[1]
|
|
41
|
-
raise EvalError, "[BUG] invalid type of operand" if !offset.is_a?(Integer)
|
|
42
|
-
|
|
43
|
-
value = runtime.stack.pop
|
|
44
|
-
addr = runtime.stack.pop
|
|
45
|
-
if !value.is_a?(F32) || !addr.is_a?(I32)
|
|
46
|
-
raise EvalError, "maybe stack too short"
|
|
47
|
-
end
|
|
48
|
-
|
|
49
|
-
at = addr.value + offset
|
|
50
|
-
data_end = at + value.packed.size
|
|
51
|
-
memory = runtime.instance.store.memories[0] || raise("[BUG] no memory")
|
|
52
|
-
if RUBY_ENGINE == "spinel"
|
|
53
|
-
memory.write_bytes(at, value.packed)
|
|
54
|
-
else
|
|
55
|
-
memory.data[at...data_end] = value.packed
|
|
56
|
-
end
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
when :f32_const
|
|
60
|
-
const = operand[0]
|
|
61
|
-
const = const.value if const.is_a?(FloatImmediate)
|
|
62
|
-
if !const.is_a?(Float)
|
|
63
|
-
raise EvalError, "invalid type of operand"
|
|
64
|
-
end
|
|
65
|
-
runtime.stack.push(F32(const))
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
when :f32_eqz
|
|
69
|
-
target = runtime.stack.pop
|
|
70
|
-
if !target.is_a?(F32)
|
|
71
|
-
raise EvalError, "maybe empty or invalid stack"
|
|
72
|
-
end
|
|
73
|
-
value = target.value.zero? ? 1 : 0
|
|
74
|
-
runtime.stack.push(I32(value))
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
when :f32_eq
|
|
78
|
-
right, left = runtime.stack.pop, runtime.stack.pop
|
|
79
|
-
if !right.is_a?(F32) || !left.is_a?(F32)
|
|
80
|
-
raise EvalError, "maybe empty or invalid stack"
|
|
81
|
-
end
|
|
82
|
-
value = (left.value == right.value) ? 1 : 0
|
|
83
|
-
runtime.stack.push(I32(value))
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
when :f32_ne
|
|
87
|
-
right, left = runtime.stack.pop, runtime.stack.pop
|
|
88
|
-
if !right.is_a?(F32) || !left.is_a?(F32)
|
|
89
|
-
raise EvalError, "maybe empty or invalid stack"
|
|
90
|
-
end
|
|
91
|
-
value = (left.value != right.value) ? 1 : 0
|
|
92
|
-
runtime.stack.push(I32(value))
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
when :f32_lt
|
|
96
|
-
right, left = runtime.stack.pop, runtime.stack.pop
|
|
97
|
-
if !right.is_a?(F32) || !left.is_a?(F32)
|
|
98
|
-
raise EvalError, "maybe empty or invalid stack"
|
|
99
|
-
end
|
|
100
|
-
value = (left.value < right.value) ? 1 : 0
|
|
101
|
-
runtime.stack.push(I32(value))
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
when :f32_gt
|
|
105
|
-
right, left = runtime.stack.pop, runtime.stack.pop
|
|
106
|
-
if !right.is_a?(F32) || !left.is_a?(F32)
|
|
107
|
-
raise EvalError, "maybe empty or invalid stack"
|
|
108
|
-
end
|
|
109
|
-
value = (left.value > right.value) ? 1 : 0
|
|
110
|
-
runtime.stack.push(I32(value))
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
when :f32_le
|
|
114
|
-
right, left = runtime.stack.pop, runtime.stack.pop
|
|
115
|
-
if !right.is_a?(F32) || !left.is_a?(F32)
|
|
116
|
-
raise EvalError, "maybe empty or invalid stack"
|
|
117
|
-
end
|
|
118
|
-
value = (left.value <= right.value) ? 1 : 0
|
|
119
|
-
runtime.stack.push(I32(value))
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
when :f32_ge
|
|
123
|
-
right, left = runtime.stack.pop, runtime.stack.pop
|
|
124
|
-
if !right.is_a?(F32) || !left.is_a?(F32)
|
|
125
|
-
raise EvalError, "maybe empty or invalid stack"
|
|
126
|
-
end
|
|
127
|
-
value = (left.value >= right.value) ? 1 : 0
|
|
128
|
-
runtime.stack.push(I32(value))
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
when :f32_abs
|
|
132
|
-
x = runtime.stack.pop
|
|
133
|
-
if !x.is_a?(F32)
|
|
134
|
-
raise EvalError, "maybe empty or invalid stack"
|
|
135
|
-
end
|
|
136
|
-
runtime.stack.push(F32(x.value.abs))
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
when :f32_neg
|
|
140
|
-
x = runtime.stack.pop
|
|
141
|
-
if !x.is_a?(F32)
|
|
142
|
-
raise EvalError, "maybe empty or invalid stack"
|
|
143
|
-
end
|
|
144
|
-
runtime.stack.push(F32(-(x.value)))
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
when :f32_ceil
|
|
148
|
-
x = runtime.stack.pop
|
|
149
|
-
if !x.is_a?(F32)
|
|
150
|
-
raise EvalError, "maybe empty or invalid stack"
|
|
151
|
-
end
|
|
152
|
-
runtime.stack.push(F32(x.value.ceil.to_f))
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
when :f32_floor
|
|
156
|
-
x = runtime.stack.pop
|
|
157
|
-
if !x.is_a?(F32)
|
|
158
|
-
raise EvalError, "maybe empty or invalid stack"
|
|
159
|
-
end
|
|
160
|
-
runtime.stack.push(F32(x.value.floor.to_f))
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
when :f32_trunc
|
|
164
|
-
x = runtime.stack.pop
|
|
165
|
-
if !x.is_a?(F32)
|
|
166
|
-
raise EvalError, "maybe empty or invalid stack"
|
|
167
|
-
end
|
|
168
|
-
runtime.stack.push(F32(x.value.to_i.to_f))
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
when :f32_nearest
|
|
172
|
-
x = runtime.stack.pop
|
|
173
|
-
if !x.is_a?(F32)
|
|
174
|
-
raise EvalError, "maybe empty or invalid stack"
|
|
175
|
-
end
|
|
176
|
-
runtime.stack.push(F32(x.value.round.to_f))
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
when :f32_sqrt
|
|
180
|
-
x = runtime.stack.pop
|
|
181
|
-
if !x.is_a?(F32)
|
|
182
|
-
raise EvalError, "maybe empty or invalid stack"
|
|
183
|
-
end
|
|
184
|
-
runtime.stack.push(F32(x.value ** 0.5))
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
when :f32_add
|
|
188
|
-
right, left = runtime.stack.pop, runtime.stack.pop
|
|
189
|
-
if !right.is_a?(F32) || !left.is_a?(F32)
|
|
190
|
-
raise EvalError, "maybe empty or invalid stack"
|
|
191
|
-
end
|
|
192
|
-
runtime.stack.push(F32(left.value + right.value))
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
when :f32_sub
|
|
196
|
-
right, left = runtime.stack.pop, runtime.stack.pop
|
|
197
|
-
if !right.is_a?(F32) || !left.is_a?(F32)
|
|
198
|
-
raise EvalError, "maybe empty or invalid stack"
|
|
199
|
-
end
|
|
200
|
-
runtime.stack.push(F32(left.value - right.value))
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
when :f32_mul
|
|
204
|
-
right, left = runtime.stack.pop, runtime.stack.pop
|
|
205
|
-
if !right.is_a?(F32) || !left.is_a?(F32)
|
|
206
|
-
raise EvalError, "maybe empty or invalid stack"
|
|
207
|
-
end
|
|
208
|
-
runtime.stack.push(F32(left.value * right.value))
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
when :f32_div
|
|
212
|
-
right, left = runtime.stack.pop, runtime.stack.pop
|
|
213
|
-
if !right.is_a?(F32) || !left.is_a?(F32)
|
|
214
|
-
raise EvalError, "maybe empty or invalid stack"
|
|
215
|
-
end
|
|
216
|
-
runtime.stack.push(F32(left.value / right.value))
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
when :f32_min
|
|
220
|
-
right, left = runtime.stack.pop, runtime.stack.pop
|
|
221
|
-
if !right.is_a?(F32) || !left.is_a?(F32)
|
|
222
|
-
raise EvalError, "maybe empty or invalid stack"
|
|
223
|
-
end
|
|
224
|
-
if right.value.nan? || left.value.nan?
|
|
225
|
-
runtime.stack.push(F32(Float::NAN))
|
|
226
|
-
return
|
|
227
|
-
end
|
|
228
|
-
runtime.stack.push(F32([left.value, right.value].min))
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
when :f32_max
|
|
232
|
-
right, left = runtime.stack.pop, runtime.stack.pop
|
|
233
|
-
if !right.is_a?(F32) || !left.is_a?(F32)
|
|
234
|
-
raise EvalError, "maybe empty or invalid stack"
|
|
235
|
-
end
|
|
236
|
-
if right.value.nan? || left.value.nan?
|
|
237
|
-
runtime.stack.push(F32(Float::NAN))
|
|
238
|
-
return
|
|
239
|
-
end
|
|
240
|
-
runtime.stack.push(F32([left.value, right.value].max))
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
when :f32_copysign
|
|
244
|
-
right, left = runtime.stack.pop, runtime.stack.pop
|
|
245
|
-
if !right.is_a?(F32) || !left.is_a?(F32)
|
|
246
|
-
raise EvalError, "maybe empty or invalid stack"
|
|
247
|
-
end
|
|
248
|
-
if left.sign == right.sign
|
|
249
|
-
runtime.stack.push(F32(left.value))
|
|
250
|
-
else
|
|
251
|
-
runtime.stack.push(F32(-left.value))
|
|
252
|
-
end
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
else
|
|
256
|
-
return
|
|
257
|
-
end
|
|
258
|
-
return true
|
|
259
|
-
end
|
|
260
|
-
end
|
|
261
|
-
end
|
|
@@ -1,261 +0,0 @@
|
|
|
1
|
-
# rbs_inline: enabled
|
|
2
|
-
require_relative "value"
|
|
3
|
-
|
|
4
|
-
module Wardite
|
|
5
|
-
module Evaluator
|
|
6
|
-
# @rbs runtime: Runtime
|
|
7
|
-
# @rbs frame: Frame
|
|
8
|
-
# @rbs code: Symbol
|
|
9
|
-
# @rbs operand: Array[operandItem]
|
|
10
|
-
# @rbs return: bool?
|
|
11
|
-
def self.f64_eval_insn(runtime, frame, code, operand)
|
|
12
|
-
case code
|
|
13
|
-
|
|
14
|
-
when :f64_load
|
|
15
|
-
_align = operand[0] # TODO: alignment support?
|
|
16
|
-
offset = operand[1]
|
|
17
|
-
raise EvalError, "[BUG] invalid type of operand" if !offset.is_a?(Integer)
|
|
18
|
-
|
|
19
|
-
addr = runtime.stack.pop
|
|
20
|
-
if !addr.is_a?(I32)
|
|
21
|
-
raise EvalError, "maybe stack too short"
|
|
22
|
-
end
|
|
23
|
-
|
|
24
|
-
at = addr.value + offset
|
|
25
|
-
data_end = at + F64.new.memsize / 8
|
|
26
|
-
memory = runtime.instance.store.memories[0] || raise("[BUG] no memory")
|
|
27
|
-
buf = if RUBY_ENGINE == "spinel"
|
|
28
|
-
memory.read_bytes(at, data_end - at)
|
|
29
|
-
else
|
|
30
|
-
memory.data[at...data_end]
|
|
31
|
-
end
|
|
32
|
-
if !buf
|
|
33
|
-
raise EvalError, "invalid memory range"
|
|
34
|
-
end
|
|
35
|
-
runtime.stack.push(F64.from_bytes(buf))
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
when :f64_store
|
|
39
|
-
_align = operand[0] # TODO: alignment support?
|
|
40
|
-
offset = operand[1]
|
|
41
|
-
raise EvalError, "[BUG] invalid type of operand" if !offset.is_a?(Integer)
|
|
42
|
-
|
|
43
|
-
value = runtime.stack.pop
|
|
44
|
-
addr = runtime.stack.pop
|
|
45
|
-
if !value.is_a?(F64) || !addr.is_a?(I32)
|
|
46
|
-
raise EvalError, "maybe stack too short"
|
|
47
|
-
end
|
|
48
|
-
|
|
49
|
-
at = addr.value + offset
|
|
50
|
-
data_end = at + value.packed.size
|
|
51
|
-
memory = runtime.instance.store.memories[0] || raise("[BUG] no memory")
|
|
52
|
-
if RUBY_ENGINE == "spinel"
|
|
53
|
-
memory.write_bytes(at, value.packed)
|
|
54
|
-
else
|
|
55
|
-
memory.data[at...data_end] = value.packed
|
|
56
|
-
end
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
when :f64_const
|
|
60
|
-
const = operand[0]
|
|
61
|
-
const = const.value if const.is_a?(FloatImmediate)
|
|
62
|
-
if !const.is_a?(Float)
|
|
63
|
-
raise EvalError, "invalid type of operand"
|
|
64
|
-
end
|
|
65
|
-
runtime.stack.push(F64(const))
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
when :f64_eqz
|
|
69
|
-
target = runtime.stack.pop
|
|
70
|
-
if !target.is_a?(F64)
|
|
71
|
-
raise EvalError, "maybe empty or invalid stack"
|
|
72
|
-
end
|
|
73
|
-
value = target.value.zero? ? 1 : 0
|
|
74
|
-
runtime.stack.push(I32(value))
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
when :f64_eq
|
|
78
|
-
right, left = runtime.stack.pop, runtime.stack.pop
|
|
79
|
-
if !right.is_a?(F64) || !left.is_a?(F64)
|
|
80
|
-
raise EvalError, "maybe empty or invalid stack"
|
|
81
|
-
end
|
|
82
|
-
value = (left.value == right.value) ? 1 : 0
|
|
83
|
-
runtime.stack.push(I32(value))
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
when :f64_ne
|
|
87
|
-
right, left = runtime.stack.pop, runtime.stack.pop
|
|
88
|
-
if !right.is_a?(F64) || !left.is_a?(F64)
|
|
89
|
-
raise EvalError, "maybe empty or invalid stack"
|
|
90
|
-
end
|
|
91
|
-
value = (left.value != right.value) ? 1 : 0
|
|
92
|
-
runtime.stack.push(I32(value))
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
when :f64_lt
|
|
96
|
-
right, left = runtime.stack.pop, runtime.stack.pop
|
|
97
|
-
if !right.is_a?(F64) || !left.is_a?(F64)
|
|
98
|
-
raise EvalError, "maybe empty or invalid stack"
|
|
99
|
-
end
|
|
100
|
-
value = (left.value < right.value) ? 1 : 0
|
|
101
|
-
runtime.stack.push(I32(value))
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
when :f64_gt
|
|
105
|
-
right, left = runtime.stack.pop, runtime.stack.pop
|
|
106
|
-
if !right.is_a?(F64) || !left.is_a?(F64)
|
|
107
|
-
raise EvalError, "maybe empty or invalid stack"
|
|
108
|
-
end
|
|
109
|
-
value = (left.value > right.value) ? 1 : 0
|
|
110
|
-
runtime.stack.push(I32(value))
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
when :f64_le
|
|
114
|
-
right, left = runtime.stack.pop, runtime.stack.pop
|
|
115
|
-
if !right.is_a?(F64) || !left.is_a?(F64)
|
|
116
|
-
raise EvalError, "maybe empty or invalid stack"
|
|
117
|
-
end
|
|
118
|
-
value = (left.value <= right.value) ? 1 : 0
|
|
119
|
-
runtime.stack.push(I32(value))
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
when :f64_ge
|
|
123
|
-
right, left = runtime.stack.pop, runtime.stack.pop
|
|
124
|
-
if !right.is_a?(F64) || !left.is_a?(F64)
|
|
125
|
-
raise EvalError, "maybe empty or invalid stack"
|
|
126
|
-
end
|
|
127
|
-
value = (left.value >= right.value) ? 1 : 0
|
|
128
|
-
runtime.stack.push(I32(value))
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
when :f64_abs
|
|
132
|
-
x = runtime.stack.pop
|
|
133
|
-
if !x.is_a?(F64)
|
|
134
|
-
raise EvalError, "maybe empty or invalid stack"
|
|
135
|
-
end
|
|
136
|
-
runtime.stack.push(F64(x.value.abs))
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
when :f64_neg
|
|
140
|
-
x = runtime.stack.pop
|
|
141
|
-
if !x.is_a?(F64)
|
|
142
|
-
raise EvalError, "maybe empty or invalid stack"
|
|
143
|
-
end
|
|
144
|
-
runtime.stack.push(F64(-(x.value)))
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
when :f64_ceil
|
|
148
|
-
x = runtime.stack.pop
|
|
149
|
-
if !x.is_a?(F64)
|
|
150
|
-
raise EvalError, "maybe empty or invalid stack"
|
|
151
|
-
end
|
|
152
|
-
runtime.stack.push(F64(x.value.ceil.to_f))
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
when :f64_floor
|
|
156
|
-
x = runtime.stack.pop
|
|
157
|
-
if !x.is_a?(F64)
|
|
158
|
-
raise EvalError, "maybe empty or invalid stack"
|
|
159
|
-
end
|
|
160
|
-
runtime.stack.push(F64(x.value.floor.to_f))
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
when :f64_trunc
|
|
164
|
-
x = runtime.stack.pop
|
|
165
|
-
if !x.is_a?(F64)
|
|
166
|
-
raise EvalError, "maybe empty or invalid stack"
|
|
167
|
-
end
|
|
168
|
-
runtime.stack.push(F64(x.value.to_i.to_f))
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
when :f64_nearest
|
|
172
|
-
x = runtime.stack.pop
|
|
173
|
-
if !x.is_a?(F64)
|
|
174
|
-
raise EvalError, "maybe empty or invalid stack"
|
|
175
|
-
end
|
|
176
|
-
runtime.stack.push(F64(x.value.round.to_f))
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
when :f64_sqrt
|
|
180
|
-
x = runtime.stack.pop
|
|
181
|
-
if !x.is_a?(F64)
|
|
182
|
-
raise EvalError, "maybe empty or invalid stack"
|
|
183
|
-
end
|
|
184
|
-
runtime.stack.push(F64(x.value ** 0.5))
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
when :f64_add
|
|
188
|
-
right, left = runtime.stack.pop, runtime.stack.pop
|
|
189
|
-
if !right.is_a?(F64) || !left.is_a?(F64)
|
|
190
|
-
raise EvalError, "maybe empty or invalid stack"
|
|
191
|
-
end
|
|
192
|
-
runtime.stack.push(F64(left.value + right.value))
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
when :f64_sub
|
|
196
|
-
right, left = runtime.stack.pop, runtime.stack.pop
|
|
197
|
-
if !right.is_a?(F64) || !left.is_a?(F64)
|
|
198
|
-
raise EvalError, "maybe empty or invalid stack"
|
|
199
|
-
end
|
|
200
|
-
runtime.stack.push(F64(left.value - right.value))
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
when :f64_mul
|
|
204
|
-
right, left = runtime.stack.pop, runtime.stack.pop
|
|
205
|
-
if !right.is_a?(F64) || !left.is_a?(F64)
|
|
206
|
-
raise EvalError, "maybe empty or invalid stack"
|
|
207
|
-
end
|
|
208
|
-
runtime.stack.push(F64(left.value * right.value))
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
when :f64_div
|
|
212
|
-
right, left = runtime.stack.pop, runtime.stack.pop
|
|
213
|
-
if !right.is_a?(F64) || !left.is_a?(F64)
|
|
214
|
-
raise EvalError, "maybe empty or invalid stack"
|
|
215
|
-
end
|
|
216
|
-
runtime.stack.push(F64(left.value / right.value))
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
when :f64_min
|
|
220
|
-
right, left = runtime.stack.pop, runtime.stack.pop
|
|
221
|
-
if !right.is_a?(F64) || !left.is_a?(F64)
|
|
222
|
-
raise EvalError, "maybe empty or invalid stack"
|
|
223
|
-
end
|
|
224
|
-
if right.value.nan? || left.value.nan?
|
|
225
|
-
runtime.stack.push(F64(Float::NAN))
|
|
226
|
-
return
|
|
227
|
-
end
|
|
228
|
-
runtime.stack.push(F64([left.value, right.value].min))
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
when :f64_max
|
|
232
|
-
right, left = runtime.stack.pop, runtime.stack.pop
|
|
233
|
-
if !right.is_a?(F64) || !left.is_a?(F64)
|
|
234
|
-
raise EvalError, "maybe empty or invalid stack"
|
|
235
|
-
end
|
|
236
|
-
if right.value.nan? || left.value.nan?
|
|
237
|
-
runtime.stack.push(F64(Float::NAN))
|
|
238
|
-
return
|
|
239
|
-
end
|
|
240
|
-
runtime.stack.push(F64([left.value, right.value].max))
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
when :f64_copysign
|
|
244
|
-
right, left = runtime.stack.pop, runtime.stack.pop
|
|
245
|
-
if !right.is_a?(F64) || !left.is_a?(F64)
|
|
246
|
-
raise EvalError, "maybe empty or invalid stack"
|
|
247
|
-
end
|
|
248
|
-
if left.sign == right.sign
|
|
249
|
-
runtime.stack.push(F64(left.value))
|
|
250
|
-
else
|
|
251
|
-
runtime.stack.push(F64(-left.value))
|
|
252
|
-
end
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
else
|
|
256
|
-
return
|
|
257
|
-
end
|
|
258
|
-
return true
|
|
259
|
-
end
|
|
260
|
-
end
|
|
261
|
-
end
|