Chez Phase 2 (inc X): #inst / #uuid literals + java.time (jolt-at0a)

The analyzer lowers a #inst/#uuid tagged form to a :inst/:uuid IR leaf, mirroring
the existing :regex node: the Janet back end punts to the interpreter (its
data-readers parse the literal, so seed behavior is unchanged), the Chez back end
emits jolt-inst-from-string / jolt-uuid-from-string.

host/chez/inst-time.ss is the Chez-native value layer: a jinst record holding
epoch ms (RFC3339 parsed via Hinnant civil/days math, with Clojure's partial
defaults and +/-hh:mm offsets), wired into jolt-get (so the overlay inst?/inst-ms
read it), jolt= / jolt-hash (instant identity as a map key), pr-str (#inst
"...-00:00"), str, type, and instance? java.util.Date. The java.time surface
(DateTimeFormatter ofPattern/ISO_LOCAL_DATE_TIME/ofLocalized*, the pattern engine,
Instant, ZoneId, LocalDateTime, FormatStyle, Locale, Date) ports java_base.janet
over host-static.ss's registries.

Corpus 2202->2238, 0 new divergences; clears the whole 'unsupported form'
emit-fail bucket. Full Janet gate green (analyzer/backend changes are
behaviour-preserving — #inst still parses through the interpreter's data-readers
on the seed).
This commit is contained in:
Yogthos 2026-06-19 11:05:22 -04:00
parent 62e636e52c
commit c70f3bae34
10 changed files with 418 additions and 1 deletions

77
test/chez/_insttime.janet Normal file
View file

