RTL gaps — string/number conversion + a bit-set type (surfaced by the demos)
- Type: feature
- Status: done
- Owner: —
- Opened: 2026-06-19 (from the Sudoku + Prime-sieve demo apps)
- Closed: 2026-06-20
- Relation: sibling to feature-random-library and feature-writeln-as-library
— the reusable-RTL lane. The demo apps in
examples/are the motivating tests: written "platonically" (assume idiomatic RTL exists), so the missing routines below are the gaps the demos expose by design. Companion to feature-demo-sudoku.
Motivation
Two new platonic demo apps were written to exercise the surface, deliberately without workarounds:
examples/sudoku/sudoku_game.pas— interactive generator + line-oriented UI (desktop terminal / ESP32 serial). UsesValto parser c vmoves.examples/primes/sieve.pas— Sieve of Eratosthenes with hand bit-packing into anarray of Integer. UsesIntToStrto render primes.
They compile against an idiomatic RTL surface that does not yet exist. Rather than hand-roll the conversions in each app, capture the gap here.
Gap 1 — number/string conversion (a SysUtils/StrUtils slice)
Missing, both demos and essentially every real app want them:
IntToStr(n)/IntToStrfor the integer widthsVal(s, v, code)— standard parse with an error code (the FPC-compatible form)StrToInt(s)/StrToIntDef(s, def)- adjacent:
Trim,UpperCase/LowerCaselikely fall out of the same unit
FPC-compatible signatures so existing/Lazarus code is unaffected. Deterministic, integer-only core → byte-identical across all targets (good cross-target oracle).
Gap 2 — a bit-set / bit-array type (TBitArray-ish)
The sieve packs bits by hand (w := n div 32; bits[w] := bits[w] or (1 shl b)).
That is fine as a demo of raw shl/and/or codegen, but the reusable type is
wanted:
- dynamic, length-set bit vector over packed machine words
SetBit/ClearBit/TestBit,Count(popcount), iteration- the right primitive for sieves, candidate sets, presence maps
Naming/shape TBD (TBitArray vs a bitset unit) — decide when picked up. Watch
the set of 1..9-from-runtime-values gap noted in feature-demo-sudoku; a proper
bit-set type may be the pragmatic answer to that lane too.
Constraints
- Per memory: write our OWN units with FPC naming; do NOT port real FPC RTL/LCL. These libs get cleaner as the compiler gains features.
.pasunits, not.inc(per the .inc→units direction).- Must not regress the self-host fixedpoint or cross-bootstrap.
Acceptance
sudoku_game.pasandsieve.pascompile and run unmodified against the new units, byte-identical across x86-64 / i386 / aarch64 / arm32.- Conversion routines: scripted input → fixed output oracle in
make test. - Bit-set: a sieve built on the type matches the hand-packed sieve's prime count.
Log
-
2026-06-19 — Opened from the two demo apps. Gaps confirmed:
IntToStrandValreferenced by name in neither test nor lib (grepclean), i.e. not yet provided. Demos left platonic on purpose to drive this ticket. -
2026-06-20 — Gap 1 expanded (track B):
lib/rtl/sysutils.pasgainedFloatToStr,FloatToStrF,StrToFloatDef,StrToFloat,Pos,PadLeft,PadRight,Delete,Insert,Concat. Float conversion avoids theStrbuiltin (which breaks when sysutils's ownCopyshadows the compiler's intercept).Valstill absent (builtin name collision);StrToFloatDefis the replacement. -
2026-06-20 — Gap 2 landed (track B):
lib/rtl/bitset.passhipsTBitArraywithBitArrayInit,BitArraySetBit,BitArrayClearBit,BitArrayToggle,BitArrayTestBit,BitArrayCount,BitArrayNextSet. Uses 32-bit Integer words (Int64 bitwise ops —not,andon sign-bit values — are unreliable on the pinned stable).shron negative Integer is arithmetic (sign-extending), so NextSet uses direct bit-index scanning.BitArrayClearBitavoidsnotvia conditional subtraction. Tested intest/lib_bitset.paswith golden-output verification (make lib-test).Compiler gaps discovered:
noton Integer is boolean, not bitwise — cannot be used for mask complementshron negative Integer is arithmetic shift (sign-extending), not logical — breaks bit-scanning on words with bit 31 set- Int64
and/or/notare unreliable — 32-bit Integer is the safe word type for now ba.bits := nilon a managed record field throughvarparam segfaults
-
2026-06-20 — Both Gap 1 (SysUtils number/string conversion) and Gap 2 (bit-set library
TBitArray) have been fully implemented, tested, and verified green inlib-test(commit d83ab99). Demos sieve and sudoku compile and run successfully.