wardite 0.2.2 → 0.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 932c8c0c36490c2b84b652ee4b43682ee0218c3d6ed4164685e5066b45e79e60
4
- data.tar.gz: d185d75762ac744752fede64fe6fd766a4639105697af520eb01b802ae7bd4a2
3
+ metadata.gz: f92001daa1c57ae535fd1556fabee90a61dbe741e4e5b9f313c26e5d75d68b3e
4
+ data.tar.gz: 237df98e70875e1b6e69fbf0019cc298c3df26fa69cd4e62df8a04eaeff37522
5
5
  SHA512:
6
- metadata.gz: 5251ca5fe770cfce8ad98f35ab31017b95d70d91e0088d640612c51f1506bb31e5484c26571cfc84503c686ab18f82a14b604698be5a0577072ef5dff6880cc7
7
- data.tar.gz: f2c8f3e17ae79c3f79b9f736d3f31e317178cecacbc562900a592572596b283fdee1594267ccc3afb156426b7f7265a0d9ad9902bfc1a6a86e5f2db5622a9aa8
6
+ metadata.gz: 94b5d318cebff3c8d87ea03fa0c5489ece3ef26ca7fcd6e6324febaf55a63f0a9ecb0a76d01b5adf5712737d8daf79ac55f5e2149ff8f85612acbaee1a2ace8c
7
+ data.tar.gz: c5991f43b9a62a7df87f23ec71350a77bf9493ccd083c6d0dba596c55976460e0c89625294048389a5fec1e35826bfbddd205718b45e04353b8e1627ccc4bb57
@@ -0,0 +1,13 @@
1
+ ;; https://developer.mozilla.org/en-US/docs/WebAssembly/Reference/Control_flow/block
2
+ (module
3
+ (func (export "ret_if_100") (param $num i32) (result i32)
4
+ (block $my_block
5
+ local.get $num
6
+ i32.const 100
7
+ i32.eq
8
+ (if
9
+ (then
10
+ br $my_block))
11
+ i32.const -1
12
+ local.set $num)
13
+ local.get $num))
@@ -0,0 +1,15 @@
1
+ (module
2
+ ;; ref https://ukyo.github.io/wasm-usui-book/webroot/get-started-webassembly.html
3
+ ;; and https://developer.mozilla.org/ja/docs/WebAssembly/Understanding_the_text_format
4
+ (type $return_i32 (func (result i32)))
5
+ (table 3 funcref)
6
+ (elem (i32.const 0) $f1 $f2 $f3)
7
+
8
+ (func $f1 (result i32) i32.const 111)
9
+ (func $f2 (result i32) i32.const 222)
10
+ (func $f3 (result i32) i32.const 333)
11
+
12
+ (func (export "call_indirect") (param $i i32) (result i32)
13
+ local.get $i
14
+ call_indirect (type $return_i32))
15
+ )
data/examples/loop.wat ADDED
@@ -0,0 +1,20 @@
1
+ (module ;; https://developer.mozilla.org/en-US/docs/WebAssembly/Reference/Control_flow/br
2
+ (global $i (mut i32) (i32.const 0))
3
+
4
+ (func $count (result i32)
5
+ (loop $my_loop (result i32)
6
+ global.get $i
7
+ i32.const 1
8
+ i32.add
9
+ global.set $i
10
+
11
+ global.get $i
12
+ global.get $i
13
+ i32.const 10
14
+ i32.lt_s
15
+ br_if $my_loop
16
+ )
17
+ )
18
+
19
+ (export "count" (func $count))
20
+ )
@@ -0,0 +1,12 @@
1
+ (module
2
+ (global $var (mut i32) (i32.const 0))
3
+ (func $init
4
+ i32.const 100
5
+ global.set $var
6
+ )
7
+ (func $main (result i32)
8
+ global.get $var ;; load $var onto the stack
9
+ )
10
+ (start $init)
11
+ (export "test" (func $main))
12
+ )
@@ -1,6 +1,9 @@
1
1
  # rbs_inline: enabled
