Skip to content

Commit

Permalink
basic: move symbols and unchanged types from eval_ast to eval
Browse files Browse the repository at this point in the history
  • Loading branch information
asarhaddon committed Nov 14, 2024
1 parent 2a8a4ec commit 8833932
Show file tree
Hide file tree
Showing 9 changed files with 159 additions and 147 deletions.
33 changes: 17 additions & 16 deletions impls/basic/step2_eval.in.bas
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,8 @@ SUB EVAL_AST
IF ER<>-2 THEN GOTO EVAL_AST_RETURN

GOSUB TYPE_A
IF T=5 THEN GOTO EVAL_AST_SYMBOL
IF T>5 AND T<9 THEN GOTO EVAL_AST_SEQ
IF T<6 OR 8<T THEN R=-1:ER=-1:E$="EVAL_AST: bad type":GOTO EVAL_AST_RETURN

REM scalar: deref to actual value and inc ref cnt
R=A
GOSUB INC_REF_R
GOTO EVAL_AST_RETURN

EVAL_AST_SYMBOL:
H=E:B$=S$(Z%(A+1)):GOSUB HASHMAP_GET
IF R3=0 THEN R=-1:ER=-1:E$="'"+B$+"' not found":GOTO EVAL_AST_RETURN
GOSUB INC_REF_R
GOTO EVAL_AST_RETURN

EVAL_AST_SEQ:
REM setup the stack for the loop
GOSUB MAP_LOOP_START

Expand Down Expand Up @@ -94,9 +81,23 @@ SUB EVAL
REM AZ=A:B=1:GOSUB PR_STR
REM PRINT "EVAL: "+R$+" [A:"+STR$(A)+", LV:"+STR$(LV)+"]"

GOSUB LIST_Q
IF R THEN GOTO APPLY_LIST
GOSUB TYPE_A
T=T-4
IF 0<T THEN ON T GOTO EVAL_SYMBOL,APPLY_LIST,EVAL_VECTOR,EVAL_MAP

REM ELSE
R=A
GOSUB INC_REF_R
GOTO EVAL_RETURN

EVAL_SYMBOL:
H=E:B$=S$(Z%(A+1)):GOSUB HASHMAP_GET
IF R3=0 THEN R=-1:ER=-1:E$="'"+B$+"' not found":GOTO EVAL_RETURN
GOSUB INC_REF_R
GOTO EVAL_RETURN

EVAL_MAP:
EVAL_VECTOR:
CALL EVAL_AST
GOTO EVAL_RETURN

Expand Down
33 changes: 17 additions & 16 deletions impls/basic/step3_env.in.bas
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,8 @@ SUB EVAL_AST
IF ER<>-2 THEN GOTO EVAL_AST_RETURN

GOSUB TYPE_A
IF T=5 THEN GOTO EVAL_AST_SYMBOL
IF T>5 AND T<9 THEN GOTO EVAL_AST_SEQ
IF T<6 OR 8<T THEN R=-1:ER=-1:E$="EVAL_AST: bad type":GOTO EVAL_AST_RETURN

REM scalar: deref to actual value and inc ref cnt
R=A
GOSUB INC_REF_R
GOTO EVAL_AST_RETURN

EVAL_AST_SYMBOL:
B$=S$(Z%(A+1)):CALL ENV_GET
IF R3=0 THEN R=-1:ER=-1:E$="'"+B$+"' not found":GOTO EVAL_AST_RETURN
GOSUB INC_REF_R
GOTO EVAL_AST_RETURN

EVAL_AST_SEQ:
REM setup the stack for the loop
GOSUB MAP_LOOP_START

Expand Down Expand Up @@ -98,9 +85,23 @@ SUB EVAL
PRINT "EVAL: "+R$+" [A:"+STR$(A)+", LV:"+STR$(LV)+"]"
DEBUG_EVAL_DONE:

GOSUB LIST_Q
IF R THEN GOTO APPLY_LIST
GOSUB TYPE_A
T=T-4
IF 0<T THEN ON T GOTO EVAL_SYMBOL,APPLY_LIST,EVAL_VECTOR,EVAL_MAP

