Chez parity: Java arrays + reader/macroexpand fns (jolt-cf1q.7)
host/chez/natives-array.ss: a jolt-array over a mutable Chez vector + object/typed constructors (object-array/int-array/.../byte-array/make-array/into-array/to-array/ aclone), typed aset-*, byte/short coercions, bytes?/bytes/ints/..., and eager chunk-buffer/chunk-* (Jolt doesn't chunk). count/nth/seq/get and jolt.host/ref-put! are extended to see a jolt-array, so the overlay's aget/aset/alength work over it. Numbers it produces are flonums (jolt's rep) so exactness-aware = holds. char-array stays in io.ss (a char-SEQ that io/reader/str/slurp consume). natives-parity.ss adds: __reader-features / -set!, reader-conditional, re-matcher, delay? (stub — no delay type yet), macroexpand / macroexpand-1 (via the host-contract macro seams). A Chez array is a DISTINCT object (= the JVM), not a seq, so comparing a BARE array to a list diverges from the Janet array-as-seq stub — those cases are allowlisted on both gates (element ops aget/aset/alength/seq/vec pass). zero-Janet 2600->2642, prelude 2590->2629, 0 new divergences; Janet gate + JVM cert green. jolt-cf1q.7
This commit is contained in:
parent
1ba19759c8
commit
ccab89e1d5
5 changed files with 205 additions and 6 deletions
|
|
@ -37,6 +37,48 @@
|
|||
(let loop ((xs (seq->list (jolt-seq (cadr a)))) (acc (car a)))
|
||||
(if (null? xs) acc (loop (cdr xs) (jolt-invoke rf acc (car xs)))))))))
|
||||
|
||||
;; --- reader feature set (for #?() conditionals) — mutable list of name strings,
|
||||
;; default jolt + default. __reader-features returns the strings; -set! replaces.
|
||||
(define np-reader-features (list "jolt" "default"))
|
||||
(define (np-reader-features-get) (list->cseq np-reader-features))
|
||||
(define (np-reader-features-set! names)
|
||||
(set! np-reader-features
|
||||
(map (lambda (n) (cond ((keyword-t? n) (keyword-t-name n)) ((string? n) n) (else (jolt-pr-str n))))
|
||||
(seq->list (jolt-seq names))))
|
||||
jolt-nil)
|
||||
|
||||
;; --- reader-conditional / re-matcher: tagged maps (reader-conditional? + the
|
||||
;; matcher consumers are overlay tagged-value predicates that read :jolt/type).
|
||||
(define np-kw-type (keyword "jolt" "type"))
|
||||
(define np-kw-rc (keyword "jolt" "reader-conditional"))
|
||||
(define np-kw-form (keyword #f "form"))
|
||||
(define np-kw-spl (keyword #f "splicing?"))
|
||||
(define np-kw-mat (keyword "jolt" "matcher"))
|
||||
(define np-kw-re (keyword #f "re"))
|
||||
(define np-kw-s (keyword #f "s"))
|
||||
(define np-kw-pos (keyword #f "pos"))
|
||||
(define (np-reader-conditional form splicing?)
|
||||
(jolt-hash-map np-kw-type np-kw-rc np-kw-form form np-kw-spl splicing?))
|
||||
(define (np-re-matcher re s)
|
||||
(jolt-hash-map np-kw-type np-kw-mat np-kw-re re np-kw-s s np-kw-pos 0.0))
|
||||
|
||||
;; --- delay? : no delay type is built on Chez yet, so always false (enough for
|
||||
;; (delay? x) on non-delays; revisit when delay/force land).
|
||||
(define (np-delay? x) #f)
|
||||
|
||||
;; --- macroexpand-1 / macroexpand: expand a (quoted) call form via the runtime
|
||||
;; macro table (host-contract hc-macro?/hc-expand-1; forward-referenced, resolved
|
||||
;; at call time after the spine loads). macroexpand loops until the head is no
|
||||
;; longer a macro (subforms are not expanded, matching Clojure).
|
||||
(define (np-macroexpand-1 form)
|
||||
(if (and (cseq? form) (cseq-list? form) (symbol-t? (seq-first form)))
|
||||
(let ((ctx (make-analyze-ctx (chez-current-ns))))
|
||||
(if (hc-macro? ctx (seq-first form)) (hc-expand-1 ctx form) form))
|
||||
form))
|
||||
(define (np-macroexpand form)
|
||||
(let loop ((cur form))
|
||||
(let ((nxt (np-macroexpand-1 cur))) (if (eq? cur nxt) cur (loop nxt)))))
|
||||
|
||||
(def-var! "clojure.core" "hash" np-hash)
|
||||
(def-var! "clojure.core" "hash-combine" np-hash-combine)
|
||||
(def-var! "clojure.core" "hash-ordered-coll" np-hash-ordered-coll)
|
||||
|
|
@ -44,3 +86,10 @@
|
|||
(def-var! "clojure.core" "transient?" np-transient?)
|
||||
(def-var! "clojure.core" "rseq" np-rseq)
|
||||
(def-var! "clojure.core" "cat" np-cat)
|
||||
(def-var! "clojure.core" "__reader-features" np-reader-features-get)
|
||||
(def-var! "clojure.core" "__reader-features-set!" np-reader-features-set!)
|
||||
(def-var! "clojure.core" "reader-conditional" np-reader-conditional)
|
||||
(def-var! "clojure.core" "re-matcher" np-re-matcher)
|
||||
(def-var! "clojure.core" "delay?" np-delay?)
|
||||
(def-var! "clojure.core" "macroexpand-1" np-macroexpand-1)
|
||||
(def-var! "clojure.core" "macroexpand" np-macroexpand)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue