Class: Wardite::Exports

Inherits:
Object
  • Object
show all
Defined in:
lib/wardite.rb

Overview

@rbs!

type exportHandle = WasmFunction | ExternalFunction | Table | Global | Memory

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(export_section, store) ⇒ Exports

Returns a new instance of Exports.



1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
# File 'lib/wardite.rb', line 1203

def initialize(export_section, store)
  @mappings = {}
  export_section.exports.each_pair do |name, desc|
    case desc.kind
    when 0x0
      @mappings[name] = [desc.kind, store.funcs[desc.index]]
    when 0x1
      @mappings[name] = [desc.kind, store.tables[desc.index]]
    when 0x2
      @mappings[name] = [desc.kind, store.memories[desc.index]]
    when 0x3
      @mappings[name] = [desc.kind, store.globals[desc.index]]
    else
    end
  end
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *_args) ⇒ Object



1230
1231
1232
1233
1234
1235
1236
# File 'lib/wardite.rb', line 1230

def method_missing(name, *_args)
  if self[name.to_s]
    self[name.to_s]
  else
    super
  end
end

Instance Attribute Details

#mappingsObject

: Hash[String, [Integer, exportHandle]]



1198
1199
1200
# File 'lib/wardite.rb', line 1198

def mappings
  @mappings
end

Instance Method Details

#[](name) ⇒ Object



1222
1223
1224
# File 'lib/wardite.rb', line 1222

def [](name)
  @mappings[name]&.[](1)
end

#respond_to?(name) ⇒ Boolean

Returns:

  • (Boolean)


1226
1227
1228
# File 'lib/wardite.rb', line 1226

def respond_to?(name) 
  !!self[name.to_s] || super
end