@@ -452,35 +452,6 @@ export class Compiler extends DiagnosticEmitter {
452
452
}
453
453
}
454
454
455
- // compile the start function if not empty or if explicitly requested
456
- var startIsEmpty = ! startFunctionBody . length ;
457
- var explicitStart = program . isWasi || options . explicitStart ;
458
- if ( ! startIsEmpty || explicitStart ) {
459
- let signature = startFunctionInstance . signature ;
460
- if ( ! startIsEmpty && explicitStart ) {
461
- module . addGlobal ( BuiltinNames . started , NativeType . I32 , true , module . i32 ( 0 ) ) ;
462
- startFunctionBody . unshift (
463
- module . global_set ( BuiltinNames . started , module . i32 ( 1 ) )
464
- ) ;
465
- startFunctionBody . unshift (
466
- module . if (
467
- module . global_get ( BuiltinNames . started , NativeType . I32 ) ,
468
- module . return ( )
469
- )
470
- ) ;
471
- }
472
- let funcRef = module . addFunction (
473
- startFunctionInstance . internalName ,
474
- signature . nativeParams ,
475
- signature . nativeResults ,
476
- typesToNativeTypes ( startFunctionInstance . additionalLocals ) ,
477
- module . flatten ( startFunctionBody )
478
- ) ;
479
- startFunctionInstance . finalize ( module , funcRef ) ;
480
- if ( ! explicitStart ) module . setStart ( funcRef ) ;
481
- else module . addFunctionExport ( startFunctionInstance . internalName , ExportNames . start ) ;
482
- }
483
-
484
455
// check if the entire program is acyclic
485
456
var cyclicClasses = program . findCyclicClasses ( ) ;
486
457
if ( cyclicClasses . size ) {
@@ -520,6 +491,37 @@ export class Compiler extends DiagnosticEmitter {
520
491
compileClassInstanceOf ( this , prototype ) ;
521
492
}
522
493
494
+ // NOTE: no more element compiles from here. may go to the start function!
495
+
496
+ // compile the start function if not empty or if explicitly requested
497
+ var startIsEmpty = ! startFunctionBody . length ;
498
+ var explicitStart = program . isWasi || options . explicitStart ;
499
+ if ( ! startIsEmpty || explicitStart ) {
500
+ let signature = startFunctionInstance . signature ;
501
+ if ( ! startIsEmpty && explicitStart ) {
502
+ module . addGlobal ( BuiltinNames . started , NativeType . I32 , true , module . i32 ( 0 ) ) ;
503
+ startFunctionBody . unshift (
504
+ module . global_set ( BuiltinNames . started , module . i32 ( 1 ) )
505
+ ) ;
506
+ startFunctionBody . unshift (
507
+ module . if (
508
+ module . global_get ( BuiltinNames . started , NativeType . I32 ) ,
509
+ module . return ( )
510
+ )
511
+ ) ;
512
+ }
513
+ let funcRef = module . addFunction (
514
+ startFunctionInstance . internalName ,
515
+ signature . nativeParams ,
516
+ signature . nativeResults ,
517
+ typesToNativeTypes ( startFunctionInstance . additionalLocals ) ,
518
+ module . flatten ( startFunctionBody )
519
+ ) ;
520
+ startFunctionInstance . finalize ( module , funcRef ) ;
521
+ if ( ! explicitStart ) module . setStart ( funcRef ) ;
522
+ else module . addFunctionExport ( startFunctionInstance . internalName , ExportNames . start ) ;
523
+ }
524
+
523
525
// set up virtual lookup tables
524
526
var functionTable = this . functionTable ;
525
527
for ( let i = 0 , k = functionTable . length ; i < k ; ++ i ) {
0 commit comments