DISABLE FDs (REMOVE ME).
[jackhill/mal.git] / pike / Env.pmod
1 import .Types;
2
3 class Env
4 {
5 Env outer;
6 mapping(string:Val) data;
7
8 void create(Env the_outer, List|void binds, List|void exprs)
9 {
10 outer = the_outer;
11 data = ([ ]);
12 if(binds)
13 {
14 for(int i = 0; i < binds.count(); i++)
15 {
16 if(binds.data[i].value == "&")
17 {
18 set(binds.data[i + 1], List(exprs.data[i..]));
19 break;
20 }
21 set(binds.data[i], exprs.data[i]);
22 }
23 }
24 }
25
26 Val set(Val key, Val val)
27 {
28 data[key.value] = val;
29 return val;
30 }
31
32 Env find(Val key)
33 {
34 if(data[key.value]) return this_object();
35 if(outer) return outer.find(key);
36 return 0;
37 }
38
39 Val get(Val key)
40 {
41 Env found_env = find(key);
42 if(!found_env) throw("'" + key.value + "' not found");
43 return found_env.data[key.value];
44 }
45 }