Basic: refactor of hashmaps, map loops, remove derefs.
authorJoel Martin <github@martintribe.org>
Wed, 16 Nov 2016 04:38:09 +0000 (22:38 -0600)
committerJoel Martin <github@martintribe.org>
Wed, 16 Nov 2016 05:00:57 +0000 (23:00 -0600)
commit9d59cdb3849ae1c8832b3ff502ed2b36e6a68099
tree20861b545a1c85dfedb6c7291e6d37a8356715a3
parent4cbca5940174ac1f2ec8e253bb86d2048a09b4b4
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.
19 files changed:
basic/Makefile
basic/core.in.bas
basic/debug.in.bas
basic/env.in.bas
basic/printer.in.bas
basic/reader.in.bas
basic/step0_repl.in.bas
basic/step1_read_print.in.bas
basic/step2_eval.in.bas
basic/step3_env.in.bas
basic/step4_if_fn_do.in.bas
basic/step5_tco.in.bas
basic/step6_file.in.bas
basic/step7_quote.in.bas
basic/step8_macros.in.bas
basic/step9_try.in.bas
basic/stepA_mal.in.bas
basic/types.in.bas
basic/variables.txt