Class: Relaton::Un::Wasm::Instance

Inherits:
Object
  • Object
show all
Defined in:
lib/relaton/un/wasm/instance.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(mod, imports = {}) ⇒ Instance

imports: { “modname” => { “fieldname” => Proc } }



10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/relaton/un/wasm/instance.rb', line 10

def initialize(mod, imports = {})
  @mod = mod
  @types = mod.types
  @imports = imports
  @funcs = []
  @globals = []
  @table = []
  link_funcs
  init_memory
  init_globals
  init_table
  init_data
  @interpreter = Interpreter.new(self)
end

Instance Attribute Details

#funcsObject (readonly)

Returns the value of attribute funcs.



7
8
9
# File 'lib/relaton/un/wasm/instance.rb', line 7

def funcs
  @funcs
end

#globalsObject (readonly)

Returns the value of attribute globals.



7
8
9
# File 'lib/relaton/un/wasm/instance.rb', line 7

def globals
  @globals
end

#memoryObject (readonly)

Returns the value of attribute memory.



7
8
9
# File 'lib/relaton/un/wasm/instance.rb', line 7

def memory
  @memory
end

#tableObject (readonly)

Returns the value of attribute table.



7
8
9
# File 'lib/relaton/un/wasm/instance.rb', line 7

def table
  @table
end

#typesObject (readonly)

Returns the value of attribute types.



7
8
9
# File 'lib/relaton/un/wasm/instance.rb', line 7

def types
  @types
end

Instance Method Details

#export_index(name, kind) ⇒ Object

Raises:



34
35
36
37
38
39
# File 'lib/relaton/un/wasm/instance.rb', line 34

def export_index(name, kind)
  exp = @mod.exports.find { |e| e.name == name && e.kind == kind }
  raise LinkError, "no export named #{name} of kind #{kind}" unless exp

  exp.index
end

#invoke(name, *args) ⇒ Object



25
26
27
28
# File 'lib/relaton/un/wasm/instance.rb', line 25

def invoke(name, *args)
  idx = export_index(name, :func)
  invoke_by_index(idx, args)
end

#invoke_by_index(func_idx, args) ⇒ Object



30
31
32
# File 'lib/relaton/un/wasm/instance.rb', line 30

def invoke_by_index(func_idx, args)
  @interpreter.invoke(func_idx, args)
end