@@ -58,6 +58,7 @@ public struct Module {
5858 public let types : [ FunctionType ]
5959
6060 let moduleImports : ModuleImports
61+ let importedFunctionTypes : [ TypeIndex ]
6162 let memoryTypes : [ MemoryType ]
6263 let tableTypes : [ TableType ]
6364 let allocator : ISeqAllocator
@@ -92,19 +93,20 @@ public struct Module {
9293 self . features = features
9394 self . hasDataCount = hasDataCount
9495
95- var functionTypeIndices : [ TypeIndex ] = [ ]
96+ var importedFunctionTypes : [ TypeIndex ] = [ ]
9697 var globalTypes : [ GlobalType ] = [ ]
9798 var memoryTypes : [ MemoryType ] = [ ]
9899 var tableTypes : [ TableType ] = [ ]
99100
100101 self . moduleImports = ModuleImports . build (
101102 from: imports,
102- functionTypeIndices: & functionTypeIndices ,
103+ functionTypeIndices: & importedFunctionTypes ,
103104 globalTypes: & globalTypes,
104105 memoryTypes: & memoryTypes,
105106 tableTypes: & tableTypes
106107 )
107108 self . types = types
109+ self . importedFunctionTypes = importedFunctionTypes
108110 self . memoryTypes = memoryTypes + memories
109111 self . tableTypes = tableTypes + tables
110112 }
@@ -116,6 +118,19 @@ public struct Module {
116118 return typeSection [ Int ( index) ]
117119 }
118120
121+ internal func resolveFunctionType( _ index: FunctionIndex ) throws -> FunctionType {
122+ guard Int ( index) < functions. count + self . moduleImports. numberOfFunctions else {
123+ throw TranslationError ( " Function index \( index) is out of range " )
124+ }
125+ if Int ( index) < self . moduleImports. numberOfFunctions {
126+ return try Self . resolveType (
127+ importedFunctionTypes [ Int ( index) ] ,
128+ typeSection: types
129+ )
130+ }
131+ return functions [ Int ( index) - self . moduleImports. numberOfFunctions] . type
132+ }
133+
119134 /// Instantiate this module in the given imports.
120135 ///
121136 /// - Parameters:
0 commit comments