wardite 0.1.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.
@@ -0,0 +1,34 @@
1
+ # Generated from lib/wardite/const.rb with RBS::Inline
2
+
3
+ # rbs_inline: enabled
4
+ module Wardite
5
+ module Const
6
+ # Section Code
7
+ # @see https://www.w3.org/TR/wasm-core-1/#sections%E2%91%A0
8
+ SectionCustom: Integer
9
+
10
+ SectionType: Integer
11
+
12
+ SectionImport: Integer
13
+
14
+ SectionFunction: Integer
15
+
16
+ SectionTable: Integer
17
+
18
+ SectionMemory: Integer
19
+
20
+ SectionGlobal: Integer
21
+
22
+ SectionExport: Integer
23
+
24
+ SectionStart: Integer
25
+
26
+ SectionElement: Integer
27
+
28
+ SectionCode: Integer
29
+
30
+ SectionData: Integer
31
+ end
32
+
33
+ include Const
34
+ end
@@ -0,0 +1,27 @@
1
+ # Generated from lib/wardite/instruction.rb with RBS::Inline
2
+
3
+ # rbs_inline: enabled
4
+ module Wardite
5
+ class Op
6
+ attr_accessor code: Symbol
7
+
8
+ attr_accessor operand: Array[Object]
9
+
10
+ # @rbs code: Symbol
11
+ # @rbs operand: Array[Object]
12
+ def initialize: (Symbol code, Array[Object] operand) -> untyped
13
+
14
+ # @rbs chr: String
15
+ # @rbs return: Symbol
16
+ def self.to_sym: (String chr) -> Symbol
17
+
18
+ # @rbs chr: Symbol
19
+ # @rbs return: Array[Symbol]
20
+ def self.operand_of: (untyped code) -> Array[Symbol]
21
+
22
+ # @see https://www.w3.org/TR/wasm-core-1/#value-types%E2%91%A2
23
+ # @rbs code: Integer
24
+ # @rbs return: Symbol
25
+ def self.i2type: (Integer code) -> Symbol
26
+ end
27
+ end
@@ -0,0 +1,14 @@
1
+ # Generated from lib/wardite/leb128.rb with RBS::Inline
2
+
3
+ # rbs_inline: enabled
4
+ module Wardite
5
+ module Leb128Helpers
6
+ # @rbs buf: File|StringIO
7
+ # @rbs return: Integer
8
+ def fetch_uleb128: (File | StringIO buf) -> Integer
9
+
10
+ # @rbs buf: File|StringIO
11
+ # @rbs return: Integer
12
+ def fetch_sleb128: (File | StringIO buf) -> Integer
13
+ end
14
+ end
@@ -0,0 +1,5 @@
1
+ # Generated from lib/wardite/version.rb with RBS::Inline
2
+
3
+ module Wardite
4
+ VERSION: String
5
+ end
@@ -0,0 +1,24 @@
1
+ # Generated from lib/wardite/wasi.rb with RBS::Inline
2
+
3
+ # rbs_inline: enabled
4
+ module Wardite
5
+ class WasiSnapshotPreview1
6
+ attr_accessor fd_table: Array[IO]
7
+
8
+ def initialize: () -> untyped
9
+
10
+ # @rbs store: Store
11
+ # @rbs args: Array[Object]
12
+ # @rbs return: Object
13
+ def fd_write: (Store store, Array[Object] args) -> Object
14
+
15
+ # @rbs return: Hash[Symbol, Proc]
16
+ def to_module: () -> Hash[Symbol, Proc]
17
+
18
+ private
19
+
20
+ # @rbs buf: String|nil
21
+ # @rbs return: Integer
22
+ def unpack_le_int: (String | nil buf) -> Integer
23
+ end
24
+ end
@@ -0,0 +1,384 @@
1
+ # Generated from lib/wardite.rb with RBS::Inline
2
+
3
+ module Wardite
4
+ class Section
5
+ attr_accessor name: String
6
+
7
+ attr_accessor code: Integer
8
+
9
+ attr_accessor size: Integer
10
+ end
11
+
12
+ class TypeSection < Section
13
+ attr_accessor defined_types: Array[Array[Symbol]]
14
+
15
+ attr_accessor defined_results: Array[Array[Symbol]]
16
+
17
+ # @rbs return: void
18
+ def initialize: () -> void
19
+ end
20
+
21
+ class FunctionSection < Section
22
+ attr_accessor func_indices: Array[Integer]
23
+
24
+ # @rbs return: void
25
+ def initialize: () -> void
26
+ end
27
+
28
+ class MemorySection < Section
29
+ attr_accessor limits: Array[[ Integer, Integer | nil ]]
30
+
31
+ # @rbs return: void
32
+ def initialize: () -> void
33
+ end
34
+
35
+ class CodeSection < Section
36
+ class CodeBody
37
+ attr_accessor locals_count: Array[Integer]
38
+
39
+ attr_accessor locals_type: Array[Symbol]
40
+
41
+ attr_accessor body: Array[Op]
42
+
43
+ # @rbs &blk: (CodeBody) -> void
44
+ # @rbs return: void
45
+ def initialize: () { (CodeBody) -> void } -> void
46
+ end
47
+
48
+ attr_accessor func_codes: Array[CodeBody]
49
+
50
+ # @rbs return: void
51
+ def initialize: () -> void
52
+ end
53
+
54
+ class DataSection < Section
55
+ class Segment
56
+ attr_accessor flags: Integer
57
+
58
+ attr_accessor offset: Integer
59
+
60
+ attr_accessor data: String
61
+
62
+ # @rbs &blk: (Segment) -> void
63
+ # @rbs return: void
64
+ def initialize: () { (Segment) -> void } -> void
65
+ end
66
+
67
+ attr_accessor segments: Array[Segment]
68
+
69
+ # @rbs return: void
70
+ def initialize: () -> void
71
+ end
72
+
73
+ class ExportSection < Section
74
+ class ExportDesc
75
+ attr_accessor name: String
76
+
77
+ attr_accessor kind: Integer
78
+
79
+ attr_accessor func_index: Integer
80
+ end
81
+
82
+ attr_accessor exports: Hash[String, ExportDesc]
83
+
84
+ def initialize: () -> void
85
+
86
+ # @rbs &blk: (ExportDesc) -> void
87
+ def add_desc: () { (ExportDesc) -> void } -> untyped
88
+ end
89
+
90
+ class ImportSection < Section
91
+ class ImportDesc
92
+ attr_accessor module_name: String
93
+
94
+ attr_accessor name: String
95
+
96
+ attr_accessor kind: Integer
97
+
98
+ attr_accessor sig_index: Integer
99
+ end
100
+
101
+ attr_accessor imports: Array[ImportDesc]
102
+
103
+ def initialize: () -> void
104
+
105
+ # @rbs &blk: (ImportDesc) -> void
106
+ def add_desc: () { (ImportDesc) -> void } -> untyped
107
+ end
108
+
109
+ module BinaryLoader
110
+ extend Wardite::Leb128Helpers
111
+
112
+ # @rbs buf: File|StringIO
113
+ # @rbs import_object: Hash[Symbol, Hash[Symbol, Proc]]
114
+ # @rbs enable_wasi: boolish
115
+ # @rbs return: Instance
116
+ def self.load_from_buffer: (File | StringIO buf, ?import_object: Hash[Symbol, Hash[Symbol, Proc]], ?enable_wasi: boolish) -> Instance
117
+
118
+ # @rbs return: Integer
119
+ def self.preamble: () -> Integer
120
+
121
+ # @rbs return: Array[Section]
122
+ def self.sections: () -> Array[Section]
123
+
124
+ # @rbs return: TypeSection
125
+ def self.type_section: () -> TypeSection
126
+
127
+ # @rbs return: ImportSection
128
+ def self.import_section: () -> ImportSection
129
+
130
+ # @rbs return: MemorySection
131
+ def self.memory_section: () -> MemorySection
132
+
133
+ # @rbs return: FunctionSection
134
+ def self.function_section: () -> FunctionSection
135
+
136
+ # @rbs return: CodeSection
137
+ def self.code_section: () -> CodeSection
138
+
139
+ # @rbs buf: StringIO
140
+ # @rbs return: Array[::Wardite::Op]
141
+ def self.code_body: (StringIO buf) -> Array[::Wardite::Op]
142
+
143
+ # @rbs return: DataSection
144
+ def self.data_section: () -> DataSection
145
+
146
+ # @rbs sbuf: StringIO
147
+ # @rbs return: String
148
+ def self.fetch_insn_while_end: (StringIO sbuf) -> String
149
+
150
+ # @rbs ops: Array[Op]
151
+ # @rbs return: Integer
152
+ def self.decode_expr: (Array[Op] ops) -> Integer
153
+
154
+ # @rbs return: ExportSection
155
+ def self.export_section: () -> ExportSection
156
+
157
+ # @rbs code: Integer
158
+ # @rbs return: nil
159
+ def self.unimplemented_skip_section: (Integer code) -> nil
160
+
161
+ # @rbs sbuf: StringIO
162
+ # @rbs n: Integer
163
+ # @rbs return: String
164
+ def self.assert_read: (StringIO sbuf, Integer n) -> String
165
+ end
166
+
167
+ class Instance
168
+ attr_accessor version: Integer
169
+
170
+ attr_accessor sections: Array[Section]
171
+
172
+ attr_accessor runtime: Runtime
173
+
174
+ attr_accessor store: Store
175
+
176
+ attr_accessor exports: Exports
177
+
178
+ attr_reader import_object: Hash[Symbol, Hash[Symbol, Proc]]
179
+
180
+ # @rbs import_object: Hash[Symbol, Hash[Symbol, Proc]]
181
+ # @rbs &blk: (Instance) -> void
182
+ def initialize: (Hash[Symbol, Hash[Symbol, Proc]] import_object) { (Instance) -> void } -> untyped
183
+
184
+ # @rbs return: ImportSection
185
+ def import_section: () -> ImportSection
186
+
187
+ # @rbs return: TypeSection|nil
188
+ def type_section: () -> (TypeSection | nil)
189
+
190
+ # @rbs return: MemorySection|nil
191
+ def memory_section: () -> (MemorySection | nil)
192
+
193
+ # @rbs return: DataSection|nil
194
+ def data_section: () -> (DataSection | nil)
195
+
196
+ # @rbs return: FunctionSection|nil
197
+ def function_section: () -> (FunctionSection | nil)
198
+
199
+ # @rbs return: CodeSection|nil
200
+ def code_section: () -> (CodeSection | nil)
201
+
202
+ # @rbs return: ExportSection
203
+ def export_section: () -> ExportSection
204
+ end
205
+
206
+ class Runtime
207
+ attr_accessor stack: Array[Object]
208
+
209
+ attr_accessor call_stack: Array[Frame]
210
+
211
+ attr_reader instance: Instance
212
+
213
+ # @rbs inst: Instance
214
+ def initialize: (Instance inst) -> untyped
215
+
216
+ # @rbs name: String|Symbol
217
+ # @rbs return: bool
218
+ def callable?: (String | Symbol name) -> bool
219
+
220
+ # @rbs name: String|Symbol
221
+ # @rbs args: Array[Object]
222
+ # @rbs return: Object|nil
223
+ def call: (String | Symbol name, Array[Object] args) -> (Object | nil)
224
+
225
+ # @rbs idx: Integer
226
+ # @rbs args: Array[Object]
227
+ # @rbs return: Object|nil
228
+ def call_index: (Integer idx, Array[Object] args) -> (Object | nil)
229
+
230
+ # @rbs wasm_function: WasmFunction
231
+ # @rbs return: void
232
+ def push_frame: (WasmFunction wasm_function) -> void
233
+
234
+ # @rbs wasm_function: WasmFunction
235
+ # @rbs return: Object|nil
236
+ def invoke_internal: (WasmFunction wasm_function) -> (Object | nil)
237
+
238
+ # @rbs external_function: ExternalFunction
239
+ # @rbs return: Object|nil
240
+ def invoke_external: (ExternalFunction external_function) -> (Object | nil)
241
+
242
+ # @rbs return: void
243
+ def execute!: () -> void
244
+
245
+ # @rbs frame: Frame
246
+ # @rbs insn: Op
247
+ # @rbs return: void
248
+ def eval_insn: (Frame frame, Op insn) -> void
249
+
250
+ # @rbs finish: Integer
251
+ # @rbs return: Array[Object]
252
+ def drained_stack: (Integer finish) -> Array[Object]
253
+
254
+ # @rbs name: Symbol
255
+ # @rbs args: Array[Object]
256
+ # @rbs return: untyped
257
+ def method_missing: (Symbol name, *untyped args) -> untyped
258
+
259
+ # @rbs name: String|Symbol
260
+ # @rbs return: bool
261
+ def respond_to?: (String | Symbol name) -> bool
262
+ end
263
+
264
+ class Frame
265
+ attr_accessor pc: Integer
266
+
267
+ attr_accessor sp: Integer
268
+
269
+ attr_accessor body: Array[Op]
270
+
271
+ attr_accessor arity: Integer
272
+
273
+ attr_accessor locals: Array[Object]
274
+
275
+ # @rbs pc: Integer
276
+ # @rbs sp: Integer
277
+ # @rbs body: Array[Op]
278
+ # @rbs arity: Integer
279
+ # @rbs locals: Array[Object]
280
+ # @rbs returb: void
281
+ def initialize: (Integer pc, Integer sp, Array[Op] body, Integer arity, Array[Object] locals) -> untyped
282
+ end
283
+
284
+ class Store
285
+ attr_accessor funcs: Array[WasmFunction | ExternalFunction]
286
+
287
+ attr_accessor memories: Array[Memory]
288
+
289
+ # @rbs inst: Instance
290
+ # @rbs return: void
291
+ def initialize: (Instance inst) -> void
292
+
293
+ # @rbs idx: Integer
294
+ def []: (Integer idx) -> untyped
295
+ end
296
+
297
+ class Memory
298
+ attr_accessor data: String
299
+
300
+ attr_accessor max: Integer | nil
301
+
302
+ # @rbs min: Integer
303
+ # @rbs max: Integer|nil
304
+ # @rbs return: void
305
+ def initialize: (Integer min, Integer | nil max) -> void
306
+
307
+ def inspect: () -> untyped
308
+ end
309
+
310
+ class WasmData
311
+ attr_accessor memory_index: Integer
312
+
313
+ attr_accessor offset: Integer
314
+
315
+ attr_accessor init: String
316
+
317
+ # @rbs &blk: (WasmData) -> void
318
+ # @rbs return: void
319
+ def initialize: () { (WasmData) -> void } -> void
320
+ end
321
+
322
+ class Exports
323
+ attr_accessor mappings: Hash[String, [ Integer, WasmFunction | ExternalFunction ]]
324
+
325
+ # @rbs export_section: ExportSection
326
+ # @rbs store: Store
327
+ # @rbs return: void
328
+ def initialize: (ExportSection export_section, Store store) -> void
329
+
330
+ # @rbs name: String
331
+ # @rbs return: [Integer, WasmFunction|ExternalFunction]
332
+ def []: (String name) -> [ Integer, WasmFunction | ExternalFunction ]
333
+ end
334
+
335
+ # TODO: common interface btw. WasmFunction and ExternalFunction?
336
+ class WasmFunction
337
+ attr_accessor callsig: Array[Symbol]
338
+
339
+ attr_accessor retsig: Array[Symbol]
340
+
341
+ attr_accessor code_body: CodeSection::CodeBody
342
+
343
+ # @rbs callsig: Array[Symbol]
344
+ # @rbs retsig: Array[Symbol]
345
+ # @rbs code_body: CodeSection::CodeBody
346
+ # @rbs return: void
347
+ def initialize: (Array[Symbol] callsig, Array[Symbol] retsig, CodeSection::CodeBody code_body) -> void
348
+
349
+ # @rbs return: Array[Op]
350
+ def body: () -> Array[Op]
351
+
352
+ # @rbs return: Array[Symbol]
353
+ def locals_type: () -> Array[Symbol]
354
+
355
+ # @rbs return: Array[Integer]
356
+ def locals_count: () -> Array[Integer]
357
+ end
358
+
359
+ class ExternalFunction
360
+ attr_accessor callsig: Array[Symbol]
361
+
362
+ attr_accessor retsig: Array[Symbol]
363
+
364
+ attr_accessor callable: Proc
365
+
366
+ # @rbs callsig: Array[Symbol]
367
+ # @rbs retsig: Array[Symbol]
368
+ # @rbs callable: Proc
369
+ # @rbs return: void
370
+ def initialize: (Array[Symbol] callsig, Array[Symbol] retsig, Proc callable) -> void
371
+ end
372
+
373
+ class GenericError < StandardError
374
+ end
375
+
376
+ class LoadError < StandardError
377
+ end
378
+
379
+ class ArgumentError < StandardError
380
+ end
381
+
382
+ class EvalError < StandardError
383
+ end
384
+ end
data/sig/wardite.rbs ADDED
@@ -0,0 +1,6 @@
1
+ module Wardite
2
+ # definitions that cannot cover by rbs-inline
3
+ module BinaryLoader
4
+ self.@buf: File|StringIO
5
+ end
6
+ end
metadata ADDED
@@ -0,0 +1,71 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: wardite
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Uchio Kondo
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2024-10-27 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: A pure-ruby webassembly runtime
14
+ email:
15
+ - udzura@udzura.jp
16
+ executables:
17
+ - wardite
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - README.md
22
+ - Rakefile
23
+ - Steepfile
24
+ - examples/.gitignore
25
+ - examples/add.wasm
26
+ - examples/add.wat
27
+ - examples/call.wat
28
+ - examples/helloworld.wat
29
+ - examples/i32_const.wat
30
+ - examples/i32_store.wat
31
+ - examples/local_set.wat
32
+ - examples/memory.wat
33
+ - exe/wardite
34
+ - lib/wardite.rb
35
+ - lib/wardite/const.rb
36
+ - lib/wardite/instruction.rb
37
+ - lib/wardite/leb128.rb
38
+ - lib/wardite/version.rb
39
+ - lib/wardite/wasi.rb
40
+ - sig/generated/wardite.rbs
41
+ - sig/generated/wardite/const.rbs
42
+ - sig/generated/wardite/instruction.rbs
43
+ - sig/generated/wardite/leb128.rbs
44
+ - sig/generated/wardite/version.rbs
45
+ - sig/generated/wardite/wasi.rbs
46
+ - sig/wardite.rbs
47
+ homepage: https://github.com/udzura/wardite
48
+ licenses: []
49
+ metadata:
50
+ homepage_uri: https://github.com/udzura/wardite
51
+ source_code_uri: https://github.com/udzura/wardite
52
+ post_install_message:
53
+ rdoc_options: []
54
+ require_paths:
55
+ - lib
56
+ required_ruby_version: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ version: 3.0.0
61
+ required_rubygems_version: !ruby/object:Gem::Requirement
62
+ requirements:
63
+ - - ">="
64
+ - !ruby/object:Gem::Version
65
+ version: '0'
66
+ requirements: []
67
+ rubygems_version: 3.5.11
68
+ signing_key:
69
+ specification_version: 4
70
+ summary: A pure-ruby webassembly runtime
71
+ test_files: []