@@ -6431,7 +6431,6 @@ export class Compiler extends DiagnosticEmitter {
64316431 let _values = Map_values ( locals ) ;
64326432 var exprs = new Array < ExpressionRef > ( _values . length ) ;
64336433 assert ( type . is ( TypeFlags . REFERENCE ) ) ;
6434- var closureClass = assert ( type . classReference ) ;
64356434 for ( let i = 0 , k = _values . length ; i < k ; ++ i ) {
64366435 let local = unchecked ( _values [ i ] ) ;
64376436 let nativeType = local . type . toNativeType ( ) ;
@@ -6440,7 +6439,7 @@ export class Compiler extends DiagnosticEmitter {
64406439 module . local_get ( closureContextLocal . index , this . options . nativeSizeType ) ,
64416440 module . local_get ( local . index , nativeType ) ,
64426441 nativeType ,
6443- closureClass . offsetof ( local . name )
6442+ assert ( local . closureContextOffset )
64446443 ) ;
64456444 }
64466445 return module . block ( null , exprs ) ;
@@ -8208,28 +8207,9 @@ export class Compiler extends DiagnosticEmitter {
82088207 var wasm64 = nativeUsize == NativeType . I64 ;
82098208
82108209 if ( instance . closedLocals . size > 0 ) {
8211- // Create field declarations for the function and each closed local
8212- var members = Array < DeclarationStatement > ( instance . closedLocals . size + 1 ) ;
8213- members [ 0 ] = this . program . makeNativeMember ( "__functionPtr" , usize . toString ( ) )
8214- for ( let _values = Map_values ( instance . closedLocals ) , i = 0 , k = _values . length ; i < k ; ++ i ) {
8215- let local = unchecked ( _values [ i ] ) ;
8216- members [ i + 1 ] = this . program . makeNativeMember ( local . name , local . type . intType . toString ( ) ) ;
8217- }
8218-
8219- // Create a native class prototype with a dummy syntax tree, similar to native functions
8220- var closureClassPrototype = assert ( this . program . makeNativeClassPrototype (
8221- "closure|" + this . program . nextClassId . toString ( ) ,
8222- members
8223- ) ) ;
8224-
8225- // Resolve this prototype to get the class
8226- var closureClass = assert ( this . resolver . resolveClass ( closureClassPrototype , null ) ) ;
8227-
8228- // Compile this class to get the type
8229- this . compileClass ( closureClass ) ;
8230-
82318210 // Append the appropriate signature and flags for this closure type, then set it to currentType
8232- this . currentType = closureClass . type . asClosure ( instance . signature )
8211+ this . currentType = Type . closure32 ;
8212+ this . currentType . signatureReference = instance . signature ;
82338213
82348214 // create a local which will hold our closure class instance
82358215 var tempLocal = flow . getAutoreleaseLocal ( this . currentType ) ;
@@ -8238,14 +8218,15 @@ export class Compiler extends DiagnosticEmitter {
82388218 // copied closed locals into type
82398219 this . currentType . locals = instance . closedLocals ;
82408220
8221+ const closureSize = instance . nextGlobalClosureOffset
82418222
82428223 var closureExpr = this . module . flatten ( [
82438224 this . module . local_set ( // Allocate memory for the closure
82448225 tempLocalIndex ,
82458226 this . makeRetain (
82468227 this . module . call ( this . program . allocInstance . internalName , [
8247- wasm64 ? this . module . i64 ( closureClass . type . byteSize ) : this . module . i32 ( closureClass . type . byteSize ) ,
8248- wasm64 ? this . module . i64 ( closureClass . id ) : this . module . i32 ( closureClass . id )
8228+ wasm64 ? this . module . i64 ( closureSize ) : this . module . i32 ( closureSize ) ,
8229+ wasm64 ? this . module . i64 ( 0 ) : this . module . i32 ( 0 )
82498230 ] , nativeUsize )
82508231 )
82518232 ) ,
0 commit comments