@@ -297,6 +297,15 @@ export class Module {
297297 }
298298 }
299299
300+ removeFunctionType ( name : string ) : void {
301+ var cStr = allocString ( name ) ;
302+ try {
303+ _BinaryenRemoveFunctionType ( this . ref , cStr ) ;
304+ } finally {
305+ free_memory ( cStr ) ;
306+ }
307+ }
308+
300309 // constants
301310
302311 createI32 ( value : i32 ) : ExpressionRef {
@@ -663,6 +672,28 @@ export class Module {
663672 }
664673 }
665674
675+ private tempName : usize = 0 ;
676+ private hasTempFunc : bool = false ;
677+
678+ addTemporaryFunction ( result : NativeType , paramTypes : NativeType [ ] | null , body : ExpressionRef ) : FunctionRef {
679+ this . hasTempFunc = assert ( ! this . hasTempFunc ) ;
680+ if ( ! this . tempName ) this . tempName = allocString ( "" ) ; // works because strings are interned
681+ var cArr = allocI32Array ( paramTypes ) ;
682+ try {
683+ let typeRef = _BinaryenAddFunctionType ( this . ref , this . tempName , result , cArr , paramTypes ? paramTypes . length : 0 ) ;
684+ return _BinaryenAddFunction ( this . ref , this . tempName , typeRef , 0 , 0 , body ) ;
685+ } finally {
686+ free_memory ( cArr ) ;
687+ }
688+ }
689+
690+ removeTemporaryFunction ( ) : void {
691+ this . hasTempFunc = ! assert ( this . hasTempFunc ) ;
692+ var tempName = assert ( this . tempName ) ;
693+ _BinaryenRemoveFunction ( this . ref , tempName ) ;
694+ _BinaryenRemoveFunctionType ( this . ref , tempName ) ;
695+ }
696+
666697 addFunctionExport (
667698 internalName : string ,
668699 externalName : string
0 commit comments