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.
- 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
data/sig/generated/wardite.rbs
CHANGED
@@ -7,171 +7,6 @@ module Wardite
|
|
7
7
|
end
|
8
8
|
|
9
9
|
module Wardite
|
10
|
-
class Section
|
11
|
-
attr_accessor name: String
|
12
|
-
|
13
|
-
attr_accessor code: Integer
|
14
|
-
|
15
|
-
attr_accessor size: Integer
|
16
|
-
end
|
17
|
-
|
18
|
-
class TypeSection < Section
|
19
|
-
attr_accessor defined_types: Array[Array[Symbol]]
|
20
|
-
|
21
|
-
attr_accessor defined_results: Array[Array[Symbol]]
|
22
|
-
|
23
|
-
# @rbs return: void
|
24
|
-
def initialize: () -> void
|
25
|
-
end
|
26
|
-
|
27
|
-
class FunctionSection < Section
|
28
|
-
attr_accessor func_indices: Array[Integer]
|
29
|
-
|
30
|
-
# @rbs return: void
|
31
|
-
def initialize: () -> void
|
32
|
-
end
|
33
|
-
|
34
|
-
class MemorySection < Section
|
35
|
-
attr_accessor limits: Array[[ Integer, Integer | nil ]]
|
36
|
-
|
37
|
-
# @rbs return: void
|
38
|
-
def initialize: () -> void
|
39
|
-
end
|
40
|
-
|
41
|
-
class CodeSection < Section
|
42
|
-
class CodeBody
|
43
|
-
attr_accessor locals_count: Array[Integer]
|
44
|
-
|
45
|
-
attr_accessor locals_type: Array[Symbol]
|
46
|
-
|
47
|
-
attr_accessor body: Array[Op]
|
48
|
-
|
49
|
-
# @rbs &blk: (CodeBody) -> void
|
50
|
-
# @rbs return: void
|
51
|
-
def initialize: () { (CodeBody) -> void } -> void
|
52
|
-
end
|
53
|
-
|
54
|
-
attr_accessor func_codes: Array[CodeBody]
|
55
|
-
|
56
|
-
# @rbs return: void
|
57
|
-
def initialize: () -> void
|
58
|
-
end
|
59
|
-
|
60
|
-
class DataSection < Section
|
61
|
-
class Segment
|
62
|
-
attr_accessor flags: Integer
|
63
|
-
|
64
|
-
attr_accessor offset: Integer
|
65
|
-
|
66
|
-
attr_accessor data: String
|
67
|
-
|
68
|
-
# @rbs &blk: (Segment) -> void
|
69
|
-
# @rbs return: void
|
70
|
-
def initialize: () { (Segment) -> void } -> void
|
71
|
-
end
|
72
|
-
|
73
|
-
attr_accessor segments: Array[Segment]
|
74
|
-
|
75
|
-
# @rbs return: void
|
76
|
-
def initialize: () -> void
|
77
|
-
end
|
78
|
-
|
79
|
-
class ExportSection < Section
|
80
|
-
class ExportDesc
|
81
|
-
attr_accessor name: String
|
82
|
-
|
83
|
-
attr_accessor kind: Integer
|
84
|
-
|
85
|
-
attr_accessor func_index: Integer
|
86
|
-
end
|
87
|
-
|
88
|
-
attr_accessor exports: Hash[String, ExportDesc]
|
89
|
-
|
90
|
-
def initialize: () -> void
|
91
|
-
|
92
|
-
# @rbs &blk: (ExportDesc) -> void
|
93
|
-
def add_desc: () { (ExportDesc) -> void } -> untyped
|
94
|
-
end
|
95
|
-
|
96
|
-
class ImportSection < Section
|
97
|
-
class ImportDesc
|
98
|
-
attr_accessor module_name: String
|
99
|
-
|
100
|
-
attr_accessor name: String
|
101
|
-
|
102
|
-
attr_accessor kind: Integer
|
103
|
-
|
104
|
-
attr_accessor sig_index: Integer
|
105
|
-
end
|
106
|
-
|
107
|
-
attr_accessor imports: Array[ImportDesc]
|
108
|
-
|
109
|
-
def initialize: () -> void
|
110
|
-
|
111
|
-
# @rbs &blk: (ImportDesc) -> void
|
112
|
-
def add_desc: () { (ImportDesc) -> void } -> untyped
|
113
|
-
end
|
114
|
-
|
115
|
-
module BinaryLoader
|
116
|
-
extend Wardite::Leb128Helper
|
117
|
-
|
118
|
-
extend Wardite::ValueHelper
|
119
|
-
|
120
|
-
# @rbs buf: File|StringIO
|
121
|
-
# @rbs import_object: Hash[Symbol, Hash[Symbol, Proc]]
|
122
|
-
# @rbs enable_wasi: boolish
|
123
|
-
# @rbs return: Instance
|
124
|
-
def self.load_from_buffer: (File | StringIO buf, ?import_object: Hash[Symbol, Hash[Symbol, Proc]], ?enable_wasi: boolish) -> Instance
|
125
|
-
|
126
|
-
# @rbs return: Integer
|
127
|
-
def self.preamble: () -> Integer
|
128
|
-
|
129
|
-
# @rbs return: Array[Section]
|
130
|
-
def self.sections: () -> Array[Section]
|
131
|
-
|
132
|
-
# @rbs return: TypeSection
|
133
|
-
def self.type_section: () -> TypeSection
|
134
|
-
|
135
|
-
# @rbs return: ImportSection
|
136
|
-
def self.import_section: () -> ImportSection
|
137
|
-
|
138
|
-
# @rbs return: MemorySection
|
139
|
-
def self.memory_section: () -> MemorySection
|
140
|
-
|
141
|
-
# @rbs return: FunctionSection
|
142
|
-
def self.function_section: () -> FunctionSection
|
143
|
-
|
144
|
-
# @rbs return: CodeSection
|
145
|
-
def self.code_section: () -> CodeSection
|
146
|
-
|
147
|
-
# @rbs buf: StringIO
|
148
|
-
# @rbs return: Array[::Wardite::Op]
|
149
|
-
def self.code_body: (StringIO buf) -> Array[::Wardite::Op]
|
150
|
-
|
151
|
-
# @rbs return: DataSection
|
152
|
-
def self.data_section: () -> DataSection
|
153
|
-
|
154
|
-
# @rbs sbuf: StringIO
|
155
|
-
# @rbs return: String
|
156
|
-
def self.fetch_insn_while_end: (StringIO sbuf) -> String
|
157
|
-
|
158
|
-
# @rbs ops: Array[Op]
|
159
|
-
# @rbs return: Integer
|
160
|
-
def self.decode_expr: (Array[Op] ops) -> Integer
|
161
|
-
|
162
|
-
# @rbs return: ExportSection
|
163
|
-
def self.export_section: () -> ExportSection
|
164
|
-
|
165
|
-
# @rbs code: Integer
|
166
|
-
# @rbs return: nil
|
167
|
-
def self.unimplemented_skip_section: (Integer code) -> nil
|
168
|
-
|
169
|
-
# @rbs sbuf: StringIO
|
170
|
-
# @rbs n: Integer
|
171
|
-
# @rbs return: String
|
172
|
-
def self.assert_read: (StringIO sbuf, Integer n) -> String
|
173
|
-
end
|
174
|
-
|
175
10
|
class Instance
|
176
11
|
attr_accessor version: Integer
|
177
12
|
|
@@ -179,15 +14,17 @@ module Wardite
|
|
179
14
|
|
180
15
|
attr_accessor runtime: Runtime
|
181
16
|
|
17
|
+
attr_accessor types: Array[Type]
|
18
|
+
|
182
19
|
attr_accessor store: Store
|
183
20
|
|
184
21
|
attr_accessor exports: Exports
|
185
22
|
|
186
|
-
attr_reader import_object: Hash[Symbol, Hash[Symbol,
|
23
|
+
attr_reader import_object: Hash[Symbol, Hash[Symbol, wasmCallable]]
|
187
24
|
|
188
|
-
# @rbs import_object: Hash[Symbol, Hash[Symbol,
|
25
|
+
# @rbs import_object: Hash[Symbol, Hash[Symbol, wasmCallable]]
|
189
26
|
# @rbs &blk: (Instance) -> void
|
190
|
-
def initialize: (Hash[Symbol, Hash[Symbol,
|
27
|
+
def initialize: (Hash[Symbol, Hash[Symbol, wasmCallable]] import_object) { (Instance) -> void } -> untyped
|
191
28
|
|
192
29
|
# @rbs return: ImportSection
|
193
30
|
def import_section: () -> ImportSection
|
@@ -198,12 +35,24 @@ module Wardite
|
|
198
35
|
# @rbs return: MemorySection|nil
|
199
36
|
def memory_section: () -> (MemorySection | nil)
|
200
37
|
|
38
|
+
# @rbs return: StartSection|nil
|
39
|
+
def start_section: () -> (StartSection | nil)
|
40
|
+
|
41
|
+
# @rbs return: GlobalSection|nil
|
42
|
+
def global_section: () -> (GlobalSection | nil)
|
43
|
+
|
201
44
|
# @rbs return: DataSection|nil
|
202
45
|
def data_section: () -> (DataSection | nil)
|
203
46
|
|
204
47
|
# @rbs return: FunctionSection|nil
|
205
48
|
def function_section: () -> (FunctionSection | nil)
|
206
49
|
|
50
|
+
# @rbs return: TableSection?
|
51
|
+
def table_section: () -> TableSection?
|
52
|
+
|
53
|
+
# @rbs return: ElemSection?
|
54
|
+
def elem_section: () -> ElemSection?
|
55
|
+
|
207
56
|
# @rbs return: CodeSection|nil
|
208
57
|
def code_section: () -> (CodeSection | nil)
|
209
58
|
|
@@ -215,7 +64,7 @@ module Wardite
|
|
215
64
|
include ValueHelper
|
216
65
|
|
217
66
|
# TODO: add types of class that the stack accomodates
|
218
|
-
attr_accessor stack: Array[
|
67
|
+
attr_accessor stack: Array[wasmValue]
|
219
68
|
|
220
69
|
attr_accessor call_stack: Array[Frame]
|
221
70
|
|
@@ -224,6 +73,9 @@ module Wardite
|
|
224
73
|
# @rbs inst: Instance
|
225
74
|
def initialize: (Instance inst) -> untyped
|
226
75
|
|
76
|
+
# @rbs return: void
|
77
|
+
def invoke_start_section: () -> void
|
78
|
+
|
227
79
|
# @rbs name: String|Symbol
|
228
80
|
# @rbs return: bool
|
229
81
|
def callable?: (String | Symbol name) -> bool
|
@@ -233,6 +85,10 @@ module Wardite
|
|
233
85
|
# @rbs return: Object|nil
|
234
86
|
def call: (String | Symbol name, Array[Object] args) -> (Object | nil)
|
235
87
|
|
88
|
+
# @rbs idx: Integer
|
89
|
+
# @rbs return: void
|
90
|
+
def call_by_index: (Integer idx) -> void
|
91
|
+
|
236
92
|
# @rbs wasm_function: WasmFunction
|
237
93
|
# @rbs return: void
|
238
94
|
def push_frame: (WasmFunction wasm_function) -> void
|
@@ -242,8 +98,8 @@ module Wardite
|
|
242
98
|
def invoke_internal: (WasmFunction wasm_function) -> (Object | nil)
|
243
99
|
|
244
100
|
# @rbs external_function: ExternalFunction
|
245
|
-
# @rbs return:
|
246
|
-
def invoke_external: (ExternalFunction external_function) -> (
|
101
|
+
# @rbs return: wasmValue|nil
|
102
|
+
def invoke_external: (ExternalFunction external_function) -> (wasmValue | nil)
|
247
103
|
|
248
104
|
# @rbs return: void
|
249
105
|
def execute!: () -> void
|
@@ -253,6 +109,17 @@ module Wardite
|
|
253
109
|
# @rbs return: void
|
254
110
|
def eval_insn: (Frame frame, Op insn) -> void
|
255
111
|
|
112
|
+
# @rbs ops: Array[Op]
|
113
|
+
# @rbs pc_start: Integer
|
114
|
+
# @rbs return: Integer
|
115
|
+
def fetch_ops_while_else_or_end: (Array[Op] ops, Integer pc_start) -> Integer
|
116
|
+
|
117
|
+
# @rbs labels: Array[Label]
|
118
|
+
# @rbs stack: Array[wasmValue]
|
119
|
+
# @rbs level: Integer
|
120
|
+
# @rbs return: Integer
|
121
|
+
def do_branch: (Array[Label] labels, Array[wasmValue] stack, Integer level) -> Integer
|
122
|
+
|
256
123
|
# @rbs ops: Array[Op]
|
257
124
|
# @rbs pc_start: Integer
|
258
125
|
# @rbs return: Integer
|
@@ -265,8 +132,8 @@ module Wardite
|
|
265
132
|
def stack_unwind: (Integer sp, Integer arity) -> void
|
266
133
|
|
267
134
|
# @rbs finish: Integer
|
268
|
-
# @rbs return: Array[
|
269
|
-
def drained_stack: (Integer finish) -> Array[
|
135
|
+
# @rbs return: Array[wasmValue]
|
136
|
+
def drained_stack: (Integer finish) -> Array[wasmValue]
|
270
137
|
|
271
138
|
# @rbs name: Symbol
|
272
139
|
# @rbs args: Array[Object]
|
@@ -278,6 +145,17 @@ module Wardite
|
|
278
145
|
def respond_to?: (String | Symbol name) -> bool
|
279
146
|
end
|
280
147
|
|
148
|
+
class Type
|
149
|
+
attr_accessor callsig: Array[Symbol]
|
150
|
+
|
151
|
+
attr_accessor retsig: Array[Symbol]
|
152
|
+
|
153
|
+
# @rbs callsig: Array[Symbol]
|
154
|
+
# @rbs retsig: Array[Symbol]
|
155
|
+
# @rbs returb: void
|
156
|
+
def initialize: (Array[Symbol] callsig, Array[Symbol] retsig) -> untyped
|
157
|
+
end
|
158
|
+
|
281
159
|
class Frame
|
282
160
|
attr_accessor pc: Integer
|
283
161
|
|
@@ -289,15 +167,15 @@ module Wardite
|
|
289
167
|
|
290
168
|
attr_accessor labels: Array[Label]
|
291
169
|
|
292
|
-
attr_accessor locals: Array[
|
170
|
+
attr_accessor locals: Array[wasmValue]
|
293
171
|
|
294
172
|
# @rbs pc: Integer
|
295
173
|
# @rbs sp: Integer
|
296
174
|
# @rbs body: Array[Op]
|
297
175
|
# @rbs arity: Integer
|
298
|
-
# @rbs locals: Array[
|
176
|
+
# @rbs locals: Array[wasmValue]
|
299
177
|
# @rbs returb: void
|
300
|
-
def initialize: (Integer pc, Integer sp, Array[Op] body, Integer arity, Array[
|
178
|
+
def initialize: (Integer pc, Integer sp, Array[Op] body, Integer arity, Array[wasmValue] locals) -> untyped
|
301
179
|
end
|
302
180
|
|
303
181
|
class Label
|
@@ -309,12 +187,15 @@ module Wardite
|
|
309
187
|
|
310
188
|
attr_accessor arity: Integer
|
311
189
|
|
190
|
+
attr_accessor start: Integer | nil
|
191
|
+
|
312
192
|
# @rbs kind: (:if|:loop|:block)
|
313
193
|
# @rbs pc: Integer
|
314
194
|
# @rbs sp: Integer
|
315
195
|
# @rbs arity: Integer
|
316
|
-
# @rbs
|
317
|
-
|
196
|
+
# @rbs start: Integer|nil
|
197
|
+
# @rbs return: void
|
198
|
+
def initialize: (:if | :loop | :block kind, Integer pc, Integer sp, Integer arity, ?Integer | nil start) -> void
|
318
199
|
end
|
319
200
|
|
320
201
|
class Store
|
@@ -322,6 +203,12 @@ module Wardite
|
|
322
203
|
|
323
204
|
attr_accessor memories: Array[Memory]
|
324
205
|
|
206
|
+
attr_accessor globals: Array[Global]
|
207
|
+
|
208
|
+
attr_accessor tables: Array[Table]
|
209
|
+
|
210
|
+
attr_accessor elements: Array[[ Symbol, Integer, Array[Integer] ]]
|
211
|
+
|
325
212
|
# @rbs inst: Instance
|
326
213
|
# @rbs return: void
|
327
214
|
def initialize: (Instance inst) -> void
|
@@ -349,6 +236,46 @@ module Wardite
|
|
349
236
|
def inspect: () -> untyped
|
350
237
|
end
|
351
238
|
|
239
|
+
class Table
|
240
|
+
attr_accessor type: Symbol
|
241
|
+
|
242
|
+
attr_accessor current: Integer
|
243
|
+
|
244
|
+
attr_accessor max: Integer | nil
|
245
|
+
|
246
|
+
attr_accessor refs: Array[WasmFunction | ExternalFunction | nil]
|
247
|
+
|
248
|
+
# @rbs type: Symbol
|
249
|
+
# @rbs init: Integer
|
250
|
+
# @rbs max: Integer|nil
|
251
|
+
# @rbs return: void
|
252
|
+
def initialize: (Symbol type, Integer init, Integer | nil max) -> void
|
253
|
+
|
254
|
+
# @rbs idx: Integer
|
255
|
+
# @rbs elem: WasmFunction|ExternalFunction|nil
|
256
|
+
# @rbs return: void
|
257
|
+
def set: (Integer idx, WasmFunction | ExternalFunction | nil elem) -> void
|
258
|
+
end
|
259
|
+
|
260
|
+
class Global
|
261
|
+
attr_accessor type: Symbol
|
262
|
+
|
263
|
+
attr_accessor mutable: bool
|
264
|
+
|
265
|
+
# TODO: unused in wasm 1.0 spec?
|
266
|
+
attr_accessor shared: bool
|
267
|
+
|
268
|
+
attr_accessor value: wasmValue
|
269
|
+
|
270
|
+
# @rbs &blk: (Global) -> void
|
271
|
+
# @rbs return: void
|
272
|
+
def initialize: () { (Global) -> void } -> void
|
273
|
+
|
274
|
+
alias mutable? mutable
|
275
|
+
|
276
|
+
alias shared? shared
|
277
|
+
end
|
278
|
+
|
352
279
|
class WasmData
|
353
280
|
attr_accessor memory_index: Integer
|
354
281
|
|
@@ -415,20 +342,32 @@ module Wardite
|
|
415
342
|
|
416
343
|
# @rbs return: Array[Integer]
|
417
344
|
def locals_count: () -> Array[Integer]
|
345
|
+
|
346
|
+
# @rbs override_type: Type?
|
347
|
+
# @rbs return: WasmFunction
|
348
|
+
def clone: (?override_type: Type?) -> WasmFunction
|
418
349
|
end
|
419
350
|
|
351
|
+
type wasmFuncReturn = Object | nil
|
352
|
+
|
353
|
+
type wasmCallable = ^(Store, Array[wasmValue]) -> wasmFuncReturn
|
354
|
+
|
420
355
|
class ExternalFunction
|
421
356
|
attr_accessor callsig: Array[Symbol]
|
422
357
|
|
423
358
|
attr_accessor retsig: Array[Symbol]
|
424
359
|
|
425
|
-
attr_accessor callable:
|
360
|
+
attr_accessor callable: wasmCallable
|
426
361
|
|
427
362
|
# @rbs callsig: Array[Symbol]
|
428
363
|
# @rbs retsig: Array[Symbol]
|
429
|
-
# @rbs callable:
|
364
|
+
# @rbs callable: wasmCallable
|
430
365
|
# @rbs return: void
|
431
|
-
def initialize: (Array[Symbol] callsig, Array[Symbol] retsig,
|
366
|
+
def initialize: (Array[Symbol] callsig, Array[Symbol] retsig, wasmCallable callable) -> void
|
367
|
+
|
368
|
+
# @rbs override_type: Type?
|
369
|
+
# @rbs return: ExternalFunction
|
370
|
+
def clone: (?override_type: Type?) -> ExternalFunction
|
432
371
|
end
|
433
372
|
|
434
373
|
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.3.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,15 +24,20 @@ 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
|
+
- examples/global.wat
|
31
34
|
- examples/helloworld.wat
|
32
35
|
- examples/i32_const.wat
|
33
36
|
- examples/i32_store.wat
|
34
37
|
- examples/local_set.wat
|
38
|
+
- examples/loop.wat
|
35
39
|
- examples/memory.wat
|
40
|
+
- examples/start.wat
|
36
41
|
- exe/wardite
|
37
42
|
- lib/wardite.rb
|
38
43
|
- lib/wardite/alu_f32.generated.rb
|
@@ -43,6 +48,7 @@ files:
|
|
43
48
|
- lib/wardite/convert.generated.rb
|
44
49
|
- lib/wardite/instruction.rb
|
45
50
|
- lib/wardite/leb128.rb
|
51
|
+
- lib/wardite/load.rb
|
46
52
|
- lib/wardite/value.rb
|
47
53
|
- lib/wardite/version.rb
|
48
54
|
- lib/wardite/wasi.rb
|
@@ -59,6 +65,7 @@ files:
|
|
59
65
|
- sig/generated/wardite/convert.generated.rbs
|
60
66
|
- sig/generated/wardite/instruction.rbs
|
61
67
|
- sig/generated/wardite/leb128.rbs
|
68
|
+
- sig/generated/wardite/load.rbs
|
62
69
|
- sig/generated/wardite/value.rbs
|
63
70
|
- sig/generated/wardite/version.rbs
|
64
71
|
- sig/generated/wardite/wasi.rbs
|