@@ -4,12 +4,13 @@ Julia ASTs
4
4
5
5
.. currentmodule :: Base
6
6
7
- Julia has two AST representations. First there is a surface syntax AST returned
7
+ Julia has two representations of code . First there is a surface syntax AST returned
8
8
by the parser (e.g. the :func: `parse ` function), and manipulated by macros.
9
9
It is a structured representation of code as it is written,
10
10
constructed by ``julia-parser.scm `` from a character stream.
11
- Next there is a lowered AST which is used by type inference and code generation.
12
- In the lowered form, there are generally fewer types of nodes, all macros
11
+ Next there is a lowered form, or IR (intermediate representation), which is used by
12
+ type inference and code generation.
13
+ In the lowered form there are fewer types of nodes, all macros
13
14
are expanded, and all control flow is converted to explicit branches and sequences
14
15
of statements. The lowered form is constructed by ``julia-syntax.scm ``.
15
16
@@ -21,17 +22,17 @@ significant rearrangement of the input syntax.
21
22
Lowered form
22
23
------------
23
24
24
- The following data types exist in lowered ASTs :
25
+ The following data types exist in lowered form :
25
26
26
27
``Expr ``
27
28
has a node type indicated by the ``head `` field, and an ``args `` field
28
29
which is a ``Vector{Any} `` of subexpressions.
29
30
30
- ``Symbol ``
31
- used to name local variables and static parameters within a function .
31
+ ``Slot ``
32
+ identifies arguments and local variables by consecutive numbering .
32
33
33
34
``LambdaInfo ``
34
- wraps the AST of each method.
35
+ wraps the IR of each method.
35
36
36
37
``LineNumberNode ``
37
38
line number metadata
@@ -54,9 +55,6 @@ The following data types exist in lowered ASTs:
54
55
forces a name to be resolved as a global in Base. This is now mostly
55
56
redundant with ``GlobalRef(Base, :x) ``.
56
57
57
- ``SymbolNode ``
58
- used to annotate a local variable with a type
59
-
60
58
``GenSym ``
61
59
refers to a consecutively-numbered (starting at 0) static single assignment
62
60
(SSA) variable inserted by the compiler.
@@ -75,6 +73,9 @@ These symbols appear in the ``head`` field of ``Expr``\s in lowered form.
75
73
function call. ``args[1] `` is the function to call, ``args[2:end] `` are the
76
74
arguments.
77
75
76
+ ``static_parameter ``
77
+ reference a static parameter by index.
78
+
78
79
``line ``
79
80
line number and file name metadata. Unlike a ``LineNumberNode ``, can also
80
81
contain a file name.
@@ -181,38 +182,27 @@ LambdaInfo
181
182
182
183
``sparam_vals `` - The values of the static parameters (once known), indexed by ``sparam_syms ``.
183
184
184
- Has an ``->ast `` field pointing to an ``Expr `` with head ``lambda ``. This
185
- ``Expr `` has the following layout:
185
+ ``code `` - An ``Any `` array of statements, or a UInt8 array with a compressed representation of the code.
186
186
187
- ``args[1] ``
188
- ``Vector{Any} `` of argument name symbols. For varargs functions, the last
189
- element is actually an ``Expr `` with head ``... ``. The argument of this
190
- ``Expr `` is an ``Expr `` with head ``:: ``. The first argument of ``:: `` is a
191
- symbol (the argument name), and the second argument is a type declaration.
187
+ ``slotnames `` - An array of symbols giving the name of each slot (argument or local variable).
192
188
193
- ``args[2] ``
194
- A ``Vector{Any} `` with variable information:
189
+ ``slottypes `` - An array of types for the slots.
195
190
196
- ``args[2][1] `` - An array of 3-element ``varinfo `` arrays, one for each
197
- argument or local variable. A ``varinfo `` array has the form ``Any[:name,
198
- type, bits] ``. The ``bits `` field is an integer
199
- describing variable properties as follows:
191
+ ``slotflags `` - A UInt8 array of slot properties, represented as bit flags:
200
192
- 1 - captured (closed over)
201
193
- 2 - assigned (only false if there are *no * assignment statements with this var on the left)
202
194
- 4 - assigned by an inner function
203
195
- 8 - const (currently unused for local variables)
204
196
- 16 - statically assigned once
205
197
- 32 - might be used before assigned. This flag is only valid after type inference.
206
198
207
- `` args[2][2] `` - An array of `` varinfo `` triples for each outer variable
208
- this function captures .
199
+ `` gensymtypes `` - Either an array or an Int giving the number of compiler-inserted
200
+ temporary locations in the function. If an array, specifies a type for each location .
209
201
210
- `` args[2][3] `` - The types of variables represented by `` GenSym `` objects.
211
- Given `` GenSym `` `` g ``, its type will be at `` args[2][3][g.id+1] `` .
202
+ `` nargs `` - The number of argument slots. The first `` nargs `` entries of the slots
203
+ arrays refer to arguments .
212
204
213
- ``args[3] ``
214
- an ``Expr `` with head ``body `` whose arguments are the statements
215
- comprising the function body.
205
+ ``isva `` - A boolean indicating whether the function is variadic.
216
206
217
207
218
208
Surface syntax AST
0 commit comments