Negate and modulo array accessors are done.
arr[-1]; // last element int index = -10; arr[%index] = 34; // arr[index %% arr.length];
This commit is contained in:
parent
aec283f0b4
commit
1d297d9248
118
README.md
118
README.md
|
|
@ -388,7 +388,7 @@ Future plans
|
||||||
int sqrt(int x?) => x ** 2;
|
int sqrt(int x?) => x ** 2;
|
||||||
sqr(); // NaN
|
sqr(); // NaN
|
||||||
|
|
||||||
- Negate array accessor ( getter )
|
- Negate array accessor ( getter ). status: done
|
||||||
|
|
||||||
arr[-1]; // last element
|
arr[-1]; // last element
|
||||||
|
|
||||||
|
|
@ -397,6 +397,64 @@ Future plans
|
||||||
int index = -10;
|
int index = -10;
|
||||||
arr[%index] = 34; // arr[index %% arr.length];
|
arr[%index] = 34; // arr[index %% arr.length];
|
||||||
|
|
||||||
|
- classes
|
||||||
|
|
||||||
|
class A {
|
||||||
|
|
||||||
|
int a = 123;
|
||||||
|
readonly String about = "class";
|
||||||
|
|
||||||
|
$("button").click(() => console.log("Button Clicked!"));
|
||||||
|
|
||||||
|
A(a){
|
||||||
|
about = "some else";
|
||||||
|
}
|
||||||
|
|
||||||
|
static Hello() => "hello!";
|
||||||
|
|
||||||
|
public String about() => about;
|
||||||
|
}
|
||||||
|
|
||||||
|
class B extends A {
|
||||||
|
|
||||||
|
B(){
|
||||||
|
parent();
|
||||||
|
about += "!";
|
||||||
|
}
|
||||||
|
|
||||||
|
B.anotherConstructor(){
|
||||||
|
about = "ups!";
|
||||||
|
}
|
||||||
|
|
||||||
|
get some => "some " + about;
|
||||||
|
set some(val) => about += val;
|
||||||
|
}
|
||||||
|
|
||||||
|
- singletones
|
||||||
|
|
||||||
|
singleton S { // in fact this is object
|
||||||
|
int x = 45;
|
||||||
|
String s = "txt";
|
||||||
|
|
||||||
|
say(some){
|
||||||
|
alert(some);
|
||||||
|
}
|
||||||
|
|
||||||
|
int operator[](int index) => index + 584;
|
||||||
|
operator[]=(int index, int val) => x = index + val;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
- injectors
|
||||||
|
|
||||||
|
injector String {
|
||||||
|
String replaceAll(a, b){
|
||||||
|
String res = this;
|
||||||
|
while(res.indexOf(a) != -1) res = res.replace(a, b);
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
- static typing
|
- static typing
|
||||||
- `@use` expressions
|
- `@use` expressions
|
||||||
|
|
||||||
|
|
@ -432,39 +490,6 @@ Future plans
|
||||||
String info?;
|
String info?;
|
||||||
}
|
}
|
||||||
|
|
||||||
- classes
|
|
||||||
|
|
||||||
class A {
|
|
||||||
|
|
||||||
int a = 123;
|
|
||||||
readonly String about = "class";
|
|
||||||
|
|
||||||
$("button").click(() => console.log("Button Clicked!"));
|
|
||||||
|
|
||||||
A(a){
|
|
||||||
about = "some else";
|
|
||||||
}
|
|
||||||
|
|
||||||
static Hello() => "hello!";
|
|
||||||
|
|
||||||
public String about() => about;
|
|
||||||
}
|
|
||||||
|
|
||||||
class B extends A {
|
|
||||||
|
|
||||||
B(){
|
|
||||||
parent();
|
|
||||||
about += "!";
|
|
||||||
}
|
|
||||||
|
|
||||||
B.anotherConstructor(){
|
|
||||||
about = "ups!";
|
|
||||||
}
|
|
||||||
|
|
||||||
get some => "some " + about;
|
|
||||||
set some(val) => about += val;
|
|
||||||
}
|
|
||||||
|
|
||||||
- classes and typing with templates
|
- classes and typing with templates
|
||||||
|
|
||||||
class A<T> {
|
class A<T> {
|
||||||
|
|
@ -474,31 +499,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
|
|
||||||
|
|
||||||
singleton S { // in fact this is object
|
|
||||||
int x = 45;
|
|
||||||
String s = "txt";
|
|
||||||
|
|
||||||
say(some){
|
|
||||||
alert(some);
|
|
||||||
}
|
|
||||||
|
|
||||||
int operator[](int index) => index + 584;
|
|
||||||
operator[]=(int index, int val) => x = index + val;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
- injectors
|
|
||||||
|
|
||||||
injector String {
|
|
||||||
String replaceAll(a, b){
|
|
||||||
String res = this;
|
|
||||||
while(res.indexOf(a) != -1) res = res.replace(a, b);
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
- ES6 `for`
|
- ES6 `for`
|
||||||
|
|
||||||
for(name of names){
|
for(name of names){
|
||||||
|
|
|
||||||
20
lib/parse.js
20
lib/parse.js
|
|
@ -2059,22 +2059,26 @@ Cola.Parser.prototype.subscripts = function(expr, allow_calls) {
|
||||||
|
|
||||||
var prop, triple;
|
var prop, triple;
|
||||||
if(this.is_js) prop = this.expression(true);
|
if(this.is_js) prop = this.expression(true);
|
||||||
else if(this.is("punc","]")) prop = new Cola.AST_Noop();
|
else if(this.is("punc", "]")) prop = new Cola.AST_Noop();
|
||||||
else {
|
else {
|
||||||
if((this.is("punc","..") || this.is("punc","...")) && !this.is_js) prop = new Cola.AST_Number({ value : 0 });
|
if(this.is("punc", "..") || this.is("punc", "..."))
|
||||||
else prop = this.expression(true, false, true);
|
prop = new Cola.AST_Number({ value : 0 });
|
||||||
//this.dumpS();
|
else if(this.is("operator", "%"))
|
||||||
if((this.is("punc","..") || this.is("punc","...")) && !this.is_js){
|
prop = new Cola.AST_UnaryPrefix({ operator : "%", expression : (this.next(), this.expression(true, false, false)) });
|
||||||
triple = this.is("punc","...");
|
else
|
||||||
|
prop = this.expression(true, false, true);
|
||||||
|
|
||||||
|
if(!(prop instanceof Cola.AST_UnaryPostfix && prop.operator == "%") && (this.is("punc", "..") || this.is("punc", "..."))){
|
||||||
|
triple = this.is("punc", "...");
|
||||||
this.next();
|
this.next();
|
||||||
prop = new Cola.AST_ArrayRange({
|
prop = new Cola.AST_ArrayRange({
|
||||||
from : prop,
|
from : prop,
|
||||||
to : ( this.is("punc","]") ? new Cola.AST_Noop() : this.expression(true, false, true) ),
|
to : ( this.is("punc", "]") ? new Cola.AST_Noop() : this.expression(true, false, true) ),
|
||||||
triple : triple,
|
triple : triple,
|
||||||
start : prop.start,
|
start : prop.start,
|
||||||
end : this.prev()
|
end : this.prev()
|
||||||
});
|
});
|
||||||
} //else this.restoreS();
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
this.expect("]");
|
this.expect("]");
|
||||||
|
|
|
||||||
13
lib/std.js
13
lib/std.js
|
|
@ -127,12 +127,23 @@ Cola._ColaRuntime$$error = function _ColaRuntime$$error(_error) {
|
||||||
};
|
};
|
||||||
Cola._ColaRuntime$$error.i = 11;
|
Cola._ColaRuntime$$error.i = 11;
|
||||||
|
|
||||||
Cola._ColaRuntime$$arguments_def = { i : 12 };
|
Cola._ColaRuntime$$array_negate_access = function _ColaRuntime$$array_negate_access(_array, _index) {
|
||||||
|
return _array instanceof Array ? _array.length + _index : _index;
|
||||||
|
};
|
||||||
|
Cola._ColaRuntime$$array_negate_access.i = 12;
|
||||||
|
|
||||||
|
Cola._ColaRuntime$$array_modulo_access = function _ColaRuntime$$array_modulo_access(_array, _index) {
|
||||||
|
return _array instanceof Array ? ((_index % _array.length + +_array.length) % _array.length) : _index;
|
||||||
|
};
|
||||||
|
Cola._ColaRuntime$$array_modulo_access.i = 13;
|
||||||
|
|
||||||
|
Cola._ColaRuntime$$arguments_def = { i : 14 };
|
||||||
|
|
||||||
Cola.$_cola =
|
Cola.$_cola =
|
||||||
Cola._ColaRuntime$$is + Cola._ColaRuntime$$isnt + Cola._ColaRuntime$$modulo + Cola._ColaRuntime$$isset +
|
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$$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 + Cola._ColaRuntime$$error +
|
Cola._ColaRuntime$$array_asplice + Cola._ColaRuntime$$func_named_args + Cola._ColaRuntime$$func_set_named_args + Cola._ColaRuntime$$error +
|
||||||
|
Cola._ColaRuntime$$array_negate_access + Cola._ColaRuntime$$array_modulo_access +
|
||||||
"var arguments;";
|
"var arguments;";
|
||||||
|
|
||||||
Cola.Compressor.StdFuncs = {
|
Cola.Compressor.StdFuncs = {
|
||||||
|
|
|
||||||
|
|
@ -824,6 +824,38 @@ Cola.AST_Toplevel.prototype.toJavaScript = function(options){
|
||||||
node = new Cola.AST_Call(props);
|
node = new Cola.AST_Call(props);
|
||||||
} else
|
} else
|
||||||
|
|
||||||
|
/*
|
||||||
|
arr[-1]
|
||||||
|
|
||||||
|
to
|
||||||
|
|
||||||
|
arr[_ColaRuntime$$array_negate_access(arr, -1)]
|
||||||
|
|
||||||
|
*/
|
||||||
|
if(node instanceof Cola.AST_Sub && node.property instanceof Cola.AST_UnaryPrefix && node.property.operator == "-" && node.property.expression instanceof Cola.AST_Number){
|
||||||
|
_ColaRuntime$$hash[Cola._ColaRuntime$$array_negate_access.i] = true;
|
||||||
|
node.property = new Cola.AST_Call({
|
||||||
|
args : [node.expression, node.property],
|
||||||
|
expression : new Cola.AST_SymbolRef({ name : '_ColaRuntime$$array_negate_access' })
|
||||||
|
});
|
||||||
|
} else
|
||||||
|
|
||||||
|
/*
|
||||||
|
arr[%index]
|
||||||
|
|
||||||
|
to
|
||||||
|
|
||||||
|
arr[_ColaRuntime$$array_modulo_access(arr, index)]
|
||||||
|
|
||||||
|
*/
|
||||||
|
if(node instanceof Cola.AST_Sub && node.property instanceof Cola.AST_UnaryPrefix && node.property.operator == "%"){
|
||||||
|
_ColaRuntime$$hash[Cola._ColaRuntime$$array_modulo_access.i] = true;
|
||||||
|
node.property = new Cola.AST_Call({
|
||||||
|
args : [node.expression, node.property.expression],
|
||||||
|
expression : new Cola.AST_SymbolRef({ name : '_ColaRuntime$$array_modulo_access' })
|
||||||
|
});
|
||||||
|
} else
|
||||||
|
|
||||||
/*
|
/*
|
||||||
arr[0..1] = 123
|
arr[0..1] = 123
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user