wardite 0.2.1 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,6 +1,8 @@
1
1
  # Generated from lib/wardite/instruction.rb with RBS::Inline
2
2
 
3
3
  module Wardite
4
+ type operandItem = Integer | Array[Integer] | Float | Block
5
+
4
6
  class Op
5
7
  # @see https://pengowray.github.io/wasm-ops/
6
8
  SYMS: Array[Symbol]
@@ -13,22 +15,23 @@ module Wardite
13
15
  attr_accessor code: Symbol
14
16
 
15
17
  # TODO: add types of potential operands
16
- attr_accessor operand: Array[Integer | Float | Block]
18
+ attr_accessor operand: Array[operandItem]
17
19
 
18
20
  # @rbs namespace: Symbol
19
21
  # @rbs code: Symbol
20
- # @rbs operand: Array[Integer|Float|Block]
21
- def initialize: (Symbol namespace, Symbol code, Array[Integer | Float | Block] operand) -> untyped
22
+ # @rbs operand: Array[operandItem]
23
+ def initialize: (Symbol namespace, Symbol code, Array[operandItem] operand) -> untyped
22
24
 
23
25
  # @rbs chr: String
24
26
  # @rbs return: [Symbol, Symbol]
25
27
  def self.to_sym: (String chr) -> [ Symbol, Symbol ]
26
28
 
27
- # @rbs chr: Symbol
29
+ # @rbs code: Symbol
28
30
  # @rbs return: Array[Symbol]
29
- def self.operand_of: (untyped code) -> Array[Symbol]
31
+ def self.operand_of: (Symbol code) -> Array[Symbol]
30
32
 
31
33
  # @see https://www.w3.org/TR/wasm-core-1/#value-types%E2%91%A2
34
+ # We use this for reftype conversion. https://webassembly.github.io/spec/core/binary/types.html#binary-reftype
32
35
  # @rbs code: Integer
33
36
  # @rbs return: Symbol
34
37
  def self.i2type: (Integer code) -> Symbol
