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 | |
f9f1cec9 | 6 | AY=R |
0cb556e0 | 7 | |
60270667 | 8 | REM set the outer and data pointer |
d7a6c2d6 | 9 | T=13:L=R:M=C:GOSUB ALLOC |
f9f1cec9 | 10 | 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: | |
d7a6c2d6 | 21 | IF Z%(A+1)=0 THEN R=E:RETURN |
c756af81 | 22 | REM get/deref the key from A |
d7a6c2d6 | 23 | K=Z%(A+2) |
241d5d57 | 24 | |
d7a6c2d6 | 25 | IF S$(Z%(K+1))="&" THEN GOTO EVAL_NEW_BINDS_VARGS |
241d5d57 JM |
26 | |
27 | EVAL_NEW_BINDS_1x1: | |
c756af81 | 28 | REM get/deref the key from B |
d7a6c2d6 | 29 | C=Z%(B+2) |
241d5d57 JM |
30 | REM set the binding in the environment data |
31 | GOSUB ENV_SET | |
c756af81 | 32 | REM go to next element of A and B |
d7a6c2d6 JM |
33 | A=Z%(A+1) |
34 | B=Z%(B+1) | |
241d5d57 JM |
35 | GOTO ENV_NEW_BINDS_LOOP |
36 | ||
37 | EVAL_NEW_BINDS_VARGS: | |
c756af81 | 38 | REM get/deref the key from next element of A |
d7a6c2d6 JM |
39 | A=Z%(A+1) |
40 | K=Z%(A+2) | |
c756af81 JM |
41 | REM the value is the remaining list in B |
42 | A=B:T=6:GOSUB FORCE_SEQ_TYPE | |
43 | C=R | |
241d5d57 JM |
44 | REM set the binding in the environment data |
45 | GOSUB ENV_SET | |
cc9dbd92 | 46 | R=E |
c756af81 | 47 | AY=C:GOSUB RELEASE: REM list is owned by environment |
241d5d57 JM |
48 | RETURN |
49 | ||
c756af81 | 50 | REM ENV_SET(E, K, C) -> R |
0cb556e0 | 51 | ENV_SET: |
d7a6c2d6 | 52 | H=Z%(E+1) |
0cb556e0 | 53 | GOSUB ASSOC1 |
d7a6c2d6 | 54 | Z%(E+1)=R |
c756af81 | 55 | R=C |
0cb556e0 JM |
56 | RETURN |
57 | ||
037815e0 | 58 | REM ENV_SET_S(E, B$, C) -> R |
0cb556e0 | 59 | ENV_SET_S: |
d7a6c2d6 | 60 | H=Z%(E+1) |
0cb556e0 | 61 | GOSUB ASSOC1_S |
d7a6c2d6 | 62 | Z%(E+1)=R |
c756af81 | 63 | R=C |
0cb556e0 JM |
64 | RETURN |
65 | ||
cc9dbd92 JM |
66 | REM ENV_FIND(E, K) -> R |
67 | REM Returns environment (R) containing K. If found, value found is | |
f9f1cec9 | 68 | REM in R4 |
af621e3a | 69 | SUB ENV_FIND |
c756af81 | 70 | T=E |
0cb556e0 | 71 | ENV_FIND_LOOP: |
d7a6c2d6 | 72 | H=Z%(T+1) |
f9f1cec9 | 73 | REM More efficient to use GET for value (R) and contains? (R3) |
0cb556e0 | 74 | GOSUB HASHMAP_GET |
f9f1cec9 | 75 | REM if we found it, save value in R4 for ENV_GET |
9d59cdb3 | 76 | IF R3=1 THEN R4=R:R=T:GOTO ENV_FIND_DONE |
d7a6c2d6 | 77 | T=Z%(T+2): REM get outer environment |
9d59cdb3 JM |
78 | IF T>0 THEN GOTO ENV_FIND_LOOP |
79 | R=-1 | |
0cb556e0 | 80 | ENV_FIND_DONE: |
af621e3a | 81 | END SUB |
0cb556e0 | 82 | |
cc9dbd92 | 83 | REM ENV_GET(E, K) -> R |
0cb556e0 | 84 | ENV_GET: |
af621e3a | 85 | CALL ENV_FIND |
d7a6c2d6 | 86 | IF R=-1 THEN ER=-1:E$="'"+S$(Z%(K+1))+"' not found":GOTO ENV_GET_RETURN |
9d59cdb3 | 87 | R=R4 |
4202ef7b | 88 | GOSUB INC_REF_R |
af621e3a | 89 | GOTO ENV_GET_RETURN |