From 899678d0e14d82fc21d7af60513710c3156651bd Mon Sep 17 00:00:00 2001 From: Richard Feldman Date: Wed, 24 Jul 2013 00:41:31 -0500 Subject: [PATCH 1/5] Added brushtail dependencies to package.json. (Should replace with just brushtail dependency once brushtail is added to npm. --- package.json | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index 1399e4c..44628f0 100644 --- a/package.json +++ b/package.json @@ -25,7 +25,9 @@ "escodegen": "0.0.22", "source-map": "0.1.8", "underscore": "1.2.0", - "unicode-categories": "0.9.1" + "unicode-categories": "0.9.1", + "estraverse": "1.2.0", + "escope": "0.0.14" }, "devDependencies": { "jison": "0.2.7", From 105f68a6c510d7ccc337aeb083621b6d36af6aa7 Mon Sep 17 00:00:00 2001 From: Richard Feldman Date: Wed, 24 Jul 2013 00:42:15 -0500 Subject: [PATCH 2/5] Call brushtail.mutateAST before generation for great TCO justice. --- src/compile.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/compile.js b/src/compile.js index a9c4e4c..b89f31b 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('../lib/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( From fafa162d7f54a54453478e06e1c8965fc7b21958 Mon Sep 17 00:00:00 2001 From: Richard Feldman Date: Wed, 24 Jul 2013 01:19:37 -0500 Subject: [PATCH 3/5] Added fixture to verify TCO is working. --- test/CompileSpec.js | 3 +++ test/fixtures/good/tco.out | 1 + test/fixtures/good/tco.roy | 7 +++++++ 3 files changed, 11 insertions(+) create mode 100644 test/fixtures/good/tco.out create mode 100644 test/fixtures/good/tco.roy 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 From 55d1fd534009830cce5b9e7e038d5005e92b5097 Mon Sep 17 00:00:00 2001 From: Richard Feldman Date: Wed, 24 Jul 2013 01:43:52 -0500 Subject: [PATCH 4/5] Added TCO to list of language features. --- site/index.htm | 1 + 1 file changed, 1 insertion(+) 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
  • From 45dee680779e447e6d03d9e7bd5c0df9b93267cc Mon Sep 17 00:00:00 2001 From: Richard Feldman Date: Wed, 24 Jul 2013 20:14:47 -0500 Subject: [PATCH 5/5] Use the npm version of Brushtail. --- package.json | 3 +-- src/compile.js | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index 44628f0..e475d3f 100644 --- a/package.json +++ b/package.json @@ -26,8 +26,7 @@ "source-map": "0.1.8", "underscore": "1.2.0", "unicode-categories": "0.9.1", - "estraverse": "1.2.0", - "escope": "0.0.14" + "brushtail": "0.0.1" }, "devDependencies": { "jison": "0.2.7", diff --git a/src/compile.js b/src/compile.js index b89f31b..312c27c 100644 --- a/src/compile.js +++ b/src/compile.js @@ -7,7 +7,7 @@ var typecheck = require('./typeinference').typecheck, lexer = require('./lexer'), parser = require('../lib/parser').parser, typeparser = require('../lib/typeparser').parser, - brushtail = require('../lib/brushtail'), + brushtail = require('brushtail'), escodegen = require('escodegen'), _ = require('underscore');