Coco ecd6aa4: Accessor -> Access
This commit is contained in:
parent
d3ae3525b8
commit
93cf3bd922
|
@ -157,13 +157,13 @@
|
||||||
],
|
],
|
||||||
Accessor: [
|
Accessor: [
|
||||||
o('. Identifier', function() {
|
o('. Identifier', function() {
|
||||||
return new Accessor($2);
|
return new Access($2);
|
||||||
}), o('?. Identifier', function() {
|
}), o('?. Identifier', function() {
|
||||||
return new Accessor($2, 'soak');
|
return new Access($2, 'soak');
|
||||||
}), o(':: Identifier', function() {
|
}), o(':: Identifier', function() {
|
||||||
return new Accessor($2, 'proto');
|
return new Access($2, 'proto');
|
||||||
}), o('::', function() {
|
}), o('::', function() {
|
||||||
return new Accessor(new Literal('prototype'));
|
return new Access(new Literal('prototype'));
|
||||||
}), o('Index'), o('Slice', function() {
|
}), o('Index'), o('Slice', function() {
|
||||||
return new Slice($1);
|
return new Slice($1);
|
||||||
})
|
})
|
||||||
|
@ -252,7 +252,7 @@
|
||||||
],
|
],
|
||||||
ThisProperty: [
|
ThisProperty: [
|
||||||
o('@ Identifier', function() {
|
o('@ Identifier', function() {
|
||||||
return new Value(new Literal('this'), [new Accessor($2)], 'this');
|
return new Value(new Literal('this'), [new Access($2)], 'this');
|
||||||
})
|
})
|
||||||
],
|
],
|
||||||
Array: [
|
Array: [
|
||||||
|
|
30
lib/nodes.js
30
lib/nodes.js
|
@ -1,5 +1,5 @@
|
||||||
(function() {
|
(function() {
|
||||||
var Accessor, Arr, Assign, Base, Call, Class, Closure, Code, Comment, Existence, Expressions, Extends, For, IDENTIFIER, IS_STRING, If, In, Index, LEVEL_ACCESS, LEVEL_COND, LEVEL_LIST, LEVEL_OP, LEVEL_PAREN, LEVEL_TOP, Literal, NEGATE, NO, NUMBER, Obj, Op, Param, Parens, Push, Range, Return, SIMPLENUM, Scope, Slice, Splat, Switch, TAB, THIS, TRAILING_WHITESPACE, Throw, Try, UTILITIES, Value, While, YES, compact, del, ends, extend, flatten, last, merge, multident, starts, unfoldSoak, utility, _ref;
|
var Access, Arr, Assign, Base, Call, Class, Closure, Code, Comment, Existence, Expressions, Extends, For, IDENTIFIER, IS_STRING, If, In, Index, LEVEL_ACCESS, LEVEL_COND, LEVEL_LIST, LEVEL_OP, LEVEL_PAREN, LEVEL_TOP, Literal, NEGATE, NO, NUMBER, Obj, Op, Param, Parens, Push, Range, Return, SIMPLENUM, Scope, Slice, Splat, Switch, TAB, THIS, TRAILING_WHITESPACE, Throw, Try, UTILITIES, Value, While, YES, compact, del, ends, extend, flatten, last, merge, multident, starts, unfoldSoak, utility, _ref;
|
||||||
var __hasProp = Object.prototype.hasOwnProperty, __extends = function(child, parent) {
|
var __hasProp = Object.prototype.hasOwnProperty, __extends = function(child, parent) {
|
||||||
for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; }
|
for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; }
|
||||||
function ctor() { this.constructor = child; }
|
function ctor() { this.constructor = child; }
|
||||||
|
@ -449,7 +449,7 @@
|
||||||
this.base.front = this.front;
|
this.base.front = this.front;
|
||||||
props = this.properties;
|
props = this.properties;
|
||||||
code = this.base.compile(o, props.length ? LEVEL_ACCESS : null);
|
code = this.base.compile(o, props.length ? LEVEL_ACCESS : null);
|
||||||
if (props[0] instanceof Accessor && this.isSimpleNumber()) {
|
if (props[0] instanceof Access && this.isSimpleNumber()) {
|
||||||
code = "(" + code + ")";
|
code = "(" + code + ")";
|
||||||
}
|
}
|
||||||
for (_i = 0, _len = props.length; _i < _len; _i++) {
|
for (_i = 0, _len = props.length; _i < _len; _i++) {
|
||||||
|
@ -644,21 +644,21 @@
|
||||||
};
|
};
|
||||||
return Extends;
|
return Extends;
|
||||||
}();
|
}();
|
||||||
exports.Accessor = Accessor = function() {
|
exports.Access = Access = function() {
|
||||||
function Accessor(_arg, tag) {
|
function Access(_arg, tag) {
|
||||||
this.name = _arg;
|
this.name = _arg;
|
||||||
this.proto = tag === 'proto' ? '.prototype' : '';
|
this.proto = tag === 'proto' ? '.prototype' : '';
|
||||||
this.soak = tag === 'soak';
|
this.soak = tag === 'soak';
|
||||||
}
|
}
|
||||||
__extends(Accessor, Base);
|
__extends(Access, Base);
|
||||||
Accessor.prototype.children = ['name'];
|
Access.prototype.children = ['name'];
|
||||||
Accessor.prototype.compile = function(o) {
|
Access.prototype.compile = function(o) {
|
||||||
var name;
|
var name;
|
||||||
name = this.name.compile(o);
|
name = this.name.compile(o);
|
||||||
return this.proto + (IS_STRING.test(name) ? "[" + name + "]" : "." + name);
|
return this.proto + (IS_STRING.test(name) ? "[" + name + "]" : "." + name);
|
||||||
};
|
};
|
||||||
Accessor.prototype.isComplex = NO;
|
Access.prototype.isComplex = NO;
|
||||||
return Accessor;
|
return Access;
|
||||||
}();
|
}();
|
||||||
exports.Index = Index = function() {
|
exports.Index = Index = function() {
|
||||||
function Index(_arg) {
|
function Index(_arg) {
|
||||||
|
@ -941,7 +941,7 @@
|
||||||
if (!this.variable) {
|
if (!this.variable) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
decl = (tail = last(this.variable.properties)) ? tail instanceof Accessor && tail.name.value : this.variable.base.value;
|
decl = (tail = last(this.variable.properties)) ? tail instanceof Access && tail.name.value : this.variable.base.value;
|
||||||
return decl && (decl = IDENTIFIER.test(decl) && decl);
|
return decl && (decl = IDENTIFIER.test(decl) && decl);
|
||||||
};
|
};
|
||||||
Class.prototype.setContext = function(name) {
|
Class.prototype.setContext = function(name) {
|
||||||
|
@ -993,7 +993,7 @@
|
||||||
assign = null;
|
assign = null;
|
||||||
} else {
|
} else {
|
||||||
if (!assign.variable["this"]) {
|
if (!assign.variable["this"]) {
|
||||||
assign.variable = new Value(new Literal(name), [new Accessor(base, 'proto')]);
|
assign.variable = new Value(new Literal(name), [new Access(base, 'proto')]);
|
||||||
}
|
}
|
||||||
if (func instanceof Code && func.bound) {
|
if (func instanceof Code && func.bound) {
|
||||||
this.boundFuncs.push(base);
|
this.boundFuncs.push(base);
|
||||||
|
@ -1129,7 +1129,7 @@
|
||||||
}
|
}
|
||||||
acc = IDENTIFIER.test(idx.unwrap().value || 0);
|
acc = IDENTIFIER.test(idx.unwrap().value || 0);
|
||||||
value = new Value(value);
|
value = new Value(value);
|
||||||
value.properties.push(new (acc ? Accessor : Index)(idx));
|
value.properties.push(new (acc ? Access : Index)(idx));
|
||||||
return new Assign(obj, value).compile(o);
|
return new Assign(obj, value).compile(o);
|
||||||
}
|
}
|
||||||
vvar = value.compile(o, LEVEL_LIST);
|
vvar = value.compile(o, LEVEL_LIST);
|
||||||
|
@ -1174,7 +1174,7 @@
|
||||||
} else {
|
} else {
|
||||||
acc = isObject && IDENTIFIER.test(idx.unwrap().value || 0);
|
acc = isObject && IDENTIFIER.test(idx.unwrap().value || 0);
|
||||||
}
|
}
|
||||||
val = new Value(new Literal(vvar), [new (acc ? Accessor : Index)(idx)]);
|
val = new Value(new Literal(vvar), [new (acc ? Access : Index)(idx)]);
|
||||||
}
|
}
|
||||||
assigns.push(new Assign(obj, val).compile(o, LEVEL_TOP));
|
assigns.push(new Assign(obj, val).compile(o, LEVEL_TOP));
|
||||||
}
|
}
|
||||||
|
@ -2023,7 +2023,7 @@
|
||||||
if (exps.isEmpty() || last(exps.expressions).containsPureStatement()) {
|
if (exps.isEmpty() || last(exps.expressions).containsPureStatement()) {
|
||||||
return exps;
|
return exps;
|
||||||
}
|
}
|
||||||
return exps.push(new Call(new Value(new Literal(name), [new Accessor(new Literal('push'))]), [exps.pop()]));
|
return exps.push(new Call(new Value(new Literal(name), [new Access(new Literal('push'))]), [exps.pop()]));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
Closure = {
|
Closure = {
|
||||||
|
@ -2040,7 +2040,7 @@
|
||||||
if (mentionsArgs) {
|
if (mentionsArgs) {
|
||||||
args.push(new Literal('arguments'));
|
args.push(new Literal('arguments'));
|
||||||
}
|
}
|
||||||
func = new Value(func, [new Accessor(meth)]);
|
func = new Value(func, [new Access(meth)]);
|
||||||
func.noReturn = noReturn;
|
func.noReturn = noReturn;
|
||||||
}
|
}
|
||||||
call = new Call(func, args);
|
call = new Call(func, args);
|
||||||
|
|
|
@ -157,13 +157,13 @@ case 73:this.$ = new yy.Value($$[$0-1+1-1]);
|
||||||
break;
|
break;
|
||||||
case 74:this.$ = $$[$0-1+1-1];
|
case 74:this.$ = $$[$0-1+1-1];
|
||||||
break;
|
break;
|
||||||
case 75:this.$ = new yy.Accessor($$[$0-2+2-1]);
|
case 75:this.$ = new yy.Access($$[$0-2+2-1]);
|
||||||
break;
|
break;
|
||||||
case 76:this.$ = new yy.Accessor($$[$0-2+2-1], 'soak');
|
case 76:this.$ = new yy.Access($$[$0-2+2-1], 'soak');
|
||||||
break;
|
break;
|
||||||
case 77:this.$ = new yy.Accessor($$[$0-2+2-1], 'proto');
|
case 77:this.$ = new yy.Access($$[$0-2+2-1], 'proto');
|
||||||
break;
|
break;
|
||||||
case 78:this.$ = new yy.Accessor(new yy.Literal('prototype'));
|
case 78:this.$ = new yy.Access(new yy.Literal('prototype'));
|
||||||
break;
|
break;
|
||||||
case 79:this.$ = $$[$0-1+1-1];
|
case 79:this.$ = $$[$0-1+1-1];
|
||||||
break;
|
break;
|
||||||
|
@ -227,7 +227,7 @@ case 106:this.$ = new yy.Value(new yy.Literal('this'));
|
||||||
break;
|
break;
|
||||||
case 107:this.$ = new yy.Value(new yy.Literal('this'));
|
case 107:this.$ = new yy.Value(new yy.Literal('this'));
|
||||||
break;
|
break;
|
||||||
case 108:this.$ = new yy.Value(new yy.Literal('this'), [new yy.Accessor($$[$0-2+2-1])], 'this');
|
case 108:this.$ = new yy.Value(new yy.Literal('this'), [new yy.Access($$[$0-2+2-1])], 'this');
|
||||||
break;
|
break;
|
||||||
case 109:this.$ = new yy.Arr([]);
|
case 109:this.$ = new yy.Arr([]);
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -240,10 +240,10 @@ grammar =
|
||||||
# The general group of accessors into an object, by property, by prototype
|
# The general group of accessors into an object, by property, by prototype
|
||||||
# or by array index or slice.
|
# or by array index or slice.
|
||||||
Accessor: [
|
Accessor: [
|
||||||
o '. Identifier', -> new Accessor $2
|
o '. Identifier', -> new Access $2
|
||||||
o '?. Identifier', -> new Accessor $2, 'soak'
|
o '?. Identifier', -> new Access $2, 'soak'
|
||||||
o ':: Identifier', -> new Accessor $2, 'proto'
|
o ':: Identifier', -> new Access $2, 'proto'
|
||||||
o '::', -> new Accessor new Literal 'prototype'
|
o '::', -> new Access new Literal 'prototype'
|
||||||
o 'Index'
|
o 'Index'
|
||||||
o 'Slice', -> new Slice $1
|
o 'Slice', -> new Slice $1
|
||||||
]
|
]
|
||||||
|
@ -313,7 +313,7 @@ grammar =
|
||||||
|
|
||||||
# A reference to a property on *this*.
|
# A reference to a property on *this*.
|
||||||
ThisProperty: [
|
ThisProperty: [
|
||||||
o '@ Identifier', -> new Value new Literal('this'), [new Accessor($2)], 'this'
|
o '@ Identifier', -> new Value new Literal('this'), [new Access($2)], 'this'
|
||||||
]
|
]
|
||||||
|
|
||||||
# The array literal.
|
# The array literal.
|
||||||
|
|
|
@ -383,7 +383,7 @@ exports.Value = class Value extends Base
|
||||||
@base.front = @front
|
@base.front = @front
|
||||||
props = @properties
|
props = @properties
|
||||||
code = @base.compile o, if props.length then LEVEL_ACCESS else null
|
code = @base.compile o, if props.length then LEVEL_ACCESS else null
|
||||||
code = "(#{code})" if props[0] instanceof Accessor and @isSimpleNumber()
|
code = "(#{code})" if props[0] instanceof Access and @isSimpleNumber()
|
||||||
code += prop.compile o for prop in props
|
code += prop.compile o for prop in props
|
||||||
code
|
code
|
||||||
|
|
||||||
|
@ -535,11 +535,11 @@ exports.Extends = class Extends extends Base
|
||||||
utility 'hasProp'
|
utility 'hasProp'
|
||||||
new Call(new Value(new Literal utility 'extends'), [@child, @parent]).compile o
|
new Call(new Value(new Literal utility 'extends'), [@child, @parent]).compile o
|
||||||
|
|
||||||
#### Accessor
|
#### Access
|
||||||
|
|
||||||
# A `.` accessor into a property of a value, or the `::` shorthand for
|
# A `.` access into a property of a value, or the `::` shorthand for
|
||||||
# an accessor into the object's prototype.
|
# an access into the object's prototype.
|
||||||
exports.Accessor = class Accessor extends Base
|
exports.Access = class Access extends Base
|
||||||
constructor: (@name, tag) ->
|
constructor: (@name, tag) ->
|
||||||
@proto = if tag is 'proto' then '.prototype' else ''
|
@proto = if tag is 'proto' then '.prototype' else ''
|
||||||
@soak = tag is 'soak'
|
@soak = tag is 'soak'
|
||||||
|
@ -554,7 +554,7 @@ exports.Accessor = class Accessor extends Base
|
||||||
|
|
||||||
#### Index
|
#### Index
|
||||||
|
|
||||||
# A `[ ... ]` indexed accessor into an array or object.
|
# A `[ ... ]` indexed access into an array or object.
|
||||||
exports.Index = class Index extends Base
|
exports.Index = class Index extends Base
|
||||||
constructor: (@index) ->
|
constructor: (@index) ->
|
||||||
|
|
||||||
|
@ -756,7 +756,7 @@ exports.Class = class Class extends Base
|
||||||
determineName: ->
|
determineName: ->
|
||||||
return null unless @variable
|
return null unless @variable
|
||||||
decl = if tail = last @variable.properties
|
decl = if tail = last @variable.properties
|
||||||
tail instanceof Accessor and tail.name.value
|
tail instanceof Access and tail.name.value
|
||||||
else
|
else
|
||||||
@variable.base.value
|
@variable.base.value
|
||||||
decl and= IDENTIFIER.test(decl) and decl
|
decl and= IDENTIFIER.test(decl) and decl
|
||||||
|
@ -800,7 +800,7 @@ exports.Class = class Class extends Base
|
||||||
assign = null
|
assign = null
|
||||||
else
|
else
|
||||||
unless assign.variable.this
|
unless assign.variable.this
|
||||||
assign.variable = new Value(new Literal(name), [new Accessor(base, 'proto')])
|
assign.variable = new Value(new Literal(name), [new Access(base, 'proto')])
|
||||||
if func instanceof Code and func.bound
|
if func instanceof Code and func.bound
|
||||||
@boundFuncs.push base
|
@boundFuncs.push base
|
||||||
func.bound = no
|
func.bound = no
|
||||||
|
@ -910,7 +910,7 @@ exports.Assign = class Assign extends Base
|
||||||
new Literal 0
|
new Literal 0
|
||||||
acc = IDENTIFIER.test idx.unwrap().value or 0
|
acc = IDENTIFIER.test idx.unwrap().value or 0
|
||||||
value = new Value value
|
value = new Value value
|
||||||
value.properties.push new (if acc then Accessor else Index) idx
|
value.properties.push new (if acc then Access else Index) idx
|
||||||
return new Assign(obj, value).compile o
|
return new Assign(obj, value).compile o
|
||||||
vvar = value.compile o, LEVEL_LIST
|
vvar = value.compile o, LEVEL_LIST
|
||||||
assigns = []
|
assigns = []
|
||||||
|
@ -950,7 +950,7 @@ exports.Assign = class Assign extends Base
|
||||||
acc = no
|
acc = no
|
||||||
else
|
else
|
||||||
acc = isObject and IDENTIFIER.test idx.unwrap().value or 0
|
acc = isObject and IDENTIFIER.test idx.unwrap().value or 0
|
||||||
val = new Value new Literal(vvar), [new (if acc then Accessor else Index) idx]
|
val = new Value new Literal(vvar), [new (if acc then Access else Index) idx]
|
||||||
assigns.push new Assign(obj, val).compile o, LEVEL_TOP
|
assigns.push new Assign(obj, val).compile o, LEVEL_TOP
|
||||||
assigns.push vvar unless top
|
assigns.push vvar unless top
|
||||||
code = assigns.join ', '
|
code = assigns.join ', '
|
||||||
|
@ -1610,7 +1610,7 @@ exports.If = class If extends Base
|
||||||
Push =
|
Push =
|
||||||
wrap: (name, exps) ->
|
wrap: (name, exps) ->
|
||||||
return exps if exps.isEmpty() or last(exps.expressions).containsPureStatement()
|
return exps if exps.isEmpty() or last(exps.expressions).containsPureStatement()
|
||||||
exps.push new Call new Value(new Literal(name), [new Accessor new Literal 'push']), [exps.pop()]
|
exps.push new Call new Value(new Literal(name), [new Access new Literal 'push']), [exps.pop()]
|
||||||
|
|
||||||
#### Closure
|
#### Closure
|
||||||
|
|
||||||
|
@ -1629,7 +1629,7 @@ Closure =
|
||||||
meth = new Literal if mentionsArgs then 'apply' else 'call'
|
meth = new Literal if mentionsArgs then 'apply' else 'call'
|
||||||
args = [new Literal 'this']
|
args = [new Literal 'this']
|
||||||
args.push new Literal 'arguments' if mentionsArgs
|
args.push new Literal 'arguments' if mentionsArgs
|
||||||
func = new Value func, [new Accessor meth]
|
func = new Value func, [new Access meth]
|
||||||
func.noReturn = noReturn
|
func.noReturn = noReturn
|
||||||
call = new Call func, args
|
call = new Call func, args
|
||||||
if statement then Expressions.wrap [call] else call
|
if statement then Expressions.wrap [call] else call
|
||||||
|
|
Loading…
Reference in New Issue