2
2
 
3
3
  module Wardite
4
+ # @rbs!
5
+ # type operandItem = Integer | Array[Integer] | Float | Block
6
+
4
7
  class Op
5
8
  # @see https://pengowray.github.io/wasm-ops/
6
9
  SYMS = %i[
@@ -50,11 +53,11 @@ module Wardite
50
53
  attr_accessor :code #: Symbol
51
54
 
52
55
  # TODO: add types of potential operands
53
- attr_accessor :operand #: Array[Integer|Float|Block]
56
+ attr_accessor :operand #: Array[operandItem]
54
57
 
55
58
  # @rbs namespace: Symbol
56
59
  # @rbs code: Symbol
57
- # @rbs operand: Array[Integer|Float|Block]
60
+ # @rbs operand: Array[operandItem]
58
61
  def initialize(namespace, code, operand)
59
62
  @namespace = namespace
60
63
  @code = code
@@ -102,9 +105,7 @@ module Wardite
102
105
  [:f32]
103
106
  when :f64_const
104
107
  [:f64]
105
- when :if
106
- [:u8_if_block]
107
- when :block, :loop
108
+ when :if, :block, :loop
108
109
  [:u8_block]
109
110
  else
110
111
  []
@@ -112,10 +113,15 @@ module Wardite
112
113
  end
113
114
 
114
115
  # @see https://www.w3.org/TR/wasm-core-1/#value-types%E2%91%A2
116
+ # We use this for reftype conversion. https://webassembly.github.io/spec/core/binary/types.html#binary-reftype
115
117
  # @rbs code: Integer
116
118
  # @rbs return: Symbol
117
119
  def self.i2type(code)
118
120
  case code
121
+ when 0x6f
122
+ :externref
123
+ when 0x70
124
+ :funcref
119
125
  when 0x7f
120
126
  :i32
121
127
  when 0x7e
data/lib/wardite/load.rb CHANGED
@@ -35,8 +35,23 @@ module Wardite
35
35
  end
36
36
  end
37
37
 
38
+ class TableSection < Section
39
+ attr_accessor :table_types #: Array[Symbol]
40
+
41
+ attr_accessor :table_limits #: Array[[Integer, Integer?]]
42
+
43
+ # @rbs return: void
44
+ def initialize
45
+ self.name = "Table"
46
+ self.code = 0x4
47
+
48
+ @table_types = []
49
+ @table_limits = []
50
+ end
51
+ end
52
+
38
53
  class MemorySection < Section
39
- attr_accessor :limits #: Array[[Integer, Integer|nil]]
54
+ attr_accessor :limits #: Array[[Integer, Integer?]]
40
55
 
41
56
  # @rbs return: void
42
57
  def initialize
@@ -56,7 +71,7 @@ module Wardite
56
71
  # TODO: unused in wasm 1.0 spec?
57
72
  attr_accessor :shared #: bool
58
73
 
59
- attr_accessor :value #: I32|I64|F32|F64
74
+ attr_accessor :value #: wasmValue
60
75
 
61
76
  # @rbs &blk: (Global) -> void
62
77
  # @rbs return: void
@@ -76,6 +91,35 @@ module Wardite
76
91
  end
77
92
  end
78
93
 
94
+ class StartSection < Section
95
+ attr_accessor :func_index #: Integer
96
+
97
+ # @rbs return: void
98
+ def initialize
99
+ self.name = "Start"
100
+ self.code = 0x8
101
+ self.func_index = -1
102
+ end
103
+ end
104
+
105
+ class ElemSection < Section
106
+ attr_accessor :table_indices #: Array[Integer]
107
+
108
+ attr_accessor :table_offsets #: Array[Integer]
109
+
110
+ attr_accessor :element_indices #: Array[Array[Integer]]
111
+
112
+ # @rbs return: void
113
+ def initialize
114
+ self.name = "Elem"
115
+ self.code = 0x9
116
+
117
+ @table_indices = []
118
+ @table_offsets = []
119
+ @element_indices = []
120
+ end
121
+ end
122
+
79
123
  class CodeSection < Section
80
124
  class CodeBody
81
125
  attr_accessor :locals_count #: Array[Integer]
@@ -186,8 +230,10 @@ module Wardite
186
230
  extend Wardite::Leb128Helper
187
231
  extend Wardite::ValueHelper
188
232
 
233
+ # @rbs self.@buf: File|StringIO
234
+
189
235
  # @rbs buf: File|StringIO
190
- # @rbs import_object: Hash[Symbol, Hash[Symbol, Proc]]
236
+ # @rbs import_object: Hash[Symbol, Hash[Symbol, wasmCallable]]
191
237
  # @rbs enable_wasi: boolish
192
238
  # @rbs return: Instance
193
239
  def self.load_from_buffer(buf, import_object: {}, enable_wasi: true)
@@ -249,7 +295,7 @@ module Wardite
249
295
  when Wardite::SectionFunction
250
296
  function_section
251
297
  when Wardite::SectionTable
252
- unimplemented_skip_section(code)
298
+ table_section
253
299
  when Wardite::SectionMemory
254
300
  memory_section
255
301
  when Wardite::SectionGlobal
@@ -257,9 +303,9 @@ module Wardite
257
303
  when Wardite::SectionExport
258
304
  export_section
259
305
  when Wardite::SectionStart
260
- unimplemented_skip_section(code)
306
+ start_section
261
307
  when Wardite::SectionElement
262
- unimplemented_skip_section(code)
308
+ elem_section
263
309
  when Wardite::SectionCode
264
310
  code_section
265
311
  when Wardite::SectionData
@@ -387,6 +433,50 @@ module Wardite
387
433
  dest
388
434
  end
389
435
 
436
+ # @rbs return: StartSection
437
+ def self.start_section
438
+ dest = StartSection.new
439
+ size = fetch_uleb128(@buf)
440
+ dest.size = size
441
+ # StartSection won't use size
442
+ func_index = fetch_uleb128(@buf)
443
+ dest.func_index = func_index
444
+ dest
445
+ end
446
+
447
+ # @rbs return: ElemSection
448
+ def self.elem_section
449
+ dest = ElemSection.new
450
+ size = fetch_uleb128(@buf)
451
+ dest.size = size
452
+ sbuf = StringIO.new(@buf.read(size) || raise("buffer too short"))
453
+
454
+ len = fetch_uleb128(sbuf)
455
+ len.times do |i|
456
+ etype = fetch_uleb128(sbuf)
457
+ case etype
458
+ when 0x0 # expr, vec(funcidx)
459
+ dest.table_indices << 0 # default and fixed to table[0]
460
+
461
+ code = fetch_insn_while_end(sbuf)
462
+ ops = code_body(StringIO.new(code))
463
+ offset = decode_expr(ops)
464
+ dest.table_offsets << offset
465
+
466
+ elms = []
467
+ elen = fetch_uleb128(sbuf)
468
+ elen.times do |i|
469
+ index = fetch_uleb128(sbuf)
470
+ elms << index
471
+ end
472
+ dest.element_indices << elms
473
+ else
474
+ raise NotImplementedError, "element section type #{etype} is a TODO!"
475
+ end
476
+ end
477
+ dest
478
+ end
479
+
390
480
  # @rbs return: GlobalSection
391
481
  def self.global_section
392
482
  dest = GlobalSection.new
@@ -433,6 +523,30 @@ module Wardite
433
523
  dest
434
524
  end
435
525
 
526
+ # @rbs return: TableSection
527
+ def self.table_section
528
+ dest = TableSection.new
529
+ size = fetch_uleb128(@buf)
530
+ dest.size = size
531
+ sbuf = StringIO.new(@buf.read(size) || raise("buffer too short"))
532
+
533
+ len = fetch_uleb128(sbuf)
534
+ len.times do |i|
535
+ code = fetch_uleb128(sbuf)
536
+ type = Op.i2type(code)
537
+ dest.table_types << type
538
+
539
+ flags = fetch_uleb128(sbuf)
540
+ min = fetch_uleb128(sbuf)
541
+ max = nil
542
+ if flags != 0
543
+ max = fetch_uleb128(sbuf)
544
+ end
545
+ dest.table_limits << [min, max]
546
+ end
547
+ dest
548
+ end
549
+
436
550
  # @rbs return: CodeSection
437
551
  def self.code_section
438
552
  dest = CodeSection.new
@@ -478,7 +592,7 @@ module Wardite
478
592
  while c = buf.read(1)
479
593
  namespace, code = Op.to_sym(c)
480
594
  operand_types = Op.operand_of(code)
481
- operand = [] #: Array[Integer|Float|Block]
595
+ operand = [] #: Array[operandItem]
482
596
  operand_types.each do |typ|
483
597
  case typ
484
598
  when :u8
@@ -489,6 +603,13 @@ module Wardite
489
603
  operand << ope.ord
490
604
  when :u32
491
605
  operand << fetch_uleb128(buf)
606
+ when :u32_vec
607
+ len = fetch_uleb128(buf)
608
+ vec = [] #: Array[Integer]
609
+ len.times do
610
+ vec << fetch_uleb128(buf)
611
+ end
612
+ operand << vec
492
613
  when :i32
493
614
  operand << fetch_sleb128(buf)
494
615
  when :i64
@@ -509,7 +630,7 @@ module Wardite
509
630
  v = data.unpack("E")[0]
510
631
  raise "String#unpack is broken" if !v.is_a?(Float)
511
632
  operand << v
512
- when :u8_if_block # :if specific
633
+ when :u8_block
513
634
  block_ope = buf.read 1
514
635
  if ! block_ope
515
636
  raise LoadError, "buffer too short for if"
@@ -599,7 +720,7 @@ module Wardite
599
720
  end
600
721
 
601
722
  # @rbs ops: Array[Op]
602
- # @rbs return: I32|I64|F32|F64
723
+ # @rbs return: wasmValue
603
724
  def self.decode_global_expr(ops)
604
725
  # sees first opcode
605
726
  op = ops.first
data/lib/wardite/value.rb CHANGED
@@ -1,12 +1,15 @@
1
1
  # rbs_inline: enabled
2
2
 
3
3
  module Wardite
4
+ # @rbs!
5
+ # type wasmValue = I32 | I64 | F32 | F64
6
+
4
7
  module ValueHelper
5
8
  # @rbs value: Integer
6
9
  # @rbs return: I32
7
10
  def I32(value)
8
11
  if value < 0
9
- $stderr.puts "debug: negative i32 value #{value} is passed, convert to unsigned"
12
+ # $stderr.puts "trace: negative i32 value #{value} is passed, convert to unsigned"
10
13
  value = as_u32(value)
11
14
  end
12
15
  I32.new.tap{|i| i.value = value & I32::I32_MAX }
@@ -16,7 +19,7 @@ module Wardite
16
19
  # @rbs return: I64
17
20
  def I64(value)
18
21
  if value < 0
19
- $stderr.puts "debug: negative i64 value #{value} is passed, convert to unsigned"
22
+ # $stderr.puts "trace: negative i64 value #{value} is passed, convert to unsigned"
20
23
  value = as_u64(value)
21
24
  end
22
25
  I64.new.tap{|i| i.value = value & I64::I64_MAX }
@@ -107,39 +110,39 @@ module Wardite
107
110
  end
108
111
 
109
112
  # @rbs to: Symbol
110
- # @rbs return: I32|I64|F32|F64
113
+ # @rbs return: wasmValue
111
114
  def wrap(to:)
112
115
  raise EvalError, "unsupported operation"
113
116
  end
114
117
 
115
118
  # @rbs to: Symbol
116
- # @rbs return: I32|I64|F32|F64
119
+ # @rbs return: wasmValue
117
120
  def extend_s(to:)
118
121
  raise EvalError, "unsupported operation" if to != :i64
119
122
  I64(value_s)
120
123
  end
121
124
 
122
125
  # @rbs to: Symbol
123
- # @rbs return: I32|I64|F32|F64
126
+ # @rbs return: wasmValue
124
127
  def extend_u(to:)
125
128
  raise EvalError, "unsupported operation" if to != :i64
126
129
  I64(value)
127
130
  end
128
131
 
129
132
  # @rbs to: Symbol
130
- # @rbs return: I32|I64|F32|F64
133
+ # @rbs return: wasmValue
131
134
  def trunc_s(to:)
132
135
  raise EvalError, "unsupported operation"
133
136
  end
134
137
 
135
138
  # @rbs to: Symbol
136
- # @rbs return: I32|I64|F32|F64
139
+ # @rbs return: wasmValue
137
140
  def trunc_u(to:)
138
141
  raise EvalError, "unsupported operation"
139
142
  end
140
143
 
141
144
  # @rbs to: Symbol
142
- # @rbs return: I32|I64|F32|F64
145
+ # @rbs return: wasmValue
143
146
  def convert_s(to:)
144
147
  case to
145
148
  when :f32
@@ -152,7 +155,7 @@ module Wardite
152
155
  end
153
156
 
154
157
  # @rbs to: Symbol
155
- # @rbs return: I32|I64|F32|F64
158
+ # @rbs return: wasmValue
156
159
  def convert_u(to:)
157
160
  case to
158
161
  when :f32
@@ -165,21 +168,21 @@ module Wardite
165
168
  end
166
169
 
167
170
  # @rbs to: Symbol
168
- # @rbs return: I32|I64|F32|F64
171
+ # @rbs return: wasmValue
169
172
  def demote(to:)
170
173
  raise EvalError, "unsupported operation"
171
174
 
172
175
  end
173
176
 
174
177
  # @rbs to: Symbol
175
- # @rbs return: I32|I64|F32|F64
178
+ # @rbs return: wasmValue
176
179
  def promote(to:)
177
180
  raise EvalError, "unsupported operation"
178
181
 
179
182
  end
180
183
 
181
184
  # @rbs to: Symbol
182
- # @rbs return: I32|I64|F32|F64
185
+ # @rbs return: wasmValue
183
186
  def reinterpret(to:)
184
187
  raise EvalError, "unsupported operation" if to != :f32
185
188
  v = [value].pack("I!").unpack("f")[0]
@@ -252,7 +255,7 @@ module Wardite
252
255
  end
253
256
 
254
257
  # @rbs to: Symbol
255
- # @rbs return: I32|I64|F32|F64
258
+ # @rbs return: wasmValue
256
259
  def wrap(to:)
257
260
  if to != :i32
258
261
  raise EvalError, "unsupported operation #{to}"
@@ -261,31 +264,31 @@ module Wardite
261
264
  end
262
265
 
263
266
  # @rbs to: Symbol
264
- # @rbs return: I32|I64|F32|F64
267
+ # @rbs return: wasmValue
265
268
  def extend_s(to:)
266
269
  raise EvalError, "unsupported operation"
267
270
  end
268
271
 
269
272
  # @rbs to: Symbol
270
- # @rbs return: I32|I64|F32|F64
273
+ # @rbs return: wasmValue
271
274
  def extend_u(to:)
272
275
  raise EvalError, "unsupported operation"
273
276
  end
274
277
 
275
278
  # @rbs to: Symbol
276
- # @rbs return: I32|I64|F32|F64
279
+ # @rbs return: wasmValue
277
280
  def trunc_s(to:)
278
281
  raise EvalError, "unsupported operation"
279
282
  end
280
283
 
281
284
  # @rbs to: Symbol
282
- # @rbs return: I32|I64|F32|F64
285
+ # @rbs return: wasmValue
283
286
  def trunc_u(to:)
284
287
  raise EvalError, "unsupported operation"
285
288
  end
286
289
 
287
290
  # @rbs to: Symbol
288
- # @rbs return: I32|I64|F32|F64
291
+ # @rbs return: wasmValue
289
292
  def convert_s(to:)
290
293
  case to
291
294
  when :f32
@@ -298,7 +301,7 @@ module Wardite
298
301
  end
299
302
 
300
303
  # @rbs to: Symbol
301
- # @rbs return: I32|I64|F32|F64
304
+ # @rbs return: wasmValue
302
305
  def convert_u(to:)
303
306
  case to
304
307
  when :f32
@@ -311,19 +314,19 @@ module Wardite
311
314
  end
312
315
 
313
316
  # @rbs to: Symbol
314
- # @rbs return: I32|I64|F32|F64
317
+ # @rbs return: wasmValue
315
318
  def demote(to:)
316
319
  raise EvalError, "unsupported operation"
317
320
  end
318
321
 
319
322
  # @rbs to: Symbol
320
- # @rbs return: I32|I64|F32|F64
323
+ # @rbs return: wasmValue
321
324
  def promote(to:)
322
325
  raise EvalError, "unsupported operation"
323
326
  end
324
327
 
325
328
  # @rbs to: Symbol
326
- # @rbs return: I32|I64|F32|F64
329
+ # @rbs return: wasmValue
327
330
  def reinterpret(to:)
328
331
  raise EvalError, "unsupported operation" if to != :f64
329
332
  v = [value].pack("L!").unpack("d")[0]
@@ -373,19 +376,19 @@ module Wardite
373
376
  end
374
377
 
375
378
  # @rbs to: Symbol
376
- # @rbs return: I32|I64|F32|F64
379
+ # @rbs return: wasmValue
377
380
  def wrap(to:)
378
381
  raise EvalError, "unsupported operation"
379
382
  end
380
383
 
381
384
  # @rbs to: Symbol
382
- # @rbs return: I32|I64|F32|F64
385
+ # @rbs return: wasmValue
383
386
  def extend_s(to:)
384
387
  raise EvalError, "unsupported operation"
385
388
  end
386
389
 
387
390
  # @rbs to: Symbol
388
- # @rbs return: I32|I64|F32|F64
391
+ # @rbs return: wasmValue
389
392
  def extend_u(to:)
390
393
  raise EvalError, "unsupported operation"
391
394
  end
@@ -393,7 +396,7 @@ module Wardite
393
396
  # @todo need more testcase...
394
397
  # @see https://webassembly.github.io/spec/core/exec/numerics.html#xref-exec-numerics-op-trunc-s-mathrm-trunc-mathsf-s-m-n-z
395
398
  # @rbs to: Symbol
396
- # @rbs return: I32|I64|F32|F64
399
+ # @rbs return: wasmValue
397
400
  def trunc_s(to:)
398
401
  v = value.to_i
399
402
  case to
@@ -424,7 +427,7 @@ module Wardite
424
427
 
425
428
  # @see https://webassembly.github.io/spec/core/exec/numerics.html#xref-exec-numerics-op-trunc-u-mathrm-trunc-mathsf-u-m-n-z
426
429
  # @rbs to: Symbol
427
- # @rbs return: I32|I64|F32|F64
430
+ # @rbs return: wasmValue
428
431
  def trunc_u(to:)
429
432
  v = value.to_i
430
433
  if v < 0
@@ -443,32 +446,32 @@ module Wardite
443
446
  end
444
447
 
445
448
  # @rbs to: Symbol
446
- # @rbs return: I32|I64|F32|F64
449
+ # @rbs return: wasmValue
447
450
  def convert_s(to:)
448
451
  raise EvalError, "unsupported operation"
449
452
  end
450
453
 
451
454
  # @rbs to: Symbol
452
- # @rbs return: I32|I64|F32|F64
455
+ # @rbs return: wasmValue
453
456
  def convert_u(to:)
454
457
  raise EvalError, "unsupported operation"
455
458
  end
456
459
 
457
460
  # @rbs to: Symbol
458
- # @rbs return: I32|I64|F32|F64
461
+ # @rbs return: wasmValue
459
462
  def demote(to:)
460
463
  raise EvalError, "unsupported operation"
461
464
  end
462
465
 
463
466
  # @rbs to: Symbol
464
- # @rbs return: I32|I64|F32|F64
467
+ # @rbs return: wasmValue
465
468
  def promote(to:)
466
469
  raise EvalError, "unsupported operation" if to != :f64
467
470
  F64(value)
468
471
  end
469
472
 
470
473
  # @rbs to: Symbol
471
- # @rbs return: I32|I64|F32|F64
474
+ # @rbs return: wasmValue
472
475
  def reinterpret(to:)
473
476
  raise EvalError, "unsupported operation" if to != :i32
474
477
  v = [value].pack("f").unpack("I!")[0]
@@ -517,26 +520,26 @@ module Wardite
517
520
  end
518
521
 
519
522
  # @rbs to: Symbol
520
- # @rbs return: I32|I64|F32|F64
523
+ # @rbs return: wasmValue
521
524
  def wrap(to:)
522
525
  raise EvalError, "unsupported operation"
523
526
  end
524
527
 
525
528
  # @rbs to: Symbol
526
- # @rbs return: I32|I64|F32|F64
529
+ # @rbs return: wasmValue
527
530
  def extend_s(to:)
528
531
  raise EvalError, "unsupported operation"
529
532
  end
530
533
 
531
534
  # @rbs to: Symbol
532
- # @rbs return: I32|I64|F32|F64
535
+ # @rbs return: wasmValue
533
536
  def extend_u(to:)
534
537
  raise EvalError, "unsupported operation"
535
538
  end
536
539
 
537
540
  # @see the same as F32
538
541
  # @rbs to: Symbol
539
- # @rbs return: I32|I64|F32|F64
542
+ # @rbs return: wasmValue
540
543
  def trunc_s(to:)
541
544
  v = value.to_i
542
545
  case to
@@ -567,7 +570,7 @@ module Wardite
567
570
 
568
571
  # @see the same as F32
569
572
  # @rbs to: Symbol
570
- # @rbs return: I32|I64|F32|F64
573
+ # @rbs return: wasmValue
571
574
  def trunc_u(to:)
572
575
  v = value.to_i
573
576
  if v < 0
@@ -586,33 +589,33 @@ module Wardite
586
589
  end
587
590
 
588
591
  # @rbs to: Symbol
589
- # @rbs return: I32|I64|F32|F64
592
+ # @rbs return: wasmValue
590
593
  def convert_s(to:)
591
594
  raise EvalError, "unsupported operation"
592
595
  end
593
596
 
594
597
  # @rbs to: Symbol
595
- # @rbs return: I32|I64|F32|F64
598
+ # @rbs return: wasmValue
596
599
  def convert_u(to:)
597
600
  raise EvalError, "unsupported operation"
598
601
  end
599
602
 
600
603
  # @todo no loss of digits...
601
604
  # @rbs to: Symbol
602
- # @rbs return: I32|I64|F32|F64
605
+ # @rbs return: wasmValue
603
606
  def demote(to:)
604
607
  raise EvalError, "unsupported operation" if to != :f32
605
608
  F32(value)
606
609
  end
607
610
 
608
611
  # @rbs to: Symbol
609
- # @rbs return: I32|I64|F32|F64
612
+ # @rbs return: wasmValue
610
613
  def promote(to:)
611
614
  raise EvalError, "unsupported operation"
612
615
  end
613
616
 
614
617
  # @rbs to: Symbol
615
- # @rbs return: I32|I64|F32|F64
618
+ # @rbs return: wasmValue
616
619
  def reinterpret(to:)
617
620
  raise EvalError, "unsupported operation" if to != :i64
618
621
  v = [value].pack("d").unpack("L!")[0]
@@ -2,5 +2,5 @@
2
2
  # rbs_inline: enabled
3
3
 
4
4
  module Wardite
5
- VERSION = "0.2.2" #: String
5
+ VERSION = "0.3.0" #: String
6
6
  end