Comparing version 0.2.1 to 0.3.0
@@ -92,3 +92,4 @@ var cg = require('../codeGenerator'); | ||
importTerm('asyncCallback'); | ||
codegen.callbackFunction = codegen.generatedVariable(['callback']); | ||
codegen.callbackFunction = codegen.variable(['continuation'], {couldBeMacro: false}); | ||
codegen.callbackFunction.isContinuation = true; | ||
codegen.optional = cg.optional; | ||
@@ -95,0 +96,0 @@ codegen.postIncrement = cg.postIncrement; |
(function() { | ||
var self = this; | ||
var fs, ms, createParser, uglify, _, Module, path, repl, vm, versions, createTerms, runningOnNodeOrHigher, generateCode, beautify, compileFile, whenChanges, jsFilenameFromPogoFilename, compileFromFile, sourceLocationPrinter; | ||
var fs, createParser, Module, path, repl, vm, versions, compiler, createTerms, runningOnNodeOrHigher, compileFile, whenChanges, jsFilenameFromPogoFilename, compileFromFile; | ||
fs = require("fs"); | ||
ms = require("../../lib/memorystream"); | ||
createParser = require("./parser").createParser; | ||
uglify = require("uglify-js"); | ||
_ = require("underscore"); | ||
Module = require("module"); | ||
@@ -14,2 +11,3 @@ path = require("path"); | ||
versions = require("../../lib/versions"); | ||
compiler = require("./compiler"); | ||
createTerms = function() { | ||
@@ -21,15 +19,2 @@ return require("./codeGenerator").codeGenerator(); | ||
}; | ||
generateCode = function(term) { | ||
var memoryStream; | ||
memoryStream = new ms.MemoryStream; | ||
term.generateJavaScriptModule(memoryStream); | ||
return memoryStream.toString(); | ||
}; | ||
beautify = function(code) { | ||
var ast; | ||
ast = uglify.parser.parse(code); | ||
return uglify.uglify.gen_code(ast, { | ||
beautify: true | ||
}); | ||
}; | ||
exports.compileFile = compileFile = function(filename, gen1_options) { | ||
@@ -125,64 +110,2 @@ var ugly; | ||
}; | ||
exports.compile = function(pogo, gen4_options) { | ||
var self = this; | ||
var filename, inScope, ugly, global, returnResult, async, terms; | ||
filename = gen4_options !== void 0 && Object.prototype.hasOwnProperty.call(gen4_options, "filename") && gen4_options.filename !== void 0 ? gen4_options.filename : void 0; | ||
inScope = gen4_options !== void 0 && Object.prototype.hasOwnProperty.call(gen4_options, "inScope") && gen4_options.inScope !== void 0 ? gen4_options.inScope : true; | ||
ugly = gen4_options !== void 0 && Object.prototype.hasOwnProperty.call(gen4_options, "ugly") && gen4_options.ugly !== void 0 ? gen4_options.ugly : false; | ||
global = gen4_options !== void 0 && Object.prototype.hasOwnProperty.call(gen4_options, "global") && gen4_options.global !== void 0 ? gen4_options.global : false; | ||
returnResult = gen4_options !== void 0 && Object.prototype.hasOwnProperty.call(gen4_options, "returnResult") && gen4_options.returnResult !== void 0 ? gen4_options.returnResult : false; | ||
async = gen4_options !== void 0 && Object.prototype.hasOwnProperty.call(gen4_options, "async") && gen4_options.async !== void 0 ? gen4_options.async : false; | ||
terms = gen4_options !== void 0 && Object.prototype.hasOwnProperty.call(gen4_options, "terms") && gen4_options.terms !== void 0 ? gen4_options.terms : createTerms(); | ||
var parser, statements, moduleTerm, code, memoryStream, error; | ||
parser = createParser({ | ||
terms: terms | ||
}); | ||
statements = parser.parse(pogo); | ||
if (async) { | ||
statements.asyncify(); | ||
} | ||
moduleTerm = terms.module(statements, { | ||
inScope: inScope, | ||
global: global, | ||
returnLastStatement: returnResult | ||
}); | ||
code = generateCode(moduleTerm); | ||
if (parser.errors.hasErrors()) { | ||
memoryStream = new ms.MemoryStream; | ||
parser.errors.printErrors(sourceLocationPrinter({ | ||
filename: filename, | ||
source: pogo | ||
}), memoryStream); | ||
error = new Error(memoryStream.toString()); | ||
error.isSemanticErrors = true; | ||
throw error; | ||
} else { | ||
if (ugly) { | ||
return code; | ||
} else { | ||
return beautify(code); | ||
} | ||
} | ||
}; | ||
exports.evaluate = function(pogo, gen5_options) { | ||
var self = this; | ||
var definitions, ugly, global; | ||
definitions = gen5_options !== void 0 && Object.prototype.hasOwnProperty.call(gen5_options, "definitions") && gen5_options.definitions !== void 0 ? gen5_options.definitions : {}; | ||
ugly = gen5_options !== void 0 && Object.prototype.hasOwnProperty.call(gen5_options, "ugly") && gen5_options.ugly !== void 0 ? gen5_options.ugly : true; | ||
global = gen5_options !== void 0 && Object.prototype.hasOwnProperty.call(gen5_options, "global") && gen5_options.global !== void 0 ? gen5_options.global : false; | ||
var js, definitionNames, parameters, runScript, definitionValues; | ||
js = exports.compile(pogo, { | ||
ugly: ugly, | ||
inScope: !global, | ||
global: global, | ||
returnResult: !global | ||
}); | ||
definitionNames = _.keys(definitions); | ||
parameters = definitionNames.join(","); | ||
runScript = new Function(parameters, "return " + js + ";"); | ||
definitionValues = _.map(definitionNames, function(name) { | ||
return definitions[name]; | ||
}); | ||
return runScript.apply(undefined, definitionValues); | ||
}; | ||
exports.repl = function() { | ||
@@ -211,3 +134,3 @@ var self = this; | ||
try { | ||
context[terms.callbackFunction.genVar] = callback; | ||
context[terms.callbackFunction.canonicalName()] = callback; | ||
return result = vm.runInContext(js, context, filename); | ||
@@ -227,5 +150,5 @@ } catch (error) { | ||
}; | ||
compileFromFile = function(filename, gen6_options) { | ||
compileFromFile = function(filename, gen4_options) { | ||
var ugly; | ||
ugly = gen6_options !== void 0 && Object.prototype.hasOwnProperty.call(gen6_options, "ugly") && gen6_options.ugly !== void 0 ? gen6_options.ugly : false; | ||
ugly = gen4_options !== void 0 && Object.prototype.hasOwnProperty.call(gen4_options, "ugly") && gen4_options.ugly !== void 0 ? gen4_options.ugly : false; | ||
var contents; | ||
@@ -238,65 +161,4 @@ contents = fs.readFileSync(filename, "utf-8"); | ||
}; | ||
sourceLocationPrinter = function(gen7_options) { | ||
var filename, source; | ||
filename = gen7_options !== void 0 && Object.prototype.hasOwnProperty.call(gen7_options, "filename") && gen7_options.filename !== void 0 ? gen7_options.filename : void 0; | ||
source = gen7_options !== void 0 && Object.prototype.hasOwnProperty.call(gen7_options, "source") && gen7_options.source !== void 0 ? gen7_options.source : void 0; | ||
return object(function() { | ||
var self = this; | ||
self.linesInRange = function(range) { | ||
var self = this; | ||
var lines; | ||
lines = source.split(/\n/); | ||
return lines.slice(range.from - 1, range.to); | ||
}; | ||
self.printLinesInRange = function(gen8_options) { | ||
var self = this; | ||
var prefix, from, to, buffer; | ||
prefix = gen8_options !== void 0 && Object.prototype.hasOwnProperty.call(gen8_options, "prefix") && gen8_options.prefix !== void 0 ? gen8_options.prefix : ""; | ||
from = gen8_options !== void 0 && Object.prototype.hasOwnProperty.call(gen8_options, "from") && gen8_options.from !== void 0 ? gen8_options.from : void 0; | ||
to = gen8_options !== void 0 && Object.prototype.hasOwnProperty.call(gen8_options, "to") && gen8_options.to !== void 0 ? gen8_options.to : void 0; | ||
buffer = gen8_options !== void 0 && Object.prototype.hasOwnProperty.call(gen8_options, "buffer") && gen8_options.buffer !== void 0 ? gen8_options.buffer : buffer; | ||
var gen9_items, gen10_i, line; | ||
gen9_items = self.linesInRange({ | ||
from: from, | ||
to: to | ||
}); | ||
for (gen10_i = 0; gen10_i < gen9_items.length; ++gen10_i) { | ||
line = gen9_items[gen10_i]; | ||
buffer.write(prefix + line + "\n"); | ||
} | ||
return void 0; | ||
}; | ||
self.printLocation = function(location, buffer) { | ||
var self = this; | ||
var spaces, markers; | ||
buffer.write(filename + ":" + location.firstLine + "\n"); | ||
if (location.firstLine === location.lastLine) { | ||
self.printLinesInRange({ | ||
from: location.firstLine, | ||
to: location.lastLine, | ||
buffer: buffer | ||
}); | ||
spaces = self.times(" ", location.firstColumn); | ||
markers = self.times("^", location.lastColumn - location.firstColumn); | ||
return buffer.write(spaces + markers + "\n"); | ||
} else { | ||
return self.printLinesInRange({ | ||
prefix: "> ", | ||
from: location.firstLine, | ||
to: location.lastLine, | ||
buffer: buffer | ||
}); | ||
} | ||
}; | ||
return self.times = function(s, n) { | ||
var self = this; | ||
var strings, i; | ||
strings = []; | ||
for (i = 0; i < n; ++i) { | ||
strings.push(s); | ||
} | ||
return strings.join(""); | ||
}; | ||
}); | ||
}; | ||
exports.compile = compiler.compile; | ||
exports.evaluate = compiler.evaluate; | ||
}).call(this); |
@@ -11,3 +11,3 @@ (function() { | ||
}, | ||
rules: [ [ "^#![^\\n]*", "/* ignore hashbang */" ], [ " +", "/* ignore whitespace */" ], [ "\\s*$", "return yy.eof();" ], [ comments + "$", "return yy.eof();" ], [ comments, "var indentation = yy.indentation(yytext); if (indentation) { return indentation; }" ], [ "\\(\\s*", 'yy.setIndentation(yytext); if (yy.interpolation.interpolating()) {yy.interpolation.openBracket()} return "(";' ], [ "\\s*\\)", "if (yy.interpolation.interpolating()) {yy.interpolation.closeBracket(); if (yy.interpolation.finishedInterpolation()) {this.popState(); yy.interpolation.stopInterpolation()}} return yy.unsetIndentation(')');" ], [ "{\\s*", "yy.setIndentation(yytext); return '{';" ], [ "\\s*}", "return yy.unsetIndentation('}');" ], [ "\\[\\s*", "yy.setIndentation(yytext); return '[';" ], [ "\\s*\\]", "return yy.unsetIndentation(']')" ], [ "(\\r?\\n *)*\\r?\\n *", "return yy.indentation(yytext);" ], [ "[0-9]+\\.[0-9]+", "return 'float';" ], [ "[0-9]+", "return 'integer';" ], [ "@[a-zA-Z_$][a-zA-Z_$0-9]*", 'return "operator";' ], [ "\\.\\.\\.", 'return "...";' ], [ "([:;=,?!.@~#%^&*+<>\\/?\\\\|-])+", "return yy.lexOperator(yy, yytext);" ], [ "r/([^\\\\/]*\\\\.)*[^/]*/(img|mgi|gim|igm|gmi|mig|im|ig|gm|mg|mi|gi|i|m|g|)", "return 'reg_exp';" ], [ "[a-zA-Z_$][a-zA-Z_$0-9]*", "return 'identifier';" ], [ "$", "return 'eof';" ], [ "'([^']*'')*[^']*'", "return 'string';" ], [ '"', "this.begin('interpolated_string'); return 'start_interpolated_string';" ], [ [ "interpolated_string" ], "\\\\#", "return 'escaped_interpolated_string_terminal_start';" ], [ [ "interpolated_string" ], "#\\(", "yy.setIndentation('('); yy.interpolation.startInterpolation(); this.begin('INITIAL'); return '(';" ], [ [ "interpolated_string" ], "#", "return 'interpolated_string_body';" ], [ [ "interpolated_string" ], '"', "this.popState(); return 'end_interpolated_string';" ], [ [ "interpolated_string" ], "\\\\.", "return 'escape_sequence';" ], [ [ "interpolated_string" ], '[^"#\\\\]*', "return 'interpolated_string_body';" ], [ ".", "return 'non_token';" ] ] | ||
rules: [ [ "^#![^\\n]*", "/* ignore hashbang */" ], [ " +", "/* ignore whitespace */" ], [ "\\s*$", "return yy.eof();" ], [ comments + "$", "return yy.eof();" ], [ comments, "var indentation = yy.indentation(yytext); if (indentation) { return indentation; }" ], [ "\\(\\s*", 'yy.setIndentation(yytext); if (yy.interpolation.interpolating()) {yy.interpolation.openBracket()} return "(";' ], [ "\\s*\\)", "if (yy.interpolation.interpolating()) {yy.interpolation.closeBracket(); if (yy.interpolation.finishedInterpolation()) {this.popState(); yy.interpolation.stopInterpolation()}} return yy.unsetIndentation(')');" ], [ "{\\s*", "yy.setIndentation(yytext); return '{';" ], [ "\\s*}", "return yy.unsetIndentation('}');" ], [ "\\[\\s*", "yy.setIndentation(yytext); return '[';" ], [ "\\s*\\]", "return yy.unsetIndentation(']')" ], [ "(\\r?\\n *)*\\r?\\n *", "return yy.indentation(yytext);" ], [ "[0-9]+\\.[0-9]+", "return 'float';" ], [ "[0-9]+", "return 'integer';" ], [ "@[a-zA-Z_$][a-zA-Z_$0-9]*", 'return "operator";' ], [ "\\.\\.\\.", 'return "...";' ], [ "([:;=,?!.@~#%^&*+<>\\/?\\\\|-])+", "return yy.lexOperator(yy, yytext);" ], [ "r\\/([^\\\\\\/]*\\\\.)*[^\\/]*\\/(img|mgi|gim|igm|gmi|mig|im|ig|gm|mg|mi|gi|i|m|g|)", "return 'reg_exp';" ], [ "[a-zA-Z_$][a-zA-Z_$0-9]*", "return 'identifier';" ], [ "$", "return 'eof';" ], [ "'([^']*'')*[^']*'", "return 'string';" ], [ '"', "this.begin('interpolated_string'); return 'start_interpolated_string';" ], [ [ "interpolated_string" ], "\\\\#", "return 'escaped_interpolated_string_terminal_start';" ], [ [ "interpolated_string" ], "#\\(", "yy.setIndentation('('); yy.interpolation.startInterpolation(); this.begin('INITIAL'); return '(';" ], [ [ "interpolated_string" ], "#", "return 'interpolated_string_body';" ], [ [ "interpolated_string" ], '"', "this.popState(); return 'end_interpolated_string';" ], [ [ "interpolated_string" ], "\\\\.", "return 'escape_sequence';" ], [ [ "interpolated_string" ], '[^"#\\\\]*', "return 'interpolated_string_body';" ], [ ".", "return 'non_token';" ] ] | ||
}, | ||
@@ -37,3 +37,3 @@ operators: [ [ "right", ":=", "=" ], [ "left", "." ] ], | ||
async_operator: [ [ "!", "$$ = yy.loc(yy.terms.asyncArgument(), @$);" ] ], | ||
terminal: [ [ "( arguments )", "$$ = yy.loc(yy.terms.argumentList($arguments), @$);" ], [ "@ ( parameters )", "$$ = yy.loc(yy.terms.parameters($3), @$);" ], [ "block_start statements }", "$$ = yy.loc(yy.terms.block([], $2), @$);" ], [ "=> block_start statements }", "$$ = yy.loc(yy.terms.block([], $3, {redefinesSelf: true}), @$);" ], [ "[ arguments ]", "$$ = yy.loc(yy.terms.list($2), @$);" ], [ "{ hash_entries }", "$$ = yy.loc(yy.terms.hash($2), @$);" ], [ "float", "$$ = yy.loc(yy.terms.float(parseFloat(yytext)), @$);" ], [ "integer", "$$ = yy.loc(yy.terms.integer(parseInt(yytext)), @$);" ], [ "identifier", "$$ = yy.loc(yy.terms.identifier(yytext), @$);" ], [ "string", "$$ = yy.loc(yy.terms.string(yy.unindentBy(yy.normaliseString(yytext), @$.first_column + 1)), @$);" ], [ "reg_exp", "$$ = yy.loc(yy.terms.regExp(yy.parseRegExp(yy.unindentBy(yytext, @$.first_column + 2))), @$);" ], [ "interpolated_string", "$$ = yy.loc($1, @$);" ], [ "...", "$$ = yy.loc(yy.terms.splat(), @$);" ] ], | ||
terminal: [ [ "( arguments )", "$$ = yy.loc(yy.terms.argumentList($arguments), @$);" ], [ "@ ( parameters )", "$$ = yy.loc(yy.terms.parameters($3), @$);" ], [ "block_start statements }", "$$ = yy.loc(yy.terms.block([], $2), @$);" ], [ "=> block_start statements }", "$$ = yy.loc(yy.terms.block([], $3, {redefinesSelf: true}), @$);" ], [ "[ arguments ]", "$$ = yy.loc(yy.terms.list($2), @$);" ], [ "{ hash_entries }", "$$ = yy.loc(yy.terms.hash($2), @$);" ], [ "float", "$$ = yy.loc(yy.terms.float(parseFloat(yytext)), @$);" ], [ "integer", "$$ = yy.loc(yy.terms.integer(parseInt(yytext, 10)), @$);" ], [ "identifier", "$$ = yy.loc(yy.terms.identifier(yytext), @$);" ], [ "string", "$$ = yy.loc(yy.terms.string(yy.unindentBy(yy.normaliseString(yytext), @$.first_column + 1)), @$);" ], [ "reg_exp", "$$ = yy.loc(yy.terms.regExp(yy.parseRegExp(yy.unindentBy(yytext, @$.first_column + 2))), @$);" ], [ "interpolated_string", "$$ = yy.loc($1, @$);" ], [ "...", "$$ = yy.loc(yy.terms.splat(), @$);" ] ], | ||
block_start: [ [ "@ {", "$$ = '@{'" ], [ "@{", "$$ = '@{'" ] ], | ||
@@ -40,0 +40,0 @@ unary_operator: [ [ "operator", "$$ = $1;" ], [ "!", "$$ = $1;" ] ], |
@@ -257,2 +257,10 @@ var _ = require('underscore'); | ||
macros.addMacro(['continuation'], function(term, name, args) { | ||
if (args) { | ||
return cg.functionCall(cg.callbackFunction, args, {couldBeMacro: false}); | ||
} else { | ||
return cg.callbackFunction; | ||
} | ||
}); | ||
macros.addMacro(['throw'], function(term, name, args) { | ||
@@ -259,0 +267,0 @@ if (areValidArguments(args, isAny)) { |
(function() { | ||
var self = this; | ||
var jisonParser, ms, createParserContext, createDynamicLexer, grammar, parser, jisonLexer; | ||
jisonParser = require("jison").Parser; | ||
var ms, createParserContext, createDynamicLexer, parser, jisonLexer; | ||
ms = require("../../lib/memorystream"); | ||
createParserContext = require("./parserContext").createParserContext; | ||
createDynamicLexer = require("./dynamicLexer").createDynamicLexer; | ||
grammar = require("./grammar").grammar; | ||
parser = new jisonParser(grammar); | ||
parser = require("./jisonParser").parser; | ||
jisonLexer = parser.lexer; | ||
@@ -11,0 +9,0 @@ self.createParser = function(gen1_options) { |
@@ -12,9 +12,13 @@ (function() { | ||
catchErrorVariable = terms.generatedVariable([ "exception" ]); | ||
body.rewriteResultTermInto(function(term) { | ||
if (!term.originallyAsync) { | ||
return terms.functionCall(terms.callbackFunction, [ terms.nil(), term ]); | ||
} else { | ||
return term; | ||
} | ||
}); | ||
if (!body.containsContinuation()) { | ||
body.rewriteResultTermInto(function(term) { | ||
if (!term.originallyAsync) { | ||
return terms.functionCall(terms.callbackFunction, [ terms.nil(), term ]); | ||
} else { | ||
return term; | ||
} | ||
}, { | ||
async: true | ||
}); | ||
} | ||
return terms.closure([ errorVariable, resultVariable ], terms.statements([ terms.ifExpression([ { | ||
@@ -21,0 +25,0 @@ condition: errorVariable, |
@@ -11,9 +11,18 @@ (function() { | ||
createCallbackWithStatements = function(callbackStatements, gen1_options) { | ||
var resultVariable, forceAsync, global; | ||
var resultVariable, forceAsync, global, containsContinuation; | ||
resultVariable = gen1_options !== void 0 && Object.prototype.hasOwnProperty.call(gen1_options, "resultVariable") && gen1_options.resultVariable !== void 0 ? gen1_options.resultVariable : void 0; | ||
forceAsync = gen1_options !== void 0 && Object.prototype.hasOwnProperty.call(gen1_options, "forceAsync") && gen1_options.forceAsync !== void 0 ? gen1_options.forceAsync : false; | ||
global = gen1_options !== void 0 && Object.prototype.hasOwnProperty.call(gen1_options, "global") && gen1_options.global !== void 0 ? gen1_options.global : false; | ||
var asyncStmts; | ||
containsContinuation = gen1_options !== void 0 && Object.prototype.hasOwnProperty.call(gen1_options, "containsContinuation") && gen1_options.containsContinuation !== void 0 ? gen1_options.containsContinuation : containsContinuation; | ||
var errorVariable, asyncStmts; | ||
if (callbackStatements.length === 1 && callbackStatements[0].isAsyncResult) { | ||
return terms.callbackFunction; | ||
if (containsContinuation) { | ||
errorVariable = terms.generatedVariable([ "error" ]); | ||
return terms.closure([ errorVariable ], terms.statements([ terms.ifExpression([ { | ||
condition: errorVariable, | ||
body: terms.statements([ terms.functionCall(terms.callbackFunction, [ errorVariable ]) ]) | ||
} ]) ])); | ||
} else { | ||
return terms.callbackFunction; | ||
} | ||
} else { | ||
@@ -35,3 +44,21 @@ asyncStmts = putStatementsInCallbackForNextAsyncCall(callbackStatements, { | ||
global = gen2_options !== void 0 && Object.prototype.hasOwnProperty.call(gen2_options, "global") && gen2_options.global !== void 0 ? gen2_options.global : false; | ||
var n, gen3_forResult; | ||
var containsContinuation, n, gen3_forResult; | ||
containsContinuation = function() { | ||
if (statements.length > 0) { | ||
return function() { | ||
var gen4_results, gen5_items, gen6_i, stmt; | ||
gen4_results = []; | ||
gen5_items = statements; | ||
for (gen6_i = 0; gen6_i < gen5_items.length; ++gen6_i) { | ||
stmt = gen5_items[gen6_i]; | ||
gen4_results.push(stmt.containsContinuation()); | ||
} | ||
return gen4_results; | ||
}().reduce(function(l, r) { | ||
return l || r; | ||
}); | ||
} else { | ||
return false; | ||
} | ||
}(); | ||
for (n = 0; n < statements.length; ++n) { | ||
@@ -46,3 +73,4 @@ gen3_forResult = void 0; | ||
forceAsync: forceAsync, | ||
global: global | ||
global: global, | ||
containsContinuation: containsContinuation | ||
}); | ||
@@ -67,6 +95,6 @@ }); | ||
}; | ||
return asyncStatements = function(statements, gen4_options) { | ||
return asyncStatements = function(statements, gen7_options) { | ||
var forceAsync, global; | ||
forceAsync = gen4_options !== void 0 && Object.prototype.hasOwnProperty.call(gen4_options, "forceAsync") && gen4_options.forceAsync !== void 0 ? gen4_options.forceAsync : false; | ||
global = gen4_options !== void 0 && Object.prototype.hasOwnProperty.call(gen4_options, "global") && gen4_options.global !== void 0 ? gen4_options.global : false; | ||
forceAsync = gen7_options !== void 0 && Object.prototype.hasOwnProperty.call(gen7_options, "forceAsync") && gen7_options.forceAsync !== void 0 ? gen7_options.forceAsync : false; | ||
global = gen7_options !== void 0 && Object.prototype.hasOwnProperty.call(gen7_options, "global") && gen7_options.global !== void 0 ? gen7_options.global : false; | ||
var serialisedStatements; | ||
@@ -73,0 +101,0 @@ serialisedStatements = statementsUtils.serialiseStatements(statements); |
@@ -73,3 +73,3 @@ (function() { | ||
return functionCall = function(fun, args, gen2_options) { | ||
var optionalArguments, async, passThisToApply, originallyAsync, asyncCallbackArgument; | ||
var optionalArguments, async, passThisToApply, originallyAsync, asyncCallbackArgument, couldBeMacro; | ||
optionalArguments = gen2_options !== void 0 && Object.prototype.hasOwnProperty.call(gen2_options, "optionalArguments") && gen2_options.optionalArguments !== void 0 ? gen2_options.optionalArguments : []; | ||
@@ -80,2 +80,3 @@ async = gen2_options !== void 0 && Object.prototype.hasOwnProperty.call(gen2_options, "async") && gen2_options.async !== void 0 ? gen2_options.async : false; | ||
asyncCallbackArgument = gen2_options !== void 0 && Object.prototype.hasOwnProperty.call(gen2_options, "asyncCallbackArgument") && gen2_options.asyncCallbackArgument !== void 0 ? gen2_options.asyncCallbackArgument : void 0; | ||
couldBeMacro = gen2_options !== void 0 && Object.prototype.hasOwnProperty.call(gen2_options, "couldBeMacro") && gen2_options.couldBeMacro !== void 0 ? gen2_options.couldBeMacro : true; | ||
var asyncResult, name, macro, funCall; | ||
@@ -93,3 +94,3 @@ if (async) { | ||
}), asyncResult ]); | ||
} else if (fun.variable) { | ||
} else if (fun.variable && couldBeMacro) { | ||
name = fun.variable; | ||
@@ -96,0 +97,0 @@ macro = terms.macros.findMacro(name); |
@@ -41,8 +41,10 @@ (function() { | ||
}, | ||
rewriteResultTermInto: function(returnTerm) { | ||
rewriteResultTermInto: function(returnTerm, gen1_options) { | ||
var self = this; | ||
var gen1_items, gen2_i, _case; | ||
gen1_items = self.cases; | ||
for (gen2_i = 0; gen2_i < gen1_items.length; ++gen2_i) { | ||
_case = gen1_items[gen2_i]; | ||
var async; | ||
async = gen1_options !== void 0 && Object.prototype.hasOwnProperty.call(gen1_options, "async") && gen1_options.async !== void 0 ? gen1_options.async : false; | ||
var gen2_items, gen3_i, _case; | ||
gen2_items = self.cases; | ||
for (gen3_i = 0; gen3_i < gen2_items.length; ++gen3_i) { | ||
_case = gen2_items[gen3_i]; | ||
_case.body.rewriteResultTermInto(returnTerm); | ||
@@ -52,2 +54,4 @@ } | ||
self.elseBody.rewriteResultTermInto(returnTerm); | ||
} else if (async) { | ||
self.elseBody = terms.statements([ terms.functionCall(terms.callbackFunction, []) ]); | ||
} | ||
@@ -54,0 +58,0 @@ return self; |
@@ -24,5 +24,19 @@ (function() { | ||
}, | ||
rewriteResultTermInto: function(returnTerm) { | ||
rewriteResultTermInto: function(returnTerm, gen2_options) { | ||
var self = this; | ||
return self; | ||
var async; | ||
async = gen2_options !== void 0 && Object.prototype.hasOwnProperty.call(gen2_options, "async") && gen2_options.async !== void 0 ? gen2_options.async : false; | ||
var arguments; | ||
if (async) { | ||
arguments = function() { | ||
if (self.expression) { | ||
return [ terms.nil(), self.expression ]; | ||
} else { | ||
return []; | ||
} | ||
}(); | ||
return terms.functionCall(terms.callbackFunction, arguments); | ||
} else { | ||
return self; | ||
} | ||
} | ||
@@ -29,0 +43,0 @@ }); |
@@ -36,4 +36,6 @@ (function() { | ||
}, | ||
rewriteResultTermInto: function(returnTerm) { | ||
rewriteResultTermInto: function(returnTerm, gen3_options) { | ||
var self = this; | ||
var async; | ||
async = gen3_options !== void 0 && Object.prototype.hasOwnProperty.call(gen3_options, "async") && gen3_options.async !== void 0 ? gen3_options.async : false; | ||
var lastStatement, rewrittenLastStatement; | ||
@@ -44,2 +46,4 @@ if (self.statements.length > 0) { | ||
return returnTerm(term); | ||
}, { | ||
async: async | ||
}); | ||
@@ -53,8 +57,10 @@ if (rewrittenLastStatement) { | ||
}, | ||
rewriteLastStatementToReturn: function(gen3_options) { | ||
rewriteLastStatementToReturn: function(gen4_options) { | ||
var self = this; | ||
var async; | ||
async = gen3_options !== void 0 && Object.prototype.hasOwnProperty.call(gen3_options, "async") && gen3_options.async !== void 0 ? gen3_options.async : false; | ||
async = gen4_options !== void 0 && Object.prototype.hasOwnProperty.call(gen4_options, "async") && gen4_options.async !== void 0 ? gen4_options.async : false; | ||
var containsContinuation; | ||
containsContinuation = self.containsContinuation(); | ||
return self.rewriteResultTermInto(function(term) { | ||
if (async) { | ||
if (async && !containsContinuation) { | ||
return terms.functionCall(terms.callbackFunction, [ terms.nil(), term ]); | ||
@@ -66,8 +72,10 @@ } else { | ||
} | ||
}, { | ||
async: async | ||
}); | ||
}, | ||
generateVariableDeclarations: function(variables, buffer, scope, gen4_options) { | ||
generateVariableDeclarations: function(variables, buffer, scope, gen5_options) { | ||
var self = this; | ||
var global; | ||
global = gen4_options !== void 0 && Object.prototype.hasOwnProperty.call(gen4_options, "global") && gen4_options.global !== void 0 ? gen4_options.global : false; | ||
global = gen5_options !== void 0 && Object.prototype.hasOwnProperty.call(gen5_options, "global") && gen5_options.global !== void 0 ? gen5_options.global : false; | ||
if (variables.length > 0) { | ||
@@ -97,7 +105,7 @@ _(variables).each(function(name) { | ||
}, | ||
generateJavaScriptStatements: function(buffer, scope, gen5_options) { | ||
generateJavaScriptStatements: function(buffer, scope, gen6_options) { | ||
var self = this; | ||
var inClosure, global; | ||
inClosure = gen5_options !== void 0 && Object.prototype.hasOwnProperty.call(gen5_options, "inClosure") && gen5_options.inClosure !== void 0 ? gen5_options.inClosure : false; | ||
global = gen5_options !== void 0 && Object.prototype.hasOwnProperty.call(gen5_options, "global") && gen5_options.global !== void 0 ? gen5_options.global : false; | ||
inClosure = gen6_options !== void 0 && Object.prototype.hasOwnProperty.call(gen6_options, "inClosure") && gen6_options.inClosure !== void 0 ? gen6_options.inClosure : false; | ||
global = gen6_options !== void 0 && Object.prototype.hasOwnProperty.call(gen6_options, "global") && gen6_options.global !== void 0 ? gen6_options.global : false; | ||
return self.generateStatements(self.statements, buffer, scope, { | ||
@@ -108,7 +116,7 @@ inClosure: inClosure, | ||
}, | ||
blockify: function(parameters, gen6_options) { | ||
blockify: function(parameters, gen7_options) { | ||
var self = this; | ||
var optionalParameters, async; | ||
optionalParameters = gen6_options !== void 0 && Object.prototype.hasOwnProperty.call(gen6_options, "optionalParameters") && gen6_options.optionalParameters !== void 0 ? gen6_options.optionalParameters : void 0; | ||
async = gen6_options !== void 0 && Object.prototype.hasOwnProperty.call(gen6_options, "async") && gen6_options.async !== void 0 ? gen6_options.async : false; | ||
optionalParameters = gen7_options !== void 0 && Object.prototype.hasOwnProperty.call(gen7_options, "optionalParameters") && gen7_options.optionalParameters !== void 0 ? gen7_options.optionalParameters : void 0; | ||
async = gen7_options !== void 0 && Object.prototype.hasOwnProperty.call(gen7_options, "async") && gen7_options.async !== void 0 ? gen7_options.async : false; | ||
var statements; | ||
@@ -115,0 +123,0 @@ statements = function() { |
@@ -410,5 +410,22 @@ (function() { | ||
}, | ||
containsContinuation: function() { | ||
var self = this; | ||
var found; | ||
found = false; | ||
self.walkDescendants(function(term) { | ||
return found = term.isContinuation || found; | ||
}, { | ||
limit: function(term) { | ||
return term.isClosure && term.isAsync; | ||
} | ||
}); | ||
return found; | ||
}, | ||
rewriteResultTermInto: function(returnTerm) { | ||
var self = this; | ||
return returnTerm(self); | ||
if (self.containsContinuation()) { | ||
return self; | ||
} else { | ||
return returnTerm(self); | ||
} | ||
}, | ||
@@ -415,0 +432,0 @@ asyncify: function() { |
{ | ||
"name": "pogo", | ||
"version": "0.2.1", | ||
"version": "0.3.0", | ||
"description": "A readable, DSL friendly programming language that compiles to JavaScript", | ||
@@ -32,9 +32,11 @@ "maintainers": [ | ||
"mocha": "", | ||
"should": "" | ||
"should": "", | ||
"jison": "", | ||
"browserify": "", | ||
"glob": "" | ||
}, | ||
"dependencies": { | ||
"underscore": "", | ||
"jison": "", | ||
"uglify-js": "~1.3" | ||
"underscore": "1.4.4", | ||
"uglify-js": "2.2.4" | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Wildcard dependency
QualityPackage has a dependency with a floating version range. This can cause issues if the dependency publishes a new major version.
Found 2 instances in 1 package
408093
2
171
6263
1
5
+ Addedoptimist@0.3.7(transitive)
+ Addeduglify-js@2.2.4(transitive)
+ Addedunderscore@1.4.4(transitive)
+ Addedwordwrap@0.0.3(transitive)
- Removedjison@
- RemovedJSONSelect@0.4.0(transitive)
- RemovedJSV@4.0.2(transitive)
- Removedcjson@0.3.0(transitive)
- Removedcolors@0.5.1(transitive)
- Removedebnf-parser@0.1.10(transitive)
- Removedescodegen@1.3.3(transitive)
- Removedesprima@1.1.1(transitive)
- Removedestraverse@1.5.1(transitive)
- Removedesutils@1.0.0(transitive)
- Removedjison@0.4.18(transitive)
- Removedjison-lex@0.3.4(transitive)
- Removedjsonlint@1.6.0(transitive)
- Removedlex-parser@0.1.4(transitive)
- Removednomnom@1.5.2(transitive)
- Removeduglify-js@1.3.5(transitive)
- Removedunderscore@1.1.71.13.7(transitive)
Updateduglify-js@2.2.4
Updatedunderscore@1.4.4