aboutsummaryrefslogtreecommitdiff
path: root/lib/ast.js
diff options
context:
space:
mode:
authorAlex Lam S.L <alexlamsl@gmail.com>2017-04-12 21:56:27 +0800
committerGitHub <noreply@github.com>2017-04-12 21:56:27 +0800
commit2244743545e8e5a75b4cce219605588cd29581b1 (patch)
treefc5b7077957e20489fada1b3388e39be2f958404 /lib/ast.js
parent04b89645058d85b8b67bb94fb9e39252160a0959 (diff)
downloadtracifyjs-2244743545e8e5a75b4cce219605588cd29581b1.tar.gz
tracifyjs-2244743545e8e5a75b4cce219605588cd29581b1.zip
convert `AST_Seq` from binary tree to array (#1460)
- rename `AST_Seq` to `AST_Sequence` - raise default sequences_limit from 200 to 800
Diffstat (limited to 'lib/ast.js')
-rw-r--r--lib/ast.js64
1 files changed, 6 insertions, 58 deletions
diff --git a/lib/ast.js b/lib/ast.js
index ba1330f4..f78ac576 100644
--- a/lib/ast.js
+++ b/lib/ast.js
@@ -613,68 +613,16 @@ var AST_New = DEFNODE("New", null, {
$documentation: "An object instantiation. Derives from a function call since it has exactly the same properties"
}, AST_Call);
-var AST_Seq = DEFNODE("Seq", "car cdr", {
- $documentation: "A sequence expression (two comma-separated expressions)",
+var AST_Sequence = DEFNODE("Sequence", "expressions", {
+ $documentation: "A sequence expression (comma-separated expressions)",
$propdoc: {
- car: "[AST_Node] first element in sequence",
- cdr: "[AST_Node] second element in sequence"
- },
- $cons: function(x, y) {
- var seq = new AST_Seq(x);
- seq.car = x;
- seq.cdr = y;
- return seq;
- },
- $from_array: function(array) {
- if (array.length == 0) return null;
- if (array.length == 1) return array[0].clone();
- var list = null;
- for (var i = array.length; --i >= 0;) {
- list = AST_Seq.cons(array[i], list);
- }
- var p = list;
- while (p) {
- if (p.cdr && !p.cdr.cdr) {
- p.cdr = p.cdr.car;
- break;
- }
- p = p.cdr;
- }
- return list;
- },
- to_array: function() {
- var p = this, a = [];
- while (p) {
- a.push(p.car);
- if (p.cdr && !(p.cdr instanceof AST_Seq)) {
- a.push(p.cdr);
- break;
- }
- p = p.cdr;
- }
- return a;
- },
- add: function(node) {
- var p = this;
- while (p) {
- if (!(p.cdr instanceof AST_Seq)) {
- var cell = AST_Seq.cons(p.cdr, node);
- return p.cdr = cell;
- }
- p = p.cdr;
- }
- },
- len: function() {
- if (this.cdr instanceof AST_Seq) {
- return this.cdr.len() + 1;
- } else {
- return 2;
- }
+ expressions: "[AST_Node*] array of expressions (at least two)"
},
_walk: function(visitor) {
return visitor._visit(this, function(){
- this.car._walk(visitor);
- if (this.cdr) this.cdr._walk(visitor);
+ this.expressions.forEach(function(node) {
+ node._walk(visitor);
+ });
});
}
});