Skip to content

Commit

Permalink
WIP initial YIELD_FROM implementation
Browse files Browse the repository at this point in the history
TODO: check for StopIteration
  • Loading branch information
abonie committed Jul 18, 2017
1 parent 2632501 commit 9bc4dcc
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
9 changes: 9 additions & 0 deletions batavia/VirtualMachine.js
Original file line number Diff line number Diff line change
Expand Up @@ -1847,6 +1847,15 @@ VirtualMachine.prototype.byte_YIELD_VALUE = function() {
return 'yield'
}

VirtualMachine.prototype.byte_YIELD_FROM = function() {
var v = this.pop()
var receiver = this.top()

this.return_value = receiver.send(v)
this.jump(this.frame.f_lasti - 1)
return 'yield'
}

// VirtualMachine.prototype.byte_YIELD_FROM = function {
// u = this.pop()
// x = this.top()
Expand Down
15 changes: 15 additions & 0 deletions tests/structures/test_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,3 +193,18 @@ def G():
except BaseException as e:
print(type(e), e)
""")


class YieldFromTests(TranspileTestCase):
def test_regular_generator(self):
self.assertCodeExecution("""
def G(x):
yield from x
def F():
yield 1
yield 2
g = G(F())
print(list(g))
""")

0 comments on commit 9bc4dcc

Please sign in to comment.