wardite 0.2.1 → 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.
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.1" #: String
5
+ VERSION = "0.3.0" #: String
6
6
  end
data/lib/wardite/wasi.rb CHANGED
@@ -14,7 +14,7 @@ module Wardite
14
14
  end
15
15
 
16
16
  # @rbs store: Store
17
- # @rbs args: Array[I32|I64|F32|F64]
17
+ # @rbs args: Array[wasmValue]
18
18
  # @rbs return: Object
19
19
  def fd_write(store, args)
20
20
  iargs = args.map do |elm|
@@ -45,7 +45,7 @@ module Wardite
45
45
  0
46
46
  end
47
47
 
48
- # @rbs return: Hash[Symbol, Proc]
48
+ # @rbs return: Hash[Symbol, wasmCallable]
49
49
  def to_module
50
50
  {
51
51
  fd_write: lambda{|store, args| self.fd_write(store, args) },