From 9965c551e7ccd6de8c47c7b1b78f804801810dac Mon Sep 17 00:00:00 2001 From: Eduardo Julian Date: Sat, 16 May 2020 20:19:34 -0400 Subject: Parallel compilation for the new compiler(s). --- .../luxc/lang/translation/js/imports.jvm.lux | 69 --------- .../luxc/lang/translation/jvm/imports.jvm.lux | 154 --------------------- new-luxc/source/program.lux | 20 ++- 3 files changed, 9 insertions(+), 234 deletions(-) delete mode 100644 new-luxc/source/luxc/lang/translation/js/imports.jvm.lux delete mode 100644 new-luxc/source/luxc/lang/translation/jvm/imports.jvm.lux (limited to 'new-luxc/source') 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/format) - [macro] - (macro [code] - ["s" syntax]) - [io #+ Process]) - (luxc [lang] - (lang [".L" module]))) - -(do-template [] - [(exception: #export ( {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 - [_ (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 - (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/format - (coll [list "list/" Functor Fold] - (dictionary ["dict" unordered #+ Dict]))) - [macro] - (macro [code] - ["s" syntax]) - [io #+ IO Process io] - [host]) - (luxc ["&" lang] - (lang [".L" module]))) - -(do-template [] - [(exception: #export ( {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))) - -(def: (promise-to-future promise) - (All [a] (-> (Promise a) (Future a))) - (let [future (CompletableFuture::new [])] - (exec (:: promise.Functor map - (function (_ value) (CompletableFuture::complete [value] future)) - promise) - future))) - -(def: from-io - (All [a] (-> (IO a) (Process a))) - (:: io.Monad 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 - [[new? future] (stm.commit (: (STM [Bit (CompletableFuture (Error Lux))]) - (do stm.Monad - [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 - [_ (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 - [dependencies (monad.seq io.Monad (list/map from-io dependencies)) - dependencies (|> dependencies - (list/map (Future::get [])) - (monad.seq io.Monad))] - (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 [])))) -- cgit v1.2.3