tk3369 / ContextTracking.jl
Showing 2 of 4 files from the diff.

@@ -10,15 +10,16 @@
Loading
10 10
macro ctx(ex, label = nothing)
11 11
    def = splitdef(ex)
12 12
    name = QuoteNode(label !== nothing ? Symbol(label) : def[:name])
13 +
    ctx = gensym()
13 14
    def[:body] = quote
14 -
        c = ContextTracking.context()
15 +
        $ctx = ContextTracking.context()
15 16
        try
16 -
            save(c)
17 -
            push!(c.path, $name)
17 +
            ContextTracking.save($ctx)
18 +
            push!($ctx.path, $name)
18 19
            $(def[:body])
19 20
        finally
20 -
            pop!(c.path)
21 -
            restore(c)
21 +
            pop!($ctx.path)
22 +
            ContextTracking.restore($ctx)
22 23
        end
23 24
    end
24 25
    return esc(combinedef(def))
@@ -41,8 +42,9 @@
Loading
41 42
        error("@memo must be followed by an assignment or a variable name.")
42 43
    end
43 44
    sym = QuoteNode(x)
44 -
    return quote
45 -
        val = $(esc(ex))
46 -
        push!(ContextTracking.context(), $sym => val)
47 -
    end
45 +
    val = gensym()
46 +
    return esc(quote
47 +
        $val = $ex
48 +
        push!(ContextTracking.context(), $sym => $val)
49 +
    end)
48 50
end

@@ -6,7 +6,7 @@
Loading
6 6
using ExprTools: combinedef, splitdef
7 7
8 8
export Context
9 -
export context, save, restore
9 +
export context
10 10
export @ctx, @memo
11 11
12 12
include("types.jl")
Files Coverage
src 93.75%
Project Totals (5 files) 93.75%