Class: Wardite::Instance
- Inherits:
-
Object
- Object
- Wardite::Instance
- Defined in:
- lib/wardite.rb
Instance Attribute Summary collapse
-
#exports ⇒ Object
: Exports.
-
#import_object ⇒ Object
readonly
: Hash[Symbol, wasmModule].
-
#runtime ⇒ Object
: Runtime.
-
#sections ⇒ Object
: Array.
-
#store ⇒ Object
: Store.
-
#types ⇒ Object
: Array.
-
#version ⇒ Object
: Integer.
-
#wasi ⇒ Object
: ::Wardite::WasiSnapshotPreview1?.
Instance Method Summary collapse
- #check_data_count ⇒ Object
- #code_section ⇒ Object
- #data_count_section ⇒ Object
- #data_section ⇒ Object
- #elem_section ⇒ Object
- #export_section ⇒ Object
- #function_section ⇒ Object
- #global_section ⇒ Object
- #import_section ⇒ Object
-
#initialize(import_object, &blk) ⇒ Instance
constructor
A new instance of Instance.
- #memory_section ⇒ Object
- #start_section ⇒ Object
- #table_section ⇒ Object
- #type_section ⇒ Object
Constructor Details
#initialize(import_object, &blk) ⇒ Instance
Returns a new instance of Instance.
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/wardite.rb', line 45 def initialize(import_object, &blk) @wasi = nil blk.call(self) import_object.each_pair do |k, v| if v.is_a?(Hash) import_object[k] = HashModule.new(v) end end @import_object = import_object #: Hash[Symbol, wasmModule] @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 check_data_count end |
Instance Attribute Details
#exports ⇒ Object
: Exports
37 38 39 |
# File 'lib/wardite.rb', line 37 def exports @exports end |
#import_object ⇒ Object (readonly)
: Hash[Symbol, wasmModule]
39 40 41 |
# File 'lib/wardite.rb', line 39 def import_object @import_object end |
#runtime ⇒ Object
: Runtime
31 32 33 |
# File 'lib/wardite.rb', line 31 def runtime @runtime end |
#store ⇒ Object
: Store
35 36 37 |
# File 'lib/wardite.rb', line 35 def store @store end |
#version ⇒ Object
: Integer
27 28 29 |
# File 'lib/wardite.rb', line 27 def version @version end |
#wasi ⇒ Object
: ::Wardite::WasiSnapshotPreview1?
41 42 43 |
# File 'lib/wardite.rb', line 41 def wasi @wasi end |
Instance Method Details
#check_data_count ⇒ Object
74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/wardite.rb', line 74 def check_data_count data_count = self.data_count_section&.count if data_count actual_count = self.data_section&.segments&.size if !actual_count raise LoadError, "invalid data segment count" end if (data_count != actual_count) raise LoadError, "invalid data segment count" end end end |
#code_section ⇒ Object
206 207 208 209 210 211 212 213 214 215 |
# File 'lib/wardite.rb', line 206 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_count_section ⇒ Object
158 159 160 161 162 163 164 165 166 167 |
# File 'lib/wardite.rb', line 158 def data_count_section sec = @sections.find{|s| s.code == Const::SectionDataCount } if !sec return nil end if !sec.is_a?(DataCountSection) raise(GenericError, "[BUG] found invalid data section") end sec end |
#data_section ⇒ Object
146 147 148 149 150 151 152 153 154 155 |
# File 'lib/wardite.rb', line 146 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_section ⇒ Object
194 195 196 197 198 199 200 201 202 203 |
# File 'lib/wardite.rb', line 194 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_section ⇒ Object
218 219 220 221 222 223 224 225 226 227 |
# File 'lib/wardite.rb', line 218 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_section ⇒ Object
170 171 172 173 174 175 176 177 178 179 |
# File 'lib/wardite.rb', line 170 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_section ⇒ Object
134 135 136 137 138 139 140 141 142 143 |
# File 'lib/wardite.rb', line 134 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_section ⇒ Object
88 89 90 91 92 93 94 95 |
# File 'lib/wardite.rb', line 88 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_section ⇒ Object
110 111 112 113 114 115 116 117 118 119 |
# File 'lib/wardite.rb', line 110 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_section ⇒ Object
122 123 124 125 126 127 128 129 130 131 |
# File 'lib/wardite.rb', line 122 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_section ⇒ Object
182 183 184 185 186 187 188 189 190 191 |
# File 'lib/wardite.rb', line 182 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_section ⇒ Object
98 99 100 101 102 103 104 105 106 107 |
# File 'lib/wardite.rb', line 98 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 |