aboutsummaryrefslogtreecommitdiff
path: root/new-luxc/source/luxc
diff options
context:
space:
mode:
Diffstat (limited to '')
-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
2 files changed, 0 insertions, 223 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))))))