Skip to content

Commit

Permalink
Merge branch 'master' of github.com:JuliaLang/julia
Browse files Browse the repository at this point in the history
  • Loading branch information
ViralBShah committed Mar 15, 2015
2 parents dc5f15e + 6f63659 commit 6bf81b3
Show file tree
Hide file tree
Showing 17 changed files with 283 additions and 94 deletions.
14 changes: 11 additions & 3 deletions base/LineEdit.jl
Original file line number Diff line number Diff line change
Expand Up @@ -856,8 +856,6 @@ function postprocess!(dict::Dict)
# needs to be done first for every branch
if haskey(dict, '\0')
add_specialisations(dict, dict, 1)
else
dict['\0'] = (args...)->error("Unrecognized input")
end
for (k,v) in dict
k == '\0' && continue
Expand Down Expand Up @@ -1573,7 +1571,17 @@ function prompt!(term, prompt, s = init_state(term, prompt))
activate(prompt, s, term)
while true
map = keymap(s, prompt)
state = match_input(map, s)(s, keymap_data(s, prompt))
fcn = match_input(map, s)
# errors in keymaps shouldn't cause the REPL to fail, so wrap in a
# try/catch block
local state
try
state = fcn(s, keymap_data(s, prompt))
catch e
warn("Caught an exception in the keymap:")
warn(e)
state = :done
end
if state == :abort
stop_reading(term)
return buffer(s), false, false
Expand Down
7 changes: 4 additions & 3 deletions base/markdown/Common/Common.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
include("block.jl")
include("inline.jl")

@flavor common [list, indentcode, blockquote, hashheader, paragraph,
@flavor common [list, indentcode, blockquote, hashheader, horizontalrule,
paragraph,

linebreak, escapes, en_dash, inline_code, asterisk_bold,
asterisk_italic, image, link]
linebreak, escapes, en_dash, inline_code,
asterisk_bold, asterisk_italic, image, link]
47 changes: 42 additions & 5 deletions base/markdown/Common/block.jl
Original file line number Diff line number Diff line change
Expand Up @@ -119,25 +119,35 @@ type List
items::Vector{Any}
ordered::Bool

List(x::AbstractVector) = new(x)
List(x::AbstractVector, b::Bool) = new(x, b)
List(x::AbstractVector) = new(x, false)
List(b::Bool) = new(Any[], b)
end

List(xs...) = List(vcat(xs...))

const bullets = ["* ", "", "+ ", "- "]
const bullets = "*•+-"
const num_or_bullets = r"^(\*|•|\+|-|\d+(\.|\))) "

# Todo: ordered lists, inline formatting
function list(stream::IO, block::MD, config::Config)
withstream(stream) do
skipwhitespace(stream)
startswith(stream, bullets) || return false
the_list = List()
b = startswith(stream, num_or_bullets)
(b == nothing || b == "") && return false
ordered = !(b[1] in bullets)
if ordered
b = b[end - 1] == '.' ? r"^\d+\. " : r"^\d+\) "
# TODO start value
end
the_list = List(ordered)

buffer = IOBuffer()
fresh_line = false
while !eof(stream)
if fresh_line
skipwhitespace(stream)
if startswith(stream, bullets)
if startswith(stream, b) != ""
push!(the_list.items, parseinline(takebuf_string(buffer), config))
buffer = IOBuffer()
else
Expand All @@ -164,3 +174,30 @@ function list(stream::IO, block::MD, config::Config)
return true
end
end

# ––––––––––––––
# HorizontalRule
# ––––––––––––––

type HorizontalRule
end

function horizontalrule(stream::IO, block::MD, config::Config)
withstream(stream) do
n, rule = 0, ' '
while !eof(stream)
char = read(stream, Char)
char == '\n' && break
isspace(char) && continue
if n==0 || char==rule
rule = char
n += 1
else
return false
end
end
is_hr = (n 3 && rule in "*-")
is_hr && push!(block, HorizontalRule())
return is_hr
end
end
6 changes: 3 additions & 3 deletions base/markdown/Julia/Julia.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ We start by borrowing GitHub's `fencedcode` extension – more to follow.
include("interp.jl")

