Chez Phase 2 (inc R): . / .-field dot-form desugar (jolt-kuic)
The analyzer lowers the `.` special form (. target member arg*) and the
.-field field-access head to a :host-call instead of leaving them
uncompilable. Janet behaviour is unchanged — its back end punts :host-call
to the interpreter, which re-runs the original `.` form via eval-dot.
The Chez back end routes a non-shimmed :host-call through
record-method-dispatch, extended by a new host/chez/dot-forms.ss with the
arms dispatch-member covers but the record/string base did not, mirroring
src/jolt/interop/collections.janet precedence:
- collection interop first (count/seq/nth/get/valAt/containsKey on a
vector/map/set), so (. {:count 9} count) is the entry count like the seed
- field access for a "-name" member (records and maps)
- the seed's universal object-methods (getMessage/getCause/toString/
hashCode/equals) on a non-record map, winning over a field lookup
- non-record map member: a stored fn is a method called with self, else
the field value
Raw seqs are excluded from coll interop — the seed's behaviour there is
representation-dependent (plain (seq v) vs a lazy-seq) and a normalized cseq
can't mirror it. Also added getMessage/getLocalizedMessage/equals to the
string method surface so a thrown string / Exception. ctor (which keeps the
message string) answers .getMessage.
Parity 2134 -> 2150, 0 new divergences. New test/chez/_dotform.janet 26/26;
emit-test 331/331.
This commit is contained in:
parent
c90c4cb610
commit
1f96351acb
8 changed files with 224 additions and 2 deletions
|
|
@ -308,6 +308,38 @@
|
|||
(defn- analyze-ctor [ctx class args env]
|
||||
(host-new class (mapv #(analyze ctx % env) args)))
|
||||
|
||||
;; The `.` special form: `(. target member arg*)` — member access / method call.
|
||||
;; A symbol member whose name starts with "-" is a field read; otherwise it is a
|
||||
;; method (call with the trailing args). Both lower to a :host-call carrying the
|
||||
;; member name verbatim (the leading "-" survives so the runtime dispatcher reads
|
||||
;; it as a field). The Janet back end punts :host-call to the interpreter, which
|
||||
;; re-runs the original `.` form via eval-dot — so Janet behavior is unchanged;
|
||||
;; the Chez back end dispatches it through record-method-dispatch (jolt-kuic).
|
||||
;; A non-symbol member (e.g. a keyword) stays punted — the interpreter handles it.
|
||||
(defn- analyze-dot [ctx items env]
|
||||
(when (< (count items) 3)
|
||||
(throw (str "Malformed (. target member ...) form")))
|
||||
(let [member (nth items 2)]
|
||||
(if (form-sym? member)
|
||||
{:op :host-call
|
||||
:method (form-sym-name member)
|
||||
:target (analyze ctx (nth items 1) env)
|
||||
:args (mapv #(analyze ctx % env) (drop 3 items))}
|
||||
(uncompilable "special form . (non-symbol member)"))))
|
||||
|
||||
;; A `.-field` head: `(.-field target)` is field access. Lowers to a :host-call
|
||||
;; with the "-field" method (the dash signals field access to the dispatcher).
|
||||
(defn- field-head? [nm]
|
||||
(and (> (count nm) 2) (= ".-" (subs nm 0 2))))
|
||||
|
||||
(defn- analyze-field [ctx hname items env]
|
||||
(when (< (count items) 2)
|
||||
(throw (str "Malformed (.-field target) form")))
|
||||
{:op :host-call
|
||||
:method (subs hname 1) ; ".-field" -> "-field"
|
||||
:target (analyze ctx (nth items 1) env)
|
||||
:args []})
|
||||
|
||||
(defn- analyze-symbol [ctx form env]
|
||||
(let [nm (form-sym-name form) ns (form-sym-ns form)]
|
||||
(cond
|
||||
|
|
@ -364,6 +396,12 @@
|
|||
(and (= hname "new") (not shadowed) (>= (count items) 2)
|
||||
(form-sym? (nth items 1)))
|
||||
(analyze-ctor ctx (form-sym-name (nth items 1)) (drop 2 items) env)
|
||||
;; (. target member arg*) — the `.` special form.
|
||||
(and (= hname ".") (not shadowed))
|
||||
(analyze-dot ctx items env)
|
||||
;; (.-field target) — field-access head.
|
||||
(and hname (not shadowed) (field-head? hname))
|
||||
(analyze-field ctx hname items env)
|
||||
(and hname (not shadowed) (form-special? hname))
|
||||
(uncompilable (str "special form " hname))
|
||||
(and (form-sym? head) (not shadowed) (form-macro? ctx head))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue