Interesting table!

9 views
Skip to first unread message

The Beez

unread,
Jan 18, 2026, 10:40:55 AMJan 18
to 4tH-compiler
Hi 4tH-ers!

I was contemplating which places on the stack were "prime real estate" and which positions were less attractive. So, I decided on four prime actions:

  1. Copy the value to TOS,
  2. Move the value to TOS;
  3. Move the value from TOS to this position;
  4. Delete this value.
I only allowed, the primary actions, that is - things like TUCK, NIP, PLUCK, -ROT were translated to DUP, SWAP, ROT, >R, R@ and R>.

Obviously, TOS was the most advantageous position, penalty "2". Second best were 2OS and TORS, with a penalty of "5". 3OS was still better than 2OS.

In 4tH, TORS is better than 2OS, if only slightly. Other Return stack positions move up slightly, however, copying is absolutely better in every regard. This confirms that R/O values are doing just fine on the Return stack, but only TORS is acceptable to update.

So if we are analyzing our programs before implementing them, this is the order to assign values:

Most active, most used: 1. TOS, 2. 2OS, 3. TORS;
Infrequently used: 3OS
Rarely used: 2ORS

Exclusively 4tH: use 2ORS and 3ORS for R/O values.

I might do the same thing for double values (double words, strings) - but that's of later concern. In the meanwhile, I think this is a great way to lay out your stack usage.

Hans Bezemer
PenaltyForth.png
Reply all
Reply to author
Forward
0 new messages