pub struct Form {
pub kind: FormKind,
pub span: Span,
}Expand description
A parsed Clojure form with its source location.
PartialEq ignores spans so test assertions can compare forms without
constructing exact span values.
Fields§
§kind: FormKind§span: SpanImplementations§
Source§impl Form
impl Form
pub fn new(kind: FormKind, span: Span) -> Self
Sourcepub fn heap_size(&self) -> usize
pub fn heap_size(&self) -> usize
Total heap bytes owned by this form tree (excluding the Form itself).
Sourcepub fn is_kwargs_rest_pattern(&self) -> bool
pub fn is_kwargs_rest_pattern(&self) -> bool
True when this form, used as a variadic & rest pattern, selects
Clojure’s keyword-argument convention.
A map-shaped rest pattern ([& {:keys [a b]}]) does not destructure the
rest sequence; the trailing arguments are first normalized into a map
(Value::from_kwargs_rest) and the pattern is applied to that. Every
execution tier has to make this call the same way — the tree-walker in
bind_fn_params, and both lowerers on their way to KnownFn::KwargsMap
— so they share this predicate rather than three copies of the match.
Issue #368 was those copies disagreeing.
Sourcepub fn unmeta(&self) -> &Form
pub fn unmeta(&self) -> &Form
The annotated form with every ^meta wrapper removed.
Returns self when the form carries no metadata. Stacked metadata
(^:a ^:b x) is peeled down to the innermost form.
Sourcepub fn quoted_value_supports_meta(&self) -> bool
pub fn quoted_value_supports_meta(&self) -> bool
True when an evaluated-position ^meta annotation on this form becomes
runtime metadata on the value it produces.
Only a form that constructs an IObj qualifies — a collection literal
or a function. Every other form (a call, a symbol, quote, if, do)
takes the annotation as a compile-time hint and evaluates to an
unannotated value, so (meta ^{:a 1} (list 1)) and (meta ^{:a 1} x)
are both nil.
Every execution tier consults this one predicate: the tree-walker in
interp::eval, and IR lowering in lower::anf for the JIT and AOT
paths. A tier that disagreed would make meta depend on how hot the
code got.
True when the value this form denotes as data can carry metadata.
Inside quote every form is a literal, so whether an annotation lands
is a question about the form and needs no runtime test: '^{:a 1} [1]
carries it, '^{:a 1} 42 cannot. Mirrors supports_meta in
cljrs-runtime over the values form_to_value produces — a reader
macro ('x, @x, #'x, `x) denotes a list, and #(…) denotes
the fn* list it expands to.
Sourcepub fn takes_runtime_meta(&self) -> bool
pub fn takes_runtime_meta(&self) -> bool
Inside quote the rule does not apply: there the annotation is data and
lands on any value that can carry it.
Sourcepub fn peel_meta(&self) -> (Vec<&Form>, &Form)
pub fn peel_meta(&self) -> (Vec<&Form>, &Form)
The ^meta forms attached to this form, outermost first, together with
the annotated form itself.
Sourcepub fn as_keyword(&self) -> Option<&str>
pub fn as_keyword(&self) -> Option<&str>
The keyword name (without the leading :), if this form is a keyword.