Skip to content

strings: Str.find and Str.runWhile - #105

Closed
vic wants to merge 1 commit into
mainfrom
l1-scan
Closed

vic wants to merge 1 commit into
mainfrom
l1-scan

Conversation

@vic

@vic vic commented Nov 13, 2026

Copy link
Copy Markdown
Owner

Two string scans for lexers (bead vic-de9x.27; snx lexer port, which costs +5.4% instructions against its C lexer today).

  • Str.find(s, i, c): the first index >= i whose byte is c, else Str.len(s) (one memchr).
  • Str.runWhile(s, i, n, t): the first index >= i whose byte b is not in the run table t (b >= n or t(b) == 0), else Str.len(s) (one loop over raw bytes, no per-byte bound check).
  • Both are total (i clamped) and pure, and are emitted as static inline C only in a program that calls them.

Evidence:

  • Gate: EXIT=0, 881 ok, 0 FAIL.
  • prog/str_scan checks both against plain byte loops on 2000 pseudo-random strings and edge starts: 0 disagreements. Mutant (runWhile returns one past the stop): 1379 disagreements.
  • s2c compiling itself: 5.000 G instructions before and after (3 interleaved runs each).
  • 13 programs that do not call them emit the same C as main.
  • The --mem goldens change only by the new externs' params and the prelude line shift.

… run table), total and pure, emitted as static inline C only when called: a lexer's skip-while-in-class loop is one call with no per-byte bound check. Programs without them emit the same C; s2c self-compile instructions unchanged (5.000 G). Test prog/str_scan checks both against plain byte loops on 2000 pseudo-random cases
@vic vic closed this Nov 17, 2026
@vic
vic deleted the l1-scan branch November 17, 2026 16:47
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