expression-evaluation
Version:
Expression Evaluation
30 lines (29 loc) • 927 B
JavaScript
import { Node } from '../Node.js';
export class VariableNode extends Node {
_variable;
_subnode;
constructor(frame, _variable, _subnode) {
super(frame);
this._variable = _variable;
this._subnode = _subnode;
}
get type() {
return this._variable.type;
}
compile(type) {
this._subnode = this._subnode?.compile(type);
this._variable.type = this.reduceType(this._subnode?.type ?? type);
this._variable.signature = this._subnode?.signature;
return this;
}
evaluate() {
return this._subnode ? this._variable.value = this._subnode.evaluate() : this._variable.value;
}
get signature() {
return this._variable.signature;
}
toString(ident = 0) {
return `${super.toString(ident)} variable node`
+ (this._subnode ? `, subnode:\n${this._subnode?.toString(ident + 1) ?? ''}` : '');
}
}