@@ -548,57 +548,32 @@ fn instruction(js: &mut JsBuilder, instr: &Instruction, log_error: &mut bool) ->
548
548
| Instruction :: CallExport ( _)
549
549
| Instruction :: CallAdapter ( _)
550
550
| Instruction :: CallTableElement ( _)
551
- | Instruction :: DeferCallCore ( _ ) => {
551
+ | Instruction :: DeferFree { align , .. } => {
552
552
let invoc = Invocation :: from ( instr, js. cx . module ) ?;
553
553
let ( mut params, results) = invoc. params_results ( js. cx ) ;
554
+ assert_eq ! ( results, 0 , "deferred calls must have no results" ) ;
555
+ // substract alignment
556
+ params -= 1 ;
554
557
555
558
let mut args = Vec :: new ( ) ;
556
559
let tmp = js. tmp ( ) ;
557
- if invoc. defer ( ) {
558
- // substract alignment
559
- params -= 1 ;
560
- // If the call is deferred, the arguments to the function still need to be
561
- // accessible in the `finally` block, so we declare variables to hold the args
562
- // outside of the try-finally block and then set those to the args.
563
- for ( i, arg) in js. stack [ js. stack . len ( ) - params..] . iter ( ) . enumerate ( ) {
564
- let name = format ! ( "deferred{tmp}_{i}" ) ;
565
- writeln ! ( js. pre_try, "let {name};" ) . unwrap ( ) ;
566
- writeln ! ( js. prelude, "{name} = {arg};" ) . unwrap ( ) ;
567
- args. push ( name) ;
568
- }
569
- // add alignment
570
- args. push ( String :: from ( "4" ) ) ;
571
- } else {
572
- // Otherwise, pop off the number of parameters for the function we're calling.
573
- for _ in 0 ..params {
574
- args. push ( js. pop ( ) ) ;
575
- }
576
- args. reverse ( ) ;
560
+
561
+ // If the call is deferred, the arguments to the function still need to be
562
+ // accessible in the `finally` block, so we declare variables to hold the args
563
+ // outside of the try-finally block and then set those to the args.
564
+ for ( i, arg) in js. stack [ js. stack . len ( ) - params..] . iter ( ) . enumerate ( ) {
565
+ let name = format ! ( "deferred{tmp}_{i}" ) ;
566
+ writeln ! ( js. pre_try, "let {name};" ) . unwrap ( ) ;
567
+ writeln ! ( js. prelude, "{name} = {arg};" ) . unwrap ( ) ;
568
+ args. push ( name) ;
577
569
}
570
+ // add alignment
571
+ args. push ( align. to_string ( ) ) ;
578
572
579
573
// Call the function through an export of the underlying module.
580
574
let call = invoc. invoke ( js. cx , & args, & mut js. prelude , log_error) ?;
581
575
582
- // And then figure out how to actually handle where the call
583
- // happens. This is pretty conditional depending on the number of
584
- // return values of the function.
585
- match ( invoc. defer ( ) , results) {
586
- ( true , 0 ) => {
587
- js. finally ( & format ! ( "{};" , call) ) ;
588
- }
589
- ( true , _) => panic ! ( "deferred calls must have no results" ) ,
590
- ( false , 0 ) => js. prelude ( & format ! ( "{};" , call) ) ,
591
- ( false , n) => {
592
- js. prelude ( & format ! ( "const ret = {};" , call) ) ;
593
- if n == 1 {
594
- js. push ( "ret" . to_string ( ) ) ;
595
- } else {
596
- for i in 0 ..n {
597
- js. push ( format ! ( "ret[{}]" , i) ) ;
598
- }
599
- }
600
- }
601
- }
576
+ js. finally ( & format ! ( "{};" , call) ) ;
602
577
}
603
578
604
579
Instruction :: IntToWasm { input, .. } => {
@@ -1194,8 +1169,8 @@ impl Invocation {
1194
1169
defer : false ,
1195
1170
} ,
1196
1171
1197
- DeferCallCore ( f ) => Invocation :: Core {
1198
- id : * f ,
1172
+ DeferFree { free , .. } => Invocation :: Core {
1173
+ id : * free ,
1199
1174
defer : true ,
1200
1175
} ,
1201
1176
@@ -1264,13 +1239,6 @@ impl Invocation {
1264
1239
}
1265
1240
}
1266
1241
}
1267
-
1268
- fn defer ( & self ) -> bool {
1269
- match self {
1270
- Invocation :: Core { defer, .. } => * defer,
1271
- _ => false ,
1272
- }
1273
- }
1274
1242
}
1275
1243
1276
1244
fn adapter2ts ( ty : & AdapterType , dst : & mut String ) {
0 commit comments