Chez Phase 1 (increment 3p): misc seq/regex gaps + bug tracking

jolt-y1zq tail:
- 0-arg (conj) -> [] and 0-arg (conj!) -> a fresh transient vector
- nth sees through a transient (like get/count/contains?)
- irregex \p{...}/\P{...} property classes translate to the seed's ASCII char
  classes (regex.ss): \p{L} -> [a-zA-Z] + non-ASCII codepoints (the seed counts
  UTF-8 high bytes as letters), \p{N} -> [0-9], \p{Ps} -> [([{], etc. The
  translator tracks [...] nesting so a \p{} inside a class emits its content, not
  a nested class.

Two pre-existing bugs found and filed (tracked, not replicated):
- jolt-x0os: the Chez emitter mangles non-ASCII string literals into invalid Chez
  hex escapes (so p{L} utf-8 crashes on the input string, not the regex).
- jolt-ea9k: the seed's transient assoc! accepts odd args and assigns nil to the
  trailing key (non-Clojure; plain assoc throws). The Chez host throws
  (Clojure-correct); the 4 spec rows encoding the leniency are flagged in
  transients-spec.janet pending the seed fix.

Parity 1493 -> 1506/2497, 0 new divergences. emit-test 291/291.
This commit is contained in:
Yogthos 2026-06-18 00:44:21 -04:00
parent cbb0f2ab4a
commit e51cc2e47e
7 changed files with 131 additions and 12 deletions

View file

@ -202,11 +202,14 @@
(pmap-assoc coll (pvec-nth-d x 0 jolt-nil) (pvec-nth-d x 1 jolt-nil)))
(else (error 'conj "conj on a map expects a [k v] pair or a map"))))
(else (error 'conj "unsupported collection"))))
;; (conj nil a b ...) builds a list in Clojure, conj prepending -> (b a).
(define (jolt-conj coll . xs)
(if (jolt-nil? coll)
(fold-left jolt-conj1 jolt-empty-list xs)
(fold-left jolt-conj1 coll xs)))
;; (conj) -> []; (conj nil a b ...) builds a list (conj prepending -> (b a)).
(define (jolt-conj . args)
(if (null? args)
(jolt-vector)
(let ((coll (car args)) (xs (cdr args)))
(if (jolt-nil? coll)
(fold-left jolt-conj1 jolt-empty-list xs)
(fold-left jolt-conj1 coll xs)))))
(define jolt-get
(case-lambda

View file

@ -34,10 +34,67 @@
(apply %chez-error args)))
(load "vendor/irregex/irregex.scm")
;; Unicode property classes \p{...} (jolt-y1zq): irregex's string syntax has no
;; \p{...}, so translate the ones the seed's byte-PEG maps (src/jolt/regex.janet
;; prop-frag) to ASCII char classes before compiling. ASCII-only — the seed counts
;; UTF-8 high bytes as letters for \p{L}, which a Unicode-char Scheme string can't
;; reproduce byte-for-byte; the corpus tests ASCII inputs, where they agree. An
;; unmapped name is left as-is (irregex errors, as before — no new behavior). The
;; ORIGINAL source is kept for printing; only the compiled pattern is translated.
(define (prop-class name)
(cond
;; L/Alpha: ASCII letters + any non-ASCII codepoint (the seed counts UTF-8 high
;; bytes as letters, so ^\p{L}+$ accepts accented words). N/Z stay ASCII-only,
;; matching the seed's byte-PEG.
((or (string=? name "L") (string=? name "Alpha")) "a-zA-Z\\x80-\\x{10FFFF}")
((string=? name "Lu") "A-Z")
((string=? name "Ll") "a-z")
((or (string=? name "N") (string=? name "Nd") (string=? name "Digit")) "0-9")
((or (string=? name "Z") (string=? name "Zs")) " ")
((string=? name "Ps") "([{")
((string=? name "Pe") ")\\]}")
(else #f)))
;; Tracks whether the cursor is inside a [...] char class: a \p{X} there emits the
;; class CONTENT (the seed inlines it), standalone it emits a wrapping [X]. Escapes
;; (\[, \]) don't toggle the class. \P (negation) only wraps when standalone.
(define (translate-prop-classes src)
(let ((len (string-length src)) (out (open-output-string)))
(let loop ((i 0) (in-class #f))
(if (fx>=? i len)
(get-output-string out)
(let ((c (string-ref src i)))
(cond
;; \p{Name} / \P{Name}
((and (char=? c #\\) (fx<? (fx+ i 2) len)
(let ((p (string-ref src (fx+ i 1)))) (or (char=? p #\p) (char=? p #\P)))
(char=? (string-ref src (fx+ i 2)) #\{))
(let* ((close (let scan ((j (fx+ i 3)))
(cond ((fx>=? j len) #f)
((char=? (string-ref src j) #\}) j)
(else (scan (fx+ j 1))))))
(cls (and close (prop-class (substring src (fx+ i 3) close)))))
(cond
((not cls) (write-char c out) (loop (fx+ i 1) in-class))
(in-class (display cls out) (loop (fx+ close 1) in-class))
(else
(display "[" out)
(when (char=? (string-ref src (fx+ i 1)) #\P) (display "^" out))
(display cls out) (display "]" out)
(loop (fx+ close 1) in-class)))))
;; any other escape: copy the pair verbatim, don't toggle class state
((and (char=? c #\\) (fx<? (fx+ i 1) len))
(write-char c out) (write-char (string-ref src (fx+ i 1)) out)
(loop (fx+ i 2) in-class))
((and (not in-class) (char=? c #\[))
(write-char c out) (loop (fx+ i 1) #t))
((and in-class (char=? c #\]))
(write-char c out) (loop (fx+ i 1) #f))
(else (write-char c out) (loop (fx+ i 1) in-class))))))))
;; A jolt regex value: the source string (for printing / str) + the compiled
;; irregex. regex? recognizes it; the printer renders #"source".
(define-record-type regex-t (fields source irx) (nongenerative jolt-regex-v1))
(define (jolt-regex source) (make-regex-t source (irregex source)))
(define (jolt-regex source) (make-regex-t source (irregex (translate-prop-classes source))))
(define (jolt-regex? x) (regex-t? x))
(define (jolt-re-pattern x) (if (regex-t? x) x (jolt-regex x)))

View file

@ -23,10 +23,14 @@
(jolt-transient-active-set! t #f)
(jolt-transient-coll t))
(define (jolt-conj! t . xs)
(jolt-trans-check t "conj!")
(jolt-transient-coll-set! t (apply jolt-conj (jolt-transient-coll t) xs))
t)
;; (conj!) with no args -> a fresh transient vector (Clojure); otherwise mutate t.
(define (jolt-conj! . args)
(if (null? args)
(jolt-transient-new (jolt-vector))
(let ((t (car args)) (xs (cdr args)))
(jolt-trans-check t "conj!")
(jolt-transient-coll-set! t (apply jolt-conj (jolt-transient-coll t) xs))
t)))
;; (assoc! t k v & kvs): variadic like Clojure (jolt-assoc already folds pairs).
(define (jolt-assoc! t . kvs)
(jolt-trans-check t "assoc!")
@ -63,6 +67,11 @@
(set! jolt-count (lambda (coll) (%prev-jolt-count (jolt-deref-transient coll))))
(define %prev-jolt-contains? jolt-contains?)
(set! jolt-contains? (lambda (coll k) (%prev-jolt-contains? (jolt-deref-transient coll) k)))
(define %prev-jolt-nth jolt-nth)
(set! jolt-nth
(case-lambda
((coll i) (%prev-jolt-nth (jolt-deref-transient coll) i))
((coll i d) (%prev-jolt-nth (jolt-deref-transient coll) i d))))
(def-var! "clojure.core" "transient" jolt-transient-new)
(def-var! "clojure.core" "persistent!" jolt-persistent!)