@flavor julia [blocktex, blockinterp, hashheader, list, indentcode, fencedcode,
blockquote, github_table, paragraph,
blockquote, github_table, horizontalrule, paragraph,

linebreak, escapes, latex, interp, en_dash, inline_code, asterisk_bold,
asterisk_italic, image, link]
linebreak, escapes, latex, interp, en_dash, inline_code,
asterisk_bold, asterisk_italic, image, link]
10 changes: 7 additions & 3 deletions base/markdown/render/html.jl
Original file line number Diff line number Diff line change
Expand Up @@ -49,21 +49,25 @@ end

function html(io::IO, md::BlockQuote)
withtag(io, :blockquote) do
html(io, block.content)
html(io, md.content)
end
end

function html(io::IO, md::List)
withtag(io, :ul) do
withtag(io, md.ordered ? :ol : :ul) do
for item in md.items
withtag(io, :li) do
htmlinline(io, item)
println(io)
end
println(io)
end
end
end

function html(io::IO, md::HorizontalRule)
tag(io, :hr)
end

html(io::IO, x) = tohtml(io, x)

# Inline elements
Expand Down
4 changes: 4 additions & 0 deletions base/markdown/render/latex.jl
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ function writemime(io::IO, ::MIME"text/latex", md::List)
end
end

function writemime(io::IO, ::MIME"text/latex", md::HorizontalRule)
println(io, "\\rule{\\textwidth}{1pt}")
end

# Inline elements

function writemime(io::IO, ::MIME"text/latex", md::Plain)
Expand Down
8 changes: 6 additions & 2 deletions base/markdown/render/plain.jl
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,17 @@ function plain(io::IO, p::Paragraph)
end

function plain(io::IO, list::List)
for item in list.items
print(io, " * ")
for (i, item) in enumerate(list.items)
print(io, list.ordered ? "$i. " : " * ")
plaininline(io, item)
println(io)
end
end

function plain(io::IO, md::HorizontalRule)
println(io, "" ^ 3)
end

plain(io::IO, x) = tohtml(io, x)

# Inline elements
Expand Down
8 changes: 6 additions & 2 deletions base/markdown/render/terminal/render.jl
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ function term(io::IO, md::BlockQuote, columns)
end

function term(io::IO, md::List, columns)
for point in md.items
print(io, " "^2margin, " ")
for (i, point) in enumerate(md.items)
print(io, " "^2margin, md.ordered ? "$i. " : " ")
print_wrapped(io, width = columns-(4margin+2), pre = " "^(2margin+2), i = 2margin+2) do io
terminline(io, point)
end
Expand Down Expand Up @@ -86,6 +86,10 @@ function term(io::IO, br::LineBreak, columns)
println(io)
end

function term(io::IO, br::HorizontalRule, columns)
println(io, " " ^ margin, "-" ^ (columns - 2margin))
end

term(io::IO, x, _) = writemime(io, MIME"text/plain"(), x)

# Inline Content
Expand Down
2 changes: 1 addition & 1 deletion base/show.jl
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ function show(io::IO, x::ANY)
else
nb = t.size
print(io, "0x")
p = pointer_from_objref(x) + sizeof(Ptr{Void})
p = data_pointer_from_objref(x)
for i=nb-1:-1:0
print(io, hex(unsafe_load(convert(Ptr{UInt8}, p+i)), 2))
end
Expand Down
84 changes: 74 additions & 10 deletions base/sparse/cholmod.jl
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,26 @@ using Base.SparseMatrix: AbstractSparseMatrix, SparseMatrixCSC, increment, indty

include("cholmod_h.jl")

### These offsets are defined in SuiteSparse_wrapper.c
const common_size = ccall((:jl_cholmod_common_size,:libsuitesparse_wrapper),Int,())

