@@ -6431,7 +6431,6 @@ export class Compiler extends DiagnosticEmitter {
6431
6431
let _values = Map_values ( locals ) ;
6432
6432
var exprs = new Array < ExpressionRef > ( _values . length ) ;
6433
6433
assert ( type . is ( TypeFlags . REFERENCE ) ) ;
6434
- var closureClass = assert ( type . classReference ) ;
6435
6434
for ( let i = 0 , k = _values . length ; i < k ; ++ i ) {
6436
6435
let local = unchecked ( _values [ i ] ) ;
6437
6436
let nativeType = local . type . toNativeType ( ) ;
@@ -6440,7 +6439,7 @@ export class Compiler extends DiagnosticEmitter {
6440
6439
module . local_get ( closureContextLocal . index , this . options . nativeSizeType ) ,
6441
6440
module . local_get ( local . index , nativeType ) ,
6442
6441
nativeType ,
6443
- closureClass . offsetof ( local . name )
6442
+ assert ( local . closureContextOffset )
6444
6443
) ;
6445
6444
}
6446
6445
return module . block ( null , exprs ) ;
@@ -8208,28 +8207,9 @@ export class Compiler extends DiagnosticEmitter {
8208
8207
var wasm64 = nativeUsize == NativeType . I64 ;
8209
8208
8210
8209
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
-
8231
8210
// 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 ;
8233
8213
8234
8214
// create a local which will hold our closure class instance
8235
8215
var tempLocal = flow . getAutoreleaseLocal ( this . currentType ) ;
@@ -8238,14 +8218,15 @@ export class Compiler extends DiagnosticEmitter {
8238
8218
// copied closed locals into type
8239
8219
this . currentType . locals = instance . closedLocals ;
8240
8220
8221
+ const closureSize = instance . nextGlobalClosureOffset
8241
8222
8242
8223
var closureExpr = this . module . flatten ( [
8243
8224
this . module . local_set ( // Allocate memory for the closure
8244
8225
tempLocalIndex ,
8245
8226
this . makeRetain (
8246
8227
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 )
8249
8230
] , nativeUsize )
8250
8231
)
8251
8232
) ,
0 commit comments