2016-09-05 04:42:50 +03:00
|
|
|
GOTO MAIN
|
|
|
|
|
2016-11-18 09:54:04 +03:00
|
|
|
REM $INCLUDE: 'mem.in.bas'
|
2016-09-05 04:42:50 +03:00
|
|
|
REM $INCLUDE: 'types.in.bas'
|
2016-11-05 05:46:45 +03:00
|
|
|
REM $INCLUDE: 'readline.in.bas'
|
2016-09-05 04:42:50 +03:00
|
|
|
REM $INCLUDE: 'reader.in.bas'
|
|
|
|
REM $INCLUDE: 'printer.in.bas'
|
|
|
|
|
2016-09-22 07:27:12 +03:00
|
|
|
REM $INCLUDE: 'debug.in.bas'
|
|
|
|
|
2016-10-15 06:42:56 +03:00
|
|
|
REM READ(A$) -> R
|
2016-09-05 04:42:50 +03:00
|
|
|
MAL_READ:
|
|
|
|
GOSUB READ_STR
|
|
|
|
RETURN
|
|
|
|
|
2016-10-15 06:42:56 +03:00
|
|
|
REM EVAL(A, E) -> R
|
2016-10-26 09:26:05 +03:00
|
|
|
SUB EVAL
|
2016-10-15 06:42:56 +03:00
|
|
|
R=A
|
2016-10-26 09:26:05 +03:00
|
|
|
END SUB
|
2016-09-05 04:42:50 +03:00
|
|
|
|
2016-10-15 06:42:56 +03:00
|
|
|
REM PRINT(A) -> R$
|
2016-09-05 04:42:50 +03:00
|
|
|
MAL_PRINT:
|
2016-11-04 08:07:09 +03:00
|
|
|
AZ=A:B=1:GOSUB PR_STR
|
2016-09-05 04:42:50 +03:00
|
|
|
RETURN
|
|
|
|
|
2016-09-11 06:13:27 +03:00
|
|
|
REM REP(A$) -> R$
|
2016-10-26 09:26:05 +03:00
|
|
|
SUB REP
|
2016-09-05 04:42:50 +03:00
|
|
|
GOSUB MAL_READ
|
2016-10-15 06:42:56 +03:00
|
|
|
IF ER<>-2 THEN GOTO REP_DONE
|
2016-09-20 05:23:21 +03:00
|
|
|
|
2016-10-26 09:26:05 +03:00
|
|
|
A=R:CALL EVAL
|
2016-10-15 06:42:56 +03:00
|
|
|
IF ER<>-2 THEN GOTO REP_DONE
|
2016-09-16 09:00:58 +03:00
|
|
|
|
2016-10-15 06:42:56 +03:00
|
|
|
A=R:GOSUB MAL_PRINT
|
2016-09-16 09:00:58 +03:00
|
|
|
|
2016-09-20 05:23:21 +03:00
|
|
|
REP_DONE:
|
|
|
|
REM Release memory from EVAL
|
2016-10-15 06:42:56 +03:00
|
|
|
AY=R:GOSUB RELEASE
|
2016-10-26 09:26:05 +03:00
|
|
|
END SUB
|
2016-09-05 04:42:50 +03:00
|
|
|
|
2016-09-11 06:13:27 +03:00
|
|
|
REM MAIN program
|
2016-09-05 04:42:50 +03:00
|
|
|
MAIN:
|
|
|
|
GOSUB INIT_MEMORY
|
2016-09-11 06:13:27 +03:00
|
|
|
|
2016-10-23 00:11:46 +03:00
|
|
|
ZT=ZI: REM top of memory after base repl_env
|
2016-09-16 09:00:58 +03:00
|
|
|
|
2016-09-20 05:23:21 +03:00
|
|
|
REPL_LOOP:
|
2016-09-24 06:36:17 +03:00
|
|
|
A$="user> ":GOSUB READLINE: REM call input parser
|
2016-10-31 03:15:24 +03:00
|
|
|
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
|
2016-09-20 05:23:21 +03:00
|
|
|
|
2016-10-26 09:26:05 +03:00
|
|
|
A$=R$:CALL REP: REM call REP
|
2016-09-05 04:42:50 +03:00
|
|
|
|
2016-10-15 06:42:56 +03:00
|
|
|
IF ER<>-2 THEN GOSUB PRINT_ERROR:GOTO REPL_LOOP
|
2016-09-20 05:23:21 +03:00
|
|
|
PRINT R$
|
|
|
|
GOTO REPL_LOOP
|
2016-09-05 04:42:50 +03:00
|
|
|
|
2016-09-20 05:23:21 +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
|
2017-09-15 07:50:15 +03:00
|
|
|
#cbm END
|
|
|
|
#qbasic SYSTEM
|
2016-09-11 06:13:27 +03:00
|
|
|
|
2016-09-20 05:23:21 +03:00
|
|
|
PRINT_ERROR:
|
2016-11-04 08:07:09 +03:00
|
|
|
PRINT "Error: "+E$
|
|
|
|
ER=-2:E$=""
|
2016-09-20 05:23:21 +03:00
|
|
|
RETURN
|
|
|
|
|