Skip to content

Commit

Permalink
Updates prepping for julia 0.7 (#28)
Browse files Browse the repository at this point in the history
  • Loading branch information
Ben J. Ward authored and bicycle1885 committed Mar 6, 2018
1 parent db0d660 commit 01ff5f2
Show file tree
Hide file tree
Showing 39 changed files with 268 additions and 134 deletions.
3 changes: 0 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,5 @@ notifications:
# - if [[ -a .git/shallow ]]; then git fetch --unshallow; fi
# - julia -e 'Pkg.clone(pwd()); Pkg.build("Automa"); Pkg.test("Automa"; coverage=true)'
after_success:
# push coverage results to Coveralls
# - julia -e 'cd(Pkg.dir("Automa")); Pkg.add("Coverage"); using Coverage; Coveralls.submit(Coveralls.process_folder())'
# push coverage results to Codecov
- julia -e 'cd(Pkg.dir("Automa")); Pkg.add("Coverage"); using Coverage; Codecov.submit(Codecov.process_folder())'
- julia -e 'cd(Pkg.dir("Automa")); Pkg.add("Documenter"); ENV["DOCUMENTER_DEBUG"] = "true"; include(joinpath("docs", "make.jl"))'
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ context = Automa.CodeGenContext()
tokens = Tuple{Symbol,String}[]
mark = 0
$(Automa.generate_init_code(context, machine))
p_end = p_eof = endof(data)
p_end = p_eof = lastindex(data)
emit(kind) = push!(tokens, (kind, data[mark:p-1]))
$(Automa.generate_exec_code(context, machine, actions))
return tokens, cs == 0 ? :ok : cs < 0 ? :error : :incomplete
Expand Down
2 changes: 1 addition & 1 deletion REQUIRE
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
julia 0.6
DataStructures 0.5.1
Compat 0.41.0
Compat 0.55
9 changes: 3 additions & 6 deletions appveyor.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
environment:
matrix:
- JULIA_URL: "https://julialang-s3.julialang.org/bin/winnt/x86/0.6/julia-0.5-latest-win32.exe"
- JULIA_URL: "https://julialang-s3.julialang.org/bin/winnt/x64/0.6/julia-0.5-latest-win64.exe"
- JULIA_URL: "https://julialangnightlies-s3.julialang.org/bin/winnt/x86/julia-latest-win32.exe"
- JULIA_URL: "https://julialangnightlies-s3.julialang.org/bin/winnt/x64/julia-latest-win64.exe"
- Julia_URL: "https://julialang-s3.julialang.org/bin/winnt/x64/0.6/julia-0.6-latest-win64.exe"
- Julia_URL: "https://julialangnightlies-s3.julialang.org/bin/winnt/x64/julia-latest-win64.exe"

matrix:
allow_failures:
- JULIA_URL: "https://julialangnightlies-s3.julialang.org/bin/winnt/x86/julia-latest-win32.exe"
allow_failures:
- JULIA_URL: "https://julialangnightlies-s3.julialang.org/bin/winnt/x64/julia-latest-win64.exe"

branches:
Expand Down
17 changes: 9 additions & 8 deletions benchmark/runbenchmarks.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import Automa
import Automa.RegExp: @re_str
using BenchmarkTools
import Compat: lastindex

srand(1234)
data = String(vcat([push!(rand(b"ACGTacgt", 59), UInt8('\n')) for _ in 1:1000]...))
Expand Down Expand Up @@ -29,7 +30,7 @@ VISUALIZE && writesvg("case1", machine)
context = Automa.CodeGenContext(generator=:goto, checkbounds=false)
@eval function match(data)
$(Automa.generate_init_code(context, machine))
p_end = p_eof = endof(data)
p_end = p_eof = lastindex(data)
$(Automa.generate_exec_code(context, machine))
return cs == 0
end
Expand All @@ -39,7 +40,7 @@ println("Automa.jl: ", @benchmark match(data))
context = Automa.CodeGenContext(generator=:goto, checkbounds=false, loopunroll=10)
@eval function match(data)
$(Automa.generate_init_code(context, machine))
p_end = p_eof = endof(data)
p_end = p_eof = lastindex(data)
$(Automa.generate_exec_code(context, machine))
return cs == 0
end
Expand All @@ -61,7 +62,7 @@ VISUALIZE && writesvg("case2", machine)
context = Automa.CodeGenContext(generator=:goto, checkbounds=false)
@eval function match(data)
$(Automa.generate_init_code(context, machine))
p_end = p_eof = endof(data)
p_end = p_eof = lastindex(data)
$(Automa.generate_exec_code(context, machine))
return cs == 0
end
Expand All @@ -71,7 +72,7 @@ println("Automa.jl: ", @benchmark match(data))
context = Automa.CodeGenContext(generator=:goto, checkbounds=false, loopunroll=10)
@eval function match(data)
$(Automa.generate_init_code(context, machine))
p_end = p_eof = endof(data)
p_end = p_eof = lastindex(data)
$(Automa.generate_exec_code(context, machine))
return cs == 0
end
Expand All @@ -93,7 +94,7 @@ VISUALIZE && writesvg("case3", machine)
context = Automa.CodeGenContext(generator=:goto, checkbounds=false)
@eval function match(data)
$(Automa.generate_init_code(context, machine))
p_end = p_eof = endof(data)
p_end = p_eof = lastindex(data)
$(Automa.generate_exec_code(context, machine))
return cs == 0
end
Expand All @@ -103,7 +104,7 @@ println("Automa.jl: ", @benchmark match(data))
context = Automa.CodeGenContext(generator=:goto, checkbounds=false, loopunroll=10)
@eval function match(data)
$(Automa.generate_init_code(context, machine))
p_end = p_eof = endof(data)
p_end = p_eof = lastindex(data)
$(Automa.generate_exec_code(context, machine))
return cs == 0
end
Expand All @@ -125,7 +126,7 @@ VISUALIZE && writesvg("case4", machine)
context = Automa.CodeGenContext(generator=:goto, checkbounds=false)
@eval function match(data)
$(Automa.generate_init_code(context, machine))
p_end = p_eof = endof(data)
p_end = p_eof = lastindex(data)
$(Automa.generate_exec_code(context, machine))
return cs == 0
end
Expand All @@ -135,7 +136,7 @@ println("Automa.jl: ", @benchmark match(data))
context = Automa.CodeGenContext(generator=:goto, checkbounds=false, loopunroll=10)
@eval function match(data)
$(Automa.generate_init_code(context, machine))
p_end = p_eof = endof(data)
p_end = p_eof = lastindex(data)
$(Automa.generate_exec_code(context, machine))
return cs == 0
end
Expand Down
23 changes: 14 additions & 9 deletions docs/make.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,19 @@ using Automa
# run(`julia preconditions.jl`)

makedocs(
format=:html,
sitename="Automa.jl",
modules=[Automa],
pages=["Home" => "index.md", "References" => "references.md"])
format = :html,
sitename = "Automa.jl",
modules = [Automa],
pages = [
"Home" => "index.md",
"References" => "references.md"
]
)

