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

remove lowercase conversions #10452

Merged
merged 4 commits into from
Mar 9, 2015
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
13 changes: 13 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,12 @@ Language changes
macro. Instead, the string is first unindented and then `x_str` is invoked,
as if the string had been single-quoted ([#10228]).

* Numeric conversion functions whose names are lower-case versions of type
names have been removed. To convert a scalar, use the type name, e.g.
`Int32(x)`. To convert an array to a different element type, use
`Array{T}(x)`, `map(T,x)`, or `round(T,x)`. To parse a string as an integer
or floating-point number, use `parseint` or `parsefloat` ([#1470], [#6211]).

Compiler improvements
---------------------

Expand Down Expand Up @@ -963,6 +969,7 @@ Too numerous to mention.
[#987]: https://github.com/JuliaLang/julia/issues/987
[#1195]: https://github.com/JuliaLang/julia/issues/1195
[#1268]: https://github.com/JuliaLang/julia/issues/1268
[#1470]: https://github.com/JuliaLang/julia/issues/1470
[#1484]: https://github.com/JuliaLang/julia/issues/1484
[#1539]: https://github.com/JuliaLang/julia/issues/1539
[#1571]: https://github.com/JuliaLang/julia/issues/1571
Expand Down Expand Up @@ -1131,6 +1138,7 @@ Too numerous to mention.
[#6169]: https://github.com/JuliaLang/julia/issues/6169
[#6179]: https://github.com/JuliaLang/julia/issues/6179
[#6197]: https://github.com/JuliaLang/julia/issues/6197
[#6211]: https://github.com/JuliaLang/julia/issues/6211
[#6212]: https://github.com/JuliaLang/julia/issues/6212
[#6270]: https://github.com/JuliaLang/julia/issues/6270
[#6273]: https://github.com/JuliaLang/julia/issues/6273
Expand Down Expand Up @@ -1235,10 +1243,15 @@ Too numerous to mention.
[#9734]: https://github.com/JuliaLang/julia/issues/9734
[#9745]: https://github.com/JuliaLang/julia/issues/9745
[#9779]: https://github.com/JuliaLang/julia/issues/9779
[#9862]: https://github.com/JuliaLang/julia/issues/9862
[#9957]: https://github.com/JuliaLang/julia/issues/9957
[#10024]: https://github.com/JuliaLang/julia/issues/10024
[#10031]: https://github.com/JuliaLang/julia/issues/10031
[#10075]: https://github.com/JuliaLang/julia/issues/10075
[#10117]: https://github.com/JuliaLang/julia/issues/10117
[#10150]: https://github.com/JuliaLang/julia/issues/10150
[#10180]: https://github.com/JuliaLang/julia/issues/10180
[#10228]: https://github.com/JuliaLang/julia/issues/10228
[#10332]: https://github.com/JuliaLang/julia/issues/10332
[#10333]: https://github.com/JuliaLang/julia/issues/10333
[#10400]: https://github.com/JuliaLang/julia/issues/10400
14 changes: 9 additions & 5 deletions base/Enums.jl
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,7 @@ macro enum(T,syms...)
throw(ArgumentError("invalid type expression for enum $T"))
end
vals = Array((Symbol,Integer),0)
lo = typemax(Int)
hi = typemin(Int)
lo = hi = 0
i = -1
enumT = typeof(i)
hasexpr = false
Expand Down Expand Up @@ -65,9 +64,14 @@ macro enum(T,syms...)
end
push!(vals, (s,i))
I = typeof(i)
enumT = length(vals) == 1 ? I : promote_type(enumT,I)
lo = min(lo, i)
hi = max(hi, i)
if length(vals) == 1
enumT = I
lo = hi = i
else
enumT = promote_type(enumT,I)
lo = min(lo, i)
hi = max(hi, i)
end
end
if !hasexpr
n = length(vals)
Expand Down
4 changes: 2 additions & 2 deletions base/LineEdit.jl
Original file line number Diff line number Diff line change
Expand Up @@ -662,7 +662,7 @@ write_prompt(terminal, s::ASCIIString) = write(terminal, s)
### Keymap Support

normalize_key(key::Char) = string(key)
normalize_key(key::Integer) = normalize_key(char(key))
normalize_key(key::Integer) = normalize_key(Char(key))
function normalize_key(key::AbstractString)
'\0' in key && error("Matching \\0 not currently supported.")
buf = IOBuffer()
Expand Down Expand Up @@ -944,7 +944,7 @@ function keymap{D<:Dict}(keymaps::Array{D})
end

const escape_defaults = merge!(
AnyDict([char(i) => nothing for i=vcat(1:26, 28:31)]), # Ignore control characters by default
AnyDict([Char(i) => nothing for i=vcat(1:26, 28:31)]), # Ignore control characters by default
AnyDict( # And ignore other escape sequences by default
"\e*" => nothing,
"\e[*" => nothing,
Expand Down
6 changes: 3 additions & 3 deletions base/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ all: pcre_h.jl errno_h.jl build_h.jl.phony fenv_constants.jl file_constants.jl u

pcre_h.jl:
ifeq ($(USE_SYSTEM_PCRE), 1)
@$(call PRINT_PERL, $(CPP) -dM $(shell $(PCRE_CONFIG) --prefix)/include/pcre.h | perl -nle '/^\s*#define\s+PCRE_(\w*)\s*\(?($(PCRE_CONST))\)?\s*$$/ and print "const $$1 = int32($$2)"' | sort > $@)
@$(call PRINT_PERL, $(CPP) -dM $(shell $(PCRE_CONFIG) --prefix)/include/pcre.h | perl -nle '/^\s*#define\s+PCRE_(\w*)\s*\(?($(PCRE_CONST))\)?\s*$$/ and print "const $$1 = Int32($$2)"' | sort > $@)
else
@$(call PRINT_PERL, $(CPP) -dM $(build_includedir)/pcre.h | perl -nle '/^\s*#define\s+PCRE_(\w*)\s*\(?($(PCRE_CONST))\)?\s*$$/ and print "const $$1 = int32($$2)"' | sort > $@)
@$(call PRINT_PERL, $(CPP) -dM $(build_includedir)/pcre.h | perl -nle '/^\s*#define\s+PCRE_(\w*)\s*\(?($(PCRE_CONST))\)?\s*$$/ and print "const $$1 = Int32($$2)"' | sort > $@)
endif

errno_h.jl:
@$(call PRINT_PERL, echo '#include "errno.h"' | $(CPP) -dM - | perl -nle 'print "const $$1 = int32($$2)" if /^#define\s+(E\w+)\s+(\d+)\s*$$/' | sort > $@)
@$(call PRINT_PERL, echo '#include "errno.h"' | $(CPP) -dM - | perl -nle 'print "const $$1 = Int32($$2)" if /^#define\s+(E\w+)\s+(\d+)\s*$$/' | sort > $@)

fenv_constants.jl: ../src/fenv_constants.h
@$(PRINT_PERL) $(CPP_STDOUT) -DJULIA -I../deps/openlibm/include ../src/fenv_constants.h | tail -n 8 | perl -ple 's/\sFE_UN\w+/ 0x10/g; s/\sFE_O\w+/ 0x08/g; s/\sFE_DI\w+/ 0x04/g; s/\sFE_INV\w+/ 0x01/g; s/\sFE_TON\w+/ 0x00/g; s/\sFE_UP\w+/ 0x800/g; s/\sFE_DO\w+/ 0x400/g; s/\sFE_TOW\w+/ 0xc00/g' > $@
Expand Down
8 changes: 4 additions & 4 deletions base/Terminals.jl
Original file line number Diff line number Diff line change
Expand Up @@ -144,13 +144,13 @@ end
else
ccall(:jl_tty_set_mode,
Int32, (Ptr{Void},Int32),
t.in_stream.handle, int32(raw)) != -1
t.in_stream.handle, raw) != -1
end
end
end : begin
raw!(t::TTYTerminal, raw::Bool) = ccall(:uv_tty_set_mode,
Int32, (Ptr{Void},Int32),
t.in_stream.handle, int32(raw)) != -1
t.in_stream.handle, raw) != -1
end
enable_bracketed_paste(t::UnixTerminal) = write(t.out_stream, "$(CSI)?2004h")
disable_bracketed_paste(t::UnixTerminal) = write(t.out_stream, "$(CSI)?2004l")
Expand All @@ -161,7 +161,7 @@ let s = zeros(Int32, 2)
function Base.size(t::TTYTerminal)
@windows_only if ispty(t.out_stream)
try
h,w = int(split(readall(open(`stty size`, "r", t.out_stream)[1])))
h,w = map(parseint,split(readall(open(`stty size`, "r", t.out_stream)[1])))
w > 0 || (w = 80)
h > 0 || (h = 24)
return h,w
Expand All @@ -175,7 +175,7 @@ let s = zeros(Int32, 2)
w,h = s[1],s[2]
w > 0 || (w = 80)
h > 0 || (h = 24)
(int(h),int(w))
(Int(h),Int(w))
end
end

Expand Down
103 changes: 25 additions & 78 deletions base/abstractarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ function squeeze(A::AbstractArray, dims::Dims)
reshape(A, d::typeof(_sub(size(A), dims)))
end

squeeze(A::AbstractArray, dim::Integer) = squeeze(A, (int(dim),))
squeeze(A::AbstractArray, dim::Integer) = squeeze(A, (Int(dim),))

function copy!(dest::AbstractArray, src)
i = 1
Expand Down Expand Up @@ -347,73 +347,15 @@ isempty(a::AbstractArray) = (length(a) == 0)

## Conversions ##

for (f,t) in ((:char, Char),
(:int, Int),
(:int8, Int8),
(:int16, Int16),
(:int32, Int32),
(:int64, Int64),
(:int128, Int128),
(:uint, UInt),
(:uint8, UInt8),
(:uint16, UInt16),
(:uint32, UInt32),
(:uint64, UInt64),
(:uint128,UInt128))
@eval begin
($f)(x::AbstractArray{$t}) = x
($f)(x::AbstractArray{$t}) = x

function ($f)(x::AbstractArray)
y = similar(x,$t)
i = 1
for e in x
y[i] = ($f)(e)
i += 1
end
y
end
end
end

for (f,t) in ((:integer, Integer),
(:unsigned, Unsigned))
@eval begin
($f){T<:$t}(x::AbstractArray{T}) = x
($f){T<:$t}(x::AbstractArray{T}) = x

function ($f)(x::AbstractArray)
y = similar(x,typeof(($f)(one(eltype(x)))))
i = 1
for e in x
y[i] = ($f)(e)
i += 1
end
y
end
end
end

big{T<:FloatingPoint,N}(x::AbstractArray{T,N}) = convert(AbstractArray{BigFloat,N}, x)
big{T<:FloatingPoint,N}(x::AbstractArray{Complex{T},N}) = convert(AbstractArray{Complex{BigFloat},N}, x)
big{T<:Integer,N}(x::AbstractArray{T,N}) = convert(AbstractArray{BigInt,N}, x)

bool(x::AbstractArray{Bool}) = x
bool(x::AbstractArray) = copy!(similar(x,Bool), x)

convert{T,N }(::Type{AbstractArray{T,N}}, A::AbstractArray{T,N}) = A
convert{T,S,N}(::Type{AbstractArray{T,N}}, A::AbstractArray{S,N}) = copy!(similar(A,T), A)
convert{T,S,N}(::Type{AbstractArray{T }}, A::AbstractArray{S,N}) = convert(AbstractArray{T,N}, A)

convert{T,N}(::Type{Array}, A::AbstractArray{T,N}) = convert(Array{T,N}, A)

for (f,T) in ((:float16, Float16),
(:float32, Float32),
(:float64, Float64),
(:complex64, Complex64),
(:complex128, Complex128))
@eval ($f){S,N}(x::AbstractArray{S,N}) = convert(AbstractArray{$T,N}, x)
end
big{T<:FloatingPoint,N}(x::AbstractArray{T,N}) = convert(AbstractArray{BigFloat,N}, x)
big{T<:FloatingPoint,N}(x::AbstractArray{Complex{T},N}) = convert(AbstractArray{Complex{BigFloat},N}, x)
big{T<:Integer,N}(x::AbstractArray{T,N}) = convert(AbstractArray{BigInt,N}, x)

float{T<:FloatingPoint}(x::AbstractArray{T}) = x
complex{T<:Complex}(x::AbstractArray{T}) = x
Expand All @@ -434,17 +376,20 @@ end

full(x::AbstractArray) = x

map(::Type{Integer}, a::Array) = map!(Integer, similar(a,typeof(Integer(one(eltype(a))))), a)
map(::Type{Signed}, a::Array) = map!(Signed, similar(a,typeof(Signed(one(eltype(a))))), a)
map(::Type{Unsigned}, a::Array) = map!(Unsigned, similar(a,typeof(Unsigned(one(eltype(a))))), a)

## range conversions ##

for fn in _numeric_conversion_func_names
map{T<:Real}(::Type{T}, r::StepRange) = T(r.start):T(r.step):T(last(r))
map{T<:Real}(::Type{T}, r::UnitRange) = T(r.start):T(last(r))
map{T<:FloatingPoint}(::Type{T}, r::FloatRange) = FloatRange(T(r.start), T(r.step), r.len, T(r.divisor))

for fn in (:float,:big)
@eval begin
$fn(r::StepRange) = $fn(r.start):$fn(r.step):$fn(last(r))
$fn(r::UnitRange) = $fn(r.start):$fn(last(r))
end
end

for fn in (:float,:float16,:float32,:float64,:big)
@eval begin
$fn(r::FloatRange) = FloatRange($fn(r.start), $fn(r.step), r.len, $fn(r.divisor))
end
end
Expand Down Expand Up @@ -502,7 +447,7 @@ function flipdim(A::AbstractArray, d::Integer)
B = similar(A)
nnd = 0
for i = 1:nd
nnd += int(size(A,i)==1 || i==d)
nnd += Int(size(A,i)==1 || i==d)
end
if nnd==nd
# flip along the only non-singleton dimension
Expand All @@ -521,7 +466,7 @@ end
flipud(A::AbstractArray) = flipdim(A, 1)
fliplr(A::AbstractArray) = flipdim(A, 2)

circshift(a::AbstractArray, shiftamt::Real) = circshift(a, [integer(shiftamt)])
circshift(a::AbstractArray, shiftamt::Real) = circshift(a, [Integer(shiftamt)])
function circshift{T,N}(a::AbstractArray{T,N}, shiftamts)
I = ()
for i=1:N
Expand Down Expand Up @@ -1031,24 +976,24 @@ function repmat(a::AbstractVector, m::Int)
end

sub2ind(dims) = 1
sub2ind(dims, i::Integer) = int(i)
sub2ind(dims, i::Integer, j::Integer) = sub2ind(dims, int(i), int(j))
sub2ind(dims, i::Integer) = Int(i)
sub2ind(dims, i::Integer, j::Integer) = sub2ind(dims, Int(i), Int(j))
sub2ind(dims, i::Int, j::Int) = (j-1)*dims[1] + i
sub2ind(dims, i0::Integer, i1::Integer, i2::Integer) = sub2ind(dims, int(i0),int(i1),int(i2))
sub2ind(dims, i0::Integer, i1::Integer, i2::Integer) = sub2ind(dims, Int(i0),Int(i1),Int(i2))
sub2ind(dims, i0::Int, i1::Int, i2::Int) =
i0 + dims[1]*((i1-1) + dims[2]*(i2-1))
sub2ind(dims, i0::Integer, i1::Integer, i2::Integer, i3::Integer) =
sub2ind(dims, int(i0),int(i1),int(i2),int(i3))
sub2ind(dims, Int(i0),Int(i1),Int(i2),Int(i3))
sub2ind(dims, i0::Int, i1::Int, i2::Int, i3::Int) =
i0 + dims[1]*((i1-1) + dims[2]*((i2-1) + dims[3]*(i3-1)))

function sub2ind(dims, I::Integer...)
ndims = length(dims)
index = int(I[1])
index = Int(I[1])
stride = 1
for k=2:ndims
stride = stride * dims[k-1]
index += (int(I[k])-1) * stride
index += (Int(I[k])-1) * stride
end
return index
end
Expand Down Expand Up @@ -1084,7 +1029,7 @@ function ind2sub(dims::(Integer,Integer...), ind::Int)
return tuple(ind, sub...)
end

ind2sub(dims::(Integer...), ind::Integer) = ind2sub(dims, int(ind))
ind2sub(dims::(Integer...), ind::Integer) = ind2sub(dims, Int(ind))
ind2sub(dims::(), ind::Integer) = ind==1 ? () : throw(BoundsError())
ind2sub(dims::(Integer,), ind::Int) = (ind,)
ind2sub(dims::(Integer,Integer), ind::Int) =
Expand Down Expand Up @@ -1369,7 +1314,9 @@ function map_to!{T}(f, offs, dest::AbstractArray{T}, A::AbstractArray)
end

function map(f, A::AbstractArray)
if isempty(A); return similar(A); end
if isempty(A)
return isa(f,Type) ? similar(A,f) : similar(A)
end
first = f(A[1])
dest = similar(A, typeof(first))
dest[1] = first
Expand Down
6 changes: 3 additions & 3 deletions base/array.jl
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ function copy(a::Array)
end

function reinterpret{T,S}(::Type{T}, a::Array{S,1})
nel = int(div(length(a)*sizeof(S),sizeof(T)))
nel = Int(div(length(a)*sizeof(S),sizeof(T)))
# TODO: maybe check that remainder is zero?
return reinterpret(T, a, (nel,))
end
Expand Down Expand Up @@ -251,7 +251,7 @@ linspace(start::Integer, stop::Integer, n::Integer) =
function linspace(start::Real, stop::Real, n::Integer)
(start, stop) = promote(start, stop)
T = typeof(start)
a = Array(T, int(n))
a = Array(T, Int(n))
if n == 1
a[1] = start
return a
Expand Down Expand Up @@ -960,7 +960,7 @@ function flipdim{T}(A::Array{T}, d::Integer)

nnd = 0
for i = 1:nd
nnd += int(size(A,i)==1 || i==d)
nnd += Int(size(A,i)==1 || i==d)
end
if nnd==nd
# flip along the only non-singleton dimension
Expand Down
14 changes: 7 additions & 7 deletions base/ascii.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
## required core functionality ##

endof(s::ASCIIString) = length(s.data)
getindex(s::ASCIIString, i::Int) = (x=s.data[i]; x < 0x80 ? char(x) : '\ufffd')
getindex(s::ASCIIString, i::Int) = (x=s.data[i]; x < 0x80 ? Char(x) : '\ufffd')

## overload methods for efficiency ##

Expand All @@ -17,8 +17,8 @@ sizeof(s::ASCIIString) = sizeof(s.data)
getindex(s::ASCIIString, r::Vector) = ASCIIString(getindex(s.data,r))
getindex(s::ASCIIString, r::UnitRange{Int}) = ASCIIString(getindex(s.data,r))
getindex(s::ASCIIString, indx::AbstractVector{Int}) = ASCIIString(s.data[indx])
search(s::ASCIIString, c::Char, i::Integer) = c < char(0x80) ? search(s.data,uint8(c),i) : 0
rsearch(s::ASCIIString, c::Char, i::Integer) = c < char(0x80) ? rsearch(s.data,uint8(c),i) : 0
search(s::ASCIIString, c::Char, i::Integer) = c < Char(0x80) ? search(s.data,c%UInt8,i) : 0
rsearch(s::ASCIIString, c::Char, i::Integer) = c < Char(0x80) ? rsearch(s.data,c%UInt8,i) : 0

function string(c::ASCIIString...)
if length(c) == 1
Expand Down Expand Up @@ -58,10 +58,10 @@ end
function uppercase(s::ASCIIString)
d = s.data
for i = 1:length(d)
if 'a' <= char(d[i]) <= 'z'
if 'a' <= Char(d[i]) <= 'z'
td = copy(d)
for j = i:length(td)
if 'a' <= char(td[j]) <= 'z'
if 'a' <= Char(td[j]) <= 'z'
td[j] -= 32
end
end
Expand All @@ -73,10 +73,10 @@ end
function lowercase(s::ASCIIString)
d = s.data
for i = 1:length(d)
if 'A' <= char(d[i]) <= 'Z'
if 'A' <= Char(d[i]) <= 'Z'
td = copy(d)
for j = i:length(td)
if 'A' <= char(td[j]) <= 'Z'
if 'A' <= Char(td[j]) <= 'Z'
td[j] += 32
end
end
Expand Down
Loading