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 +4 -4
- data/examples/break.wat +13 -0
- data/examples/call_indirect.wat +15 -0
- data/examples/global.wat +13 -0
- data/examples/loop.wat +20 -0
- data/examples/start.wat +12 -0
- data/lib/wardite/instruction.rb +12 -6
- data/lib/wardite/load.rb +800 -0
- data/lib/wardite/value.rb +45 -42
- data/lib/wardite/version.rb +1 -1
- data/lib/wardite/wasi.rb +2 -2
- data/lib/wardite.rb +465 -605
- data/sig/generated/wardite/instruction.rbs +8 -5
- data/sig/generated/wardite/load.rbs +236 -0
- data/sig/generated/wardite/value.rbs +82 -80
- data/sig/generated/wardite/wasi.rbs +4 -4
- data/sig/generated/wardite.rbs +120 -181
- data/sig/wardite.rbs +1 -3
- metadata +9 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f92001daa1c57ae535fd1556fabee90a61dbe741e4e5b9f313c26e5d75d68b3e
|
4
|
+
data.tar.gz: 237df98e70875e1b6e69fbf0019cc298c3df26fa69cd4e62df8a04eaeff37522
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 94b5d318cebff3c8d87ea03fa0c5489ece3ef26ca7fcd6e6324febaf55a63f0a9ecb0a76d01b5adf5712737d8daf79ac55f5e2149ff8f85612acbaee1a2ace8c
|
7
|
+
data.tar.gz: c5991f43b9a62a7df87f23ec71350a77bf9493ccd083c6d0dba596c55976460e0c89625294048389a5fec1e35826bfbddd205718b45e04353b8e1627ccc4bb57
|
data/examples/break.wat
ADDED
@@ -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/global.wat
ADDED
@@ -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
|
+
)
|
data/examples/start.wat
ADDED
data/lib/wardite/instruction.rb
CHANGED
@@ -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[
|
56
|
+
attr_accessor :operand #: Array[operandItem]
|
54
57
|
|
55
58
|
# @rbs namespace: Symbol
|
56
59
|
# @rbs code: Symbol
|
57
|
-
# @rbs operand: Array[
|
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
|
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
|