deploydocs(
repo="github.com/BioJulia/Automa.jl.git",
julia="0.6",
target="build",
deps=nothing,
make=nothing)
repo = "github.com/BioJulia/Automa.jl.git",
julia = "0.6",
target = "build",
deps = nothing,
make = nothing
)
4 changes: 2 additions & 2 deletions docs/src/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ context = Automa.CodeGenContext()
tokens = Tuple{Symbol,String}[]
mark = 0
$(Automa.generate_init_code(context, machine))
p_end = p_eof = endof(data)
p_end = p_eof = lastindex(data)
emit(kind) = push!(tokens, (kind, data[mark:p-1]))
$(Automa.generate_exec_code(context, machine, actions))
return tokens, cs == 0 ? :ok : cs < 0 ? :error : :incomplete
Expand Down Expand Up @@ -251,7 +251,7 @@ context = Automa.CodeGenContext()
$(Automa.generate_init_code(context, machine))

# set end and EOF positions of data buffer
p_end = p_eof = endof(data)
p_end = p_eof = lastindex(data)

# generate code to execute FSM
$(Automa.generate_exec_code(context, machine, actions))
Expand Down
3 changes: 2 additions & 1 deletion example/fasta.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import Automa
import Automa.RegExp: @re_str
const re = Automa.RegExp
import Compat: lastindex

