From a3d820cfb8c0b317d70b14edeeb00bbabb6fb030 Mon Sep 17 00:00:00 2001 From: Eduardo Julian Date: Sat, 13 Oct 2018 20:26:52 -0400 Subject: Minor refactoring. --- stdlib/source/lux/compiler.lux | 35 +++++++++++++++---- stdlib/source/lux/compiler/default.lux | 10 +++--- .../lux/compiler/default/phase/translation.lux | 20 +++++------ stdlib/source/lux/compiler/meta/io/context.lux | 2 +- stdlib/source/lux/world/file.lux | 39 +++++++++++----------- 5 files changed, 64 insertions(+), 42 deletions(-) diff --git a/stdlib/source/lux/compiler.lux b/stdlib/source/lux/compiler.lux index cdbc598bb..bc6005382 100644 --- a/stdlib/source/lux/compiler.lux +++ b/stdlib/source/lux/compiler.lux @@ -1,20 +1,41 @@ (.module: - [lux (#- Source) + [lux (#- Module Source Code) [control ["ex" exception (#+ exception:)]] + [data + ["." error (#+ Error)] + [collection + ["." dictionary (#+ Dictionary)]]] [world + ["." binary (#+ Binary)] ["." file (#+ File)]]] [/ [meta ["." archive (#+ Document Archive)]]]) +(type: #export Module Text) + +(type: #export Code Text) + (type: #export Source - {#name Text + {#module Module #file File - #code Text}) + #code Code}) + +(type: #export Output + (Dictionary File Binary)) + +(type: #export (Compilation d) + {#dependencies (List Module) + #process (-> Archive + (Error (Either (Compilation d) + [(Document d) Output])))}) + +(type: #export (Compiler d) + (-> Source (Compilation d))) -(type: #export (Compiler d !) - (-> (file.System !) Archive Source (! (Document d)))) +(type: #export (Importer !) + (-> (file.System !) Module Archive (! (Error Archive)))) -(exception: #export (cannot-compile {name Text}) - (ex.report ["Module" name])) +(exception: #export (cannot-compile {module Module}) + (ex.report ["Module" module])) diff --git a/stdlib/source/lux/compiler/default.lux b/stdlib/source/lux/compiler/default.lux index e799f0496..efba96e05 100644 --- a/stdlib/source/lux/compiler/default.lux +++ b/stdlib/source/lux/compiler/default.lux @@ -60,11 +60,11 @@ (set@ #.cursor cursor))] output]))))) -## ## (def: (write-module target-dir file-name module-name module artifacts) -## ## (-> File Text Text Module Artifacts (Process Any)) +## ## (def: (write-module target-dir file-name module-name module outputs) +## ## (-> File Text Text Module Outputs (Process Any)) ## ## (do io.Monad ## ## [_ (monad.map @ (product.uncurry (&io.write target-dir)) -## ## (dictionary.entries artifacts))] +## ## (dictionary.entries outputs))] ## ## (&io.write target-dir ## ## (format module-name "/" cache.descriptor-name) ## ## (encoding.to-utf8 (%code (cache/description.write file-name module)))))) @@ -87,7 +87,7 @@ (do phase.Monad [_ (module.create (text/hash (get@ #//.code source)) module-name) _ (analysis.set-current-module module-name)] - (analysis.set-source-code (init.source (get@ #//.name source) (get@ #//.code source)))))) + (analysis.set-source-code (init.source (get@ #//.module source) (get@ #//.code source)))))) (def: end-module-compilation (All [anchor expression statement] @@ -136,7 +136,7 @@ (get@ #cli.sources configuration) (get@ #cli.module configuration)) ## _ (&io.prepare-module target-dir (get@ #cli.module configuration)) - ## _ (write-module target-dir file-name (get@ #cli.module configuration) module artifacts) + ## _ (write-module target-dir file-name (get@ #cli.module configuration) module outputs) ] (<| (:: @ map product.left) (:: (get@ #file-system platform) lift) diff --git a/stdlib/source/lux/compiler/default/phase/translation.lux b/stdlib/source/lux/compiler/default/phase/translation.lux index 8565cefcc..fb40f4652 100644 --- a/stdlib/source/lux/compiler/default/phase/translation.lux +++ b/stdlib/source/lux/compiler/default/phase/translation.lux @@ -41,9 +41,9 @@ (do-template [] [(exception: #export ( {name Name}) - (ex.report ["Artifact" (%name name)]))] + (ex.report ["Output" (%name name)]))] - [cannot-overwrite-artifact] + [cannot-overwrite-output] [no-buffer-for-saving-code] ) @@ -61,14 +61,14 @@ (type: #export (Buffer statement) (Row [Name statement])) -(type: #export (Artifacts statement) (Dictionary File (Buffer statement))) +(type: #export (Outputs statement) (Dictionary File (Buffer statement))) (type: #export (State anchor expression statement) {#context Context #anchor (Maybe anchor) #host (Host expression statement) #buffer (Maybe (Buffer statement)) - #artifacts (Artifacts statement) + #outputs (Outputs statement) #counter Nat #name-cache (Dictionary Name Text)}) @@ -92,7 +92,7 @@ #anchor #.None #host host #buffer #.None - #artifacts (dictionary.new text.Hash) + #outputs (dictionary.new text.Hash) #counter 0 #name-cache (dictionary.new name.Hash)}) @@ -158,10 +158,10 @@ buffer (Buffer statement) no-active-buffer] ) -(def: #export artifacts +(def: #export outputs (All [anchor expression statement] - (Operation anchor expression statement (Artifacts statement))) - (extension.read (get@ #artifacts))) + (Operation anchor expression statement (Outputs statement))) + (extension.read (get@ #outputs))) (def: #export next (All [anchor expression statement] @@ -208,7 +208,7 @@ (case ?buffer (#.Some buffer) (if (row.any? (|>> product.left (name/= name)) buffer) - (//.throw cannot-overwrite-artifact name) + (//.throw cannot-overwrite-output name) (extension.update (set@ #buffer (#.Some (row.add [name code] buffer))))) #.None @@ -219,7 +219,7 @@ (-> File (Operation anchor expression statement Any))) (do //.Monad [buffer ..buffer] - (extension.update (update@ #artifacts (dictionary.put target buffer))))) + (extension.update (update@ #outputs (dictionary.put target buffer))))) (def: #export (remember lux-name) (All [anchor expression statement] diff --git a/stdlib/source/lux/compiler/meta/io/context.lux b/stdlib/source/lux/compiler/meta/io/context.lux index 96a8d4835..2651c771d 100644 --- a/stdlib/source/lux/compiler/meta/io/context.lux +++ b/stdlib/source/lux/compiler/meta/io/context.lux @@ -96,7 +96,7 @@ binary (:: System read file)] (case (encoding.from-utf8 binary) (#error.Success code) - (wrap {#////.name module + (wrap {#////.module module #////.file file #////.code code}) diff --git a/stdlib/source/lux/world/file.lux b/stdlib/source/lux/world/file.lux index 4bc2e6632..e97668917 100644 --- a/stdlib/source/lux/world/file.lux +++ b/stdlib/source/lux/world/file.lux @@ -27,27 +27,28 @@ #Write #Execute) -(signature: #export (System m) - (: (Monad m) +(signature: #export (System !) + (: (Monad !) &monad) - (: (All [e a] (-> (Exception e) e (m a))) + (: (All [e a] (-> (Exception e) e (! a))) throw) - (: (All [a] (-> (m a) (m (Error a)))) + (: (All [a] (-> (! a) (! (Error a)))) try) - (: (All [a] (-> (Error a) (m a))) + (: (All [a] (-> (Error a) (! a))) lift) (do-template [] - [(: (-> Binary File (m Any)) + [(: (-> Binary File (! Any)) )] - [append] [write]) + [append] + [write]) (do-template [ ] - [(: (-> File (m )) + [(: (-> File (! )) )] [read Binary] @@ -56,28 +57,28 @@ [last-modified Instant]) (do-template [] - [(: (-> File (m Bit)) + [(: (-> File (! Bit)) )] [file?] [directory?] ) - (: (-> Permission File (m Bit)) + (: (-> Permission File (! Bit)) can?) (do-template [] - [(: (-> File (m Any)) + [(: (-> File (! Any)) )] [make-directory] [delete] ) - (: (-> File File (m Any)) + (: (-> File File (! Any)) move) - (: (-> Instant File (m Any)) + (: (-> Instant File (! Any)) modify) (: Text @@ -257,10 +258,10 @@ )) })) -(def: #export (exists? System file) - (All [m] (-> (System m) File (m Bit))) - (do (:: System &monad) - [??? (:: System file? file)] +(def: #export (exists? System file) + (All [!] (-> (System !) File (! Bit))) + (do (:: System &monad) + [??? (:: System file? file)] (if ??? - (wrap #1) - (:: System directory? file)))) + (wrap ???) + (:: System directory? file)))) -- cgit v1.2.3