@@ -472,14 +472,8 @@ impl Vm {
472
472
H : ToTypeHash ,
473
473
A : GuardedArgs ,
474
474
{
475
- let count = args. count ( ) ;
476
- let full_count = args. count ( ) + 1 ;
475
+ let count = args. count ( ) . wrapping_add ( 1 ) ;
477
476
let type_hash = vm_try ! ( target. type_hash( ) ) ;
478
- self . stack . push ( target) ;
479
-
480
- // Safety: We hold onto the guard for the duration of this call.
481
- let _guard = unsafe { vm_try ! ( args. unsafe_into_stack( & mut self . stack) ) } ;
482
-
483
477
let hash = Hash :: associated_function ( type_hash, hash. to_type_hash ( ) ) ;
484
478
485
479
if let Some ( UnitFn :: Offset {
@@ -488,19 +482,22 @@ impl Vm {
488
482
args : expected,
489
483
} ) = self . unit . function ( hash)
490
484
{
491
- vm_try ! ( check_args( full_count, expected) ) ;
492
- vm_try ! ( self . call_offset_fn( offset, call, full_count) ) ;
485
+ self . stack . push ( target) ;
486
+ // Safety: We hold onto the guard for the duration of this call.
487
+ let _guard = unsafe { vm_try ! ( args. unsafe_into_stack( & mut self . stack) ) } ;
488
+ vm_try ! ( check_args( count, expected) ) ;
489
+ vm_try ! ( self . call_offset_fn( offset, call, count) ) ;
493
490
return VmResult :: Ok ( CallResult :: Ok ( ( ) ) ) ;
494
491
}
495
492
496
493
if let Some ( handler) = self . context . function ( hash) {
497
- vm_try ! ( handler( & mut self . stack, full_count) ) ;
494
+ self . stack . push ( target) ;
495
+ // Safety: We hold onto the guard for the duration of this call.
496
+ let _guard = unsafe { vm_try ! ( args. unsafe_into_stack( & mut self . stack) ) } ;
497
+ vm_try ! ( handler( & mut self . stack, count) ) ;
498
498
return VmResult :: Ok ( CallResult :: Ok ( ( ) ) ) ;
499
499
}
500
500
501
- // Restore the stack!
502
- vm_try ! ( self . stack. popn( count) ) ;
503
- let target = vm_try ! ( self . stack. pop( ) ) ;
504
501
VmResult :: Ok ( CallResult :: Unsupported ( target) )
505
502
}
506
503
@@ -515,23 +512,18 @@ impl Vm {
515
512
) -> VmResult < CallResult < ( ) > >
516
513
where
517
514
N : IntoHash ,
518
- A : Args ,
515
+ A : GuardedArgs ,
519
516
{
520
- let count = args. count ( ) ;
521
- let full_count = count + 1 ;
517
+ let count = args. count ( ) . wrapping_add ( 1 ) ;
522
518
let hash = Hash :: field_function ( protocol, vm_try ! ( target. type_hash( ) ) , name) ;
523
519
524
- self . stack . push ( target) ;
525
- vm_try ! ( args. into_stack( & mut self . stack) ) ;
526
-
527
520
if let Some ( handler) = self . context . function ( hash) {
528
- vm_try ! ( handler( & mut self . stack, full_count) ) ;
521
+ self . stack . push ( target) ;
522
+ let _guard = unsafe { vm_try ! ( args. unsafe_into_stack( & mut self . stack) ) } ;
523
+ vm_try ! ( handler( & mut self . stack, count) ) ;
529
524
return VmResult :: Ok ( CallResult :: Ok ( ( ) ) ) ;
530
525
}
531
526
532
- // Restore the stack!
533
- vm_try ! ( self . stack. popn( count) ) ;
534
- let target = vm_try ! ( self . stack. pop( ) ) ;
535
527
VmResult :: Ok ( CallResult :: Unsupported ( target) )
536
528
}
537
529
@@ -545,23 +537,18 @@ impl Vm {
545
537
args : A ,
546
538
) -> VmResult < CallResult < ( ) > >
547
539
where
548
- A : Args ,
540
+ A : GuardedArgs ,
549
541
{
550
- let count = args. count ( ) ;
551
- let full_count = count + 1 ;
542
+ let count = args. count ( ) . wrapping_add ( 1 ) ;
552
543
let hash = Hash :: index_function ( protocol, vm_try ! ( target. type_hash( ) ) , Hash :: index ( index) ) ;
553
544
554
- self . stack . push ( target) ;
555
- vm_try ! ( args. into_stack( & mut self . stack) ) ;
556
-
557
545
if let Some ( handler) = self . context . function ( hash) {
558
- vm_try ! ( handler( & mut self . stack, full_count) ) ;
546
+ self . stack . push ( target) ;
547
+ let _guard = unsafe { vm_try ! ( args. unsafe_into_stack( & mut self . stack) ) } ;
548
+ vm_try ! ( handler( & mut self . stack, count) ) ;
559
549
return VmResult :: Ok ( CallResult :: Ok ( ( ) ) ) ;
560
550
}
561
551
562
- // Restore the stack!
563
- vm_try ! ( self . stack. popn( count) ) ;
564
- let target = vm_try ! ( self . stack. pop( ) ) ;
565
552
VmResult :: Ok ( CallResult :: Unsupported ( target) )
566
553
}
567
554
@@ -1257,7 +1244,7 @@ impl Vm {
1257
1244
}
1258
1245
TargetFallback :: Index ( lhs, index, rhs) => {
1259
1246
if let CallResult :: Unsupported ( lhs) =
1260
- vm_try ! ( self . call_index_fn( protocol, lhs. clone( ) , index, ( rhs, ) ) )
1247
+ vm_try ! ( self . call_index_fn( protocol, lhs. clone( ) , index, ( & rhs, ) ) )
1261
1248
{
1262
1249
return err ( VmErrorKind :: UnsupportedTupleIndexGet {
1263
1250
target : vm_try ! ( lhs. type_info( ) ) ,
0 commit comments