@@ -0,0 +1,236 @@
1
+ # Generated from lib/wardite/load.rb with RBS::Inline
2
+
3
+ # rbs_inline: enabled
4
+ module Wardite
5
+ class Section
6
+ attr_accessor name: String
7
+
8
+ attr_accessor code: Integer
9
+
10
+ attr_accessor size: Integer
11
+ end
12
+
13
+ class TypeSection < Section
14
+ attr_accessor defined_types: Array[Array[Symbol]]
15
+
16
+ attr_accessor defined_results: Array[Array[Symbol]]
17
+
18
+ # @rbs return: void
19
+ def initialize: () -> void
20
+ end
21
+
22
+ class FunctionSection < Section
23
+ attr_accessor func_indices: Array[Integer]
24
+
25
+ # @rbs return: void
26
+ def initialize: () -> void
27
+ end
28
+
29
+ class TableSection < Section
30
+ attr_accessor table_types: Array[Symbol]
31
+
32
+ attr_accessor table_limits: Array[[ Integer, Integer? ]]
33
+
34
+ # @rbs return: void
35
+ def initialize: () -> void
36
+ end
37
+
38
+ class MemorySection < Section
39
+ attr_accessor limits: Array[[ Integer, Integer? ]]
40
+
41
+ # @rbs return: void
42
+ def initialize: () -> void
43
+ end
44
+
45
+ class GlobalSection < Section
46
+ class Global
47
+ attr_accessor type: Symbol
48
+
49
+ attr_accessor mutable: bool
50
+
51
+ # TODO: unused in wasm 1.0 spec?
52
+ attr_accessor shared: bool
53
+
54
+ attr_accessor value: wasmValue
55
+
56
+ # @rbs &blk: (Global) -> void
57
+ # @rbs return: void
58
+ def initialize: () { (Global) -> void } -> void
59
+ end
60
+
61
+ attr_accessor globals: Array[Global]
62
+
63
+ # @rbs return: void
64
+ def initialize: () -> void
65
+ end
66
+
67
+ class StartSection < Section
68
+ attr_accessor func_index: Integer
69
+
70
+ # @rbs return: void
71
+ def initialize: () -> void
72
+ end
73
+
74
+ class ElemSection < Section
75
+ attr_accessor table_indices: Array[Integer]
76
+
77
+ attr_accessor table_offsets: Array[Integer]
78
+
79
+ attr_accessor element_indices: Array[Array[Integer]]
80
+
81
+ # @rbs return: void
82
+ def initialize: () -> void
83
+ end
84
+
85
+ class CodeSection < Section
86
+ class CodeBody
87
+ attr_accessor locals_count: Array[Integer]
88
+
89
+ attr_accessor locals_type: Array[Symbol]
90
+
91
+ attr_accessor body: Array[Op]
92
+
93
+ # @rbs &blk: (CodeBody) -> void
94
+ # @rbs return: void
95
+ def initialize: () { (CodeBody) -> void } -> void
96
+ end
97
+
98
+ attr_accessor func_codes: Array[CodeBody]
99
+
100
+ # @rbs return: void
101
+ def initialize: () -> void
102
+ end
103
+
104
+ class DataSection < Section
105
+ class Segment
106
+ attr_accessor flags: Integer
107
+
108
+ attr_accessor offset: Integer
109
+
110
+ attr_accessor data: String
111
+
112
+ # @rbs &blk: (Segment) -> void
113
+ # @rbs return: void
114
+ def initialize: () { (Segment) -> void } -> void
115
+ end
116
+
117
+ attr_accessor segments: Array[Segment]
118
+
119
+ # @rbs return: void
120
+ def initialize: () -> void
121
+ end
122
+
123
+ class ExportSection < Section
124
+ class ExportDesc
125
+ attr_accessor name: String
126
+
127
+ attr_accessor kind: Integer
128
+
129
+ attr_accessor func_index: Integer
130
+ end
131
+
132
+ attr_accessor exports: Hash[String, ExportDesc]
133
+
134
+ def initialize: () -> void
135
+
136
+ # @rbs &blk: (ExportDesc) -> void
137
+ def add_desc: () { (ExportDesc) -> void } -> untyped
138
+ end
139
+
140
+ class ImportSection < Section
141
+ class ImportDesc
142
+ attr_accessor module_name: String
143
+
144
+ attr_accessor name: String
145
+
146
+ attr_accessor kind: Integer
147
+
148
+ attr_accessor sig_index: Integer
149
+ end
150
+
151
+ attr_accessor imports: Array[ImportDesc]
152
+
153
+ def initialize: () -> void
154
+
155
+ # @rbs &blk: (ImportDesc) -> void
156
+ def add_desc: () { (ImportDesc) -> void } -> untyped
157
+ end
158
+
159
+ module BinaryLoader
160
+ extend Wardite::Leb128Helper
161
+
162
+ extend Wardite::ValueHelper
163
+
164
+ self.@buf: File | StringIO
165
+
166
+ # @rbs buf: File|StringIO
167
+ # @rbs import_object: Hash[Symbol, Hash[Symbol, wasmCallable]]
168
+ # @rbs enable_wasi: boolish
169
+ # @rbs return: Instance
170
+ def self.load_from_buffer: (File | StringIO buf, ?import_object: Hash[Symbol, Hash[Symbol, wasmCallable]], ?enable_wasi: boolish) -> Instance
171
+
172
+ # @rbs return: Integer
173
+ def self.preamble: () -> Integer
174
+
175
+ # @rbs return: Array[Section]
176
+ def self.sections: () -> Array[Section]
177
+
178
+ # @rbs return: TypeSection
179
+ def self.type_section: () -> TypeSection
180
+
181
+ # @rbs return: ImportSection
182
+ def self.import_section: () -> ImportSection
183
+
184
+ # @rbs return: MemorySection
185
+ def self.memory_section: () -> MemorySection
186
+
187
+ # @rbs return: StartSection
188
+ def self.start_section: () -> StartSection
189
+
190
+ # @rbs return: ElemSection
191
+ def self.elem_section: () -> ElemSection
192
+
193
+ # @rbs return: GlobalSection
194
+ def self.global_section: () -> GlobalSection
195
+
196
+ # @rbs return: FunctionSection
197
+ def self.function_section: () -> FunctionSection
198
+
199
+ # @rbs return: TableSection
200
+ def self.table_section: () -> TableSection
201
+
202
+ # @rbs return: CodeSection
203
+ def self.code_section: () -> CodeSection
204
+
205
+ # @rbs buf: StringIO
206
+ # @rbs return: Array[::Wardite::Op]
207
+ def self.code_body: (StringIO buf) -> Array[::Wardite::Op]
208
+
209
+ # @rbs return: DataSection
210
+ def self.data_section: () -> DataSection
211
+
212
+ # @rbs sbuf: StringIO
213
+ # @rbs return: String
214
+ def self.fetch_insn_while_end: (StringIO sbuf) -> String
215
+
216
+ # @rbs ops: Array[Op]
217
+ # @rbs return: Integer
218
+ def self.decode_expr: (Array[Op] ops) -> Integer
219
+
220
+ # @rbs ops: Array[Op]
221
+ # @rbs return: wasmValue
222
+ def self.decode_global_expr: (Array[Op] ops) -> wasmValue
223
+
224
+ # @rbs return: ExportSection
225
+ def self.export_section: () -> ExportSection
226
+
227
+ # @rbs code: Integer
228
+ # @rbs return: nil
229
+ def self.unimplemented_skip_section: (Integer code) -> nil
230
+
231
+ # @rbs sbuf: StringIO
232
+ # @rbs n: Integer
233
+ # @rbs return: String
234
+ def self.assert_read: (StringIO sbuf, Integer n) -> String
235
+ end
236
+ end
@@ -1,6 +1,8 @@
1
1
  # Generated from lib/wardite/value.rb with RBS::Inline
