Commit | Line | Data |
---|---|---|
4eb88ef2 DM |
1 | load "../logo/printer.lg |
2 | load "../logo/types.lg | |
3 | ||
4 | to env_new :outer :binds :exprs | |
5 | localmake "data [] | |
6 | if 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 | ] | |
21 | output listtoarray list :outer :data | |
22 | end | |
23 | ||
24 | to env_outer :env | |
25 | output item 1 :env | |
26 | end | |
27 | ||
28 | to env_data :env | |
29 | output item 2 :env | |
30 | end | |
31 | ||
32 | to env_find :env :key | |
33 | if emptyp :env [output []] | |
34 | localmake "val hashmap_get env_data :env :key | |
35 | ifelse emptyp :val [ | |
36 | output env_find env_outer :env :key | |
37 | ] [ | |
38 | output :env | |
39 | ] | |
40 | end | |
41 | ||
42 | to env_get :env :key | |
43 | localmake "foundenv env_find :env :key | |
44 | if emptyp :foundenv [(throw "error sentence (word "' pr_str :key "true "' ) [not found])] | |
45 | output hashmap_get env_data :foundenv :key | |
46 | end | |
47 | ||
48 | to env_set :env :key :val | |
49 | .setitem 2 :env hashmap_put env_data :env :key :val | |
50 | output :val | |
51 | end |