Heap Strings & File I/O V19

Heap-Backed Dynamic Strings

V19 introduces genuine heap-managed dynamic string runtimes: pb_string64 (ANSI) and pb_wstring64 (UTF-16). Previous versions used fixed-length ASCIIZ stack buffers.

STRING64 Runtime (591 lines)

File: src/runtime/pb_string64.c, include/compiler/runtime/pb_string64.h
FunctionDescription
pb_str64_initAllocate and initialize STRING descriptor
pb_str64_assignAssign from C string
pb_str64_concatConcatenate multiple STRING operands
pb_str64_compareRelational comparison (<, =, >)
pb_str64_instrFind substring position
pb_str64_left/right/midSubstring extraction
pb_str64_trim/ucase/lcaseWhitespace/case operations
pb_str64_space/stringGenerate filled strings
pb_str64_remove/extractRemove substring / extract field
pb_str64_format_i64/_dNumeric formatting
UTF-8 conversionConvert from UTF-16LE to narrow UTF-8

WSTRING64 Runtime (388 lines)

File: src/runtime/pb_wstring64.c, include/compiler/runtime/pb_wstring64.h

Mirror API of STRING64 operating on uint16_t* (UTF-16 code units). Includes: init, assign, concat, compare, instr, left, right, mid, trim, ucase, lcase, space, string, remove, extract, parse, WCHR, ASCW, from_ascii, to_ascii, plus UTF-8/UTF-16LE conversion helpers.

OPEN FOR RANDOM / BINARY

Syntax: OPEN "file" FOR RANDOM AS #n LEN = recLen | OPEN "file" FOR BINARY AS #n

V19 adds full RANDOM and BINARY file modes. Both open handles for simultaneous read+write using the Win32 file pipeline.

RANDOM Mode

' Open random-access file with 128-byte records
OPEN "data.dat" FOR RANDOM AS #1 LEN = 128

' Write record 5
PUT #1, 5, myRecord

' Read record 3
GET #1, 3, myRecord

' Query position
PRINT LOC(1)     ' record number (RANDOM mode)
PRINT SEEK(1)    ' 1-based byte position

' Seek to record
SEEK #1, 10

BINARY Mode

OPEN "data.bin" FOR BINARY AS #2
GET #2, 100, value     ' read at byte offset 100
PUT #2, 200, value     ' write at byte offset 200
SEEK #2, 50            ' seek to byte 50
PRINT LOC(2)           ' byte position (BINARY mode)

Scalar Size Hardening

Numeric GET/PUT now uses the packed scalar byte size instead of always 8 bytes. UDTs with dynamic STRING/WSTRING fields are rejected with a diagnostic in BINARY/RANDOM mode.

Encoding-Aware LINE INPUT for STRING

Syntax: LINE INPUT #n, s$ with encoding-aware files

V19 adds UTF-16LE-to-narrow conversion: LINE INPUT from UTF16LE/UTF16LE_BOM files now reads UTF-16 code units and converts to UTF-8-compatible heap strings for STRING targets.

OPEN "unicode.txt" FOR INPUT ENCODING UTF16LE_BOM AS #1
LINE INPUT #1, s$     ' reads UTF-16LE, converts to STRING
CLOSE #1