@@ -11,24 +11,24 @@ use crate::{
1111 AsObject , Context , PyObject , PyObjectRef , PyPayload , PyRef , PyResult , VirtualMachine ,
1212} ;
1313use num_traits:: Zero ;
14- use std:: { fmt, ops:: Deref } ;
14+ use std:: { borrow :: Borrow , fmt, ops:: Deref } ;
1515
1616#[ derive( Clone ) ]
17- pub struct PyConstant ( pub PyObjectRef ) ;
18- // pub(crate) enum PyConstant {
19- // Integer { value: super::int::PyIntRef },
20- // Float { value: super::int::PyFloatRef },
21- // Complex { value: super::complex::PyComplexRef },
22- // Boolean { value: super::int::PyIntRef },
23- // Str { value: super::pystr::PyStrRef },
24- // Bytes { value: super::bytes::PyBytesRef },
25- // Code { code: PyRef<PyCode> },
26- // Tuple { elements: super::tuple::PyTupleRef },
27- // None(PyObjectRef),
28- // Ellipsis(PyObjectRef),
29- // }
30-
31- fn borrow_obj_constant ( obj : & PyObject ) -> BorrowedConstant < PyConstant > {
17+ pub struct Literal ( PyObjectRef ) ;
18+
19+ impl Borrow < PyObject > for Literal {
20+ fn borrow ( & self ) -> & PyObject {
21+ & self . 0
22+ }
23+ }
24+
25+ impl From < Literal > for PyObjectRef {
26+ fn from ( obj : Literal ) -> Self {
27+ obj . 0
28+ }
29+ }
30+
31+ fn borrow_obj_constant ( obj : & PyObject ) -> BorrowedConstant < Literal > {
3232 match_class ! ( match obj {
3333 ref i @ super :: int:: PyInt => {
3434 let value = i. as_bigint( ) ;
@@ -62,7 +62,7 @@ fn borrow_obj_constant(obj: &PyObject) -> BorrowedConstant<PyConstant> {
6262 } )
6363}
6464
65- impl Constant for PyConstant {
65+ impl Constant for Literal {
6666 type Name = PyStrRef ;
6767 fn borrow_constant ( & self ) -> BorrowedConstant < Self > {
6868 borrow_obj_constant ( & self . 0 )
@@ -73,7 +73,7 @@ impl Constant for PyConstant {
7373pub ( crate ) struct PyObjBag < ' a > ( pub & ' a Context ) ;
7474
7575impl ConstantBag for PyObjBag < ' _ > {
76- type Constant = PyConstant ;
76+ type Constant = Literal ;
7777
7878 fn make_constant < C : Constant > ( & self , constant : BorrowedConstant < C > ) -> Self :: Constant {
7979 let ctx = self . 0 ;
@@ -100,15 +100,15 @@ impl ConstantBag for PyObjBag<'_> {
100100 bytecode:: BorrowedConstant :: None => ctx. none ( ) ,
101101 bytecode:: BorrowedConstant :: Ellipsis => ctx. ellipsis ( ) ,
102102 } ;
103- PyConstant ( obj)
103+ Literal ( obj)
104104 }
105105
106106 fn make_name ( & self , name : & str ) -> PyStrRef {
107107 self . 0 . intern_string ( name) . into_pyref ( )
108108 }
109109}
110110
111- pub type CodeObject = bytecode:: CodeObject < PyConstant > ;
111+ pub type CodeObject = bytecode:: CodeObject < Literal > ;
112112
113113pub trait IntoCodeObject {
114114 fn into_codeobj ( self , ctx : & Context ) -> CodeObject ;
0 commit comments