expression-evaluation
Version:
Expression Evaluation
34 lines (33 loc) • 1.13 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.ArrayNode = void 0;
const Node_js_1 = require("../Node.js");
const ConstantNode_js_1 = require("./ConstantNode.js");
const Type_js_1 = require("../Type.js");
class ArrayNode extends Node_js_1.Node {
_subnodes;
constructor(frame, _subnodes) {
super(frame);
this._subnodes = _subnodes;
}
get type() {
return Type_js_1.typeArray;
}
compile(type) {
this.reduceType(type);
let constant = true;
for (let i = 0; i < this._subnodes.length; ++i) {
this._subnodes[i] = this._subnodes[i].compile(Type_js_1.typeUnknown);
constant &&= this._subnodes[i].constant;
}
return constant ? new ConstantNode_js_1.ConstantNode(this, this.evaluate()) : this;
}
evaluate() {
return this._subnodes.map((s) => s.evaluate());
}
toString(ident = 0) {
return `${super.toString(ident)} array node`
+ `, subnodes:\n${this._subnodes.map((s) => s.toString(ident + 1)).join('\n')}`;
}
}
exports.ArrayNode = ArrayNode;
;