- Use inline `isset` expression instead function. status: done
- Use inline `is`. status: done
- `some is NaN` to `isNaN(some)`. status: done
- operator `?` instead `isset`. status: done
- rename runtime prefix `$_cola` to `_ColaRuntime$$`. status: done
- dotal names of refs: done
This commit is contained in:
Onoshko Dan 2014-08-14 20:05:38 +07:00
parent a9010b529b
commit c3df8f1d3f
9 changed files with 424 additions and 264 deletions

108
README.md
View File

@ -360,10 +360,33 @@ 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
- Use inline `is`.
- `some is NaN` to `isNaN(some)` status: done
- operator `?` instead `isset`, fix the operator with function call
- Use inline `is`. status: done
- `some is NaN` to `isNaN(some)`. status: done
- operator `?` instead `isset`. status: done
- rename runtime prefix `$_cola` to `_ColaRuntime$$`. status: done
- dotal names of refs: done
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;
- operator `?.`
- 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];
- operator `?` to sign an argument as not-required
int sqr(int x) => x ** 2;
@ -374,22 +397,16 @@ Future plans
int sqrt(int x?) => x ** 2;
sqr(); // NaN
- 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
- rename runtime prefix `$_cola` to `_crt$$`
- `@use klosure` wrapped code will be execute on `DOMContentLoaded`, `main` functions will triggered firstly:
- `@use` expressions
@use strict closure
- `@use await closure` wrapped code will be execute on `DOMContentLoaded`, `main` functions will triggered firstly:
// cola
@use klosure
@use await closure
main(){
alert('loaded!');
@ -406,36 +423,7 @@ Future plans
document.addEventListener('DOMContentLoaded', function(){
document.title = "Page";
}, false);
- inline using of `@use`
@use meteor
@use strict
@use closure
// or you can...
@use meteor strict closure
- dotal names of refs
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;
// or
Cola.AST_Node node = new Cola.AST_Node;
- interface
interface UserProfile {
@ -448,10 +436,10 @@ Future plans
class A {
private int a = 123;
protected var o = {};
int a = 123;
readonly String about = "class";
$("button").click(() => console.log("Button Clicked!"));
A(a){
about = "some else";
@ -510,12 +498,6 @@ Future plans
return res;
}
}
- destructed function arguments
test({String name, String login, String photoUrl}){
console.log(name, login, photoUrl);
}
- ES6 `for`
@ -530,24 +512,6 @@ Future plans
@import dirname from 'path'
String code = fs.readFileSync(dirname(filePath) + "/main.cola", "utf8");
- set parameters to calling function
$(".btn").on("click", *(){
this; // parent context
});
- namespaces, name of namespace must be cupitalized
@use Cola {
class AST_Node {
...
}
}
Cola.AST_Node node = new Cola.AST_Node();
- write documentation of tokenizer/parser methods

View File

@ -719,6 +719,16 @@ Cola.AST_Proto = Cola.DEFNODE("Proto", null, {
}
}, Cola.AST_PropAccess);
Cola.AST_CondAccess = Cola.DEFNODE("CondAccess", null, {
$iscola: true,
$documentation: "Conditional accessor",
_walk: function(visitor) {
return visitor._visit(this, function(){
this.expression._walk(visitor);
});
}
}, Cola.AST_PropAccess);
Cola.AST_Cascade = Cola.DEFNODE("Cascade", "expression subexpressions", {
$iscola: true,
$documentation: "Base class for properties access expressions, i.e. `a..foo..bar`",

File diff suppressed because one or more lines are too long

View File

@ -1704,16 +1704,8 @@ Cola.Compressor.MathFuncs = {
} else
if (!compressor.option("is_js") && self.expression instanceof Cola.AST_SymbolRef && Cola.Compressor.StdFuncs[self.expression.name] && self.args[0] instanceof Cola.AST_Constant) {
if (self.expression.name == "$_cola_isset" || self.expression.name == "$_cola_isntset")
return make_node(Cola.AST_Boolean, self, { value : Cola[self.expression.name](self.args[0].value) }).transform(compressor);
if ((self.expression.name == "$_cola_is" || self.expression.name == "$_cola_isnt") &&
self.args[1] instanceof Cola.AST_SymbolRef &&
(self.args[1].value == "Number" || self.args[1].value == "Boolean" || self.args[1].value == "String"))
return make_node(Cola.AST_Boolean, self, { value : Cola[self.expression.name](self.args[0].value, eval(self.args[1].value)) }).transform(compressor);
if (self.expression.name == "$_cola_modulo" && self.args[1] instanceof Cola.AST_Constant)
return make_node(Cola.AST_Number, self, { value : Cola.$_cola_modulo(self.args[0].value, self.args[1].value) }).transform(compressor);
if (self.expression.name == "_ColaRuntime$$modulo" && self.args[1] instanceof Cola.AST_Constant)
return make_node(Cola.AST_Number, self, { value : Cola._ColaRuntime$$modulo(self.args[0].value, self.args[1].value) }).transform(compressor);
}
}
if (compressor.option("unsafe")) {

View File

@ -224,7 +224,7 @@ main();</textarea>
mainbinding = document.getElementById("main_binding"),
compressed = document.getElementById("compressed"),
source;
//localStorage.clear();
if(!localStorage.source) localStorage.source = source = sourceArea.value;
else sourceArea.value = source = localStorage.source;
isjs.checked = localStorage.isjs == "t";
@ -315,7 +315,7 @@ main();</textarea>
}
}
compile();
changeClass();
compile();
</script>
</html>

View File

@ -49,7 +49,7 @@
!this.Cola && (this.Cola = {});
Cola.KEYWORDS = 'break case catch const continue debugger default delete do else finally for function if in instanceof new return switch throw try typeof var void while with';
Cola.cKEYWORDS = Cola.KEYWORDS.replace(' void', '') + ' when clone isset is isnt class singleton injector';
Cola.cKEYWORDS = Cola.KEYWORDS.replace(' void', '') + ' when clone is isnt class singleton injector';
Cola.KEYWORDS_ATOM = 'false null true';
Cola.cKEYWORDS_ATOM = Cola.KEYWORDS_ATOM + ' on yes off no';
@ -126,7 +126,6 @@ Cola.OPERATORS = [ // d - different left and right types of vars, s - same
"||", // binary - s
// ColaScript
"clone",
"isset",
"is",
"isnt",
"**",
@ -136,7 +135,7 @@ Cola.OPERATORS = [ // d - different left and right types of vars, s - same
];
Cola.cOPERATORS = Cola.makePredicate(Cola.OPERATORS);
Cola.OPERATORS = Cola.OPERATORS.slice(0, Cola.OPERATORS.length - 7);
Cola.OPERATORS = Cola.OPERATORS.slice(0, Cola.OPERATORS.length - 6);
Cola.OPERATORS.push('void');
Cola.OPERATORS = Cola.makePredicate(Cola.OPERATORS);
@ -145,10 +144,10 @@ Cola.COMPARISON = Cola.makePredicate("< > <= >= == === != !==");
Cola.WHITESPACE_CHARS = Cola.makePredicate(Cola.characters(" \u00a0\n\r\t\f\u000b\u200b\u180e\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200a\u202f\u205f\u3000"));
Cola.cPUNC_BEFORE_EXPRESSION = Cola.makePredicate(Cola.characters("[{(,.;:").concat(["::"]));
Cola.cPUNC_BEFORE_EXPRESSION = Cola.makePredicate(Cola.characters("[{(,.;:").concat(["::", "?."]));
Cola.PUNC_BEFORE_EXPRESSION = Cola.makePredicate(Cola.characters("[{(,.;:"));
Cola.PUNC_CHARS = Cola.makePredicate(Cola.characters("[]{}(),;:"));
Cola.PUNC_CHARS = Cola.makePredicate(Cola.characters("[]{}(),;:?"));
Cola.REGEXP_MODIFIERS = Cola.makePredicate(Cola.characters("gmsiy"));
@ -313,8 +312,11 @@ Cola.Tokenizer.prototype.dumpS = function () {
this.dumps[++this.dumpi] = Cola.clone(this.S);
};
Cola.Tokenizer.prototype.restoreS = function () {
Cola.Tokenizer.prototype.restoreS = function (onlyDown) {
if(this.dumpi == -1) return;
if(onlyDown) return this.dumpi--;
this.S = this.dumps[this.dumpi];
delete this.dumps[this.dumpi--];
};
@ -359,7 +361,7 @@ Cola.Tokenizer.prototype.token = function (type, value, is_comment) {
this.S.regex_allowed = ((type == "operator" && !this.UNARY_POSTFIX(value)) ||
(type == "keyword" && this.KEYWORDS_BEFORE_EXPRESSION(value)) ||
(type == "punc" && this.PUNC_BEFORE_EXPRESSION(value)));
this.prev_was_dot = (type == "punc" && value == ".") || (!this.is_js && type == "punc" && value == "::");
this.prev_was_dot = (type == "punc" && value == ".") || (!this.is_js && type == "punc" && (value == "::" || value == "?."));
var ret = {
type : type,
value : value,
@ -708,6 +710,7 @@ Cola.Tokenizer.prototype.next_token = function (force_regexp) {
if (Cola.PUNC_CHARS(ch)){
if (!this.is_js && ch == ":" && this.peek(1) == ":") return this.next(), this.next(), this.token("punc", "::");
if (!this.is_js && ch == "?" && this.peek(1) == ".") return this.next(), this.next(), this.token("punc", "?.");
if (!this.is_js && this.S.string.at[this.S.string.level].inside && (this.S.string.at[this.S.string.level].inside_at || this.S.string.at[this.S.string.level].inside_braces)) {
if (ch == '{') this.S.string.at[this.S.string.level].balance++;
@ -755,7 +758,6 @@ Cola.UNARY_PREFIX = Cola.makePredicate([
]);
Cola.cUNARY_PREFIX = Cola.makePredicate([
"clone",
"isset",
"typeof",
"delete",
"--",
@ -767,7 +769,7 @@ Cola.cUNARY_PREFIX = Cola.makePredicate([
]);
Cola.UNARY_POSTFIX = Cola.makePredicate([ "--", "++" ]);
Cola.cUNARY_POSTFIX = Cola.UNARY_POSTFIX;
Cola.cUNARY_POSTFIX = Cola.makePredicate([ "--", "++", "?" ]);
Cola.ASSIGNMENT = Cola.makePredicate([ "=", "+=", "-=", "/=", "*=", "%=", ">>=", "<<=", ">>>=", "|=", "^=", "&=" ]);
Cola.cASSIGNMENT = Cola.makePredicate([ "=", "+=", "-=", "/=", "*=", "%=", ">>=", "<<=", ">>>=", "|=", "^=", "&=", "?=" ]);
@ -891,13 +893,16 @@ Cola.Parser.prototype.parse = function () {
};
Cola.Parser.prototype.dumpS = function () {
this.dumps[++this.dumpi] = Cola.clone(this.S);
this.dumps[++this.dumpi] = Cola.clone(this.S);
this.tokenizer.dumpS();
};
Cola.Parser.prototype.restoreS = function () {
Cola.Parser.prototype.restoreS = function (onlyDown) {
if(this.dumpi == -1) return;
this.tokenizer.restoreS();
this.tokenizer.restoreS(onlyDown);
if(onlyDown) return this.dumpi--;
this.S = this.dumps[this.dumpi];
delete this.dumps[this.dumpi--];
};
@ -1022,15 +1027,22 @@ Cola.Parser.prototype.statement = Cola.Parser.embed_tokens(function() {
case "name":
if(!this.is_js && this.next_is("name")){
type = this.S.token.value, this.next();
if(this.next_is("punc", "(")) return this.function_(Cola.AST_Defun, type);
var isfun = false;
this.dumpS();
this.subscripts(this.as_symbol(Cola.AST_SymbolDefun), false);
isfun = this.is("punc", "(");
this.restoreS();
if(isfun) return this.function_(Cola.AST_Defun, type);
return tmp = this.var_(false, type), this.semicolon(), tmp;
}
if(!this.is_js){
if(!this.is_js){
var _this = this, balance = 1, isfun = false;
this.dumpS();
this.next();
this.subscripts(this.as_symbol(Cola.AST_SymbolDefun), false);
if(this.is('punc', '(')){
this.next();
this.next_until(function(){
@ -1331,6 +1343,7 @@ Cola.Parser.prototype.function_ = function(ctor, type) {
var in_statement = ctor === Cola.AST_Defun, _this = this, splatedexist = false;
var name = this.is("name") ? this.as_symbol(in_statement ? Cola.AST_SymbolDefun : Cola.AST_SymbolLambda) : null;
if (name != null) name = this.subscripts(name, false);
if (in_statement && !name)
this.unexpected();
this.expect("(");
@ -1482,6 +1495,10 @@ Cola.Parser.prototype.vardefs = function (no_in, in_const, type) {
start : this.S.token,
type : type,
name : (function(_this){
if(!_this.is_js) return _this.subscripts(_this.as_symbol(in_const ? Cola.AST_SymbolConst : Cola.AST_SymbolVar), false);
//_this.dumpS();
//console.log(_this.subscripts(_this.as_symbol(in_const ? Cola.AST_SymbolConst : Cola.AST_SymbolVar), true));
//_this.restoreS();
//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);
@ -1745,10 +1762,11 @@ Cola.Parser.prototype.expr_list = function (closing, allow_trailing_comma, allow
a.push(new Cola.AST_Hole({ start: this.S.token, end: this.S.token }));
} else
if(this.is("name") && allow_named_args){
name = Cola.$_cola_clone(this.S.token);
name = this.S.token.clone();
this.dumpS();
this.next();
if(this.is("punc",":")){
this.restoreS(true);
this.next();
a.push(new Cola.AST_Namedarg({
name : name.value,
@ -1847,7 +1865,7 @@ Cola.Parser.prototype.array_ = Cola.Parser.embed_tokens(function(is_template, is
}
if (!(val instanceof Cola.AST_SymbolRef ||
val instanceof Cola.AST_ObjectTemplate || val instanceof Cola.AST_ArrayTemplate ||
!is_var && ( val instanceof Cola.AST_Dot || val instanceof Cola.AST_Sub ) ||
!is_var && ( val instanceof Cola.AST_PropAccess ) ||
val instanceof Cola.AST_Object && val.template == true ||
val instanceof Cola.AST_Array && val.template == true)) {
@ -1926,7 +1944,7 @@ Cola.Parser.prototype.object_ = Cola.Parser.embed_tokens(function(is_template, i
}
if (!(val instanceof Cola.AST_SymbolRef ||
val instanceof Cola.AST_ObjectTemplate || val instanceof Cola.AST_ArrayTemplate ||
!is_var && ( val instanceof Cola.AST_Dot || val instanceof Cola.AST_Sub ) ||
!is_var && ( val instanceof Cola.AST_PropAccess ) ||
val instanceof Cola.AST_Object && val.template == true ||
val instanceof Cola.AST_Array && val.template == true)) {
@ -2018,6 +2036,15 @@ Cola.Parser.prototype.subscripts = function(expr, allow_calls) {
end : this.prev()
}), allow_calls);
}
if (this.is("punc", "?.") && !this.is_js) {
this.next();
return this.subscripts(new Cola.AST_CondAccess({
start : start,
expression : expr,
property : this.as_name(),
end : this.prev()
}), allow_calls);
}
if (this.is("punc", "[")) {
this.next();
@ -2025,10 +2052,10 @@ Cola.Parser.prototype.subscripts = function(expr, allow_calls) {
if(this.is_js) prop = this.expression(true);
else if(this.is("punc","]")) prop = new Cola.AST_Noop();
else {
if(this.is("punc","..") || this.is("punc","...")) prop = new Cola.AST_Number({ value : 0 });
if((this.is("punc","..") || this.is("punc","...")) && !this.is_js) prop = new Cola.AST_Number({ value : 0 });
else prop = this.expression(true, false, true);
this.dumpS();
if(this.is("punc","..") || this.is("punc","...")){
//this.dumpS();
if((this.is("punc","..") || this.is("punc","...")) && !this.is_js){
triple = this.is("punc","...");
this.next();
prop = new Cola.AST_ArrayRange({
@ -2038,7 +2065,7 @@ Cola.Parser.prototype.subscripts = function(expr, allow_calls) {
start : prop.start,
end : this.prev()
});
} else this.restoreS();
} //else this.restoreS();
}
this.expect("]");
@ -2073,6 +2100,11 @@ Cola.Parser.prototype.maybe_unary = function(allow_calls) {
}
var val = this.expr_atom(allow_calls);
while (this.is("operator") && this.UNARY_POSTFIX(this.S.token.value) && !this.S.token.nlb) {
if(!this.is_js && this.is("operator", "?") &&
!(this.next_is("punc", ";") || this.next_is("punc", ",") || this.next_is("punc", ":") ||
this.next_is("punc", ")") || this.next_is("punc", "]") || this.next_is("punc", "}") ||
this.next_is("operator", "?") || this.next_is("operator") && this.PRECEDENCE[this.peek().value])) break;
val = this.make_unary(Cola.AST_UnaryPostfix, this.S.token.value, val);
val.start = start;
val.end = this.S.token;
@ -2139,6 +2171,15 @@ Cola.Parser.prototype.maybe_conditional = function(no_in) {
var expr = this.expr_ops(no_in);
if (this.is("operator", "?")) {
this.next();
/*if(!this.is_js && (this.is("punc", ";") || this.is("punc", ",") || this.is("punc", ":") ||
this.is("punc", ")") || this.is("punc", "]") || this.is("punc", "}") ||
this.is("operator", "?") || this.PRECEDENCE[this.S.token.value]))
return new Cola.AST_UnaryPostfix({
operator : "?",
expression : expr
});*/
var yes = this.expression(false);
return new Cola.AST_Conditional({
@ -2186,6 +2227,7 @@ Cola.Parser.prototype.cascade = function(expr, start) {
while (this.next()) {
if (this.is("name") || this.is("punc","[")) {
last = this.expression(false, false, true);
if (this.is("punc", ":")) {
last = this.cascade(last, last.start);
this.next();
@ -2194,10 +2236,8 @@ Cola.Parser.prototype.cascade = function(expr, start) {
if (!( last instanceof Cola.AST_SymbolRef
|| last instanceof Cola.AST_Binary
|| last instanceof Cola.AST_Call
|| last instanceof Cola.AST_Sub
|| last instanceof Cola.AST_Dot
|| last instanceof Cola.AST_PropAccess
|| last instanceof Cola.AST_Array
|| last instanceof Cola.AST_Cascade
)) this.unexpected();
}
if (!this.is("punc", "..")) break;

View File

@ -36,48 +36,40 @@
!this.Cola && (this.Cola = {});
Cola.$_cola_is = function $_cola_is(_object, _type){
Cola._ColaRuntime$$is = function _ColaRuntime$$is(_object, _type){
return _object === _type || _type.prototype && (_object instanceof _type || _object.__proto__ === _type.prototype);
}
Cola.$_cola_is.i = 0;
Cola._ColaRuntime$$is.i = 0;
Cola.$_cola_isnt = function $_cola_isnt(_object, _type){
Cola._ColaRuntime$$isnt = function _ColaRuntime$$isnt(_object, _type){
return !(_object === _type || _type.prototype && (_object instanceof _type || _object.__proto__ === _type.prototype));
}
Cola.$_cola_isnt.i = 1;
Cola._ColaRuntime$$isnt.i = 1;
Cola.$_cola_modulo = function $_cola_modulo(_a, _b){
Cola._ColaRuntime$$modulo = function _ColaRuntime$$modulo(_a, _b){
return (_a % _b + +_b) % _b;
}
Cola.$_cola_modulo.i = 2;
Cola._ColaRuntime$$modulo.i = 2;
Cola.$_cola_isset = function $_cola_isset(_object){
Cola._ColaRuntime$$isset = function _ColaRuntime$$isset(_object){
return !(typeof _object === "undefined" || _object === null);
}
Cola.$_cola_isset.i = 3;
Cola._ColaRuntime$$isset.i = 3;
Cola.$_cola_isntset = function $_cola_isntset(_object){
Cola._ColaRuntime$$isntset = function _ColaRuntime$$isntset(_object){
return (typeof _object === "undefined" || _object === null);
}
Cola.$_cola_isntset.i = 4;
Cola._ColaRuntime$$isntset.i = 4;
Cola.$_cola_clone = function $_cola_clone(_item){
Cola._ColaRuntime$$clone = function _ColaRuntime$$clone(_item){
if (_item === undefined || _item === null) return _item;
if (_item.__clone__ instanceof Function) return _item.__clone__();
var result, types = [ Number, String, Boolean ];
for (var i in types)
if(types.hasOwnProperty(i) && _item instanceof types[i])
return types[i]( _item );
if(_item instanceof Number) return Number(_item);
if(_item instanceof String) return String(_item);
if(_item instanceof Boolean) return Boolean(_item);
if (_item.__proto__ === Array.prototype) {
result = [];
_item.forEach(function(child, index, array) {
result[index] = $_cola_clone( child );
});
return result;
}
var result;
if (!(_item instanceof Object)) return _item;
@ -87,61 +79,56 @@ Cola.$_cola_clone = function $_cola_clone(_item){
if (_item instanceof Date) return new Date(_item);
if (_item instanceof Function) return _item;
result = {};
for (var i in _item) result[i] = $_cola_clone( _item[i] );
result.__proto__ = _item.__proto__;
result = new (Object.getPrototypeOf(_item).constructor);
for (var i in _item) result[i] = _ColaRuntime$$clone( _item[i] );
return result;
}
return _item;
}
Cola.$_cola_clone.i = 5;
Cola._ColaRuntime$$clone.i = 5;
Cola.$_cola_array_last = function $_cola_array_last(_array){
Cola._ColaRuntime$$array_last = function _ColaRuntime$$array_last(_array){
return _array[_array.length - 1];
}
Cola.$_cola_array_last.i = 6;
Cola._ColaRuntime$$array_last.i = 6;
Cola.$_cola_array_range = function $_cola_array_range(_from, _to){
Cola._ColaRuntime$$array_range = function _ColaRuntime$$array_range(_from, _to){
var range = [];
if(_from <= _to) for(var i = _from; i <= _to; i++) range.push(i);
else for(var i = _from; i >= _to; i--) range.push(i);
return range;
}
Cola.$_cola_array_range.i = 7;
Cola._ColaRuntime$$array_range.i = 7;
Cola.$_cola_array_asplice = function $_cola_array_asplice(_array, _from, _to, _a){
Cola._ColaRuntime$$array_asplice = function _ColaRuntime$$array_asplice(_array, _from, _to, _a){
_to = _to - _from + 1;
return [].splice.apply(_array, [_from, _to].concat(_a)), _a;
}
Cola.$_cola_array_asplice.i = 8;
Cola._ColaRuntime$$array_asplice.i = 8;
Cola.$_cola_func_named_args = function $_cola_func_named_args(_args){
Cola._ColaRuntime$$func_named_args = function _ColaRuntime$$func_named_args(_args){
this.$ = _args;
}
Cola.$_cola_func_named_args.i = 9;
Cola._ColaRuntime$$func_named_args.i = 9;
Cola.$_cola_func_set_named_args = function $_cola_func_set_named_args(_args){
if(_args[_args.length - 1] instanceof $_cola_func_named_args){
Cola._ColaRuntime$$func_set_named_args = function _ColaRuntime$$func_set_named_args(_args){
if(_args[_args.length - 1] instanceof _ColaRuntime$$func_named_args){
var nargs = _args[_args.length - 1].$;
for(var i in nargs) if(nargs.hasOwnProperty(i))
_args[i] = nargs[i];
}
}
Cola.$_cola_func_set_named_args.i = 10;
Cola.$_cola_arguments_def = { i : 11 };
Cola._ColaRuntime$$func_set_named_args.i = 10;
Cola._ColaRuntime$$arguments_def = { i : 11 };
Cola.$_cola =
Cola.$_cola_is + Cola.$_cola_isnt + Cola.$_cola_modulo + Cola.$_cola_isset +
Cola.$_cola_isntset + Cola.$_cola_clone + Cola.$_cola_array_last + Cola.$_cola_array_range +
Cola.$_cola_array_asplice + Cola.$_cola_func_named_args + Cola.$_cola_func_set_named_args +
Cola._ColaRuntime$$is + Cola._ColaRuntime$$isnt + Cola._ColaRuntime$$modulo + Cola._ColaRuntime$$isset +
Cola._ColaRuntime$$isntset + Cola._ColaRuntime$$clone + Cola._ColaRuntime$$array_last + Cola._ColaRuntime$$array_range +
Cola._ColaRuntime$$array_asplice + Cola._ColaRuntime$$func_named_args + Cola._ColaRuntime$$func_set_named_args +
"var arguments;";
Cola.Compressor.StdFuncs = {
$_cola_is : true,
$_cola_isnt : true,
$_cola_modulo : true,
$_cola_isset : true,
$_cola_isntset : true
_ColaRuntime$$modulo : true
};

View File

@ -46,6 +46,97 @@ Cola.Constructions.setPos = function(node, ext){
return node;
};
/*
({{left}} === {{right}} || {{right}}.prototype && ({{left}} instanceof {{right}} || typeof {{left}} === typeof {{right}}()))
*/
Cola.Constructions.Is = function(left, right, ext){
return this.setPos(new Cola.AST_Binary({
left : new Cola.AST_Binary({
left : left,
operator : "===",
right : right
}),
operator : "||",
right : new Cola.AST_Binary({
left : new Cola.AST_Dot({
expression : right,
property : "prototype"
}),
operator : "&&",
right : new Cola.AST_Binary({
left : new Cola.AST_Binary({
left : left,
operator : "instanceof",
right : right
}),
operator : "||",
right : new Cola.AST_Binary({
left : new Cola.AST_UnaryPrefix({
operator : "typeof",
expression : left
}),
operator : "===",
right : new Cola.AST_UnaryPrefix({
operator : "typeof",
expression : new Cola.AST_Call({
expression : right,
args : []
})
})
})
})
})
}), ext);
};
/*
!({{left}} === {{right}} || {{right}}.prototype && ({{left}} instanceof {{right}} || typeof {{left}} === typeof {{right}}()))
*/
Cola.Constructions.Isnt = function(left, right, ext){
return this.setPos(new Cola.AST_UnaryPrefix({
operator : "!",
expression : new Cola.AST_Binary({
left : new Cola.AST_Binary({
left : left,
operator : "===",
right : right
}),
operator : "||",
right : new Cola.AST_Binary({
left : new Cola.AST_Dot({
expression : right,
property : "prototype"
}),
operator : "&&",
right : new Cola.AST_Binary({
left : new Cola.AST_Binary({
left : left,
operator : "instanceof",
right : right
}),
operator : "||",
right : new Cola.AST_Binary({
left : new Cola.AST_UnaryPrefix({
operator : "typeof",
expression : left
}),
operator : "===",
right : new Cola.AST_UnaryPrefix({
operator : "typeof",
expression : new Cola.AST_Call({
expression : right,
args : []
})
})
})
})
})
})
}), ext);
};
/*
!(typeof {{node}} === "undefined" || {{node}} === null)
@ -100,7 +191,7 @@ Cola.Constructions.IsntSet = function(node, ext){
*/
Cola.Constructions.SplatedConditional = function(name, uid, pos, after, length){
if(Cola.$_cola_is(name, String)) name = new Cola.AST_SymbolRef({ name : name });
if(Cola._ColaRuntime$$is(name, String)) name = new Cola.AST_SymbolRef({ name : name });
return new Cola.AST_Conditional({
condition : new Cola.AST_Binary({
operator : "<=",
@ -155,7 +246,7 @@ Cola.Constructions.SplatedConditional = function(name, uid, pos, after, length){
*/
Cola.Constructions.ValueWithOffset = function(name, uid, cond, pos, after){
if(Cola.$_cola_is(name, String)) name = new Cola.AST_SymbolRef({ name : name });
if(Cola._ColaRuntime$$is(name, String)) name = new Cola.AST_SymbolRef({ name : name });
return new Cola.AST_Sub({
expression : name,
property : cond
@ -189,11 +280,11 @@ Cola.Constructions.ValueWithKey = function(cond, name, key){
};
/*
{{name}} = {{length}} <= arguments.length ? [].slice.call(arguments, {{pos}}, $_cola_i = arguments.length - {{after}}) : ($_cola_i = {{pos}}, [])
{{name}} = {{length}} <= arguments.length ? [].slice.call(arguments, {{pos}}, _ColaRuntime$$i = arguments.length - {{after}}) : (_ColaRuntime$$i = {{pos}}, [])
*/
Cola.Constructions.SplatedVarDef = function(name, pos, after, length){
if(Cola.$_cola_is(name, String)) name = { name : name };
if(Cola._ColaRuntime$$is(name, String)) name = { name : name };
return new Cola.AST_VarDef({
type : "Array",
name : new Cola.AST_SymbolVar(name), // name
@ -206,11 +297,11 @@ Cola.Constructions.SplatedVarDef = function(name, pos, after, length){
or
{{name}} = arguments[$_cola_i + {{aftersplated}}]
{{name}} = arguments[_ColaRuntime$$i + {{aftersplated}}]
*/
Cola.Constructions.PosedVarDef = function(name, type, pos, aftersplated){
if(Cola.$_cola_is(name, String)) name = { name : name };
if(Cola._ColaRuntime$$is(name, String)) name = { name : name };
return new Cola.AST_VarDef({
type : type,
name : new Cola.AST_SymbolVar(name),
@ -223,11 +314,11 @@ Cola.Constructions.PosedVarDef = function(name, type, pos, aftersplated){
or
{{name}} = arguments[$_cola_i + {{aftersplated}}] !== undefined ? arguments[$_cola_i + {{aftersplated}}] : {{defval}}
{{name}} = arguments[_ColaRuntime$$i + {{aftersplated}}] !== undefined ? arguments[_ColaRuntime$$i + {{aftersplated}}] : {{defval}}
*/
Cola.Constructions.PosedWithDefsVarDef = function(name, type, defval, pos, aftersplated){
if(Cola.$_cola_is(name, String)) name = { name : name };
if(Cola._ColaRuntime$$is(name, String)) name = { name : name };
return new Cola.AST_VarDef({
type : type,
name : new Cola.AST_SymbolVar(name),
@ -248,7 +339,7 @@ Cola.Constructions.PosedWithDefsVarDef = function(name, type, defval, pos, after
*/
Cola.Constructions.NamedVarDef = function(name, type, defval, key){
if(Cola.$_cola_is(name, String)) name = { name : name };
if(Cola._ColaRuntime$$is(name, String)) name = { name : name };
return new Cola.AST_VarDef({
type : type,
name : new Cola.AST_SymbolVar(name),
@ -270,6 +361,14 @@ Cola.Constructions.NamedVarDef = function(name, type, defval, key){
});
};
Cola.CondAccessContains = function(node){
if(!(node instanceof Cola.AST_Call || node instanceof Cola.AST_PropAccess)) return false;
var expr = node;
while(expr.expression instanceof Cola.AST_Call || expr.expression instanceof Cola.AST_PropAccess){
expr = expr.expression;
}
};
Cola.AST_Toplevel.prototype.toJavaScript = function(options){
if(this.language == 'js') return this;
@ -283,8 +382,8 @@ Cola.AST_Toplevel.prototype.toJavaScript = function(options){
path : ""
});
var $_cola_ast = Cola.parse(Cola.$_cola, { is_js : true }),
$_cola_hash = {},
var _ColaRuntime$$ast = Cola.parse(Cola.$_cola, { is_js : true }),
_ColaRuntime$$hash = {},
_this,
@ -353,21 +452,33 @@ Cola.AST_Toplevel.prototype.toJavaScript = function(options){
to
$_cola_modulo(5, 2)
_ColaRuntime$$modulo(5, 2)
*/
if(node instanceof Cola.AST_Binary && node.operator == '%%'){
$_cola_hash[Cola.$_cola_modulo.i] = true;
_ColaRuntime$$hash[Cola._ColaRuntime$$modulo.i] = true;
props = {
start : node.start,
end : node.end,
args : [node.left, node.right],
expression : new Cola.AST_SymbolRef({ name : '$_cola_modulo' })
expression : new Cola.AST_SymbolRef({ name : '_ColaRuntime$$modulo' })
};
node = new Cola.AST_Call(props);
} else
/*
a.b?.c();
to
typeof a.b === "undefined" && a.b === null ? undefined : a.b.c();
*/
if(node instanceof ){
} else
/*
a ?= b;
@ -494,19 +605,11 @@ Cola.AST_Toplevel.prototype.toJavaScript = function(options){
to
$_cola_is(123, Number)
123 === Number || Number.prototype && (123 instanceof Number || typeof 123 === typeof Number()))
*/
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],
expression : new Cola.AST_SymbolRef({ name : '$_cola_is' })
};
node = new Cola.AST_Call(props);
node = Cola.Constructions.Is(node.left, node.right, node);
} else
/*
@ -514,30 +617,22 @@ Cola.AST_Toplevel.prototype.toJavaScript = function(options){
to
$_cola_isnt(true, String);
!(true === String || String.prototype && (true instanceof String || typeof true === typeof String())))
*/
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],
expression : new Cola.AST_SymbolRef({ name : '$_cola_isnt' })
};
node = new Cola.AST_Call(props);
node = Cola.Constructions.Isnt(node.left, node.right, node);
} else
/*
isset a
a?
to
$_cola_isset(a)
_ColaRuntime$$isset(a)
*/
if(node instanceof Cola.AST_UnaryPrefix && node.operator == 'isset'){
if(node instanceof Cola.AST_UnaryPostfix && node.operator == '?'){
node = Cola.Constructions.IsSet(node.expression, node);
} else
@ -546,16 +641,16 @@ Cola.AST_Toplevel.prototype.toJavaScript = function(options){
to
a = $_cola_clone(b)
a = _ColaRuntime$$clone(b)
*/
if(node instanceof Cola.AST_UnaryPrefix && node.operator == 'clone'){
$_cola_hash[Cola.$_cola_clone.i] = true;
_ColaRuntime$$hash[Cola._ColaRuntime$$clone.i] = true;
props = {
start : node.start,
end : node.end,
args : [node.expression],
expression : new Cola.AST_SymbolRef({ name : '$_cola_clone' })
expression : new Cola.AST_SymbolRef({ name : '_ColaRuntime$$clone' })
};
node = new Cola.AST_Call(props);
@ -611,16 +706,16 @@ Cola.AST_Toplevel.prototype.toJavaScript = function(options){
to
func($_cola_array_last(arr))
func(_ColaRuntime$$array_last(arr))
*/
if(node instanceof Cola.AST_Sub && node.property instanceof Cola.AST_Noop){
$_cola_hash[Cola.$_cola_array_last.i] = true;
_ColaRuntime$$hash[Cola._ColaRuntime$$array_last.i] = true;
props = {
start : node.start,
end : node.end,
args : [node.expression],
expression : new Cola.AST_SymbolRef({ name : '$_cola_array_last' })
expression : new Cola.AST_SymbolRef({ name : '_ColaRuntime$$array_last' })
};
node = new Cola.AST_Call(props);
@ -631,16 +726,16 @@ Cola.AST_Toplevel.prototype.toJavaScript = function(options){
to
$_cola_array_asplice(arr, 0, 1, 123)
_ColaRuntime$$array_asplice(arr, 0, 1, 123)
*/
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;
_ColaRuntime$$hash[Cola._ColaRuntime$$array_asplice.i] = true;
props = {
start : node.start,
end : node.end,
args : [node.left.expression, node.left.property.from, node.left.property.to, node.right],
expression : new Cola.AST_SymbolRef({ name : '$_cola_array_asplice' })
expression : new Cola.AST_SymbolRef({ name : '_ColaRuntime$$array_asplice' })
};
if(node.left.property.to instanceof Cola.AST_Noop) props.args[2] = new Cola.AST_Number({ value : '9e9' });
@ -689,16 +784,16 @@ Cola.AST_Toplevel.prototype.toJavaScript = function(options){
to
$_cola_array_range(0, 3)
_ColaRuntime$$array_range(0, 3)
*/
if(node instanceof Cola.AST_ArrayRange){
$_cola_hash[Cola.$_cola_array_range.i] = true;
_ColaRuntime$$hash[Cola._ColaRuntime$$array_range.i] = true;
props = {
start : node.start,
end : node.end,
args : [node.from, node.to],
expression : new Cola.AST_SymbolRef({ name : '$_cola_array_range' })
expression : new Cola.AST_SymbolRef({ name : '_ColaRuntime$$array_range' })
};
if(node.triple) props.args[1] = new Cola.AST_Binary({
@ -710,12 +805,85 @@ Cola.AST_Toplevel.prototype.toJavaScript = function(options){
node = new Cola.AST_Call(props);
} else
/*
int obj.num = 0
to
obj.num = 0
*/
if(node instanceof Cola.AST_Var){
var defCache = []; newNode = [];
node.definitions.forEach(function(def, i){
if(!(def.name instanceof Cola.AST_SymbolVar)){
if(defCache.length != 0){
newNode.push(node.clone());
newNode[newNode.length - 1].definitions = defCache;
defCache = [];
}
newNode.push(new Cola.AST_Assign({
start : def.start,
end : def.end,
operator : '=',
left : def.name,
right : def.value
}));
newNode[newNode.length - 1] = new Cola.AST_SimpleStatement({
body : newNode[newNode.length - 1]
});
} else defCache.push(def);
});
if(defCache.length != 0){
newNode.push(node.clone());
newNode[newNode.length - 1].definitions = defCache;
defCache = [];
}
node = newNode;
} else
/*
int Math.rand(){} or Math.rand(){}
to
Math.rand = function(){}
*/
if(node instanceof Cola.AST_Defun && !(node.name instanceof Cola.AST_SymbolDefun)){
var texpr = node.name;
while(!(texpr.expression instanceof Cola.AST_SymbolDefun)) texpr = texpr.expression;
texpr.expression = new Cola.AST_SymbolRef(texpr.expression);
node = new Cola.AST_Assign({
start : node.start,
end : node.end,
operator : '=',
left : node.name,
right : (function(node){
node.name = new Cola.AST_SymbolLambda({
start : node.name.start,
end : node.name.end,
name : node.name.property
});
return new Cola.AST_Function(node);
})(node)
});
node = new Cola.AST_SimpleStatement({
body : node
});
} else
/*
func(a, b, name : name, c)
to
func(a, b, c, new $_cola_func_named_args({ name : name }))
func(a, b, c, new _ColaRuntime$$func_named_args({ name : name }))
*/
if(node instanceof Cola.AST_Call){
@ -725,7 +893,7 @@ Cola.AST_Toplevel.prototype.toJavaScript = function(options){
node.args.forEach(function(val, i){
if(!(val instanceof Cola.AST_Namedarg)) return;
$_cola_hash[Cola.$_cola_func_named_args.i] = true;
_ColaRuntime$$hash[Cola._ColaRuntime$$func_named_args.i] = true;
delQueue.push(i);
props.properties.push(new Cola.AST_ObjectKeyVal({
@ -745,7 +913,7 @@ Cola.AST_Toplevel.prototype.toJavaScript = function(options){
start : node.start,
end : node.end,
args : [new Cola.AST_Object(props)],
expression : new Cola.AST_SymbolRef({ name : '$_cola_func_named_args' })
expression : new Cola.AST_SymbolRef({ name : '_ColaRuntime$$func_named_args' })
};
node.args.push(new Cola.AST_New(props));
@ -760,9 +928,9 @@ Cola.AST_Toplevel.prototype.toJavaScript = function(options){
to
function func(s){
$_cola_func_set_named_args(arguments);
var $_cola_i, list = 3 <= arguments.length ? [].slice.call(arguments, 1, $_cola_i = arguments.length - 1) : ($_cola_i = 2, []),
b = arguments[$_cola_i+0] !== undefined ? arguments[$_cola_i+0] : false,
_ColaRuntime$$func_set_named_args(arguments);
var _ColaRuntime$$i, list = 3 <= arguments.length ? [].slice.call(arguments, 1, _ColaRuntime$$i = arguments.length - 1) : (_ColaRuntime$$i = 2, []),
b = arguments[_ColaRuntime$$i+0] !== undefined ? arguments[_ColaRuntime$$i+0] : false,
n = arguments.n,
h = arguments.h !== undefined ? arguments.h : 123;
}
@ -807,7 +975,7 @@ Cola.AST_Toplevel.prototype.toJavaScript = function(options){
aftersplated = 0;
props.definitions.push(new Cola.AST_VarDef({
type : "int",
name : new Cola.AST_SymbolVar({ name : '$_cola_i' }),
name : new Cola.AST_SymbolVar({ name : '_ColaRuntime$$i' }),
value : null
}));
@ -834,12 +1002,12 @@ Cola.AST_Toplevel.prototype.toJavaScript = function(options){
if(delQueue.length != 0 || named.length != 0) node.body.unshift(new Cola.AST_Var(props));
if(named.length != 0){
$_cola_hash[Cola.$_cola_func_named_args.i] = true;
$_cola_hash[Cola.$_cola_func_set_named_args.i] = true;
_ColaRuntime$$hash[Cola._ColaRuntime$$func_named_args.i] = true;
_ColaRuntime$$hash[Cola._ColaRuntime$$func_set_named_args.i] = true;
node.body.unshift(new Cola.AST_SimpleStatement({
body : new Cola.AST_Call({
args : [new Cola.AST_SymbolRef({ name : 'arguments' })],
expression : new Cola.AST_SymbolRef({ name : '$_cola_func_set_named_args' })
expression : new Cola.AST_SymbolRef({ name : '_ColaRuntime$$func_set_named_args' })
})
}));
}
@ -857,24 +1025,24 @@ Cola.AST_Toplevel.prototype.toJavaScript = function(options){
to
(function($_cola_expr, arguments){
$_cola_expr[0] = yes;
$_cola_expr.foo = bar;
$_cola_expr.baz();
(function(_ColaRuntime$$expr, arguments){
_ColaRuntime$$expr[0] = yes;
_ColaRuntime$$expr.foo = bar;
_ColaRuntime$$expr.baz();
(function($_cola_expr, arguments){
$_cola_expr.subfoo = no;
$_cola_expr.subaz();
(function(_ColaRuntime$$expr, arguments){
_ColaRuntime$$expr.subfoo = no;
_ColaRuntime$$expr.subaz();
return $_cola_expr;
}).call(this, $_cola_expr.sub, arguments);
return _ColaRuntime$$expr;
}).call(this, _ColaRuntime$$expr.sub, arguments);
return $_cola_expr;
return _ColaRuntime$$expr;
}).call(this, obj, arguments);
*/
if(node instanceof Cola.AST_Cascade){
$_cola_hash[Cola.$_cola_arguments_def.i] = true;
_ColaRuntime$$hash[Cola._ColaRuntime$$arguments_def.i] = true;
props = {
type : "dynamic",
@ -883,7 +1051,7 @@ Cola.AST_Toplevel.prototype.toJavaScript = function(options){
argtype : "positional",
type : "dynamic",
defval : new Cola.AST_Noop(),
name : new Cola.AST_SymbolFunarg({ name : "$_cola_expr", start : node.expression.start, end : node.expression.end })
name : new Cola.AST_SymbolFunarg({ name : "_ColaRuntime$$expr", start : node.expression.start, end : node.expression.end })
}), new Cola.AST_ArgDef({
argtype : "positional",
type : "dynamic",
@ -896,8 +1064,7 @@ Cola.AST_Toplevel.prototype.toJavaScript = function(options){
node.subexpressions.forEach(function(expr){
Expr = expr, Parent = false;
while(true)
if( expr instanceof Cola.AST_Call || expr instanceof Cola.AST_Dot ||
expr instanceof Cola.AST_Sub || expr instanceof Cola.AST_Cascade){
if( expr instanceof Cola.AST_Call || expr instanceof Cola.AST_PropAccess){
Parent = expr;
expr = expr.expression;
} else
@ -911,13 +1078,13 @@ Cola.AST_Toplevel.prototype.toJavaScript = function(options){
if(expr instanceof Cola.AST_Array || expr instanceof Cola.AST_ArrayRange) Expr = new Cola.AST_Sub({
start : Expr.start,
end : Expr.end,
expression : new Cola.AST_SymbolRef({ name : "$_cola_expr" }),
expression : new Cola.AST_SymbolRef({ name : "_ColaRuntime$$expr" }),
property : expr instanceof Cola.AST_ArrayRange ? expr : ( expr.elements.length == 0 ? new Cola.AST_Noop() : expr.elements[0] )
}); else
if(expr instanceof Cola.AST_SymbolRef) Expr = new Cola.AST_Dot({
start : Expr.start,
end : Expr.end,
expression : new Cola.AST_SymbolRef({ name : "$_cola_expr" }),
expression : new Cola.AST_SymbolRef({ name : "_ColaRuntime$$expr" }),
property : Expr.name
});
} else {
@ -925,19 +1092,18 @@ Cola.AST_Toplevel.prototype.toJavaScript = function(options){
expr = new Cola.AST_Sub({
start : expr.start,
end : expr.end,
expression : new Cola.AST_SymbolRef({ name : "$_cola_expr" }),
expression : new Cola.AST_SymbolRef({ name : "_ColaRuntime$$expr" }),
property : expr instanceof Cola.AST_ArrayRange ? expr : ( expr.elements.length == 0 ? new Cola.AST_Noop() : expr.elements[0] )
});
else
expr = new Cola.AST_Dot({
start : expr.start,
end : expr.end,
expression : new Cola.AST_SymbolRef({ name : "$_cola_expr" }),
expression : new Cola.AST_SymbolRef({ name : "_ColaRuntime$$expr" }),
property : expr.name
});
if( Parent instanceof Cola.AST_Call || Parent instanceof Cola.AST_Dot ||
Parent instanceof Cola.AST_Sub || Parent instanceof Cola.AST_Cascade) Parent.expression = expr;
if( Parent instanceof Cola.AST_Call || Parent instanceof Cola.AST_PropAccess) Parent.expression = expr;
else
if(Parent instanceof Cola.AST_Binary) Parent.left = expr;
}
@ -950,7 +1116,7 @@ Cola.AST_Toplevel.prototype.toJavaScript = function(options){
});
props.body.push(new Cola.AST_Return({
value : new Cola.AST_SymbolRef({ name : "$_cola_expr" })
value : new Cola.AST_SymbolRef({ name : "_ColaRuntime$$expr" })
}));
props = {
@ -972,8 +1138,8 @@ Cola.AST_Toplevel.prototype.toJavaScript = function(options){
to
var c = obj[0], b = obj[1][0], b2 = obj[1][1], $_cola_i = obj.length - 1, a = obj[$_cola_i++].key;
var $_cola_tmp = { key : "val" }, d = $_cola_tmp["key"];
var c = obj[0], b = obj[1][0], b2 = obj[1][1], _ColaRuntime$$i = obj.length - 1, a = obj[_ColaRuntime$$i++].key;
var _ColaRuntime$$tmp = { key : "val" }, d = _ColaRuntime$$tmp["key"];
*/
/*if(node instanceof Cola.AST_Var){
@ -986,7 +1152,7 @@ Cola.AST_Toplevel.prototype.toJavaScript = function(options){
var Symbol = def.value instanceof Cola.AST_SymbolRef
? def.value
: new Cola.AST_SymbolRef({ name : "$_cola_tmp" });
: new Cola.AST_SymbolRef({ name : "_ColaRuntime$$tmp" });
if(!(def.value instanceof Cola.AST_SymbolRef)) defs.push(new Cola.AST_VarDef({
type : node.type,
name : new Cola.AST_SymbolVar(Symbol),
@ -1148,7 +1314,7 @@ Cola.AST_Toplevel.prototype.toJavaScript = function(options){
var Symbol = node.right instanceof Cola.AST_SymbolRef
? node.right
: new Cola.AST_SymbolRef({ name : "$_cola_tmp" });
: new Cola.AST_SymbolRef({ name : "_ColaRuntime$$tmp" });
if(!(node.right instanceof Cola.AST_SymbolRef)) defs.push(new Cola.AST_VarDef({
type : "dynamic",
name : new Cola.AST_SymbolVar(Symbol),
@ -1170,7 +1336,7 @@ Cola.AST_Toplevel.prototype.toJavaScript = function(options){
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){
if((el instanceof Cola.AST_SymbolRef || el instanceof Cola.AST_PropAccess) && el.splated){
skiped = true;
defs.push(new Cola.AST_VarDef({
type : "int",
@ -1188,7 +1354,7 @@ Cola.AST_Toplevel.prototype.toJavaScript = function(options){
el.value = Cola.Constructions.ValueWithOffset(symbol, uid, !skiped, j, k++);
defs.push(el);
} else
if(el instanceof Cola.AST_SymbolRef || el instanceof Cola.AST_Sub || el instanceof Cola.AST_Dot) defs.push(new Cola.AST_Assign({
if(el instanceof Cola.AST_SymbolRef || el instanceof Cola.AST_PropAccess) defs.push(new Cola.AST_Assign({
operator : node.operator,
left : el,
right : Cola.Constructions.ValueWithOffset(symbol, uid, !skiped, j, k++)
@ -1221,7 +1387,7 @@ Cola.AST_Toplevel.prototype.toJavaScript = function(options){
name : el.value instanceof Cola.AST_Noop ? new Cola.AST_SymbolVar({ name : el.key }) : new Cola.AST_SymbolVar(el.value),
value : Cola.Constructions.ValueWithKey(el.start.type == "name" || el.start.type == "keyword", symbol, el.key)
})); else
if(el.value instanceof Cola.AST_SymbolRef || el.value instanceof Cola.AST_Sub || el.value instanceof Cola.AST_Dot || el.value instanceof Cola.AST_Noop && el.start.type == "name") defs.push(new Cola.AST_Assign({
if(el.value instanceof Cola.AST_SymbolRef || el.value instanceof Cola.AST_PropAccess || el.value instanceof Cola.AST_Noop && el.start.type == "name") defs.push(new Cola.AST_Assign({
operator : node.operator,
left : el.value instanceof Cola.AST_Noop ? new Cola.AST_SymbolRef({ name : el.key }) : el.value,
right : Cola.Constructions.ValueWithKey(el.start.type == "name" || el.start.type == "keyword", symbol, el.key)
@ -1270,28 +1436,28 @@ Cola.AST_Toplevel.prototype.toJavaScript = function(options){
to
func((function($_cola_expr, arguments){
aname = $_cola_expr.a;
bname = $_cola_expr.b;
func((function(_ColaRuntime$$expr, arguments){
aname = _ColaRuntime$$expr.a;
bname = _ColaRuntime$$expr.b;
return $_cola_expr;
return _ColaRuntime$$expr;
}).call(this, obj, arguments))
*/
if(node instanceof Cola.AST_Assign && (node.left instanceof Cola.AST_ArrayTemplate || node.left instanceof Cola.AST_ObjectTemplate ||
(node.left instanceof Cola.AST_Array || node.left instanceof Cola.AST_Object) && node.left.template)){
if(node.left.vardef) Cola.Parser.prototype.unexpected.call(Cola.Parser.prototype, node.start);
$_cola_hash[Cola.$_cola_arguments_def.i] = true;
_ColaRuntime$$hash[Cola._ColaRuntime$$arguments_def.i] = true;
var defs = [];
var Symbol = new Cola.AST_SymbolRef({ name : "$_cola_expr" });
var Symbol = new Cola.AST_SymbolRef({ name : "_ColaRuntime$$expr" });
(function _rec(def, symbol, uid){
var skiped = false, k = 0, is_arrayt = def instanceof Cola.AST_Array || def instanceof Cola.AST_ArrayTemplate, _ = is_arrayt ? def.elements : def.properties;
_.forEach( is_arrayt
? function(el, j){
if((el instanceof Cola.AST_SymbolRef || el instanceof Cola.AST_Sub || el instanceof Cola.AST_Dot) && el.splated){
if((el instanceof Cola.AST_SymbolRef || el instanceof Cola.AST_PropAccess && el.splated){
skiped = true;
defs.push(new Cola.AST_VarDef({
type : "int",
@ -1305,7 +1471,7 @@ Cola.AST_Toplevel.prototype.toJavaScript = function(options){
right : Cola.Constructions.SplatedConditional(symbol, uid, j, _.length - j - 1, _.length)
}));
} else
if(el instanceof Cola.AST_SymbolRef || el instanceof Cola.AST_Sub || el instanceof Cola.AST_Dot) defs.push(new Cola.AST_Assign({
if(el instanceof Cola.AST_SymbolRef || el instanceof Cola.AST_PropAccess) defs.push(new Cola.AST_Assign({
operator : node.operator,
left : el,
right : Cola.Constructions.ValueWithOffset(symbol, uid, !skiped, j, k++)
@ -1331,7 +1497,7 @@ Cola.AST_Toplevel.prototype.toJavaScript = function(options){
_rec(el, Cola.Constructions.ValueWithOffset(symbol, uid, !skiped, j, k++), uid + "_");
}
: function(el, j){
if(el.value instanceof Cola.AST_SymbolRef || el.value instanceof Cola.AST_Sub || el.value instanceof Cola.AST_Dot || el.value instanceof Cola.AST_Noop && el.start.type == "name") defs.push(new Cola.AST_Assign({
if(el.value instanceof Cola.AST_SymbolRef || el.value instanceof Cola.AST_PropAccess || el.value instanceof Cola.AST_Noop && el.start.type == "name") defs.push(new Cola.AST_Assign({
operator : node.operator,
left : el.value instanceof Cola.AST_Noop ? new Cola.AST_SymbolRef({ name : el.key }) : el.value,
right : Cola.Constructions.ValueWithKey(el.start.type == "name" || el.start.type == "keyword", symbol, el.key)
@ -1348,7 +1514,7 @@ Cola.AST_Toplevel.prototype.toJavaScript = function(options){
argtype : "positional",
type : "dynamic",
defval : new Cola.AST_Noop(),
name : new Cola.AST_SymbolFunarg({ name : "$_cola_expr", start : node.right.start, end : node.right.end })
name : new Cola.AST_SymbolFunarg({ name : "_ColaRuntime$$expr", start : node.right.start, end : node.right.end })
}), new Cola.AST_ArgDef({
argtype : "positional",
type : "dynamic",
@ -1388,7 +1554,7 @@ Cola.AST_Toplevel.prototype.toJavaScript = function(options){
if(i == defs.length - 1) _(false);
});
props.body.push(new Cola.AST_Return({ value : new Cola.AST_SymbolRef({ name : "$_cola_expr" }) }));
props.body.push(new Cola.AST_Return({ value : new Cola.AST_SymbolRef({ name : "_ColaRuntime$$expr" }) }));
props = {
expression : new Cola.AST_Function(props),
@ -1414,7 +1580,7 @@ Cola.AST_Toplevel.prototype.toJavaScript = function(options){
*/
if(node instanceof Cola.AST_If && node.inline && !(parent instanceof Cola.AST_If && parent.inline)){
$_cola_hash[Cola.$_cola_arguments_def.i] = true;
_ColaRuntime$$hash[Cola._ColaRuntime$$arguments_def.i] = true;
var s = node;
@ -1466,7 +1632,7 @@ Cola.AST_Toplevel.prototype.toJavaScript = function(options){
*/
if(node instanceof Cola.AST_Switch && !(parent instanceof Cola.AST_Block)){
$_cola_hash[Cola.$_cola_arguments_def.i] = true;
_ColaRuntime$$hash[Cola._ColaRuntime$$arguments_def.i] = true;
node.body.forEach(function(branch){
if(!branch.body.length) return;
@ -1706,7 +1872,7 @@ Cola.AST_Toplevel.prototype.toJavaScript = function(options){
});
if (node.args[1]){
$_cola_hash[Cola.$_cola_arguments_def.i] = true;
_ColaRuntime$$hash[Cola._ColaRuntime$$arguments_def.i] = true;
props = new Cola.AST_Dot({
expression : props,
@ -1739,8 +1905,8 @@ Cola.AST_Toplevel.prototype.toJavaScript = function(options){
_this.body = required.concat(_this.body);
if(options.std){
for(var i in $_cola_hash) if($_cola_hash.hasOwnProperty(i))
_this.body.unshift($_cola_ast.body[i]);
for(var i in _ColaRuntime$$hash) if(_ColaRuntime$$hash.hasOwnProperty(i))
_this.body.unshift(_ColaRuntime$$ast.body[i]);
}
return _this;

View File

@ -369,9 +369,10 @@ Cola.Dictionary.prototype = {
}
};
Cola.clone = function (item) {
Cola.clone = function (item) {
if (item === undefined || item === null) return item;
if (item.__clone__ instanceof Function) return item.__clone__();
if (item.clone instanceof Function) return item.clone();
var result, types = [ Number, String, Boolean ];
for (var i in types)