REM ELSE
R=A
GOSUB INC_REF_R
GOTO EVAL_RETURN

EVAL_SYMBOL:
B$=S$(Z%(A+1)):CALL ENV_GET
IF R3=0 THEN R=-1:ER=-1:E$="'"+B$+"' not found":GOTO EVAL_RETURN
GOSUB INC_REF_R
GOTO EVAL_RETURN

EVAL_MAP:
EVAL_VECTOR:
CALL EVAL_AST
GOTO EVAL_RETURN

Expand Down
33 changes: 17 additions & 16 deletions impls/basic/step4_if_fn_do.in.bas
Original file line number Diff line number Diff line change
Expand Up @@ -21,21 +21,8 @@ SUB EVAL_AST
IF ER<>-2 THEN GOTO EVAL_AST_RETURN

GOSUB TYPE_A
IF T=5 THEN GOTO EVAL_AST_SYMBOL
IF T>5 AND T<9 THEN GOTO EVAL_AST_SEQ
IF T<6 OR 8<T THEN R=-1:ER=-1:E$="EVAL_AST: bad type":GOTO EVAL_AST_RETURN

REM scalar: deref to actual value and inc ref cnt
R=A
GOSUB INC_REF_R
GOTO EVAL_AST_RETURN

EVAL_AST_SYMBOL:
B$=S$(Z%(A+1)):CALL ENV_GET
IF R3=0 THEN R=-1:ER=-1:E$="'"+B$+"' not found":GOTO EVAL_AST_RETURN
GOSUB INC_REF_R
GOTO EVAL_AST_RETURN

EVAL_AST_SEQ:
REM setup the stack for the loop
GOSUB MAP_LOOP_START

Expand Down Expand Up @@ -101,9 +88,23 @@ SUB EVAL
PRINT "EVAL: "+R$+" [A:"+STR$(A)+", LV:"+STR$(LV)+"]"
DEBUG_EVAL_DONE:

GOSUB LIST_Q
IF R THEN GOTO APPLY_LIST
GOSUB TYPE_A
T=T-4
IF 0<T THEN ON T GOTO EVAL_SYMBOL,APPLY_LIST,EVAL_VECTOR,EVAL_MAP

REM ELSE
R=A
GOSUB INC_REF_R
GOTO EVAL_RETURN

EVAL_SYMBOL:
B$=S$(Z%(A+1)):CALL ENV_GET
IF R3=0 THEN R=-1:ER=-1:E$="'"+B$+"' not found":GOTO EVAL_RETURN
GOSUB INC_REF_R
GOTO EVAL_RETURN

EVAL_MAP:
EVAL_VECTOR:
CALL EVAL_AST
GOTO EVAL_RETURN

Expand Down
33 changes: 17 additions & 16 deletions impls/basic/step5_tco.in.bas
Original file line number Diff line number Diff line change
Expand Up @@ -21,21 +21,8 @@ SUB EVAL_AST
IF ER<>-2 THEN GOTO EVAL_AST_RETURN

GOSUB TYPE_A
IF T=5 THEN GOTO EVAL_AST_SYMBOL
IF T>5 AND T<9 THEN GOTO EVAL_AST_SEQ
IF T<6 OR 8<T THEN R=-1:ER=-1:E$="EVAL_AST: bad type":GOTO EVAL_AST_RETURN

REM scalar: deref to actual value and inc ref cnt
R=A
GOSUB INC_REF_R
GOTO EVAL_AST_RETURN

EVAL_AST_SYMBOL:
B$=S$(Z%(A+1)):CALL ENV_GET
IF R3=0 THEN R=-1:ER=-1:E$="'"+B$+"' not found":GOTO EVAL_AST_RETURN
GOSUB INC_REF_R
GOTO EVAL_AST_RETURN

EVAL_AST_SEQ:
REM setup the stack for the loop
GOSUB MAP_LOOP_START

