Class: Dewasm::Pozeiden::WasmModule::Rt::Table

Inherits:
Object
  • Object
show all
Defined in:
lib/dewasm/pozeiden/wasm_module.rb

Instance Method Summary collapse

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.



349
350
351
352
# File 'lib/dewasm/pozeiden/wasm_module.rb', line 349

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.



359
360
361
362
363
364
365
366
# File 'lib/dewasm/pozeiden/wasm_module.rb', line 359

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.



369
370
371
372
373
374
375
376
# File 'lib/dewasm/pozeiden/wasm_module.rb', line 369

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.



379
380
381
382
383
384
385
386
# File 'lib/dewasm/pozeiden/wasm_module.rb', line 379

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.



389
390
391
392
393
394
395
396
# File 'lib/dewasm/pozeiden/wasm_module.rb', line 389

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.



399
400
401
402
403
404
405
406
# File 'lib/dewasm/pozeiden/wasm_module.rb', line 399

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.



409
410
411
412
413
414
415
416
# File 'lib/dewasm/pozeiden/wasm_module.rb', line 409

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.



420
421
422
# File 'lib/dewasm/pozeiden/wasm_module.rb', line 420

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.



426
427
428
429
430
431
# File 'lib/dewasm/pozeiden/wasm_module.rb', line 426

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

#sizeObject



356
# File 'lib/dewasm/pozeiden/wasm_module.rb', line 356

def size = @slots.size

#wasm_kindObject



354
# File 'lib/dewasm/pozeiden/wasm_module.rb', line 354

def wasm_kind = :table