Compile data readers that return code forms
A registered #tag data reader whose fn returns a FORM (borkdude/html's #html expands to (->Html (str …))) was rewritten to a runtime call (reader-fn 'inner), so the returned code became a runtime list value instead of being compiled — (str #html [:div]) rendered the code, not "<div>". Clojure applies a data reader at read time and substitutes its result as code. loader.ss now applies the reader at load time: a code form (a list) is spliced in to be compiled, a value (time-literals #time/date -> a Date) keeps the runtime call, which also keeps a non-serializable constant out of an AOT build. The build emit path never applied data readers at all (a #tag literal failed a `jolt build` with "unsupported form"); emit-image.ss gets an ei-emit-form-hook the build sets to the same rewrite, left as a no-op elsewhere so the seed mint (which doesn't load loader.ss) is unaffected and the self-host byte-fixpoint holds. Also make clojure.test report the actual values of a failing (is (= a b)) — it printed only the form. Restricted to the common pure predicates so a macro head still takes the plain path. Fixture test/chez/datareader-app + a smoke check (interpreted) and a build-smoke check (AOT). make test green, no corpus change.
This commit is contained in:
parent
1008e922d8
commit
908ad63caa
10 changed files with 88 additions and 8 deletions
|
|
@ -102,6 +102,12 @@
|
|||
(clojure.test/do-report {:type :error :message ~msg :form '~form
|
||||
:actual (clojure.test/err-text e#)}))))
|
||||
|
||||
;; The common pure predicates whose args `is` evaluates so a failure shows the
|
||||
;; actual values — (is (= expected got)) prints `got`, not just the form. A macro
|
||||
;; head (not in this set) keeps the plain form-only path.
|
||||
(def ^:private reported-preds
|
||||
'#{= not= == < > <= >= identical? contains? instance? nil? some? empty? even? odd? pos? neg? zero?})
|
||||
|
||||
;; --- class matching for thrown? --------------------------------------------
|
||||
|
||||
(defn- last-seg [s]
|
||||
|
|
@ -173,6 +179,18 @@
|
|||
(contains? (methods clojure.test/assert-expr) (first form)))
|
||||
(clojure.test/assert-expr msg form)
|
||||
|
||||
;; a predicate call — (= a b), (< x y), (pred? v): evaluate the args so a
|
||||
;; failure shows the actual values, like clojure.test's assert-predicate.
|
||||
(and (seq? form) (contains? clojure.test/reported-preds (first form)))
|
||||
`(try
|
||||
(let [vs# (list ~@(rest form))]
|
||||
(if (apply ~(first form) vs#)
|
||||
(clojure.test/inc-pass!)
|
||||
(clojure.test/fail! (str (pr-str (list '~'not (cons '~(first form) vs#)))
|
||||
(when ~msg (str " — " ~msg))))))
|
||||
(catch Throwable e#
|
||||
(clojure.test/err! (str (pr-str '~form) " threw: " (clojure.test/err-text e#)))))
|
||||
|
||||
:else
|
||||
`(try
|
||||
(if ~form
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue