@@ -56,10 +56,8 @@ export class Module {
56
56
57
57
public getID ( id : SectionId ) : SectionHeader [ ] {
58
58
let res : SectionHeader [ ] = [ ] ;
59
- log < i32 > ( 42 ) ;
60
59
let x : i32 = this . Headers . length ;
61
60
for ( let i = 0 ; i < x ; i ++ ) {
62
- // log<u32>(i);
63
61
if ( this . Headers [ i ] . id == id ) {
64
62
res . push ( this . Headers [ i ] ) ;
65
63
}
@@ -197,22 +195,21 @@ class Section {
197
195
class FuncType {
198
196
public parameters : i32 [ ] ;
199
197
public returnVals : i32 [ ] ;
200
- constructor ( public index : u32 , public form : i32 ) {
201
- this . parameters = [ ] ;
202
- this . returnVals = [ ] ;
198
+ constructor ( public index : u32 , public form : i8 ) {
203
199
}
204
200
205
201
206
202
207
203
toString ( ) : string {
208
204
let index = itoa < u32 > ( this . index ) ;
209
205
let form = typeName ( this . form ) ;
210
- let parameters :string [ ] = [ ] ;
206
+ let parameters :string = "" ;
211
207
for ( let i = 0 ; i < this . parameters . length ; i ++ ) {
212
- parameters . push ( typeName ( this . parameters [ i ] ) ) ;
208
+ parameters += typeName ( this . parameters [ i ] ) ;
209
+ parameters = i < this . parameters . length - 1 ? parameters += ", " : parameters ;
213
210
}
214
- let returnVal = this . returnVals . length == 1 ? typeName ( this . returnVals [ 0 ] ) : "" ;
215
- return "index: " + index + ", " + "form: " + form + ", parameters: " + parameters . join ( ", " ) + " returnVal: " + returnVal ;
211
+ let returnVal = this . returnVals . length == 1 ? typeName ( this . returnVals [ 0 ] ) : "void " ;
212
+ return "index: " + index + ", " + "form: " + form + ", ( " + parameters + ") => " + returnVal ;
216
213
}
217
214
}
218
215
@@ -226,53 +223,28 @@ export class TypeSection {
226
223
227
224
// constructor(public header: SectionHeader){}
228
225
parse ( buf : Buffer ) : TypeSection {
229
- log_str ( "parsing TypeSection" ) ;
230
- log < usize > ( buf . off ) ;
231
- log_str ( this . header . name ) ;
232
226
buf . off = this . header . payload_off ;
233
- log < usize > ( buf . off ) ;
234
227
let count = buf . readVaruint ( 32 ) ;
235
- log < usize > ( count ) ;
236
- // let func: FuncType;
237
- let parameters : i32 [ ] ;
228
+ let func : FuncType [ ] = new Array < FuncType > ( count ) ;
238
229
for ( let index : u32 = 0 ; index < count ; ++ index ) {
239
- log < u32 > ( index ) ;
240
- let form = buf . readVarint ( 7 ) & 0x7f ;
241
- // func = new FuncType(index, form);
242
- // opt.onType(
243
- // index,
244
- // form
245
- // );
230
+ let form = buf . readVarint8 ( 7 ) & 0x7f ;
231
+ let fun = new FuncType ( index , form ) ;
232
+ func [ index ] = fun ;
246
233
let paramCount = buf . readVaruint ( 32 ) ;
247
- log_str ( "param count." ) ;
248
- log < u32 > ( paramCount ) ;
249
- parameters = [ ] ;
250
- log < u32 > ( parameters . length ) ;
234
+ fun . parameters = new Array < i32 > ( paramCount ) ;
251
235
for ( let paramIndex : u32 = 0 ; paramIndex < paramCount ; ++ paramIndex ) {
252
- let paramType = buf . readVarint ( 7 ) & 0x7f ;
253
- // opt.onTypeParam(
254
- // index,
255
- // paramIndex,
256
- // paramType
257
- // );
258
- parameters . push ( paramType )
236
+ let paramType = buf . readVarint8 ( 7 ) & 0x7f ;
237
+ func [ index ] . parameters [ paramIndex ] = paramType ;
259
238
}
260
- log < i32 > ( parameters . length ) ;
239
+
261
240
let returnCount = buf . readVaruint ( 1 ) ; // MVP
241
+ func [ index ] . returnVals = new Array < i32 > ( returnCount ) ;
262
242
for ( let returnIndex : u32 = 0 ; returnIndex < returnCount ; ++ returnIndex ) {
263
- let returnType = buf . readVarint ( 7 ) & 0x7f ;
264
- // opt.onTypeReturn(
265
- // index,
266
- // returnIndex,
267
- // returnType
268
- // );
269
- // func.returnVals.push(returnType);
243
+ let returnType = buf . readVarint8 ( 7 ) & 0x7f ;
244
+ func [ index ] . returnVals [ returnIndex ] = returnType ;
270
245
}
271
- // log_str(func.toString());
272
- // this.funcs.push(func);
246
+ log ( func [ index ] . toString ( ) ) ;
273
247
}
274
- // buf.off = this.end;
275
- log_str ( "Finished type section" ) ;
276
248
return this ;
277
249
}
278
250
0 commit comments