expression-evaluation
Version:
Expression Evaluation
37 lines (36 loc) • 955 B
JavaScript
import { Node } from '../Node.js';
import { Type } from '../Type.js';
export class ConstantNode extends Node {
_value;
_signature;
_subnode;
constructor(frame, _value, _signature, _subnode) {
super(frame);
this._value = _value;
this._signature = _signature;
this._subnode = _subnode;
}
get type() {
return Type.of(this._value);
}
compile(type) {
this.reduceType(type);
if (this._signature && this._subnode) {
this._subnode = this._subnode.compile(this._signature.type);
}
return this;
}
evaluate() {
return this._value;
}
get constant() {
return !this._subnode;
}
get signature() {
return this._signature;
}
toString(ident = 0) {
return `${super.toString(ident)} constant node`
+ (this._subnode ? `, subnode:\n${this._subnode.toString(ident + 1)}` : '');
}
}