diff options
author | Eduardo Julian | 2019-12-24 23:05:30 -0400 |
---|---|---|
committer | Eduardo Julian | 2019-12-24 23:05:30 -0400 |
commit | fa37f5d17184db1ed95949352e71542af8fb4ce1 (patch) | |
tree | c75422049da941ea1f0e61d72b263cb38ed072e2 /new-luxc/source/luxc/lang/packager.lux | |
parent | 2690a6ba8ff7998f8dbb778b93fa22976eadb4ac (diff) |
Ported program generation, host environment and packaging machinery to stdlib.
Diffstat (limited to 'new-luxc/source/luxc/lang/packager.lux')
-rw-r--r-- | new-luxc/source/luxc/lang/packager.lux | 112 |
1 files changed, 0 insertions, 112 deletions
diff --git a/new-luxc/source/luxc/lang/packager.lux b/new-luxc/source/luxc/lang/packager.lux deleted file mode 100644 index d72506da2..000000000 --- a/new-luxc/source/luxc/lang/packager.lux +++ /dev/null @@ -1,112 +0,0 @@ -(.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) -## https://en.wikipedia.org/wiki/Kibibyte -(def: kibi-byte (n.* 1,024 byte)) -## https://en.wikipedia.org/wiki/Mebibyte -(def: mebi-byte (n.* 1,024 kibi-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 ..mebi-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)))) |