This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var _marked = [inorder].map(regeneratorRuntime.mark); | |
| function inorder(t) { | |
| return regeneratorRuntime.wrap(function inorder$(_context2) { | |
| while (1) { | |
| switch (_context2.prev = _context2.next) { | |
| case 0: | |
| if (t) { | |
| _context2.next = 2; | |
| break; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function fibo2() { | |
| var a, b; // local vars | |
| return wrap(function (c) { | |
| while (1) { | |
| switch (c.next) { | |
| case 0: | |
| a=0, b=1; | |
| case 1: // while begin | |
| if (!true) { // while cond | |
| c.next = 3; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function Context() { | |
| this.next = 0; | |
| } | |
| var stop = {}; | |
| Context.prototype.stop = function stop() { | |
| return stop; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function GenIter(c, genf) { | |
| this.c = c; | |
| this.genf = genf; | |
| } | |
| GenIter.prototype.next = function next() { | |
| var f = this.genf; | |
| var result = f(this.c); | |
| if (result === stop) { | |
| return {done: true}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function pair(left, right) { | |
| return { | |
| left() { | |
| if (arguments.length == 1) left = arguments[0]; | |
| return left; | |
| }, | |
| right() { | |
| if (arguments.length == 1) right = arguments[0]; | |
| return right; | |
| }, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // http://www.inf.puc-rio.br/~roberto/docs/MCC15-04.pdf | |
| function prim(str) { | |
| const len = str.length; | |
| return function* primMatcher(S, pos) { | |
| if (S.substr(pos, len) === str) { | |
| yield pos + len; | |
| } | |
| }; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const coro = require('symcoro'); | |
| const {create, transfer} = coro; | |
| // Figure 4. Implementing one-shot continuations with symmetric coroutines | |
| // http://www.inf.puc-rio.br/~roberto/docs/MCC15-04.pdf | |
| function* call1cc(f) { | |
| // save the continuation "creator" | |
| let currentCoro = coro.current; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function makeKnockCodeHandler(preset) { | |
| let input = []; | |
| return function knockCodeHandler(e) { | |
| input.push(getCode(e)); | |
| if (input.length === preset.length) { | |
| if (input.join("") === preset) { | |
| success(); | |
| } else { | |
| failure(); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function* knockCodeHandler(preset) { | |
| while (true) { | |
| const input = []; | |
| for (let i=0; i<preset.length; i++) { | |
| input.push(getCode(yield)); | |
| } | |
| if (input.join("") === preset) { | |
| success(); | |
| } else { | |
| failure(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function coro(g) { | |
| g.next(); | |
| return g.next.bind(g); | |
| } |