Prepare code to the static typing.

This commit is contained in:
Onoshko Dan 2014-06-01 03:14:13 +07:00
parent cdf1161409
commit 3e4589b331
6 changed files with 378 additions and 364 deletions

124
README.md
View File

@ -359,21 +359,30 @@ As you see, you can use keyword `when`, it's like `case`, but if the condition i
Future plans
===
- Use inline `isset` expression instead function. status: done
- `some is NaN` to `isNaN(some)` status: done
- Negate array accessor ( getter )
arr[-1]; // last element
only for static negate index, for other cases you can use `%` unary prefix:
int index = -10;
arr[%index] = 34; // arr[index %% arr.length];
- static typing
- Compiler command `@import` to import modules ( AMD, CommonJS... )
- declaration function by object's property
// node.js
@import 'fs' as fs
@import dirname from 'path'
String String::replaceAll(a, b){
String res = this;
while(res.indexOf(a) != -1) res = res.replace(a, b);
return res;
}
String code = fs.readFileSync(dirname(filePath) + "/main.cola", "utf8");
- set parameters to calling function
$(".btn").on("click", () use (context: myContext){
this; // myContext
});
// or
Object data = someData;
int data.getFriendsCount() => this.friends.length;
- classes
class A {
@ -405,9 +414,7 @@ Future plans
get some => "some " + about;
set some(val) => about += val;
}
- classes and typing with templates
}- classes and typing with templates
class A<T> {
// ...
@ -416,7 +423,6 @@ Future plans
Array<int> arr = [0...10];
Object<String, String> obj = { name: "Eric" };
- singletones
singleton S { // in fact this is object
@ -442,19 +448,6 @@ Future plans
}
}
- declaration function by objects' property
String String::replaceAll(a, b){
String res = this;
while(res.indexOf(a) != -1) res = res.replace(a, b);
return res;
}
// or
Object data = someData;
int data.getFriendsCount() => this.friends.length;
- destructed function arguments
test({String name, String login, String photoUrl}){
@ -471,6 +464,51 @@ Future plans
}
- Compiler command `@import` to import modules ( AMD, CommonJS... )
// node.js
@import 'fs' as fs
@import dirname from 'path'
String code = fs.readFileSync(dirname(filePath) + "/main.cola", "utf8");
- set parameters to calling function
$(".btn").on("click", *(){
this; // parent context
});
- write documentation of tokenizer/parser methods
- more informative exceptions
- better source maps
- HTML and CSS stuff
String width = 12px;
String div = <div class="inline">
<h1>Example of Embedded HTML</h1>
</div>;
by default it will parsed as `String`, but it may be handled by Plugins.
- Plugin API to make native syntax for libraries and frameworks
class MyComponent extends PolymerComponent {
String tagname = "my-component";
ready(){
// ...
}
}
to
Polymer('my-component', {
ready: function(){
// ...
}
});
- Compiler command `@use plugin "path/to/plugin.cola"`
- asm.js native syntax, for example
// cola
@ -494,33 +532,3 @@ Future plans
return i|0;
}
- Plugin API to make native syntax for libraries and frameworks
class MyComponent extends PolymerComponent {
String tagname = "my-component";
ready(){
// ...
}
}
to
Polymer('my-component', {
ready: function(){
// ...
}
});
- Compiler command `@use plugin "path/to/plugin.cola"`
- write documentation of tokenizer/parser methods
- HTML and CSS stuff
String width = 12px;
String div = <div class="inline">
<h1>Example of Embedded HTML</h1>
</div>;
by default it will parsed as `String`, but it may be handled by Plugins.

View File

