diff options
author | Alex Lam S.L <alexlamsl@gmail.com> | 2017-04-12 21:56:27 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-04-12 21:56:27 +0800 |
commit | 2244743545e8e5a75b4cce219605588cd29581b1 (patch) | |
tree | fc5b7077957e20489fada1b3388e39be2f958404 /lib/ast.js | |
parent | 04b89645058d85b8b67bb94fb9e39252160a0959 (diff) | |
download | tracifyjs-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.js | 64 |
1 files changed, 6 insertions, 58 deletions
@@ -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); + }); }); } }); |