From c2830c26e55da02ac628be9a220cd824264cdc9e Mon Sep 17 00:00:00 2001 From: Eduardo Julian Date: Sun, 18 Dec 2022 18:55:32 -0400 Subject: Caching compiler artifacts into TAR files, instead of huge directories. --- stdlib/source/library/lux/data/color/rgb.lux | 49 ++++++++--------- stdlib/source/library/lux/meta/compiler.lux | 46 ++++++++-------- .../library/lux/meta/compiler/meta/cache.lux | 3 +- stdlib/source/library/lux/world/file.lux | 61 ++++++++++++++++------ 4 files changed, 91 insertions(+), 68 deletions(-) (limited to 'stdlib/source/library') diff --git a/stdlib/source/library/lux/data/color/rgb.lux b/stdlib/source/library/lux/data/color/rgb.lux index 4dff2eb5d..1a140c9a4 100644 --- a/stdlib/source/library/lux/data/color/rgb.lux +++ b/stdlib/source/library/lux/data/color/rgb.lux @@ -89,19 +89,18 @@ [#blue] ))])) -(def .public black - RGB - [#red ..least - #green ..least - #blue ..least]) - -(def .public white - RGB - [#red ..most - #green ..most - #blue ..most]) - -(with_template [ ] +(with_template [ ] + [(def .public + RGB + [#red + #green + #blue ])] + + [black ..least] + [white ..most] + ) + +(with_template [ ] [(def .public (Monoid RGB) (implementation @@ -109,19 +108,17 @@ ) (def (composite left right) - (let [left ( left) - right ( right)] - (`` [(,, (with_template [] - [ ( (the left) - (the right))] - - [#red] - [#green] - [#blue] - ))])))))] - - [addition ..black n.max |> |>] - [subtraction ..white n.min ..complement |>] + (`` [(,, (with_template [] + [ ( (the left) + (the right))] + + [#red] + [#green] + [#blue] + ))]))))] + + [..black n.max addition] + [..white n.min subtraction] ) (def (ratio it) diff --git a/stdlib/source/library/lux/meta/compiler.lux b/stdlib/source/library/lux/meta/compiler.lux index 0bac9c1be..4721d1374 100644 --- a/stdlib/source/library/lux/meta/compiler.lux +++ b/stdlib/source/library/lux/meta/compiler.lux @@ -1,24 +1,21 @@ (.require [library - [lux (.except Module Code #module) + [lux (.except Code #module) [control - ["<>" parser (.only)] - ["[0]" try (.only Try)] + [try (.only Try)] ["[0]" exception (.only Exception)]] [data - ["[0]" text] - ["[0]" binary (.only Binary) + [binary [\\format (.only Format)] - ["<[1]>" \\parser (.only Parser)]]] + [\\parser (.only Parser)]]] [world - ["[0]" file (.only Path)]]]] + ["[0]" file]]]] [/ [meta - ["[0]" archive (.only Output Archive) + ["[0]" archive (.only Archive) [key (.only Key)] [module - [descriptor (.only Descriptor Module)] - [document (.only Document)]]]]]) + ["[0]" descriptor]]]]]) (type .public Code Text) @@ -28,20 +25,21 @@ (type .public Input (Record - [#module Module - #file Path + [#module descriptor.Module + #file file.Path #hash Nat #code Code])) -(type .public (Compilation s d) +(type .public (Compilation state document) (Record - [#dependencies (List Module) - #process (-> s Archive - (Try [s (Either (Compilation s d) - (archive.Entry d))]))])) + [#dependencies (List descriptor.Module) + #process (-> state Archive + (Try [state (Either (Compilation state document) + (archive.Entry document))]))])) -(type .public (Compiler s d) - (-> Input (Compilation s d))) +(type .public (Compiler state document) + (-> Input + (Compilation state document))) (type .public Custom (Ex (_ state document) @@ -49,12 +47,14 @@ (Key document) (Format document) (Parser document) - (-> Input (Try (Compilation state document)))])) + (-> Input + (Try (Compilation state document)))])) -(type .public (Instancer s d) - (-> (Key d) (List Parameter) (Compiler s d))) +(type .public (Instancer state document) + (-> (Key document) (List Parameter) + (Compiler state document))) (exception.def .public (cannot_compile module) - (Exception Module) + (Exception descriptor.Module) (exception.report (list ["Module" module]))) diff --git a/stdlib/source/library/lux/meta/compiler/meta/cache.lux b/stdlib/source/library/lux/meta/compiler/meta/cache.lux index e4825872c..e2c09daa8 100644 --- a/stdlib/source/library/lux/meta/compiler/meta/cache.lux +++ b/stdlib/source/library/lux/meta/compiler/meta/cache.lux @@ -18,8 +18,7 @@ (def .public (path fs context) (All (_ !) (-> (file.System !) Context file.Path)) (let [/ (of fs separator)] - (format (the context.#target context) - / (the context.#host context) + (format (the context.#host context) / (version.format //.version)))) (def .public (enabled? fs context) diff --git a/stdlib/source/library/lux/world/file.lux b/stdlib/source/library/lux/world/file.lux index 608d9689e..94bea7fad 100644 --- a/stdlib/source/library/lux/world/file.lux +++ b/stdlib/source/library/lux/world/file.lux @@ -83,7 +83,9 @@ )) (def (un_rooted fs path) - (All (_ !) (-> (System !) Path (Maybe [Path Text]))) + (All (_ !) + (-> (System !) Path + (Maybe [Path Text]))) (let [/ (of fs separator)] (when (text.last_index / path) {.#None} @@ -96,20 +98,25 @@ (in [parent child]))))) (def .public (parent fs path) - (All (_ !) (-> (System !) Path (Maybe Path))) + (All (_ !) + (-> (System !) Path + (Maybe Path))) (|> path (..un_rooted fs) (maybe#each product.left))) (def .public (name fs path) - (All (_ !) (-> (System !) Path Text)) + (All (_ !) + (-> (System !) Path + Text)) (|> path (..un_rooted fs) (maybe#each product.right) (maybe.else path))) (def .public (async fs) - (-> (System IO) (System Async)) + (-> (System IO) + (System Async)) (`` (implementation (def separator (of fs separator)) @@ -143,7 +150,9 @@ ))) (def .public (rooted fs parent child) - (All (_ !) (-> (System !) Path Text Path)) + (All (_ !) + (-> (System !) Path Text + Path)) (format parent (of fs separator) child)) (with_template [] @@ -961,7 +970,9 @@ (these))) (def .public (exists? monad fs path) - (All (_ !) (-> (Monad !) (System !) Path (! Bit))) + (All (_ !) + (-> (Monad !) (System !) Path + (! Bit))) (do monad [verdict (of fs file? path)] (if verdict @@ -983,7 +994,8 @@ (dictionary.empty text.hash)) (def (retrieve_mock_file! separator path mock) - (-> Text Path Mock (Try [Text Mock_File])) + (-> Text Path Mock + (Try [Text Mock_File])) (loop (again [directory mock trail (text.all_split_by separator path)]) (when trail @@ -1007,7 +1019,8 @@ (exception.except ..cannot_find_file [path])))) (def (update_mock_file! / path now content mock) - (-> Text Path Instant Binary Mock (Try Mock)) + (-> Text Path Instant Binary Mock + (Try Mock)) (loop (again [directory mock trail (text.all_split_by / path)]) (when trail @@ -1046,7 +1059,8 @@ (exception.except ..cannot_find_file [path])))) (def (delete_mock_node! / path mock) - (-> Text Path Mock (Try Mock)) + (-> Text Path Mock + (Try Mock)) (loop (again [directory mock trail (text.all_split_by / path)]) (when trail @@ -1081,7 +1095,9 @@ (exception.except ..cannot_delete [path])))) (def (attempt! transform var) - (All (_ a) (-> (-> a (Try a)) (Var a) (STM (Try Any)))) + (All (_ of) + (-> (-> of (Try of)) (Var of) + (STM (Try Any)))) (do [! stm.monad] [|var| (stm.read var)] (when (transform |var|) @@ -1094,7 +1110,8 @@ (in {try.#Failure error})))) (def (make_mock_directory! / path mock) - (-> Text Path Mock (Try Mock)) + (-> Text Path Mock + (Try Mock)) (loop (again [directory mock trail (text.all_split_by / path)]) (when trail @@ -1122,7 +1139,8 @@ (exception.except ..cannot_make_directory [path])))) (def (retrieve_mock_directory! / path mock) - (-> Text Path Mock (Try Mock)) + (-> Text Path Mock + (Try Mock)) (loop (again [directory mock trail (text.all_split_by / path)]) (when trail @@ -1148,7 +1166,8 @@ (again sub_directory tail))))))) (def .public (mock separator) - (-> Text (System Async)) + (-> Text + (System Async)) (let [store (stm.var ..empty_mock)] (`` (implementation (def separator @@ -1288,7 +1307,9 @@ )))) (def (check_or_make_directory monad fs path) - (All (_ !) (-> (Monad !) (System !) Path (! (Try Any)))) + (All (_ !) + (-> (Monad !) (System !) Path + (! (Try Any)))) (do monad [? (of fs directory? path)] (if ? @@ -1296,7 +1317,9 @@ (of fs make_directory path)))) (def .public (make_directories monad fs path) - (All (_ !) (-> (Monad !) (System !) Path (! (Try Any)))) + (All (_ !) + (-> (Monad !) (System !) Path + (! (Try Any)))) (let [rooted? (text.starts_with? (of fs separator) path) segments (text.all_split_by (of fs separator) path)] (when (if rooted? @@ -1328,7 +1351,9 @@ (in {try.#Failure error})))))))) (def .public (make_file monad fs content path) - (All (_ !) (-> (Monad !) (System !) Binary Path (! (Try Any)))) + (All (_ !) + (-> (Monad !) (System !) Binary Path + (! (Try Any)))) (do monad [? (of fs file? path)] (if ? @@ -1336,7 +1361,9 @@ (of fs write path content)))) (def .public (copy monad fs from to) - (All (_ !) (-> (Monad !) (System !) Path Path (! (Try Any)))) + (All (_ !) + (-> (Monad !) (System !) Path Path + (! (Try Any)))) (do (try.with monad) [data (of fs read from)] (of fs write to data))) -- cgit v1.2.3