@@ -333,11 +333,7 @@ function generateManifest (interfaceManifest, opts) {
333333 locals += `(local $offset${ numOfLocals } i32)`
334334 body += `(set_local $offset${ numOfLocals } ${ checkOverflowStackItem256 ( spOffset ) } )`
335335 call += `(get_local $offset${ numOfLocals } )`
336- } else if ( input === 'length' && ( opcode === 'CALL' || opcode === 'CALLCODE' || opcode === 'DELEGATECALL' || opcode === 'STATICCALL' ) ) {
337- // CALLs in EVM have 7 arguments
338- // but in ewasm CALLs only have 5 arguments
339- // so delete the bottom two stack elements, after processing the 5th argument
340-
336+ } else if ( input === 'length' ) {
341337 locals += `(local $length${ numOfLocals } i32)`
342338 body += `(set_local $length${ numOfLocals } ${ checkOverflowStackItem256 ( spOffset ) } )`
343339
@@ -348,21 +344,13 @@ function generateManifest (interfaceManifest, opts) {
348344 call += `(get_local $length${ numOfLocals } )`
349345 numOfLocals ++
350346
351- // delete 6th stack element
352- spOffset --
353-
354- // delete 7th stack element
355- spOffset --
356- } else if ( input === 'length' && ( opcode !== 'CALL' && opcode !== 'CALLCODE' && opcode !== 'DELEGATECALL' && opcode !== 'STATICCALL' ) ) {
357- locals += `(local $length${ numOfLocals } i32)`
358- body += `(set_local $length${ numOfLocals } ${ checkOverflowStackItem256 ( spOffset ) } )`
359-
360- body += `
361- (call $memusegas (get_local $offset${ numOfLocals } ) (get_local $length${ numOfLocals } ))
362- (set_local $offset${ numOfLocals } (i32.add (get_global $memstart) (get_local $offset${ numOfLocals } )))`
363-
364- call += `(get_local $length${ numOfLocals } )`
365- numOfLocals ++
347+ // CALLs in EVM have 7 arguments
348+ // but in ewasm CALLs only have 5 arguments
349+ // so delete the bottom two stack elements, after processing the 5th argument
350+ if ( opcode === 'CALL' || opcode === 'CALLCODE' ) {
351+ spOffset --
352+ spOffset --
353+ }
366354 }
367355 spOffset --
368356 } )
@@ -408,21 +396,16 @@ function generateManifest (interfaceManifest, opts) {
408396 call += '(get_local $callback)'
409397 }
410398
411- if ( opcode === 'CALL' || opcode === 'CALLCODE' || opcode === 'DELEGATECALL' || opcode === 'STATICCALL' ) {
412- call =
413- `(i64.store
414- (i32.add (get_global $sp) (i32.const ${ spOffset * 32 } ))
415- (i64.extend_u/i32
416- (i32.eqz ${ call } ) ;; flip CALL result from EEI to EVM convention (0 -> 1, 1,2,.. -> 1)
417- )))`
418-
399+ let wrapper
400+ if ( opcode === 'CALL' || opcode === 'CALLCODE' || opcode === 'DELEGATECALL' ) {
401+ // flip CALL result from EEI to EVM convention (0 -> 1, 1,2,.. -> 0)
402+ wrapper = `(i32.eqz ${ call } )`
419403 } else {
420- call =
421- `(i64.store
422- (i32.add (get_global $sp) (i32.const ${ spOffset * 32 } ))
423- (i64.extend_u/i32
424- ${ call } )))`
404+ wrapper = call
425405 }
406+ call = `(i64.store
407+ (i32.add (get_global $sp) (i32.const ${ spOffset * 32 } ))
408+ (i64.extend_u/i32 ${ wrapper } )))`
426409
427410 call += cleanupStackItem64 ( spOffset )
428411 } else if ( output === 'i64' ) {
0 commit comments