diff options
Diffstat (limited to 'new-luxc/source/luxc/lang')
-rw-r--r-- | new-luxc/source/luxc/lang/packager.lux | 110 | ||||
-rw-r--r-- | new-luxc/source/luxc/lang/translation/jvm/extension.lux | 16 | ||||
-rw-r--r-- | new-luxc/source/luxc/lang/translation/jvm/extension/common.lux (renamed from new-luxc/source/luxc/lang/translation/jvm/procedure/common.lux) | 0 | ||||
-rw-r--r-- | new-luxc/source/luxc/lang/translation/jvm/extension/host.lux (renamed from new-luxc/source/luxc/lang/translation/jvm/procedure/host.lux) | 0 | ||||
-rw-r--r-- | new-luxc/source/luxc/lang/translation/jvm/runtime.lux | 8 |
5 files changed, 130 insertions, 4 deletions
diff --git a/new-luxc/source/luxc/lang/packager.lux b/new-luxc/source/luxc/lang/packager.lux new file mode 100644 index 000000000..f18055b18 --- /dev/null +++ b/new-luxc/source/luxc/lang/packager.lux @@ -0,0 +1,110 @@ +(.module: + [lux #* + ["." host (#+ import: do-to)] + [data + ["." binary (#+ Binary)] + ["." text] + [number + ["n" nat]] + [collection + ["." row] + ["." list ("#@." fold)]]] + [target + [jvm + [encoding + ["." name (#+ External)]]]] + [tool + [compiler + [phase + [generation (#+ Buffer Output)]] + [meta + [archive + [descriptor (#+ Module)]]]]]] + [// + [host + [jvm (#+ Definition)]]]) + +(import: #long java/lang/Object) + +(import: #long java/lang/String) + +(import: #long java/util/jar/Attributes + (put [java/lang/Object java/lang/Object] #? java/lang/Object)) + +(import: #long java/util/jar/Attributes$Name + (#static MAIN_CLASS java/util/jar/Attributes$Name) + (#static MANIFEST_VERSION java/util/jar/Attributes$Name)) + +(import: #long java/util/jar/Manifest + (new []) + (getMainAttributes [] java/util/jar/Attributes)) + +(import: #long java/io/Flushable + (flush [] void)) + +(import: #long java/io/Closeable + (close [] void)) + +(import: #long java/io/OutputStream) + +(import: #long java/io/ByteArrayOutputStream + (new [int]) + (toByteArray [] [byte])) + +(import: #long java/util/zip/ZipEntry) + +(import: #long java/util/zip/ZipOutputStream + (write [[byte] int int] void) + (closeEntry [] void)) + +(import: #long java/util/jar/JarEntry + (new [java/lang/String])) + +(import: #long java/util/jar/JarOutputStream + (new [java/io/OutputStream java/util/jar/Manifest]) + (putNextEntry [java/util/zip/ZipEntry] void)) + +(def: byte 1) +(def: kilo-byte (n.* 1,000 byte)) +(def: mega-byte (n.* 1,000 kilo-byte)) + +(def: manifest-version "1.0") + +(def: class-name + (-> Text Text) + (text.suffix ".class")) + +(def: (manifest program-class) + (-> External java/util/jar/Manifest) + (let [manifest (java/util/jar/Manifest::new)] + (exec (do-to (java/util/jar/Manifest::getMainAttributes manifest) + (java/util/jar/Attributes::put (java/util/jar/Attributes$Name::MAIN_CLASS) program-class) + (java/util/jar/Attributes::put (java/util/jar/Attributes$Name::MANIFEST_VERSION) ..manifest-version)) + manifest))) + +(def: (write-class [def-name [class-name bytecode]] sink) + (-> [Name Definition] java/util/jar/JarOutputStream java/util/jar/JarOutputStream) + (let [class-name (|> class-name name.internal name.read ..class-name)] + (do-to sink + (java/util/jar/JarOutputStream::putNextEntry (java/util/jar/JarEntry::new class-name)) + (java/util/zip/ZipOutputStream::write bytecode +0 (.int (binary.size bytecode))) + (java/io/Flushable::flush) + (java/util/zip/ZipOutputStream::closeEntry)))) + +(def: (write-module [module classes] sink) + (-> [Module (Buffer Definition)] java/util/jar/JarOutputStream java/util/jar/JarOutputStream) + (|> classes + row.to-list + (list@fold ..write-class sink))) + +(def: #export (package program-class outputs) + (-> External (Output Definition) Binary) + (let [buffer (java/io/ByteArrayOutputStream::new (.int mega-byte)) + sink (java/util/jar/JarOutputStream::new buffer (manifest program-class))] + (exec (|> outputs + row.to-list + (list@fold ..write-module sink)) + (do-to sink + (java/io/Flushable::flush) + (java/io/Closeable::close)) + (java/io/ByteArrayOutputStream::toByteArray buffer)))) diff --git a/new-luxc/source/luxc/lang/translation/jvm/extension.lux b/new-luxc/source/luxc/lang/translation/jvm/extension.lux new file mode 100644 index 000000000..9066dd156 --- /dev/null +++ b/new-luxc/source/luxc/lang/translation/jvm/extension.lux @@ -0,0 +1,16 @@ +(.module: + [lux #* + [data + [collection + ["." dictionary]]]] + [//// + [host + [jvm (#+ Bundle)]]] + ["." / #_ + ["#." common] + ["#." host]]) + +(def: #export bundle + Bundle + (dictionary.merge /common.bundle + /host.bundle)) diff --git a/new-luxc/source/luxc/lang/translation/jvm/procedure/common.lux b/new-luxc/source/luxc/lang/translation/jvm/extension/common.lux index a46813232..a46813232 100644 --- a/new-luxc/source/luxc/lang/translation/jvm/procedure/common.lux +++ b/new-luxc/source/luxc/lang/translation/jvm/extension/common.lux diff --git a/new-luxc/source/luxc/lang/translation/jvm/procedure/host.lux b/new-luxc/source/luxc/lang/translation/jvm/extension/host.lux index ca6e31bfd..ca6e31bfd 100644 --- a/new-luxc/source/luxc/lang/translation/jvm/procedure/host.lux +++ b/new-luxc/source/luxc/lang/translation/jvm/extension/host.lux diff --git a/new-luxc/source/luxc/lang/translation/jvm/runtime.lux b/new-luxc/source/luxc/lang/translation/jvm/runtime.lux index d616d62e9..f97831ac5 100644 --- a/new-luxc/source/luxc/lang/translation/jvm/runtime.lux +++ b/new-luxc/source/luxc/lang/translation/jvm/runtime.lux @@ -322,7 +322,7 @@ (def: reflection (|>> type.reflection reflection.reflection)) (def: translate-runtime - (Operation ByteCode) + (Operation Any) (let [runtime-class (..reflection //.$Runtime) bytecode ($d.class #$.V1_6 #$.Public $.finalC runtime-class (list) (type.class "java.lang.Object" (list)) (list) (|>> adt-methods @@ -331,10 +331,10 @@ io-methods))] (do phase.monad [_ (generation.execute! runtime-class [runtime-class bytecode])] - (wrap bytecode)))) + (generation.save! false ["" runtime-class] [runtime-class bytecode])))) (def: translate-function - (Operation ByteCode) + (Operation Any) (let [applyI (|> (list.n/range 2 num-apply-variants) (list@map (function (_ arity) ($d.method #$.Public $.noneM apply-method (apply-signature arity) @@ -363,7 +363,7 @@ applyI))] (do phase.monad [_ (generation.execute! function-class [function-class bytecode])] - (wrap bytecode)))) + (generation.save! false ["" function-class] [function-class bytecode])))) (def: #export translate (Operation Any) |