2
2
 
3
3
  module Wardite
4
+ type wasmValue = I32 | I64 | F32 | F64
5
+
4
6
  module ValueHelper
5
7
  # @rbs value: Integer
6
8
  # @rbs return: I32
@@ -59,44 +61,44 @@ module Wardite
59
61
  def packed: (?size: Integer | nil) -> String
60
62
 
61
63
  # @rbs to: Symbol
62
- # @rbs return: I32|I64|F32|F64
63
- def wrap: (to: Symbol) -> (I32 | I64 | F32 | F64)
64
+ # @rbs return: wasmValue
65
+ def wrap: (to: Symbol) -> wasmValue
64
66
 
65
67
  # @rbs to: Symbol
66
- # @rbs return: I32|I64|F32|F64
67
- def extend_s: (to: Symbol) -> (I32 | I64 | F32 | F64)
68
+ # @rbs return: wasmValue
69
+ def extend_s: (to: Symbol) -> wasmValue
68
70
 
69
71
  # @rbs to: Symbol
70
- # @rbs return: I32|I64|F32|F64
71
- def extend_u: (to: Symbol) -> (I32 | I64 | F32 | F64)
72
+ # @rbs return: wasmValue
73
+ def extend_u: (to: Symbol) -> wasmValue
72
74
 
73
75
  # @rbs to: Symbol
74
- # @rbs return: I32|I64|F32|F64
75
- def trunc_s: (to: Symbol) -> (I32 | I64 | F32 | F64)
76
+ # @rbs return: wasmValue
77
+ def trunc_s: (to: Symbol) -> wasmValue
76
78
 
77
79
  # @rbs to: Symbol
78
- # @rbs return: I32|I64|F32|F64
79
- def trunc_u: (to: Symbol) -> (I32 | I64 | F32 | F64)
80
+ # @rbs return: wasmValue
81
+ def trunc_u: (to: Symbol) -> wasmValue
80
82
 
81
83
  # @rbs to: Symbol
82
- # @rbs return: I32|I64|F32|F64
83
- def convert_s: (to: Symbol) -> (I32 | I64 | F32 | F64)
84
+ # @rbs return: wasmValue
85
+ def convert_s: (to: Symbol) -> wasmValue
84
86
 
85
87
  # @rbs to: Symbol
86
- # @rbs return: I32|I64|F32|F64
87
- def convert_u: (to: Symbol) -> (I32 | I64 | F32 | F64)
88
+ # @rbs return: wasmValue
89
+ def convert_u: (to: Symbol) -> wasmValue
88
90
 
