Class: Wardite::Instance

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(import_object, &blk) ⇒ Instance

Returns a new instance of Instance.



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/wardite.rb', line 44

def initialize(import_object, &blk)
  blk.call(self)
  @import_object = import_object

  @store = Store.new(self)
  @exports = Exports.new(self.export_section, store)
  @runtime = Runtime.new(self)

  @types = []
  type_section = self.type_section
  if type_section
    type_section.defined_types.each_with_index do |calltype, idx|
      rettype = type_section.defined_results[idx]
      @types << Type.new(calltype, rettype)
    end
  end
end

Instance Attribute Details

#exportsObject

: Exports



38
39
40
# File 'lib/wardite.rb', line 38

def exports
  @exports
end

#import_objectObject (readonly)

: Hash[Symbol, Hash[Symbol, wasmCallable]]



40
41
42
# File 'lib/wardite.rb', line 40

def import_object
  @import_object
end

#runtimeObject

: Runtime



32
33
34
# File 'lib/wardite.rb', line 32

def runtime
  @runtime
end

#sectionsObject

: Array



30
31
32
# File 'lib/wardite.rb', line 30

def sections
  @sections
end

#storeObject

: Store



36
37
38
# File 'lib/wardite.rb', line 36

def store
  @store
end

#typesObject

: Array



34
35
36
# File 'lib/wardite.rb', line 34

def types
  @types
end

#versionObject

: Integer



28
29
30
# File 'lib/wardite.rb', line 28

def version
  @version
end

Instance Method Details

#code_sectionObject



169
170
171
172
173
174
175
176
177
178
# File 'lib/wardite.rb', line 169

def code_section
  sec = @sections.find{|s| s.code == Const::SectionCode }
  if !sec
    return nil
  end
  if !sec.is_a?(CodeSection)
    raise(GenericError, "instance doesn't have required section")
  end
  sec
end

#data_sectionObject



121
122
123
124
125
126
127
128
129
130
# File 'lib/wardite.rb', line 121

def data_section
  sec = @sections.find{|s| s.code == Const::SectionData }
  if !sec
    return nil
  end
  if !sec.is_a?(DataSection)
    raise(GenericError, "[BUG] found invalid data section")
  end
  sec
end

#elem_sectionObject



157
158
159
160
161
162
163
164
165
166
# File 'lib/wardite.rb', line 157

def elem_section
  sec = @sections.find{|s| s.code == Const::SectionElement }
  if !sec
    return nil
  end
  if !sec.is_a?(ElemSection)
    raise(GenericError, "instance doesn't have required section")
  end
  sec
end

#export_sectionObject



181
182
183
184
185
186
187
188
189
190
# File 'lib/wardite.rb', line 181

def export_section
  sec = @sections.find{|s| s.code == Const::SectionExport }
  if !sec
    return ExportSection.new
  end
  if !sec.is_a?(ExportSection)
    raise(GenericError, "instance doesn't have required section")
  end
  sec
end

#function_sectionObject



133
134
135
136
137
138
139
140
141
142
# File 'lib/wardite.rb', line 133

def function_section
  sec = @sections.find{|s| s.code == Const::SectionFunction }
  if !sec
    return nil
  end
  if !sec.is_a?(FunctionSection)
    raise(GenericError, "instance doesn't have required section")
  end
  sec
end

#global_sectionObject



109
110
111
112
113
114
115
116
117
118
# File 'lib/wardite.rb', line 109

def global_section
  sec = @sections.find{|s| s.code == Const::SectionGlobal }
  if !sec
    return nil
  end
  if !sec.is_a?(GlobalSection)
    raise(GenericError, "instance doesn't have required section")
  end
  sec
end

#import_sectionObject



63
64
65
66
67
68
69
70
# File 'lib/wardite.rb', line 63

def import_section
  sec = @sections.find{|s| s.code == Const::SectionImport }
  if !sec.is_a?(ImportSection)
    # returns dummy empty section
    return ImportSection.new
  end
  sec
end

#memory_sectionObject



85
86
87
88
89
90
91
92
93
94
# File 'lib/wardite.rb', line 85

def memory_section
  sec = @sections.find{|s| s.code == Const::SectionMemory }
  if !sec
    return nil
  end
  if !sec.is_a?(MemorySection)
    raise(GenericError, "[BUG] found invalid memory section")
  end
  sec
end

#start_sectionObject



97
98
99
100
101
102
103
104
105
106
# File 'lib/wardite.rb', line 97

def start_section
  sec = @sections.find{|s| s.code == Const::SectionStart }
  if !sec
    return nil
  end
  if !sec.is_a?(StartSection)
    raise(GenericError, "[BUG] found invalid start section")
  end
  sec
end

#table_sectionObject



145
146
147
148
149
150
151
152
153
154
# File 'lib/wardite.rb', line 145

def table_section
  sec = @sections.find{|s| s.code == Const::SectionTable }
  if !sec
    return nil
  end
  if !sec.is_a?(TableSection)
    raise(GenericError, "instance doesn't have required section")
  end
  sec
end

#type_sectionObject



73
74
75
76
77
78
79
80
81
82
# File 'lib/wardite.rb', line 73

def type_section
  sec = @sections.find{|s| s.code == Wardite::Const::SectionType }
  if !sec
    return nil
  end
  if !sec.is_a?(TypeSection)
    raise(GenericError, "instance doesn't have required section")
  end
  sec
end