const cholmod_com_offsets = Array(Csize_t, 19)
ccall((:jl_cholmod_common_offsets, :libsuitesparse_wrapper),
Void, (Ptr{Csize_t},), cholmod_com_offsets)

const common_supernodal = (1:4) + cholmod_com_offsets[4]
const common_final_ll = (1:4) + cholmod_com_offsets[7]
const common_print = (1:4) + cholmod_com_offsets[13]
const common_itype = (1:4) + cholmod_com_offsets[18]
const common_dtype = (1:4) + cholmod_com_offsets[19]

## macro to generate the name of the C function according to the integer type
macro cholmod_name(nm,typ) string("cholmod_", eval(typ) == SuiteSparse_long ? "l_" : "", nm) end

for Ti in IndexTypes
@eval begin
function common(::Type{$Ti})
a = fill(0xff, cholmod_com_sz)
a = fill(0xff, common_size)
@isok ccall((@cholmod_name "start" $Ti
, :libcholmod), Cint, (Ptr{UInt8},), a)
set_print_level(a, 0) # no printing from CHOLMOD by default
Expand All @@ -36,15 +49,66 @@ for Ti in IndexTypes
end
end

### These offsets are defined in SuiteSparse_wrapper.c
const cholmod_com_offsets = Array(Csize_t, 19)
ccall((:jl_cholmod_common_offsets, :libsuitesparse_wrapper),
Void, (Ptr{Csize_t},), cholmod_com_offsets)
const common_supernodal = (1:4) + cholmod_com_offsets[4]
const common_final_ll = (1:4) + cholmod_com_offsets[7]
const common_print = (1:4) + cholmod_com_offsets[13]
const common_itype = (1:4) + cholmod_com_offsets[18]
const common_dtype = (1:4) + cholmod_com_offsets[19]
const version_array = Array(Cint, 3)
if dlsym(dlopen("libcholmod"), :cholmod_version) != C_NULL
ccall((:cholmod_version, :libcholmod), Cint, (Ptr{Cint},), version_array)
else
ccall((:jl_cholmod_version, :libsuitesparse_wrapper), Cint, (Ptr{Cint},), version_array)
end
const version = VersionNumber(version_array...)

function __init__()
if dlsym(dlopen("libcholmod"), :cholmod_version) == C_NULL
warn("""
CHOLMOD version incompatibility
Julia was compiled with CHOLMOD version $version, but is currently linked with a
version older than 2.1.0. This might cause Julia to terminate when working with
sparse matrices for operations involving factorization of a matrix, e.g. solving
systems of equations with \\.
It is recommended that you either upgrade the package that provides CHOLMOD or
download the OS X or generic Linux binary from www.julialang.org, which is
shipped with the correct versions of all dependencies.
""")
else
tmp = Array(Cint, 3)
ccall((:cholmod_version, :libcholmod), Cint, (Ptr{Cint},), version_array)
ccall((:jl_cholmod_version, :libsuitesparse_wrapper), Cint, (Ptr{Cint},), tmp)
if tmp != version_array
warn("""
CHOLMOD version incompatibility
Julia was compiled with CHOLMOD version $version, but is currently linked
with version $(VersionNumber(tmp...)). This might cause Julia to terminate when working
with sparse matrices for operations involving factorization of a matrix,
e.g. solving systems of equations with \\.
It is recommended that you either upgrade the package that provides CHOLMOD
or download the OS X or generic Linux binary from www.julialang.org, which
is shipped with the correct versions of all dependencies.
""")
end
end

intsize = Int(ccall((:jl_cholmod_sizeof_long,:libsuitesparse_wrapper),Csize_t,()))
if intsize != 4length(IndexTypes)
warn("""
CHOLMOD integer size incompatibility
Julia was compiled with a version of CHOLMOD that supported $(32length(IndexTypes)) bit integers,
but is currently linked with version that supports $(8intsize) integers. This might
cause Julia to terminate when working with sparse matrices for operations
involving factorization of a matrix, e.g. solving systems of equations with \\.
This problem can be fixed by downloading the OS X or generic Linux binary from
www.julialang.org, which are shipped with the correct versions of all dependencies.
""")
end
end

