wardite 0.4.2 → 0.4.3

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a6335000832a623233f1a9719fe271fa4a000270bc55312fc996fe3f4e72bad9
4
- data.tar.gz: d72874301c47400a24fa9992de296d5d490c04d2c6f1dad2b76493f7eed3b464
3
+ metadata.gz: f1960efc493205587db2fbb0e21504247d120831417b081dc169c0b7c10fccaf
4
+ data.tar.gz: cbdbf5e122fe118ccee7a615b184be2032b6000a043b3642a9b5336f6b0fbe19
5
5
  SHA512:
6
- metadata.gz: 3d3a12027244cac1cc6efeb382a6a164c070946a85886eae1915c90360a6c139766ae2780103511bf1e332418576a6dbdc1fd7ca7266a2974dd228d24155bedb
7
- data.tar.gz: 282d5051760ca800a876daaa1962bea603961ce3fc4551560255030c433e445ba0efc945b75b5829112a6742b6492142ad3c2a1d577f30816bcf76f39bd58f2e
6
+ metadata.gz: 207a1cd23ab5f25fdf9dd421ab42c70528be1987e57f41d656f47e205ee78ba321b9553364f988f6f039f87a77878e040075e690b00b97ace0bf91e35c07431f
7
+ data.tar.gz: 944b8112be80c9c3b78dd7cdec01ac3c72f7e4e077196a315bfaa14ffeb4dfa6cdb868570ae0bc55fb4f07da858f968807fee8bb50d5846fa763dd7b82359f98
data/README.md CHANGED
@@ -43,7 +43,7 @@ path = ARGV[0]
43
43
  method = ARGV[1]
44
44
  args = ARGV[2..-1] || []
45
45
 
46
- instance = Wardite::new(path: path);
46
+ instance = Wardite::new(path: path)
47
47
  if !method && instance.runtime.respond_to?(:_start)
48
48
  instance.runtime._start
49
49
  else
data/lib/wardite/load.rb CHANGED
@@ -193,7 +193,7 @@ module Wardite
193
193
 
194
194
  attr_accessor :kind #: Integer
195
195
 
196
- attr_accessor :func_index #: Integer
196
+ attr_accessor :index #: Integer
197
197
  end
198
198
 
199
199
  attr_accessor :exports #: Hash[String, ExportDesc]
@@ -840,7 +840,7 @@ module Wardite
840
840
  dest.add_desc do |desc|
841
841
  desc.name = name
842
842
  desc.kind = kind
843
- desc.func_index = index
843
+ desc.index = index
844
844
  end
845
845
  end
846
846
 
data/lib/wardite/value.rb CHANGED
@@ -237,6 +237,10 @@ module Wardite
237
237
  def inspect
238
238
  "I32(#{value_s})"
239
239
  end
240
+
241
+ def ==(other)
242
+ return self.class == other.class && self.value == other.value
243
+ end
240
244
  end
241
245
 
242
246
  class I64
@@ -400,6 +404,10 @@ module Wardite
400
404
  def inspect
401
405
  "I64(#{@value})"
402
406
  end
407
+
408
+ def ==(other)
409
+ return self.class == other.class && self.value == other.value
410
+ end
403
411
  end
404
412
 
405
413
  class F32
@@ -601,6 +609,10 @@ module Wardite
601
609
  def inspect
602
610
  "F32(#{@value})"
603
611
  end
612
+
613
+ def ==(other)
614
+ return self.class == other.class && self.value == other.value
615
+ end
604
616
  end
605
617
 
606
618
  class F64
@@ -800,5 +812,9 @@ module Wardite
800
812
  def inspect
801
813
  "F64(#{@value})"
802
814
  end
815
+
816
+ def ==(other)
817
+ return self.class == other.class && self.value == other.value
818
+ end
803
819
  end
804
820
  end
@@ -2,5 +2,5 @@
2
2
  # rbs_inline: enabled
3
3
 
4
4
  module Wardite
5
- VERSION = "0.4.2" #: String
5
+ VERSION = "0.4.3" #: String
6
6
  end
data/lib/wardite.rb CHANGED
@@ -258,10 +258,13 @@ module Wardite
258
258
  if !callable?(name)
259
259
  raise ::NoMethodError, "function #{name} not found"
260
260
  end
261
- kind, fn = @instance.exports[name.to_s]
261
+ kind, fn = @instance.exports.mappings[name.to_s]
262
262
  if kind != 0
263
263
  raise ::NoMethodError, "#{name} is not a function"
264
264
  end
265
+ if !fn.is_a?(WasmFunction) && !fn.is_a?(ExternalFunction)
266
+ raise ::NoMethodError, "#{name} is not a function"
267
+ end
265
268
  if fn.callsig.size != args.size
266
269
  raise ArgumentError, "unmatch arg size"
267
270
  end
@@ -727,10 +730,12 @@ module Wardite
727
730
  end
728
731
 
729
732
  rescue => e
730
- require "pp"
731
- $stderr.puts "instance:::\n#{self.instance.pretty_inspect}"
732
- $stderr.puts "frame:::\n#{frame.pretty_inspect}"
733
- $stderr.puts "stack:::\n#{stack.pretty_inspect}"
733
+ if ENV["DEBUG"]
734
+ require "pp"
735
+ $stderr.puts "instance:::\n#{self.instance.pretty_inspect}"
736
+ $stderr.puts "frame:::\n#{frame.pretty_inspect}"
737
+ $stderr.puts "stack:::\n#{stack.pretty_inspect}"
738
+ end
734
739
  raise e