Expand Down Expand Up @@ -107,9 +94,23 @@ SUB EVAL
PRINT "EVAL: "+R$+" [A:"+STR$(A)+", LV:"+STR$(LV)+"]"
DEBUG_EVAL_DONE:

GOSUB LIST_Q
IF R THEN GOTO APPLY_LIST
GOSUB TYPE_A
T=T-4
IF 0<T THEN ON T GOTO EVAL_SYMBOL,APPLY_LIST,EVAL_VECTOR,EVAL_MAP

REM ELSE
R=A
GOSUB INC_REF_R
GOTO EVAL_RETURN

EVAL_SYMBOL:
B$=S$(Z%(A+1)):CALL ENV_GET
IF R3=0 THEN R=-1:ER=-1:E$="'"+B$+"' not found":GOTO EVAL_RETURN
GOSUB INC_REF_R
GOTO EVAL_RETURN

EVAL_MAP:
EVAL_VECTOR:
CALL EVAL_AST
GOTO EVAL_RETURN

Expand Down
33 changes: 17 additions & 16 deletions impls/basic/step6_file.in.bas
Original file line number Diff line number Diff line change
Expand Up @@ -21,21 +21,8 @@ SUB EVAL_AST
IF ER<>-2 THEN GOTO EVAL_AST_RETURN

GOSUB TYPE_A
IF T=5 THEN GOTO EVAL_AST_SYMBOL
IF T>5 AND T<9 THEN GOTO EVAL_AST_SEQ
IF T<6 OR 8<T THEN R=-1:ER=-1:E$="EVAL_AST: bad type":GOTO EVAL_AST_RETURN

REM scalar: deref to actual value and inc ref cnt
R=A
GOSUB INC_REF_R
GOTO EVAL_AST_RETURN

EVAL_AST_SYMBOL:
B$=S$(Z%(A+1)):CALL ENV_GET
IF R3=0 THEN R=-1:ER=-1:E$="'"+B$+"' not found":GOTO EVAL_AST_RETURN
GOSUB INC_REF_R
GOTO EVAL_AST_RETURN

EVAL_AST_SEQ:
REM setup the stack for the loop
GOSUB MAP_LOOP_START

Expand Down Expand Up @@ -107,9 +94,23 @@ SUB EVAL
PRINT "EVAL: "+R$+" [A:"+STR$(A)+", LV:"+STR$(LV)+"]"
DEBUG_EVAL_DONE:

GOSUB LIST_Q
IF R THEN GOTO APPLY_LIST
GOSUB TYPE_A
T=T-4
IF 0<T THEN ON T GOTO EVAL_SYMBOL,APPLY_LIST,EVAL_VECTOR,EVAL_MAP

REM ELSE
R=A
GOSUB INC_REF_R
GOTO EVAL_RETURN

EVAL_SYMBOL:
B$=S$(Z%(A+1)):CALL ENV_GET
IF R3=0 THEN R=-1:ER=-1:E$="'"+B$+"' not found":GOTO EVAL_RETURN
GOSUB INC_REF_R
GOTO EVAL_RETURN

EVAL_MAP:
EVAL_VECTOR:
CALL EVAL_AST
GOTO EVAL_RETURN

Expand Down
33 changes: 17 additions & 16 deletions impls/basic/step7_quote.in.bas
Original file line number Diff line number Diff line change
Expand Up @@ -132,21 +132,8 @@ SUB EVAL_AST
IF ER<>-2 THEN GOTO EVAL_AST_RETURN

GOSUB TYPE_A
IF T=5 THEN GOTO EVAL_AST_SYMBOL
IF T>5 AND T<9 THEN GOTO EVAL_AST_SEQ
IF T<6 OR 8<T THEN R=-1:ER=-1:E$="EVAL_AST: bad type":GOTO EVAL_AST_RETURN

REM scalar: deref to actual value and inc ref cnt
R=A
GOSUB INC_REF_R
GOTO EVAL_AST_RETURN

