Chez parity: deftype (P. args) constructor via host-new var fallback (jolt-cf1q.7)

deftype binds the type name as a VAR (the make-deftype-ctor closure), but (P. 5)
lowers to (host-new "P"), which only checked class-ctors-tbl -> "No constructor".
Fall back to resolving the class name as a var in the current ns / clojure.core
and invoking it — so (P. args) constructs the same jrec as the ->P factory, and
protocol method dispatch (.m / .-field) over it works.

zero-Janet 2685->2688 (no-constructor 5->2); prelude floor bumped to 2641 (the
delay batch's run). Self-host + Janet gates + JVM cert green.

jolt-cf1q.7
This commit is contained in:
Yogthos 2026-06-20 17:36:54 -04:00
parent 1d6e740668
commit 60b4bae105
3 changed files with 17 additions and 6 deletions

View file

@ -94,8 +94,18 @@
(define (host-new class . args)
(let ((ctor (lookup-class class-ctors-tbl class)))
(if ctor (apply ctor args)
(error #f (string-append "No constructor for class " class)))))
(cond
(ctor (apply ctor args))
;; deftype/defrecord (jolt-499t): the type name is bound as a VAR (the
;; make-deftype-ctor closure) in its defining ns, not a registered host class.
;; Resolve it in the current ns / clojure.core and invoke it — so (P. args)
;; works the same as the ->P factory.
(else
(let ((cell (or (var-cell-lookup (chez-current-ns) class)
(var-cell-lookup "clojure.core" class))))
(if (and cell (var-cell-defined? cell) (procedure? (var-cell-root cell)))
(apply (var-cell-root cell) args)
(error #f (string-append "No constructor for class " class))))))))
;; ---- coercion helpers -------------------------------------------------------
(define (->num x) (exact->inexact x))