Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

coffee#1638: helper functions are now declared last

  • Loading branch information...
commit 63d66d7095a382fe9708f4b1b338cbeec473b293 1 parent f470b45
@satyr authored
View
2  extras/coco.js
1 addition, 1 deletion not shown
View
2  extras/mode-coco.js
@@ -1 +1 @@
-(function(){var a=function(a,b){function c(){}c.prototype=(a.superclass=b).prototype,(a.prototype=new c).constructor=a,typeof b.extended=="function"&&b.extended(a);return a};define("ace/mode/coco",function(b,c,d){var e,f,g,h;e="[$A-Za-z_\\x7f-\\uffff][$\\w\\x7f-\\uffff]*",c.Mode=f=function(c){function g(){var a;this.$tokenizer=new(b("ace/tokenizer").Tokenizer)(g.Rules);if(a=b("ace/mode/matching_brace_outdent"))this.$outdent=new a.MatchingBraceOutdent}g.displayName="CocoMode";var d,f=a(g,c).prototype;d=RegExp("(?:[({[=:]|[-~]>|\\b(?:else|d(?:o|efault)|t(?:ry|hen)|finally|let|new|(?:catch|function)(?:\\s*"+e+")?))\\s*$"),f.getNextLineIndent=function(a,b,c){var e,f;e=this.$getIndent(b),f=this.$tokenizer.getLineTokens(b,a).tokens,(!f.length||f[f.length-1].type!=="comment")&&a==="start"&&d.test(b)&&(e+=c);return e},f.toggleCommentLines=function(a,c,d,e){var f,g,h,i,j;f=/^(\s*)#/,g=new(b("ace/range").Range)(0,0,0,0);for(h=d;h<=e;++h)(j=f.test(i=c.getLine(h)))?i=i.replace(f,"$1"):i=i.replace(/^\s*/,"$&#"),g.end.row=g.start.row=h,g.end.column=i.length+1,c.replace(g,i);return 1-j*2},f.checkOutdent=function(a,b,c){var d;return(d=this.$outdent)!=null?d.checkOutdent(b,c):void 8},f.autoOutdent=function(a,b,c){var d;return(d=this.$outdent)!=null?d.autoOutdent(b,c):void 8};return g}(b("ace/mode/text").Mode),g="(?![$\\w]|\\s*:(?![:=]))",h={token:"string",regex:".+"},f.Rules={start:[{token:"keyword",regex:"(?:t(?:h(?:is|row|en)|ry|ypeof!?)|c(?:ontinue|a(?:se|tch)|lass)|i(?:n(?:stanceof)?|mport(?:\\s+all)?|[fs])|d(?:e(?:fault|lete|bugger)|o)|f(?:or(?:\\s+own)?|inally|unction)|s(?:uper|witch)|e(?:lse|xtends|val)|a(?:nd|rguments)|n(?:ew|ot)|un(?:less|til)|w(?:hile|ith)|o[fr]|return|break|let)"+g},{token:"constant.language",regex:"(?:true|false|null|void)"+g},{token:"invalid.illegal",regex:"(?:p(?:ackage|r(?:ivate|otected)|ublic)|i(?:mplements|nterface)|e(?:num|xport)|var|const|static|yield)"+g},{token:"language.support.class",regex:"(?:R(?:e(?:gExp|ferenceError)|angeError)|S(?:tring|yntaxError)|E(?:rror|valError)|Array|Boolean|Date|Function|Number|Object|TypeError|URIError)"+g},{token:"language.support.function",regex:"(?:is(?:NaN|Finite)|parse(?:Int|Float)|Math|JSON|(?:en|de)codeURI(?:Component)?)"+g},{token:"variable.language",regex:"(?:t(?:hat|il|o)|f(?:rom|allthrough)|it|by)"+g},{token:"identifier",regex:e+"\\s*:(?![:=])"},{token:"variable",regex:e},{token:"keyword.operator",regex:"(?:\\.{3}|\\s+\\?)"},{token:"keyword.variable",regex:"(?:@+|::|\\.\\.)",next:"key"},{token:"keyword.operator",regex:"\\.\\s*",next:"key"},{token:"string",regex:"\\\\\\S[^\\s,;)}\\]]*"},{token:"string.doc",regex:"'''",next:"qdoc"},{token:"string.doc",regex:'"""',next:"qqdoc"},{token:"string",regex:"'",next:"qstring"},{token:"string",regex:'"',next:"qqstring"},{token:"string",regex:"`",next:"js"},{token:"string",regex:"<\\[",next:"words"},{token:"string.regex",regex:"//",next:"heregex"},{token:"comment.doc",regex:"/\\*",next:"comment"},{token:"comment",regex:"#.*"},{token:"string.regex",regex:"\\/(?:[^[\\/\\n\\\\]*(?:(?:\\\\.|\\[[^\\]\\n\\\\]*(?:\\\\.[^\\]\\n\\\\]*)*\\])[^[\\/\\n\\\\]*)*)\\/[gimy$]{0,4}",next:"key"},{token:"constant.numeric",regex:"(?:0[xX][\\da-fA-F][\\da-fA-F_]*|(?:[2-9]|[12]\\d|3[0-6])[rR][\\da-zA-Z][\\da-zA-Z_]*|(?:\\d[\\d_]*(?:\\.\\d[\\d_]*)?|\\.\\d[\\d_]*)(?:[eE][+-]?\\d[\\d_]*)?[a-zA-Z_]*)"},{token:"lparen",regex:"[({[]"},{token:"rparen",regex:"[)}\\]]",next:"key"},{token:"keyword.operator",regex:"\\S+"},{token:"text",regex:"\\s+"}],heregex:[{token:"string.regex",regex:".*?//[gimy$?]{0,4}",next:"start"},{token:"string.regex",regex:"\\s*#{"},{token:"comment.regex",regex:"\\s+(?:#.*)?"},{token:"string.regex",regex:"\\S+"}],key:[{token:"keyword.operator",regex:"[.?@!]+"},{token:"identifier",regex:e,next:"start"},{token:"text",regex:".",next:"start"}],comment:[{token:"comment.doc",regex:".*?\\*/",next:"start"},{token:"comment.doc",regex:".+"}],qdoc:[{token:"string",regex:".*?'''",next:"key"},h],qqdoc:[{token:"string",regex:'.*?"""',next:"key"},h],qstring:[{token:"string",regex:"[^\\\\']*(?:\\\\.[^\\\\']*)*'",next:"key"},h],qqstring:[{token:"string",regex:'[^\\\\"]*(?:\\\\.[^\\\\"]*)*"',next:"key"},h],js:[{token:"string",regex:"[^\\\\`]*(?:\\\\.[^\\\\`]*)*`",next:"key"},h],words:[{token:"string",regex:".*?\\]>",next:"key"},h]}})}).call(this)
+(function(){function a(a,b){function c(){}c.prototype=(a.superclass=b).prototype,(a.prototype=new c).constructor=a,typeof b.extended=="function"&&b.extended(a);return a}define("ace/mode/coco",function(b,c,d){var e,f,g,h;e="[$A-Za-z_\\x7f-\\uffff][$\\w\\x7f-\\uffff]*",c.Mode=f=function(c){function g(){var a;this.$tokenizer=new(b("ace/tokenizer").Tokenizer)(g.Rules);if(a=b("ace/mode/matching_brace_outdent"))this.$outdent=new a.MatchingBraceOutdent}g.displayName="CocoMode";var d,f=a(g,c).prototype;d=RegExp("(?:[({[=:]|[-~]>|\\b(?:else|d(?:o|efault)|t(?:ry|hen)|finally|let|new|(?:catch|function)(?:\\s*"+e+")?))\\s*$"),f.getNextLineIndent=function(a,b,c){var e,f;e=this.$getIndent(b),f=this.$tokenizer.getLineTokens(b,a).tokens,(!f.length||f[f.length-1].type!=="comment")&&a==="start"&&d.test(b)&&(e+=c);return e},f.toggleCommentLines=function(a,c,d,e){var f,g,h,i,j;f=/^(\s*)#/,g=new(b("ace/range").Range)(0,0,0,0);for(h=d;h<=e;++h)(j=f.test(i=c.getLine(h)))?i=i.replace(f,"$1"):i=i.replace(/^\s*/,"$&#"),g.end.row=g.start.row=h,g.end.column=i.length+1,c.replace(g,i);return 1-j*2},f.checkOutdent=function(a,b,c){var d;return(d=this.$outdent)!=null?d.checkOutdent(b,c):void 8},f.autoOutdent=function(a,b,c){var d;return(d=this.$outdent)!=null?d.autoOutdent(b,c):void 8};return g}(b("ace/mode/text").Mode),g="(?![$\\w]|\\s*:(?![:=]))",h={token:"string",regex:".+"},f.Rules={start:[{token:"keyword",regex:"(?:t(?:h(?:is|row|en)|ry|ypeof!?)|c(?:ontinue|a(?:se|tch)|lass)|i(?:n(?:stanceof)?|mport(?:\\s+all)?|[fs])|d(?:e(?:fault|lete|bugger)|o)|f(?:or(?:\\s+own)?|inally|unction)|s(?:uper|witch)|e(?:lse|xtends|val)|a(?:nd|rguments)|n(?:ew|ot)|un(?:less|til)|w(?:hile|ith)|o[fr]|return|break|let)"+g},{token:"constant.language",regex:"(?:true|false|null|void)"+g},{token:"invalid.illegal",regex:"(?:p(?:ackage|r(?:ivate|otected)|ublic)|i(?:mplements|nterface)|e(?:num|xport)|var|const|static|yield)"+g},{token:"language.support.class",regex:"(?:R(?:e(?:gExp|ferenceError)|angeError)|S(?:tring|yntaxError)|E(?:rror|valError)|Array|Boolean|Date|Function|Number|Object|TypeError|URIError)"+g},{token:"language.support.function",regex:"(?:is(?:NaN|Finite)|parse(?:Int|Float)|Math|JSON|(?:en|de)codeURI(?:Component)?)"+g},{token:"variable.language",regex:"(?:t(?:hat|il|o)|f(?:rom|allthrough)|it|by)"+g},{token:"identifier",regex:e+"\\s*:(?![:=])"},{token:"variable",regex:e},{token:"keyword.operator",regex:"(?:\\.{3}|\\s+\\?)"},{token:"keyword.variable",regex:"(?:@+|::|\\.\\.)",next:"key"},{token:"keyword.operator",regex:"\\.\\s*",next:"key"},{token:"string",regex:"\\\\\\S[^\\s,;)}\\]]*"},{token:"string.doc",regex:"'''",next:"qdoc"},{token:"string.doc",regex:'"""',next:"qqdoc"},{token:"string",regex:"'",next:"qstring"},{token:"string",regex:'"',next:"qqstring"},{token:"string",regex:"`",next:"js"},{token:"string",regex:"<\\[",next:"words"},{token:"string.regex",regex:"//",next:"heregex"},{token:"comment.doc",regex:"/\\*",next:"comment"},{token:"comment",regex:"#.*"},{token:"string.regex",regex:"\\/(?:[^[\\/\\n\\\\]*(?:(?:\\\\.|\\[[^\\]\\n\\\\]*(?:\\\\.[^\\]\\n\\\\]*)*\\])[^[\\/\\n\\\\]*)*)\\/[gimy$]{0,4}",next:"key"},{token:"constant.numeric",regex:"(?:0[xX][\\da-fA-F][\\da-fA-F_]*|(?:[2-9]|[12]\\d|3[0-6])[rR][\\da-zA-Z][\\da-zA-Z_]*|(?:\\d[\\d_]*(?:\\.\\d[\\d_]*)?|\\.\\d[\\d_]*)(?:[eE][+-]?\\d[\\d_]*)?[a-zA-Z_]*)"},{token:"lparen",regex:"[({[]"},{token:"rparen",regex:"[)}\\]]",next:"key"},{token:"keyword.operator",regex:"\\S+"},{token:"text",regex:"\\s+"}],heregex:[{token:"string.regex",regex:".*?//[gimy$?]{0,4}",next:"start"},{token:"string.regex",regex:"\\s*#{"},{token:"comment.regex",regex:"\\s+(?:#.*)?"},{token:"string.regex",regex:"\\S+"}],key:[{token:"keyword.operator",regex:"[.?@!]+"},{token:"identifier",regex:e,next:"start"},{token:"text",regex:".",next:"start"}],comment:[{token:"comment.doc",regex:".*?\\*/",next:"start"},{token:"comment.doc",regex:".+"}],qdoc:[{token:"string",regex:".*?'''",next:"key"},h],qqdoc:[{token:"string",regex:'.*?"""',next:"key"},h],qstring:[{token:"string",regex:"[^\\\\']*(?:\\\\.[^\\\\']*)*'",next:"key"},h],qqstring:[{token:"string",regex:'[^\\\\"]*(?:\\\\.[^\\\\"]*)*"',next:"key"},h],js:[{token:"string",regex:"[^\\\\`]*(?:\\\\.[^\\\\`]*)*`",next:"key"},h],words:[{token:"string",regex:".*?\\]>",next:"key"},h]}})}).call(this)
View
88 lib/ast.js
@@ -1,19 +1,4 @@
-var Node, Negatable, Block, Atom, Literal, Var, Key, Index, Chain, Call, List, Obj, Prop, Arr, Op, Assign, Import, Of, Existence, Fun, Class, Super, Parens, Splat, Jump, Throw, Return, While, For, Try, Switch, Case, If, Label, JS, Util, UTILITIES, LEVEL_TOP, LEVEL_PAREN, LEVEL_LIST, LEVEL_COND, LEVEL_OP, LEVEL_CALL, PREC, TAB, ID, SIMPLENUM, _ref, __import = function(obj, src){
- var own = {}.hasOwnProperty;
- for (var key in src) if (own.call(src, key)) obj[key] = src[key];
- return obj;
-}, __clone = function(it){
- function fn(){ if (this.__proto__ !== it) this.__proto__ = it }
- return fn.prototype = it, new fn;
-}, __extends = function(sub, sup){
- function ctor(){} ctor.prototype = (sub.superclass = sup).prototype;
- (sub.prototype = new ctor).constructor = sub;
- if (typeof sup.extended == 'function') sup.extended(sub);
- return sub;
-}, __repeatString = function(str, n){
- for (var r = ''; n > 0; (n >>= 1) && (str += str)) if (n & 1) r += str;
- return r;
-}, __importAll = function(obj, src){ for (var key in src) obj[key] = src[key]; return obj };
+var Node, Negatable, Block, Atom, Literal, Var, Key, Index, Chain, Call, List, Obj, Prop, Arr, Op, Assign, Import, Of, Existence, Fun, Class, Super, Parens, Splat, Jump, Throw, Return, While, For, Try, Switch, Case, If, Label, JS, Util, UTILITIES, LEVEL_TOP, LEVEL_PAREN, LEVEL_LIST, LEVEL_COND, LEVEL_OP, LEVEL_CALL, PREC, TAB, ID, SIMPLENUM, _ref;
(Node = function(){
throw Error('unimplemented');
}).prototype = {
@@ -159,15 +144,16 @@ var Node, Negatable, Block, Atom, Literal, Var, Key, Index, Chain, Call, List, O
})));
},
delegate: function(names, fn){
- var name, _i, _len, _fn = function(name){
- this[name] = function(it){
- return fn.call(this, name, it);
- };
- };
+ var name, _i, _len;
for (_i = 0, _len = names.length; _i < _len; ++_i) {
name = names[_i];
(_fn.call(this, name));
}
+ function _fn(name){
+ this[name] = function(it){
+ return fn.call(this, name, it);
+ };
+ }
},
children: [],
terminator: ';',
@@ -410,9 +396,9 @@ exports.Block = Block = (function(_super){
return [prefix] + code;
};
prototype.compileWithDeclarations = function(o){
- var code, i, node, rest, post, that, _ref, _len;
+ var pre, i, node, rest, post, that, _ref, _len;
o.level = LEVEL_TOP;
- code = '';
+ pre = '';
for (i = 0, _len = (_ref = this.lines).length; i < _len; ++i) {
node = _ref[i];
if (!(node.comment || node instanceof Literal)) {
@@ -421,16 +407,13 @@ exports.Block = Block = (function(_super){
}
if (i) {
rest = this.lines.splice(i, 9e9);
- code = this.compile(o);
+ pre = this.compile(o);
this.lines = rest;
}
- if (post = this.compile(o)) {
- code && (code += '\n');
+ if (!(post = this.compile(o))) {
+ return pre;
}
- if (that = (_ref = this.scope) != null ? _ref.vars(o) : void 8) {
- code += o.indent + that + ';\n';
- }
- return code + post;
+ return (pre && pre + "\n") + ((that = this.scope) ? that.emit(post, o.indent) : post);
};
return Block;
}(Node));
@@ -3006,21 +2989,31 @@ _ref.type = function(it){
var _ref;
return (_ref = this.variables[this.positions[it]]) != null ? _ref.type : void 8;
};
-_ref.vars = function(o){
- var usr, tmp, asn, name, type, that, _i, _ref, _len, _ref2;
+_ref.emit = function(code, tab){
+ var usr, tmp, asn, fun, name, type, that, val, _i, _ref, _len, _ref2;
usr = [];
tmp = [];
asn = [];
+ fun = [];
for (_i = 0, _len = (_ref = this.variables).length; _i < _len; ++_i) {
_ref2 = _ref[_i], name = _ref2.name, type = _ref2.type;
if (type === 'var' || type === 'reuse') {
('_' === name.charAt(0) ? tmp : usr).push(name);
- } else if (type.value) {
- asn.push(entab(name + ' = ' + type.value, o.indent));
+ } else if (that = type.value) {
+ if (~(val = entab(that, tab)).lastIndexOf('function(', 0)) {
+ fun.push("function " + name + val.slice(8));
+ } else {
+ asn.push(name + " = " + val);
+ }
}
}
if (that = usr.concat(tmp, asn).join(', ')) {
- return 'var ' + that;
+ code = tab + "var " + that + ";\n" + code;
+ }
+ if (that = fun.join("\n" + tab)) {
+ return code + "\n" + tab + that;
+ } else {
+ return code;
}
};
function YES(){
@@ -3038,7 +3031,7 @@ UTILITIES = {
'extends': 'function(sub, sup){\n function ctor(){} ctor.prototype = (sub.superclass = sup).prototype;\n (sub.prototype = new ctor).constructor = sub;\n if (typeof sup.extended == \'function\') sup.extended(sub);\n return sub;\n}',
bind: 'function(me, fn){ return function(){ return fn.apply(me, arguments) } }',
'import': 'function(obj, src){\n var own = {}.hasOwnProperty;\n for (var key in src) if (own.call(src, key)) obj[key] = src[key];\n return obj;\n}',
- importAll: 'function(obj, src){ for (var key in src) obj[key] = src[key]; return obj }',
+ importAll: 'function(obj, src){\n for (var key in src) obj[key] = src[key];\n return obj;\n}',
repeatString: 'function(str, n){\n for (var r = \'\'; n > 0; (n >>= 1) && (str += str)) if (n & 1) r += str;\n return r;\n}',
repeatArray: 'function(arr, n){\n for (var r = []; n > 0; (n >>= 1) && (arr = arr.concat(arr)))\n if (n & 1) r.push.apply(r, arr);\n return r;\n}',
split: "''.split",
@@ -3073,4 +3066,27 @@ function utility(it){
}
function entab(code, tab){
return code.replace(/\n/g, '\n' + tab);
+}
+function __import(obj, src){
+ var own = {}.hasOwnProperty;
+ for (var key in src) if (own.call(src, key)) obj[key] = src[key];
+ return obj;
+}
+function __clone(it){
+ function fn(){ if (this.__proto__ !== it) this.__proto__ = it }
+ return fn.prototype = it, new fn;
+}
+function __extends(sub, sup){
+ function ctor(){} ctor.prototype = (sub.superclass = sup).prototype;
+ (sub.prototype = new ctor).constructor = sub;
+ if (typeof sup.extended == 'function') sup.extended(sub);
+ return sub;
+}
+function __repeatString(str, n){
+ for (var r = ''; n > 0; (n >>= 1) && (str += str)) if (n & 1) r += str;
+ return r;
+}
+function __importAll(obj, src){
+ for (var key in src) obj[key] = src[key];
+ return obj;
}
View
15 lib/coco.js
@@ -1,8 +1,4 @@
-var lexer, parser, __import = function(obj, src){
- var own = {}.hasOwnProperty;
- for (var key in src) if (own.call(src, key)) obj[key] = src[key];
- return obj;
-}, __importAll = function(obj, src){ for (var key in src) obj[key] = src[key]; return obj };
+var lexer, parser;
lexer = require('./lexer');
parser = require('./parser').parser;
parser.yy = require('./ast');
@@ -54,4 +50,13 @@ if (require.extensions) {
if ('' + this === '[object BackstagePass]') {
this.EXPORTED_SYMBOLS = ['Coco'];
}
+}
+function __import(obj, src){
+ var own = {}.hasOwnProperty;
+ for (var key in src) if (own.call(src, key)) obj[key] = src[key];
+ return obj;
+}
+function __importAll(obj, src){
+ for (var key in src) obj[key] = src[key];
+ return obj;
}
View
9 lib/coke.js
@@ -1,8 +1,5 @@
#!/usr/bin/env node
-var Tasks, Aliases, Flags, Options, args, filename, _ref, __slice = [].slice, __repeatString = function(str, n){
- for (var r = ''; n > 0; (n >>= 1) && (str += str)) if (n & 1) r += str;
- return r;
-};
+var Tasks, Aliases, Flags, Options, args, filename, _ref, __slice = [].slice;
Tasks = {
__proto__: null
};
@@ -85,4 +82,8 @@ function printTasks(){
say('\nTask options:\n' + that);
}
return say('\nCoke options:\n -f, --cokefile FILE use FILE as the Cokefile');
+}
+function __repeatString(str, n){
+ for (var r = ''; n > 0; (n >>= 1) && (str += str)) if (n & 1) r += str;
+ return r;
}
View
26 lib/command.js
@@ -1,15 +1,5 @@
#!/usr/bin/env node
-var o, that, $args, argv, filename, __join = [].join, __import = function(obj, src){
- var own = {}.hasOwnProperty;
- for (var key in src) if (own.call(src, key)) obj[key] = src[key];
- return obj;
-}, __bind = function(me, fn){ return function(){ return fn.apply(me, arguments) } }, __clone = function(it){
- function fn(){ if (this.__proto__ !== it) this.__proto__ = it }
- return fn.prototype = it, new fn;
-}, __repeatString = function(str, n){
- for (var r = ''; n > 0; (n >>= 1) && (str += str)) if (n & 1) r += str;
- return r;
-};
+var o, that, $args, argv, filename, __join = [].join;
global.Coco = require('./coco');
global.fs = require('fs');
global.path = require('path');
@@ -372,4 +362,18 @@ function help(){
}
function version(){
return "Coco " + Coco.VERSION;
+}
+function __import(obj, src){
+ var own = {}.hasOwnProperty;
+ for (var key in src) if (own.call(src, key)) obj[key] = src[key];
+ return obj;
+}
+function __bind(me, fn){ return function(){ return fn.apply(me, arguments) } }
+function __clone(it){
+ function fn(){ if (this.__proto__ !== it) this.__proto__ = it }
+ return fn.prototype = it, new fn;
+}
+function __repeatString(str, n){
+ for (var r = ''; n > 0; (n >>= 1) && (str += str)) if (n & 1) r += str;
+ return r;
}
View
11 lib/lexer.js
@@ -1,7 +1,4 @@
-var string, TABS, INDENTS, LINES, BACKSLASHES, reslash, character, KEYWORDS_SHARED, KEYWORDS_UNUSED, KEYWORDS, COCO_ALIASES, ID, SYMBOL, SPACE, MULTIDENT, SIMPLESTR, JSTOKEN, BSTOKEN, NUMBER, NUMBER_OMIT, REGEX, HEREGEX_OMIT, LASTDENT, LINE_CONTINUER, OPENERS, CLOSERS, INVERSES, CHAIN, ARG, __clone = function(it){
- function fn(){ if (this.__proto__ !== it) this.__proto__ = it }
- return fn.prototype = it, new fn;
-}, __indexOf = [].indexOf || function(x){
+var string, TABS, INDENTS, LINES, BACKSLASHES, reslash, character, KEYWORDS_SHARED, KEYWORDS_UNUSED, KEYWORDS, COCO_ALIASES, ID, SYMBOL, SPACE, MULTIDENT, SIMPLESTR, JSTOKEN, BSTOKEN, NUMBER, NUMBER_OMIT, REGEX, HEREGEX_OMIT, LASTDENT, LINE_CONTINUER, OPENERS, CLOSERS, INVERSES, CHAIN, ARG, __indexOf = [].indexOf || function(x){
var i = -1, l = this.length;
while (++i < l) if (this.hasOwnProperty(i) && this[i] === x) return i;
return -1;
@@ -1336,4 +1333,8 @@ INVERSES = new function(){
}
};
CHAIN = ['(', '{', '[', 'ID', 'STRNUM', 'LITERAL', 'LET', 'WITH', 'WORDS'];
-ARG = CHAIN.concat(['...', 'UNARY', 'CREMENT', 'PARAM(', 'FUNCTION', 'IF', 'SWITCH', 'TRY', 'CLASS', 'SUPER', 'RANGE', 'LABEL', 'DO']);
+ARG = CHAIN.concat(['...', 'UNARY', 'CREMENT', 'PARAM(', 'FUNCTION', 'IF', 'SWITCH', 'TRY', 'CLASS', 'SUPER', 'RANGE', 'LABEL', 'DO']);
+function __clone(it){
+ function fn(){ if (this.__proto__ !== it) this.__proto__ = it }
+ return fn.prototype = it, new fn;
+}
View
7 lib/node.js
@@ -1,4 +1,3 @@
-var __importAll = function(obj, src){ for (var key in src) obj[key] = src[key]; return obj };
module.exports = function(Coco){
var fs, path;
fs = require('fs');
@@ -24,4 +23,8 @@ module.exports = function(Coco){
bare: true
}), filename);
};
-};
+};
+function __importAll(obj, src){
+ for (var key in src) obj[key] = src[key];
+ return obj;
+}
View
9 lib/optparse.js
@@ -1,7 +1,4 @@
-var __toString = {}.toString, __repeatString = function(str, n){
- for (var r = ''; n > 0; (n >>= 1) && (str += str)) if (n & 1) r += str;
- return r;
-};
+var __toString = {}.toString;
module.exports = function(flags, args, options){
var MULTI, name, desc, arg, abbr, FLAG, unknowns, i, literals, flag, value, _res, _ref, _len, _i, _len2, _key;
args || (args = process.argv.slice(2));
@@ -77,4 +74,8 @@ function help(){
lf = (longs[i] + pad).slice(0, width);
return " " + sf + " " + lf + " " + flag.desc;
}).join('\n');
+}
+function __repeatString(str, n){
+ for (var r = ''; n > 0; (n >>= 1) && (str += str)) if (n & 1) r += str;
+ return r;
}
View
29 src/ast.co
@@ -264,15 +264,14 @@ class exports.Block extends Node
# declarations of all inner variables pushed up to the top.
compileWithDeclarations: (o) ->
o.level = LEVEL_TOP
- code = ''
+ pre = ''
break unless node.comment or node instanceof Literal for node, i of @lines
if i
rest = @lines.splice i, 9e9
- code = @compile o
+ pre = @compile o
@lines = rest
- code &&+= \\n if post = @compile o
- code += o.indent + that + \;\n if @scope?vars o
- code + post
+ return pre unless post = @compile o
+ (pre and "#pre\n") + if @scope then that.emit post, o.indent else post
#### Atom
# An abstract node for simple values.
@@ -1856,15 +1855,18 @@ Scope::<<<
# Gets the type of a variable from name.
type: -> @variables[@positions[it]]?type
- # Returns the list of variables declared in this scope.
- vars: (o) ->
- usr = []; tmp = []; asn = []
+ # Concatenates the declarations in this scope.
+ emit: (code, tab) ->
+ usr = []; tmp = []; asn = []; fun = []
for {name, type} of @variables
if type of <[ var reuse ]>
(if \_ is name.charAt 0 then tmp else usr)push name
else if type.value
- asn.push entab name + ' = ' + type.value, o.indent
- 'var ' + that if usr.concat(tmp, asn)join ', '
+ if ~(val = entab that, tab)lastIndexOf \function( 0
+ then fun.push "function #name#{ val.slice 8 }"
+ else asn.push "#name = #val"
+ code = "#{tab}var #that;\n#code" if usr.concat(tmp, asn)join ', '
+ if fun.join "\n#tab" then "#code\n#tab#that" else code
##### Constants
@@ -1899,9 +1901,10 @@ UTILITIES =
for (var key in src) if (own.call(src, key)) obj[key] = src[key];
return obj;
}'''
- importAll: '''
- function(obj, src){ for (var key in src) obj[key] = src[key]; return obj }
- '''
+ importAll: '''function(obj, src){
+ for (var key in src) obj[key] = src[key];
+ return obj;
+ }'''
repeatString: '''function(str, n){
for (var r = ''; n > 0; (n >>= 1) && (str += str)) if (n & 1) r += str;
View
14 test/compilation.co
@@ -119,17 +119,19 @@ eq '1;\n2;', Coco.compile ' 1\n 2' bare
eq '''
(function(){
- var k, _this = this, __clone = function(it){
- function fn(){ if (this.__proto__ !== it) this.__proto__ = it }
- return fn.prototype = it, new fn;
- }, _fn = function(k){
- __clone(_this);
- };
+ var k, _this = this;
try {
for (k in o) {
(_fn(k));
}
} catch (_e) {}
+ function __clone(it){
+ function fn(){ if (this.__proto__ !== it) this.__proto__ = it }
+ return fn.prototype = it, new fn;
+ }
+ function _fn(k){
+ __clone(_this);
+ }
}).call(this);
''', Coco.compile '''try for k in o then do ~> ^@'''
Please sign in to comment.
Something went wrong with that request. Please try again.