boot2

Playing with the boostrap
git clone https://git.ryansepassi.com/git/boot2.git
Log | Files | Refs | README

commit b3400673b940e51488715314374ef8cdc9ff3a41
parent 82c6a330b5de3aaeb5f7ec8aa79fa97f957e3d9d
Author: Ryan Sepassi <rsepassi@gmail.com>
Date:   Sat, 25 Apr 2026 14:30:22 -0700

scheme1: tests for string->symbol, symbol->string, bytevector-append

Adds tests/scheme1/65-string-symbol.scm covering both directions of
the symbol/bytevector bridge (intern round-trip, eq? canonicalization,
fresh-allocation guarantees from symbol->string) and
tests/scheme1/66-bytevector-append.scm covering 0-, 1-, 2-, and N-arg
forms plus empty-operand handling and result-vs-input independence.

Deletes tests/scheme1/34-bv-grow.scm in anticipation of dropping the
public bytevector-grow! primitive (the source-side removal lands
separately once parallel work merges).

Diffstat:
Dtests/scheme1/34-bv-grow.expected-exit | 1-
Dtests/scheme1/34-bv-grow.scm | 15---------------
Atests/scheme1/65-string-symbol.expected-exit | 1+
Atests/scheme1/65-string-symbol.scm | 35+++++++++++++++++++++++++++++++++++
Atests/scheme1/66-bytevector-append.expected-exit | 1+
Atests/scheme1/66-bytevector-append.scm | 38++++++++++++++++++++++++++++++++++++++
6 files changed, 75 insertions(+), 16 deletions(-)

diff --git a/tests/scheme1/34-bv-grow.expected-exit b/tests/scheme1/34-bv-grow.expected-exit @@ -1 +0,0 @@ -46 diff --git a/tests/scheme1/34-bv-grow.scm b/tests/scheme1/34-bv-grow.scm @@ -1,15 +0,0 @@ -; bytevector-grow! enlarges capacity in place; existing data must survive -; the alloc + copy. Length stays unchanged. -(define b (make-bytevector 5 0)) -(bytevector-u8-set! b 0 11) -(bytevector-u8-set! b 1 13) -(bytevector-u8-set! b 4 17) - -; Force growth past initial 16-byte capacity. -(bytevector-grow! b 100) - -; Length still 5; bytes still readable. -(sys-exit (+ (bytevector-length b) - (+ (+ (bytevector-u8-ref b 0) (bytevector-u8-ref b 1)) - (bytevector-u8-ref b 4)))) -; 5 + 11 + 13 + 17 = 46 diff --git a/tests/scheme1/65-string-symbol.expected-exit b/tests/scheme1/65-string-symbol.expected-exit @@ -0,0 +1 @@ +0 diff --git a/tests/scheme1/65-string-symbol.scm b/tests/scheme1/65-string-symbol.scm @@ -0,0 +1,35 @@ +; (string->symbol bv) and (symbol->string sym) -- bridge between the +; bytevector and symbol spaces. string->symbol interns into the global +; symtab; symbol->string returns a fresh bytevector copy of the name. + +; Round-trip a literal. +(define s (string->symbol "hello")) +(if (eq? s 'hello) 0 (sys-exit 1)) + +; Two interns of the same bytes give eq? symbols (interning, not just +; structural equality). +(if (eq? (string->symbol "abc") (string->symbol "abc")) 0 (sys-exit 2)) + +; Interning a literal matches a quoted symbol. +(if (eq? (string->symbol "foo") 'foo) 0 (sys-exit 3)) + +; symbol->string returns a bytevector with the right bytes. +(define name (symbol->string 'world)) +(if (string? name) 0 (sys-exit 4)) +(if (bytevector=? name "world") 0 (sys-exit 5)) + +; symbol->string returns a *fresh* bv: mutating it does not bleed back +; into the symtab (next conversion still gives "world"). +(bytevector-u8-set! name 0 88) ; 'X' +(if (bytevector=? (symbol->string 'world) "world") 0 (sys-exit 6)) + +; Round-trip both directions. +(if (eq? 'banana (string->symbol (symbol->string 'banana))) 0 (sys-exit 7)) +(if (bytevector=? "banana" + (symbol->string (string->symbol "banana"))) 0 (sys-exit 8)) + +; Empty bytevector interns to a single canonical empty-named symbol. +(if (eq? (string->symbol "") (string->symbol "")) 0 (sys-exit 9)) +(if (bytevector=? "" (symbol->string (string->symbol ""))) 0 (sys-exit 10)) + +(sys-exit 0) diff --git a/tests/scheme1/66-bytevector-append.expected-exit b/tests/scheme1/66-bytevector-append.expected-exit @@ -0,0 +1 @@ +0 diff --git a/tests/scheme1/66-bytevector-append.scm b/tests/scheme1/66-bytevector-append.scm @@ -0,0 +1,38 @@ +; (bytevector-append bv ...) -- variadic concatenation, returns a +; fresh bytevector. R7RS: zero-arg form is the empty bytevector. + +; Zero-arg form: empty bv. +(define z (bytevector-append)) +(if (string? z) 0 (sys-exit 1)) +(if (= (bytevector-length z) 0) 0 (sys-exit 2)) + +; One-arg form: equal contents but a fresh allocation. +(define a (bytevector-append "abc")) +(if (bytevector=? a "abc") 0 (sys-exit 3)) +(bytevector-u8-set! a 0 88) +(if (bytevector=? "abc" "abc") 0 (sys-exit 4)) ; literal untouched + +; Two-arg form: simple concat. +(if (bytevector=? "abcdef" (bytevector-append "abc" "def")) 0 (sys-exit 5)) + +; Three+ args. +(if (bytevector=? "abcdefghi" + (bytevector-append "abc" "def" "ghi")) 0 (sys-exit 6)) + +; Empty operands flush through. +(if (bytevector=? "abc" (bytevector-append "" "abc")) 0 (sys-exit 7)) +(if (bytevector=? "abc" (bytevector-append "abc" "")) 0 (sys-exit 8)) +(if (bytevector=? "abc" (bytevector-append "" "abc" "")) 0 (sys-exit 9)) +(if (bytevector=? "" (bytevector-append "" "" "")) 0 (sys-exit 10)) + +; Non-literal bytevectors (built via make-bytevector + set!). +(define p (make-bytevector 2 65)) ; "AA" +(define q (make-bytevector 3 66)) ; "BBB" +(if (bytevector=? "AABBB" (bytevector-append p q)) 0 (sys-exit 11)) + +; Result is independent: mutating the result doesn't affect the inputs. +(define r (bytevector-append p q)) +(bytevector-u8-set! r 0 90) +(if (= (bytevector-u8-ref p 0) 65) 0 (sys-exit 12)) + +(sys-exit 0)