12345678910111213141516171819202122232425262728293031323334 |
- const AST = require('./ast')
- const core = require('./core')
- const OsloError = require('./osloError')
-
- module.exports = class Env {
- constructor(parent = null) {
- this.data = {}
-
- if (parent) {
- Object.keys(parent.data).forEach(key => {
- this.data[key] = parent.data[key]
- })
- } else {
- Object.keys(core).forEach(key => {
- this.data[key] = core[key]
- })
- }
- }
-
- get(symbol) {
- if (this.data[symbol.name]) {
- return this.data[symbol.name]
- }
-
- return new OsloError({
- line: symbol.line,
- message: `Symbol '${symbol.name}' is not bound`,
- })
- }
-
- set(symbol, value) {
- this.data[symbol.name] = value
- }
- }
|