735
740
  end
736
741
 
@@ -1219,8 +1224,11 @@ module Wardite
1219
1224
  end
1220
1225
  end
1221
1226
 
1227
+ # @rbs!
1228
+ # type exportHandle = WasmFunction | ExternalFunction | Table | Global | Memory
1229
+
1222
1230
  class Exports
1223
- attr_accessor :mappings #: Hash[String, [Integer, WasmFunction|ExternalFunction]]
1231
+ attr_accessor :mappings #: Hash[String, [Integer, exportHandle]]
1224
1232
 
1225
1233
  # @rbs export_section: ExportSection
1226
1234
  # @rbs store: Store
@@ -1228,15 +1236,36 @@ module Wardite
1228
1236
  def initialize(export_section, store)
1229
1237
  @mappings = {}
1230
1238
  export_section.exports.each_pair do |name, desc|
1231
- # TODO: introduce map by kind
1232
- @mappings[name] = [desc.kind, store.funcs[desc.func_index]]
1239
+ case desc.kind
1240
+ when 0x0
1241
+ @mappings[name] = [desc.kind, store.funcs[desc.index]]
1242
+ when 0x1
1243
+ @mappings[name] = [desc.kind, store.tables[desc.index]]
1244
+ when 0x2
1245
+ @mappings[name] = [desc.kind, store.memories[desc.index]]
1246
+ when 0x3
1247
+ @mappings[name] = [desc.kind, store.globals[desc.index]]
1248
+ else
1249
+ end
1233
1250
  end
1234
1251
  end
1235
1252
 
1236
1253
  # @rbs name: String
1237
- # @rbs return: [Integer, WasmFunction|ExternalFunction]
1254
+ # @rbs return: exportHandle|nil
1238
1255
  def [](name)
1239
- @mappings[name]
1256
+ @mappings[name]&.[](1)
1257
+ end
1258
+
1259
+ def respond_to?(name)
1260
+ !!self[name.to_s] || super
1261
+ end
1262
+
1263
+ def method_missing(name, *_args)
1264
+ if self[name.to_s]
1265
+ self[name.to_s]
1266
+ else
1267
+ super
1268
+ end
1240
1269
  end
1241
1270
  end
1242
1271
 
@@ -136,7 +136,7 @@ module Wardite
136
136
 
137
137
  attr_accessor kind: Integer
138
138
 
139
- attr_accessor func_index: Integer
139
+ attr_accessor index: Integer
140
140
  end
141
141
 
142
142
  attr_accessor exports: Hash[String, ExportDesc]
@@ -115,6 +115,8 @@ module Wardite
115
115
 
116
116
  # I32#inspect shows signed value for convinience
117
117
  def inspect: () -> untyped
118
+
119
+ def ==: (untyped other) -> untyped
118
120
  end
119
121
 
120
122
  class I64
@@ -196,6 +198,8 @@ module Wardite
196
198
 
197
199
  # I64#inspect shows signed value
198
200
  def inspect: () -> untyped
201
+
202
+ def ==: (untyped other) -> untyped
199
203
  end
200
204
 
201
205
  class F32
@@ -278,6 +282,8 @@ module Wardite
278
282
  def trunc_sat_s: (to: Symbol) -> wasmValue
279
283
 
280
284
  def inspect: () -> untyped
285
+
286
+ def ==: (untyped other) -> untyped
281
287
  end
282
288
 
283
289
  class F64
@@ -358,5 +364,7 @@ module Wardite
358
364
  def trunc_sat_s: (to: Symbol) -> wasmValue
359
365
 
360
366
  def inspect: () -> untyped
367
+
368
+ def ==: (untyped other) -> untyped
361
369
  end
362
370
  end
@@ -315,8 +315,10 @@ module Wardite
315
315
  def result_size: () -> Integer
316
316
  end
317
317
 
318
+ type exportHandle = WasmFunction | ExternalFunction | Table | Global | Memory
319
+
318
320
  class Exports
319
- attr_accessor mappings: Hash[String, [ Integer, WasmFunction | ExternalFunction ]]
321
+ attr_accessor mappings: Hash[String, [ Integer, exportHandle ]]
320
322
 
321
323
  # @rbs export_section: ExportSection
322
324
  # @rbs store: Store
@@ -324,8 +326,12 @@ module Wardite
324
326
  def initialize: (ExportSection export_section, Store store) -> void
325
327
 
326
328
  # @rbs name: String
327
- # @rbs return: [Integer, WasmFunction|ExternalFunction]
328
- def []: (String name) -> [ Integer, WasmFunction | ExternalFunction ]
329
+ # @rbs return: exportHandle|nil
330
+ def []: (String name) -> (exportHandle | nil)
331
+
332
+ def respond_to?: (untyped name) -> untyped
333
+
334
+ def method_missing: (untyped name, *untyped _args) -> untyped
329
335
  end
330
336
 
331
337
  # TODO: common interface btw. WasmFunction and ExternalFunction?
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.2
4
+ version: 0.4.3
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 00:00:00.000000000 Z
11
+ date: 2024-11-17 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: A pure-ruby webassembly runtime
14
14
  email: