|
1 | 1 | # This file provides an adaptor to match the API expected by the Julia runtime
|
2 | 2 | # code in the binding Core._parse
|
3 | 3 |
|
4 |
| -function _set_core_parse_hook(parser) |
5 |
| - # HACK! Fool the runtime into allowing us to set Core._parse, even during |
6 |
| - # incremental compilation. (Ideally we'd just arrange for Core._parse to be |
7 |
| - # set to the JuliaSyntax parser. But how do we signal that to the dumping |
8 |
| - # code outside of the initial creation of Core?) |
9 |
| - i = findfirst(==(:incremental), fieldnames(Base.JLOptions)) |
10 |
| - ptr = convert(Ptr{fieldtype(Base.JLOptions, i)}, |
11 |
| - cglobal(:jl_options, Base.JLOptions) + fieldoffset(Base.JLOptions, i)) |
12 |
| - incremental = unsafe_load(ptr) |
13 |
| - if incremental != 0 |
14 |
| - unsafe_store!(ptr, 0) |
15 |
| - end |
| 4 | +if isdefined(Core, :set_parser) |
| 5 | + const _set_core_parse_hook = Core.set_parser |
| 6 | +else |
| 7 | + function _set_core_parse_hook(parser) |
| 8 | + # HACK! Fool the runtime into allowing us to set Core._parse, even during |
| 9 | + # incremental compilation. (Ideally we'd just arrange for Core._parse to be |
| 10 | + # set to the JuliaSyntax parser. But how do we signal that to the dumping |
| 11 | + # code outside of the initial creation of Core?) |
| 12 | + i = findfirst(==(:incremental), fieldnames(Base.JLOptions)) |
| 13 | + ptr = convert(Ptr{fieldtype(Base.JLOptions, i)}, |
| 14 | + cglobal(:jl_options, Base.JLOptions) + fieldoffset(Base.JLOptions, i)) |
| 15 | + incremental = unsafe_load(ptr) |
| 16 | + if incremental != 0 |
| 17 | + unsafe_store!(ptr, 0) |
| 18 | + end |
16 | 19 |
|
17 |
| - Base.eval(Core, :(_parse = $parser)) |
| 20 | + Base.eval(Core, :(_parse = $parser)) |
18 | 21 |
|
19 |
| - if incremental != 0 |
20 |
| - unsafe_store!(ptr, incremental) |
| 22 | + if incremental != 0 |
| 23 | + unsafe_store!(ptr, incremental) |
| 24 | + end |
21 | 25 | end
|
22 | 26 | end
|
23 | 27 |
|
|
0 commit comments