From 6b6901b31bbec9947522a94274cd11c8e7683168 Mon Sep 17 00:00:00 2001 From: Eduardo Julian Date: Sun, 28 Jan 2018 19:41:01 -0400 Subject: - Got JS backend to build with the rest of the new-luxc code. --- .../luxc/lang/translation/js/imports.jvm.lux | 64 ++++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 new-luxc/source/luxc/lang/translation/js/imports.jvm.lux (limited to 'new-luxc/source/luxc/lang/translation/js/imports.jvm.lux') 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/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 + [_ (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 + (function [import] + (translate-module (get@ #module import))) + compiler + imports)))) -- cgit v1.2.3