Skip to content

Commit

Permalink
basic: merge eval_ast and macroexpand into EVAL
Browse files Browse the repository at this point in the history
  • Loading branch information
asarhaddon committed Nov 13, 2024
1 parent 972d561 commit 44503b5
Show file tree
Hide file tree
Showing 9 changed files with 240 additions and 328 deletions.
38 changes: 18 additions & 20 deletions impls/basic/step2_eval.in.bas
Original file line number Diff line number Diff line change
Expand Up @@ -12,28 +12,12 @@ REM READ is inlined in RE

REM EVAL_AST(A, E) -> R
SUB EVAL_AST
REM A must be a list, sequence or map

REM push A and E on the stack
Q=E:GOSUB PUSH_Q
GOSUB PUSH_A

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

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,13 +78,27 @@ 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
IF T=5 THEN GOTO EVAL_SYMBOL
IF T=6 THEN GOTO APPLY_LIST
IF T=7 OR T=8 THEN GOTO EVAL_MAP_VECTOR
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_VECTOR:
CALL EVAL_AST
GOTO EVAL_RETURN

APPLY_LIST:

GOSUB EMPTY_Q
IF R THEN R=A:GOSUB INC_REF_R:GOTO EVAL_RETURN

Expand Down
38 changes: 18 additions & 20 deletions impls/basic/step3_env.in.bas
Original file line number Diff line number Diff line change
Expand Up @@ -13,28 +13,12 @@ REM READ is inlined in RE

REM EVAL_AST(A, E) -> R
SUB EVAL_AST
REM A must be a list, sequence or map

REM push A and E on the stack
Q=E:GOSUB PUSH_Q
GOSUB PUSH_A

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

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,13 +82,27 @@ 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
IF T=5 THEN GOTO EVAL_SYMBOL
IF T=6 THEN GOTO APPLY_LIST
IF T=7 OR T=8 THEN GOTO EVAL_MAP_VECTOR
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_VECTOR:
CALL EVAL_AST
GOTO EVAL_RETURN

APPLY_LIST:

GOSUB EMPTY_Q
IF R THEN R=A:GOSUB INC_REF_R:GOTO EVAL_RETURN

Expand Down
38 changes: 18 additions & 20 deletions impls/basic/step4_if_fn_do.in.bas
Original file line number Diff line number Diff line change
Expand Up @@ -14,28 +14,12 @@ REM READ is inlined in RE

REM EVAL_AST(A, E) -> R
SUB EVAL_AST
REM A must be a list, sequence or map

REM push A and E on the stack
Q=E:GOSUB PUSH_Q
GOSUB PUSH_A

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

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,13 +85,27 @@ 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
IF T=5 THEN GOTO EVAL_SYMBOL
IF T=6 THEN GOTO APPLY_LIST
IF T=7 OR T=8 THEN GOTO EVAL_MAP_VECTOR
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_VECTOR:
CALL EVAL_AST
GOTO EVAL_RETURN

APPLY_LIST:

GOSUB EMPTY_Q
IF R THEN R=A:GOSUB INC_REF_R:GOTO EVAL_RETURN

Expand Down
38 changes: 18 additions & 20 deletions impls/basic/step5_tco.in.bas
Original file line number Diff line number Diff line change
Expand Up @@ -14,28 +14,12 @@ REM READ is inlined in RE

REM EVAL_AST(A, E) -> R
SUB EVAL_AST
REM A must be a list, sequence or map

REM push A and E on the stack
Q=E:GOSUB PUSH_Q
GOSUB PUSH_A

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

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,13 +91,27 @@ 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
IF T=5 THEN GOTO EVAL_SYMBOL
IF T=6 THEN GOTO APPLY_LIST
IF T=7 OR T=8 THEN GOTO EVAL_MAP_VECTOR
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_VECTOR:
CALL EVAL_AST
GOTO EVAL_RETURN

APPLY_LIST:

GOSUB EMPTY_Q
IF R THEN R=A:GOSUB INC_REF_R:GOTO EVAL_RETURN

Expand Down
38 changes: 18 additions & 20 deletions impls/basic/step6_file.in.bas
Original file line number Diff line number Diff line change
Expand Up @@ -14,28 +14,12 @@ REM READ is inlined in RE

REM EVAL_AST(A, E) -> R
SUB EVAL_AST
REM A must be a list, sequence or map

REM push A and E on the stack
Q=E:GOSUB PUSH_Q
GOSUB PUSH_A

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

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,13 +91,27 @@ 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
IF T=5 THEN GOTO EVAL_SYMBOL
IF T=6 THEN GOTO APPLY_LIST
IF T=7 OR T=8 THEN GOTO EVAL_MAP_VECTOR
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_VECTOR:
CALL EVAL_AST
GOTO EVAL_RETURN

APPLY_LIST:

GOSUB EMPTY_Q
IF R THEN R=A:GOSUB INC_REF_R:GOTO EVAL_RETURN

Expand Down
39 changes: 18 additions & 21 deletions impls/basic/step7_quote.in.bas
Original file line number Diff line number Diff line change
Expand Up @@ -124,31 +124,14 @@ SUB QQ_FOLDR
QQ_FOLDR_DONE:
END SUB


REM EVAL_AST(A, E) -> R
SUB EVAL_AST
REM A must be a list, sequence or map

REM push A and E on the stack
Q=E:GOSUB PUSH_Q
GOSUB PUSH_A

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

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 @@ -220,13 +203,27 @@ 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
IF T=5 THEN GOTO EVAL_SYMBOL
IF T=6 THEN GOTO APPLY_LIST
IF T=7 OR T=8 THEN GOTO EVAL_MAP_VECTOR
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_VECTOR:
CALL EVAL_AST
GOTO EVAL_RETURN

APPLY_LIST:

GOSUB EMPTY_Q
IF R THEN R=A:GOSUB INC_REF_R:GOTO EVAL_RETURN

Expand Down
Loading

0 comments on commit 44503b5

Please sign in to comment.