Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

allow macros to be reset

  • Loading branch information...
commit d52a4a2cf154210758d9167b3c521efc574aca92 1 parent 8eea04f
Scott Taylor authored
2  lib/loop.js
View
@@ -3,7 +3,7 @@ var loop = module.exports;
loop.VERSION = '0.0.1';
loop.parse = require('./loop/parser').parse;
loop.loopEval = require('./loop/eval');
-loop.macroTransform = require('./loop/macro-compiler').macroTransform;
+loop.macroCompiler = require('./loop/macro-compiler');
loop.toUglifyTree = require('./loop/uglify').transform;
loop.compile = require('./loop/compiler').compile;
loop.reverseCompile = require('./loop/reverse-compiler').compile;
2  lib/loop/compiler.js
View
@@ -8,7 +8,7 @@ compiler.compile = function(str, options) {
options = {};
}
- var macroTransformedAst = loop.macroTransform(loop.parse(str));
+ var macroTransformedAst = loop.macroCompiler.macroTransform(loop.parse(str));
var ast = loop.loopEval(macroTransformedAst);
var uglifyAst = loop.toUglifyTree(ast, options);
6 lib/loop/macro-compiler.js
View
@@ -3,15 +3,17 @@ var printTree = require('./util/tree-inspector').withLineNumbers;
var helpers = require('./util/helpers');
var compiler = {};
-var macros;
+var macros = {};
var extractFormals;
var macroReplaceFromLocals;
var isList;
-compiler.macroTransform = function(ast) {
+compiler.reset = function() {
macros = {};
+};
+compiler.macroTransform = function(ast) {
// extract out macro definitions,
_.each(ast, function(tree) {
if (tree.type === 'list') {
16 test/integration/macro-spec.js
View
@@ -23,6 +23,10 @@ var let_star = function() {
};
describe("integration specs (macros)", function() {
+ beforeEach(function() {
+ loop.macroCompiler.reset();
+ });
+
it('should be able to use a simple macro', function() {
var code = "";
code += "(define-macro";
@@ -303,18 +307,22 @@ describe("integration specs (macros)", function() {
macroDefinitions += ' (arg-macro x y ...)';
macroDefinitions += ' (console.log "multi-args"))';
+ loop.macroCompiler.reset();
code = macroDefinitions;
code += '(arg-macro)';
assert.equal(loop.compile(code), 'console.log("zero-args")');
+ loop.macroCompiler.reset();
code = macroDefinitions;
code += '(arg-macro 1)';
assert.equal(loop.compile(code), 'console.log("one-arg")');
+ loop.macroCompiler.reset();
code = macroDefinitions;
code += '(arg-macro 1 2)';
assert.equal(loop.compile(code), 'console.log("multi-args")');
+ loop.macroCompiler.reset();
code = macroDefinitions;
code += '(arg-macro 1 2 3)';
assert.equal(loop.compile(code), 'console.log("multi-args")');
@@ -332,18 +340,22 @@ describe("integration specs (macros)", function() {
macroDefinitions += ' (arg-macro (x y ...))';
macroDefinitions += ' (console.log "multi-args"))';
+ loop.macroCompiler.reset();
code = macroDefinitions;
code += '(arg-macro ())';
assert.equal(loop.compile(code), 'console.log("zero-args")');
+ loop.macroCompiler.reset();
code = macroDefinitions;
code += '(arg-macro (1))';
assert.equal(loop.compile(code), 'console.log("one-arg")');
+ loop.macroCompiler.reset();
code = macroDefinitions;
code += '(arg-macro (1 2))';
assert.equal(loop.compile(code), 'console.log("multi-args")');
+ loop.macroCompiler.reset();
code = macroDefinitions;
code += '(arg-macro (1 2 3))';
assert.equal(loop.compile(code), 'console.log("multi-args")');
@@ -358,18 +370,22 @@ describe("integration specs (macros)", function() {
macroDefinitions += ' (arg-macro (x y ...))';
macroDefinitions += ' (console.log x y ...))';
+ loop.macroCompiler.reset();
code = macroDefinitions;
code += '(arg-macro ())';
assert.equal(loop.compile(code), 'console.log("zero-args")');
+ loop.macroCompiler.reset();
code = macroDefinitions;
code += '(arg-macro (1))';
assert.equal(loop.compile(code), 'console.log(1)');
+ loop.macroCompiler.reset();
code = macroDefinitions;
code += '(arg-macro (1 2))';
assert.equal(loop.compile(code), 'console.log(1,2)');
+ loop.macroCompiler.reset();
code = macroDefinitions;
code += '(arg-macro (1 2 3))';
assert.equal(loop.compile(code), 'console.log(1,2,3)');
4 test/macros/macro-matching-spec.js
View
@@ -15,6 +15,10 @@ var multi_arg_let_star = function() {
};
describe("macro matching", function() {
+ beforeEach(function() {
+ macroCompiler.reset();
+ });
+
it('should match a symbol to the same symbol', function() {
var macro = parseCode('foo');
var code = parseCode('foo');
Please sign in to comment.
Something went wrong with that request. Please try again.