Skip to content

Commit

Permalink
begin removing lowercase conversion functions (#1470)
Browse files Browse the repository at this point in the history
not quite done with renaming

[ci skip]
  • Loading branch information
JeffBezanson committed Mar 8, 2015
1 parent b80f7db commit 52709a1
Show file tree
Hide file tree
Showing 131 changed files with 1,445 additions and 1,496 deletions.
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
99 changes: 23 additions & 76 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,22 @@ end

full(x::AbstractArray) = x

map{T}(::Type{T}, a::AbstractArray{T}) = a
map{T}(::Type{T}, a::AbstractArray) = convert(AbstractArray{T}, a)
map(::Type{Integer}, a::AbstractArray) = convert(AbstractArray{typeof(Integer(one(eltype(a))))}, a)
map(::Type{Signed}, a::AbstractArray) = convert(AbstractArray{typeof(Signed(one(eltype(a))))}, a)
map(::Type{Unsigned}, a::AbstractArray) = convert(AbstractArray{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 +449,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 Down Expand Up @@ -1031,24 +978,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 +1031,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
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
11 changes: 3 additions & 8 deletions base/base.jl
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ end
type SystemError <: Exception
prefix::AbstractString
errnum::Int32
SystemError(p::AbstractString, e::Integer) = new(p, int32(e))
SystemError(p::AbstractString, e::Integer) = new(p, e)
SystemError(p::AbstractString) = new(p, errno())
end

Expand Down Expand Up @@ -138,11 +138,6 @@ end
ccall(:jl_get_system_hooks, Void, ())


int(x) = convert(Int, x)
int(x::Int) = x
uint(x) = convert(UInt, x)
uint(x::UInt) = x

# index colon
type Colon
end
Expand All @@ -162,8 +157,8 @@ end
finalize(o::ANY) = ccall(:jl_finalize, Void, (Any,), o)

gc(full::Bool=true) = ccall(:jl_gc_collect, Void, (Cint,), full)
gc_enable() = bool(ccall(:jl_gc_enable, Cint, ()))
gc_disable() = bool(ccall(:jl_gc_disable, Cint, ()))
gc_enable() = Bool(ccall(:jl_gc_enable, Cint, ()))
gc_disable() = Bool(ccall(:jl_gc_disable, Cint, ()))

bytestring(str::ByteString) = str

Expand Down
6 changes: 3 additions & 3 deletions base/base64.jl
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@ end

const b64chars = ['A':'Z';'a':'z';'0':'9';'+';'/']

const base64_pad = uint8('=')
const base64_pad = UInt8('=')

function b64(x::UInt8, y::UInt8, z::UInt8)
n = int(x)<<16 | int(y)<<8 | int(z)
n = Int(x)<<16 | Int(y)<<8 | Int(z)
b64chars[(n >> 18) + 1],
b64chars[(n >> 12) & 0b111111 + 1],
b64chars[(n >> 6) & 0b111111 + 1],
Expand All @@ -56,7 +56,7 @@ const sentinel = typemax(UInt8)
const revb64chars = fill(sentinel, 256)
# Fill revb64chars
for (val, ch) in enumerate(b64chars)
revb64chars[uint8(ch)] = uint8(val - 1)
revb64chars[UInt8(ch)] = UInt8(val - 1)
end

#Decode a block of at least 2 and at most 4 bytes, received in encvec
Expand Down
Loading

0 comments on commit 52709a1

Please sign in to comment.