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