Skip to content

Comments

Allocate RAM for RAM words in dictionary space#43

Open
mkobetic wants to merge 2 commits intomainfrom
ram-dict
Open

Allocate RAM for RAM words in dictionary space#43
mkobetic wants to merge 2 commits intomainfrom
ram-dict

Conversation

@mkobetic
Copy link
Owner

@mkobetic mkobetic commented Feb 18, 2026

The gist of this PR is to disentangle RAM dictionary words from RAM pool, and leave RAM pool purely for FLASH dictionary words. To do that we need to allocate RAM space in the RAM dictionary space when compiling RAM words (variables, values, defers). This means that the mode of allocation when these types of words are compiled needs to change based on MEMMODE.

The heart of the implementation hijacks the RAMPLUSPLUS word, changes its semantics to be MEMMODE dependent and changes all the call sites (variable, value, defer) to use the word in a new way. The pre-existing RAMHERE and RAMPLUS words are removed as unused and hard to use correctly in this new world.

Similarly the semantics of here, align and allot are changed to reflect the RAM strategy based on MEMMODE as well.

This makes the RAM mode act like standard RAM based Forth (with RAM and dictionary allocated in the same memory space) and FLASH mode act like embedded Forth (with RAM and dictionary allocated in separate spaces).

The tester fix that used vallot explicitly had to reverted back to allot as well, for tests to run correctly.

Second commit changes the search order when switching between RAM and FLASH modes to control word visibility. It essentially hides the ram-wordlist when in FLASH mode. This should help preventing compilation of flash words that depend on RAM words (caveat: if people start messing with wordlists and search orders this might be too constraining, but we can cross that bridge when we get there).
It also changes words to show all visible words based on the search order rather than just the forth-wordlist.

Outstanding issues

  1. runtime defined values and defers are different from compile time (ITC) defined equivalents, in that they don't have default values, getters, setters embedded in the instance words. This may not be that much of an issue for RAM words, since they don't exist at boot time. But words compiled into flash persist so this is likely an issue there, when the init-ram process tries to initialize these words.

.word XT_CELL
.word XT_VALLOT
.word XT_EXIT
NONAME RAMHEREPLUSPLUS /* ( x -- ) allocate 1 cell in RAM, store x in it, compile the address into the dictionary */
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had to pull the XT_COMMA in here, because it needs to happen differently based on the MEMMODE. It would be good to come up with better word name, but it should probably be a NONAME as it is very specialized, internal word now.

.word XT_REVEAL
.word XT_COMPILE
.word PFA_DODEFER
.word XT_RAMHEREPLUSPLUS
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

RAMHEREPLUSPLUS now does the job of those removed words internally.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant