@@ -13,6 +13,8 @@ const wasmTypes = {
1313 ipointer : 'i32' ,
1414 opointer : 'i32' ,
1515 gasLimit : 'i64' ,
16+ callReturnMemoryOffset : 'i32' ,
17+ callReturnMemorySize : 'i32' ,
1618 // FIXME: these are handled wrongly currently
1719 address : 'i32' ,
1820 i128 : 'i32' ,
@@ -140,19 +142,19 @@ const interfaceManifest = {
140142 CALL : {
141143 name : 'call' ,
142144 async : true ,
143- input : [ 'gasLimit' , 'address' , 'i128' , 'readOffset' , 'length' ] ,
145+ input : [ 'gasLimit' , 'address' , 'i128' , 'readOffset' , 'length' , 'callReturnMemoryOffset' , 'callReturnMemorySize' ] ,
144146 output : [ 'i32' ]
145147 } ,
146148 CALLCODE : {
147149 name : 'callCode' ,
148150 async : true ,
149- input : [ 'gasLimit' , 'address' , 'i128' , 'readOffset' , 'length' ] ,
151+ input : [ 'gasLimit' , 'address' , 'i128' , 'readOffset' , 'length' , 'callReturnMemoryOffset' , 'callReturnMemorySize' ] ,
150152 output : [ 'i32' ]
151153 } ,
152154 DELEGATECALL : {
153155 name : 'callDelegate' ,
154156 async : true ,
155- input : [ 'gasLimit' , 'address' , 'i128' , 'readOffset' , 'length' , 'writeOffset' , 'length' ] ,
157+ input : [ 'gasLimit' , 'address' , 'i128' , 'readOffset' , 'length' , 'writeOffset' , 'length' , 'callReturnMemoryOffset' , 'callReturnMemorySize' ] ,
156158 output : [ 'i32' ]
157159 } ,
158160 SSTORE : {
@@ -207,7 +209,8 @@ function generateManifest (interfaceManifest, opts) {
207209 for ( let opcode in interfaceManifest ) {
208210 const op = interfaceManifest [ opcode ]
209211 // Translate input types to native wasm types
210- let inputs = op . input . map ( type => toWasmType ( type ) )
212+ // callReturnMemoryOffset and callReturnMemorySize are actually output and must be ignored here
213+ let inputs = op . input . filter ( type => type !== 'callReturnMemoryOffset' && type !== 'callReturnMemorySize' ) . map ( type => toWasmType ( type ) )
211214 // Also add output types which are non-basic because they need to be passed as inputs
212215 inputs = inputs . concat ( op . output . filter ( type => type !== 'i32' && type !== 'i64' ) . map ( type => toWasmType ( type ) ) )
213216 let params = ''
@@ -289,6 +292,12 @@ function generateManifest (interfaceManifest, opts) {
289292 locals += `(local $offset${ numOfLocals } i32)`
290293 body += `(set_local $offset${ numOfLocals } ${ checkOverflowStackItem256 ( spOffset ) } )`
291294 call += `(get_local $offset${ numOfLocals } )`
295+ } else if ( input === 'callReturnMemoryOffset' || input === 'callReturnMemorySize' ) {
296+ // FIXME: this should actually insert a wrapper for invoking returndatacopy
297+ // with these arguments in the postprocessing step
298+
299+ // Remove (ignore) this stack item here
300+ spOffset --
292301 } else if ( input === 'length' && ( opcode === 'CALL' || opcode === 'CALLCODE' ) ) {
293302 // CALLs in EVM have 7 arguments
294303 // but in ewasm CALLs only have 5 arguments
@@ -303,12 +312,6 @@ function generateManifest (interfaceManifest, opts) {
303312
304313 call += `(get_local $length${ numOfLocals } )`
305314 numOfLocals ++
306-
307- // delete 6th stack element
308- spOffset --
309-
310- // delete 7th stack element
311- spOffset --
312315 } else if ( input === 'length' && ( opcode !== 'CALL' && opcode !== 'CALLCODE' ) ) {
313316 locals += `(local $length${ numOfLocals } i32)`
314317 body += `(set_local $length${ numOfLocals } ${ checkOverflowStackItem256 ( spOffset ) } )`
@@ -376,6 +379,8 @@ function generateManifest (interfaceManifest, opts) {
376379 (i32.eqz ${ call } ) ;; flip CALL result from EEI to EVM convention (0 -> 1, 1,2,.. -> 1)
377380 )))`
378381
382+ // FIXME: add callReturnMemory* handling here
383+
379384 } else {
380385 call =
381386 `(i64.store
0 commit comments