89
91
  # @rbs to: Symbol
90
- # @rbs return: I32|I64|F32|F64
91
- def demote: (to: Symbol) -> (I32 | I64 | F32 | F64)
92
+ # @rbs return: wasmValue
93
+ def demote: (to: Symbol) -> wasmValue
92
94
 
93
95
  # @rbs to: Symbol
94
- # @rbs return: I32|I64|F32|F64
95
- def promote: (to: Symbol) -> (I32 | I64 | F32 | F64)
96
+ # @rbs return: wasmValue
97
+ def promote: (to: Symbol) -> wasmValue
96
98
 
97
99
  # @rbs to: Symbol
98
- # @rbs return: I32|I64|F32|F64
99
- def reinterpret: (to: Symbol) -> (I32 | I64 | F32 | F64)
100
+ # @rbs return: wasmValue
101
+ def reinterpret: (to: Symbol) -> wasmValue
100
102
 
101
103
  # I32#inspect shows signed value for convinience
102
104
  def inspect: () -> untyped
@@ -127,44 +129,44 @@ module Wardite
127
129
  def packed: (?size: Integer | nil) -> String
128
130
 
129
131
  # @rbs to: Symbol
130
- # @rbs return: I32|I64|F32|F64
131
- def wrap: (to: Symbol) -> (I32 | I64 | F32 | F64)
132
+ # @rbs return: wasmValue
133
+ def wrap: (to: Symbol) -> wasmValue
132
134
 
133
135
  # @rbs to: Symbol
134
- # @rbs return: I32|I64|F32|F64
135
- def extend_s: (to: Symbol) -> (I32 | I64 | F32 | F64)
136
+ # @rbs return: wasmValue
137
+ def extend_s: (to: Symbol) -> wasmValue
136
138
 
137
139
  # @rbs to: Symbol
138
- # @rbs return: I32|I64|F32|F64
139
- def extend_u: (to: Symbol) -> (I32 | I64 | F32 | F64)
140
+ # @rbs return: wasmValue
141
+ def extend_u: (to: Symbol) -> wasmValue
140
142
 
141
143
  # @rbs to: Symbol
142
- # @rbs return: I32|I64|F32|F64
143
- def trunc_s: (to: Symbol) -> (I32 | I64 | F32 | F64)
144
+ # @rbs return: wasmValue
145
+ def trunc_s: (to: Symbol) -> wasmValue
144
146
 
145
147
  # @rbs to: Symbol
146
- # @rbs return: I32|I64|F32|F64
147
- def trunc_u: (to: Symbol) -> (I32 | I64 | F32 | F64)
148
+ # @rbs return: wasmValue
149
+ def trunc_u: (to: Symbol) -> wasmValue
148
150
 
149
151
  # @rbs to: Symbol
150
- # @rbs return: I32|I64|F32|F64
151
- def convert_s: (to: Symbol) -> (I32 | I64 | F32 | F64)
152
+ # @rbs return: wasmValue
153
+ def convert_s: (to: Symbol) -> wasmValue
152
154
 
153
155
  # @rbs to: Symbol
154
- # @rbs return: I32|I64|F32|F64
155
- def convert_u: (to: Symbol) -> (I32 | I64 | F32 | F64)
156
+ # @rbs return: wasmValue
157
+ def convert_u: (to: Symbol) -> wasmValue
156
158
 
157
159
  # @rbs to: Symbol
158
- # @rbs return: I32|I64|F32|F64
159
- def demote: (to: Symbol) -> (I32 | I64 | F32 | F64)
160
+ # @rbs return: wasmValue
161
+ def demote: (to: Symbol) -> wasmValue
160
162
 
161
163
  # @rbs to: Symbol
162
- # @rbs return: I32|I64|F32|F64
163
- def promote: (to: Symbol) -> (I32 | I64 | F32 | F64)
164
+ # @rbs return: wasmValue
165
+ def promote: (to: Symbol) -> wasmValue
164
166
 
165
167
  # @rbs to: Symbol
