120120
121121# Convert SyntaxTree to the CodeInfo+Expr data stuctures understood by the
122122# Julia runtime
123- function to_code_info (ex, mod, funcname, slots)
124- input_code = children (ex)
123+ function to_code_info (ex:: SyntaxTree , slots:: Vector{Slot} )
125124 stmts = Any[]
126125
127126 current_codelocs_stack = ir_debug_info_state (ex)
@@ -156,7 +155,7 @@ function to_code_info(ex, mod, funcname, slots)
156155
157156 stmt_offset = length (stmts)
158157 for stmt in children (ex)
159- push! (stmts, _to_lowered_expr (mod, stmt, stmt_offset))
158+ push! (stmts, _to_lowered_expr (stmt, stmt_offset))
160159 add_ir_debug_info! (current_codelocs_stack, stmt)
161160 end
162161
@@ -223,11 +222,11 @@ function to_code_info(ex, mod, funcname, slots)
223222 )
224223end
225224
226- @fzone " JL: to_lowered_expr" function to_lowered_expr (mod, ex )
227- _to_lowered_expr (mod, ex, 0 )
225+ @fzone " JL: to_lowered_expr" function to_lowered_expr (ex :: SyntaxTree )
226+ _to_lowered_expr (ex, 0 )
228227end
229228
230- function _to_lowered_expr (mod, ex , stmt_offset)
229+ function _to_lowered_expr (ex :: SyntaxTree , stmt_offset:: Int )
231230 k = kind (ex)
232231 if is_literal (k)
233232 ex. value
@@ -263,15 +262,12 @@ function _to_lowered_expr(mod, ex, stmt_offset)
263262 elseif k == K " SSAValue"
264263 Core. SSAValue (ex. var_id + stmt_offset)
265264 elseif k == K " return"
266- Core. ReturnNode (_to_lowered_expr (mod, ex[1 ], stmt_offset))
265+ Core. ReturnNode (_to_lowered_expr (ex[1 ], stmt_offset))
267266 elseif k == K " inert"
268267 e1 = ex[1 ]
269268 getmeta (ex, :as_Expr , false ) ? QuoteNode (Expr (e1)) : e1
270269 elseif k == K " code_info"
271- funcname = ex. is_toplevel_thunk ?
272- " top-level scope" :
273- " none" # FIXME
274- ir = to_code_info (ex[1 ], mod, funcname, ex. slots)
270+ ir = to_code_info (ex[1 ], ex. slots)
275271 if ex. is_toplevel_thunk
276272 Expr (:thunk , ir)
277273 else
@@ -282,36 +278,40 @@ function _to_lowered_expr(mod, ex, stmt_offset)
282278 elseif k == K " goto"
283279 Core. GotoNode (ex[1 ]. id + stmt_offset)
284280 elseif k == K " gotoifnot"
285- Core. GotoIfNot (_to_lowered_expr (mod, ex[1 ], stmt_offset), ex[2 ]. id + stmt_offset)
281+ Core. GotoIfNot (_to_lowered_expr (ex[1 ], stmt_offset), ex[2 ]. id + stmt_offset)
286282 elseif k == K " enter"
287283 catch_idx = ex[1 ]. id
288284 numchildren (ex) == 1 ?
289285 Core. EnterNode (catch_idx) :
290- Core. EnterNode (catch_idx, _to_lowered_expr (mod, ex[2 ], stmt_offset))
286+ Core. EnterNode (catch_idx, _to_lowered_expr (ex[2 ], stmt_offset))
291287 elseif k == K " method"
292- cs = map (e-> _to_lowered_expr (mod, e, stmt_offset), children (ex))
288+ cs = map (e-> _to_lowered_expr (e, stmt_offset), children (ex))
293289 # Ad-hoc unwrapping to satisfy `Expr(:method)` expectations
294- c1 = cs[1 ] isa QuoteNode ? cs[1 ]. value : cs[1 ]
290+ cs1 = cs[1 ]
291+ c1 = cs1 isa QuoteNode ? cs1. value : cs1
295292 Expr (:method , c1, cs[2 : end ]. .. )
296293 elseif k == K " newvar"
297- Core. NewvarNode (_to_lowered_expr (mod, ex[1 ], stmt_offset))
294+ Core. NewvarNode (_to_lowered_expr (ex[1 ], stmt_offset))
298295 elseif k == K " opaque_closure_method"
299- args = map (e-> _to_lowered_expr (mod, e, stmt_offset), children (ex))
296+ args = map (e-> _to_lowered_expr (e, stmt_offset), children (ex))
300297 # opaque_closure_method has special non-evaluated semantics for the
301298 # `functionloc` line number node so we need to undo a level of quoting
302- @assert args[4 ] isa QuoteNode
303- args[4 ] = args[4 ]. value
299+ arg4 = args[4 ]
300+ @assert arg4 isa QuoteNode
301+ args[4 ] = arg4. value
304302 Expr (:opaque_closure_method , args... )
305303 elseif k == K " meta"
306- args = Any[_to_lowered_expr (mod, e, stmt_offset) for e in children (ex)]
304+ args = Any[_to_lowered_expr (e, stmt_offset) for e in children (ex)]
307305 # Unpack K"Symbol" QuoteNode as `Expr(:meta)` requires an identifier here.
308- args[1 ] = args[1 ]. value
306+ arg1 = args[1 ]
307+ @assert arg1 isa QuoteNode
308+ args[1 ] = arg1. value
309309 Expr (:meta , args... )
310310 elseif k == K " static_eval"
311311 @assert numchildren (ex) == 1
312- _to_lowered_expr (mod, ex[1 ], stmt_offset)
312+ _to_lowered_expr (ex[1 ], stmt_offset)
313313 elseif k == K " cfunction"
314- args = Any[_to_lowered_expr (mod, e, stmt_offset) for e in children (ex)]
314+ args = Any[_to_lowered_expr (e, stmt_offset) for e in children (ex)]
315315 if kind (ex[2 ]) == K " static_eval"
316316 args[2 ] = QuoteNode (args[2 ])
317317 end
@@ -343,7 +343,11 @@ function _to_lowered_expr(mod, ex, stmt_offset)
343343 if isnothing (head)
344344 throw (LoweringError (ex, " Unhandled form for kind $k " ))
345345 end
346- Expr (head, map (e-> _to_lowered_expr (mod, e, stmt_offset), children (ex))... )
346+ ret = Expr (head)
347+ for e in children (ex)
348+ push! (ret. args, _to_lowered_expr (e, stmt_offset))
349+ end
350+ return ret
347351 end
348352end
349353
359363 return x
360364 end
361365 linear_ir = lower (mod, ex; expr_compat_mode)
362- thunk = to_lowered_expr (mod, linear_ir)
366+ thunk = to_lowered_expr (linear_ir)
363367 Core. eval (mod, thunk)
364368end
365369
@@ -400,4 +404,3 @@ function include_string(mod::Module, code::AbstractString, filename::AbstractStr
400404 expr_compat_mode= false )
401405 eval (mod, parseall (SyntaxTree, code; filename= filename); expr_compat_mode)
402406end
403-
0 commit comments