diff --git a/batavia/VirtualMachine.js b/batavia/VirtualMachine.js index a6d9891d1..30ae56a6c 100644 --- a/batavia/VirtualMachine.js +++ b/batavia/VirtualMachine.js @@ -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() diff --git a/tests/structures/test_generator.py b/tests/structures/test_generator.py index 85ba0a36d..a80ca4d69 100644 --- a/tests/structures/test_generator.py +++ b/tests/structures/test_generator.py @@ -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)) + """)