To recap: It looks like Simon was looking for the AST for a specific method associated with a generic function. We can get a LambdaStaticData
object, which contains the AST, for a specific method as follows:
julia> f(x,y)=x+y
julia> f0 = methods(f, (Any, Any))[1]
((Any,Any),(),AST(:($(expr(:lambda, {x, y}, {{}, {{x, Any, 0}, {y, Any, 0}}, {}}, quote # none, line 1:
return +(x,y)
end)))),())
julia> f0[3]
AST(:($(expr(:lambda, {x, y}, {{}, {{x, Any, 0}, {y, Any, 0}}, {}}, quote # none, line 1:
return +(x,y)
end))))
julia> typeof(ans)
LambdaStaticData
Apparently this AST can either be an Expr object or a compressed AST object, represented as a sequence of bytes:
julia> typeof(f0[3].ast)
Array{Uint8,1}
The show()
method for LambdaStaticData
from base/show.jl
illustrates how to decompress this, when encountered:
julia> ccall(:jl_uncompress_ast, Any, (Any, Any), f0[3], f0[3].ast)
:($(expr(:lambda, {x, y}, {{}, {{x, Any, 0}, {y, Any, 0}}, {}}, quote # none, line 1:
return +(x,y)
end)))
julia> typeof(ans)
Expr