class WAG::Module

Public Class Methods

new() click to toggle source
# File lib/wag/module.rb, line 7
def initialize
  @data = []
  @elements = []
  @exports = []
  @functions = []
  @globals = []
  @imports = []
  @memories = []
  @tables = []
  @types = []
end

Public Instance Methods

build(&block) click to toggle source
# File lib/wag/module.rb, line 19
def build(&block)
  instance_exec(&block)
  self
end
data(offset, value) click to toggle source
# File lib/wag/module.rb, line 66
def data(offset, value)
  data = Data.new(offset, value)
  @data << data
  data
end
elem(table_id, *labels, &block) click to toggle source
# File lib/wag/module.rb, line 59
def elem(table_id, *labels, &block)
  elem = Element.new(table_id, *labels)
  @elements << elem
  elem.instance_exec(&block) if block
  elem
end
export(name, &block) click to toggle source
# File lib/wag/module.rb, line 31
def export(name, &block)
  export = Export.new(name)
  @exports << export
  export.instance_exec(&block) if block
  export
end
func(label = nil, &block) click to toggle source
# File lib/wag/module.rb, line 72
def func(label = nil, &block)
  func = Function.new(label)
  @functions << func
  func.instance_exec(&block) if block
  func
end
global(label, type, &block) click to toggle source
# File lib/wag/module.rb, line 45
def global(label, type, &block)
  global = Global.new(label, type)
  @globals << global
  global.instance_exec(&block) if block
  global
end
import(module_name, name, &block) click to toggle source
# File lib/wag/module.rb, line 24
def import(module_name, name, &block)
  import = Import.new(module_name, name)
  @imports << import
  import.instance_exec(&block) if block
  import
end
memory(number, min = nil, max = nil, &block) click to toggle source
# File lib/wag/module.rb, line 38
def memory(number, min = nil, max = nil, &block)
  mem = Memory.new(number, min, max)
  @memories << mem
  mem.instance_exec(&block) if block
  mem
end
table(elements, type = :anyfunc, &block) click to toggle source
# File lib/wag/module.rb, line 79
def table(elements, type = :anyfunc, &block)
  table = Table.new(elements, type)
  @tables << table
  table.instance_exec(&block) if block
  table
end
to_sexpr() click to toggle source
# File lib/wag/module.rb, line 86
def to_sexpr # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
  mod = [:module]
  mod.concat(@imports.map(&:to_sexpr))
  mod.concat(@exports.map(&:to_sexpr))
  mod.concat(@memories.map(&:to_sexpr))
  mod.concat(@globals.map(&:to_sexpr))
  mod.concat(@types.map(&:to_sexpr))
  mod.concat(@tables.map(&:to_sexpr))
  mod.concat(@elements.map(&:to_sexpr))
  mod.concat(@data.map(&:to_sexpr))
  mod.concat(@functions.map(&:to_sexpr))
  mod
end
type(label, &block) click to toggle source
# File lib/wag/module.rb, line 52
def type(label, &block)
  type = FunctionType.new(label)
  @types << type
  type.instance_exec(&block) if block
  type
end