Class: Wardite::Store
- Inherits:
-
Object
- Object
- Wardite::Store
- Defined in:
- lib/wardite.rb
Instance Attribute Summary collapse
-
#funcs ⇒ Object
: Array.
-
#memories ⇒ Object
FIXME: attr_accessor :modules.
Instance Method Summary collapse
- #[](idx) ⇒ Object
-
#initialize(inst) ⇒ Store
constructor
A new instance of Store.
Constructor Details
#initialize(inst) ⇒ Store
Returns a new instance of Store.
1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 |
# File 'lib/wardite.rb', line 1085 def initialize(inst) type_section = inst.type_section func_section = inst.function_section code_section = inst.code_section import_section = inst.import_section @funcs = [] if type_section && func_section && code_section import_section.imports.each do |desc| callsig = type_section.defined_types[desc.sig_index] retsig = type_section.defined_results[desc.sig_index] imported_module = inst.import_object[desc.module_name.to_sym] if !imported_module raise ::NameError, "module #{desc.module_name} not found" end imported_proc = imported_module[desc.name.to_sym] if !imported_proc raise ::NameError, "function #{desc.module_name}.#{desc.name} not found" end ext_function = ExternalFunction.new(callsig, retsig, imported_proc) self.funcs << ext_function end func_section.func_indices.each_with_index do |sigindex, findex| callsig = type_section.defined_types[sigindex] retsig = type_section.defined_results[sigindex] codes = code_section.func_codes[findex] wasm_function = WasmFunction.new(callsig, retsig, codes) self.funcs << wasm_function end end @memories = [] memory_section = inst.memory_section if memory_section memory_section.limits.each do |(min, max)| self.memories << Memory.new(min, max) end data_section = inst.data_section if data_section data_section.segments.each do |segment| memory = self.memories[segment.flags] if !memory raise GenericError, "invalid memory index: #{segment.flags}" end data_start = segment.offset data_end = segment.offset + segment.data.size if data_end > memory.data.size raise GenericError, "data too large for memory" end memory.data[data_start...data_end] = segment.data end end end end |
Instance Attribute Details
#memories ⇒ Object
FIXME: attr_accessor :modules
1081 1082 1083 |
# File 'lib/wardite.rb', line 1081 def memories @memories end |
Instance Method Details
#[](idx) ⇒ Object
1147 1148 1149 |
# File 'lib/wardite.rb', line 1147 def [](idx) @funcs[idx] end |