Skip to content

Commit

Permalink
merge with coco, change cascade op to .., removed constructor shortha…
Browse files Browse the repository at this point in the history
…nd, closes #121
  • Loading branch information
gkz committed Jul 27, 2012
1 parent 6c1859a commit 1aa4ea5
Show file tree
Hide file tree
Showing 12 changed files with 241 additions and 168 deletions.
60 changes: 41 additions & 19 deletions lib/ast.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
var Node, Negatable, Block, Atom, Literal, Var, Key, Index, Slice, Chain, Call, List, Obj, Prop, Arr, Unary, Binary, Assign, Import, In, Existence, Fun, Class, Super, Parens, Splat, Jump, Throw, Return, While, For, Try, Switch, Case, If, Label, JS, Util, Vars, DECLS, ref$, UTILS, LEVEL_TOP, LEVEL_PAREN, LEVEL_LIST, LEVEL_COND, LEVEL_OP, LEVEL_CALL, PREC, TAB, ID, SIMPLENUM, slice$ = [].slice, toString$ = {}.toString;
var Node, Negatable, Block, Atom, Literal, Var, Key, Index, Slice, Chain, Call, List, Obj, Prop, Arr, Unary, Binary, Assign, Import, In, Existence, Fun, Class, Super, Parens, Splat, Jump, Throw, Return, While, For, Try, Switch, Case, If, Label, Cascade, JS, Util, Vars, DECLS, ref$, UTILS, LEVEL_TOP, LEVEL_PAREN, LEVEL_LIST, LEVEL_COND, LEVEL_OP, LEVEL_CALL, PREC, TAB, ID, SIMPLENUM, slice$ = [].slice, toString$ = {}.toString;
(Node = function(){
throw Error('unimplemented');
}).prototype = {
Expand Down Expand Up @@ -503,18 +503,12 @@ exports.Literal = Literal = (function(superclass){
return this$;
} function ctor$(){} ctor$.prototype = prototype;
prototype.isEmpty = function(){
switch (this.value) {
case 'void':
case 'null':
return true;
}
var ref$;
return (ref$ = this.value) == 'void' || ref$ == 'null';
};
prototype.isCallable = function(){
switch (this.value) {
case 'this':
case 'eval':
return true;
}
var ref$;
return (ref$ = this.value) == 'this' || ref$ == 'eval' || ref$ == '..';
};
prototype.isString = function(){
return 0 <= '\'"'.indexOf((this.value + "").charAt());
Expand Down Expand Up @@ -577,6 +571,11 @@ exports.Literal = Literal = (function(superclass){
case '*':
this.carp('stray star');
break;
case '..':
if (!(val = o.cascadee)) {
this.carp('stray cascadee');
}
break;
case 'debugger':
if (level) {
return "(function(){\n" + TAB + o.indent + "debugger;\n" + o.indent + "}())";
Expand Down Expand Up @@ -3584,6 +3583,27 @@ exports.Label = Label = (function(superclass){
};
return Label;
}(Node));
exports.Cascade = Cascade = (function(superclass){
var prototype = extend$((import$(Cascade, superclass).displayName = 'Cascade', Cascade), superclass).prototype, constructor = Cascade;
function Cascade(target, block){
this.target = target;
this.block = block;
}
prototype.children = ['target', 'block'];
prototype.terminator = '';
prototype.compileNode = function(o){
var ref, t, b;
this.temps = [ref = o.scope.temporary('x')];
t = ref + ' = ' + this.target.compile(o, LEVEL_LIST);
b = this.block.compile((o.cascadee = ref, o));
if (o.level) {
return "(" + t + ", " + b + ")";
} else {
return t + ";\n" + b;
}
};
return Cascade;
}(Node));
exports.JS = JS = (function(superclass){
var prototype = extend$((import$(JS, superclass).displayName = 'JS', JS), superclass).prototype, constructor = JS;
function JS(code, literal, comment){
Expand Down Expand Up @@ -3751,15 +3771,17 @@ ref$.assign = function(name, value){
});
};
ref$.temporary = function(name){
var i, temp, ref$;
var ref$;
name || (name = 'ref');
i = 0;
do {
temp = (name.length > 1
? name + (i++ || '')
: (i++ + parseInt(name, 36)).toString(36)) + "$";
} while ((ref$ = this.variables[temp + "."]) != 'reuse' && ref$ != void 8);
return this.add(temp, 'var');
while ((ref$ = this.variables[name + "$."]) != 'reuse' && ref$ != void 8) {
name = name.length < 2 && name < 'z'
? String.fromCharCode(name.charCodeAt() + 1)
: name.replace(/\d*$/, fn$);
}
return this.add(name + '$', 'var');
function fn$(it){
return ++it;
}
};
ref$.free = function(name){
return this.add(name, 'reuse');
Expand Down
4 changes: 3 additions & 1 deletion lib/grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,9 @@ bnf = {
}), o('Lines NEWLINE')
],
Line: [
o('Expression'), o('PARAM( ArgList OptComma )PARAM <- Expression', function(){
o('Expression'), o('Expression Block', function(){
return new Cascade($1, $2);
}), o('PARAM( ArgList OptComma )PARAM <- Expression', function(){
return Call.back($2, $6, $5.charAt(1) === '~', $5.length === 3);
}), o('COMMENT', function(){
return L(JS($1, true, true));
Expand Down
17 changes: 13 additions & 4 deletions lib/lexer.js
Original file line number Diff line number Diff line change
Expand Up @@ -638,6 +638,9 @@ exports.doLiteral = function(code, index){
tag = 'NEWLINE';
this.wantBy = false;
break;
case '..':
tag = 'LITERAL';
break;
case '.':
if (this.last[0] === '(') {
createItFunc();
Expand Down Expand Up @@ -861,6 +864,15 @@ exports.doLiteral = function(code, index){
}
tag = 'UNARY';
break;
case '&':
if (!able(this.tokens)) {
tag = 'LITERAL';
break;
}
// fallthrough
case '|':
tag = 'BITWISE';
break;
case '~':
if (this.dotcat(val)) {
return 1;
Expand All @@ -880,12 +892,9 @@ exports.doLiteral = function(code, index){
this.parameters(tag = up || '<-');
break;
case '::':
up = 'prototype';
// fallthrough
case '..':
this.adi();
val = 'prototype';
tag = 'ID';
val = up || 'constructor';
break;
default:
switch (val.charAt(0)) {
Expand Down
Loading

0 comments on commit 1aa4ea5

Please sign in to comment.