Skip to content

Commit

Permalink
random crap
Browse files Browse the repository at this point in the history
  • Loading branch information
vendethiel committed Feb 8, 2013
1 parent 7915ca5 commit d3223ce
Show file tree
Hide file tree
Showing 6 changed files with 160 additions and 123 deletions.
2 changes: 1 addition & 1 deletion Cokefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ tint = (text, color ? green) -> color + text + reset

# Run our node/coco interpreter.
run = (args) ->
proc = spawn \node [\bin/coco]concat args
proc = spawn \node [\lib/command]concat args
proc.stderr.on \data say
proc .on \exit -> process.exit it if it

Expand Down
25 changes: 22 additions & 3 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, Chain, Call, List, Obj, Prop, Arr, Unary, Binary, Assign, Import, Of, Existence, Fun, Class, Super, Parens, Splat, Jump, Throw, Return, While, For, Try, Switch, Case, If, Label, Pipe, JS, Util, Vars, DECLS, ref$, UTILS, LEVEL_TOP, LEVEL_PAREN, LEVEL_LIST, LEVEL_COND, LEVEL_OP, LEVEL_CALL, PREC, TAB, ID, SIMPLENUM, slice$ = [].slice, replace$ = ''.replace;
var Node, Negatable, Block, Atom, Literal, Var, Key, Index, Chain, Call, List, Obj, Prop, Arr, Unary, Binary, Assign, Import, Of, Existence, Fun, Class, Super, Parens, Splat, Jump, Throw, Return, While, For, Try, Switch, Case, If, Label, Pipe, JS, Util, Vars, DECLS, ref$, UTILS, LEVEL_TOP, LEVEL_PAREN, LEVEL_LIST, LEVEL_COND, LEVEL_OP, LEVEL_CALL, PREC, TAB, ID, SIMPLENUM, slice$ = [].slice, replace$ = ''.replace, join$ = [].join;
(Node = function(){
throw Error('unimplemented');
}).prototype = {
Expand Down Expand Up @@ -2701,9 +2701,15 @@ exports.While = While = (function(superclass){
}
}
yet && lines.unshift(JS(yet + " = false;"));
if (this['let']) {
tab += TAB;
o.indent += TAB;
code += "\n" + tab + "(function (" + join$.call(this.capture, ', ') + ") {";
}
if (that = this.body.compile(o, LEVEL_TOP)) {
code += "\n" + that + "\n" + tab;
}
this['let'] && (code += "}).call(this, " + join$.call(this.capture, ', ') + ");\n");
code += '}';
if (this.post) {
code += " while (" + this.test.compile((o.tab = tab, o), LEVEL_PAREN) + ");";
Expand All @@ -2714,6 +2720,9 @@ exports.While = While = (function(superclass){
}
return code + ret;
};
prototype.setLet = function(){
throw Error('unimplemented');
};
return While;
}(Node));
exports.For = For = (function(superclass){
Expand All @@ -2734,10 +2743,13 @@ exports.For = For = (function(superclass){
var temps, idx, ref$, pvar, step, tvar, tail, fvar, vars, eq, cond, svar, srcPart, lvar, head, that, body;
o.loop = true;
temps = this.temps = [];
if (idx = this.index) {
if (this['let']) {
this.capture = [];
}
if (idx = this.idx = this.index) {
o.scope.declare(idx, this);
} else {
temps.push(idx = o.scope.temporary('i'));
temps.push(idx = this.idx = o.scope.temporary('i'));
}
if (!this.object) {
ref$ = (this.step || Literal(1)).compileLoopReference(o, 'step'), pvar = ref$[0], step = ref$[1];
Expand Down Expand Up @@ -2800,6 +2812,9 @@ exports.For = For = (function(superclass){
this.infuseIIFE();
o.indent += TAB;
if (this.item && !this.item.isEmpty()) {
if (this['let']) {
this.capture = this.item.compile(o, LEVEL_PAREN);
}
head += '\n' + o.indent + Assign(this.item, JS(svar + "[" + idx + "]")).compile(o, LEVEL_TOP) + ';';
}
if (this.ref) {
Expand All @@ -2811,6 +2826,10 @@ exports.For = For = (function(superclass){
}
return head + body;
};
prototype.setLet = function(){
this['let'] = true;
return this;
};
prototype.infuseIIFE = function(){
var this$ = this;
function dup(params, name){
Expand Down
2 changes: 2 additions & 0 deletions lib/grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ bnf = {
return Chain(Existence($1.unwrap()));
}), o('LET CALL( ArgList OptComma )CALL Block', function(){
return Chain(Call['let']($3, $6));
}), o('LET LoopHead Block', function(){
return $2.setLet().addBody($3);
}), o('WITH Expression Block', function(){
return Chain(Pipe($2, $3, 'with'));
}), o('FOR Expression Block', function(){
Expand Down
Loading

0 comments on commit d3223ce

Please sign in to comment.