Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Backport @static macro (JuliaLang/julia#16219) #204

Merged
merged 1 commit into from
May 23, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,8 @@ Currently, the `@compat` macro supports the following syntaxes:

## New macros

* `@static` has been added [#16219](https://github.com/JuliaLang/julia/pull/16219).

* `@inline` and `@noinline` have been added. On 0.3, these are "no-ops," meaning they don't actually do anything.

* `@functorize` (not present in any Julia version) takes a function (or operator) and turns it into a functor object if one is available in the used Julia version. E.g. something like `mapreduce(Base.AbsFun(), Base.MulFun(), x)` can now be written as `mapreduce(@functorize(abs), @functorize(*), x)`, and `f(::Base.AbsFun())` as `f(::typeof(@functorize(abs)))`, to work across different Julia versions. `Func{1}` can be written as `supertype(typeof(@functorize(abs)))` (and so on for `Func{2}`), which will fall back to `Function` on Julia 0.5.
Expand Down
20 changes: 20 additions & 0 deletions src/Compat.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1118,4 +1118,24 @@ if !isdefined(Base, :unsafe_write)
export unsafe_write
end

# JuliaLang/julia#16219
if !isdefined(Base, @compat Symbol("@static"))
macro static(ex)
if isa(ex, Expr)
if ex.head === :if
cond = eval(current_module(), ex.args[1])
if cond
return esc(ex.args[2])
elseif length(ex.args) == 3
return esc(ex.args[3])
else
return nothing
end
end
end
throw(ArgumentError("invalid @static macro"))
end
export @static
end

end # module
6 changes: 6 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1141,3 +1141,9 @@ let io = IOBuffer(), s = "hello"
unsafe_write(io, pointer(s), length(s))
@test takebuf_string(io) == s
end

@static if VERSION ≥ v"0.4"
@test VERSION ≥ v"0.4"
else
@test VERSION < v"0.4"
end