Prepare code to the static typing.
This commit is contained in:
parent
cdf1161409
commit
3e4589b331
124
README.md
124
README.md
|
|
@ -359,21 +359,30 @@ As you see, you can use keyword `when`, it's like `case`, but if the condition i
|
||||||
|
|
||||||
Future plans
|
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
|
- static typing
|
||||||
- Compiler command `@import` to import modules ( AMD, CommonJS... )
|
- declaration function by object's property
|
||||||
|
|
||||||
// node.js
|
String String::replaceAll(a, b){
|
||||||
@import 'fs' as fs
|
String res = this;
|
||||||
@import dirname from 'path'
|
while(res.indexOf(a) != -1) res = res.replace(a, b);
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
String code = fs.readFileSync(dirname(filePath) + "/main.cola", "utf8");
|
// or
|
||||||
|
|
||||||
- set parameters to calling function
|
|
||||||
|
|
||||||
$(".btn").on("click", () use (context: myContext){
|
|
||||||
this; // myContext
|
|
||||||
});
|
|
||||||
|
|
||||||
|
Object data = someData;
|
||||||
|
int data.getFriendsCount() => this.friends.length;
|
||||||
- classes
|
- classes
|
||||||
|
|
||||||
class A {
|
class A {
|
||||||
|
|
@ -405,9 +414,7 @@ Future plans
|
||||||
|
|
||||||
get some => "some " + about;
|
get some => "some " + about;
|
||||||
set some(val) => about += val;
|
set some(val) => about += val;
|
||||||
}
|
}- classes and typing with templates
|
||||||
|
|
||||||
- classes and typing with templates
|
|
||||||
|
|
||||||
class A<T> {
|
class A<T> {
|
||||||
// ...
|
// ...
|
||||||
|
|
@ -416,7 +423,6 @@ Future plans
|
||||||
Array<int> arr = [0...10];
|
Array<int> arr = [0...10];
|
||||||
Object<String, String> obj = { name: "Eric" };
|
Object<String, String> obj = { name: "Eric" };
|
||||||
|
|
||||||
|
|
||||||
- singletones
|
- singletones
|
||||||
|
|
||||||
singleton S { // in fact this is object
|
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
|
- destructed function arguments
|
||||||
|
|
||||||
test({String name, String login, String photoUrl}){
|
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
|
- asm.js native syntax, for example
|
||||||
|
|
||||||
// cola
|
// cola
|
||||||
|
|
@ -494,33 +532,3 @@ Future plans
|
||||||
return i|0;
|
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.
|
|
||||||
|
|
|
||||||
|
|
@ -56,12 +56,13 @@ Cola.DEFNODE = function (type, props, methods, base) {
|
||||||
props = props.concat(base.PROPS);
|
props = props.concat(base.PROPS);
|
||||||
var code = "return function AST_" + type + "(props){ if (props) { ";
|
var code = "return function AST_" + type + "(props){ if (props) { ";
|
||||||
for (var i = props.length; --i >= 0;) {
|
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;
|
var proto = base && new base;
|
||||||
if (proto && proto.initialize || (methods && methods.initialize))
|
if (proto && proto.initialize || (methods && methods.initialize))
|
||||||
code += "this.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)();
|
var ctor = new Function(code)();
|
||||||
if (proto) {
|
if (proto) {
|
||||||
ctor.prototype = proto;
|
ctor.prototype = proto;
|
||||||
|
|
|
||||||
|
|
@ -241,7 +241,7 @@ main();</textarea>
|
||||||
localStorage.isjs = isjs.checked ? "t" : "f";
|
localStorage.isjs = isjs.checked ? "t" : "f";
|
||||||
localStorage.mainbinding = mainbinding.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 });
|
compressor = new Cola.Compressor({ is_js : isjs.checked });
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
|
||||||
13
lib/parse.js
13
lib/parse.js
|
|
@ -131,13 +131,12 @@ Cola.OPERATORS = [
|
||||||
"isnt",
|
"isnt",
|
||||||
"**",
|
"**",
|
||||||
"%%",
|
"%%",
|
||||||
"?=",
|
"?="
|
||||||
"??"
|
|
||||||
|
|
||||||
];
|
];
|
||||||
Cola.cOPERATORS = Cola.makePredicate(Cola.OPERATORS);
|
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.push('void');
|
||||||
|
|
||||||
Cola.OPERATORS = Cola.makePredicate(Cola.OPERATORS);
|
Cola.OPERATORS = Cola.makePredicate(Cola.OPERATORS);
|
||||||
|
|
@ -768,7 +767,7 @@ Cola.cUNARY_PREFIX = Cola.makePredicate([
|
||||||
]);
|
]);
|
||||||
|
|
||||||
Cola.UNARY_POSTFIX = Cola.makePredicate([ "--", "++" ]);
|
Cola.UNARY_POSTFIX = Cola.makePredicate([ "--", "++" ]);
|
||||||
Cola.cUNARY_POSTFIX = Cola.makePredicate([ "--", "++", "??" ]);
|
Cola.cUNARY_POSTFIX = Cola.UNARY_POSTFIX;
|
||||||
|
|
||||||
Cola.ASSIGNMENT = Cola.makePredicate([ "=", "+=", "-=", "/=", "*=", "%=", ">>=", "<<=", ">>>=", "|=", "^=", "&=" ]);
|
Cola.ASSIGNMENT = Cola.makePredicate([ "=", "+=", "-=", "/=", "*=", "%=", ">>=", "<<=", ">>>=", "|=", "^=", "&=" ]);
|
||||||
Cola.cASSIGNMENT = Cola.makePredicate([ "=", "+=", "-=", "/=", "*=", "%=", ">>=", "<<=", ">>>=", "|=", "^=", "&=", "?=" ]);
|
Cola.cASSIGNMENT = Cola.makePredicate([ "=", "+=", "-=", "/=", "*=", "%=", ">>=", "<<=", ">>>=", "|=", "^=", "&=", "?=" ]);
|
||||||
|
|
@ -1483,9 +1482,9 @@ Cola.Parser.prototype.vardefs = function (no_in, in_const, type) {
|
||||||
start : this.S.token,
|
start : this.S.token,
|
||||||
type : type,
|
type : type,
|
||||||
name : (function(_this){
|
name : (function(_this){
|
||||||
was_template = !_this.is_js && ( _this.is("punc","[") || _this.is("punc","{") );
|
//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.array_(true, true);
|
||||||
if (!_this.is_js && _this.is("punc","{")) return _this.object_(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);
|
return _this.as_symbol(in_const ? Cola.AST_SymbolConst : Cola.AST_SymbolVar);
|
||||||
})(this),
|
})(this),
|
||||||
value : this.is("operator", "=") ? (this.next(), this.expression(false, no_in)) : ( was_template ? this.expect_token("operator","=") : null ),
|
value : this.is("operator", "=") ? (this.next(), this.expression(false, no_in)) : ( was_template ? this.expect_token("operator","=") : null ),
|
||||||
|
|
|
||||||
|
|
@ -37,12 +37,12 @@
|
||||||
!this.Cola && (this.Cola = {});
|
!this.Cola && (this.Cola = {});
|
||||||
|
|
||||||
Cola.$_cola_is = function $_cola_is(_object, _type){
|
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_is.i = 0;
|
||||||
|
|
||||||
Cola.$_cola_isnt = function $_cola_isnt(_object, _type){
|
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;
|
Cola.$_cola_isnt.i = 1;
|
||||||
|
|
||||||
|
|
|
||||||
584
lib/translate.js
584
lib/translate.js
|
|
@ -37,6 +37,205 @@
|
||||||
"use strict";
|
"use strict";
|
||||||
!this.Cola && (this.Cola = {});
|
!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){
|
Cola.AST_Toplevel.prototype.toJavaScript = function(options){
|
||||||
if(this.language == 'js') return this;
|
if(this.language == 'js') return this;
|
||||||
this.language = 'js';
|
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()],
|
args : [new Cola.AST_String({ value : options.main_event }), node, new Cola.AST_False()],
|
||||||
expression : new Cola.AST_Dot({
|
expression : new Cola.AST_Dot({
|
||||||
property : 'addEventListener',
|
property : 'addEventListener',
|
||||||
//start : props.start,
|
|
||||||
//end : new Cola.AST_Token({ nlb : false, type : 'name', value : 'pow' }),
|
|
||||||
expression : new Cola.AST_SymbolRef({ name : 'window' })
|
expression : new Cola.AST_SymbolRef({ name : 'window' })
|
||||||
})
|
})
|
||||||
};
|
};
|
||||||
|
|
||||||
node = new Cola.AST_SimpleStatement({
|
node = new Cola.AST_SimpleStatement({
|
||||||
body : new Cola.AST_Call(props),
|
|
||||||
start : node.start,
|
start : node.start,
|
||||||
end : node.left
|
end : node.left,
|
||||||
|
body : new Cola.AST_Call(props)
|
||||||
});
|
});
|
||||||
} else
|
} else
|
||||||
|
|
||||||
|
|
@ -104,19 +301,16 @@ Cola.AST_Toplevel.prototype.toJavaScript = function(options){
|
||||||
*/
|
*/
|
||||||
if(node instanceof Cola.AST_Binary && node.operator == '**'){
|
if(node instanceof Cola.AST_Binary && node.operator == '**'){
|
||||||
props = {
|
props = {
|
||||||
|
start : node.start,
|
||||||
|
end : node.left,
|
||||||
args : [node.left, node.right],
|
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({
|
expression : new Cola.AST_Dot({
|
||||||
property : 'pow',
|
property : 'pow',
|
||||||
//start : props.start,
|
|
||||||
//end : new Cola.AST_Token({ nlb : false, type : 'name', value : 'pow' }),
|
|
||||||
expression : new Cola.AST_SymbolRef({ name : 'Math' })
|
expression : new Cola.AST_SymbolRef({ name : 'Math' })
|
||||||
})
|
})
|
||||||
};
|
};
|
||||||
|
|
||||||
node = new Cola.AST_Call(props);
|
node = new Cola.AST_Call(props);
|
||||||
|
|
||||||
} else
|
} else
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
@ -130,18 +324,13 @@ Cola.AST_Toplevel.prototype.toJavaScript = function(options){
|
||||||
if(node instanceof Cola.AST_Binary && node.operator == '%%'){
|
if(node instanceof Cola.AST_Binary && node.operator == '%%'){
|
||||||
$_cola_hash[Cola.$_cola_modulo.i] = true;
|
$_cola_hash[Cola.$_cola_modulo.i] = true;
|
||||||
props = {
|
props = {
|
||||||
|
start : node.start,
|
||||||
|
end : node.end,
|
||||||
args : [node.left, node.right],
|
args : [node.left, node.right],
|
||||||
start : node.start, //new Cola.AST_Token({ nlb : false, type : 'name', value : '$_cola_modulo' }),
|
expression : new Cola.AST_SymbolRef({ name : '$_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
|
|
||||||
})
|
|
||||||
};
|
};
|
||||||
|
|
||||||
node = new Cola.AST_Call(props);
|
node = new Cola.AST_Call(props);
|
||||||
|
|
||||||
} else
|
} else
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
@ -149,15 +338,13 @@ Cola.AST_Toplevel.prototype.toJavaScript = function(options){
|
||||||
|
|
||||||
to
|
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 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){
|
if(node.body.left instanceof Cola.AST_Sub && node.body.left.property instanceof Cola.AST_Noop){
|
||||||
props = {
|
props = {
|
||||||
property : "length",
|
property : "length",
|
||||||
//start : node.left.start,
|
|
||||||
//end : new Cola.AST_Token({ nlb : false, type : 'name', value : 'push' }),
|
|
||||||
expression : node.body.left.expression
|
expression : node.body.left.expression
|
||||||
};
|
};
|
||||||
props = {
|
props = {
|
||||||
|
|
@ -169,25 +356,12 @@ Cola.AST_Toplevel.prototype.toJavaScript = function(options){
|
||||||
node.body.left.property = new Cola.AST_Binary(props);
|
node.body.left.property = new Cola.AST_Binary(props);
|
||||||
}
|
}
|
||||||
|
|
||||||
$_cola_hash[Cola.$_cola_isntset.i] = true;
|
|
||||||
node.body.operator = '=';
|
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({
|
node = new Cola.AST_If({
|
||||||
|
start : node.start,
|
||||||
|
end : node.end,
|
||||||
body : node.clone(),
|
body : node.clone(),
|
||||||
start : node.start, //new Cola.AST_Token({ nlb : false, type : 'keyword', value : 'if' }),
|
condition : Cola.Constructions.IsntSet(node.body.left)
|
||||||
end : node.end, //new Cola.AST_Token({ nlb : false, type : 'punc', value : ';' }),
|
|
||||||
condition : new Cola.AST_Call(props)
|
|
||||||
});
|
});
|
||||||
} else
|
} else
|
||||||
|
|
||||||
|
|
@ -196,15 +370,13 @@ Cola.AST_Toplevel.prototype.toJavaScript = function(options){
|
||||||
|
|
||||||
to
|
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){
|
if(node.left instanceof Cola.AST_Sub && node.left.property instanceof Cola.AST_Noop){
|
||||||
props = {
|
props = {
|
||||||
property : "length",
|
property : "length",
|
||||||
//start : node.left.start,
|
|
||||||
//end : new Cola.AST_Token({ nlb : false, type : 'name', value : 'push' }),
|
|
||||||
expression : node.left.expression
|
expression : node.left.expression
|
||||||
};
|
};
|
||||||
props = {
|
props = {
|
||||||
|
|
@ -216,24 +388,11 @@ Cola.AST_Toplevel.prototype.toJavaScript = function(options){
|
||||||
node.left.property = new Cola.AST_Binary(props);
|
node.left.property = new Cola.AST_Binary(props);
|
||||||
}
|
}
|
||||||
|
|
||||||
$_cola_hash[Cola.$_cola_isntset.i] = true;
|
|
||||||
node.operator = '=';
|
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({
|
node = new Cola.AST_Conditional({
|
||||||
start : node.start, //new Cola.AST_Token({ nlb : false, type : 'punc', value : '(' }),
|
start : node.start,
|
||||||
end : node.end, //new Cola.AST_Token({ nlb : false, type : 'punc', value : ')' }),
|
end : node.end,
|
||||||
condition : new Cola.AST_Call(props),
|
condition : Cola.Constructions.IsntSet(node.left),
|
||||||
consequent : node.clone(),
|
consequent : node.clone(),
|
||||||
alternative : node.left
|
alternative : node.left
|
||||||
});
|
});
|
||||||
|
|
@ -244,26 +403,55 @@ Cola.AST_Toplevel.prototype.toJavaScript = function(options){
|
||||||
|
|
||||||
to
|
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){
|
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.alternative = node.consequent;
|
||||||
node.consequent = node.condition;
|
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
|
} else
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
@ -277,14 +465,10 @@ Cola.AST_Toplevel.prototype.toJavaScript = function(options){
|
||||||
if(node instanceof Cola.AST_Binary && node.operator == 'is'){
|
if(node instanceof Cola.AST_Binary && node.operator == 'is'){
|
||||||
$_cola_hash[Cola.$_cola_is.i] = true;
|
$_cola_hash[Cola.$_cola_is.i] = true;
|
||||||
props = {
|
props = {
|
||||||
|
start : node.start,
|
||||||
|
end : node.end,
|
||||||
args : [node.left, node.right],
|
args : [node.left, node.right],
|
||||||
start : node.start, //new Cola.AST_Token({ nlb : false, type : 'name', value : '$_cola_is' }),
|
expression : new Cola.AST_SymbolRef({ name : '$_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
|
|
||||||
})
|
|
||||||
};
|
};
|
||||||
|
|
||||||
node = new Cola.AST_Call(props);
|
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'){
|
if(node instanceof Cola.AST_Binary && node.operator == 'isnt'){
|
||||||
$_cola_hash[Cola.$_cola_isnt.i] = true;
|
$_cola_hash[Cola.$_cola_isnt.i] = true;
|
||||||
props = {
|
props = {
|
||||||
|
start : node.start,
|
||||||
|
end : node.end,
|
||||||
args : [node.left, node.right],
|
args : [node.left, node.right],
|
||||||
start : node.start, //new Cola.AST_Token({ nlb : false, type : 'name', value : '$_cola_isnt' }),
|
expression : new Cola.AST_SymbolRef({ name : '$_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
|
|
||||||
})
|
|
||||||
};
|
};
|
||||||
|
|
||||||
node = new Cola.AST_Call(props);
|
node = new Cola.AST_Call(props);
|
||||||
|
|
@ -317,29 +497,13 @@ Cola.AST_Toplevel.prototype.toJavaScript = function(options){
|
||||||
/*
|
/*
|
||||||
isset a
|
isset a
|
||||||
|
|
||||||
or
|
|
||||||
|
|
||||||
a??
|
|
||||||
|
|
||||||
to
|
to
|
||||||
|
|
||||||
$_cola_isset(a)
|
$_cola_isset(a)
|
||||||
|
|
||||||
*/
|
*/
|
||||||
if(node instanceof Cola.AST_UnaryPostfix && node.operator == '??' || node instanceof Cola.AST_UnaryPrefix && node.operator == 'isset'){
|
if(node instanceof Cola.AST_UnaryPrefix && node.operator == 'isset'){
|
||||||
$_cola_hash[Cola.$_cola_isset.i] = true;
|
node = Cola.Constructions.IsSet(node.expression, node);
|
||||||
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);
|
|
||||||
} else
|
} else
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
@ -353,14 +517,10 @@ Cola.AST_Toplevel.prototype.toJavaScript = function(options){
|
||||||
if(node instanceof Cola.AST_UnaryPrefix && node.operator == 'clone'){
|
if(node instanceof Cola.AST_UnaryPrefix && node.operator == 'clone'){
|
||||||
$_cola_hash[Cola.$_cola_clone.i] = true;
|
$_cola_hash[Cola.$_cola_clone.i] = true;
|
||||||
props = {
|
props = {
|
||||||
|
start : node.start,
|
||||||
|
end : node.end,
|
||||||
args : [node.expression],
|
args : [node.expression],
|
||||||
start : node.start, //new Cola.AST_Token({ nlb : false, type : 'name', value : '$_cola_clone' }),
|
expression : new Cola.AST_SymbolRef({ name : '$_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
|
|
||||||
})
|
|
||||||
};
|
};
|
||||||
|
|
||||||
node = new Cola.AST_Call(props);
|
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){
|
if(node instanceof Cola.AST_Assign && node.operator == "=" && node.left instanceof Cola.AST_Sub && node.left.property instanceof Cola.AST_Noop){
|
||||||
props = {
|
props = {
|
||||||
property : "push",
|
property : "push",
|
||||||
//start : node.left.start,
|
|
||||||
//end : new Cola.AST_Token({ nlb : false, type : 'name', value : 'push' }),
|
|
||||||
expression : node.left.expression
|
expression : node.left.expression
|
||||||
};
|
};
|
||||||
props = {
|
props = {
|
||||||
|
start : node.start,
|
||||||
|
end : node.end,
|
||||||
args : [node.right],
|
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)
|
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){
|
if(node instanceof Cola.AST_Sub && node.property instanceof Cola.AST_Noop){
|
||||||
$_cola_hash[Cola.$_cola_array_last.i] = true;
|
$_cola_hash[Cola.$_cola_array_last.i] = true;
|
||||||
props = {
|
props = {
|
||||||
args : [node.expression],
|
|
||||||
start : node.start,
|
start : node.start,
|
||||||
end : node.end,
|
end : node.end,
|
||||||
expression : new Cola.AST_SymbolRef({
|
args : [node.expression],
|
||||||
name : '$_cola_array_last'
|
expression : new Cola.AST_SymbolRef({ name : '$_cola_array_last' })
|
||||||
})
|
|
||||||
};
|
};
|
||||||
|
|
||||||
node = new Cola.AST_Call(props);
|
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){
|
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;
|
$_cola_hash[Cola.$_cola_array_asplice.i] = true;
|
||||||
props = {
|
props = {
|
||||||
args : [node.left.expression, node.left.property.from, node.left.property.to, node.right],
|
|
||||||
start : node.start,
|
start : node.start,
|
||||||
end : node.end,
|
end : node.end,
|
||||||
expression : new Cola.AST_SymbolRef({
|
args : [node.left.expression, node.left.property.from, node.left.property.to, node.right],
|
||||||
name : '$_cola_array_asplice'
|
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' });
|
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
|
expression : node.expression
|
||||||
};
|
};
|
||||||
props = {
|
props = {
|
||||||
args : [node.property.from],
|
|
||||||
start : node.start,
|
start : node.start,
|
||||||
end : node.end,
|
end : node.end,
|
||||||
|
args : [node.property.from],
|
||||||
expression : new Cola.AST_Dot(props)
|
expression : new Cola.AST_Dot(props)
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -506,12 +660,10 @@ Cola.AST_Toplevel.prototype.toJavaScript = function(options){
|
||||||
if(node instanceof Cola.AST_ArrayRange){
|
if(node instanceof Cola.AST_ArrayRange){
|
||||||
$_cola_hash[Cola.$_cola_array_range.i] = true;
|
$_cola_hash[Cola.$_cola_array_range.i] = true;
|
||||||
props = {
|
props = {
|
||||||
args : [node.from, node.to],
|
|
||||||
start : node.start,
|
start : node.start,
|
||||||
end : node.end,
|
end : node.end,
|
||||||
expression : new Cola.AST_SymbolRef({
|
args : [node.from, node.to],
|
||||||
name : '$_cola_array_range'
|
expression : new Cola.AST_SymbolRef({ name : '$_cola_array_range' })
|
||||||
})
|
|
||||||
};
|
};
|
||||||
|
|
||||||
if(node.triple) props.args[1] = new Cola.AST_Binary({
|
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){
|
if(node instanceof Cola.AST_Call){
|
||||||
props = {
|
props = { properties : [] };
|
||||||
properties : []
|
|
||||||
};
|
|
||||||
|
|
||||||
var delQueue = [];
|
var delQueue = [];
|
||||||
node.args.forEach(function(val, i){
|
node.args.forEach(function(val, i){
|
||||||
if(!(val instanceof Cola.AST_Namedarg)) return;
|
if(!(val instanceof Cola.AST_Namedarg)) return;
|
||||||
|
|
||||||
$_cola_hash[Cola.$_cola_func_named_args.i] = true;
|
$_cola_hash[Cola.$_cola_func_named_args.i] = true;
|
||||||
delQueue.push(i);
|
delQueue.push(i);
|
||||||
|
|
||||||
props.properties.push(new Cola.AST_ObjectKeyVal({
|
props.properties.push(new Cola.AST_ObjectKeyVal({
|
||||||
key : val.name,
|
|
||||||
value : val.value,
|
|
||||||
start : val.start,
|
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 = {
|
props = {
|
||||||
args : [new Cola.AST_Object(props)],
|
|
||||||
start : node.start,
|
start : node.start,
|
||||||
end : node.end,
|
end : node.end,
|
||||||
expression : new Cola.AST_SymbolRef({
|
args : [new Cola.AST_Object(props)],
|
||||||
name : '$_cola_func_named_args'
|
expression : new Cola.AST_SymbolRef({ name : '$_cola_func_named_args' })
|
||||||
})
|
|
||||||
};
|
};
|
||||||
|
|
||||||
node.args.push(new Cola.AST_New(props));
|
node.args.push(new Cola.AST_New(props));
|
||||||
|
|
@ -625,126 +775,24 @@ Cola.AST_Toplevel.prototype.toJavaScript = function(options){
|
||||||
value : null
|
value : null
|
||||||
}));
|
}));
|
||||||
|
|
||||||
props.definitions.push(new Cola.AST_VarDef({
|
props.definitions.push(Cola.Constructions.SplatedVarDef(splated.val.name, splated.pos, splated.after, splated.pos + splated.after + 1));
|
||||||
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 : [] })
|
|
||||||
})
|
|
||||||
})
|
|
||||||
}));
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|
||||||
if(val.defval instanceof Cola.AST_Noop) props.definitions.push(new Cola.AST_VarDef({
|
if(val.defval instanceof Cola.AST_Noop) props.definitions.push(Cola.Constructions.PosedVarDef(val.name, val.type, pos, aftersplated)), aftersplated++;
|
||||||
name : new Cola.AST_SymbolVar(val.name),
|
else props.definitions.push(Cola.Constructions.PosedWithDefsVarDef(val.name, val.type, val.defval, pos, aftersplated)), aftersplated++;
|
||||||
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
|
|
||||||
})
|
|
||||||
}));
|
|
||||||
});
|
});
|
||||||
|
|
||||||
named.forEach(function(val, i){
|
named.forEach(function(val, i){
|
||||||
if(val.defval instanceof Cola.AST_Noop) props.definitions.push(new Cola.AST_VarDef({
|
if(val.defval instanceof Cola.AST_Noop) props.definitions.push(new Cola.AST_VarDef({
|
||||||
|
type : val.type,
|
||||||
name : new Cola.AST_SymbolVar(val.name),
|
name : new Cola.AST_SymbolVar(val.name),
|
||||||
value : new Cola.AST_Dot({
|
value : new Cola.AST_Dot({
|
||||||
expression : new Cola.AST_SymbolRef({ name : 'arguments' }),
|
expression : new Cola.AST_SymbolRef({ name : 'arguments' }),
|
||||||
property : val.name.name
|
property : val.name.name
|
||||||
})
|
})
|
||||||
}));
|
}));
|
||||||
else props.definitions.push(new Cola.AST_VarDef({
|
else props.definitions.push(Cola.Constructions.NamedVarDef(val.name, val.type, val.defval, val.name.name));
|
||||||
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
|
|
||||||
})
|
|
||||||
}));
|
|
||||||
});
|
});
|
||||||
|
|
||||||
if(delQueue.length != 0 || named.length != 0) node.body.unshift(new Cola.AST_Var(props));
|
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"];
|
var $_cola_tmp = { key : "val" }, d = $_cola_tmp["key"];
|
||||||
|
|
||||||
*/
|
*/
|
||||||
if(node instanceof Cola.AST_Var){
|
/*if(node instanceof Cola.AST_Var){
|
||||||
var defs = [];
|
var defs = [];
|
||||||
node.definitions.forEach(function(def, i){
|
node.definitions.forEach(function(def, i){
|
||||||
if(!(def.name instanceof Cola.AST_ArrayTemplate || def.name instanceof Cola.AST_ObjectTemplate)){
|
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;
|
node.definitions = defs;
|
||||||
} else
|
} else*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
{ String name, age : ages.age } = pro;
|
{ String name, age : ages.age } = pro;
|
||||||
|
|
@ -1083,49 +1131,7 @@ Cola.AST_Toplevel.prototype.toJavaScript = function(options){
|
||||||
value : null
|
value : null
|
||||||
}));
|
}));
|
||||||
el.name.splated = undefined;
|
el.name.splated = undefined;
|
||||||
el.value = new Cola.AST_Conditional({
|
el.value = Cola.Constructions.SplatedConditional(symbol, uid, j, _.length - j - 1, _.length);
|
||||||
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 : [] })
|
|
||||||
})
|
|
||||||
});
|
|
||||||
defs.push(el);
|
defs.push(el);
|
||||||
} else
|
} 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_Sub || el instanceof Cola.AST_Dot) && el.splated){
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user