Summary
Make parameter (and shared) declarations carry element type and size so indexing is in elements by default, removing error-prone 4 * / CELLS patterns for narrow types.
Motivation
demo/attention.forth must use byte addressing for f32 globals:
2 PICK HEAD_DIM * I + 4 * Q + F32@
while f64 shared uses CELLS. Mixing F32@ (4-byte) with cell-oriented mental models is a footgun and obscures algorithms.
Proposed model
\! param Q f32[32768]
\! param SCALE f64
\! shared SCORES f64[1024]
Using Q pushes a typed base; indexing words scale by element size:
| Word / form |
Behavior |
i Q []@ or Q I @ |
load element i of Q with correct width/address space |
x i Q []! |
store element |
Or keep Q I CELLS + @ but define CELLS relative to the pointer’s element type |
|
Minimum viable improvement:
- Allow
f32 / i32 / f16 / … in \! param / \! shared (not only i64/f64 storage with separate access words).
- Document that addresses are byte addresses always, or introduce element-pointer types — pick one model and stick to it.
- Provide
[]@ / []! (or typed @) that scale correctly.
Acceptance criteria
Related
Summary
Make parameter (and shared) declarations carry element type and size so indexing is in elements by default, removing error-prone
4 */CELLSpatterns for narrow types.Motivation
demo/attention.forthmust use byte addressing for f32 globals:while f64 shared uses
CELLS. MixingF32@(4-byte) with cell-oriented mental models is a footgun and obscures algorithms.Proposed model
Using
Qpushes a typed base; indexing words scale by element size:i Q []@orQ I @iof Q with correct width/address spacex i Q []!Q I CELLS + @but defineCELLSrelative to the pointer’s element typeMinimum viable improvement:
f32/i32/f16/ … in\! param/\! shared(not only i64/f64 storage with separate access words).[]@/[]!(or typed@) that scale correctly.Acceptance criteria
4 *for f32F32@/I32@/CELLSwords (compat policy)Related
@vsS@(Proposal: split global vs shared memory words (@/! and S@/S!) #36 closed)