aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source/program
diff options
context:
space:
mode:
authorEduardo Julian2020-05-29 00:19:24 -0400
committerEduardo Julian2020-05-29 00:19:24 -0400
commit6eaa3b57f3f1ea2ce13b942bdb4ef502fc1729bc (patch)
tree746eb35ad0e8d10d3a6587bf0f6b3c5d867f7899 /stdlib/source/program
parentfcb1dcee2a4d502b41852a4c8e26b53ae7b2041e (diff)
Can now import previously exported libraries.
Diffstat (limited to 'stdlib/source/program')
-rw-r--r--stdlib/source/program/compositor.lux4
-rw-r--r--stdlib/source/program/compositor/cli.lux6
-rw-r--r--stdlib/source/program/compositor/export.lux6
-rw-r--r--stdlib/source/program/compositor/import.lux62
4 files changed, 73 insertions, 5 deletions
diff --git a/stdlib/source/program/compositor.lux b/stdlib/source/program/compositor.lux
index d431198fa..63a73260d 100644
--- a/stdlib/source/program/compositor.lux
+++ b/stdlib/source/program/compositor.lux
@@ -94,7 +94,7 @@
(#/cli.Compilation compilation)
(<| (or-crash! "Compilation failed:")
(do (try.with promise.monad)
- [#let [[compilation-sources compilation-target compilation-module] compilation]
+ [#let [[compilation-sources compilation-libraries compilation-target compilation-module] compilation]
[state archive] (:share [<parameters>]
{(Platform <parameters>)
platform}
@@ -105,7 +105,7 @@
{(Platform <parameters>)
platform}
{(Promise (Try [Archive (directive.State+ <parameters>)]))
- (:assume (platform.compile static expander platform compilation [archive state]))})
+ (:assume (platform.compile compilation-libraries static expander platform compilation [archive state]))})
_ (ioW.freeze (get@ #platform.&file-system platform) (get@ #/static.host static) (get@ #/static.target static) archive)]
(wrap (log! "Compilation complete!"))))
diff --git a/stdlib/source/program/compositor/cli.lux b/stdlib/source/program/compositor/cli.lux
index 940665680..e0bcd6e00 100644
--- a/stdlib/source/program/compositor/cli.lux
+++ b/stdlib/source/program/compositor/cli.lux
@@ -12,10 +12,11 @@
[file (#+ Path)]]])
(type: #export Source Path)
+(type: #export Library Path)
(type: #export Target Path)
(type: #export Compilation
- [(List Source) Target Module])
+ [(List Source) (List Library) Target Module])
(type: #export Export
[(List Source) Target])
@@ -31,6 +32,7 @@
(cli.named <long> cli.any))]
[source "--source" Source]
+ [library "--library" Library]
[target "--target" Target]
[module "--module" Module]
)
@@ -41,11 +43,13 @@
(<>.after (cli.this "build")
($_ <>.and
(<>.some ..source)
+ (<>.some ..library)
..target
..module))
(<>.after (cli.this "repl")
($_ <>.and
(<>.some ..source)
+ (<>.some ..library)
..target
..module))
(<>.after (cli.this "export")
diff --git a/stdlib/source/program/compositor/export.lux b/stdlib/source/program/compositor/export.lux
index 6e364800f..f6a78ed78 100644
--- a/stdlib/source/program/compositor/export.lux
+++ b/stdlib/source/program/compositor/export.lux
@@ -9,7 +9,7 @@
[security
["!" capability]]]
[data
- [text
+ ["." text
["%" format (#+ format)]]
[collection
["." dictionary]
@@ -48,7 +48,9 @@
(monad.map try.monad
(function (_ [path source-code])
(do try.monad
- [path (tar.path path)
+ [path (|> path
+ (text.replace-all (:: system separator) .module-separator)
+ tar.path)
source-code (tar.content source-code)]
(wrap (#tar.Normal [path
(instant.from-millis +0)
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
+ ["<b>" 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 (<b>.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))