# Create a machine of FASTA.
fasta_machine = (function ()
Expand Down Expand Up @@ -63,7 +64,7 @@ context = Automa.CodeGenContext(generator=:goto, checkbounds=false)

# Initialize variables used by the state machine.
$(Automa.generate_init_code(context, fasta_machine))
p_end = p_eof = endof(data)
p_end = p_eof = lastindex(data)

# This is the main loop to iterate over the input data.
$(Automa.generate_exec_code(context, fasta_machine, fasta_actions))
Expand Down
3 changes: 2 additions & 1 deletion example/numbers.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import Automa
import Automa.RegExp: @re_str
const re = Automa.RegExp
import Compat: lastindex

# Describe patterns in regular expression.
oct = re"0o[0-7]+"
Expand Down Expand Up @@ -43,7 +44,7 @@ context = Automa.CodeGenContext()
tokens = Tuple{Symbol,String}[]
mark = 0
$(Automa.generate_init_code(context, machine))
p_end = p_eof = endof(data)
p_end = p_eof = lastindex(data)
emit(kind) = push!(tokens, (kind, data[mark:p-1]))
$(Automa.generate_exec_code(context, machine, actions))
return tokens, cs == 0 ? :ok : cs < 0 ? :error : :incomplete
Expand Down
9 changes: 9 additions & 0 deletions src/Automa.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,15 @@ __precompile__()
module Automa

import DataStructures: DefaultDict
import Compat: Compat,
AbstractDict,
argmax,
lastindex,
uninitialized,
findfirst,
Nothing,
popfirst!,
objectid

if VERSION > v"0.7-"
using Printf: @sprintf
Expand Down
6 changes: 3 additions & 3 deletions src/action.jl
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ function Base.:(==)(l1::ActionList, l2::ActionList)
if length(l1) != length(l2)
return false
end
for i in 1:endof(l1.actions)
for i in 1:lastindex(l1.actions)
if l1.actions[i].name != l2.actions[i].name
return false
end
Expand All @@ -39,8 +39,8 @@ function Base.hash(list::ActionList, h::UInt)
end

function Base.push!(list::ActionList, action::Action)
i = findfirst(a -> a.name == action.name, list.actions)
if i > 0
i = Compat.findfirst(a -> a.name == action.name, list.actions)
if i != nothing
if action.order < list.actions[i].order
list.actions[i] = action # replace
end
Expand Down
4 changes: 2 additions & 2 deletions src/byteset.jl
Original file line number Diff line number Diff line change
Expand Up @@ -135,10 +135,10 @@ function range_encode(set::ByteSet)
labels = collect(set)
labels′ = UnitRange{UInt8}[]
while !isempty(labels)
lo = shift!(labels)
lo = popfirst!(labels)
hi = lo
while !isempty(labels) && first(labels) == hi + 1
hi = shift!(labels)
hi = popfirst!(labels)
end
push!(labels′, lo:hi)
end
Expand Down
4 changes: 2 additions & 2 deletions src/codegen.jl
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ function generate_exec_code(ctx::CodeGenContext, machine::Machine, actions=nothi
actions = Dict{Symbol,Expr}()
elseif actions == :debug
actions = debug_actions(machine)
elseif isa(actions, Associative{Symbol,Expr})
elseif isa(actions, AbstractDict{Symbol,Expr})
actions = Dict{Symbol,Expr}(collect(actions))
else
throw(ArgumentError("invalid actions argument"))
Expand Down Expand Up @@ -181,7 +181,7 @@ function generate_table_code(ctx::CodeGenContext, machine::Machine, actions::Dic
end

function generate_transition_table(machine::Machine)
trans_table = Matrix{Int}(256, length(machine.states))
trans_table = Matrix{Int}(uninitialized, 256, length(machine.states))
for j in 1:size(trans_table, 2)
trans_table[:,j] = -j
end
Expand Down
11 changes: 6 additions & 5 deletions src/dfa.jl
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ function DFANode(final::Bool, nodes::Set{NFANode})
end

function Base.show(io::IO, node::DFANode)
print(io, summary(node), "(<", length(node.edges), " edges", '@', object_id(node), ">)")
print(io, summary(node), "(<", length(node.edges), " edges", '@', objectid(node), ">)")
end

struct DFA
Expand All @@ -28,7 +28,7 @@ end
function validate(dfa::DFA)
is_non_deterministic(e1, e2) = !(isdisjoint(e1.labels, e2.labels) || conflicts(e1.precond, e2.precond))
for s in traverse(dfa.start)
for i in 1:endof(s.edges), j in 1:i-1
for i in 1:lastindex(s.edges), j in 1:i-1
ei = s.edges[i][1]
ej = s.edges[j][1]
if overlaps(ei, ej)
Expand Down Expand Up @@ -190,7 +190,8 @@ function remove_redundant_preconds(names::Vector{Symbol}, pvs::Vector{UInt64})
left = length(names)
for name in names
sort!(pvs)
k = findfirst(pv -> bitat(pv, left), pvs)
fnd = findfirst(pv -> bitat(pv, left), pvs)
k = ifelse(fnd == nothing, 0, fnd) # TODO: See if there is a more elegant way of doing this.
if (k - 1) * 2 == length(pvs)
redundant = true
for i in 1:k-1
Expand All @@ -205,13 +206,13 @@ function remove_redundant_preconds(names::Vector{Symbol}, pvs::Vector{UInt64})
end
if redundant
left -= 1
for i in 1:endof(pvs)
for i in 1:lastindex(pvs)
# remove the redundant bit
pvs[i] = pvs[i] & mask(left)
end
else
push!(newnames, name)
for i in 1:endof(pvs)
for i in 1:lastindex(pvs)
# circular left shift
pvs[i] = ((pvs[i] << 1) & mask(left)) | bitat(pvs[i], left)
end
Expand Down
2 changes: 1 addition & 1 deletion src/memory.jl
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ function Base.getindex(mem::SizedMemory, i::Integer)
return unsafe_load(mem.ptr, i)
end

function Base.endof(mem::SizedMemory)
function Compat.lastindex(mem::SizedMemory)
return Int(mem.len)
end

Expand Down
2 changes: 1 addition & 1 deletion src/nfa.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ function NFANode()
end

function Base.show(io::IO, node::NFANode)
print(io, summary(node), "(<", length(node.edges), " edges", '@', object_id(node), ">)")
print(io, summary(node), "(<", length(node.edges), " edges", '@', objectid(node), ">)")
end

struct NFA
Expand Down
4 changes: 2 additions & 2 deletions src/precond.jl
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ end
function Base.push!(precond::Precondition, kv::Pair{Symbol,Value})
name, value = kv
i = findfirst(n -> n == name, precond.names)
if i == 0
if i == nothing
push!(precond.names, name)
push!(precond.values, value)
else
Expand Down Expand Up @@ -74,7 +74,7 @@ function Base.start(precond::Precondition)
end

function Base.done(precond::Precondition, i)
return i > endof(precond.names)
return i > lastindex(precond.names)
end

function Base.next(precond::Precondition, i)
Expand Down
Loading

0 comments on commit 01ff5f2

Please sign in to comment.