forth: String word set COMPARE/SEARCH/SLITERAL (+9)
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Has been cancelled

This commit is contained in:
2026-04-25 02:53:46 +00:00
parent 64af162b5d
commit 1b2935828c
6 changed files with 134 additions and 3 deletions

View File

@@ -94,7 +94,7 @@ Representation:
- [x] Source/state: `EVALUATE`, `STATE`, `[`, `]` (`SOURCE`/`>IN` stubbed; tokenized input means the exact byte/offset semantics aren't useful here)
- [x] Misc Core: `WITHIN`, `MAX`/`MIN` (already), `ABORT`, `ABORT"`, `EXIT`, `UNLOOP`
- [x] File Access word set (in-memory — `read-file` is not reachable from the epoch eval env)
- [ ] String word set (`SLITERAL`, `COMPARE`, `SEARCH`)
- [x] String word set (`SLITERAL`, `COMPARE`, `SEARCH`)
- [ ] Target: 100% Hayes Core
### Phase 6 — speed
@@ -106,6 +106,17 @@ Representation:
_Newest first._
- **Phase 5 — String word set `COMPARE`/`SEARCH`/`SLITERAL` (+9).**
`COMPARE` walks bytes via the new `forth-compare-bytes-loop`,
returning -1/0/1 with standard prefix semantics (shorter string
compares less than its extension). `SEARCH` scans the haystack
with a helper `forth-search-bytes` and `forth-match-at`, returning
the tail after the first match or the original string with flag=0.
Empty needle returns at offset 0 with flag=-1 per ANS. `SLITERAL`
is IMMEDIATE: pops `(c-addr u)` at compile time, copies the bytes
into a fresh allocation, and emits the two pushes so the compiled
word yields the interned string at runtime.
- **Phase 5 — File Access word set (in-memory backing; +4).**
`OPEN-FILE`/`CREATE-FILE`/`CLOSE-FILE`/`READ-FILE`/`WRITE-FILE`/
`FILE-POSITION`/`FILE-SIZE`/`REPOSITION-FILE`/`DELETE-FILE` plus