(;module: lux (lux (concurrency ["A" atom]) (data ["R" result] (coll ["D" dict])) [macro] [host #+ jvm-import])) ## [Host] (jvm-import org.objectweb.asm.MethodVisitor (visitLdcInsn [Object] void)) (jvm-import java.lang.ClassLoader) ## [Types] (type: #export Compiled Unit) (type: #export Blob host;Byte-Array) (type: #export Class-Store (A;Atom (D;Dict Text Blob))) (type: #export Host {#visitor (Maybe MethodVisitor) #loader ClassLoader #store Class-Store}) (def: #export unit-value Text "\u0000unit\u0000") (def: (visitor::get compiler) (-> Compiler (Maybe MethodVisitor)) (|> (get@ #;host compiler) (:! Host) (get@ #visitor))) (def: (visitor::put ?visitor compiler) (-> (Maybe MethodVisitor) Compiler Compiler) (update@ #;host (function [host] (|> host (:! Host) (set@ #visitor ?visitor) (:! Void))) compiler)) (def: #export get-visitor (Lux MethodVisitor) (function [compiler] (case (visitor::get compiler) #;None (#R;Error "No visitor has been set.") (#;Some visitor) (#R;Success [compiler visitor])))) (def: #export (with-visitor visitor body) (All [a] (-> MethodVisitor (Lux a) (Lux a))) (function [compiler] (case (macro;run' (visitor::put (#;Some visitor) compiler) body) (#R;Error error) (#R;Error error) (#R;Success [compiler' output]) (#R;Success [(visitor::put (visitor::get compiler) compiler') output]))))