Skip to content

Commit

Permalink
remove unused things, document things
Browse files Browse the repository at this point in the history
  • Loading branch information
thofma committed Oct 26, 2024
1 parent 908a929 commit 88705c4
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 70 deletions.
8 changes: 1 addition & 7 deletions src/macro.jl
Original file line number Diff line number Diff line change
Expand Up @@ -84,13 +84,7 @@ macro resumable(ex::Expr...)
func_def[:body] = postwalk(transform_yieldfrom, func_def[:body])
func_def[:body] = postwalk(x->transform_for(x, ui8), func_def[:body])
@debug func_def[:body]|>MacroTools.striplines
#func_def[:body] = postwalk(x->transform_macro(x), func_def[:body])
#@debug func_def[:body]|>MacroTools.striplines
#func_def[:body] = postwalk(x->transform_macro_undo(x), func_def[:body])
#@debug func_def[:body]|>MacroTools.striplines
#func_def[:body] = postwalk(x->transform_let(x), func_def[:body])
#@info func_def[:body]|>MacroTools.striplines
#func_def[:body] = postwalk(x->transform_local(x), func_def[:body])

# Scoping fixes

# :name is :(fA::A) if it is an overloading call function (fA::A)(...)
Expand Down
64 changes: 3 additions & 61 deletions src/transforms.jl
Original file line number Diff line number Diff line change
@@ -1,20 +1,11 @@
"""
Function that removes `local x` expression.
"""
function transform_remove_local(ex)
ex isa Expr && ex.head === :local && return Expr(:block)
return ex
end

function transform_macro(ex)
ex isa Expr || return ex
ex.head !== :macrocall && return ex
return Expr(:call, :__secret__, ex.args)
end

function transform_macro_undo(ex)
ex isa Expr || return ex
(ex.head !== :call || ex.args[1] !== :__secret__) && return ex
return Expr(:macrocall, ex.args[2]...)
end

"""
Function that replaces a variable
"""
Expand Down Expand Up @@ -152,55 +143,6 @@ function transform_slots(expr, symbols)
expr
end

#"""
#Function that handles `let` block
#"""
#function transform_slots_let(expr::Expr, symbols)
# @capture(expr, let vars_; body_ end)
# locals = Set{Symbol}()
# (isa(vars, Expr) && vars.head==:(=)) || error("@resumable currently supports only single variable declarations in let blocks, i.e. only let blocks exactly of the form `let i=j; ...; end`. If you need multiple variables, please submit an issue on the issue tracker and consider contributing a patch.")
# sym = vars.args[1].args[2].value
# push!(locals, sym)
# vars.args[1] = sym
# body = postwalk(x->transform_let(x, locals), :(begin $(body) end))
# :(let $vars; $body end)
#end

function transform_let(expr)
expr isa Expr || return expr
expr.head === :block && return expr
#@info "inside transform let"
@capture(expr, let arg_; body_; end) || return expr
#@info "captured let"
#arg |> dump
#@info expr
#@info arg
#error("ASds")
res = quote
let
local $arg
$body
end
end
#@info "emitting $res"
res
#expr.head === :. || return expr
#expr = expr.args[2].value in symbols ? :($(expr.args[2].value)) : expr
end

"""
Function that replaces a variable `_fsmi.x` in an expression by `x` where `x` is a variable declared in a `let` block.
"""
function transform_local(expr)
expr isa Expr || return expr
@capture(expr, local arg_ = ex_) || return expr
res = quote
local $arg
$arg = $ex
end
res
end

"""
Function that replaces a `arg = @yield ret` statement by
```julia
Expand Down
2 changes: 1 addition & 1 deletion src/utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ end
# inside the current scope.
#
# We exploit this when rewriting let and for constructions, see below for
# examples with let.
# examples with let. At the end, all `local x` are removed.

mutable struct ScopeTracker
i::Int
Expand Down
1 change: 0 additions & 1 deletion test/test_main.jl
Original file line number Diff line number Diff line change
Expand Up @@ -440,4 +440,3 @@ end
end
@test collect(test_weird_for(3)) == [(1, 1), (2, 1), (2, 2), (3, 1), (3, 2), (3, 3)]
end
end

0 comments on commit 88705c4

Please sign in to comment.