From ea904e3dcf0ccc951b9b416de7031fc2c7cd307c Mon Sep 17 00:00:00 2001 From: AI Date: Fri, 10 Jul 2026 20:44:53 +0530 Subject: [PATCH] Draft POC for JuliaLowering FSM generation --- src/macro_lowered.jl | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 src/macro_lowered.jl diff --git a/src/macro_lowered.jl b/src/macro_lowered.jl new file mode 100644 index 0000000..296ff91 --- /dev/null +++ b/src/macro_lowered.jl @@ -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