Class: Dewasm::Pozeiden::WasmModule::Rt::Table
- Inherits:
-
Object
- Object
- Dewasm::Pozeiden::WasmModule::Rt::Table
- Defined in:
- lib/dewasm/pozeiden/wasm_module.rb
Instance Method Summary collapse
-
#call(i, type_key, *args) ⇒ Object
type_keyis a symbol interned from the function type's shape (not a type index): tables can be shared across modules, whose index spaces differ. -
#call1(i, type_key, a0) ⇒ Object
Same dispatch and trap contract as
call, with no*args/splat array built on either side. -
#call3(i, type_key, a0, a1, a2) ⇒ Object
Same dispatch and trap contract as
call, with no*args/splat array built on either side. -
#call4(i, type_key, a0, a1, a2, a3) ⇒ Object
Same dispatch and trap contract as
call, with no*args/splat array built on either side. -
#call5(i, type_key, a0, a1, a2, a3, a4) ⇒ Object
Same dispatch and trap contract as
call, with no*args/splat array built on either side. -
#call6(i, type_key, a0, a1, a2, a3, a4, a5) ⇒ Object
Same dispatch and trap contract as
call, with no*args/splat array built on either side. -
#check_range(offset, count) ⇒ Object
Bounds check for an (active) element segment before initializing it; also catches empty segments whose offset is past the end.
-
#init(dst, elem, src, len) ⇒ Object
elemis an Array of table slot values ([type_key, func]pairs, ornilfor aref.nullitem), built once at instantiation/ table.init-population time. -
#initialize(size, max = nil) ⇒ Table
constructor
One slot per element: a
[type_symbol, callable]pair for funcref tables, ornilfor a null slot. - #size ⇒ Object
- #wasm_kind ⇒ Object
Constructor Details
#initialize(size, max = nil) ⇒ Table
One slot per element: a [type_symbol, callable] pair for funcref tables, or nil for a null slot. call_indirect compares type keys, not module-local indices, so a shared table stays consistent across modules.
436 437 438 439 |
# File 'lib/dewasm/pozeiden/wasm_module.rb', line 436 def initialize(size, max = nil) @slots = Array.new(size) @max = max end |
Instance Method Details
#call(i, type_key, *args) ⇒ Object
type_key is a symbol interned from the function type's shape (not a type index): tables can be shared across modules, whose index spaces differ.
446 447 448 449 450 451 452 453 |
# File 'lib/dewasm/pozeiden/wasm_module.rb', line 446 def call(i, type_key, *args) Rt.trap("undefined element") if i >= @slots.size slot = @slots[i] Rt.trap("uninitialized element") if slot.nil? ty, func = slot Rt.trap("indirect call type mismatch") unless ty == type_key func.call(*args) end |
#call1(i, type_key, a0) ⇒ Object
Same dispatch and trap contract as call, with no *args/splat array built on either side.
456 457 458 459 460 461 462 463 |
# File 'lib/dewasm/pozeiden/wasm_module.rb', line 456 def call1(i, type_key, a0) Rt.trap("undefined element") if i >= @slots.size slot = @slots[i] Rt.trap("uninitialized element") if slot.nil? ty, func = slot Rt.trap("indirect call type mismatch") unless ty == type_key func.call(a0) end |
#call3(i, type_key, a0, a1, a2) ⇒ Object
Same dispatch and trap contract as call, with no *args/splat array built on either side.
466 467 468 469 470 471 472 473 |
# File 'lib/dewasm/pozeiden/wasm_module.rb', line 466 def call3(i, type_key, a0, a1, a2) Rt.trap("undefined element") if i >= @slots.size slot = @slots[i] Rt.trap("uninitialized element") if slot.nil? ty, func = slot Rt.trap("indirect call type mismatch") unless ty == type_key func.call(a0, a1, a2) end |
#call4(i, type_key, a0, a1, a2, a3) ⇒ Object
Same dispatch and trap contract as call, with no *args/splat array built on either side.
476 477 478 479 480 481 482 483 |
# File 'lib/dewasm/pozeiden/wasm_module.rb', line 476 def call4(i, type_key, a0, a1, a2, a3) Rt.trap("undefined element") if i >= @slots.size slot = @slots[i] Rt.trap("uninitialized element") if slot.nil? ty, func = slot Rt.trap("indirect call type mismatch") unless ty == type_key func.call(a0, a1, a2, a3) end |
#call5(i, type_key, a0, a1, a2, a3, a4) ⇒ Object
Same dispatch and trap contract as call, with no *args/splat array built on either side.
486 487 488 489 490 491 492 493 |
# File 'lib/dewasm/pozeiden/wasm_module.rb', line 486 def call5(i, type_key, a0, a1, a2, a3, a4) Rt.trap("undefined element") if i >= @slots.size slot = @slots[i] Rt.trap("uninitialized element") if slot.nil? ty, func = slot Rt.trap("indirect call type mismatch") unless ty == type_key func.call(a0, a1, a2, a3, a4) end |
#call6(i, type_key, a0, a1, a2, a3, a4, a5) ⇒ Object
Same dispatch and trap contract as call, with no *args/splat array built on either side.
496 497 498 499 500 501 502 503 |
# File 'lib/dewasm/pozeiden/wasm_module.rb', line 496 def call6(i, type_key, a0, a1, a2, a3, a4, a5) Rt.trap("undefined element") if i >= @slots.size slot = @slots[i] Rt.trap("uninitialized element") if slot.nil? ty, func = slot Rt.trap("indirect call type mismatch") unless ty == type_key func.call(a0, a1, a2, a3, a4, a5) end |
#check_range(offset, count) ⇒ Object
Bounds check for an (active) element segment before initializing it; also catches empty segments whose offset is past the end.
507 508 509 |
# File 'lib/dewasm/pozeiden/wasm_module.rb', line 507 def check_range(offset, count) Rt.trap("out of bounds table access") if offset + count > @slots.size end |
#init(dst, elem, src, len) ⇒ Object
elem is an Array of table slot values ([type_key, func] pairs, or
nil for a ref.null item), built once at instantiation/ table.init-population time.
513 514 515 516 517 518 |
# File 'lib/dewasm/pozeiden/wasm_module.rb', line 513 def init(dst, elem, src, len) Rt.trap("out of bounds table access") if src + len > elem.size check_range(dst, len) return if len == 0 @slots[dst, len] = elem[src, len] end |
#size ⇒ Object
443 |
# File 'lib/dewasm/pozeiden/wasm_module.rb', line 443 def size = @slots.size |
#wasm_kind ⇒ Object
441 |
# File 'lib/dewasm/pozeiden/wasm_module.rb', line 441 def wasm_kind = :table |