@@ -344,7 +344,8 @@ impl Val {
344344 VMErrorKind :: BuiltinTypeError { expected, got } ,
345345 ) ) ;
346346 }
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)
348349 }
349350
350351 /// Produce a new `Val` which divides `other` from this.
@@ -371,7 +372,8 @@ impl Val {
371372 let got = other. dyn_objtype ( vm) ;
372373 return Err ( VMError :: new ( vm, VMErrorKind :: NotANumber { got } ) ) ;
373374 }
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)
375377 }
376378
377379 /// Produce a new `Val` which perfoms a Double divide on `other` with this.
@@ -399,7 +401,10 @@ impl Val {
399401 let got = other. dyn_objtype ( vm) ;
400402 return Err ( VMError :: new ( vm, VMErrorKind :: NotANumber { got } ) ) ;
401403 }
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)
403408 }
404409
405410 /// Produce a new `Val` which performs a mod operation on this with `other`.
@@ -420,7 +425,8 @@ impl Val {
420425 let got = other. dyn_objtype ( vm) ;
421426 return Err ( VMError :: new ( vm, VMErrorKind :: NotANumber { got } ) ) ;
422427 }
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)
424430 }
425431
426432 /// Produce a new `Val` which multiplies `other` to this.
@@ -450,7 +456,8 @@ impl Val {
450456 let got = other. dyn_objtype ( vm) ;
451457 return Err ( VMError :: new ( vm, VMErrorKind :: NotANumber { got } ) ) ;
452458 }
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)
454461 }
455462
456463 /// Produce a new `Val` which shifts `self` `other` bits to the left.
@@ -485,7 +492,8 @@ impl Val {
485492 let got = other. dyn_objtype ( vm) ;
486493 return Err ( VMError :: new ( vm, VMErrorKind :: NotANumber { got } ) ) ;
487494 }
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)
489497 }
490498
491499 /// Produce a new `Val` which shifts `self` `other` bits to the right, treating `self` as if it
@@ -507,7 +515,8 @@ impl Val {
507515 let got = other. dyn_objtype ( vm) ;
508516 return Err ( VMError :: new ( vm, VMErrorKind :: NotANumber { got } ) ) ;
509517 }
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)
511520 }
512521
513522 /// Produces a new `Val` which is the square root of this.
@@ -524,7 +533,8 @@ impl Val {
524533 }
525534 }
526535 }
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)
528538 }
529539
530540 /// Produce a new `Val` which subtracts `other` from this.
@@ -556,15 +566,18 @@ impl Val {
556566 VMErrorKind :: BuiltinTypeError { expected, got } ,
557567 ) ) ;
558568 }
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)
560571 }
561572
562573 /// Is this `Val` reference equal to `other`? Notice that for integers (but not Doubles)
563574 /// "reference equal" is equivalent to "equals".
564575 pub fn ref_equals ( & self , vm : & mut VM , other : Val ) -> Result < Val , Box < VMError > > {
565576 match self . valkind ( ) {
566577 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) ,
568581 ValKind :: ILLEGAL => unreachable ! ( ) ,
569582 }
570583 }
@@ -586,7 +599,8 @@ macro_rules! binop_all {
586599 Ok ( vm. $tf)
587600 }
588601 } 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)
590604 }
591605 }
592606 }
@@ -610,7 +624,8 @@ macro_rules! binop_typeerror {
610624 } ) )
611625 }
612626 } 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)
614629 }
615630 }
616631 }
0 commit comments