DISABLE FDs (REMOVE ME).
[jackhill/mal.git] / logo / env.lg
CommitLineData
4eb88ef2
DM
1load "../logo/printer.lg
2load "../logo/types.lg
3
4to env_new :outer :binds :exprs
5localmake "data []
6if not emptyp :binds [
7 localmake "i 0
8 while [:i < _count :binds] [
9 ifelse (nth :binds :i) = [symbol &] [
10 localmake "val drop :exprs :i
11 make "i (:i + 1)
12 localmake "key nth :binds :i
13 ] [
14 localmake "val nth :exprs :i
15 localmake "key nth :binds :i
16 ]
17 make "data hashmap_put :data :key :val
18 make "i (:i + 1)
19 ]
20]
21output listtoarray list :outer :data
22end
23
24to env_outer :env
25output item 1 :env
26end
27
28to env_data :env
29output item 2 :env
30end
31
32to env_find :env :key
33if emptyp :env [output []]
34localmake "val hashmap_get env_data :env :key
35ifelse emptyp :val [
36 output env_find env_outer :env :key
37] [
38 output :env
39]
40end
41
42to env_get :env :key
43localmake "foundenv env_find :env :key
44if emptyp :foundenv [(throw "error sentence (word "' pr_str :key "true "' ) [not found])]
45output hashmap_get env_data :foundenv :key
46end
47
48to env_set :env :key :val
49.setitem 2 :env hashmap_put env_data :env :key :val
50output :val
51end