@@ -530,38 +530,38 @@ fn builtin_ord(string: Either<PyByteInner, PyStringRef>, vm: &VirtualMachine) ->
530
530
}
531
531
}
532
532
533
- fn builtin_pow ( vm : & VirtualMachine , args : PyFuncArgs ) -> PyResult {
534
- arg_check ! (
535
- vm,
536
- args,
537
- required = [ ( x, None ) , ( y, None ) ] ,
538
- optional = [ ( mod_value, Some ( vm. ctx. int_type( ) ) ) ]
539
- ) ;
540
-
533
+ fn builtin_pow (
534
+ x : PyObjectRef ,
535
+ y : PyObjectRef ,
536
+ mod_value : OptionalArg < PyIntRef > ,
537
+ vm : & VirtualMachine ,
538
+ ) -> PyResult {
541
539
match mod_value {
542
- None => vm. call_or_reflection ( x. clone ( ) , y. clone ( ) , "__pow__" , "__rpow__" , |vm, x, y| {
543
- Err ( vm. new_unsupported_operand_error ( x, y, "pow" ) )
544
- } ) ,
545
- Some ( m) => {
540
+ OptionalArg :: Missing => {
541
+ vm. call_or_reflection ( x. clone ( ) , y. clone ( ) , "__pow__" , "__rpow__" , |vm, x, y| {
542
+ Err ( vm. new_unsupported_operand_error ( x, y, "pow" ) )
543
+ } )
544
+ }
545
+ OptionalArg :: Present ( m) => {
546
546
// Check if the 3rd argument is defined and perform modulus on the result
547
- if !( objtype:: isinstance ( x, & vm. ctx . int_type ( ) )
548
- && objtype:: isinstance ( y, & vm. ctx . int_type ( ) ) )
547
+ if !( objtype:: isinstance ( & x, & vm. ctx . int_type ( ) )
548
+ && objtype:: isinstance ( & y, & vm. ctx . int_type ( ) ) )
549
549
{
550
550
return Err ( vm. new_type_error (
551
551
"pow() 3rd argument not allowed unless all arguments are integers" . to_string ( ) ,
552
552
) ) ;
553
553
}
554
- let y = objint:: get_value ( y) ;
554
+ let y = objint:: get_value ( & y) ;
555
555
if y. sign ( ) == Sign :: Minus {
556
556
return Err ( vm. new_value_error (
557
557
"pow() 2nd argument cannot be negative when 3rd argument specified" . to_string ( ) ,
558
558
) ) ;
559
559
}
560
- let m = objint :: get_value ( m ) ;
560
+ let m = m . as_bigint ( ) ;
561
561
if m. is_zero ( ) {
562
562
return Err ( vm. new_value_error ( "pow() 3rd argument cannot be 0" . to_string ( ) ) ) ;
563
563
}
564
- let x = objint:: get_value ( x) ;
564
+ let x = objint:: get_value ( & x) ;
565
565
Ok ( vm. new_int ( x. modpow ( & y, & m) ) )
566
566
}
567
567
}
0 commit comments