wardite 0.8.1 → 0.9.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.
data/scripts/gen_alu.rb CHANGED
@@ -49,8 +49,8 @@ module GenAlu
49
49
  DEFS = { #: Hash[Symbol, String]
50
50
  load: <<~RUBY,
51
51
  when :${PREFIX}_load
52
- _align = insn.operand[0] # TODO: alignment support?
53
- offset = insn.operand[1]
52
+ _align = operand[0] # TODO: alignment support?
53
+ offset = operand[1]
54
54
  raise EvalError, "[BUG] invalid type of operand" if !offset.is_a?(Integer)
55
55
 
56
56
  addr = runtime.stack.pop
@@ -70,8 +70,8 @@ module GenAlu
70
70
 
71
71
  load8_s: <<~RUBY,
72
72
  when :${PREFIX}_load8_s
73
- _align = insn.operand[0] # TODO: alignment support?
74
- offset = insn.operand[1]
73
+ _align = operand[0] # TODO: alignment support?
74
+ offset = operand[1]
75
75
  raise EvalError, "[BUG] invalid type of operand" if !offset.is_a?(Integer)
76
76
 
77
77
  addr = runtime.stack.pop
@@ -91,8 +91,8 @@ module GenAlu
91
91
 
92
92
  load8_u: <<~RUBY,
93
93
  when :${PREFIX}_load8_u
94
- _align = insn.operand[0] # TODO: alignment support?
95
- offset = insn.operand[1]
94
+ _align = operand[0] # TODO: alignment support?
95
+ offset = operand[1]
96
96
  raise EvalError, "[BUG] invalid type of operand" if !offset.is_a?(Integer)
97
97
 
98
98
  addr = runtime.stack.pop
@@ -112,8 +112,8 @@ module GenAlu
112
112
 
113
113
  load16_s: <<~RUBY,
114
114
  when :${PREFIX}_load16_s
115
- _align = insn.operand[0] # TODO: alignment support?
116
- offset = insn.operand[1]
115
+ _align = operand[0] # TODO: alignment support?
116
+ offset = operand[1]
117
117
  raise EvalError, "[BUG] invalid type of operand" if !offset.is_a?(Integer)
118
118
 
119
119
  addr = runtime.stack.pop
@@ -133,8 +133,8 @@ module GenAlu
133
133
 
134
134
  load16_u: <<~RUBY,
135
135
  when :${PREFIX}_load16_u
136
- _align = insn.operand[0] # TODO: alignment support?
137
- offset = insn.operand[1]
136
+ _align = operand[0] # TODO: alignment support?
137
+ offset = operand[1]
138
138
  raise EvalError, "[BUG] invalid type of operand" if !offset.is_a?(Integer)
139
139
 
140
140
  addr = runtime.stack.pop
@@ -154,8 +154,8 @@ module GenAlu
154
154
 
155
155
  load32_s: <<~RUBY,
156
156
  when :${PREFIX}_load32_s
157
- _align = insn.operand[0] # TODO: alignment support?
158
- offset = insn.operand[1]
157
+ _align = operand[0] # TODO: alignment support?
158
+ offset = operand[1]
159
159
  raise EvalError, "[BUG] invalid type of operand" if !offset.is_a?(Integer)
160
160
 
161
161
  addr = runtime.stack.pop
@@ -175,8 +175,8 @@ module GenAlu
175
175
 
176
176
  load32_u: <<~RUBY,
177
177
  when :${PREFIX}_load32_u
178
- _align = insn.operand[0] # TODO: alignment support?
179
- offset = insn.operand[1]
178
+ _align = operand[0] # TODO: alignment support?
179
+ offset = operand[1]
180
180
  raise EvalError, "[BUG] invalid type of operand" if !offset.is_a?(Integer)
181
181
 
182
182
  addr = runtime.stack.pop
@@ -196,8 +196,8 @@ module GenAlu
196
196
 
197
197
  store: <<~RUBY,
198
198
  when :${PREFIX}_store
199
- _align = insn.operand[0] # TODO: alignment support?
200
- offset = insn.operand[1]
199
+ _align = operand[0] # TODO: alignment support?
200
+ offset = operand[1]
201
201
  raise EvalError, "[BUG] invalid type of operand" if !offset.is_a?(Integer)
202
202
 
203
203
  value = runtime.stack.pop
@@ -214,8 +214,8 @@ module GenAlu
214
214
 
215
215
  store8: <<~RUBY,
216
216
  when :${PREFIX}_store8
217
- _align = insn.operand[0] # TODO: alignment support?
218
- offset = insn.operand[1]
217
+ _align = operand[0] # TODO: alignment support?
218
+ offset = operand[1]
219
219
  raise EvalError, "[BUG] invalid type of operand" if !offset.is_a?(Integer)
220
220
 
221
221
  value = runtime.stack.pop
@@ -232,8 +232,8 @@ module GenAlu
232
232
 
233
233
  store16: <<~RUBY,
234
234
  when :${PREFIX}_store16
235
- _align = insn.operand[0] # TODO: alignment support?
236
- offset = insn.operand[1]
235
+ _align = operand[0] # TODO: alignment support?
236
+ offset = operand[1]
237
237
  raise EvalError, "[BUG] invalid type of operand" if !offset.is_a?(Integer)
238
238
 
239
239
  value = runtime.stack.pop
@@ -250,8 +250,8 @@ module GenAlu
250
250
 
251
251
  store32: <<~RUBY,
252
252
  when :${PREFIX}_store32
253
- _align = insn.operand[0] # TODO: alignment support?
254
- offset = insn.operand[1]
253
+ _align = operand[0] # TODO: alignment support?
254
+ offset = operand[1]
255
255
  raise EvalError, "[BUG] invalid type of operand" if !offset.is_a?(Integer)
256
256
 
257
257
  value = runtime.stack.pop
@@ -268,7 +268,7 @@ module GenAlu
268
268
 
269
269
  const: <<~RUBY,
270
270
  when :${PREFIX}_const
271
- const = insn.operand[0]
271
+ const = operand[0]
272
272
  if !const.is_a?(Integer)
273
273
  raise EvalError, "invalid type of operand"
274
274
  end
@@ -277,7 +277,7 @@ module GenAlu
277
277
 
278
278
  const__f: <<~RUBY,
279
279
  when :${PREFIX}_const
280
- const = insn.operand[0]
280
+ const = operand[0]
281
281
  if !const.is_a?(Float)
282
282
  raise EvalError, "invalid type of operand"
283
283
  end
@@ -5,14 +5,16 @@ module Wardite
5
5
  module Evaluator
6
6
  # @rbs runtime: Runtime
7
7
  # @rbs frame: Frame
8
- # @rbs insn: Op
9
- # @rbs return: void
10
- def self.${PREFIX}_eval_insn(runtime, frame, insn)
11
- case insn.code
8
+ # @rbs code: Symbol
9
+ # @rbs operand: Array[operandItem]
10
+ # @rbs return: bool?
11
+ def self.${PREFIX}_eval_insn(runtime, frame, code, operand)
12
+ case code
12
13
  ${DEFS}
13
14
  else
14
- raise "Unknown opcode for namespace #{insn.namespace}: #{insn.code}"
15
+ return
15
16
  end
17
+ return true
16
18
  end
17
19
  end
18
20
  end
@@ -5,14 +5,16 @@ module Wardite
5
5
  module Evaluator
6
6
  # @rbs runtime: Runtime
7
7
  # @rbs frame: Frame
8
- # @rbs insn: Op
9
- # @rbs return: void
10
- def self.convert_eval_insn(runtime, frame, insn)
11
- case insn.code
8
+ # @rbs code: Symbol
9
+ # @rbs operand: Array[operandItem]
10
+ # @rbs return: bool?
11
+ def self.convert_eval_insn(runtime, frame, code, operand)
12
+ case code
12
13
  ${DEFS}
13
14
  else
14
- raise "Unknown opcode for namespace #{insn.namespace}: #{insn.code}"
15
+ return
15
16
  end
17
+ return true
16
18
  end
17
19
  end
18
20
  end
@@ -4,8 +4,9 @@ module Wardite
4
4
  module Evaluator
5
5
  # @rbs runtime: Runtime
6
6
  # @rbs frame: Frame
7
- # @rbs insn: Op
8
- # @rbs return: void
9
- def self.f32_eval_insn: (Runtime runtime, Frame frame, Op insn) -> void
7
+ # @rbs code: Symbol
8
+ # @rbs operand: Array[operandItem]
9
+ # @rbs return: bool?
10
+ def self.f32_eval_insn: (Runtime runtime, Frame frame, Symbol code, Array[operandItem] operand) -> bool?
10
11
  end
11
12
  end
@@ -4,8 +4,9 @@ module Wardite
4
4
  module Evaluator
5
5
  # @rbs runtime: Runtime
6
6
  # @rbs frame: Frame
7
- # @rbs insn: Op
8
- # @rbs return: void
9
- def self.f64_eval_insn: (Runtime runtime, Frame frame, Op insn) -> void
7
+ # @rbs code: Symbol
8
+ # @rbs operand: Array[operandItem]
9
+ # @rbs return: bool?
10
+ def self.f64_eval_insn: (Runtime runtime, Frame frame, Symbol code, Array[operandItem] operand) -> bool?
10
11
  end
11
12
  end
@@ -4,8 +4,9 @@ module Wardite
4
4
  module Evaluator
5
5
  # @rbs runtime: Runtime
6
6
  # @rbs frame: Frame
7
- # @rbs insn: Op
8
- # @rbs return: void
9
- def self.i32_eval_insn: (Runtime runtime, Frame frame, Op insn) -> void
7
+ # @rbs code: Symbol
8
+ # @rbs operand: Array[operandItem]
9
+ # @rbs return: bool?
10
+ def self.i32_eval_insn: (Runtime runtime, Frame frame, Symbol code, Array[operandItem] operand) -> bool?
10
11
  end
11
12
  end
@@ -4,8 +4,9 @@ module Wardite
4
4
  module Evaluator
5
5
  # @rbs runtime: Runtime
6
6
  # @rbs frame: Frame
7
- # @rbs insn: Op
8
- # @rbs return: void
9
- def self.i64_eval_insn: (Runtime runtime, Frame frame, Op insn) -> void
7
+ # @rbs code: Symbol
8
+ # @rbs operand: Array[operandItem]
9
+ # @rbs return: bool?
10
+ def self.i64_eval_insn: (Runtime runtime, Frame frame, Symbol code, Array[operandItem] operand) -> bool?
10
11
  end
11
12
  end
@@ -17,6 +17,8 @@ module Wardite
17
17
 
18
18
  attr_reader yjit: bool
19
19
 
20
+ attr_reader profile_file_path: String?
21
+
20
22
  # @rbs args: Array[String]
21
23
  # @rbs return: void
22
24
  def initialize: (Array[String] args) -> void
@@ -32,6 +34,9 @@ module Wardite
32
34
  # @rbs return: void
33
35
  def run: () -> void
34
36
 
37
+ # @rbs return: void
38
+ def __run: () -> void
39
+
35
40
  # @rbs return: void
36
41
  def invoke_function: () -> void
37
42
 
@@ -4,8 +4,9 @@ module Wardite
4
4
  module Evaluator
5
5
  # @rbs runtime: Runtime
6
6
  # @rbs frame: Frame
7
- # @rbs insn: Op
8
- # @rbs return: void
9
- def self.convert_eval_insn: (Runtime runtime, Frame frame, Op insn) -> void
7
+ # @rbs code: Symbol
8
+ # @rbs operand: Array[operandItem]
9
+ # @rbs return: bool?
10
+ def self.convert_eval_insn: (Runtime runtime, Frame frame, Symbol code, Array[operandItem] operand) -> bool?
10
11
  end
11
12
  end
@@ -9,11 +9,11 @@ module Wardite
9
9
 
10
10
  FC_SYMS: Array[Symbol]
11
11
 
12
- # @rbs return: Hash[Integer, Symbol]
13
- def self.table: () -> Hash[Integer, Symbol]
12
+ OPERANDS: Array[Array[Symbol]]
14
13
 
15
- # @rbs return: Hash[Integer, Symbol]
16
- def self.fc_table: () -> Hash[Integer, Symbol]
14
+ NAMESPACES: Array[Symbol]
15
+
16
+ FC_OPERANDS: Array[Symbol]
17
17
 
18
18
  attr_accessor namespace: Symbol
19
19
 
@@ -24,18 +24,22 @@ module Wardite
24
24
 
25
25
  attr_accessor meta: Hash[Symbol, Integer]
26
26
 
27
+ # $OP_COUNT = 0
28
+ # END {
29
+ # puts "Total opcodes: #{$OP_COUNT}"
30
+ # }
27
31
  # @rbs namespace: Symbol
28
32
  # @rbs code: Symbol
29
33
  # @rbs operand: Array[operandItem]
30
34
  def initialize: (Symbol namespace, Symbol code, Array[operandItem] operand) -> untyped
31
35
 
32
- # @rbs chr: String
33
- # @rbs return: [Symbol, Symbol]
34
- def self.to_sym: (String chr) -> [ Symbol, Symbol ]
36
+ # @rbs chr: Integer
37
+ # @rbs return: Symbol
38
+ def self.to_sym: (Integer chr) -> Symbol
35
39
 
36
40
  # @rbs lower: Integer
37
- # @rbs return: [Symbol, Symbol]
38
- def self.resolve_fc_sym: (Integer lower) -> [ Symbol, Symbol ]
41
+ # @rbs return: Symbol
42
+ def self.resolve_fc_sym: (Integer lower) -> Symbol
39
43
 
40
44
  # @rbs code: Symbol
41
45
  # @rbs return: Array[Symbol]
@@ -87,7 +87,7 @@ module Wardite
87
87
 
88
88
  attr_accessor locals_type: Array[Symbol]
89
89
 
90
- attr_accessor body: Array[Op]
90
+ attr_accessor body: Array[[ Symbol, Symbol, Array[operandItem], Integer?, Integer? ]]
91
91
 
92
92
  # @rbs &blk: (CodeBody) -> void
93
93
  # @rbs return: void
@@ -212,13 +212,13 @@ module Wardite
212
212
  def self.code_section: () -> CodeSection
213
213
 
214
214
  # @rbs buf: StringIO
215
- # @rbs return: Array[::Wardite::Op]
216
- def self.code_body: (StringIO buf) -> Array[::Wardite::Op]
215
+ # @rbs return: Array[[Symbol, Symbol, Array[operandItem], Integer?, Integer?]]
216
+ def self.code_body: (StringIO buf) -> Array[[ Symbol, Symbol, Array[operandItem], Integer?, Integer? ]]
217
217
 
218
218
  # @rbs c: String
219
219
  # @rbs buf: StringIO
220
- # @rbs return: [Symbol, Symbol]
221
- def self.resolve_code: (String c, StringIO buf) -> [ Symbol, Symbol ]
220
+ # @rbs return: [Symbol, Symbol, Array[Symbol]]
221
+ def self.resolve_code: (String c, StringIO buf) -> [ Symbol, Symbol, Array[Symbol] ]
222
222
 
223
223
  # @rbs return: DataSection
224
224
  def self.data_section: () -> DataSection
@@ -230,13 +230,13 @@ module Wardite
230
230
  # @rbs return: String
231
231
  def self.fetch_insn_while_end: (StringIO sbuf) -> String
232
232
 
233
- # @rbs ops: Array[Op]
233
+ # @rbs ops: Array[[Symbol, Symbol, Array[operandItem], Integer?, Integer?]]
234
234
  # @rbs return: Integer
235
- def self.decode_expr: (Array[Op] ops) -> Integer
235
+ def self.decode_expr: (Array[[ Symbol, Symbol, Array[operandItem], Integer?, Integer? ]] ops) -> Integer
236
236
 
237
- # @rbs ops: Array[Op]
237
+ # @rbs ops: Array[[Symbol, Symbol, Array[operandItem], Integer?, Integer?]]
238
238
  # @rbs return: wasmValue
239
- def self.decode_global_expr: (Array[Op] ops) -> wasmValue
239
+ def self.decode_global_expr: (Array[[ Symbol, Symbol, Array[operandItem], Integer?, Integer? ]] ops) -> wasmValue
240
240
 
241
241
  # @rbs return: ExportSection
242
242
  def self.export_section: () -> ExportSection
@@ -110,6 +110,10 @@ module Wardite
110
110
  # @rbs return: Object|nil
111
111
  def invoke_internal: (WasmFunction wasm_function) -> (Object | nil)
112
112
 
113
+ $GLOBAL_EXTERNAL_ELAP: Float
114
+
115
+ $GLOBAL_EXTERNAL_TIMES: Integer
116
+
113
117
  # @rbs external_function: ExternalFunction
114
118
  # @rbs return: wasmValue|nil
115
119
  def invoke_external: (ExternalFunction external_function) -> (wasmValue | nil)
@@ -118,9 +122,9 @@ module Wardite
118
122
  def execute!: () -> void
119
123
 
120
124
  # @rbs frame: Frame
121
- # @rbs insn: Op
125
+ # @rbs insn: [Symbol, Symbol, Array[operandItem], Integer?, Integer?]
122
126
  # @rbs return: void
123
- def eval_insn: (Frame frame, Op insn) -> void
127
+ def eval_insn: (Frame frame, [ Symbol, Symbol, Array[operandItem], Integer?, Integer? ] insn) -> void
124
128
 
125
129
  # @rbs labels: Array[Label]
126
130
  # @rbs stack: Array[wasmValue]
@@ -168,7 +172,7 @@ module Wardite
168
172
 
169
173
  attr_accessor sp: Integer
170
174
 
171
- attr_accessor body: Array[Op]
175
+ attr_accessor body: Array[[ Symbol, Symbol, Array[Wardite::operandItem], Integer?, Integer? ]]
172
176
 
173
177
  attr_accessor arity: Integer
174
178
 
@@ -180,11 +184,11 @@ module Wardite
180
184
 
181
185
  # @rbs pc: Integer
182
186
  # @rbs sp: Integer
183
- # @rbs body: Array[Op]
187
+ # @rbs body: Array[[Symbol, Symbol, Array[Wardite::operandItem], Integer?, Integer?]]
184
188
  # @rbs arity: Integer
185
189
  # @rbs locals: Array[wasmValue]
186
190
  # @rbs returb: void
187
- def initialize: (Integer pc, Integer sp, Array[Op] body, Integer arity, Array[wasmValue] locals) -> untyped
191
+ def initialize: (Integer pc, Integer sp, Array[[ Symbol, Symbol, Array[Wardite::operandItem], Integer?, Integer? ]] body, Integer arity, Array[wasmValue] locals) -> untyped
188
192
  end
189
193
 
190
194
  class Label
@@ -358,8 +362,8 @@ module Wardite
358
362
  # @rbs return: void
359
363
  def initialize: (Array[Symbol] callsig, Array[Symbol] retsig, CodeSection::CodeBody code_body) -> void
360
364
 
361
- # @rbs return: Array[Op]
362
- def body: () -> Array[Op]
365
+ # @rbs return: Array[[Symbol, Symbol, Array[operandItem], Integer?, Integer?]]
366
+ def body: () -> Array[[ Symbol, Symbol, Array[operandItem], Integer?, Integer? ]]
363
367
 
364
368
  # @rbs return: Array[Symbol]
365
369
  def locals_type: () -> Array[Symbol]
data/sig/vernier.rbs ADDED
@@ -0,0 +1,3 @@
1
+ module Vernier
2
+ def self.profile: (?out: String) { (void) -> void } -> void
3
+ end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wardite
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.1
4
+ version: 0.9.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Uchio Kondo
8
8
  bindir: exe
9
9
  cert_chain: []
10
- date: 2025-04-05 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
11
11
  dependencies: []
12
12
  description: A pure-ruby webassembly runtime
13
13
  email:
@@ -31,8 +31,12 @@ files:
31
31
  - examples/global.wat
32
32
  - examples/grayscale.rb
33
33
  - examples/helloworld.wat
34
+ - examples/i32_bench.html
35
+ - examples/i32_bench.wat
36
+ - examples/i32_bench_original.wat
34
37
  - examples/i32_const.wat
35
38
  - examples/i32_store.wat
39
+ - examples/load_perf.rb
36
40
  - examples/local_set.wat
37
41
  - examples/loop.wat
38
42
  - examples/memory.wat
@@ -97,6 +101,7 @@ files:
97
101
  - sig/generated/wardite/wasi/dirent_cache.rbs
98
102
  - sig/generated/wardite/wasi/preopens.rbs
99
103
  - sig/generated/wardite/wasm_module.rbs
104
+ - sig/vernier.rbs
100
105
  - sig/wardite.rbs
101
106
  homepage: https://github.com/udzura/wardite
102
107
  licenses: []
@@ -117,7 +122,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
117
122
  - !ruby/object:Gem::Version
118
123
  version: '0'
119
124
  requirements: []
120
- rubygems_version: 3.6.2
125
+ rubygems_version: 3.6.9
121
126
  specification_version: 4
122
127
  summary: A pure-ruby webassembly runtime
123
128
  test_files: []