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 --------------------- 2 files changed, 223 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/luxc/lang') 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)))))) -- cgit v1.2.3