diff --git a/impls/basic/step0_repl.in.bas b/impls/basic/step0_repl.in.bas index a7c3e74b2b..aae8a06383 100755 --- a/impls/basic/step0_repl.in.bas +++ b/impls/basic/step0_repl.in.bas @@ -1,38 +1,34 @@ GOTO MAIN +REM $INCLUDE: 'mem.in.bas' REM $INCLUDE: 'readline.in.bas' REM $INCLUDE: 'debug.in.bas' -REM READ(A$) -> R$ -MAL_READ: - R$=A$ - RETURN +REM READ is inlined in RE -REM EVAL(A$, E) -> R$ -EVAL: +REM EVAL(A$) -> R$ +SUB EVAL R$=A$ - RETURN +END SUB -REM PRINT(A$) -> R$ -MAL_PRINT: - R$=A$ - RETURN +REM PRINT is inlined in REP REM REP(A$) -> R$ -REP: - GOSUB MAL_READ - A=R:GOSUB EVAL - A=R:GOSUB MAL_PRINT - RETURN +SUB REP + REM inlined READ (not affecting A$) + CALL EVAL + REM inlined PRINT (not affecting A$) +END SUB REM MAIN program MAIN: REPL_LOOP: A$="user> ":GOSUB READLINE: REM call input parser IF EZ=1 THEN GOTO QUIT + IF R$="" THEN GOTO REPL_LOOP - A$=R$:GOSUB REP: REM call REP + A$=R$:CALL REP PRINT R$ GOTO REPL_LOOP @@ -41,4 +37,3 @@ MAIN: REM GOSUB PR_MEMORY_SUMMARY_SMALL #cbm END #qbasic SYSTEM - diff --git a/impls/basic/step1_read_print.in.bas b/impls/basic/step1_read_print.in.bas index aa0c45f310..ca9ba1f90a 100755 --- a/impls/basic/step1_read_print.in.bas +++ b/impls/basic/step1_read_print.in.bas @@ -8,34 +8,41 @@ REM $INCLUDE: 'printer.in.bas' REM $INCLUDE: 'debug.in.bas' -REM READ(A$) -> R -MAL_READ: - GOSUB READ_STR - RETURN +REM READ is inlined in RE -REM EVAL(A, E) -> R +REM EVAL(A) -> R SUB EVAL R=A END SUB -REM PRINT(A) -> R$ -MAL_PRINT: - AZ=A:B=1:GOSUB PR_STR - RETURN +REM PRINT is inlined in REP + +REM RE(A$) -> R +REM caller must release result +RE: + R1=-1 + GOSUB READ_STR: REM inlined READ + R1=R + IF ER<>-2 THEN GOTO RE_DONE + + A=R:CALL EVAL + + RE_DONE: + RETURN: REM caller must release result of EVAL REM REP(A$) -> R$ SUB REP - GOSUB MAL_READ - IF ER<>-2 THEN GOTO REP_DONE + R2=-1 - A=R:CALL EVAL + GOSUB RE + R2=R IF ER<>-2 THEN GOTO REP_DONE - A=R:GOSUB MAL_PRINT + AZ=R:B=1:GOSUB PR_STR: REM inlined PRINT REP_DONE: REM Release memory from EVAL - AY=R:GOSUB RELEASE + AY=R2:GOSUB RELEASE END SUB REM MAIN program @@ -49,7 +56,7 @@ MAIN: IF EZ=1 THEN GOTO QUIT IF R$="" THEN GOTO REPL_LOOP - A$=R$:CALL REP: REM call REP + A$=R$:CALL REP IF ER<>-2 THEN GOSUB PRINT_ERROR:GOTO REPL_LOOP PRINT R$ @@ -57,6 +64,10 @@ MAIN: QUIT: REM GOSUB PR_MEMORY_SUMMARY_SMALL + REM GOSUB PR_MEMORY_MAP + REM P1=0:P2=ZI:GOSUB PR_MEMORY + REM P1=D:GOSUB PR_OBJECT + REM P1=ZK:GOSUB PR_OBJECT #cbm END #qbasic SYSTEM @@ -64,4 +75,3 @@ MAIN: PRINT "Error: "+E$ ER=-2:E$="" RETURN - diff --git a/impls/basic/step2_eval.in.bas b/impls/basic/step2_eval.in.bas index b7fa00ec51..53fd4a4942 100755 --- a/impls/basic/step2_eval.in.bas +++ b/impls/basic/step2_eval.in.bas @@ -12,8 +12,7 @@ REM READ is inlined in RE REM EVAL_AST(A, E) -> R SUB EVAL_AST - REM push A and E on the stack - Q=E:GOSUB PUSH_Q + REM push A on the stack GOSUB PUSH_A IF ER<>-2 THEN GOTO EVAL_AST_RETURN @@ -46,7 +45,6 @@ SUB EVAL_AST REM release it below) IF T=8 THEN N=M:M=Z%(A+2):Z%(M)=Z%(M)+32 - REM update the return sequence structure REM release N (and M if T=8) since seq takes full ownership C=1:GOSUB MAP_LOOP_UPDATE @@ -61,17 +59,15 @@ SUB EVAL_AST GOTO EVAL_AST_RETURN EVAL_AST_RETURN: - REM pop A and E off the stack + REM pop A off the stack GOSUB POP_A - GOSUB POP_Q:E=Q END SUB REM EVAL(A, E) -> R SUB EVAL LV=LV+1: REM track basic return stack level - REM push A and E on the stack - Q=E:GOSUB PUSH_Q + REM push A on the stack GOSUB PUSH_A REM PRINT "EVAL A:"+STR$(A)+",X:"+STR$(X)+",LV:"+STR$(LV)+",FRE:"+STR$(FRE(0)) @@ -117,8 +113,6 @@ SUB EVAL F=Z%(R+2) GOSUB TYPE_F - - REM ON .. GOTO here reduces the diff with later steps. T=T-8 IF 0 R$ +REM RE(A$) -> R REM Assume D has repl_env -SUB REP +REM caller must release result +RE: R1=-1 - GOSUB READ_STR: REM inlined MAL_READ + GOSUB READ_STR: REM inlined READ R1=R - IF ER<>-2 THEN GOTO REP_DONE + IF ER<>-2 THEN GOTO RE_DONE A=R:E=D:CALL EVAL + + RE_DONE: + REM Release memory from READ + AY=R1:GOSUB RELEASE + RETURN: REM caller must release result of EVAL + +REM REP(A$) -> R$ +REM Assume D has repl_env +SUB REP + R2=-1 + + GOSUB RE R2=R IF ER<>-2 THEN GOTO REP_DONE - AZ=R:B=1:GOSUB PR_STR: REM MAL_PRINT + AZ=R:B=1:GOSUB PR_STR: REM inlined PRINT REP_DONE: - REM Release memory from MAL_READ and EVAL + REM Release memory from EVAL AY=R2:GOSUB RELEASE - AY=R1:GOSUB RELEASE END SUB REM MAIN program @@ -244,7 +244,7 @@ MAIN: IF EZ=1 THEN GOTO QUIT IF R$="" THEN GOTO REPL_LOOP - A$=R$:CALL REP: REM call REP + A$=R$:CALL REP IF ER<>-2 THEN GOSUB PRINT_ERROR:GOTO REPL_LOOP PRINT R$ @@ -263,4 +263,3 @@ MAIN: PRINT "Error: "+E$ ER=-2:E$="" RETURN - diff --git a/impls/basic/step3_env.in.bas b/impls/basic/step3_env.in.bas index 2e48973071..e89209be67 100755 --- a/impls/basic/step3_env.in.bas +++ b/impls/basic/step3_env.in.bas @@ -47,7 +47,6 @@ SUB EVAL_AST REM release it below) IF T=8 THEN N=M:M=Z%(A+2):Z%(M)=Z%(M)+32 - REM update the return sequence structure REM release N (and M if T=8) since seq takes full ownership C=1:GOSUB MAP_LOOP_UPDATE @@ -183,8 +182,6 @@ SUB EVAL F=Z%(R+2) GOSUB TYPE_F - - REM ON .. GOTO here reduces the diff with later steps. T=T-8 IF 0Q THEN AY=E:GOSUB RELEASE - LV=LV-1: REM track basic return stack level REM release everything we couldn't release earlier @@ -257,24 +250,36 @@ DO_FUNCTION: REM PRINT is inlined in REP -REM REP(A$) -> R$ +REM RE(A$) -> R REM Assume D has repl_env -SUB REP +REM caller must release result +RE: R1=-1 - GOSUB READ_STR: REM inlined MAL_READ + GOSUB READ_STR: REM inlined READ R1=R - IF ER<>-2 THEN GOTO REP_DONE + IF ER<>-2 THEN GOTO RE_DONE A=R:E=D:CALL EVAL + + RE_DONE: + REM Release memory from READ + AY=R1:GOSUB RELEASE + RETURN: REM caller must release result of EVAL + +REM REP(A$) -> R$ +REM Assume D has repl_env +SUB REP + R2=-1 + + GOSUB RE R2=R IF ER<>-2 THEN GOTO REP_DONE - AZ=R:B=1:GOSUB PR_STR: REM MAL_PRINT + AZ=R:B=1:GOSUB PR_STR: REM inlined PRINT REP_DONE: - REM Release memory from MAL_READ and EVAL + REM Release memory from EVAL AY=R2:GOSUB RELEASE - AY=R1:GOSUB RELEASE END SUB REM MAIN program @@ -285,8 +290,8 @@ MAIN: REM create repl_env C=0:GOSUB ENV_NEW:D=R - E=D + REM + function T=9:L=1:GOSUB ALLOC: REM native function B$="+":C=R:GOSUB ENV_SET_S @@ -310,7 +315,7 @@ MAIN: IF EZ=1 THEN GOTO QUIT IF R$="" THEN GOTO REPL_LOOP - A$=R$:CALL REP: REM call REP + A$=R$:CALL REP IF ER<>-2 THEN GOSUB PRINT_ERROR:GOTO REPL_LOOP PRINT R$ @@ -329,4 +334,3 @@ MAIN: PRINT "Error: "+E$ ER=-2:E$="" RETURN - diff --git a/impls/basic/step4_if_fn_do.in.bas b/impls/basic/step4_if_fn_do.in.bas index 7f257c1e73..d37898116d 100755 --- a/impls/basic/step4_if_fn_do.in.bas +++ b/impls/basic/step4_if_fn_do.in.bas @@ -48,7 +48,6 @@ SUB EVAL_AST REM release it below) IF T=8 THEN N=M:M=Z%(A+2):Z%(M)=Z%(M)+32 - REM update the return sequence structure REM release N (and M if T=8) since seq takes full ownership C=1:GOSUB MAP_LOOP_UPDATE @@ -225,10 +224,7 @@ SUB EVAL AR=Z%(R+1): REM rest F=Z%(R+2) - REM if metadata, get the actual object GOSUB TYPE_F - IF T=14 THEN F=Z%(F+1):GOSUB TYPE_F - T=T-8 IF 0 R REM Assume D has repl_env REM caller must release result RE: R1=-1 - GOSUB READ_STR: REM inlined MAL_READ + GOSUB READ_STR: REM inlined READ R1=R IF ER<>-2 THEN GOTO RE_DONE A=R:E=D:CALL EVAL RE_DONE: - REM Release memory from MAL_READ + REM Release memory from READ AY=R1:GOSUB RELEASE RETURN: REM caller must release result of EVAL @@ -325,10 +320,10 @@ SUB REP R2=R IF ER<>-2 THEN GOTO REP_DONE - AZ=R:B=1:GOSUB PR_STR: REM MAL_PRINT + AZ=R:B=1:GOSUB PR_STR: REM inlined PRINT REP_DONE: - REM Release memory from MAL_READ and EVAL + REM Release memory from EVAL AY=R2:GOSUB RELEASE END SUB @@ -355,7 +350,7 @@ MAIN: IF EZ=1 THEN GOTO QUIT IF R$="" THEN GOTO REPL_LOOP - A$=R$:CALL REP: REM call REP + A$=R$:CALL REP IF ER<>-2 THEN GOSUB PRINT_ERROR:GOTO REPL_LOOP PRINT R$ @@ -374,4 +369,3 @@ MAIN: PRINT "Error: "+E$ ER=-2:E$="" RETURN - diff --git a/impls/basic/step5_tco.in.bas b/impls/basic/step5_tco.in.bas index 23adb7c25e..bf56efcf3e 100755 --- a/impls/basic/step5_tco.in.bas +++ b/impls/basic/step5_tco.in.bas @@ -54,7 +54,6 @@ SUB EVAL_AST REM release it below) IF T=8 THEN N=M:M=Z%(A+2):Z%(M)=Z%(M)+32 - REM update the return sequence structure REM release N (and M if T=8) since seq takes full ownership C=1:GOSUB MAP_LOOP_UPDATE @@ -249,10 +248,7 @@ SUB EVAL AR=Z%(R+1): REM rest F=Z%(R+2) - REM if metadata, get the actual object GOSUB TYPE_F - IF T=14 THEN F=Z%(F+1):GOSUB TYPE_F - T=T-8 IF 0 R REM Assume D has repl_env REM caller must release result RE: R1=-1 - GOSUB READ_STR: REM inlined MAL_READ + GOSUB READ_STR: REM inlined READ R1=R IF ER<>-2 THEN GOTO RE_DONE A=R:E=D:CALL EVAL RE_DONE: - REM Release memory from MAL_READ + REM Release memory from READ AY=R1:GOSUB RELEASE RETURN: REM caller must release result of EVAL @@ -349,10 +344,10 @@ SUB REP R2=R IF ER<>-2 THEN GOTO REP_DONE - AZ=R:B=1:GOSUB PR_STR: REM MAL_PRINT + AZ=R:B=1:GOSUB PR_STR: REM inlined PRINT REP_DONE: - REM Release memory from MAL_READ and EVAL + REM Release memory from EVAL AY=R2:GOSUB RELEASE END SUB @@ -379,7 +374,7 @@ MAIN: IF EZ=1 THEN GOTO QUIT IF R$="" THEN GOTO REPL_LOOP - A$=R$:CALL REP: REM call REP + A$=R$:CALL REP IF ER<>-2 THEN GOSUB PRINT_ERROR:GOTO REPL_LOOP PRINT R$ @@ -398,4 +393,3 @@ MAIN: PRINT "Error: "+E$ ER=-2:E$="" RETURN - diff --git a/impls/basic/step6_file.in.bas b/impls/basic/step6_file.in.bas index 084b0b1f96..ac9c470c46 100755 --- a/impls/basic/step6_file.in.bas +++ b/impls/basic/step6_file.in.bas @@ -54,7 +54,6 @@ SUB EVAL_AST REM release it below) IF T=8 THEN N=M:M=Z%(A+2):Z%(M)=Z%(M)+32 - REM update the return sequence structure REM release N (and M if T=8) since seq takes full ownership C=1:GOSUB MAP_LOOP_UPDATE @@ -249,10 +248,7 @@ SUB EVAL AR=Z%(R+1): REM rest F=Z%(R+2) - REM if metadata, get the actual object GOSUB TYPE_F - IF T=14 THEN F=Z%(F+1):GOSUB TYPE_F - T=T-8 IF 0 R REM Assume D has repl_env REM caller must release result RE: R1=-1 - GOSUB READ_STR: REM inlined MAL_READ + GOSUB READ_STR: REM inlined READ R1=R IF ER<>-2 THEN GOTO RE_DONE A=R:E=D:CALL EVAL RE_DONE: - REM Release memory from MAL_READ + REM Release memory from READ AY=R1:GOSUB RELEASE RETURN: REM caller must release result of EVAL @@ -349,10 +344,10 @@ SUB REP R2=R IF ER<>-2 THEN GOTO REP_DONE - AZ=R:B=1:GOSUB PR_STR: REM MAL_PRINT + AZ=R:B=1:GOSUB PR_STR: REM inlined PRINT REP_DONE: - REM Release memory from MAL_READ and EVAL + REM Release memory from EVAL AY=R2:GOSUB RELEASE END SUB @@ -392,30 +387,28 @@ MAIN: GOSUB RE REM no arguments, start REPL loop - IF R<16 THEN GOTO REPL_LOOP - REM if there is an argument, then run it as a program - - RUN_PROG: - REM free up first arg because we get it again - AY=R:GOSUB RELEASE - REM run a single mal program and exit - A$="(load-file (first -*ARGS*-))" - GOSUB RE - IF ER<>-2 THEN GOSUB PRINT_ERROR - GOTO QUIT + IF 15-2 THEN GOSUB PRINT_ERROR:GOTO REPL_LOOP PRINT R$ GOTO REPL_LOOP + RUN_PROG: + REM free up first arg because we get it again + AY=R:GOSUB RELEASE + REM run a single mal program and exit + A$="(load-file (first -*ARGS*-))" + GOSUB RE + IF ER<>-2 THEN GOSUB PRINT_ERROR + QUIT: REM GOSUB PR_MEMORY_SUMMARY_SMALL REM GOSUB PR_MEMORY_MAP @@ -429,4 +422,3 @@ MAIN: PRINT "Error: "+E$ ER=-2:E$="" RETURN - diff --git a/impls/basic/step7_quote.in.bas b/impls/basic/step7_quote.in.bas index cfd968a656..8cf109a00b 100755 --- a/impls/basic/step7_quote.in.bas +++ b/impls/basic/step7_quote.in.bas @@ -122,7 +122,6 @@ SUB QQ_FOLDR QQ_FOLDR_DONE: END SUB - REM EVAL_AST(A, E) -> R SUB EVAL_AST REM push A and E on the stack @@ -165,7 +164,6 @@ SUB EVAL_AST REM release it below) IF T=8 THEN N=M:M=Z%(A+2):Z%(M)=Z%(M)+32 - REM update the return sequence structure REM release N (and M if T=8) since seq takes full ownership C=1:GOSUB MAP_LOOP_UPDATE @@ -377,10 +375,7 @@ SUB EVAL AR=Z%(R+1): REM rest F=Z%(R+2) - REM if metadata, get the actual object GOSUB TYPE_F - IF T=14 THEN F=Z%(F+1):GOSUB TYPE_F - T=T-8 IF 0 R REM Assume D has repl_env REM caller must release result RE: R1=-1 - GOSUB READ_STR: REM inlined MAL_READ + GOSUB READ_STR: REM inlined READ R1=R IF ER<>-2 THEN GOTO RE_DONE A=R:E=D:CALL EVAL RE_DONE: - REM Release memory from MAL_READ + REM Release memory from READ AY=R1:GOSUB RELEASE RETURN: REM caller must release result of EVAL @@ -477,10 +471,10 @@ SUB REP R2=R IF ER<>-2 THEN GOTO REP_DONE - AZ=R:B=1:GOSUB PR_STR: REM MAL_PRINT + AZ=R:B=1:GOSUB PR_STR: REM inlined PRINT REP_DONE: - REM Release memory from MAL_READ and EVAL + REM Release memory from EVAL AY=R2:GOSUB RELEASE END SUB @@ -520,30 +514,28 @@ MAIN: GOSUB RE REM no arguments, start REPL loop - IF R<16 THEN GOTO REPL_LOOP - REM if there is an argument, then run it as a program - - RUN_PROG: - REM free up first arg because we get it again - AY=R:GOSUB RELEASE - REM run a single mal program and exit - A$="(load-file (first -*ARGS*-))" - GOSUB RE - IF ER<>-2 THEN GOSUB PRINT_ERROR - GOTO QUIT + IF 15-2 THEN GOSUB PRINT_ERROR:GOTO REPL_LOOP PRINT R$ GOTO REPL_LOOP + RUN_PROG: + REM free up first arg because we get it again + AY=R:GOSUB RELEASE + REM run a single mal program and exit + A$="(load-file (first -*ARGS*-))" + GOSUB RE + IF ER<>-2 THEN GOSUB PRINT_ERROR + QUIT: REM GOSUB PR_MEMORY_SUMMARY_SMALL REM GOSUB PR_MEMORY_MAP @@ -557,4 +549,3 @@ MAIN: PRINT "Error: "+E$ ER=-2:E$="" RETURN - diff --git a/impls/basic/step8_macros.in.bas b/impls/basic/step8_macros.in.bas index 45917c9074..60be62305e 100755 --- a/impls/basic/step8_macros.in.bas +++ b/impls/basic/step8_macros.in.bas @@ -200,7 +200,6 @@ SUB EVAL_AST REM release it below) IF T=8 THEN N=M:M=Z%(A+2):Z%(M)=Z%(M)+32 - REM update the return sequence structure REM release N (and M if T=8) since seq takes full ownership C=1:GOSUB MAP_LOOP_UPDATE @@ -434,10 +433,7 @@ SUB EVAL AR=Z%(R+1): REM rest F=Z%(R+2) - REM if metadata, get the actual object GOSUB TYPE_F - IF T=14 THEN F=Z%(F+1):GOSUB TYPE_F - T=T-8 IF 0 R REM Assume D has repl_env REM caller must release result RE: R1=-1 - GOSUB READ_STR: REM inlined MAL_READ + GOSUB READ_STR: REM inlined READ R1=R IF ER<>-2 THEN GOTO RE_DONE A=R:E=D:CALL EVAL RE_DONE: - REM Release memory from MAL_READ + REM Release memory from READ AY=R1:GOSUB RELEASE RETURN: REM caller must release result of EVAL @@ -534,10 +529,10 @@ SUB REP R2=R IF ER<>-2 THEN GOTO REP_DONE - AZ=R:B=1:GOSUB PR_STR: REM MAL_PRINT + AZ=R:B=1:GOSUB PR_STR: REM inlined PRINT REP_DONE: - REM Release memory from MAL_READ and EVAL + REM Release memory from EVAL AY=R2:GOSUB RELEASE END SUB @@ -582,30 +577,28 @@ MAIN: GOSUB RE REM no arguments, start REPL loop - IF R<16 THEN GOTO REPL_LOOP - REM if there is an argument, then run it as a program - - RUN_PROG: - REM free up first arg because we get it again - AY=R:GOSUB RELEASE - REM run a single mal program and exit - A$="(load-file (first -*ARGS*-))" - GOSUB RE - IF ER<>-2 THEN GOSUB PRINT_ERROR - GOTO QUIT + IF 15-2 THEN GOSUB PRINT_ERROR:GOTO REPL_LOOP PRINT R$ GOTO REPL_LOOP + RUN_PROG: + REM free up first arg because we get it again + AY=R:GOSUB RELEASE + REM run a single mal program and exit + A$="(load-file (first -*ARGS*-))" + GOSUB RE + IF ER<>-2 THEN GOSUB PRINT_ERROR + QUIT: REM GOSUB PR_MEMORY_SUMMARY_SMALL REM GOSUB PR_MEMORY_MAP @@ -619,4 +612,3 @@ MAIN: PRINT "Error: "+E$ ER=-2:E$="" RETURN - diff --git a/impls/basic/step9_try.in.bas b/impls/basic/step9_try.in.bas index 895ef40a02..47cfc0a8b9 100755 --- a/impls/basic/step9_try.in.bas +++ b/impls/basic/step9_try.in.bas @@ -200,7 +200,6 @@ SUB EVAL_AST REM release it below) IF T=8 THEN N=M:M=Z%(A+2):Z%(M)=Z%(M)+32 - REM update the return sequence structure REM release N (and M if T=8) since seq takes full ownership C=1:GOSUB MAP_LOOP_UPDATE @@ -467,10 +466,7 @@ SUB EVAL AR=Z%(R+1): REM rest F=Z%(R+2) - REM if metadata, get the actual object GOSUB TYPE_F - IF T=14 THEN F=Z%(F+1):GOSUB TYPE_F - T=T-8 IF 0 R REM Assume D has repl_env REM caller must release result RE: R1=-1 - GOSUB READ_STR: REM inlined MAL_READ + GOSUB READ_STR: REM inlined READ R1=R IF ER<>-2 THEN GOTO RE_DONE A=R:E=D:CALL EVAL RE_DONE: - REM Release memory from MAL_READ + REM Release memory from READ AY=R1:GOSUB RELEASE RETURN: REM caller must release result of EVAL @@ -567,10 +562,10 @@ SUB REP R2=R IF ER<>-2 THEN GOTO REP_DONE - AZ=R:B=1:GOSUB PR_STR: REM MAL_PRINT + AZ=R:B=1:GOSUB PR_STR: REM inlined PRINT REP_DONE: - REM Release memory from MAL_READ and EVAL + REM Release memory from EVAL AY=R2:GOSUB RELEASE END SUB @@ -615,30 +610,28 @@ MAIN: GOSUB RE REM no arguments, start REPL loop - IF R<16 THEN GOTO REPL_LOOP - REM if there is an argument, then run it as a program - - RUN_PROG: - REM free up first arg because we get it again - AY=R:GOSUB RELEASE - REM run a single mal program and exit - A$="(load-file (first -*ARGS*-))" - GOSUB RE - IF ER<>-2 THEN GOSUB PRINT_ERROR - GOTO QUIT + IF 15-2 THEN GOSUB PRINT_ERROR:GOTO REPL_LOOP PRINT R$ GOTO REPL_LOOP + RUN_PROG: + REM free up first arg because we get it again + AY=R:GOSUB RELEASE + REM run a single mal program and exit + A$="(load-file (first -*ARGS*-))" + GOSUB RE + IF ER<>-2 THEN GOSUB PRINT_ERROR + QUIT: REM GOSUB PR_MEMORY_SUMMARY_SMALL REM GOSUB PR_MEMORY_MAP @@ -654,4 +647,3 @@ MAIN: PRINT "Error: "+E$ ER=-2:E$="" RETURN - diff --git a/impls/basic/stepA_mal.in.bas b/impls/basic/stepA_mal.in.bas index 375fc4d445..4d06608852 100755 --- a/impls/basic/stepA_mal.in.bas +++ b/impls/basic/stepA_mal.in.bas @@ -200,7 +200,6 @@ SUB EVAL_AST REM release it below) IF T=8 THEN N=M:M=Z%(A+2):Z%(M)=Z%(M)+32 - REM update the return sequence structure REM release N (and M if T=8) since seq takes full ownership C=1:GOSUB MAP_LOOP_UPDATE @@ -470,7 +469,6 @@ SUB EVAL REM if metadata, get the actual object GOSUB TYPE_F IF T=14 THEN F=Z%(F+1):GOSUB TYPE_F - T=T-8 IF 0 R REM Assume D has repl_env REM caller must release result RE: R1=-1 - GOSUB READ_STR: REM inlined MAL_READ + GOSUB READ_STR: REM inlined READ R1=R IF ER<>-2 THEN GOTO RE_DONE A=R:E=D:CALL EVAL RE_DONE: - REM Release memory from MAL_READ + REM Release memory from READ AY=R1:GOSUB RELEASE RETURN: REM caller must release result of EVAL @@ -567,10 +564,10 @@ SUB REP R2=R IF ER<>-2 THEN GOTO REP_DONE - AZ=R:B=1:GOSUB PR_STR: REM MAL_PRINT + AZ=R:B=1:GOSUB PR_STR: REM inlined PRINT REP_DONE: - REM Release memory from MAL_READ and EVAL + REM Release memory from EVAL AY=R2:GOSUB RELEASE END SUB @@ -619,36 +616,33 @@ MAIN: GOSUB RE REM no arguments, start REPL loop - IF R<16 THEN GOTO REPL - REM if there is an argument, then run it as a program + IF 15-2 THEN GOSUB PRINT_ERROR - GOTO QUIT - - REPL: - REM print the REPL startup header - REM save memory by printing this directly - #cbm PRINT "Mal [C64 BASIC]" - #qbasic PRINT "Mal [QBasic]" + REM print the REPL startup header + REM save memory by printing this directly + #cbm PRINT "Mal [C64 BASIC]" + #qbasic PRINT "Mal [QBasic]" REPL_LOOP: A$="user> ":GOSUB READLINE: REM call input parser IF EZ=1 THEN GOTO QUIT IF R$="" THEN GOTO REPL_LOOP - A$=R$:CALL REP: REM call REP + A$=R$:CALL REP IF ER<>-2 THEN GOSUB PRINT_ERROR:GOTO REPL_LOOP PRINT R$ GOTO REPL_LOOP + RUN_PROG: + REM free up first arg because we get it again + AY=R:GOSUB RELEASE + REM run a single mal program and exit + A$="(load-file (first -*ARGS*-))" + GOSUB RE + IF ER<>-2 THEN GOSUB PRINT_ERROR + QUIT: REM GOSUB PR_MEMORY_SUMMARY_SMALL REM GOSUB PR_MEMORY_MAP @@ -664,4 +658,3 @@ MAIN: PRINT "Error: "+E$ ER=-2:E$="" RETURN -