aboutsummaryrefslogtreecommitdiff
path: root/new-luxc
diff options
context:
space:
mode:
authorEduardo Julian2020-05-16 20:19:34 -0400
committerEduardo Julian2020-05-16 20:19:34 -0400
commit9965c551e7ccd6de8c47c7b1b78f804801810dac (patch)
tree05538c6ede048898f375ce3a333a2c4dd6b6f4a7 /new-luxc
parent65d0beab4cb53a9ba8574e1133d105420f0b23aa (diff)
Parallel compilation for the new compiler(s).
Diffstat (limited to 'new-luxc')
-rw-r--r--new-luxc/source/luxc/lang/translation/js/imports.jvm.lux69
-rw-r--r--new-luxc/source/luxc/lang/translation/jvm/imports.jvm.lux154
-rw-r--r--new-luxc/source/program.lux20
3 files changed, 9 insertions, 234 deletions
diff --git a/new-luxc/source/luxc/lang/translation/js/imports.jvm.lux b/new-luxc/source/luxc/lang/translation/js/imports.jvm.lux
deleted file mode 100644
index 575650457..000000000
--- a/new-luxc/source/luxc/lang/translation/js/imports.jvm.lux
+++ /dev/null
@@ -1,69 +0,0 @@
-(.module:
- lux
- (lux (control [monad #+ do]
- ["p" parser]
- ["ex" exception #+ exception:])
- (data ["e" error #+ Error]
- [maybe]
- [text "text/" Eq<Text>]
- text/format)
- [macro]
- (macro [code]
- ["s" syntax])
- [io #+ Process])
- (luxc [lang]
- (lang [".L" module])))
-
-(do-template [<name>]
- [(exception: #export (<name> {message Text})
- message)]
-
- [Invalid-Imports]
- [Module-Cannot-Import-Itself]
- [Circular-Dependency]
- )
-
-(type: Import
- {#module Text
- #alias Text})
-
-(def: import (s.Syntax Import) (s.tuple (p.seq s.text s.text)))
-
-(def: #export (translate-imports translate-module annotations)
- (-> (-> Text Lux (Process Lux))
- Code
- (Meta (Process Lux)))
- (do macro.Monad<Meta>
- [_ (moduleL.set-annotations annotations)
- current-module macro.current-module-name
- imports (let [imports (|> (macro.get-tuple-ann (name-of #.imports) annotations)
- (maybe.default (list)))]
- (case (s.run imports (p.some import))
- (#e.Success imports)
- (wrap imports)
-
- (#e.Error error)
- (lang.throw Invalid-Imports (%code (code.tuple imports)))))
- _ (monad.map @ (function (_ [dependency alias])
- (do @
- [_ (lang.assert Module-Cannot-Import-Itself current-module
- (not (text/= current-module dependency)))
- already-seen? (moduleL.exists? dependency)
- circular-dependency? (if already-seen?
- (moduleL.active? dependency)
- (wrap #0))
- _ (lang.assert Circular-Dependency (format "From: " current-module "\n"
- " To: " dependency)
- (not circular-dependency?))
- _ (moduleL.import dependency)
- _ (if (text/= "" alias)
- (wrap [])
- (moduleL.alias alias dependency))]
- (wrap [])))
- imports)
- compiler macro.get-compiler]
- (wrap (monad.fold io.Monad<Process>
- (function (_ import)
- (translate-module (get@ #module import)))
- compiler
- imports))))
diff --git a/new-luxc/source/luxc/lang/translation/jvm/imports.jvm.lux b/new-luxc/source/luxc/lang/translation/jvm/imports.jvm.lux
deleted file mode 100644
index ec791019c..000000000
--- a/new-luxc/source/luxc/lang/translation/jvm/imports.jvm.lux
+++ /dev/null
@@ -1,154 +0,0 @@
-(.module:
- lux
- (lux (control [monad #+ do]
- ["p" parser]
- ["ex" exception #+ exception:]
- pipe)
- (concurrency [promise #+ Promise]
- [stm #+ Var STM])
- (data ["e" error #+ Error]
- [maybe]
- [product]
- [text "text/" Eq<Text>]
- text/format
- (coll [list "list/" Functor<List> Fold<List>]
- (dictionary ["dict" unordered #+ Dict])))
- [macro]
- (macro [code]
- ["s" syntax])
- [io #+ IO Process io]
- [host])
- (luxc ["&" lang]
- (lang [".L" module])))
-
-(do-template [<name>]
- [(exception: #export (<name> {message Text})
- message)]
-
- [Invalid-Imports]
- [Module-Cannot-Import-Itself]
- [Circular-Dependency]
- )
-
-(host.import: (java/util/concurrent/Future a)
- (get [] #io a))
-
-(host.import: (java/util/concurrent/CompletableFuture a)
- (new [])
- (complete [a] boolean)
- (#static [a] completedFuture [a] (CompletableFuture a)))
-
-(type: Import
- {#module Text
- #alias Text})
-
-(def: import (s.Syntax Import) (s.tuple (p.seq s.text s.text)))
-
-(def: compilations
- (Var (Dict Text (CompletableFuture (Error Lux))))
- (stm.var (dict.new text.Hash<Text>)))
-
-(def: (promise-to-future promise)
- (All [a] (-> (Promise a) (Future a)))
- (let [future (CompletableFuture::new [])]
- (exec (:: promise.Functor<Promise> map
- (function (_ value) (CompletableFuture::complete [value] future))
- promise)
- future)))
-
-(def: from-io
- (All [a] (-> (IO a) (Process a)))
- (:: io.Monad<IO> map (|>> #e.Success)))
-
-(def: (translate-dependency translate-module dependency compiler)
- (-> (-> Text Lux (Process Lux))
- (-> Text Lux (IO (Future (Error Lux)))))
- (<| (Future::get [])
- promise-to-future
- (do promise.Monad<Promise>
- [[new? future] (stm.commit (: (STM [Bit (CompletableFuture (Error Lux))])
- (do stm.Monad<STM>
- [current-compilations (stm.read compilations)]
- (case (dict.get dependency current-compilations)
- (#.Some ongoing)
- (wrap [#0 ongoing])
-
- #.None
- (do @
- [#let [pending (: (CompletableFuture (Error Lux))
- (CompletableFuture::new []))]
- _ (stm.write (dict.put dependency pending current-compilations)
- compilations)]
- (wrap [#1 pending]))))))]
- (if new?
- (exec (promise.future (io (CompletableFuture::complete [(io.run (translate-module dependency compiler))]
- future)))
- (wrap future))
- (wrap future)))))
-
-(def: compiled?
- (-> Module Bit)
- (|>> (get@ #.module-state)
- (case>
- (^or #.Cached #.Compiled)
- #1
-
- _
- #0)))
-
-(def: (merge-modules current-module from-dependency from-current)
- (-> Text (List [Text Module]) (List [Text Module]) (List [Text Module]))
- (|> from-dependency
- (list.filter (|>> product.right compiled?))
- (list/fold (function (_ [dep-name dep-module] total) (&.pl-put dep-name dep-module total))
- from-current)))
-
-(def: (merge-compilers current-module dependency total)
- (-> Text Lux Lux Lux)
- (|> total
- (update@ #.modules (merge-modules current-module (get@ #.modules dependency)))
- (set@ #.seed (get@ #.seed dependency))))
-
-(def: #export (translate-imports translate-module annotations)
- (-> (-> Text Lux (Process Lux))
- Code
- (Meta (Process Lux)))
- (do macro.Monad<Meta>
- [_ (moduleL.set-annotations annotations)
- current-module macro.current-module-name
- imports (let [imports (|> (macro.get-tuple-ann (name-of #.imports) annotations)
- (maybe.default (list)))]
- (case (s.run imports (p.some import))
- (#e.Success imports)
- (wrap imports)
-
- (#e.Error error)
- (&.throw Invalid-Imports (%code (code.tuple imports)))))
- dependencies (monad.map @ (: (-> [Text Text] (Meta (IO (Future (Error Lux)))))
- (function (_ [dependency alias])
- (do @
- [_ (&.assert Module-Cannot-Import-Itself current-module
- (not (text/= current-module dependency)))
- already-seen? (moduleL.exists? dependency)
- circular-dependency? (if already-seen?
- (moduleL.active? dependency)
- (wrap #0))
- _ (&.assert Circular-Dependency (format "From: " current-module "\n"
- " To: " dependency)
- (not circular-dependency?))
- _ (moduleL.import dependency)
- _ (if (text/= "" alias)
- (wrap [])
- (moduleL.alias alias dependency))
- compiler macro.get-compiler]
- (if already-seen?
- (wrap (io (CompletableFuture::completedFuture [(#e.Success compiler)])))
- (wrap (translate-dependency translate-module dependency compiler))))))
- imports)
- compiler macro.get-compiler]
- (wrap (do io.Monad<Process>
- [dependencies (monad.seq io.Monad<Process> (list/map from-io dependencies))
- dependencies (|> dependencies
- (list/map (Future::get []))
- (monad.seq io.Monad<Process>))]
- (wrap (list/fold (merge-compilers current-module) compiler dependencies))))))
diff --git a/new-luxc/source/program.lux b/new-luxc/source/program.lux
index dc293cf81..44a09d4b9 100644
--- a/new-luxc/source/program.lux
+++ b/new-luxc/source/program.lux
@@ -48,7 +48,8 @@
]]]]]]]]
[program
["/" compositor
- ["/." cli]]]
+ ["/." cli]
+ ["/." static]]]
[luxc
[lang
[host
@@ -146,23 +147,20 @@
(host.array-write 3 (:coerce java/lang/Object state)))
method))))
-(program: [{service /cli.service}]
- (let [(^slots [#/cli.target #/cli.module]) (case service
- (#/cli.Compilation configuration) configuration
- (#/cli.Interpretation configuration) configuration)
- jar-path (format target (:: file.system separator) "program.jar")]
- (exec (/.compiler target
- ".jvm"
+(program: [{configuration /cli.configuration}]
+ (let [jar-path (format (get@ #/cli.target configuration) (:: file.system separator) "program.jar")]
+ (exec (/.compiler {#/static.host @.jvm
+ #/static.host-module-extension ".jvm"
+ #/static.target (get@ #/cli.target configuration)
+ #/static.artifact-extension ".class"}
..expander
analysis.bundle
..platform
- @.jvm
## generation.bundle
translation.bundle
(directive.bundle extender)
jvm/program.program
..extender
- service
- ".class"
+ configuration
[(packager.package jvm/program.class) jar-path])
(io.io []))))