@@ -5,18 +5,23 @@ use std::iter;
55use std:: ops:: RangeInclusive ;
66use std:: rc:: { Rc , Weak } ;
77
8+ use num_bigint:: BigInt ;
9+ use num_bigint:: ToBigInt ;
10+ use num_complex:: Complex64 ;
11+ use num_traits:: { One , Zero } ;
12+
813use crate :: bytecode;
914use crate :: exceptions;
1015use crate :: frame:: { Frame , Scope , ScopeRef } ;
1116use crate :: obj:: objbool;
1217use crate :: obj:: objbytearray;
1318use crate :: obj:: objbytes;
1419use crate :: obj:: objcode;
15- use crate :: obj:: objcomplex;
20+ use crate :: obj:: objcomplex:: { self , PyComplex } ;
1621use crate :: obj:: objdict;
1722use crate :: obj:: objenumerate;
1823use crate :: obj:: objfilter;
19- use crate :: obj:: objfloat;
24+ use crate :: obj:: objfloat:: { self , PyFloat } ;
2025use crate :: obj:: objframe;
2126use crate :: obj:: objfunction;
2227use crate :: obj:: objgenerator;
@@ -37,10 +42,6 @@ use crate::obj::objtuple;
3742use crate :: obj:: objtype;
3843use crate :: obj:: objzip;
3944use crate :: vm:: VirtualMachine ;
40- use num_bigint:: BigInt ;
41- use num_bigint:: ToBigInt ;
42- use num_complex:: Complex64 ;
43- use num_traits:: { One , Zero } ;
4445
4546/* Python objects and references.
4647
@@ -463,14 +464,19 @@ impl PyContext {
463464pub fn new_float ( & self , value : f64 ) ->PyObjectRef {
464465PyObject :: new (
465466PyObjectPayload :: AnyRustValue {
466- value : Box :: new ( objfloat :: PyFloat :: from ( value) ) ,
467+ value : Box :: new ( PyFloat :: from ( value) ) ,
467468} ,
468469self . float_type ( ) ,
469470)
470471}
471472
472- pub fn new_complex ( & self , i : Complex64 ) ->PyObjectRef {
473- PyObject :: new ( PyObjectPayload :: Complex { value : i} , self . complex_type ( ) )
473+ pub fn new_complex ( & self , value : Complex64 ) ->PyObjectRef {
474+ PyObject :: new (
475+ PyObjectPayload :: AnyRustValue {
476+ value : Box :: new ( PyComplex :: from ( value) ) ,
477+ } ,
478+ self . complex_type ( ) ,
479+ )
474480}
475481
476482pub fn new_str ( & self , s : String ) ->PyObjectRef {
@@ -1408,9 +1414,6 @@ pub enum PyObjectPayload {
14081414Integer {
14091415value : BigInt ,
14101416} ,
1411- Complex {
1412- value : Complex64 ,
1413- } ,
14141417Sequence {
14151418elements : RefCell < Vec < PyObjectRef > > ,
14161419} ,
@@ -1494,7 +1497,6 @@ impl fmt::Debug for PyObjectPayload {
14941497fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
14951498match self {
14961499PyObjectPayload :: Integer { ref value} =>write ! ( f, "int {}" , value) ,
1497- PyObjectPayload :: Complex { ref value} =>write ! ( f, "complex {}" , value) ,
14981500PyObjectPayload :: MemoryView { ref obj} =>write ! ( f, "bytes/bytearray {:?}" , obj) ,
14991501PyObjectPayload :: Sequence { ..} =>write ! ( f, "list or tuple" ) ,
15001502PyObjectPayload :: Dict { ..} =>write ! ( f, "dict" ) ,