Skip to content

Commit

Permalink
Merge pull request #363 from JuliaLang/teh/MODULE
Browse files Browse the repository at this point in the history
Support atsign-__MODULE__
  • Loading branch information
timholy committed Jun 8, 2017
2 parents c38d6cd + 8ed726c commit 2436d35
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 2 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,8 @@ Currently, the `@compat` macro supports the following syntaxes:

* `==(::Period, ::Period)` and `isless(::Period, ::Period)` is supported for 0.5 and below. Earlier versions of Julia only supported limited comparison methods between Periods which did not support comparing custom Period subtypes. ([#21378])

* `@__MODULE__` is aliased to `current_module()` for Julia versions 0.6 and below. Versions of `Base.binding_module`, `expand`, `macroexpand`, and `include_string` were added that accept a module as the first argument. ([#22064])

## Renamed functions

* `pointer_to_array` and `pointer_to_string` have been replaced with `unsafe_wrap(Array, ...)` and `unsafe_wrap(String, ...)` respectively
Expand Down Expand Up @@ -377,3 +379,4 @@ includes this fix. Find the minimum version from there.
[#20500]: https://github.com/JuliaLang/julia/issues/20500
[#21257]: https://github.com/JuliaLang/julia/issues/21257
[#21346]: https://github.com/JuliaLang/julia/issues/21346
[#22064]: https://github.com/JuliaLang/julia/issues/22064
14 changes: 14 additions & 0 deletions src/Compat.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1481,6 +1481,20 @@ else
using Base: StringVector
end

# https://github.com/JuliaLang/julia/pull/22064
if !isdefined(Base, Symbol("@__MODULE__"))
export @__MODULE__
macro __MODULE__()
return current_module()
end
Base.expand(mod::Module, x::ANY) = eval(mod, :(expand($(QuoteNode(x)))))
Base.macroexpand(mod::Module, x::ANY) = eval(mod, :(macroexpand($(QuoteNode(x)))))
Base.include_string(mod::Module, code::String, fname::String) =
eval(mod, :(include_string($code, $fname)))
Base.include_string(mod::Module, code::AbstractString, fname::AbstractString="string") =
eval(mod, :(include_string($code, $fname)))
end

# https://github.com/JuliaLang/julia/pull/19784
if isdefined(Base, :invokelatest)
import Base.invokelatest
Expand Down
7 changes: 5 additions & 2 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1567,7 +1567,7 @@ A = view(rand(5,5), 1:3, 1:3)
# julia#17623
if VERSION >= v"0.5.0-dev+5509"
# Use include_string to work around unsupported syntax on Julia 0.4
include_string("""
include_string(Main, """
@test [true, false] .& [true, true] == [true, false]
@test [true, false] .| [true, true] == [true, true]
""")
Expand Down Expand Up @@ -1852,6 +1852,8 @@ if VERSION >= v"0.5.0-rc1+46"
@test b == [1,2,3]
end

@test (@__MODULE__) === Main

# invokelatest
issue19774(x) = 1
let foo() = begin
Expand All @@ -1860,7 +1862,8 @@ let foo() = begin
end
@test foo() == 2
end
@test Compat.invokelatest(current_module) === current_module()
cm359() = @__MODULE__
@test Compat.invokelatest(cm359) === @__MODULE__

# PR 21378
let
Expand Down

0 comments on commit 2436d35

Please sign in to comment.