diff --git a/impls/basic/env.in.bas b/impls/basic/env.in.bas index 6f1ed97c57..5a4f4d639d 100644 --- a/impls/basic/env.in.bas +++ b/impls/basic/env.in.bas @@ -63,27 +63,16 @@ ENV_SET_S: R=C RETURN -REM ENV_FIND(E, K) -> R -REM Returns environment (R) containing K. If found, value found is -REM in R4 -SUB ENV_FIND +REM ENV_GET(E, K) -> R +REM R3 is either 0 (missing key) or 1, then R is the increfed value. +SUB ENV_GET T=E ENV_FIND_LOOP: H=Z%(T+1) REM More efficient to use GET for value (R) and contains? (R3) GOSUB HASHMAP_GET - REM if we found it, save value in R4 for ENV_GET - IF R3=1 THEN R4=R:R=T:GOTO ENV_FIND_DONE + REM if we found it, return it + IF R3=1 THEN GOTO INC_REF_R T=Z%(T+2): REM get outer environment IF T>0 THEN GOTO ENV_FIND_LOOP - R=-1 - ENV_FIND_DONE: END SUB - -REM ENV_GET(E, K) -> R -ENV_GET: - CALL ENV_FIND - IF R=-1 THEN ER=-1:E$="'"+S$(Z%(K+1))+"' not found":GOTO ENV_GET_RETURN - R=R4 - GOSUB INC_REF_R - GOTO ENV_GET_RETURN diff --git a/impls/basic/step2_eval.in.bas b/impls/basic/step2_eval.in.bas index b72100ebc8..0f4de6d11f 100755 --- a/impls/basic/step2_eval.in.bas +++ b/impls/basic/step2_eval.in.bas @@ -29,8 +29,7 @@ SUB EVAL_AST EVAL_AST_SYMBOL: H=E:K=A:GOSUB HASHMAP_GET - IF R3=0 THEN R=-1:ER=-1:E$="'"+S$(Z%(A+1))+"' not found":GOTO EVAL_AST_RETURN - GOSUB INC_REF_R + IF R3=0 THEN ER=-1:E$="'"+S$(Z%(A+1))+"' not found" ELSE GOSUB INC_REF_R GOTO EVAL_AST_RETURN EVAL_AST_SEQ: diff --git a/impls/basic/step3_env.in.bas b/impls/basic/step3_env.in.bas index 96ee355265..592fa961fe 100755 --- a/impls/basic/step3_env.in.bas +++ b/impls/basic/step3_env.in.bas @@ -29,8 +29,8 @@ SUB EVAL_AST GOTO EVAL_AST_RETURN EVAL_AST_SYMBOL: - K=A:GOTO ENV_GET - ENV_GET_RETURN: + K=A:CALL ENV_GET + IF R3=0 THEN ER=-1:E$="'"+S$(Z%(A+1))+"' not found" GOTO EVAL_AST_RETURN EVAL_AST_SEQ: diff --git a/impls/basic/step4_if_fn_do.in.bas b/impls/basic/step4_if_fn_do.in.bas index 16e47ebfbe..4d3a4518f7 100755 --- a/impls/basic/step4_if_fn_do.in.bas +++ b/impls/basic/step4_if_fn_do.in.bas @@ -30,8 +30,8 @@ SUB EVAL_AST GOTO EVAL_AST_RETURN EVAL_AST_SYMBOL: - K=A:GOTO ENV_GET - ENV_GET_RETURN: + K=A:CALL ENV_GET + IF R3=0 THEN ER=-1:E$="'"+S$(Z%(A+1))+"' not found" GOTO EVAL_AST_RETURN EVAL_AST_SEQ: diff --git a/impls/basic/step5_tco.in.bas b/impls/basic/step5_tco.in.bas index f41c7a804d..2019cdbb80 100755 --- a/impls/basic/step5_tco.in.bas +++ b/impls/basic/step5_tco.in.bas @@ -30,8 +30,8 @@ SUB EVAL_AST GOTO EVAL_AST_RETURN EVAL_AST_SYMBOL: - K=A:GOTO ENV_GET - ENV_GET_RETURN: + K=A:CALL ENV_GET + IF R3=0 THEN ER=-1:E$="'"+S$(Z%(A+1))+"' not found" GOTO EVAL_AST_RETURN EVAL_AST_SEQ: diff --git a/impls/basic/step6_file.in.bas b/impls/basic/step6_file.in.bas index cfe8a34fe4..3538b96d73 100755 --- a/impls/basic/step6_file.in.bas +++ b/impls/basic/step6_file.in.bas @@ -30,8 +30,8 @@ SUB EVAL_AST GOTO EVAL_AST_RETURN EVAL_AST_SYMBOL: - K=A:GOTO ENV_GET - ENV_GET_RETURN: + K=A:CALL ENV_GET + IF R3=0 THEN ER=-1:E$="'"+S$(Z%(A+1))+"' not found" GOTO EVAL_AST_RETURN EVAL_AST_SEQ: diff --git a/impls/basic/step7_quote.in.bas b/impls/basic/step7_quote.in.bas index 6151e615d0..ab3e90f559 100755 --- a/impls/basic/step7_quote.in.bas +++ b/impls/basic/step7_quote.in.bas @@ -143,8 +143,8 @@ SUB EVAL_AST GOTO EVAL_AST_RETURN EVAL_AST_SYMBOL: - K=A:GOTO ENV_GET - ENV_GET_RETURN: + K=A:CALL ENV_GET + IF R3=0 THEN ER=-1:E$="'"+S$(Z%(A+1))+"' not found" GOTO EVAL_AST_RETURN EVAL_AST_SEQ: diff --git a/impls/basic/step8_macros.in.bas b/impls/basic/step8_macros.in.bas index 9a83de0e15..b5a174aef4 100755 --- a/impls/basic/step8_macros.in.bas +++ b/impls/basic/step8_macros.in.bas @@ -138,9 +138,9 @@ SUB MACROEXPAND REM symbol? in first position IF (Z%(B)AND 31)<>5 THEN GOTO MACROEXPAND_DONE REM defined in environment? - K=B:CALL ENV_FIND - IF R=-1 THEN GOTO MACROEXPAND_DONE - B=R4 + K=B:CALL ENV_GET + IF R3=0 THEN GOTO MACROEXPAND_DONE + B=R REM macro? IF (Z%(B)AND 31)<>11 THEN GOTO MACROEXPAND_DONE @@ -177,8 +177,8 @@ SUB EVAL_AST GOTO EVAL_AST_RETURN EVAL_AST_SYMBOL: - K=A:GOTO ENV_GET - ENV_GET_RETURN: + K=A:CALL ENV_GET + IF R3=0 THEN ER=-1:E$="'"+S$(Z%(A+1))+"' not found" GOTO EVAL_AST_RETURN EVAL_AST_SEQ: diff --git a/impls/basic/step9_try.in.bas b/impls/basic/step9_try.in.bas index 657a67f507..d4d9147c4d 100755 --- a/impls/basic/step9_try.in.bas +++ b/impls/basic/step9_try.in.bas @@ -138,9 +138,9 @@ SUB MACROEXPAND REM symbol? in first position IF (Z%(B)AND 31)<>5 THEN GOTO MACROEXPAND_DONE REM defined in environment? - K=B:CALL ENV_FIND - IF R=-1 THEN GOTO MACROEXPAND_DONE - B=R4 + K=B:CALL ENV_GET + IF R3=0 THEN GOTO MACROEXPAND_DONE + B=R REM macro? IF (Z%(B)AND 31)<>11 THEN GOTO MACROEXPAND_DONE @@ -177,8 +177,8 @@ SUB EVAL_AST GOTO EVAL_AST_RETURN EVAL_AST_SYMBOL: - K=A:GOTO ENV_GET - ENV_GET_RETURN: + K=A:CALL ENV_GET + IF R3=0 THEN ER=-1:E$="'"+S$(Z%(A+1))+"' not found" GOTO EVAL_AST_RETURN EVAL_AST_SEQ: diff --git a/impls/basic/stepA_mal.in.bas b/impls/basic/stepA_mal.in.bas index 9a3790ff1c..b746489455 100755 --- a/impls/basic/stepA_mal.in.bas +++ b/impls/basic/stepA_mal.in.bas @@ -138,9 +138,9 @@ SUB MACROEXPAND REM symbol? in first position IF (Z%(B)AND 31)<>5 THEN GOTO MACROEXPAND_DONE REM defined in environment? - K=B:CALL ENV_FIND - IF R=-1 THEN GOTO MACROEXPAND_DONE - B=R4 + K=B:CALL ENV_GET + IF R3=0 THEN GOTO MACROEXPAND_DONE + B=R REM macro? IF (Z%(B)AND 31)<>11 THEN GOTO MACROEXPAND_DONE @@ -177,8 +177,8 @@ SUB EVAL_AST GOTO EVAL_AST_RETURN EVAL_AST_SYMBOL: - K=A:GOTO ENV_GET - ENV_GET_RETURN: + K=A:CALL ENV_GET + IF R3=0 THEN ER=-1:E$="'"+S$(Z%(A+1))+"' not found" GOTO EVAL_AST_RETURN EVAL_AST_SEQ: diff --git a/impls/basic/variables.txt b/impls/basic/variables.txt index 3e7afc7623..9e112c7ca5 100644 --- a/impls/basic/variables.txt +++ b/impls/basic/variables.txt @@ -60,7 +60,6 @@ P3 : PR_OBJECT, PR_MEMORY_VALUE R1 : REP, RE - MAL_READ result temp R2 : REP, RE - EVAL result temp R3 : HASHMAP_GET, DO_HASH_MAP, DO_KEYS_VALS temp and return value -R4 : ENV_FIND temp and return value R6 : SLICE return value (last element) SZ : size argument to ALLOC S1$ : REPLACE needle