@@ -5,6 +5,7 @@ use super::obj::objdict;
5
5
use super :: obj:: objfloat;
6
6
use super :: obj:: objfunction;
7
7
use super :: obj:: objint;
8
+ use super :: obj:: objiter;
8
9
use super :: obj:: objlist;
9
10
use super :: obj:: objobject;
10
11
use super :: obj:: objstr;
@@ -60,6 +61,7 @@ pub struct PyContext {
60
61
pub false_value : PyObjectRef ,
61
62
pub list_type : PyObjectRef ,
62
63
pub tuple_type : PyObjectRef ,
64
+ pub iter_type : PyObjectRef ,
63
65
pub str_type : PyObjectRef ,
64
66
pub function_type : PyObjectRef ,
65
67
pub module_type : PyObjectRef ,
@@ -123,6 +125,7 @@ impl PyContext {
123
125
let float_type = create_type ( "float" , & type_type, & object_type, & dict_type) ;
124
126
let bytes_type = create_type ( "bytes" , & type_type, & object_type, & dict_type) ;
125
127
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) ;
126
129
let bool_type = create_type ( "bool" , & type_type, & int_type, & dict_type) ;
127
130
let exceptions = exceptions:: ExceptionZoo :: new ( & type_type, & object_type, & dict_type) ;
128
131
@@ -142,6 +145,7 @@ impl PyContext {
142
145
true_value : true_value,
143
146
false_value : false_value,
144
147
tuple_type : tuple_type,
148
+ iter_type : iter_type,
145
149
dict_type : dict_type,
146
150
none : none,
147
151
str_type : str_type,
@@ -164,6 +168,7 @@ impl PyContext {
164
168
objbytes:: init ( & context) ;
165
169
objstr:: init ( & context) ;
166
170
objtuple:: init ( & context) ;
171
+ objiter:: init ( & context) ;
167
172
objbool:: init ( & context) ;
168
173
exceptions:: init ( & context) ;
169
174
context
@@ -190,6 +195,9 @@ impl PyContext {
190
195
pub fn tuple_type ( & self ) -> PyObjectRef {
191
196
self . tuple_type . clone ( )
192
197
}
198
+ pub fn iter_type ( & self ) -> PyObjectRef {
199
+ self . iter_type . clone ( )
200
+ }
193
201
pub fn dict_type ( & self ) -> PyObjectRef {
194
202
self . dict_type . clone ( )
195
203
}
@@ -750,35 +758,6 @@ impl PyObject {
750
758
}
751
759
}
752
760
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
-
782
761
// Move this object into a reference object, transferring ownership.
783
762
pub fn into_ref ( self ) -> PyObjectRef {
784
763
Rc :: new ( RefCell :: new ( self ) )
0 commit comments