(analyze form env)
Given a form to analyze and an environment, a map containing:
* :locals a map from binding symbol to AST of the binding value
* :context a keyword describing the form's context from the :ctx/* hierarchy.
** :ctx/expr the form is an expression: its value is used
** :ctx/return the form is an expression in return position, derives :ctx/expr
** :ctx/statement the value of the form is not used
* :ns a symbol representing the current namespace of the form to be
analyzed
returns an AST for that form.
Every node in the AST is a map that is *guaranteed* to have the following keys:
* :op a keyword describing the AST node
* :form the form represented by the AST node
* :env the environment map of the AST node
Additionaly if the AST node contains sub-nodes, it is guaranteed to have:
* :children a vector of the keys of the AST node mapping to the sub-nodes,
ordered, when that makes sense
It is considered a node either the top-level node (marked with :top-level true)
or a node that can be reached via :children; if a node contains a node-like
map that is not reachable by :children, there's no guarantee that such a map
will contain the guaranteed keys.
Source
(defn analyze
"Given a form to analyze and an environment, a map containing:
* :locals a map from binding symbol to AST of the binding value
* :context a keyword describing the form's context from the :ctx/* hierarchy.
** :ctx/expr the form is an expression: its value is used
** :ctx/return the form is an expression in return position, derives :ctx/expr
** :ctx/statement the value of the form is not used
* :ns a symbol representing the current namespace of the form to be
analyzed
returns an AST for that form.
Every node in the AST is a map that is *guaranteed* to have the following keys:
* :op a keyword describing the AST node
* :form the form represented by the AST node
* :env the environment map of the AST node
Additionaly if the AST node contains sub-nodes, it is guaranteed to have:
* :children a vector of the keys of the AST node mapping to the sub-nodes,
ordered, when that makes sense
It is considered a node either the top-level node (marked with :top-level true)
or a node that can be reached via :children; if a node contains a node-like
map that is not reachable by :children, there's no guarantee that such a map
will contain the guaranteed keys."
[form env]
(assoc (analyze-form form env) :top-level true))