diff --git a/package.json b/package.json
index 1399e4c..e475d3f 100644
--- a/package.json
+++ b/package.json
@@ -25,7 +25,8 @@
"escodegen": "0.0.22",
"source-map": "0.1.8",
"underscore": "1.2.0",
- "unicode-categories": "0.9.1"
+ "unicode-categories": "0.9.1",
+ "brushtail": "0.0.1"
},
"devDependencies": {
"jison": "0.2.7",
diff --git a/site/index.htm b/site/index.htm
index 13df17a..67fe15d 100644
--- a/site/index.htm
+++ b/site/index.htm
@@ -99,6 +99,7 @@
About
Pattern matching
Structural typing
Monad syntax
+ Tail call optimization
Automatic currying
Eager evaluation
diff --git a/src/compile.js b/src/compile.js
index a9c4e4c..312c27c 100644
--- a/src/compile.js
+++ b/src/compile.js
@@ -7,6 +7,7 @@ var typecheck = require('./typeinference').typecheck,
lexer = require('./lexer'),
parser = require('../lib/parser').parser,
typeparser = require('../lib/typeparser').parser,
+ brushtail = require('brushtail'),
escodegen = require('escodegen'),
_ = require('underscore');
@@ -909,6 +910,8 @@ var compile = function(source, env, aliases, opts) {
});
}
+ brushtail.mutateAST(jsAst);
+
return {
type: resultType,
output: escodegen.generate(
diff --git a/test/CompileSpec.js b/test/CompileSpec.js
index cfb3e06..422162d 100644
--- a/test/CompileSpec.js
+++ b/test/CompileSpec.js
@@ -108,5 +108,8 @@ describe('compiler', function(){
it('with.roy with expected output', function() {
expectExecutionToHaveExpectedOutput('good/with');
});
+ it('tco.roy with expected output', function() {
+ expectExecutionToHaveExpectedOutput('good/tco');
+ });
});
});
diff --git a/test/fixtures/good/tco.out b/test/fixtures/good/tco.out
new file mode 100644
index 0000000..749fce6
--- /dev/null
+++ b/test/fixtures/good/tco.out
@@ -0,0 +1 @@
+1000000
diff --git a/test/fixtures/good/tco.roy b/test/fixtures/good/tco.roy
new file mode 100644
index 0000000..c14eb38
--- /dev/null
+++ b/test/fixtures/good/tco.roy
@@ -0,0 +1,7 @@
+let count from to =
+ if from >= to then
+ from
+ else
+ count (from + 1) to
+
+console.log (count 0 1000000)
\ No newline at end of file