11use std:: cell:: { Ref , RefCell , RefMut } ;
22use std:: fmt:: Debug ;
33use std:: rc:: Rc ;
4- use crate :: parser:: CodeBlock ;
4+ // use crate::parser::CodeBlock;
55use crate :: pyarena:: PyArena ;
66use crate :: builtins:: structure:: magic_methods:: { PyMagicMethod } ;
77use crate :: builtins:: structure:: pyclass:: PyClass ;
88use crate :: builtins:: structure:: pyexception:: PyException ;
99use crate :: builtins:: structure:: pyinstance:: PyInstance ;
1010
11+ #[ derive( Debug ) ]
12+ pub enum StatementOperation {
13+ Return ( Option < PyObject > ) ,
14+ Expression ( PyObject ) ,
15+ Pass ,
16+ Continue ,
17+ Break
18+ }
19+
1120#[ derive( Clone , Debug ) ]
1221pub enum PyObject {
1322 Immutable ( Rc < PyImmutableObject > ) , // TODO, consider using Cow's here
1423 Mutable ( PyPointer < PyMutableObject > ) ,
1524 Internal ( PyInternalObject ) ,
16- IteratorFlag ( PyIteratorFlag )
25+ // IteratorFlag(PyIteratorFlag)
1726}
1827
1928impl PyObject {
@@ -48,14 +57,14 @@ impl PyObject {
4857 }
4958
5059
51- pub fn break_ ( ) -> Self { // TODO prob should be moved out of the pyobject class (currently in here for legacy reasons)
52- PyObject :: IteratorFlag ( PyIteratorFlag :: Break )
53- }
54-
55- pub fn continue_ ( ) -> Self { // TODO prob should be moved out of the pyobject class (currently in here for legacy reasons)
56- PyObject :: IteratorFlag ( PyIteratorFlag :: Continue )
57- }
58-
60+ // pub fn break_() -> Self { // TODO prob should be moved out of the pyobject class (currently in here for legacy reasons)
61+ // PyObject::IteratorFlag(PyIteratorFlag::Break)
62+ // }
63+ //
64+ // pub fn continue_() -> Self { // TODO prob should be moved out of the pyobject class (currently in here for legacy reasons)
65+ // PyObject::IteratorFlag(PyIteratorFlag::Continue)
66+ // }
67+ //
5968 pub fn create_new_none ( ) -> Self {
6069 PyObject :: Immutable ( Rc :: new ( PyImmutableObject :: None ) )
6170 }
@@ -68,9 +77,9 @@ impl PyObject {
6877 Self :: new_immutable ( PyImmutableObject :: Bool ( value) )
6978 }
7079
71- pub fn stop_iteration ( ) -> Self { // TODO prob should be moved out of the pyobject class (currently in here for legacy reasons)
72- PyObject :: IteratorFlag ( PyIteratorFlag :: StopIteration )
73- }
80+ // pub fn stop_iteration() -> Self { // TODO prob should be moved out of the pyobject class (currently in here for legacy reasons)
81+ // PyObject::IteratorFlag(PyIteratorFlag::StopIteration)
82+ // }
7483
7584 pub fn expect_immutable ( & self ) -> & Rc < PyImmutableObject > {
7685 match self {
@@ -97,7 +106,7 @@ impl PyObject {
97106 match self {
98107 PyObject :: Immutable ( inner) => inner. get_magic_method ( py_magic_method, arena) ,
99108 PyObject :: Mutable ( inner) => inner. borrow ( ) . get_magic_method ( py_magic_method, arena) ,
100- PyObject :: IteratorFlag ( _) => { panic ! ( "IteratorFlag has no magic methods" ) }
109+ // PyObject::IteratorFlag(_) => {panic!("IteratorFlag has no magic methods")}
101110 PyObject :: Internal ( _) => { todo ! ( ) }
102111 }
103112 }
@@ -106,7 +115,7 @@ impl PyObject {
106115 match * self {
107116 PyObject :: Immutable ( ref inner) => inner. get_class ( arena) . clone ( ) ,
108117 PyObject :: Mutable ( ref inner) => inner. borrow ( ) . get_class ( ) . clone ( ) ,
109- PyObject :: IteratorFlag ( _) => { panic ! ( "IteratorFlag has no class" ) }
118+ // PyObject::IteratorFlag(_) => {panic!("IteratorFlag has no class")}
110119 PyObject :: Internal ( _) => { todo ! ( ) }
111120 }
112121 }
@@ -116,7 +125,7 @@ impl PyObject {
116125 PyObject :: Immutable ( immutable) => & * immutable. clone ( ) as * const PyImmutableObject as usize ,
117126 PyObject :: Mutable ( mutable) => & * mutable. clone ( ) . borrow ( ) as * const PyMutableObject as usize ,
118127 PyObject :: Internal ( internal) => internal. get_memory_location ( ) ,
119- PyObject :: IteratorFlag ( flag) => flag as * const PyIteratorFlag as usize
128+ // PyObject::IteratorFlag(flag) => flag as *const PyIteratorFlag as usize
120129 }
121130 }
122131}
@@ -189,25 +198,25 @@ impl PyInternalObject {
189198
190199#[ derive( Debug ) ]
191200pub enum PyMutableObject {
192- // Class(Rc<PyClass>),
201+ Class ( Rc < PyClass > ) ,
193202 Instance ( PyInstance ) ,
194- Function ( PyFunction ) ,
203+ // Function(PyFunction),
195204}
196205
197206impl PyMutableObject {
198207 pub fn get_class ( & self ) -> & Rc < PyClass > {
199208 match self {
200209 PyMutableObject :: Instance ( py_instance) => py_instance. get_class ( ) ,
201- // PyMutableObject::Class(py_class) => py_class,
202- PyMutableObject :: Function ( _py_function) => todo ! ( ) ,
210+ PyMutableObject :: Class ( py_class) => py_class,
211+ // PyMutableObject::Function(_py_function) => todo!(),
203212 }
204213 }
205214
206215 pub fn get_field ( & self , name : & str , arena : & mut PyArena ) -> FuncReturnType {
207216 match self {
208217 PyMutableObject :: Instance ( instance) => instance. get_field ( name, arena) ,
209- // PyMutableObject::Class(py_class) => todo!(),
210- PyMutableObject :: Function ( _py_function) => todo ! ( ) ,
218+ PyMutableObject :: Class ( py_class) => todo ! ( ) ,
219+ // PyMutableObject::Function(_py_function) => todo!(),
211220 }
212221 }
213222
@@ -228,19 +237,19 @@ impl PyMutableObject {
228237
229238 pub fn get_magic_method ( & self , py_magic_method : & PyMagicMethod , _arena : & mut PyArena ) -> Option < PyObject > {
230239 match self {
231- // PyMutableObject::Class(_) => {todo!()}
240+ PyMutableObject :: Class ( _) => { todo ! ( ) }
232241 PyMutableObject :: Instance ( instance) => { instance. get_class ( ) . search_for_magic_method ( py_magic_method) }
233- PyMutableObject :: Function ( _) => { todo ! ( ) }
242+ // PyMutableObject::Function(_) => {todo!()}
234243 }
235244 }
236245}
237246
238- #[ derive( Debug ) ]
239- pub struct PyFunction {
240- name : String ,
241- args : Vec < String > ,
242- body : Vec < CodeBlock > ,
243- }
247+ // #[derive(Debug)]
248+ // pub struct PyFunction {
249+ // name: String,
250+ // args: Vec<String>,
251+ // body: Vec<CodeBlock>,
252+ // }
244253
245254pub type FuncReturnType = Result < PyObject , PyException > ;
246255pub type EmptyFuncReturnType = Result < ( ) , PyException > ;
0 commit comments