Skip to content

Commit

Permalink
remove deprecated functions of codegen (#30)
Browse files Browse the repository at this point in the history
  • Loading branch information
bicycle1885 authored Mar 6, 2018
1 parent 01ff5f2 commit 6dbf580
Show file tree
Hide file tree
Showing 3 changed files with 0 additions and 263 deletions.
34 changes: 0 additions & 34 deletions src/codegen.jl
Original file line number Diff line number Diff line change
Expand Up @@ -84,24 +84,6 @@ function CodeGenContext(;
return CodeGenContext(vars, generator, checkbounds, loopunroll, getbyte, clean)
end

"""
generate_init_code(machine)
Generate variable initialization code.
The generated code is equivalent to:
```julia
p::Int = 1
p_end::Int = 0
p_eof::Int = -1
cs::Int = <start state of machine>
```
"""
function generate_init_code(machine::Machine)
warn("this method is deprecated; use `generate_init_code(::CodeGenContext, ::Machine)`", once=true, key=generate_init_code)
return generate_init_code(CodeGenContext(), machine)
end

"""
generate_init_code(context::CodeGenContext, machine::Machine)::Expr
Expand All @@ -116,22 +98,6 @@ function generate_init_code(ctx::CodeGenContext, machine::Machine)
end
end

function generate_exec_code(
machine::Machine;
actions=nothing,
code::Symbol=:table,
check::Bool=true,
clean::Bool=false,
getbyte::Function=Base.getindex)
warn("this method is deprecated; use `generate_exec_code(::CodeGenContext, ::Machine)`", once=true, key=generate_exec_code)
ctx = CodeGenContext(
generator=code,
checkbounds=check,
getbyte=getbyte,
clean=clean)
return generate_exec_code(ctx, machine, actions)
end

"""
generate_exec_code(ctx::CodeGenContext, machine::Machine, actions=nothing)::Expr
Expand Down
5 changes: 0 additions & 5 deletions src/tokenizer.jl
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,6 @@ function generate_init_code(ctx::CodeGenContext, tokenizer::Tokenizer)
end
end

function generate_exec_code(tokenizer::Tokenizer; actions=nothing)
warn("this method is deprecated; use `generate_exec_code(::CodeGenContext, ::Tokenizer)`", once=true, key=generate_exec_code)
return generate_exec_code(CodeGenContext(), tokenizer, actions)
end

function generate_exec_code(ctx::CodeGenContext, tokenizer::Tokenizer, actions=nothing)
if actions == nothing
actions = Dict{Symbol,Expr}()
Expand Down
224 changes: 0 additions & 224 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -149,227 +149,3 @@ end
(:newline,"\n")]
end
end


# TODO: The follwoing tests are written using the deprecated syntax; should be
# removed in the future.

module Test1
import Automa
import Automa.RegExp: @re_str
import Compat: lastindex

if VERSION >= v"0.7-"
using Test
else
using Base.Test
end

re = re""

re.actions[:enter] = [:enter_re]
re.actions[:exit] = [:exit_re]

machine = Automa.compile(re)
@test ismatch(r"^Automa.Machine\(<.*>\)$", repr(machine))

last, actions = Automa.execute(machine, "")
@test last == 0
@test actions == [:enter_re, :exit_re]
last, actions = Automa.execute(machine, "a")
@test last < 0
@test actions == []

init_code = Automa.generate_init_code(machine)
exec_code = Automa.generate_exec_code(machine, actions=:debug)

@eval function validate(data)
logger = Symbol[]
$(init_code)
p_end = p_eof = lastindex(data)
$(exec_code)
return cs == 0, logger
end

@test validate(b"") == (true, [:enter_re, :exit_re])
@test validate(b"a") == (false, Symbol[])

# inlined code
exec_code = Automa.generate_exec_code(machine, actions=:debug, code=:inline)
@eval function validate2(data)
logger = Symbol[]
$(init_code)
p_end = p_eof = lastindex(data)
$(exec_code)
return cs == 0, logger
end
@test validate2(b"") == (true, [:enter_re, :exit_re])
@test validate2(b"a") == (false, Symbol[])

# goto code
exec_code = Automa.generate_exec_code(machine, actions=:debug, code=:goto)
@eval function validate3(data)
logger = Symbol[]
$(init_code)
p_end = p_eof = lastindex(data)
$(exec_code)
return cs == 0, logger
end
@test validate3(b"") == (true, [:enter_re, :exit_re])
@test validate3(b"a") == (false, Symbol[])
end

module Test2
import Automa
import Automa.RegExp: @re_str
const re = Automa.RegExp
import Compat: lastindex

if VERSION >= v"0.7-"
using Test
else
using Base.Test
end

a = re.rep('a')
b = re.cat('b', re.rep('b'))
ab = re.cat(a, b)

a.actions[:enter] = [:enter_a]
a.actions[:exit] = [:exit_a]
a.actions[:final] = [:final_a]
b.actions[:enter] = [:enter_b]
b.actions[:exit] = [:exit_b]
b.actions[:final] = [:final_b]
ab.actions[:enter] = [:enter_re]
ab.actions[:exit] = [:exit_re]
ab.actions[:final] = [:final_re]

machine = Automa.compile(ab)

last, actions = Automa.execute(machine, "ab")
@test last == 0
@test actions == [:enter_re,:enter_a,:final_a,:exit_a,:enter_b,:final_b,:final_re,:exit_b,:exit_re]

init_code = Automa.generate_init_code(machine)
exec_code = Automa.generate_exec_code(machine, actions=:debug)

@eval function validate(data)
logger = Symbol[]
$(init_code)
p_end = p_eof = lastindex(data)
$(exec_code)
return cs == 0, logger
end

@test validate(b"b") == (true, [:enter_re,:enter_a,:exit_a,:enter_b,:final_b,:final_re,:exit_b,:exit_re])
@test validate(b"a") == (false, [:enter_re,:enter_a,:final_a])
@test validate(b"ab") == (true, [:enter_re,:enter_a,:final_a,:exit_a,:enter_b,:final_b,:final_re,:exit_b,:exit_re])
@test validate(b"abb") == (true, [:enter_re,:enter_a,:final_a,:exit_a,:enter_b,:final_b,:final_re,:final_b,:final_re,:exit_b,:exit_re])

# inlined code
exec_code = Automa.generate_exec_code(machine, actions=:debug, code=:inline)
@eval function validate2(data)
logger = Symbol[]
$(init_code)
p_end = p_eof = lastindex(data)
$(exec_code)
return cs == 0, logger
end
@test validate2(b"b") == (true, [:enter_re,:enter_a,:exit_a,:enter_b,:final_b,:final_re,:exit_b,:exit_re])
@test validate2(b"a") == (false, [:enter_re,:enter_a,:final_a])
@test validate2(b"ab") == (true, [:enter_re,:enter_a,:final_a,:exit_a,:enter_b,:final_b,:final_re,:exit_b,:exit_re])
@test validate2(b"abb") == (true, [:enter_re,:enter_a,:final_a,:exit_a,:enter_b,:final_b,:final_re,:final_b,:final_re,:exit_b,:exit_re])

# goto code
exec_code = Automa.generate_exec_code(machine, actions=:debug, code=:goto)
@eval function validate3(data)
logger = Symbol[]
$(init_code)
p_end = p_eof = lastindex(data)
$(exec_code)
return cs == 0, logger
end
@test validate3(b"b") == (true, [:enter_re,:enter_a,:exit_a,:enter_b,:final_b,:final_re,:exit_b,:exit_re])
@test validate3(b"a") == (false, [:enter_re,:enter_a,:final_a])
@test validate3(b"ab") == (true, [:enter_re,:enter_a,:final_a,:exit_a,:enter_b,:final_b,:final_re,:exit_b,:exit_re])
@test validate3(b"abb") == (true, [:enter_re,:enter_a,:final_a,:exit_a,:enter_b,:final_b,:final_re,:final_b,:final_re,:exit_b,:exit_re])
end

module Test3
import Automa
import Automa.RegExp: @re_str
const re = Automa.RegExp
import Compat: lastindex
if VERSION >= v"0.7-"
using Test
else
using Base.Test
end

header = re"[ -~]*"
newline = re"\r?\n"
sequence = re.rep(re.cat(re"[A-Za-z]*", newline))
fasta = re.rep(re.cat('>', header, newline, sequence))

machine = Automa.compile(fasta)
init_code = Automa.generate_init_code(machine)
exec_code = Automa.generate_exec_code(machine)

@eval function validate(data)
$(init_code)
p_end = p_eof = lastindex(data)
$(exec_code)
return cs == 0
end

@test validate(b"") == true
@test validate(b">\naa\n") == true
@test validate(b">seq1\n") == true
@test validate(b">seq1\na\n") == true
@test validate(b">seq1\nac\ngt\n") == true
@test validate(b">seq1\r\nacgt\r\n") == true
@test validate(b">seq1\nac\n>seq2\ngt\n") == true
@test validate(b"a") == false
@test validate(b">") == false
@test validate(b">seq1\na") == false
@test validate(b">seq1\nac\ngt") == false

exec_code = Automa.generate_exec_code(machine, code=:inline)
@eval function validate2(data)
$(init_code)
p_end = p_eof = lastindex(data)
$(exec_code)
return cs == 0
end
@test validate2(b"") == true
@test validate2(b">\naa\n") == true
@test validate2(b">seq1\n") == true
@test validate2(b">seq1\na\n") == true
@test validate2(b">seq1\nac\ngt\n") == true
@test validate2(b">seq1\r\nacgt\r\n") == true
@test validate2(b">seq1\nac\n>seq2\ngt\n") == true
@test validate2(b"a") == false
@test validate2(b">") == false
@test validate2(b">seq1\na") == false
@test validate2(b">seq1\nac\ngt") == false

exec_code = Automa.generate_exec_code(machine, code=:goto)
@eval function validate3(data)
$(init_code)
p_end = p_eof = lastindex(data)
$(exec_code)
return cs == 0
end
@test validate3(b"") == true
@test validate3(b">\naa\n") == true
@test validate3(b">seq1\n") == true
@test validate3(b">seq1\na\n") == true
@test validate3(b">seq1\nac\ngt\n") == true
@test validate3(b">seq1\r\nacgt\r\n") == true
@test validate3(b">seq1\nac\n>seq2\ngt\n") == true
@test validate3(b"a") == false
@test validate3(b">") == false
@test validate3(b">seq1\na") == false
@test validate3(b">seq1\nac\ngt") == false
end

0 comments on commit 6dbf580

Please sign in to comment.