@ -0,0 +1,77 @@
# jolt-at0a (inc X) — #inst / #uuid literals + java.time formatting on Chez.
# #inst lowers (analyzer :inst node) to a jinst value (RFC3339 ms, partial
# defaults + offsets); #uuid to a juuid; the java.time shim (DateTimeFormatter/
# Instant/ZoneId/LocalDateTime/FormatStyle/Locale/Date) ports java_base.janet.
# Mirrors the :regex IR-leaf precedent: Janet back end punts to the interpreter's
# data-readers, Chez emits the runtime value (host/chez/inst-time.ss).
# Oracle = build/jolt.
#
# janet test/chez/_insttime.janet
(def jolt-bin (or (os/getenv "JOLT_BIN") "bin/jolt-chez"))
(def cases
[# --- #inst reading + identity ---
["(inst? #inst \"2020-01-01T00:00:00Z\")" "true"]
["(inst-ms #inst \"1970-01-01T00:00:01Z\")" "1000"]
["(inst-ms #inst \"1970-01-01T00:00:00.123Z\")" "123"]
["(inst-ms #inst \"2020-01-01T00:00:00Z\")" "1577836800000"]
["(inst-ms* #inst \"1970-01-01T00:00:00Z\")" "0"]
["(some? #inst \"2020-01-01T00:00:00Z\")" "true"]
["(str (type #inst \"2020-01-01T00:00:00Z\"))" ":jolt/inst"]
# --- partial timestamps + offsets (value equality by instant) ---
["(= #inst \"2020\" #inst \"2020-01-01T00:00:00.000Z\")" "true"]
["(= #inst \"2020-03\" #inst \"2020-03-01T00:00:00Z\")" "true"]
["(= #inst \"2020-03-15\" #inst \"2020-03-15T00:00:00Z\")" "true"]
["(= #inst \"2020-01-01T01:00:00+01:00\" #inst \"2020-01-01T00:00:00Z\")" "true"]
["(= #inst \"2019-12-31T23:00:00-01:00\" #inst \"2020-01-01T00:00:00Z\")" "true"]
["(= #inst \"2020-01-01T00:00:00Z\" #inst \"2020-01-01T00:00:01Z\")" "false"]
# --- map key + pr-str round trip ---
["(get {#inst \"2020-01-01T00:00:00Z\" :v} #inst \"2020-01-01T00:00:00.000Z\")" ":v"]
["(pr-str #inst \"2020-01-01T00:00:00Z\")" "#inst \"2020-01-01T00:00:00.000-00:00\""]
["(str #inst \"2020-01-01T00:00:00Z\")" "2020-01-01T00:00:00.000-00:00"]
# --- #uuid ---
["(uuid? #uuid \"550e8400-e29b-41d4-a716-446655440000\")" "true"]
["(= #uuid \"550E8400-E29B-41D4-A716-446655440000\" #uuid \"550e8400-e29b-41d4-a716-446655440000\")" "true"]
["(pr-str #uuid \"550e8400-e29b-41d4-a716-446655440000\")" "#uuid \"550e8400-e29b-41d4-a716-446655440000\""]
# --- java.util.Date / java.time.Instant interop ---
["(.getTime #inst \"1970-01-01T00:00:00Z\")" "0"]
["(instance? java.util.Date #inst \"2020-01-01T00:00:00Z\")" "true"]
["(instance? java.sql.Timestamp #inst \"2020-01-01T00:00:00Z\")" "false"]
["(.toEpochMilli (Instant/ofEpochMilli 1234))" "1234"]
["(instance? java.time.Instant (Instant/ofEpochMilli 0))" "true"]
["(> (.toEpochMilli (Instant/now)) 1500000000000)" "true"]
["(instance? LocalDateTime (-> #inst \"2020-03-05T13:45:30Z\" (.toInstant) (.atZone (ZoneId/systemDefault)) (.toLocalDateTime)))" "true"]
# --- DateTimeFormatter pattern engine ---
["(.format (DateTimeFormatter/ofPattern \"yyyy-MM-dd\") #inst \"2020-03-05T13:45:30Z\")" "2020-03-05"]
["(boolean (re-matches #\"[A-Z][a-z]{2} \\d{1,2}, 2020 \\d{1,2}:\\d{2} [AP]M\" (.format (DateTimeFormatter/ofPattern \"MMM d, yyyy h:mm a\") #inst \"2020-03-05T13:45:30Z\")))" "true"]
["(boolean (re-matches #\"\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}\" (.format DateTimeFormatter/ISO_LOCAL_DATE_TIME #inst \"2020-03-05T13:45:30Z\")))" "true"]
["(string? (.format (DateTimeFormatter/ofLocalizedDate FormatStyle/MEDIUM) #inst \"2020-03-05T13:45:30Z\"))" "true"]
["(string? (.format (.withLocale (DateTimeFormatter/ofPattern \"yyyy\") (java.util.Locale. \"en\")) #inst \"2020-01-01T00:00:00Z\"))" "true"]])
(defn run-capture [bin expr]
(def proc (os/spawn [bin "-e" expr] :p {:out :pipe :err :pipe}))
(def out (ev/read (proc :out) 0x100000))
(def err (ev/read (proc :err) 0x100000))
(def code (os/proc-wait proc))
(def lines (filter (fn [l] (not (empty? l)))
(string/split "\n" (string/trim (if out (string out) "")))))
[code (if (empty? lines) "" (last lines)) (string/trim (if err (string err) ""))])
(var pass 0)
(def fails @[])
(each [expr expected] cases
(def [ocode oracle _] (run-capture "build/jolt" expr))
(def [code got err] (run-capture jolt-bin expr))
(cond
(not= ocode 0) (array/push fails [expr (string "ORACLE FAILED exit " ocode)])
(not= oracle expected) (array/push fails [expr (string "ORACLE MISMATCH want `" expected "` got `" oracle "`")])
(not= code 0) (array/push fails [expr (string "exit " code "; err: " err)])
(= got expected) (++ pass)
(array/push fails [expr (string "want `" expected "`, got `" got "`")])))
(printf "\n_insttime parity [%s]: %d/%d passed" jolt-bin pass (length cases))
(when (> (length fails) 0)
(printf "%d FAIL(s):" (length fails))
(each [e m] fails (printf " FAIL %s\n %s" e m)))
(flush)
(os/exit (if (empty? fails) 0 1))

View file

@ -261,8 +261,16 @@
# (slurp/string/char[]/File), File .toURL/.toURI + a url jhost, slurp draining a
# StringReader, char-array, and with-open's __close seam over jhost readers + plain
# :close maps; all in host/chez/io.ss, no analyzer change) 2202.
# jolt-at0a inc X (#inst / #uuid literals + java.time formatting — the analyzer
# lowers a #inst/#uuid tagged form to a :inst/:uuid IR leaf (mirroring :regex):
# the Janet back end punts to the interpreter's data-readers, the Chez back end
# emits jolt-inst-from-string / jolt-uuid-from-string. host/chez/inst-time.ss is
# the jinst value (RFC3339 ms via Hinnant civil/days math, partial defaults +
# offsets, = / hash / pr-str / get-as-overlay-seam) plus the DateTimeFormatter
# pattern engine + Instant/ZoneId/LocalDateTime/FormatStyle/Locale/Date shims.
# This cleared the whole "unsupported form" emit-fail bucket) 2238.
# Strided runs scale down.
(def base-floor (scan-number (or (os/getenv "JOLT_CHEZ_PRELUDE_FLOOR") "2202")))
(def base-floor (scan-number (or (os/getenv "JOLT_CHEZ_PRELUDE_FLOOR") "2238")))
(def floor (if (os/getenv "JOLT_CORPUS_LIMIT") 0 base-floor))
(when (or (> (length diverged) 0) (< pass floor))
(printf "REGRESSION: pass %d < floor %d or %d new divergence(s)" pass floor (length diverged)))