|
1 | 1 | module JuliaInterpreter
|
2 | 2 |
|
3 |
| -using Base.Meta |
4 |
| -import Base: +, -, convert, isless |
5 |
| -using Core: CodeInfo, SimpleVector, LineInfoNode, GotoNode, Slot, |
6 |
| - GeneratedFunctionStub, MethodInstance, NewvarNode, TypeName |
| 3 | +# We use a code structure where all `using` and `import` |
| 4 | +# statements in the package that load anything other than |
| 5 | +# a Julia base or stdlib package are located in this file here. |
| 6 | +# Nothing else should appear in this file here, apart from |
| 7 | +# the `include("packagedef.jl")` statement, which loads what |
| 8 | +# we would normally consider the bulk of the package code. |
| 9 | +# This somewhat unusual structure is in place to support |
| 10 | +# the VS Code extension integration. |
7 | 11 |
|
8 |
| -using UUIDs |
9 |
| -using Random |
10 |
| -# The following are for circumventing #28, memcpy invalid instruction error, |
11 |
| -# in Base and stdlib |
12 |
| -using Random.DSFMT |
13 |
| -using InteractiveUtils |
14 | 12 | using CodeTracking
|
15 | 13 |
|
16 |
| -export @interpret, Compiled, Frame, root, leaf, |
17 |
| - BreakpointRef, breakpoint, @breakpoint, breakpoints, enable, disable, remove, toggle, |
18 |
| - debug_command, @bp, break_on, break_off, on_breakpoints_updated |
19 |
| - |
20 |
| -module CompiledCalls |
21 |
| -# This module is for handling intrinsics that must be compiled (llvmcall) as well as ccalls |
22 |
| -end |
23 |
| - |
24 |
| -# "Backport" of https://github.com/JuliaLang/julia/pull/31536 |
25 |
| -if VERSION < v"1.2.0-DEV.572" |
26 |
| - Base.convert(::Type{Some{T}}, x::Some{T}) where {T} = x |
27 |
| -end |
28 |
| - |
29 |
| -const SlotNamesType = VERSION < v"1.2.0-DEV.606" ? Vector{Any} : Vector{Symbol} |
30 |
| - |
31 |
| -@static if VERSION < v"1.3.0-DEV.179" |
32 |
| - const append_any = Base.append_any |
33 |
| -else |
34 |
| - append_any(@nospecialize x...) = append!([], Core.svec((x...)...)) |
35 |
| -end |
36 |
| - |
37 |
| -include("types.jl") |
38 |
| -include("utils.jl") |
39 |
| -include("construct.jl") |
40 |
| -include("localmethtable.jl") |
41 |
| -include("interpret.jl") |
42 |
| -include("builtins.jl") |
43 |
| -include("optimize.jl") |
44 |
| -include("commands.jl") |
45 |
| -include("breakpoints.jl") |
46 |
| - |
47 |
| -function set_compiled_methods() |
48 |
| - ########### |
49 |
| - # Methods # |
50 |
| - ########### |
51 |
| - # Work around #28 by preventing interpretation of all Base methods that have a ccall to memcpy |
52 |
| - push!(compiled_methods, which(vcat, (Vector,))) |
53 |
| - push!(compiled_methods, first(methods(Base._getindex_ra))) |
54 |
| - push!(compiled_methods, first(methods(Base._setindex_ra!))) |
55 |
| - push!(compiled_methods, which(Base.decompose, (BigFloat,))) |
56 |
| - push!(compiled_methods, which(DSFMT.dsfmt_jump, (DSFMT.DSFMT_state, DSFMT.GF2X))) |
57 |
| - @static if Sys.iswindows() |
58 |
| - push!(compiled_methods, which(InteractiveUtils.clipboard, (AbstractString,))) |
59 |
| - end |
60 |
| - # issue #76 |
61 |
| - push!(compiled_methods, which(unsafe_store!, (Ptr{Any}, Any, Int))) |
62 |
| - push!(compiled_methods, which(unsafe_store!, (Ptr, Any, Int))) |
63 |
| - # issue #92 |
64 |
| - push!(compiled_methods, which(objectid, Tuple{Any})) |
65 |
| - # issue #106 --- anything that uses sigatomic_(begin|end) |
66 |
| - push!(compiled_methods, which(flush, Tuple{IOStream})) |
67 |
| - push!(compiled_methods, which(disable_sigint, Tuple{Function})) |
68 |
| - push!(compiled_methods, which(reenable_sigint, Tuple{Function})) |
69 |
| - # Signal-handling in the `print` dispatch hierarchy |
70 |
| - push!(compiled_methods, which(Base.unsafe_write, Tuple{Base.LibuvStream, Ptr{UInt8}, UInt})) |
71 |
| - push!(compiled_methods, which(print, Tuple{IO, Any})) |
72 |
| - push!(compiled_methods, which(print, Tuple{IO, Any, Any})) |
73 |
| - # Libc.GetLastError() |
74 |
| - @static if Sys.iswindows() |
75 |
| - push!(compiled_methods, which(Base.access_env, Tuple{Function, AbstractString})) |
76 |
| - push!(compiled_methods, which(Base._hasenv, Tuple{Vector{UInt16}})) |
77 |
| - end |
78 |
| - # These are currently extremely slow to interpret (https://github.com/JuliaDebug/JuliaInterpreter.jl/issues/193) |
79 |
| - push!(compiled_methods, which(subtypes, Tuple{Module, Type})) |
80 |
| - push!(compiled_methods, which(subtypes, Tuple{Type})) |
81 |
| - push!(compiled_methods, which(match, Tuple{Regex, String, Int, UInt32})) |
82 |
| - |
83 |
| - # Anything that ccalls jl_typeinf_begin cannot currently be handled |
84 |
| - for finf in (Core.Compiler.typeinf_code, Core.Compiler.typeinf_ext, Core.Compiler.typeinf_type) |
85 |
| - for m in methods(finf) |
86 |
| - push!(compiled_methods, m) |
87 |
| - end |
88 |
| - end |
89 |
| - |
90 |
| - ########### |
91 |
| - # Modules # |
92 |
| - ########### |
93 |
| - push!(compiled_modules, Base.Threads) |
94 |
| -end |
95 |
| - |
96 |
| -function __init__() |
97 |
| - set_compiled_methods() |
98 |
| - # If we interpret into Core.Compiler, we need to take precautions to avoid needing |
99 |
| - # inference of JuliaInterpreter methods in the middle of a `ccall(:jl_typeinf_begin, ...)` |
100 |
| - # block. |
101 |
| - # for (sym, RT, AT) in ((:jl_typeinf_begin, Cvoid, ()), |
102 |
| - # (:jl_typeinf_end, Cvoid, ()), |
103 |
| - # (:jl_isa_compileable_sig, Int32, (Any, Any)), |
104 |
| - # (:jl_compress_ast, Any, (Any, Any)), |
105 |
| - # # (:jl_set_method_inferred, Ref{Core.CodeInstance}, (Any, Any, Any, Any, Int32, UInt, UInt)), |
106 |
| - # (:jl_method_instance_add_backedge, Cvoid, (Any, Any)), |
107 |
| - # (:jl_method_table_add_backedge, Cvoid, (Any, Any, Any)), |
108 |
| - # (:jl_new_code_info_uninit, Ref{CodeInfo}, ()), |
109 |
| - # (:jl_uncompress_argnames, Vector{Symbol}, (Any,)), |
110 |
| - # (:jl_get_tls_world_age, UInt, ()), |
111 |
| - # (:jl_call_in_typeinf_world, Any, (Ptr{Ptr{Cvoid}}, Cint)), |
112 |
| - # (:jl_value_ptr, Any, (Ptr{Cvoid},)), |
113 |
| - # (:jl_value_ptr, Ptr{Cvoid}, (Any,))) |
114 |
| - # fname = Symbol(:ccall_, sym) |
115 |
| - # qsym = QuoteNode(sym) |
116 |
| - # argnames = [Symbol(:arg_, string(i)) for i = 1:length(AT)] |
117 |
| - # TAT = Expr(:tuple, [parametric_type_to_expr(t) for t in AT]...) |
118 |
| - # def = :($fname($(argnames...)) = ccall($qsym, $RT, $TAT, $(argnames...))) |
119 |
| - # f = Core.eval(Core.Compiler, def) |
120 |
| - # compiled_calls[(qsym, RT, Core.svec(AT...), Core.Compiler)] = f |
121 |
| - # precompile(f, AT) |
122 |
| - # end |
123 |
| -end |
124 |
| - |
125 |
| -include("precompile.jl") |
126 |
| -_precompile_() |
| 14 | +include("packagedef.jl") |
127 | 15 |
|
128 | 16 | end # module
|
0 commit comments