UNPKG

calcium-lang

Version:
59 lines 1.56 kB
import Address from "./address"; import Namespace from "./namespace"; import { None } from "../factory"; /** * the runtime environment that has data to control the execution */ export default class Environment { /** * * @param code must be a valid JSON array or its stringified representation. * @param builtin the namespace for built-in objects */ constructor(code, builtin) { /** * the current point of the execution */ this.address = new Address(1, 0); /** * a stack of command blocks */ this.blocks = []; /** * used when a function call is returned, and the command is restarted */ this.commandsWithCall = []; /** * used to return a value from a function */ this.returnedValue = None; /** * a call stack */ this.callStack = []; if (typeof code === "string") { this.code = JSON.parse(code); } else { this.code = code; } const global = new Namespace(builtin); this.context = global; } /** * get the current line index in the code array */ get currentLineIndex() { return this.address.line; } get exceptionThrown() { return this.exception !== undefined; } /** * get the last block that had been entered */ get lastBlock() { return this.blocks[this.blocks.length - 1]; } } //# sourceMappingURL=environment.js.map