@@ -5,6 +5,7 @@ use super::obj::objdict;
55use super :: obj:: objfloat;
66use super :: obj:: objfunction;
77use super :: obj:: objint;
8+ use super :: obj:: objiter;
89use super :: obj:: objlist;
910use super :: obj:: objobject;
1011use super :: obj:: objstr;
@@ -60,6 +61,7 @@ pub struct PyContext {
6061 pub false_value : PyObjectRef ,
6162 pub list_type : PyObjectRef ,
6263 pub tuple_type : PyObjectRef ,
64+ pub iter_type : PyObjectRef ,
6365 pub str_type : PyObjectRef ,
6466 pub function_type : PyObjectRef ,
6567 pub module_type : PyObjectRef ,
@@ -123,6 +125,7 @@ impl PyContext {
123125 let float_type = create_type ( "float" , & type_type, & object_type, & dict_type) ;
124126 let bytes_type = create_type ( "bytes" , & type_type, & object_type, & dict_type) ;
125127 let tuple_type = create_type ( "tuple" , & type_type, & object_type, & dict_type) ;
128+ let iter_type = create_type ( "iter" , & type_type, & object_type, & dict_type) ;
126129 let bool_type = create_type ( "bool" , & type_type, & int_type, & dict_type) ;
127130 let exceptions = exceptions:: ExceptionZoo :: new ( & type_type, & object_type, & dict_type) ;
128131
@@ -142,6 +145,7 @@ impl PyContext {
142145 true_value : true_value,
143146 false_value : false_value,
144147 tuple_type : tuple_type,
148+ iter_type : iter_type,
145149 dict_type : dict_type,
146150 none : none,
147151 str_type : str_type,
@@ -164,6 +168,7 @@ impl PyContext {
164168 objbytes:: init ( & context) ;
165169 objstr:: init ( & context) ;
166170 objtuple:: init ( & context) ;
171+ objiter:: init ( & context) ;
167172 objbool:: init ( & context) ;
168173 exceptions:: init ( & context) ;
169174 context
@@ -190,6 +195,9 @@ impl PyContext {
190195 pub fn tuple_type ( & self ) -> PyObjectRef {
191196 self . tuple_type . clone ( )
192197 }
198+ pub fn iter_type ( & self ) -> PyObjectRef {
199+ self . iter_type . clone ( )
200+ }
193201 pub fn dict_type ( & self ) -> PyObjectRef {
194202 self . dict_type . clone ( )
195203 }
@@ -750,35 +758,6 @@ impl PyObject {
750758 }
751759 }
752760
753- // Implement iterator protocol:
754- pub fn nxt ( & mut self ) -> Option < PyObjectRef > {
755- match self . kind {
756- PyObjectKind :: Iterator {
757- ref mut position,
758- iterated_obj : ref iterated_obj_ref,
759- } => {
760- let iterated_obj = & * iterated_obj_ref. borrow_mut ( ) ;
761- match iterated_obj. kind {
762- PyObjectKind :: List { ref elements } => {
763- if * position < elements. len ( ) {
764- let obj_ref = elements[ * position] . clone ( ) ;
765- * position += 1 ;
766- Some ( obj_ref)
767- } else {
768- None
769- }
770- }
771- _ => {
772- panic ! ( "NOT IMPL" ) ;
773- }
774- }
775- }
776- _ => {
777- panic ! ( "NOT IMPL" ) ;
778- }
779- }
780- }
781-
782761 // Move this object into a reference object, transferring ownership.
783762 pub fn into_ref ( self ) -> PyObjectRef {
784763 Rc :: new ( RefCell :: new ( self ) )
0 commit comments