(.module: [lux #* ["@" target] ["." host (#+ import:)] [abstract [monad (#+ do)]] [control ["." io (#+ IO)] ["." try (#+ Try)] [parser [cli (#+ program:)]]] [data [collection [array (#+ Array)] ["." dictionary]]] [world ["." file]] [target [jvm ["$t" type]]] [tool [compiler [phase ["." macro (#+ Expander)] ["." extension #_ [analysis ["#" jvm]]]] [default ["." platform (#+ Platform)]]]]] [program ["/" compositor ["/." cli]]] [luxc [lang [host ["_" jvm ["$d" def] ["$i" inst]]] [directive [".S" jvm]] [translation ["." jvm ["." runtime] ["." expression] [procedure [".E" common] [".E" host]]]]]]) (import: #long java/lang/reflect/Method (invoke [java/lang/Object [java/lang/Object]] #try java/lang/Object)) (import: #long (java/lang/Class c) (getMethod [java/lang/String [(java/lang/Class java/lang/Object)]] #try java/lang/reflect/Method)) (import: #long java/lang/Object (getClass [] (java/lang/Class java/lang/Object))) (def: _object-class (java/lang/Class java/lang/Object) (host.class-for java/lang/Object)) (def: _apply-args (Array (java/lang/Class java/lang/Object)) (|> (host.array (java/lang/Class java/lang/Object) 2) (host.array-write 0 _object-class) (host.array-write 1 _object-class))) (def: #export (expander macro inputs lux) Expander (do try.monad [apply-method (|> macro (:coerce java/lang/Object) (java/lang/Object::getClass) (java/lang/Class::getMethod "apply" _apply-args))] (:coerce (Try (Try [Lux (List Code)])) (java/lang/reflect/Method::invoke (:coerce java/lang/Object macro) (|> (host.array java/lang/Object 2) (host.array-write 0 (:coerce java/lang/Object inputs)) (host.array-write 1 (:coerce java/lang/Object lux))) apply-method)))) (def: #export jvm (IO (Platform IO _.Anchor _.Inst _.Definition)) (do io.monad [host jvm.host] (wrap {#platform.&monad io.monad #platform.&file-system file.system #platform.host host #platform.phase expression.translate #platform.runtime runtime.translate}))) (def: #export (program programI) (-> _.Inst _.Definition) (let [$Object ($t.class "java.lang.Object" (list)) nilI runtime.noneI num-inputsI (|>> ($i.ALOAD 0) $i.ARRAYLENGTH) decI (|>> ($i.int +1) $i.ISUB) headI (|>> $i.DUP ($i.ALOAD 0) $i.SWAP $i.AALOAD $i.SWAP $i.DUP_X2 $i.POP) pairI (|>> ($i.int +2) ($i.ANEWARRAY $Object) $i.DUP_X1 $i.SWAP ($i.int +0) $i.SWAP $i.AASTORE $i.DUP_X1 $i.SWAP ($i.int +1) $i.SWAP $i.AASTORE) consI (|>> ($i.int +1) ($i.string "") $i.DUP2_X1 $i.POP2 runtime.variantI) prepare-input-listI (<| $i.with-label (function (_ @loop)) $i.with-label (function (_ @end)) (|>> nilI num-inputsI ($i.label @loop) decI $i.DUP ($i.IFLT @end) headI pairI consI $i.SWAP ($i.GOTO @loop) ($i.label @end) $i.POP ($i.ASTORE 0))) run-ioI (|>> ($i.CHECKCAST jvm.$Function) $i.NULL ($i.INVOKEVIRTUAL jvm.$Function runtime.apply-method (runtime.apply-signature 1))) main-type ($t.method [(list ($t.array ($t.class "java.lang.String" (list)))) $t.void (list)]) bytecode-name "_"] [bytecode-name ($d.class #_.V1_6 #_.Public _.finalC bytecode-name (list) $Object (list) (|>> ($d.method #_.Public _.staticM "main" main-type (|>> prepare-input-listI programI run-ioI $i.POP $i.RETURN))))])) (def: #export bundle _.Bundle (dictionary.merge commonE.bundle hostE.bundle)) (program: [{service /cli.service}] (/.compiler @.jvm ".jvm" ..expander extension.bundle ..jvm ..bundle jvmS.bundle ..program service))