166
- # @rbs return: I32|I64|F32|F64
167
- def reinterpret: (to: Symbol) -> (I32 | I64 | F32 | F64)
168
+ # @rbs return: wasmValue
169
+ def reinterpret: (to: Symbol) -> wasmValue
168
170
 
169
171
  # I64#inspect shows signed value
170
172
  def inspect: () -> untyped
@@ -190,47 +192,47 @@ module Wardite
190
192
  def packed: (?size: Integer | nil) -> String
191
193
 
192
194
  # @rbs to: Symbol
193
- # @rbs return: I32|I64|F32|F64
194
- def wrap: (to: Symbol) -> (I32 | I64 | F32 | F64)
195
+ # @rbs return: wasmValue
196
+ def wrap: (to: Symbol) -> wasmValue
195
197
 
196
198
  # @rbs to: Symbol
197
- # @rbs return: I32|I64|F32|F64
198
- def extend_s: (to: Symbol) -> (I32 | I64 | F32 | F64)
199
+ # @rbs return: wasmValue
200
+ def extend_s: (to: Symbol) -> wasmValue
199
201
 
200
202
  # @rbs to: Symbol
201
- # @rbs return: I32|I64|F32|F64
202
- def extend_u: (to: Symbol) -> (I32 | I64 | F32 | F64)
203
+ # @rbs return: wasmValue
204
+ def extend_u: (to: Symbol) -> wasmValue
203
205
 
204
206
  # @todo need more testcase...
205
207
  # @see https://webassembly.github.io/spec/core/exec/numerics.html#xref-exec-numerics-op-trunc-s-mathrm-trunc-mathsf-s-m-n-z
206
208
  # @rbs to: Symbol
207
- # @rbs return: I32|I64|F32|F64
208
- def trunc_s: (to: Symbol) -> (I32 | I64 | F32 | F64)
209
+ # @rbs return: wasmValue
210
+ def trunc_s: (to: Symbol) -> wasmValue
209
211
 
210
212
  # @see https://webassembly.github.io/spec/core/exec/numerics.html#xref-exec-numerics-op-trunc-u-mathrm-trunc-mathsf-u-m-n-z
211
213
  # @rbs to: Symbol
212
- # @rbs return: I32|I64|F32|F64
213
- def trunc_u: (to: Symbol) -> (I32 | I64 | F32 | F64)
214
+ # @rbs return: wasmValue
215
+ def trunc_u: (to: Symbol) -> wasmValue
214
216
 
215
217
  # @rbs to: Symbol
216
- # @rbs return: I32|I64|F32|F64
217
- def convert_s: (to: Symbol) -> (I32 | I64 | F32 | F64)
218
+ # @rbs return: wasmValue
219
+ def convert_s: (to: Symbol) -> wasmValue
218
220
 
219
221
  # @rbs to: Symbol
220
- # @rbs return: I32|I64|F32|F64
221
- def convert_u: (to: Symbol) -> (I32 | I64 | F32 | F64)
222
+ # @rbs return: wasmValue
223
+ def convert_u: (to: Symbol) -> wasmValue
222
224
 
223
225
  # @rbs to: Symbol
224
- # @rbs return: I32|I64|F32|F64
225
- def demote: (to: Symbol) -> (I32 | I64 | F32 | F64)
226
+ # @rbs return: wasmValue
227
+ def demote: (to: Symbol) -> wasmValue
226
228
 
227
229
  # @rbs to: Symbol
228
- # @rbs return: I32|I64|F32|F64
229
- def promote: (to: Symbol) -> (I32 | I64 | F32 | F64)
230
+ # @rbs return: wasmValue
231
+ def promote: (to: Symbol) -> wasmValue
230
232
 
231
233
  # @rbs to: Symbol
232
- # @rbs return: I32|I64|F32|F64
233
- def reinterpret: (to: Symbol) -> (I32 | I64 | F32 | F64)
234
+ # @rbs return: wasmValue
235
+ def reinterpret: (to: Symbol) -> wasmValue
234
236
 
235
237
  def inspect: () -> untyped
236
238
  end
@@ -255,47 +257,47 @@ module Wardite
255
257
  def packed: (?size: Integer | nil) -> String
