(;module: lux (lux [io] (concurrency ["A" atom]) (data ["R" result] (coll ["d" dict]) text/format) [host #+ jvm-import]) (luxc (generator (host ["$" jvm] (jvm ["$t" type] ["$d" def] ["$i" inst]))))) ## [Host] (jvm-import org.objectweb.asm.Opcodes (#static V1_6 int)) (jvm-import java.lang.Object) (jvm-import (java.lang.Class a)) (jvm-import java.lang.ClassLoader (loadClass [String] (Class Object))) ## [Types] (type: #export Bytecode host;Byte-Array) (type: #export Class-Store (A;Atom (d;Dict Text Bytecode))) (type: #export Host {#loader ClassLoader #store Class-Store}) (def: #export (store-class name byte-code) (-> Text Bytecode (Lux Unit)) (function [compiler] (let [store (|> (get@ #;host compiler) (:! Host) (get@ #store))] (if (d;contains? name (|> store A;get io;run)) (#R;Error (format "Cannot store class that already exists: " name)) (#R;Success [compiler (io;run (A;update (d;put name byte-code) store))]) )))) (def: #export (load-class name) (-> Text (Lux (Class Object))) (function [compiler] (let [host (:! Host (get@ #;host compiler)) store (|> host (get@ #store) A;get io;run)] (if (d;contains? name store) (#R;Success [compiler (ClassLoader.loadClass [name] (get@ #loader host))]) (#R;Error (format "Unknown class: " name)))))) (def: #export bytecode-version Int Opcodes.V1_6)