calcium-lang
Version:
Calcium language interpreter
62 lines • 1.5 kB
JavaScript
/**
* Represent the point of the execution or function's address.
*/
export default class Address {
/**
*
*/
/**
*
* @param indent corresponds to Python's indent
* @param line line number (index in the code array)
* @param file module index
* @param call call counter for a recursive function
*/
constructor(indent, line, file = 0, call = 0) {
this.indent = indent;
this.line = line;
this.file = file;
this.call = call;
}
/**
* Make a copy
*/
clone() {
return new Address(this.indent, this.line, this.file, this.call);
}
/**
*
* @param address another address
* @returns whether two addresses are at same position
*/
isAt(address) {
return (this.indent === address.indent &&
this.line === address.line &&
this.file === address.file &&
this.call === address.call);
}
/**
* jump and go to the specified address
* @param toPoint
*/
jump(toPoint) {
this.indent = toPoint.indent;
this.line = toPoint.line;
this.file = toPoint.file;
}
/**
* add the delta to the indent
* @param x the delta of the indent
*/
shift(x) {
this.indent += x;
}
/**
* add the delta to the line number
* @param y the delta of the line number
*/
skip(y) {
this.line += y;
}
}
//# sourceMappingURL=address.js.map