1
1
mirror of https://github.com/kanaka/mal.git synced 2024-09-21 10:37:58 +03:00
mal/basic/step1_read_print.in.bas

68 lines
1.0 KiB
QBasic
Raw Normal View History

2016-09-05 04:42:50 +03:00
GOTO MAIN
REM $INCLUDE: 'mem.in.bas'
2016-09-05 04:42:50 +03:00
REM $INCLUDE: 'types.in.bas'
REM $INCLUDE: 'readline.in.bas'
2016-09-05 04:42:50 +03:00
REM $INCLUDE: 'reader.in.bas'
REM $INCLUDE: 'printer.in.bas'
REM $INCLUDE: 'debug.in.bas'
REM READ(A$) -> R
2016-09-05 04:42:50 +03:00
MAL_READ:
GOSUB READ_STR
RETURN
REM EVAL(A, E) -> R
SUB EVAL
R=A
END SUB
2016-09-05 04:42:50 +03:00
REM PRINT(A) -> R$
2016-09-05 04:42:50 +03:00
MAL_PRINT:
AZ=A:B=1:GOSUB PR_STR
2016-09-05 04:42:50 +03:00
RETURN
REM REP(A$) -> R$
SUB REP
2016-09-05 04:42:50 +03:00
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
2016-09-05 04:42:50 +03:00
REM MAIN program
2016-09-05 04:42:50 +03:00
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
Basic: refactor of hashmaps, map loops, remove derefs. - Alternate memory layout of hash-maps: Instead of hash-maps being an alternating sequence of keys and values, combine the key/values into a single entry. In other words, switch from this: 8 -> next Z% index (0 for last) 14 key/value (alternating) To this: 8 -> next Z% index (0 for last) key value This requires refactoring of the sequence reader, EVAL_AST and especially DO_HASHMAP and DO_KEY_VALS. So that leads to the next big refactoring: - Change mapping/lapping constructs to share code: Several pieces of mapping/looping code have a common structure, so this moves that common structure to types.in.bas: MAP_LOOP_START, MAP_LOOP_UPDATE, MAP_LOOP_DONE. Then use this code in: - EVAL_AST - READ_SEQ_* - DO_MAP - DO_HASH_MAP - DO_KEYS_VALS This also fixes the issue that several of these looping constructs were creating new empty sequence entries instead of using the common ones at the beginning of memory. - Remove the use of DEREF_*. This isn't actually needed because we no longer create structure that refer to multiple levels of type 14 references. Replace DEREF_* with VAL_* which gets the value of a particular sequence element i.e. Z%(A+1,1). All together, the above changes save over 300 bytes. Also: - Fix empty nil/false/true entries so they are treated the same as other types of data with regards to reference counting and ALLOC/RELEASE. - Add a new memory summary function in debug.in.bas that just prints out free, value count, and references for the early scalar and empty list elements. Comment out the larger one. This saves about 90 bytes.
2016-11-16 07:38:09 +03:00
IF R$="" THEN GOTO REPL_LOOP
A$=R$:CALL REP: REM call REP
2016-09-05 04:42:50 +03:00
IF ER<>-2 THEN GOSUB PRINT_ERROR:GOTO REPL_LOOP
PRINT R$
GOTO REPL_LOOP
2016-09-05 04:42:50 +03:00
QUIT:
Basic: refactor of hashmaps, map loops, remove derefs. - Alternate memory layout of hash-maps: Instead of hash-maps being an alternating sequence of keys and values, combine the key/values into a single entry. In other words, switch from this: 8 -> next Z% index (0 for last) 14 key/value (alternating) To this: 8 -> next Z% index (0 for last) key value This requires refactoring of the sequence reader, EVAL_AST and especially DO_HASHMAP and DO_KEY_VALS. So that leads to the next big refactoring: - Change mapping/lapping constructs to share code: Several pieces of mapping/looping code have a common structure, so this moves that common structure to types.in.bas: MAP_LOOP_START, MAP_LOOP_UPDATE, MAP_LOOP_DONE. Then use this code in: - EVAL_AST - READ_SEQ_* - DO_MAP - DO_HASH_MAP - DO_KEYS_VALS This also fixes the issue that several of these looping constructs were creating new empty sequence entries instead of using the common ones at the beginning of memory. - Remove the use of DEREF_*. This isn't actually needed because we no longer create structure that refer to multiple levels of type 14 references. Replace DEREF_* with VAL_* which gets the value of a particular sequence element i.e. Z%(A+1,1). All together, the above changes save over 300 bytes. Also: - Fix empty nil/false/true entries so they are treated the same as other types of data with regards to reference counting and ALLOC/RELEASE. - Add a new memory summary function in debug.in.bas that just prints out free, value count, and references for the early scalar and empty list elements. Comment out the larger one. This saves about 90 bytes.
2016-11-16 07:38:09 +03:00
REM GOSUB PR_MEMORY_SUMMARY_SMALL
#cbm END
#qbasic SYSTEM
PRINT_ERROR:
PRINT "Error: "+E$
ER=-2:E$=""
RETURN