@@ -344,7 +344,8 @@ impl Val {
344
344
VMErrorKind :: BuiltinTypeError { expected, got } ,
345
345
) ) ;
346
346
}
347
- self . tobj ( vm) . unwrap ( ) . as_gc ( ) . and ( vm, other)
347
+ debug_assert_eq ! ( self . valkind( ) , ValKind :: GCBOX ) ;
348
+ unsafe { self . gcbox_to_tobj ( ) } . as_gc ( ) . and ( vm, other)
348
349
}
349
350
350
351
/// Produce a new `Val` which divides `other` from this.
@@ -371,7 +372,8 @@ impl Val {
371
372
let got = other. dyn_objtype ( vm) ;
372
373
return Err ( VMError :: new ( vm, VMErrorKind :: NotANumber { got } ) ) ;
373
374
}
374
- self . tobj ( vm) . unwrap ( ) . as_gc ( ) . div ( vm, other)
375
+ debug_assert_eq ! ( self . valkind( ) , ValKind :: GCBOX ) ;
376
+ unsafe { self . gcbox_to_tobj ( ) } . as_gc ( ) . div ( vm, other)
375
377
}
376
378
377
379
/// Produce a new `Val` which perfoms a Double divide on `other` with this.
@@ -399,7 +401,10 @@ impl Val {
399
401
let got = other. dyn_objtype ( vm) ;
400
402
return Err ( VMError :: new ( vm, VMErrorKind :: NotANumber { got } ) ) ;
401
403
}
402
- self . tobj ( vm) . unwrap ( ) . as_gc ( ) . double_div ( vm, other)
404
+ debug_assert_eq ! ( self . valkind( ) , ValKind :: GCBOX ) ;
405
+ unsafe { self . gcbox_to_tobj ( ) }
406
+ . as_gc ( )
407
+ . double_div ( vm, other)
403
408
}
404
409
405
410
/// Produce a new `Val` which performs a mod operation on this with `other`.
@@ -420,7 +425,8 @@ impl Val {
420
425
let got = other. dyn_objtype ( vm) ;
421
426
return Err ( VMError :: new ( vm, VMErrorKind :: NotANumber { got } ) ) ;
422
427
}
423
- self . tobj ( vm) . unwrap ( ) . as_gc ( ) . modulus ( vm, other)
428
+ debug_assert_eq ! ( self . valkind( ) , ValKind :: GCBOX ) ;
429
+ unsafe { self . gcbox_to_tobj ( ) } . as_gc ( ) . modulus ( vm, other)
424
430
}
425
431
426
432
/// Produce a new `Val` which multiplies `other` to this.
@@ -450,7 +456,8 @@ impl Val {
450
456
let got = other. dyn_objtype ( vm) ;
451
457
return Err ( VMError :: new ( vm, VMErrorKind :: NotANumber { got } ) ) ;
452
458
}
453
- self . tobj ( vm) . unwrap ( ) . as_gc ( ) . remainder ( vm, other)
459
+ debug_assert_eq ! ( self . valkind( ) , ValKind :: GCBOX ) ;
460
+ unsafe { self . gcbox_to_tobj ( ) } . as_gc ( ) . remainder ( vm, other)
454
461
}
455
462
456
463
/// Produce a new `Val` which shifts `self` `other` bits to the left.
@@ -485,7 +492,8 @@ impl Val {
485
492
let got = other. dyn_objtype ( vm) ;
486
493
return Err ( VMError :: new ( vm, VMErrorKind :: NotANumber { got } ) ) ;
487
494
}
488
- self . tobj ( vm) . unwrap ( ) . as_gc ( ) . shl ( vm, other)
495
+ debug_assert_eq ! ( self . valkind( ) , ValKind :: GCBOX ) ;
496
+ unsafe { self . gcbox_to_tobj ( ) } . as_gc ( ) . shl ( vm, other)
489
497
}
490
498
491
499
/// Produce a new `Val` which shifts `self` `other` bits to the right, treating `self` as if it
@@ -507,7 +515,8 @@ impl Val {
507
515
let got = other. dyn_objtype ( vm) ;
508
516
return Err ( VMError :: new ( vm, VMErrorKind :: NotANumber { got } ) ) ;
509
517
}
510
- self . tobj ( vm) . unwrap ( ) . as_gc ( ) . shr ( vm, other)
518
+ debug_assert_eq ! ( self . valkind( ) , ValKind :: GCBOX ) ;
519
+ unsafe { self . gcbox_to_tobj ( ) } . as_gc ( ) . shr ( vm, other)
511
520
}
512
521
513
522
/// Produces a new `Val` which is the square root of this.
@@ -524,7 +533,8 @@ impl Val {
524
533
}
525
534
}
526
535
}
527
- self . tobj ( vm) . unwrap ( ) . as_gc ( ) . sqrt ( vm)
536
+ debug_assert_eq ! ( self . valkind( ) , ValKind :: GCBOX ) ;
537
+ unsafe { self . gcbox_to_tobj ( ) } . as_gc ( ) . sqrt ( vm)
528
538
}
529
539
530
540
/// Produce a new `Val` which subtracts `other` from this.
@@ -556,15 +566,18 @@ impl Val {
556
566
VMErrorKind :: BuiltinTypeError { expected, got } ,
557
567
) ) ;
558
568
}
559
- self . tobj ( vm) . unwrap ( ) . as_gc ( ) . xor ( vm, other)
569
+ debug_assert_eq ! ( self . valkind( ) , ValKind :: GCBOX ) ;
570
+ unsafe { self . gcbox_to_tobj ( ) } . as_gc ( ) . xor ( vm, other)
560
571
}
561
572
562
573
/// Is this `Val` reference equal to `other`? Notice that for integers (but not Doubles)
563
574
/// "reference equal" is equivalent to "equals".
564
575
pub fn ref_equals ( & self , vm : & mut VM , other : Val ) -> Result < Val , Box < VMError > > {
565
576
match self . valkind ( ) {
566
577
ValKind :: INT => self . equals ( vm, other) ,
567
- ValKind :: GCBOX => self . tobj ( vm) ?. as_gc ( ) . ref_equals ( vm, other) ,
578
+ ValKind :: GCBOX => unsafe { self . gcbox_to_tobj ( ) }
579
+ . as_gc ( )
580
+ . ref_equals ( vm, other) ,
568
581
ValKind :: ILLEGAL => unreachable ! ( ) ,
569
582
}
570
583
}
@@ -586,7 +599,8 @@ macro_rules! binop_all {
586
599
Ok ( vm. $tf)
587
600
}
588
601
} else {
589
- self . tobj( vm) . unwrap( ) . as_gc( ) . $name( vm, other)
602
+ debug_assert_eq!( self . valkind( ) , ValKind :: GCBOX ) ;
603
+ unsafe { self . gcbox_to_tobj( ) } . as_gc( ) . $name( vm, other)
590
604
}
591
605
}
592
606
}
@@ -610,7 +624,8 @@ macro_rules! binop_typeerror {
610
624
} ) )
611
625
}
612
626
} else {
613
- self . tobj( vm) . unwrap( ) . as_gc( ) . $name( vm, other)
627
+ debug_assert_eq!( self . valkind( ) , ValKind :: GCBOX ) ;
628
+ unsafe { self . gcbox_to_tobj( ) } . as_gc( ) . $name( vm, other)
614
629
}
615
630
}
616
631
}
0 commit comments