Commit | Line | Data |
---|---|---|
0cb556e0 JM |
1 | |
2 | REM ENV_NEW(EO%) -> R% | |
3 | ENV_NEW: | |
4 | REM allocate the data hashmap | |
5 | GOSUB HASHMAP | |
412e7348 | 6 | ET%=R% |
0cb556e0 | 7 | |
60270667 | 8 | REM set the outer and data pointer |
60ef223c | 9 | SZ%=2:GOSUB ALLOC |
bf8d1f7d JM |
10 | Z%(R%,0)=13+16 |
11 | Z%(R%,1)=ET% | |
12 | Z%(R%+1,0)=13 | |
13 | Z%(R%+1,1)=EO% | |
4b84a23b | 14 | IF EO%<>-1 THEN Z%(EO%,0)=Z%(EO%,0)+16 |
0cb556e0 JM |
15 | RETURN |
16 | ||
4b84a23b JM |
17 | REM see RELEASE types.in.bas for environment cleanup |
18 | ||
241d5d57 JM |
19 | REM ENV_NEW_BINDS(EO%, BI%, EX%) -> R% |
20 | ENV_NEW_BINDS: | |
21 | GOSUB ENV_NEW | |
22 | E%=R% | |
23 | REM process bindings | |
24 | ENV_NEW_BINDS_LOOP: | |
60ef223c | 25 | IF Z%(BI%,1)=0 THEN R%=E%:RETURN |
241d5d57 | 26 | REM get/deref the key from BI% |
60ef223c | 27 | R%=BI%+1:GOSUB DEREF_R |
241d5d57 JM |
28 | K%=R% |
29 | ||
60ef223c | 30 | IF ZS$(Z%(K%,1))="&" THEN GOTO EVAL_NEW_BINDS_VARGS |
241d5d57 JM |
31 | |
32 | EVAL_NEW_BINDS_1x1: | |
33 | REM get/deref the key from EX% | |
60ef223c | 34 | R%=EX%+1:GOSUB DEREF_R |
241d5d57 JM |
35 | V%=R% |
36 | REM set the binding in the environment data | |
37 | GOSUB ENV_SET | |
38 | REM go to next element of BI% and EX% | |
39 | BI%=Z%(BI%,1) | |
40 | EX%=Z%(EX%,1) | |
41 | GOTO ENV_NEW_BINDS_LOOP | |
42 | ||
43 | EVAL_NEW_BINDS_VARGS: | |
44 | REM get/deref the key from next element of BI% | |
45 | BI%=Z%(BI%,1) | |
60ef223c | 46 | R%=BI%+1:GOSUB DEREF_R |
241d5d57 JM |
47 | K%=R% |
48 | REM the value is the remaining list in EX% | |
49 | V%=EX% | |
50 | REM set the binding in the environment data | |
51 | GOSUB ENV_SET | |
52 | R%=E% | |
53 | RETURN | |
54 | ||
0cb556e0 JM |
55 | REM ENV_SET(E%, K%, V%) -> R% |
56 | ENV_SET: | |
60270667 | 57 | HM%=Z%(E%,1) |
0cb556e0 | 58 | GOSUB ASSOC1 |
60270667 | 59 | Z%(E%,1)=R% |
0cb556e0 JM |
60 | R%=V% |
61 | RETURN | |
62 | ||
63 | REM ENV_SET_S(E%, K$, V%) -> R% | |
64 | ENV_SET_S: | |
60270667 | 65 | HM%=Z%(E%,1) |
0cb556e0 | 66 | GOSUB ASSOC1_S |
60270667 | 67 | Z%(E%,1)=R% |
0cb556e0 JM |
68 | R%=V% |
69 | RETURN | |
70 | ||
71 | REM ENV_FIND(E%, K%) -> R% | |
70f29a2b JM |
72 | REM Returns environment (R%) containing K%. If found, value found is |
73 | REM in T4% | |
0cb556e0 JM |
74 | ENV_FIND: |
75 | EF%=E% | |
76 | ENV_FIND_LOOP: | |
60270667 | 77 | HM%=Z%(EF%,1) |
0cb556e0 JM |
78 | REM More efficient to use GET for value (R%) and contains? (T3%) |
79 | GOSUB HASHMAP_GET | |
80 | REM if we found it, save value in T4% for ENV_GET | |
60ef223c | 81 | IF T3%=1 THEN T4%=R%:GOTO ENV_FIND_DONE |
60270667 | 82 | EF%=Z%(EF%+1,1): REM get outer environment |
0cb556e0 JM |
83 | IF EF%<>-1 THEN GOTO ENV_FIND_LOOP |
84 | ENV_FIND_DONE: | |
85 | R%=EF% | |
86 | RETURN | |
87 | ||
88 | REM ENV_GET(E%, K%) -> R% | |
89 | ENV_GET: | |
90 | GOSUB ENV_FIND | |
5e5ca0d4 | 91 | IF R%=-1 THEN R%=0:ER%=-1:ER$="'"+ZS$(Z%(K%,1))+"' not found":RETURN |
60ef223c | 92 | R%=T4%:GOSUB DEREF_R |
4b84a23b | 93 | Z%(R%,0)=Z%(R%,0)+16 |
0cb556e0 | 94 | RETURN |