256
258
 
257
259
  # @rbs to: Symbol
258
- # @rbs return: I32|I64|F32|F64
259
- def wrap: (to: Symbol) -> (I32 | I64 | F32 | F64)
260
+ # @rbs return: wasmValue
261
+ def wrap: (to: Symbol) -> wasmValue
260
262
 
261
263
  # @rbs to: Symbol
262
- # @rbs return: I32|I64|F32|F64
263
- def extend_s: (to: Symbol) -> (I32 | I64 | F32 | F64)
264
+ # @rbs return: wasmValue
265
+ def extend_s: (to: Symbol) -> wasmValue
264
266
 
265
267
  # @rbs to: Symbol
266
- # @rbs return: I32|I64|F32|F64
267
- def extend_u: (to: Symbol) -> (I32 | I64 | F32 | F64)
268
+ # @rbs return: wasmValue
269
+ def extend_u: (to: Symbol) -> wasmValue
268
270
 
269
271
  # @see the same as F32
270
272
  # @rbs to: Symbol
271
- # @rbs return: I32|I64|F32|F64
272
- def trunc_s: (to: Symbol) -> (I32 | I64 | F32 | F64)
273
+ # @rbs return: wasmValue
274
+ def trunc_s: (to: Symbol) -> wasmValue
273
275
 
274
276
  # @see the same as F32
275
277
  # @rbs to: Symbol
276
- # @rbs return: I32|I64|F32|F64
277
- def trunc_u: (to: Symbol) -> (I32 | I64 | F32 | F64)
278
+ # @rbs return: wasmValue
279
+ def trunc_u: (to: Symbol) -> wasmValue
278
280
 
279
281
  # @rbs to: Symbol
280
- # @rbs return: I32|I64|F32|F64
281
- def convert_s: (to: Symbol) -> (I32 | I64 | F32 | F64)
282
+ # @rbs return: wasmValue
283
+ def convert_s: (to: Symbol) -> wasmValue
282
284
 
283
285
  # @rbs to: Symbol
284
- # @rbs return: I32|I64|F32|F64
285
- def convert_u: (to: Symbol) -> (I32 | I64 | F32 | F64)
286
+ # @rbs return: wasmValue
287
+ def convert_u: (to: Symbol) -> wasmValue
286
288
 
287
289
  # @todo no loss of digits...
288
290
  # @rbs to: Symbol
289
- # @rbs return: I32|I64|F32|F64
290
- def demote: (to: Symbol) -> (I32 | I64 | F32 | F64)
291
+ # @rbs return: wasmValue
292
+ def demote: (to: Symbol) -> wasmValue
291
293
 
292
294
  # @rbs to: Symbol
293
- # @rbs return: I32|I64|F32|F64
294
- def promote: (to: Symbol) -> (I32 | I64 | F32 | F64)
295
+ # @rbs return: wasmValue
296
+ def promote: (to: Symbol) -> wasmValue
295
297
 
296
298
  # @rbs to: Symbol
297
- # @rbs return: I32|I64|F32|F64
298
- def reinterpret: (to: Symbol) -> (I32 | I64 | F32 | F64)
299
+ # @rbs return: wasmValue
300
+ def reinterpret: (to: Symbol) -> wasmValue
299
301
 
300
302
  def inspect: () -> untyped
301
303
  end
@@ -10,12 +10,12 @@ module Wardite
10
10
  def initialize: () -> untyped
11
11
 
12
12
  # @rbs store: Store
13
- # @rbs args: Array[I32|I64|F32|F64]
13
+ # @rbs args: Array[wasmValue]
14
14
  # @rbs return: Object
15
- def fd_write: (Store store, Array[I32 | I64 | F32 | F64] args) -> Object
15
+ def fd_write: (Store store, Array[wasmValue] args) -> Object
16
16
 
17
- # @rbs return: Hash[Symbol, Proc]
18
- def to_module: () -> Hash[Symbol, Proc]
17
+ # @rbs return: Hash[Symbol, wasmCallable]
18
+ def to_module: () -> Hash[Symbol, wasmCallable]
19
19
 
20
20
  private
21
21