Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions src/macro_lowered.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
using JuliaLowering
using JuliaSyntax

macro resumable(ex)
# 1. Parse using JuliaSyntax
st = JuliaSyntax.parsestmt(JuliaLowering.SyntaxTree, string(ex))

# 2. Lower
lowered = JuliaLowering.lower(__module__, st)
code = JuliaLowering.to_lowered_expr(lowered)

# 3. Extract CodeInfo
ci = nothing
if code.head === :thunk && code.args[1] isa Core.CodeInfo
for stmt in code.args[1].code
if stmt isa Expr && stmt.head === :method && length(stmt.args) >= 3 && stmt.args[3] isa Core.CodeInfo
ci = stmt.args[3]
break
end
end
end
if ci === nothing
error("Could not lower to method CodeInfo")
end

# 4. Generate the struct and stepping function from CodeInfo
# (Proof of concept)
return quote
println("Resumable FSM generated from JuliaLowering CodeInfo!")
end
end
Loading