wardite 0.2.1 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: cefed459056cdf59c5c8823b1b4ef8ff53c84fd09a9f73883aaa291561ba4e00
4
- data.tar.gz: b4ac97c31de3cc655aaf68d9c2097d1cb73ff67a184fd0c365d99b36371f1f93
3
+ metadata.gz: f92001daa1c57ae535fd1556fabee90a61dbe741e4e5b9f313c26e5d75d68b3e
4
+ data.tar.gz: 237df98e70875e1b6e69fbf0019cc298c3df26fa69cd4e62df8a04eaeff37522
5
5
  SHA512:
6
- metadata.gz: b3987aab13095263b109e7c907bee2640c3b9d2a5777b1b81812f692508de160d7fdd9f28e8c19c25d53445905e3b7b65379e0443f36dd56232e5c61b7d054bc
7
- data.tar.gz: ca3e1e1b0390869ce69ddc880e574ff3fb6c75c7def7538ad628c121ea5c12e1c860dbadc960cbaba48841f6ab5be3f1eeb117e0822dd9488271eab0eb1745d9
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
+ )
@@ -0,0 +1,13 @@
1
+ (module ;; from https://developer.mozilla.org/en-US/docs/WebAssembly/Reference/Variables/Global_set
2
+ (global $var (mut i32) (i32.const 0))
3
+ (global $var2 (mut i32) (i32.const 40))
4
+ (func $main (result i32)
5
+ i32.const 10 ;; load a number onto the stack
6
+ global.set $var ;; set the $var
7
+
8
+ global.get $var ;; load $var onto the stack
9
+ global.get $var2
10
+ i32.add ;; 10 + 40
11
+ )
12
+ (export "test" (func $main))
13
+ )
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
@@ -82,7 +85,7 @@ module Wardite
82
85
  end
83
86
  end
84
87
 
85
- # @rbs chr: Symbol
88
+ # @rbs code: Symbol
86
89
  # @rbs return: Array[Symbol]
87
90
  def self.operand_of(code)
88
91
  case 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