Skip to content

Commit 952856d

Browse files
committed
Fix bugs and add tests
1 parent d035f79 commit 952856d

10 files changed

Lines changed: 101 additions & 14 deletions

File tree

src/SimJulia.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,11 @@ module SimJulia
3131
include("operators.jl")
3232
include("time.jl")
3333
include("simulation.jl")
34-
include("coroutines/utils.jl")
35-
include("coroutines/transforms.jl")
36-
include("coroutines/macro.jl")
34+
include("finitestatemachines/utils.jl")
35+
include("finitestatemachines/transforms.jl")
36+
include("finitestatemachines/macro.jl")
3737
include("coroutines.jl")
38-
include("processes/base.jl")
38+
include("tasks/base.jl")
3939
include("processes.jl")
4040
include("resources/base.jl")
4141
include("resources/containers.jl")

src/coroutines.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ function execute{E<:Environment}(ev::AbstractEvent{E}, proc::Coroutine{E})
7575
end
7676
end
7777

78-
function interrupt{E<:Environment}(proc::Coroutine{E}, cause::Any=nothing)
78+
function interrupt(proc::Coroutine, cause::Any=nothing)
7979
if !iscoroutinedone(proc.fsm)
8080
remove_callback(proc.resume, proc.target)
8181
proc.target = Timeout(environment(proc), priority=true, value=InterruptException(proc, cause))

src/processes.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,8 @@ function execute{E<:Environment}(ev::AbstractEvent{E}, proc::Process{E})
8484
end
8585
end
8686

87-
function interrupt{E<:Environment}(proc::Process{E}, cause::Any=nothing)
88-
if !istaskdone(proc.fsm)
87+
function interrupt(proc::Process, cause::Any=nothing)
88+
if !istaskdone(proc.task)
8989
remove_callback(proc.resume, proc.target)
9090
proc.target = Timeout(environment(proc), priority=true, value=InterruptException(proc, cause))
9191
proc.resume = append_callback(execute, proc.target, proc)
Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,3 @@
1-
function produce(consumer::Task, values...)
2-
ct = current_task()
3-
ct.result = length(values)==1 ? values[1] : values
4-
Base.schedule_and_wait(consumer)
5-
return consumer.result
6-
end
7-
81
function produce(v)
92
ct = current_task()
103
consumer = ct.consumers
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
using SimJulia
2+
using Base.Test
3+
4+
expr = :(begin
5+
while true
6+
@yield return a
7+
a, b = b, a+b
8+
end
9+
end)
10+
11+
slots = Dict{Symbol, Type}()
12+
slots[:a] = Float64
13+
slots[:b] = Float64
14+
slots[:c] = Float64
15+
16+
SimJulia.transformVars!(expr, keys(slots))
17+
18+
println(Base.remove_linenums!(expr))
19+
20+
expr =:(begin
21+
@yield return 1
22+
while true
23+
@yield return 2
24+
f(@yield return 3)
25+
res = @yield return 4
26+
end
27+
end)
28+
29+
@test SimJulia.transformYield!(expr) == 4
30+
31+
println(Base.remove_linenums!(expr))
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
using SimJulia
2+
using Base.Test
3+
4+
expr = :(function my_test(a, b)
5+
nothing
6+
end)
7+
8+
@test SimJulia.getArguments(expr) == Symbol[:my_test,:a,:b]
9+
10+
expr = :(function my_test(a, b) :: Any
11+
nothing
12+
end)
13+
14+
@test SimJulia.getArguments(expr) == Symbol[:my_test,:a,:b]
15+
16+
expr = :(function my_test(a, b::Float64)
17+
nothing
18+
end)
19+
20+
@test SimJulia.getArguments(expr) == Symbol[:my_test,:a,:b]
21+
22+
expr = :(function my_test(a, b=1.0)
23+
nothing
24+
end)
25+
26+
@test SimJulia.getArguments(expr) == Symbol[:my_test,:a,:b]
27+
28+
expr = :(function my_test(a, b::Float64=1.0)
29+
nothing
30+
end)
31+
32+
@test SimJulia.getArguments(expr) == Symbol[:my_test,:a,:b]
33+
34+
expr = :(function my_test(a; b=1.0)
35+
nothing
36+
end)
37+
38+
@test SimJulia.getArguments(expr) == Symbol[:my_test,:a,:b]
39+
40+
expr = :(function my_test(a; b::Float64=1.0)
41+
nothing
42+
end)
43+
44+
@test SimJulia.getArguments(expr) == Symbol[:my_test,:a,:b]
45+
46+
expr = :(function my_test(;a=0.0, b=1.0)
47+
nothing
48+
end)
49+
50+
@test SimJulia.getArguments(expr) == Symbol[:my_test,:a,:b]
51+
52+
expr = :(function my_test(a::Float64, b::Float64)
53+
c = a * b
54+
end)
55+
56+
slots = Dict{Symbol, Type}()
57+
slots[:a] = Float64
58+
slots[:b] = Float64
59+
slots[:c] = Float64
60+
61+
@test SimJulia.getSlots(expr, :my_test) == slots

test/runtests.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
testpath(f) = joinpath(dirname(@__FILE__), f)
22

33
for test_file in [
4+
"finitestatemachines/test_transforms.jl",
5+
"finitestatemachines/test_utils.jl",
46
"test_base.jl",
57
"test_events.jl",
68
"test_operators.jl",

0 commit comments

Comments
 (0)