@ -56,12 +56,13 @@ Cola.DEFNODE = function (type, props, methods, base) {
props = props.concat(base.PROPS);
var code = "return function AST_" + type + "(props){ if (props) { ";
for (var i = props.length; --i >= 0;) {
code += "this." + props[i] + " = props." + props[i] + ";";
if (props[i] == "start" || props[i] == "end") code += "this." + props[i] + " = props." + props[i] + " || new Cola.AST_Token();";
else code += "this." + props[i] + " = props." + props[i] + ";";
}
var proto = base && new base;
if (proto && proto.initialize || (methods && methods.initialize))
code += "this.initialize();";
code += "}}";
code += type == "Token" ? "}}" : "} else { this.end = new Cola.AST_Token(); this.start = new Cola.AST_Token(); } }";
var ctor = new Function(code)();
if (proto) {
ctor.prototype = proto;

View File

@ -241,7 +241,7 @@ main();</textarea>
localStorage.isjs = isjs.checked ? "t" : "f";
localStorage.mainbinding = mainbinding.checked ? "t" : "f";
stream = new Cola.OutputStream({ beautify : true });
stream = new Cola.OutputStream({ beautify : true, comments : true });
compressor = new Cola.Compressor({ is_js : isjs.checked });
try {

View File

@ -131,13 +131,12 @@ Cola.OPERATORS = [
"isnt",
"**",
"%%",
"?=",
"??"
"?="
];
Cola.cOPERATORS = Cola.makePredicate(Cola.OPERATORS);
Cola.OPERATORS = Cola.OPERATORS.slice(0, Cola.OPERATORS.length - 8);
Cola.OPERATORS = Cola.OPERATORS.slice(0, Cola.OPERATORS.length - 7);
Cola.OPERATORS.push('void');
Cola.OPERATORS = Cola.makePredicate(Cola.OPERATORS);
@ -768,7 +767,7 @@ Cola.cUNARY_PREFIX = Cola.makePredicate([
]);
Cola.UNARY_POSTFIX = Cola.makePredicate([ "--", "++" ]);
Cola.cUNARY_POSTFIX = Cola.makePredicate([ "--", "++", "??" ]);
Cola.cUNARY_POSTFIX = Cola.UNARY_POSTFIX;
Cola.ASSIGNMENT = Cola.makePredicate([ "=", "+=", "-=", "/=", "*=", "%=", ">>=", "<<=", ">>>=", "|=", "^=", "&=" ]);
Cola.cASSIGNMENT = Cola.makePredicate([ "=", "+=", "-=", "/=", "*=", "%=", ">>=", "<<=", ">>>=", "|=", "^=", "&=", "?=" ]);
@ -1483,9 +1482,9 @@ Cola.Parser.prototype.vardefs = function (no_in, in_const, type) {
start : this.S.token,
type : type,
name : (function(_this){
was_template = !_this.is_js && ( _this.is("punc","[") || _this.is("punc","{") );
if (!_this.is_js && _this.is("punc","[")) return _this.array_(true, true);
if (!_this.is_js && _this.is("punc","{")) return _this.object_(true, true);
//was_template = !_this.is_js && ( _this.is("punc","[") || _this.is("punc","{") );
//if (!_this.is_js && _this.is("punc","[")) return _this.array_(true, true);
//if (!_this.is_js && _this.is("punc","{")) return _this.object_(true, true);
return _this.as_symbol(in_const ? Cola.AST_SymbolConst : Cola.AST_SymbolVar);
})(this),
value : this.is("operator", "=") ? (this.next(), this.expression(false, no_in)) : ( was_template ? this.expect_token("operator","=") : null ),

View File

@ -37,12 +37,12 @@
!this.Cola && (this.Cola = {});
Cola.$_cola_is = function $_cola_is(_object, _type){
return _object === _type || _type.prototype && (_object instanceof _type || _object.__proto__ === _type.prototype) || isNaN(_object) && isNaN(_type);
return _object === _type || _type.prototype && (_object instanceof _type || _object.__proto__ === _type.prototype);
}
Cola.$_cola_is.i = 0;
Cola.$_cola_isnt = function $_cola_isnt(_object, _type){
return !(_object === _type || _type.prototype && (_object instanceof _type || _object.__proto__ === _type.prototype) || isNaN(_object) && isNaN(_type));
return !(_object === _type || _type.prototype && (_object instanceof _type || _object.__proto__ === _type.prototype));
}
Cola.$_cola_isnt.i = 1;

View File

@ -37,6 +37,205 @@
"use strict";
!this.Cola && (this.Cola = {});
Cola.Constructions = {};
Cola.Constructions.setPos = function(node, ext){
if(!ext) return node;
if(ext.start) node.start = ext.start;
if(ext.end) node.end = ext.end;
return node;
};
/*
!(typeof {{node}} === "undefined" || {{node}} === null)
*/
Cola.Constructions.IsSet = function(node, ext){
return this.setPos(new Cola.AST_UnaryPrefix({
expression : new Cola.AST_Binary({
right : new Cola.AST_Binary({
right : new Cola.AST_Null,
operator : "===",
left : node
}),
operator : "||",
left : new Cola.AST_Binary({
right : new Cola.AST_String({ value: "undefined" }),
operator : "===",
left : new Cola.AST_UnaryPrefix({
expression : node,
operator : "typeof"
})
})
}),
operator : "!"
}), ext);
};
/*
(typeof {{node}} === "undefined" || {{node}} === null)
*/
Cola.Constructions.IsntSet = function(node, ext){
return this.setPos(new Cola.AST_Binary({
right : new Cola.AST_Binary({
right : new Cola.AST_Null,
operator : "===",
left : node
}),
operator : "||",
left : new Cola.AST_Binary({
right : new Cola.AST_String({ value: "undefined" }),
operator : "===",
left : new Cola.AST_UnaryPrefix({
expression : node,
operator : "typeof"
})
})
}), ext);
};
/*
{{length}} <= {{name}}.length ? [].slice.call({{name}}, {{pos}}, $_cola{{uid}}i = {{name}}.length - {{after}}) : ($_cola{{uid}}i = {{pos}}, [])
*/
Cola.Constructions.SplatedConditional = function(name, uid, pos, after, length){
if(Cola.$_cola_is(name, String)) name = new Cola.AST_SymbolRef({ name : name });
return new Cola.AST_Conditional({
condition : new Cola.AST_Binary({
operator : "<=",
left : new Cola.AST_Number({ value : length }), // length
right : new Cola.AST_Dot({
expression : name, // name
property : "length"
})
}),
consequent : new Cola.AST_Call({
expression : new Cola.AST_Dot({
property : "call",
expression : new Cola.AST_Dot({
property : "slice",
expression : new Cola.AST_Array({ elements : [] })
})
}),
args : [
name, // name
new Cola.AST_Number({ value : pos }), // pos
new Cola.AST_Assign({
operator : '=',
left : new Cola.AST_SymbolRef({ name : "$_cola" + uid + "i" }),
right : new Cola.AST_Binary({
operator : '-',
left : new Cola.AST_Dot({
property : "length",
expression : name // name
}),
right : new Cola.AST_Number({ value : after }) // after
})
})
]
}),
alternative : new Cola.AST_Seq({
car : new Cola.AST_Assign({
operator : '=',
left : new Cola.AST_SymbolRef({ name : "$_cola" + uid + "i" }),
right : new Cola.AST_Number({ value : pos }) // pos
}),
cdr : new Cola.AST_Array({ elements : [] })
})
});
};
/*
{{name}} = {{length}} <= arguments.length ? [].slice.call(arguments, {{pos}}, $_cola_i = arguments.length - {{after}}) : ($_cola_i = {{pos}}, [])
*/
Cola.Constructions.SplatedVarDef = function(name, pos, after, length){
if(Cola.$_cola_is(name, String)) name = { name : name };
return new Cola.AST_VarDef({
type : "Array",
name : new Cola.AST_SymbolVar(name), // name
value : Cola.Constructions.SplatedConditional('arguments', '_', pos, after, length)
});
};
Cola.Constructions.PosedVarDef = function(name, type, pos, aftersplated){
if(Cola.$_cola_is(name, String)) name = { name : name };
return new Cola.AST_VarDef({
type : type,
name : new Cola.AST_SymbolVar(name),
value : new Cola.AST_Sub({
expression : new Cola.AST_SymbolRef({ name : 'arguments' }),
property : aftersplated == -1
? new Cola.AST_Number({ value : pos })
: new Cola.AST_Binary({
operator : '+',
left : new Cola.AST_SymbolRef({ name : '$_cola_i' }),
right : new Cola.AST_Number({ value : aftersplated })
})
})
});
};
Cola.Constructions.PosedWithDefsVarDef = function(name, type, defval, pos, aftersplated){
if(Cola.$_cola_is(name, String)) name = { name : name };
return new Cola.AST_VarDef({
type : type,
name : new Cola.AST_SymbolVar(name),
value : new Cola.AST_Conditional({
condition : new Cola.AST_Binary({
operator : "!==",
left : new Cola.AST_Sub({
expression : new Cola.AST_SymbolRef({ name : 'arguments' }),
property : aftersplated == -1
? new Cola.AST_Number({ value : pos })
: new Cola.AST_Binary({
operator : '+',
left : new Cola.AST_SymbolRef({ name : '$_cola_i' }),
right : new Cola.AST_Number({ value : aftersplated })
})
}),
right : new Cola.AST_SymbolRef({ name : 'undefined' })
}),
consequent : new Cola.AST_Sub({
expression : new Cola.AST_SymbolRef({ name : 'arguments' }),
property : aftersplated == -1
? new Cola.AST_Number({ value : pos })
: new Cola.AST_Binary({
operator : '+',
left : new Cola.AST_SymbolRef({ name : '$_cola_i' }),
right : new Cola.AST_Number({ value : aftersplated })
})
}),
alternative : defval
})
});
};
Cola.Constructions.NamedVarDef = function(name, type, defval, key){
if(Cola.$_cola_is(name, String)) name = { name : name };
return new Cola.AST_VarDef({
type : type,
name : new Cola.AST_SymbolVar(name),
value : new Cola.AST_Conditional({
condition : new Cola.AST_Binary({
operator : "!==",
left : new Cola.AST_Dot({
expression : new Cola.AST_SymbolRef({ name : 'arguments' }),
property : key
}),
right : new Cola.AST_SymbolRef({ name : 'undefined' })
}),
consequent : new Cola.AST_Dot({
expression : new Cola.AST_SymbolRef({ name : 'arguments' }),
property : key
}),
alternative : defval
})
});
};
Cola.AST_Toplevel.prototype.toJavaScript = function(options){
if(this.language == 'js') return this;
this.language = 'js';
@ -81,16 +280,14 @@ Cola.AST_Toplevel.prototype.toJavaScript = function(options){
args : [new Cola.AST_String({ value : options.main_event }), node, new Cola.AST_False()],
expression : new Cola.AST_Dot({
property : 'addEventListener',
//start : props.start,
//end : new Cola.AST_Token({ nlb : false, type : 'name', value : 'pow' }),
expression : new Cola.AST_SymbolRef({ name : 'window' })
})
};
node = new Cola.AST_SimpleStatement({
body : new Cola.AST_Call(props),
start : node.start,
end : node.left
end : node.left,
body : new Cola.AST_Call(props)
});
} else
@ -104,19 +301,16 @@ Cola.AST_Toplevel.prototype.toJavaScript = function(options){
*/
if(node instanceof Cola.AST_Binary && node.operator == '**'){
props = {
start : node.start,
end : node.left,
args : [node.left, node.right],
start : node.start, //new Cola.AST_Token({ nlb : false, type : 'name', value : 'Math' }),
end : node.left, //new Cola.AST_Token({ nlb : false, type : 'punc', value : ')' })
expression : new Cola.AST_Dot({
property : 'pow',
//start : props.start,
//end : new Cola.AST_Token({ nlb : false, type : 'name', value : 'pow' }),
expression : new Cola.AST_SymbolRef({ name : 'Math' })
})
};
node = new Cola.AST_Call(props);
} else
/*
@ -130,18 +324,13 @@ Cola.AST_Toplevel.prototype.toJavaScript = function(options){
if(node instanceof Cola.AST_Binary && node.operator == '%%'){
$_cola_hash[Cola.$_cola_modulo.i] = true;
props = {
start : node.start,
end : node.end,
args : [node.left, node.right],
start : node.start, //new Cola.AST_Token({ nlb : false, type : 'name', value : '$_cola_modulo' }),
end : node.end, //new Cola.AST_Token({ nlb : false, type : 'punc', value : ')' })
expression : new Cola.AST_SymbolRef({
name : '$_cola_modulo'
//start : props.start,
//end : props.start
})
expression : new Cola.AST_SymbolRef({ name : '$_cola_modulo' })
};
node = new Cola.AST_Call(props);
} else
/*
@ -149,15 +338,13 @@ Cola.AST_Toplevel.prototype.toJavaScript = function(options){
to
if($_cola_isntset(a)) a = b;
if(typeof a === "undefined" || a === null) a = b;
*/
if(node instanceof Cola.AST_SimpleStatement && node.body instanceof Cola.AST_Assign && node.body.operator == '?='){
if(node.body.left instanceof Cola.AST_Sub && node.body.left.property instanceof Cola.AST_Noop){
props = {
property : "length",
//start : node.left.start,
//end : new Cola.AST_Token({ nlb : false, type : 'name', value : 'push' }),
expression : node.body.left.expression
};
props = {
@ -169,25 +356,12 @@ Cola.AST_Toplevel.prototype.toJavaScript = function(options){
node.body.left.property = new Cola.AST_Binary(props);
}
$_cola_hash[Cola.$_cola_isntset.i] = true;
node.body.operator = '=';
props = {
args : [node.body.left],
//start : node.start, //new Cola.AST_Token({ nlb : false, type : 'name', value : '$_cola_isntset' }),
//end : node.end //new Cola.AST_Token({ nlb : false, type : 'punc', value : ')' })
expression : new Cola.AST_SymbolRef({
name : '$_cola_isntset'
//start : props.start,
//end : props.start
})
};
node = new Cola.AST_If({
start : node.start,
end : node.end,
body : node.clone(),
start : node.start, //new Cola.AST_Token({ nlb : false, type : 'keyword', value : 'if' }),
end : node.end, //new Cola.AST_Token({ nlb : false, type : 'punc', value : ';' }),
condition : new Cola.AST_Call(props)
condition : Cola.Constructions.IsntSet(node.body.left)
});
} else
@ -196,15 +370,13 @@ Cola.AST_Toplevel.prototype.toJavaScript = function(options){
to
func($_cola_isntset(a) ? a = b : a);
func(typeof a === "undefined" || a === null ? a = b : a);
*/
if(node instanceof Cola.AST_Assign && node.operator == '?='/* && !(parent instanceof Cola.AST_SimpleStatement)*/){
if(node instanceof Cola.AST_Assign && node.operator == '?='){
if(node.left instanceof Cola.AST_Sub && node.left.property instanceof Cola.AST_Noop){
props = {
property : "length",
//start : node.left.start,
//end : new Cola.AST_Token({ nlb : false, type : 'name', value : 'push' }),
expression : node.left.expression
};
props = {
@ -216,24 +388,11 @@ Cola.AST_Toplevel.prototype.toJavaScript = function(options){
node.left.property = new Cola.AST_Binary(props);
}
$_cola_hash[Cola.$_cola_isntset.i] = true;
node.operator = '=';
props = {
args : [node.left],
//start : new Cola.AST_Token({ nlb : false, type : 'name', value : '$_cola_isntset' }),
//end : new Cola.AST_Token({ nlb : false, type : 'punc', value : ')' })
expression : new Cola.AST_SymbolRef({
name : '$_cola_isntset'
//start : props.start,
//end : props.start
})
};
node = new Cola.AST_Conditional({
start : node.start, //new Cola.AST_Token({ nlb : false, type : 'punc', value : '(' }),
end : node.end, //new Cola.AST_Token({ nlb : false, type : 'punc', value : ')' }),
condition : new Cola.AST_Call(props),
start : node.start,
end : node.end,
condition : Cola.Constructions.IsntSet(node.left),
consequent : node.clone(),
alternative : node.left
});
@ -244,26 +403,55 @@ Cola.AST_Toplevel.prototype.toJavaScript = function(options){
to
$_cola_isset(a) ? a : b
!(typeof a === "undefined" || a === null) ? a : b
*/
if(node instanceof Cola.AST_Conditional && node.alternative instanceof Cola.AST_Noop){
$_cola_hash[Cola.$_cola_isset.i] = true;
props = {
args : [node.condition],
start : node.start, //new Cola.AST_Token({ nlb : false, type : 'name', value : '$_cola_isset' }),
end : node.end, //new Cola.AST_Token({ nlb : false, type : 'punc', value : ')' })
expression : new Cola.AST_SymbolRef({
name : '$_cola_isset'
//start : props.start,
//end : props.start
})
};
node.alternative = node.consequent;
node.consequent = node.condition;
node.condition = new Cola.AST_Call(props);
node.condition = Cola.Constructions.IsSet(node.condition);
} else
/*
123 is NaN
to
isNaN(123)
*/
if(node instanceof Cola.AST_Binary && node.operator == 'is' && node.right instanceof Cola.AST_SymbolRef && node.right.name == "NaN"){
props = {
start : node.start,
end : node.end,
args : [node.left],
expression : new Cola.AST_SymbolRef({ name : 'isNaN' })
};
node = new Cola.AST_Call(props);
} else
/*
123 isnt NaN
to
!isNaN(123)
*/
if(node instanceof Cola.AST_Binary && node.operator == 'isnt' && node.right instanceof Cola.AST_SymbolRef && node.right.name == "NaN"){
props = {
args : [node.left],
expression : new Cola.AST_SymbolRef({ name : 'isNaN' })
};
props = {
start : node.start,
end : node.end,
operator : '!',
expression : new Cola.AST_Call(props)
};
node = new Cola.AST_UnaryPrefix(props);
} else
/*
@ -277,14 +465,10 @@ Cola.AST_Toplevel.prototype.toJavaScript = function(options){
if(node instanceof Cola.AST_Binary && node.operator == 'is'){
$_cola_hash[Cola.$_cola_is.i] = true;
props = {
start : node.start,
end : node.end,
args : [node.left, node.right],
start : node.start, //new Cola.AST_Token({ nlb : false, type : 'name', value : '$_cola_is' }),
end : node.end, //new Cola.AST_Token({ nlb : false, type : 'punc', value : ')' })
expression : new Cola.AST_SymbolRef({
name : '$_cola_is'
//start : props.start,
//end : props.start
})
expression : new Cola.AST_SymbolRef({ name : '$_cola_is' })
};
node = new Cola.AST_Call(props);
@ -301,14 +485,10 @@ Cola.AST_Toplevel.prototype.toJavaScript = function(options){
if(node instanceof Cola.AST_Binary && node.operator == 'isnt'){
$_cola_hash[Cola.$_cola_isnt.i] = true;
props = {
start : node.start,
end : node.end,
args : [node.left, node.right],
start : node.start, //new Cola.AST_Token({ nlb : false, type : 'name', value : '$_cola_isnt' }),
end : node.end, //new Cola.AST_Token({ nlb : false, type : 'punc', value : ')' })
expression : new Cola.AST_SymbolRef({
name : '$_cola_isnt'
//start : props.start,
//end : props.start
})
expression : new Cola.AST_SymbolRef({ name : '$_cola_isnt' })
};
node = new Cola.AST_Call(props);
@ -317,29 +497,13 @@ Cola.AST_Toplevel.prototype.toJavaScript = function(options){
/*
isset a
or
a??
to
$_cola_isset(a)
*/
if(node instanceof Cola.AST_UnaryPostfix && node.operator == '??' || node instanceof Cola.AST_UnaryPrefix && node.operator == 'isset'){
$_cola_hash[Cola.$_cola_isset.i] = true;
props = {
args : [node.expression],
start : node.start, //new Cola.AST_Token({ nlb : false, type : 'name', value : '$_cola_isset' }),
end : node.end, //new Cola.AST_Token({ nlb : false, type : 'punc', value : ')' })
expression : new Cola.AST_SymbolRef({
name : '$_cola_isset'
//start : props.start,
//end : props.start
})
};
node = new Cola.AST_Call(props);
if(node instanceof Cola.AST_UnaryPrefix && node.operator == 'isset'){
node = Cola.Constructions.IsSet(node.expression, node);
} else
/*
@ -353,14 +517,10 @@ Cola.AST_Toplevel.prototype.toJavaScript = function(options){
if(node instanceof Cola.AST_UnaryPrefix && node.operator == 'clone'){
$_cola_hash[Cola.$_cola_clone.i] = true;
props = {
start : node.start,
end : node.end,
args : [node.expression],
start : node.start, //new Cola.AST_Token({ nlb : false, type : 'name', value : '$_cola_clone' }),
end : node.end, //new Cola.AST_Token({ nlb : false, type : 'punc', value : ')' })
expression : new Cola.AST_SymbolRef({
name : '$_cola_clone'
//start : props.start,
//end : props.start
})
expression : new Cola.AST_SymbolRef({ name : '$_cola_clone' })
};
node = new Cola.AST_Call(props);
@ -377,14 +537,12 @@ Cola.AST_Toplevel.prototype.toJavaScript = function(options){
if(node instanceof Cola.AST_Assign && node.operator == "=" && node.left instanceof Cola.AST_Sub && node.left.property instanceof Cola.AST_Noop){
props = {
property : "push",
//start : node.left.start,
//end : new Cola.AST_Token({ nlb : false, type : 'name', value : 'push' }),
expression : node.left.expression
};
props = {
start : node.start,
end : node.end,
args : [node.right],
start : node.start, //props.start,
end : node.end, //new Cola.AST_Token({ nlb : false, type : 'punc', value : ')' }),
expression : new Cola.AST_Dot(props)
};
@ -424,12 +582,10 @@ Cola.AST_Toplevel.prototype.toJavaScript = function(options){
if(node instanceof Cola.AST_Sub && node.property instanceof Cola.AST_Noop){
$_cola_hash[Cola.$_cola_array_last.i] = true;
props = {
args : [node.expression],
start : node.start,
end : node.end,
expression : new Cola.AST_SymbolRef({
name : '$_cola_array_last'
})
args : [node.expression],
expression : new Cola.AST_SymbolRef({ name : '$_cola_array_last' })
};
node = new Cola.AST_Call(props);
@ -446,12 +602,10 @@ Cola.AST_Toplevel.prototype.toJavaScript = function(options){
if(node instanceof Cola.AST_Assign && node.operator == '=' && node.left instanceof Cola.AST_Sub && node.left.property instanceof Cola.AST_ArrayRange){
$_cola_hash[Cola.$_cola_array_asplice.i] = true;
props = {
args : [node.left.expression, node.left.property.from, node.left.property.to, node.right],
start : node.start,
end : node.end,
expression : new Cola.AST_SymbolRef({
name : '$_cola_array_asplice'
})
args : [node.left.expression, node.left.property.from, node.left.property.to, node.right],
expression : new Cola.AST_SymbolRef({ name : '$_cola_array_asplice' })
};
if(node.left.property.to instanceof Cola.AST_Noop) props.args[2] = new Cola.AST_Number({ value : '9e9' });
@ -478,9 +632,9 @@ Cola.AST_Toplevel.prototype.toJavaScript = function(options){
expression : node.expression
};
props = {
args : [node.property.from],
start : node.start,
end : node.end,
args : [node.property.from],
expression : new Cola.AST_Dot(props)
};
@ -506,12 +660,10 @@ Cola.AST_Toplevel.prototype.toJavaScript = function(options){
if(node instanceof Cola.AST_ArrayRange){
$_cola_hash[Cola.$_cola_array_range.i] = true;
props = {
args : [node.from, node.to],
start : node.start,
end : node.end,
expression : new Cola.AST_SymbolRef({
name : '$_cola_array_range'
})
args : [node.from, node.to],
expression : new Cola.AST_SymbolRef({ name : '$_cola_array_range' })
};
if(node.triple) props.args[1] = new Cola.AST_Binary({
@ -532,20 +684,20 @@ Cola.AST_Toplevel.prototype.toJavaScript = function(options){
*/
if(node instanceof Cola.AST_Call){
props = {
properties : []
};
props = { properties : [] };
var delQueue = [];
node.args.forEach(function(val, i){
if(!(val instanceof Cola.AST_Namedarg)) return;
$_cola_hash[Cola.$_cola_func_named_args.i] = true;
delQueue.push(i);
props.properties.push(new Cola.AST_ObjectKeyVal({
key : val.name,
value : val.value,
start : val.start,
end : val.end
end : val.end,
key : val.name,
value : val.value
}));
});
@ -555,12 +707,10 @@ Cola.AST_Toplevel.prototype.toJavaScript = function(options){
});
props = {
args : [new Cola.AST_Object(props)],
start : node.start,
end : node.end,
expression : new Cola.AST_SymbolRef({
name : '$_cola_func_named_args'
})
args : [new Cola.AST_Object(props)],
expression : new Cola.AST_SymbolRef({ name : '$_cola_func_named_args' })
};
node.args.push(new Cola.AST_New(props));
@ -625,126 +775,24 @@ Cola.AST_Toplevel.prototype.toJavaScript = function(options){
value : null
}));
props.definitions.push(new Cola.AST_VarDef({
name : new Cola.AST_SymbolVar(splated.val.name),
value : new Cola.AST_Conditional({
condition : new Cola.AST_Binary({
operator : "<=",
left : new Cola.AST_Number({ value : splated.pos + splated.after + 1 }),
right : new Cola.AST_Dot({
expression : new Cola.AST_SymbolRef({ name : 'arguments' }),
property : "length"
})
}),
consequent : new Cola.AST_Call({
expression : new Cola.AST_Dot({
property : "call",
expression : new Cola.AST_Dot({
property : "slice",
expression : new Cola.AST_Array({ elements : [] })
})
}),
args : [
new Cola.AST_SymbolRef({ name : 'arguments' }),
new Cola.AST_Number({ value : splated.pos }),
new Cola.AST_Assign({
operator : '=',
left : new Cola.AST_SymbolRef({ name : '$_cola_i' }),
right : new Cola.AST_Binary({
operator : '-',
left : new Cola.AST_Dot({
property : "length",
expression : new Cola.AST_SymbolRef({ name : 'arguments' })
}),
right : new Cola.AST_Number({ value : splated.after })
})
})
]
}),
alternative : new Cola.AST_Seq({
car : new Cola.AST_Assign({
operator : '=',
left : new Cola.AST_SymbolRef({ name : '$_cola_i' }),
right : new Cola.AST_Number({ value : splated.pos })
}),
cdr : new Cola.AST_Array({ elements : [] })
})
})
}));
props.definitions.push(Cola.Constructions.SplatedVarDef(splated.val.name, splated.pos, splated.after, splated.pos + splated.after + 1));
}
else
if(val.defval instanceof Cola.AST_Noop) props.definitions.push(new Cola.AST_VarDef({
name : new Cola.AST_SymbolVar(val.name),
value : new Cola.AST_Sub({
expression : new Cola.AST_SymbolRef({ name : 'arguments' }),
property : aftersplated == -1
? new Cola.AST_Number({ value : pos })
: new Cola.AST_Binary({
operator : '+',
left : new Cola.AST_SymbolRef({ name : '$_cola_i' }),
right : new Cola.AST_Number({ value : aftersplated++ })
})
})
}));
else props.definitions.push(new Cola.AST_VarDef({
name : new Cola.AST_SymbolVar(val.name),
value : new Cola.AST_Conditional({
condition : new Cola.AST_Binary({
operator : "!==",
left : new Cola.AST_Sub({
expression : new Cola.AST_SymbolRef({ name : 'arguments' }),
property : aftersplated == -1
? new Cola.AST_Number({ value : pos })
: new Cola.AST_Binary({
operator : '+',
left : new Cola.AST_SymbolRef({ name : '$_cola_i' }),
right : new Cola.AST_Number({ value : aftersplated })
})
}),
right : new Cola.AST_SymbolRef({ name : 'undefined' })
}),
consequent : new Cola.AST_Sub({
expression : new Cola.AST_SymbolRef({ name : 'arguments' }),
property : aftersplated == -1
? new Cola.AST_Number({ value : pos })
: new Cola.AST_Binary({
operator : '+',
left : new Cola.AST_SymbolRef({ name : '$_cola_i' }),
right : new Cola.AST_Number({ value : aftersplated++ })
})
}),
alternative : val.defval
})
}));
if(val.defval instanceof Cola.AST_Noop) props.definitions.push(Cola.Constructions.PosedVarDef(val.name, val.type, pos, aftersplated)), aftersplated++;
else props.definitions.push(Cola.Constructions.PosedWithDefsVarDef(val.name, val.type, val.defval, pos, aftersplated)), aftersplated++;
});
named.forEach(function(val, i){
if(val.defval instanceof Cola.AST_Noop) props.definitions.push(new Cola.AST_VarDef({
type : val.type,
name : new Cola.AST_SymbolVar(val.name),
value : new Cola.AST_Dot({
expression : new Cola.AST_SymbolRef({ name : 'arguments' }),
property : val.name.name
})
}));
else props.definitions.push(new Cola.AST_VarDef({
name : new Cola.AST_SymbolVar(val.name),
value : new Cola.AST_Conditional({
condition : new Cola.AST_Binary({
operator : "!==",
left : new Cola.AST_Dot({
expression : new Cola.AST_SymbolRef({ name : 'arguments' }),
property : val.name.name
}),
right : new Cola.AST_SymbolRef({ name : 'undefined' })
}),
consequent : new Cola.AST_Dot({
expression : new Cola.AST_SymbolRef({ name : 'arguments' }),
property : val.name.name
}),
alternative : val.defval
})
}));
else props.definitions.push(Cola.Constructions.NamedVarDef(val.name, val.type, val.defval, val.name.name));
});
if(delQueue.length != 0 || named.length != 0) node.body.unshift(new Cola.AST_Var(props));
@ -892,7 +940,7 @@ Cola.AST_Toplevel.prototype.toJavaScript = function(options){
var $_cola_tmp = { key : "val" }, d = $_cola_tmp["key"];
*/
if(node instanceof Cola.AST_Var){
/*if(node instanceof Cola.AST_Var){
var defs = [];
node.definitions.forEach(function(def, i){
if(!(def.name instanceof Cola.AST_ArrayTemplate || def.name instanceof Cola.AST_ObjectTemplate)){
@ -1043,7 +1091,7 @@ Cola.AST_Toplevel.prototype.toJavaScript = function(options){
});
node.definitions = defs;
} else
} else*/
/*
{ String name, age : ages.age } = pro;
@ -1083,49 +1131,7 @@ Cola.AST_Toplevel.prototype.toJavaScript = function(options){
value : null
}));
el.name.splated = undefined;
el.value = new Cola.AST_Conditional({
condition : new Cola.AST_Binary({
operator : "<=",
left : new Cola.AST_Number({ value : _.length }),
right : new Cola.AST_Dot({
expression : symbol,
property : "length"
})
}),
consequent : new Cola.AST_Call({
expression : new Cola.AST_Dot({
property : "call",
expression : new Cola.AST_Dot({
property : "slice",
expression : new Cola.AST_Array({ elements : [] })
})
}),
args : [
symbol,
new Cola.AST_Number({ value : j }),
new Cola.AST_Assign({
operator : '=',
left : new Cola.AST_SymbolVar({ name : "$_cola" + uid + "i" }),
right : new Cola.AST_Binary({
operator : '-',
left : new Cola.AST_Dot({
property : "length",
expression : symbol
}),
right : new Cola.AST_Number({ value : _.length - j - 1 })
})
})
]
}),
alternative : new Cola.AST_Seq({
car : new Cola.AST_Assign({
operator : '=',
left : new Cola.AST_SymbolRef({ name : "$_cola" + uid + "i" }),
right : new Cola.AST_Number({ value : j })
}),
cdr : new Cola.AST_Array({ elements : [] })
})
});
el.value = Cola.Constructions.SplatedConditional(symbol, uid, j, _.length - j - 1, _.length);
defs.push(el);
} else
if((el instanceof Cola.AST_SymbolRef || el instanceof Cola.AST_Sub || el instanceof Cola.AST_Dot) && el.splated){