wardite 0.2.2 → 0.4.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/Rakefile +6 -0
- data/examples/break.wat +13 -0
- data/examples/call_indirect.wat +15 -0
- data/examples/loop.wat +20 -0
- data/examples/memory_init.wat +18 -0
- data/examples/saturate.wat +8 -0
- data/examples/saturate_u.wat +9 -0
- data/examples/start.wat +12 -0
- data/lib/wardite/const.rb +13 -12
- data/lib/wardite/convert.generated.rb +104 -0
- data/lib/wardite/instruction.rb +67 -8
- data/lib/wardite/load.rb +216 -28
- data/lib/wardite/value.rb +247 -70
- data/lib/wardite/version.rb +1 -1
- data/lib/wardite/wasi.rb +2 -2
- data/lib/wardite.rb +471 -17
- data/scripts/gen_conv.rb +12 -2
- data/sig/generated/wardite/const.rbs +2 -0
- data/sig/generated/wardite/instruction.rbs +15 -3
- data/sig/generated/wardite/load.rbs +63 -7
- data/sig/generated/wardite/value.rbs +142 -82
- data/sig/generated/wardite/wasi.rbs +4 -4
- data/sig/generated/wardite.rbs +103 -17
- data/sig/wardite.rbs +1 -3
- metadata +9 -2
data/sig/generated/wardite.rbs
CHANGED
@@ -14,15 +14,20 @@ module Wardite
|
|
14
14
|
|
15
15
|
attr_accessor runtime: Runtime
|
16
16
|
|
17
|
+
attr_accessor types: Array[Type]
|
18
|
+
|
17
19
|
attr_accessor store: Store
|
18
20
|
|
19
21
|
attr_accessor exports: Exports
|
20
22
|
|
21
|
-
attr_reader import_object: Hash[Symbol, Hash[Symbol,
|
23
|
+
attr_reader import_object: Hash[Symbol, Hash[Symbol, wasmCallable]]
|
22
24
|
|
23
|
-
# @rbs import_object: Hash[Symbol, Hash[Symbol,
|
25
|
+
# @rbs import_object: Hash[Symbol, Hash[Symbol, wasmCallable]]
|
24
26
|
# @rbs &blk: (Instance) -> void
|
25
|
-
def initialize: (Hash[Symbol, Hash[Symbol,
|
27
|
+
def initialize: (Hash[Symbol, Hash[Symbol, wasmCallable]] import_object) { (Instance) -> void } -> untyped
|
28
|
+
|
29
|
+
# @rbs return: void
|
30
|
+
def check_data_count: () -> void
|
26
31
|
|
27
32
|
# @rbs return: ImportSection
|
28
33
|
def import_section: () -> ImportSection
|
@@ -33,15 +38,27 @@ module Wardite
|
|
33
38
|
# @rbs return: MemorySection|nil
|
34
39
|
def memory_section: () -> (MemorySection | nil)
|
35
40
|
|
41
|
+
# @rbs return: StartSection|nil
|
42
|
+
def start_section: () -> (StartSection | nil)
|
43
|
+
|
36
44
|
# @rbs return: GlobalSection|nil
|
37
45
|
def global_section: () -> (GlobalSection | nil)
|
38
46
|
|
39
47
|
# @rbs return: DataSection|nil
|
40
48
|
def data_section: () -> (DataSection | nil)
|
41
49
|
|
50
|
+
# @rbs return: DataCountSection|nil
|
51
|
+
def data_count_section: () -> (DataCountSection | nil)
|
52
|
+
|
42
53
|
# @rbs return: FunctionSection|nil
|
43
54
|
def function_section: () -> (FunctionSection | nil)
|
44
55
|
|
56
|
+
# @rbs return: TableSection?
|
57
|
+
def table_section: () -> TableSection?
|
58
|
+
|
59
|
+
# @rbs return: ElemSection?
|
60
|
+
def elem_section: () -> ElemSection?
|
61
|
+
|
45
62
|
# @rbs return: CodeSection|nil
|
46
63
|
def code_section: () -> (CodeSection | nil)
|
47
64
|
|
@@ -53,7 +70,7 @@ module Wardite
|
|
53
70
|
include ValueHelper
|
54
71
|
|
55
72
|
# TODO: add types of class that the stack accomodates
|
56
|
-
attr_accessor stack: Array[
|
73
|
+
attr_accessor stack: Array[wasmValue]
|
57
74
|
|
58
75
|
attr_accessor call_stack: Array[Frame]
|
59
76
|
|
@@ -62,6 +79,9 @@ module Wardite
|
|
62
79
|
# @rbs inst: Instance
|
63
80
|
def initialize: (Instance inst) -> untyped
|
64
81
|
|
82
|
+
# @rbs return: void
|
83
|
+
def invoke_start_section: () -> void
|
84
|
+
|
65
85
|
# @rbs name: String|Symbol
|
66
86
|
# @rbs return: bool
|
67
87
|
def callable?: (String | Symbol name) -> bool
|
@@ -71,6 +91,10 @@ module Wardite
|
|
71
91
|
# @rbs return: Object|nil
|
72
92
|
def call: (String | Symbol name, Array[Object] args) -> (Object | nil)
|
73
93
|
|
94
|
+
# @rbs idx: Integer
|
95
|
+
# @rbs return: void
|
96
|
+
def call_by_index: (Integer idx) -> void
|
97
|
+
|
74
98
|
# @rbs wasm_function: WasmFunction
|
75
99
|
# @rbs return: void
|
76
100
|
def push_frame: (WasmFunction wasm_function) -> void
|
@@ -80,8 +104,8 @@ module Wardite
|
|
80
104
|
def invoke_internal: (WasmFunction wasm_function) -> (Object | nil)
|
81
105
|
|
82
106
|
# @rbs external_function: ExternalFunction
|
83
|
-
# @rbs return:
|
84
|
-
def invoke_external: (ExternalFunction external_function) -> (
|
107
|
+
# @rbs return: wasmValue|nil
|
108
|
+
def invoke_external: (ExternalFunction external_function) -> (wasmValue | nil)
|
85
109
|
|
86
110
|
# @rbs return: void
|
87
111
|
def execute!: () -> void
|
@@ -91,6 +115,17 @@ module Wardite
|
|
91
115
|
# @rbs return: void
|
92
116
|
def eval_insn: (Frame frame, Op insn) -> void
|
93
117
|
|
118
|
+
# @rbs ops: Array[Op]
|
119
|
+
# @rbs pc_start: Integer
|
120
|
+
# @rbs return: Integer
|
121
|
+
def fetch_ops_while_else_or_end: (Array[Op] ops, Integer pc_start) -> Integer
|
122
|
+
|
123
|
+
# @rbs labels: Array[Label]
|
124
|
+
# @rbs stack: Array[wasmValue]
|
125
|
+
# @rbs level: Integer
|
126
|
+
# @rbs return: Integer
|
127
|
+
def do_branch: (Array[Label] labels, Array[wasmValue] stack, Integer level) -> Integer
|
128
|
+
|
94
129
|
# @rbs ops: Array[Op]
|
95
130
|
# @rbs pc_start: Integer
|
96
131
|
# @rbs return: Integer
|
@@ -103,8 +138,8 @@ module Wardite
|
|
103
138
|
def stack_unwind: (Integer sp, Integer arity) -> void
|
104
139
|
|
105
140
|
# @rbs finish: Integer
|
106
|
-
# @rbs return: Array[
|
107
|
-
def drained_stack: (Integer finish) -> Array[
|
141
|
+
# @rbs return: Array[wasmValue]
|
142
|
+
def drained_stack: (Integer finish) -> Array[wasmValue]
|
108
143
|
|
109
144
|
# @rbs name: Symbol
|
110
145
|
# @rbs args: Array[Object]
|
@@ -116,6 +151,17 @@ module Wardite
|
|
116
151
|
def respond_to?: (String | Symbol name) -> bool
|
117
152
|
end
|
118
153
|
|
154
|
+
class Type
|
155
|
+
attr_accessor callsig: Array[Symbol]
|
156
|
+
|
157
|
+
attr_accessor retsig: Array[Symbol]
|
158
|
+
|
159
|
+
# @rbs callsig: Array[Symbol]
|
160
|
+
# @rbs retsig: Array[Symbol]
|
161
|
+
# @rbs returb: void
|
162
|
+
def initialize: (Array[Symbol] callsig, Array[Symbol] retsig) -> untyped
|
163
|
+
end
|
164
|
+
|
119
165
|
class Frame
|
120
166
|
attr_accessor pc: Integer
|
121
167
|
|
@@ -127,15 +173,15 @@ module Wardite
|
|
127
173
|
|
128
174
|
attr_accessor labels: Array[Label]
|
129
175
|
|
130
|
-
attr_accessor locals: Array[
|
176
|
+
attr_accessor locals: Array[wasmValue]
|
131
177
|
|
132
178
|
# @rbs pc: Integer
|
133
179
|
# @rbs sp: Integer
|
134
180
|
# @rbs body: Array[Op]
|
135
181
|
# @rbs arity: Integer
|
136
|
-
# @rbs locals: Array[
|
182
|
+
# @rbs locals: Array[wasmValue]
|
137
183
|
# @rbs returb: void
|
138
|
-
def initialize: (Integer pc, Integer sp, Array[Op] body, Integer arity, Array[
|
184
|
+
def initialize: (Integer pc, Integer sp, Array[Op] body, Integer arity, Array[wasmValue] locals) -> untyped
|
139
185
|
end
|
140
186
|
|
141
187
|
class Label
|
@@ -147,12 +193,15 @@ module Wardite
|
|
147
193
|
|
148
194
|
attr_accessor arity: Integer
|
149
195
|
|
196
|
+
attr_accessor start: Integer | nil
|
197
|
+
|
150
198
|
# @rbs kind: (:if|:loop|:block)
|
151
199
|
# @rbs pc: Integer
|
152
200
|
# @rbs sp: Integer
|
153
201
|
# @rbs arity: Integer
|
154
|
-
# @rbs
|
155
|
-
|
202
|
+
# @rbs start: Integer|nil
|
203
|
+
# @rbs return: void
|
204
|
+
def initialize: (:if | :loop | :block kind, Integer pc, Integer sp, Integer arity, ?Integer | nil start) -> void
|
156
205
|
end
|
157
206
|
|
158
207
|
class Store
|
@@ -162,6 +211,10 @@ module Wardite
|
|
162
211
|
|
163
212
|
attr_accessor globals: Array[Global]
|
164
213
|
|
214
|
+
attr_accessor tables: Array[Table]
|
215
|
+
|
216
|
+
attr_accessor elements: Array[[ Symbol, Integer, Array[Integer] ]]
|
217
|
+
|
165
218
|
# @rbs inst: Instance
|
166
219
|
# @rbs return: void
|
167
220
|
def initialize: (Instance inst) -> void
|
@@ -189,6 +242,27 @@ module Wardite
|
|
189
242
|
def inspect: () -> untyped
|
190
243
|
end
|
191
244
|
|
245
|
+
class Table
|
246
|
+
attr_accessor type: Symbol
|
247
|
+
|
248
|
+
attr_accessor current: Integer
|
249
|
+
|
250
|
+
attr_accessor max: Integer | nil
|
251
|
+
|
252
|
+
attr_accessor refs: Array[WasmFunction | ExternalFunction | nil]
|
253
|
+
|
254
|
+
# @rbs type: Symbol
|
255
|
+
# @rbs init: Integer
|
256
|
+
# @rbs max: Integer|nil
|
257
|
+
# @rbs return: void
|
258
|
+
def initialize: (Symbol type, Integer init, Integer | nil max) -> void
|
259
|
+
|
260
|
+
# @rbs idx: Integer
|
261
|
+
# @rbs elem: WasmFunction|ExternalFunction|nil
|
262
|
+
# @rbs return: void
|
263
|
+
def set: (Integer idx, WasmFunction | ExternalFunction | nil elem) -> void
|
264
|
+
end
|
265
|
+
|
192
266
|
class Global
|
193
267
|
attr_accessor type: Symbol
|
194
268
|
|
@@ -197,7 +271,7 @@ module Wardite
|
|
197
271
|
# TODO: unused in wasm 1.0 spec?
|
198
272
|
attr_accessor shared: bool
|
199
273
|
|
200
|
-
attr_accessor value:
|
274
|
+
attr_accessor value: wasmValue
|
201
275
|
|
202
276
|
# @rbs &blk: (Global) -> void
|
203
277
|
# @rbs return: void
|
@@ -274,20 +348,32 @@ module Wardite
|
|
274
348
|
|
275
349
|
# @rbs return: Array[Integer]
|
276
350
|
def locals_count: () -> Array[Integer]
|
351
|
+
|
352
|
+
# @rbs override_type: Type?
|
353
|
+
# @rbs return: WasmFunction
|
354
|
+
def clone: (?override_type: Type?) -> WasmFunction
|
277
355
|
end
|
278
356
|
|
357
|
+
type wasmFuncReturn = Object | nil
|
358
|
+
|
359
|
+
type wasmCallable = ^(Store, Array[wasmValue]) -> wasmFuncReturn
|
360
|
+
|
279
361
|
class ExternalFunction
|
280
362
|
attr_accessor callsig: Array[Symbol]
|
281
363
|
|
282
364
|
attr_accessor retsig: Array[Symbol]
|
283
365
|
|
284
|
-
attr_accessor callable:
|
366
|
+
attr_accessor callable: wasmCallable
|
285
367
|
|
286
368
|
# @rbs callsig: Array[Symbol]
|
287
369
|
# @rbs retsig: Array[Symbol]
|
288
|
-
# @rbs callable:
|
370
|
+
# @rbs callable: wasmCallable
|
289
371
|
# @rbs return: void
|
290
|
-
def initialize: (Array[Symbol] callsig, Array[Symbol] retsig,
|
372
|
+
def initialize: (Array[Symbol] callsig, Array[Symbol] retsig, wasmCallable callable) -> void
|
373
|
+
|
374
|
+
# @rbs override_type: Type?
|
375
|
+
# @rbs return: ExternalFunction
|
376
|
+
def clone: (?override_type: Type?) -> ExternalFunction
|
291
377
|
end
|
292
378
|
|
293
379
|
class GenericError < StandardError
|
data/sig/wardite.rbs
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: wardite
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Uchio Kondo
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-11-
|
11
|
+
date: 2024-11-10 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: A pure-ruby webassembly runtime
|
14
14
|
email:
|
@@ -24,7 +24,9 @@ files:
|
|
24
24
|
- examples/.gitignore
|
25
25
|
- examples/add.wasm
|
26
26
|
- examples/add.wat
|
27
|
+
- examples/break.wat
|
27
28
|
- examples/call.wat
|
29
|
+
- examples/call_indirect.wat
|
28
30
|
- examples/consts.wat
|
29
31
|
- examples/fib.wat
|
30
32
|
- examples/fib2.wat
|
@@ -33,7 +35,12 @@ files:
|
|
33
35
|
- examples/i32_const.wat
|
34
36
|
- examples/i32_store.wat
|
35
37
|
- examples/local_set.wat
|
38
|
+
- examples/loop.wat
|
36
39
|
- examples/memory.wat
|
40
|
+
- examples/memory_init.wat
|
41
|
+
- examples/saturate.wat
|
42
|
+
- examples/saturate_u.wat
|
43
|
+
- examples/start.wat
|
37
44
|
- exe/wardite
|
38
45
|
- lib/wardite.rb
|
39
46
|
- lib/wardite/alu_f32.generated.rb
|