From 6eaa3b57f3f1ea2ce13b942bdb4ef502fc1729bc Mon Sep 17 00:00:00 2001 From: Eduardo Julian Date: Fri, 29 May 2020 00:19:24 -0400 Subject: Can now import previously exported libraries. --- stdlib/source/program/compositor/import.lux | 62 +++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 stdlib/source/program/compositor/import.lux (limited to 'stdlib/source/program/compositor/import.lux') diff --git a/stdlib/source/program/compositor/import.lux b/stdlib/source/program/compositor/import.lux new file mode 100644 index 000000000..2e53e0976 --- /dev/null +++ b/stdlib/source/program/compositor/import.lux @@ -0,0 +1,62 @@ +(.module: + [lux #* + [abstract + ["." monad (#+ Monad do)]] + [control + ["." try (#+ Try)] + ["." exception (#+ exception:)] + [concurrency + ["." promise (#+ Promise) ("#@." monad)]] + [security + ["!" capability]] + ["<>" parser + ["" binary]]] + [data + [binary (#+ Binary)] + ["." text] + [collection + ["." dictionary (#+ Dictionary)] + ["." row]] + [format + ["." tar]]] + [world + ["." file (#+ Path File)]]] + [// + [cli (#+ Library)]]) + +(def: Action + (type (All [a] (Promise (Try a))))) + +(exception: #export useless-tar-entry) + +(type: #export Import + (Dictionary Path Binary)) + +(def: (import-library system library import) + (-> (file.System Promise) Library Import (Action Import)) + (do (try.with promise.monad) + [library (: (Action (File Promise)) + (!.use (:: system file) [library])) + binary (!.use (:: library content) [])] + (promise@wrap + (do {@ try.monad} + [tar (.run tar.parser binary)] + (monad.fold @ (function (_ entry import) + (case entry + (#tar.Normal [path instant mode ownership content]) + (dictionary.try-put (tar.from-path path) + (tar.data content) + import) + + _ + (exception.throw ..useless-tar-entry []))) + import + (row.to-list tar)))))) + +(def: #export (import system libraries) + (-> (file.System Promise) (List Library) (Action Import)) + (monad.fold (: (Monad Action) + (try.with promise.monad)) + (..import-library system) + (dictionary.new text.hash) + libraries)) -- cgit v1.2.3