EVAL_AST_SYMBOL:
B$=S$(Z%(A+1)):CALL ENV_GET
IF R3=0 THEN R=-1:ER=-1:E$="'"+B$+"' not found":GOTO EVAL_AST_RETURN
GOSUB INC_REF_R
GOTO EVAL_AST_RETURN

EVAL_AST_SEQ:
REM setup the stack for the loop
GOSUB MAP_LOOP_START

Expand Down Expand Up @@ -218,9 +205,23 @@ SUB EVAL
PRINT "EVAL: "+R$+" [A:"+STR$(A)+", LV:"+STR$(LV)+"]"
DEBUG_EVAL_DONE:

GOSUB LIST_Q
IF R THEN GOTO APPLY_LIST
GOSUB TYPE_A
T=T-4
IF 0<T THEN ON T GOTO EVAL_SYMBOL,APPLY_LIST,EVAL_VECTOR,EVAL_MAP

REM ELSE
R=A
GOSUB INC_REF_R
GOTO EVAL_RETURN

EVAL_SYMBOL:
B$=S$(Z%(A+1)):CALL ENV_GET
IF R3=0 THEN R=-1:ER=-1:E$="'"+B$+"' not found":GOTO EVAL_RETURN
GOSUB INC_REF_R
GOTO EVAL_RETURN

EVAL_MAP:
EVAL_VECTOR:
CALL EVAL_AST
GOTO EVAL_RETURN

Expand Down
36 changes: 19 additions & 17 deletions impls/basic/step8_macros.in.bas
Original file line number Diff line number Diff line change
Expand Up @@ -167,21 +167,8 @@ SUB EVAL_AST
IF ER<>-2 THEN GOTO EVAL_AST_RETURN

GOSUB TYPE_A
IF T=5 THEN GOTO EVAL_AST_SYMBOL
IF T>5 AND T<9 THEN GOTO EVAL_AST_SEQ
IF T<6 OR 8<T THEN R=-1:ER=-1:E$="EVAL_AST: bad type":GOTO EVAL_AST_RETURN

REM scalar: deref to actual value and inc ref cnt
R=A
GOSUB INC_REF_R
GOTO EVAL_AST_RETURN

EVAL_AST_SYMBOL:
B$=S$(Z%(A+1)):CALL ENV_GET
IF R3=0 THEN R=-1:ER=-1:E$="'"+B$+"' not found":GOTO EVAL_AST_RETURN
GOSUB INC_REF_R
GOTO EVAL_AST_RETURN

EVAL_AST_SEQ:
REM setup the stack for the loop
GOSUB MAP_LOOP_START

Expand Down Expand Up @@ -247,16 +234,31 @@ SUB EVAL

IF ER<>-2 THEN GOTO EVAL_RETURN

EVAL_NOT_LIST:

B$="DEBUG-EVAL":CALL ENV_GET
IF R3=0 OR R=0 OR R=2 THEN GOTO DEBUG_EVAL_DONE
AZ=A:B=1:GOSUB PR_STR
PRINT "EVAL: "+R$+" [A:"+STR$(A)+", LV:"+STR$(LV)+"]"
DEBUG_EVAL_DONE:

GOSUB LIST_Q
IF R THEN GOTO APPLY_LIST
EVAL_NOT_LIST:
GOSUB TYPE_A
T=T-4
IF 0<T THEN ON T GOTO EVAL_SYMBOL,APPLY_LIST,EVAL_VECTOR,EVAL_MAP

REM ELSE
R=A
GOSUB INC_REF_R
GOTO EVAL_RETURN

EVAL_SYMBOL:
B$=S$(Z%(A+1)):CALL ENV_GET
IF R3=0 THEN R=-1:ER=-1:E$="'"+B$+"' not found":GOTO EVAL_RETURN
GOSUB INC_REF_R
GOTO EVAL_RETURN

EVAL_MAP:
EVAL_VECTOR:
CALL EVAL_AST
GOTO EVAL_RETURN

Expand Down
Loading

0 comments on commit 8833932

Please sign in to comment.