Commit | Line | Data |
---|---|---|
a9c0e8ba JB |
1 | export class Env |
2 | (outer = null, data = {}) -> | |
3 | @outer = outer | |
4 | @data = data | |
5 | ||
6 | set: (symbol, ast) -> | |
7 | @data[symbol] = ast | |
8 | ||
9 | find: (symbol) -> | |
10 | if symbol of @data then @ | |
11 | else if @outer? then @outer.find symbol | |
12 | ||
13 | get: (symbol) -> | |
86e32f4d JB |
14 | result = @try-get symbol |
15 | if not result | |
65164fe2 | 16 | then throw new Error "'#{symbol}' not found" |
86e32f4d JB |
17 | else result |
18 | ||
19 | try-get: (symbol) -> | |
a9c0e8ba JB |
20 | env = @find symbol |
21 | if env then env.data[symbol] |