Skip to content

Commit

Permalink
Fix for coroutines issue (#31).
Browse files Browse the repository at this point in the history
  • Loading branch information
Paul Cuthbertson committed Dec 23, 2015
1 parent 1a3f5f2 commit 2f3d088
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 6 deletions.
6 changes: 5 additions & 1 deletion test/distil-tests
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
#!/usr/bin/env bash
../bin/moonshine distil ./scripts -o ./test-package.json -pm ./scripts/test-runner.lua
COMPILER='luac'
if [ $1 ]; then
COMPILER=$1
fi
../bin/moonshine distil ./scripts -o ./test-package.json -pm ./scripts/test-runner.lua -c $COMPILER
14 changes: 14 additions & 0 deletions test/scripts/lib-coroutine.lua
Original file line number Diff line number Diff line change
Expand Up @@ -96,3 +96,17 @@ assertTrue (arguments == 'OaMaIaIIaanilnillooptrueIIaanilIb123nilnilMbObMaIaIIaa



order = ''
local c = coroutine.create(function() order = order..'1' coroutine.yield(2) order = order..'3' return 4 end)
local res, retval = coroutine.resume(c)

assertTrue (res, 'coroutine should yeild successfully')
assertEqual (retval, 2, 'coroutine should yeild correct value')
assertEqual (order, '1', 'coroutine should yeild at correct point.')

res, retval = coroutine.resume(c)

assertTrue (res, 'coroutine should yeild successfully when function returns at end')
assertEqual (retval, 4, 'coroutine should yeild value that is returned from function')
assertEqual (order, '13', 'coroutine should resume at correct point.')
assertEqual (coroutine.status(c), 'dead', 'coroutine should be dead after function returns')
2 changes: 1 addition & 1 deletion test/test-package.json

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions vm/moonshine.js
Original file line number Diff line number Diff line change
Expand Up @@ -1653,7 +1653,7 @@ shine.Coroutine._add = function (co) {
*/
shine.Coroutine._remove = function () {
var vm = shine.getCurrentVM();
vm._coroutineRunning = vm._coroutineStack.pop();
if (vm) vm._coroutineRunning = vm._coroutineStack.pop();
};


Expand Down Expand Up @@ -5090,7 +5090,7 @@ if (typeof module != 'undefined') module.exports = shine.jit;
switch (co.status) {
case shine.RUNNING: return (co === getVM()._coroutineRunning)? 'running' : 'normal';
case shine.SUSPENDED: return 'suspended';
case shine.DEAD: return 'dead';
default: return 'dead';
}
},

Expand Down
2 changes: 1 addition & 1 deletion vm/src/Coroutine.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ shine.Coroutine._add = function (co) {
*/
shine.Coroutine._remove = function () {
var vm = shine.getCurrentVM();
vm._coroutineRunning = vm._coroutineStack.pop();
if (vm) vm._coroutineRunning = vm._coroutineStack.pop();
};


Expand Down
2 changes: 1 addition & 1 deletion vm/src/lib.js
Original file line number Diff line number Diff line change
Expand Up @@ -789,7 +789,7 @@
switch (co.status) {
case shine.RUNNING: return (co === getVM()._coroutineRunning)? 'running' : 'normal';
case shine.SUSPENDED: return 'suspended';
case shine.DEAD: return 'dead';
default: return 'dead';
}
},

Expand Down

0 comments on commit 2f3d088

Please sign in to comment.