diff options
Diffstat (limited to 'new-luxc/source/luxc/lang/translation/js/imports.jvm.lux')
-rw-r--r-- | new-luxc/source/luxc/lang/translation/js/imports.jvm.lux | 64 |
1 files changed, 64 insertions, 0 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 new file mode 100644 index 000000000..725aff705 --- /dev/null +++ b/new-luxc/source/luxc/lang/translation/js/imports.jvm.lux @@ -0,0 +1,64 @@ +(.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]))) + +(exception: #export Invalid-Imports) +(exception: #export Module-Cannot-Import-Itself) +(exception: #export 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 Compiler (Process Compiler)) + Code + (Meta (Process Compiler))) + (do macro.Monad<Meta> + [_ (moduleL.set-annotations annotations) + current-module macro.current-module-name + imports (let [imports (|> (macro.get-tuple-ann (ident-for #.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 false)) + _ (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)))) |