1
1
mirror of https://github.com/kanaka/mal.git synced 2024-09-20 01:57:09 +03:00
mal/basic/step1_read_print.in.bas
Joel Martin d7a6c2d6c9 Basic: refactor memory layout.
Use a one dimensional array for the Z% value array. This enables
lists, vectors, environments and metadata pointers to all save off
1 word (2 bytes) of space.

Split the memory init and functions into mem.in.bas.

In addition, change type 14 to be metdata rather than any type 16-31.

This change saves about 560 bytes (no second array dimension
subscripts) and reduces Z% value usage by 10%-15%.

Bump the number of Z% words by 200 (to 8591). This enables
self-hosting up to step7 (without step8-stepA functions in core.mal).
2016-11-18 01:26:23 -06:00

67 lines
1.0 KiB
QBasic
Executable File

GOTO MAIN
REM $INCLUDE: 'mem.in.bas'
REM $INCLUDE: 'types.in.bas'
REM $INCLUDE: 'readline.in.bas'
REM $INCLUDE: 'reader.in.bas'
REM $INCLUDE: 'printer.in.bas'
REM $INCLUDE: 'debug.in.bas'
REM READ(A$) -> R
MAL_READ:
GOSUB READ_STR
RETURN
REM EVAL(A, E) -> R
SUB EVAL
R=A
END SUB
REM PRINT(A) -> R$
MAL_PRINT:
AZ=A:B=1:GOSUB PR_STR
RETURN
REM REP(A$) -> R$
SUB REP
GOSUB MAL_READ
IF ER<>-2 THEN GOTO REP_DONE
A=R:CALL EVAL
IF ER<>-2 THEN GOTO REP_DONE
A=R:GOSUB MAL_PRINT
REP_DONE:
REM Release memory from EVAL
AY=R:GOSUB RELEASE
END SUB
REM MAIN program
MAIN:
GOSUB INIT_MEMORY
ZT=ZI: REM top of memory after base repl_env
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
IF ER<>-2 THEN GOSUB PRINT_ERROR:GOTO REPL_LOOP
PRINT R$
GOTO REPL_LOOP
QUIT:
REM GOSUB PR_MEMORY_SUMMARY_SMALL
END
PRINT_ERROR:
PRINT "Error: "+E$
ER=-2:E$=""
RETURN