aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source/program/compositor
diff options
context:
space:
mode:
authorEduardo Julian2021-07-06 21:34:21 -0400
committerEduardo Julian2021-07-06 21:34:21 -0400
commit2b909032e7a0bd10cd7db52067d2fb701bfa95e5 (patch)
tree0e2aaef228f80f3336715327f7f34065c309de22 /stdlib/source/program/compositor
parent5cf4efa861075f8276f43a2516f5beacaf610b44 (diff)
Simplified the API for file-system operations.
Diffstat (limited to '')
-rw-r--r--stdlib/source/program/compositor.lux50
-rw-r--r--stdlib/source/program/compositor/export.lux22
-rw-r--r--stdlib/source/program/compositor/import.lux50
3 files changed, 45 insertions, 77 deletions
diff --git a/stdlib/source/program/compositor.lux b/stdlib/source/program/compositor.lux
index f443301db..8b577ec09 100644
--- a/stdlib/source/program/compositor.lux
+++ b/stdlib/source/program/compositor.lux
@@ -2,7 +2,6 @@
[lux (#- Module)
[type (#+ :share)]
["." debug]
- ["@" target]
[abstract
[monad (#+ Monad do)]]
[control
@@ -21,7 +20,7 @@
[time
["." instant]]
["." world #_
- ["." file (#+ File Path)]
+ ["." file]
["#/." program]
## ["." console]
]
@@ -83,43 +82,14 @@
(format "Duration: ")))]]
(wrap output)))
-(def: (package! monad file_system [packager package] static archive context)
- (All [!] (-> (Monad !) (file.System !) [Packager Path] Static Archive Context (! (Try Any))))
- (for {@.old
- (case (packager archive context)
- (#try.Success content)
- (do (try.with monad)
- [package (:share [!]
- (Monad !)
- monad
-
- (! (Try (File !)))
- (:assume (file.get_file monad file_system package)))]
- (\ (:share [!]
- (Monad !)
- monad
-
- (File !)
- (:assume package))
- over_write
- content))
-
- (#try.Failure error)
- (\ monad wrap (#try.Failure error)))}
- ## TODO: Fix whatever type_checker bug is forcing me into this compromise...
- (:assume
- (: (Promise (Try Any))
- (let [monad (:coerce (Monad Promise) monad)
- file_system (:coerce (file.System Promise) file_system)]
- (case (packager archive context)
- (#try.Success content)
- (do (try.with monad)
- [package (: (Promise (Try (File Promise)))
- (file.get_file monad file_system package))]
- (\ (: (File Promise) package) over_write content))
-
- (#try.Failure error)
- (\ monad wrap (#try.Failure error))))))))
+(def: (package! monad fs [packager package] static archive context)
+ (All [!] (-> (Monad !) (file.System !) [Packager file.Path] Static Archive Context (! (Try Any))))
+ (case (packager archive context)
+ (#try.Success content)
+ (\ fs write content package)
+
+ (#try.Failure error)
+ (\ monad wrap (#try.Failure error))))
(with_expansions [<parameters> (as_is anchor expression artifact)]
(def: #export (compiler static
@@ -137,7 +107,7 @@
[Type Type Type]
Extender
Service
- [Packager Path]
+ [Packager file.Path]
(Promise Any)))
(do {! promise.monad}
[platform (promise.future platform)]
diff --git a/stdlib/source/program/compositor/export.lux b/stdlib/source/program/compositor/export.lux
index 238034534..24ba3492c 100644
--- a/stdlib/source/program/compositor/export.lux
+++ b/stdlib/source/program/compositor/export.lux
@@ -38,16 +38,16 @@
{#tar.user commons
#tar.group commons}))
-(def: #export (library system sources)
+(def: #export (library fs sources)
(-> (file.System Promise) (List Source) (Promise (Try tar.Tar)))
(do (try.with promise.monad)
- [files (io.enumerate system sources)]
+ [files (io.enumerate fs sources)]
(|> (dictionary.entries files)
(monad.map try.monad
(function (_ [path source_code])
(do try.monad
[path (|> path
- (text.replace_all (\ system separator) .module_separator)
+ (text.replace_all (\ fs separator) .module_separator)
tar.path)
source_code (tar.content source_code)]
(wrap (#tar.Normal [path
@@ -61,13 +61,11 @@
(\ try.monad map row.from_list)
(\ promise.monad wrap))))
-(def: #export (export system [sources target])
+(def: #export (export fs [sources target])
(-> (file.System Promise) Export (Promise (Try Any)))
- (do (try.with promise.monad)
- [tar (..library system sources)
- package (: (Promise (Try (file.File Promise)))
- (file.get_file promise.monad system
- (format target (\ system separator) ..file)))]
- (|> tar
- (binary.run tar.writer)
- (\ package over_write))))
+ (do {! (try.with promise.monad)}
+ [tar (\ ! map (binary.run tar.writer)
+ (..library fs sources))]
+ (|> ..file
+ (format target (\ fs separator))
+ (\ fs write tar))))
diff --git a/stdlib/source/program/compositor/import.lux b/stdlib/source/program/compositor/import.lux
index 19a2d7607..f91ad03e7 100644
--- a/stdlib/source/program/compositor/import.lux
+++ b/stdlib/source/program/compositor/import.lux
@@ -8,7 +8,7 @@
[concurrency
["." promise (#+ Promise) ("#\." monad)]]
["<>" parser
- ["<b>" binary]]]
+ ["<.>" binary]]]
[data
[binary (#+ Binary)]
["." text
@@ -24,7 +24,7 @@
[archive
[descriptor (#+ Module)]]]]]
[world
- ["." file (#+ Path File)]]]
+ ["." file]]]
[//
[cli (#+ Library)]])
@@ -39,32 +39,32 @@
["Library" (%.text library)]))
(type: #export Import
- (Dictionary Path Binary))
+ (Dictionary file.Path Binary))
(def: (import_library system library import)
(-> (file.System Promise) Library Import (Action Import))
- (do (try.with promise.monad)
- [file (: (Action (File Promise))
- (\ system file library))
- binary (\ file content [])]
- (promise\wrap
- (do {! try.monad}
- [tar (<b>.run tar.parser binary)]
- (monad.fold ! (function (_ entry import)
- (case entry
- (#tar.Normal [path instant mode ownership content])
- (let [path (tar.from_path path)]
- (case (dictionary.try_put path (tar.data content) import)
- (#try.Success import)
- (wrap import)
-
- (#try.Failure error)
- (exception.throw ..duplicate [library path])))
-
- _
- (exception.throw ..useless_tar_entry [])))
- import
- (row.to_list tar))))))
+ (let [! promise.monad]
+ (|> library
+ (\ system read)
+ (\ ! map (let [! try.monad]
+ (|>> (\ ! map (<binary>.run tar.parser))
+ (\ ! join)
+ (\ ! map (|>> row.to_list
+ (monad.fold ! (function (_ entry import)
+ (case entry
+ (#tar.Normal [path instant mode ownership content])
+ (let [path (tar.from_path path)]
+ (case (dictionary.try_put path (tar.data content) import)
+ (#try.Failure error)
+ (exception.throw ..duplicate [library path])
+
+ import'
+ import'))
+
+ _
+ (exception.throw ..useless_tar_entry [])))
+ import)))
+ (\ ! join)))))))
(def: #export (import system libraries)
(-> (file.System Promise) (List Library) (Action Import))