function set_print_level(cm::Array{UInt8}, lev::Integer)
cm[common_print] = reinterpret(UInt8, [Int32(lev)])
Expand Down
9 changes: 0 additions & 9 deletions base/sparse/cholmod_h.jl
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,3 @@ end
macro isok(A)
:($A == TRUE || throw(CHOLMODException("")))
end

const version_array = Array(Cint, 3)
if dlsym(dlopen("libcholmod"), :cholmod_version) != C_NULL
ccall((:cholmod_version, :libcholmod), Cint, (Ptr{Cint},), version_array)
else
ccall((:jl_cholmod_version, :libsuitesparse_wrapper), Cint, (Ptr{Cint},), version_array)
end
const version = VersionNumber(version_array...)
const cholmod_com_sz = ccall((:jl_cholmod_common_size,:libsuitesparse_wrapper),Int,())
21 changes: 9 additions & 12 deletions base/sysinfo.jl
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ function cpu_info()
cpus[i] = CPUinfo(unsafe_load(UVcpus[1],i))
end
ccall(:uv_free_cpu_info, Void, (Ptr{UV_cpu_info_t}, Int32), UVcpus[1], count[1])
cpus
return cpus
end

function uptime()
Expand Down Expand Up @@ -165,16 +165,13 @@ const shlib_ext = dlext
end

# This callback function called by dl_iterate_phdr() on Linux
function dl_phdr_info_callback( di_ptr::Ptr{dl_phdr_info}, size::Csize_t, dynamic_libraries_ptr::Ptr{Array{AbstractString,1}} )
di = unsafe_load(di_ptr)

function dl_phdr_info_callback(di::dl_phdr_info, size::Csize_t, dynamic_libraries::Array{AbstractString,1})
# Skip over objects without a path (as they represent this own object)
name = bytestring(di.name)
if !isempty(name)
dynamic_libraries = unsafe_pointer_to_objref( dynamic_libraries_ptr )
push!(dynamic_libraries, name )
push!(dynamic_libraries, name)
end
convert(Cint, 0)::Cint
return convert(Cint, 0)::Cint
end
end #@linux_only

Expand All @@ -183,8 +180,8 @@ function dllist()

@linux_only begin
const callback = cfunction(dl_phdr_info_callback, Cint,
(Ptr{dl_phdr_info}, Csize_t, Ptr{Array{AbstractString,1}} ))
ccall(:dl_iterate_phdr, Cint, (Ptr{Void}, Ptr{Void}), callback, pointer_from_objref(dynamic_libraries))
(Ref{dl_phdr_info}, Csize_t, Ref{Array{AbstractString,1}} ))
ccall(:dl_iterate_phdr, Cint, (Ptr{Void}, Any), callback, dynamic_libraries)
end

@osx_only begin
Expand All @@ -201,7 +198,7 @@ function dllist()
ccall(:jl_dllist, Cint, (Any,), dynamic_libraries)
end

dynamic_libraries
return dynamic_libraries
end

function dlpath( handle::Ptr{Void} )
Expand All @@ -211,7 +208,7 @@ function dlpath( handle::Ptr{Void} )
return s
end

function dlpath{T<:Union(AbstractString, Symbol)}(libname::T)
function dlpath(libname::Union(AbstractString,Symbol))
handle = dlopen(libname)
path = dlpath(handle)
dlclose(handle)
Expand All @@ -222,7 +219,7 @@ function get_process_title()
buf = zeros(Uint8, 512)
err = ccall(:uv_get_process_title, Cint, (Ptr{Uint8}, Cint), buf, 512)
uv_error("get_process_title", err)
bytestring(pointer(buf))
return bytestring(pointer(buf))
end
function set_process_title(title::AbstractString)
err = ccall(:uv_set_process_title, Cint, (Ptr{UInt8},), bytestring(title))
Expand Down
Loading

0 comments on commit 6bf81b3

Please sign in to comment.