Skip to content

Commit 7619a72

Browse files
committed
Make py.Iter and make FOR_ITER use it
1 parent b5c3273 commit 7619a72

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

py/internal.go

+12
Original file line numberDiff line numberDiff line change
@@ -220,3 +220,15 @@ func SetAttr(self Object, keyObj Object, value Object) Object {
220220
// FIXME should be TypeError
221221
panic(fmt.Sprintf("TypeError: attribute name must be string, not '%s'", self.Type().Name))
222222
}
223+
224+
// Call __next__ for the python object
225+
func Next(self Object) Object {
226+
if I, ok := self.(I__next__); ok {
227+
return I.M__next__()
228+
} else if res, ok := TypeCall0(self, "__next__"); ok {
229+
return res
230+
}
231+
232+
// FIXME should be TypeError
233+
panic(fmt.Sprintf("TypeError: '%s' object is not iterable", self.Type().Name))
234+
}

vm/eval.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -667,8 +667,7 @@ func do_FOR_ITER(vm *Vm, delta int32) {
667667
}
668668
}()
669669
// FIXME should look in instance dictionary
670-
it := vm.TOP().(py.I__next__)
671-
r := it.M__next__()
670+
r := py.Next(vm.TOP())
672671
vm.PUSH(r)
673672
}
674673

0 commit comments

Comments
 (0)