Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Monads now implemented via generators - reusing control flow logic, a…
…nd to allow use of native generators implementation where available (this will be a command line flag later on).
- Loading branch information
Showing
11 changed files
with
183 additions
and
29 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
|
||
// Benchmark to compare Latte generator performance against native V8 generators. | ||
// Run with --harmony flag: | ||
// node --harmony benchmark/generator_native.js | ||
|
||
var tests = require('./src/generator.latte').tests; | ||
|
||
var suite = new (require('benchmark').Suite); | ||
|
||
suite.add('trampoline', require('./src/generator.latte').tests['trampoline']); | ||
suite.add('native generator', require('./src/generator.latte').tests['generator']); | ||
suite.add('latte generator', require('./out/generator').tests['generator']); | ||
|
||
suite.on('cycle', function(event) { | ||
console.log(String(event.target)); | ||
}) | ||
.on('complete', function() { | ||
console.log('Fastest is ' + this.filter('fastest').pluck('name')); | ||
}) | ||
.run(); |
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
function __convertForIn(obj) { | ||
return [k for (k in obj)]; | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,12 @@ | ||
function __monad(m, lv) { | ||
function __monad(m, value) { | ||
while (true) { | ||
try { | ||
var v = m.send(lv); | ||
if ( v && typeof v.then === "function" ) { | ||
return v.then(nv => __monad(m, nv)) | ||
} | ||
} catch (e) { | ||
if ( e === StopIteration ) return lv; | ||
throw e; | ||
var bind = m.send(value); | ||
if ( bind.done ) return value; | ||
value = bind.value; | ||
if ( value && typeof value.then === "function" ) { | ||
return value.then(nv => __monad(m, nv)) | ||
} | ||
} | ||
} |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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