@@ -4,126 +4,31 @@ module Compat
44
55using Base. Meta
66
7+ if ! isdefined (Base, Symbol (" @nospecialize" ))
8+ # 0.7
9+ macro nospecialize (arg)
10+ earg = esc (arg)
11+ if isa (arg, Symbol)
12+ return :($ earg:: ANY )
13+ end
14+ return earg
15+ end
16+ export @nospecialize
17+ end
18+
719""" Get just the function part of a function declaration."""
820withincurly (ex) = isexpr (ex, :curly ) ? ex. args[1 ] : ex
921
1022if VERSION < v " 0.6.0-dev.2043"
1123 Base. take! (t:: Task ) = consume (t)
1224end
1325
14- function rewrite_show (ex)
15- if isexpr (ex, :call )
16- Expr (:call , rewrite_show (ex. args[1 ]), ex. args[2 : end ]. .. )
17- elseif isexpr (ex, :curly )
18- Expr (:curly , rewrite_show (ex. args[1 ]), ex. args[2 : end ]. .. )
19- else
20- :(Base. writemime)
21- end
22- end
23-
24- function rewrite_dict (ex)
25- length (ex. args) == 1 && return ex
26-
27- f = ex. args[1 ]
28- if isexpr (f, :curly )
29- newex = Expr (:typed_dict , :($ (f. args[2 ])=> $ (f. args[3 ])))
30- else
31- newex = Expr (:dict )
32- end
33-
34- for i = 2 : length (ex. args)
35- pair = ex. args[i]
36- ! isexpr (pair, :(=> )) && return ex
37- push! (newex. args, pair)
38- end
39- newex
40- end
41-
42- function rewrite_ordereddict (ex)
43- length (ex. args) == 1 && return ex
44-
45- f = ex. args[1 ]
46- newex = Expr (:call , f, :[])
47-
48- for i = 2 : length (ex. args)
49- pair = ex. args[i]
50- ! isexpr (pair, :(=> )) && return ex
51- push! (newex. args[2 ]. args, Expr (:tuple , pair. args... ))
52- end
53-
54- newex
55- end
56-
57- # rewrites all subexpressions of the form `a => b` to `(a, b)`
58- function rewrite_pairs_to_tuples! (expr:: Expr )
59- if expr. head == :(=> )
60- expr. head = :tuple
61- end
62- for subexpr in expr. args
63- isa (subexpr, Expr) && rewrite_pairs_to_tuples! (subexpr)
64- end
65- return expr
66- end
67-
68- function is_quote_symbol (ex:: ANY , val:: Symbol )
69- if isa (ex, QuoteNode)
70- return (ex:: QuoteNode ). value === val
71- elseif isa (ex, Expr)
72- ex = ex:: Expr
73- return ex. head === :quote && length (ex. args) == 1 && ex. args[1 ] === val
74- end
75- return false
76- end
77-
7826is_index_style (ex:: Expr ) = ex == :(Compat. IndexStyle) || ex == :(Base. IndexStyle) ||
7927 (ex. head == :(.) && (ex. args[1 ] == :Compat || ex. args[1 ] == :Base ) &&
8028 ex. args[2 ] == Expr (:quote , :IndexStyle ))
8129
8230is_index_style (arg) = false
8331
84- # rewrites accesses to IOContext dicts
85- function rewrite_iocontext! (expr:: Expr )
86- args = expr. args
87- nargs = length (args)
88- if nargs == 4 && expr. head === :call && args[1 ] === :get && args[4 ] === false
89- key = args[3 ]
90- if is_quote_symbol (key, :limit ) || is_quote_symbol (key, :compact )
91- if VERSION >= v " 0.5.0-dev+1936" && VERSION < v " 0.5.0-dev+4305"
92- args[1 ] = :(Base. limit_output)
93- deleteat! (args, 3 : 4 )
94- elseif VERSION < v " 0.5.0-dev+1936"
95- expr. head = :quote
96- args[1 ] = false
97- deleteat! (args, 3 : 4 )
98- end
99- elseif is_quote_symbol (key, :multiline )
100- if VERSION < v " 0.5.0-dev+4305"
101- expr. head = :quote
102- args[1 ] = false
103- deleteat! (args, 3 : 4 )
104- end
105- end
106- end
107- end
108-
109- # JuliaLang/julia#10543
110- if ! isdefined (Base, :tryparse )
111- function tryparse {T} (:: Type{T} , args... )
112- try
113- Nullable (Base. parse (T, args... ))
114- catch
115- Nullable {T} ()
116- end
117- end
118- end
119-
120- import Base. unsafe_convert
121-
122- function new_style_call_overload (ex:: Expr )
123- Base. depwarn (" new_style_call_overload is deprecated." , :new_style_call_overload )
124- false
125- end
126-
12732istopsymbol (ex, mod, sym) = ex in (sym, Expr (:(.), mod, Expr (:quote , sym)))
12833
12934if VERSION < v " 0.6.0-dev.2782"
@@ -145,18 +50,13 @@ function _compat(ex::Expr)
14550 end
14651 elseif ex. head === :curly
14752 f = ex. args[1 ]
148- if ex == :(Ptr{Void})
149- # Do not change Ptr{Void} to Ptr{Nothing}: 0.4.0-dev+768
150- return ex
151- elseif VERSION < v " 0.6.0-dev.2575" # 20414
53+ if VERSION < v " 0.6.0-dev.2575" # 20414
15254 ex = Expr (:curly , map (a -> isexpr (a, :call , 2 ) && a. args[1 ] == :(< :) ?
15355 :($ TypeVar ($ (QuoteNode (gensym (:T ))), $ (a. args[2 ]), false )) :
15456 isexpr (a, :call , 2 ) && a. args[1 ] == :(> :) ?
15557 :($ TypeVar ($ (QuoteNode (gensym (:T ))), $ (a. args[2 ]), $ Any, false )) : a,
15658 ex. args)... )
15759 end
158- elseif ex. head === :macrocall
159- f = ex. args[1 ]
16060 elseif ex. head === :quote && isa (ex. args[1 ], Symbol)
16161 # Passthrough
16262 return ex
@@ -240,98 +140,7 @@ macro compat(ex...)
240140 esc (_compat (ex[1 ]))
241141end
242142
243- export @compat , @inline , @noinline
244-
245- import Base. @irrational
246-
247- import Base: remotecall, remotecall_fetch, remotecall_wait, remote_do
248-
249- import Base. Filesystem
250-
251- if ! isdefined (Base, :istextmime )
252- export istextmime
253- istextmime (m: :@compat (Union{MIME,AbstractString})) = istext (m)
254- end
255-
256- function primarytype (t:: ANY )
257- tn = t. name
258- if isdefined (tn, :primary )
259- return tn. primary
260- else
261- return tn. wrapper
262- end
263- end
264-
265- if ! isdefined (Base, :Threads )
266- @eval module Threads
267- macro threads (expr)
268- return esc (expr)
269- end
270- threadid () = 1
271- nthreads () = 1
272- export @threads , threadid, nthreads
273- end
274- export Threads
275- end
276-
277- if ! isdefined (Base, :normalize )
278- function normalize! (v:: AbstractVector , p:: Real = 2 )
279- nrm = norm (v, p)
280- __normalize! (v, nrm)
281- end
282-
283- @inline function __normalize! (v:: AbstractVector , nrm:: AbstractFloat )
284- # The largest positive floating point number whose inverse is less than
285- # infinity
286- δ = inv (prevfloat (typemax (nrm)))
287- if nrm ≥ δ # Safe to multiply with inverse
288- invnrm = inv (nrm)
289- scale! (v, invnrm)
290- else # scale elements to avoid overflow
291- εδ = eps (one (nrm))/ δ
292- scale! (v, εδ)
293- scale! (v, inv (nrm* εδ))
294- end
295- v
296- end
297-
298- copy_oftype {T,N} (A:: AbstractArray{T,N} , :: Type{T} ) = copy (A)
299- copy_oftype {T,N,S} (A:: AbstractArray{T,N} , :: Type{S} ) = convert (AbstractArray{S,N}, A)
300-
301- function normalize (v:: AbstractVector , p:: Real = 2 )
302- nrm = norm (v, p)
303- if ! isempty (v)
304- vv = copy_oftype (v, typeof (v[1 ]/ nrm))
305- return __normalize! (vv, nrm)
306- else
307- T = typeof (zero (eltype (v))/ nrm)
308- return T[]
309- end
310- end
311-
312- export normalize, normalize!
313- end
314-
315- import Base. AsyncCondition
316- import Base: srand, rand, rand!
317-
318-
319- if ! isdefined (Base, :pointer_to_string )
320-
321- function pointer_to_string (p:: Ptr{UInt8} , len:: Integer , own:: Bool = false )
322- a = ccall (:jl_ptr_to_array_1d , Vector{UInt8},
323- (Any, Ptr{UInt8}, Csize_t, Cint), Vector{UInt8}, p, len, own)
324- ccall (:jl_array_to_string , Ref{String}, (Any,), a)
325- end
326-
327- pointer_to_string (p:: Ptr{UInt8} , own:: Bool = false ) =
328- pointer_to_string (p, ccall (:strlen , Csize_t, (Cstring,), p), own)
329-
330- end
331-
332- import Base. promote_eltype_op
333-
334- import Base. LinAlg. BLAS. @blasfunc
143+ export @compat
335144
336145import Base: redirect_stdin, redirect_stdout, redirect_stderr
337146if VERSION < v " 0.6.0-dev.374"
@@ -412,20 +221,23 @@ end
412221
413222# julia#18977
414223if ! isdefined (Base, :xor )
224+ # 0.6
415225 const xor = $
416226 const ⊻ = xor
417227 export xor, ⊻
418228end
419229
420230# julia#19246
421231if ! isdefined (Base, :numerator )
232+ # 0.6
422233 const numerator = num
423234 const denominator = den
424235 export numerator, denominator
425236end
426237
427238# julia #19950
428239if ! isdefined (Base, :iszero )
240+ # 0.6
429241 iszero (x) = x == zero (x)
430242 iszero (x:: Number ) = x == 0
431243 iszero (x:: AbstractArray ) = all (iszero, x)
434246
435247# julia #20407
436248if ! isdefined (Base, :(> :))
249+ # 0.6
437250 const > : = let
438251 _issupertype (a:: ANY , b:: ANY ) = issubtype (b, a)
439252 end
568381
569382# https://github.com/JuliaLang/julia/pull/22064
570383if ! isdefined (Base, Symbol (" @__MODULE__" ))
384+ # 0.7
571385 export @__MODULE__
572386 macro __MODULE__ ()
573387 return current_module ()
582396
583397# https://github.com/JuliaLang/julia/pull/19784
584398if isdefined (Base, :invokelatest )
399+ # 0.6
585400 import Base. invokelatest
586401else
587402 invokelatest (f, args... ) = eval (current_module (), Expr (:call , f, map (QuoteNode, args)... ))
@@ -667,6 +482,12 @@ if VERSION < v"0.7.0-DEV.892"
667482 export fieldcount
668483end
669484
485+ if VERSION < v " 0.7.0-DEV.1053"
486+ Base. read (obj:: IO , :: Type{String} ) = readstring (obj)
487+ Base. read (obj:: AbstractString , :: Type{String} ) = readstring (obj)
488+ Base. read (obj:: Cmd , :: Type{String} ) = readstring (obj)
489+ end
490+
670491include (" deprecated.jl" )
671492
672493end # module Compat
0 commit comments