From 7542b0addd9eaf01dd5f1c4c8a39b67f51a4bd06 Mon Sep 17 00:00:00 2001 From: Eduardo Julian Date: Thu, 7 Apr 2022 00:59:30 -0400 Subject: More efficient TAR handling. --- .github/workflows/test.yml | 2 +- documentation/bookmark/culture.md | 5 ++- lux-lua/commands.md | 2 +- stdlib/source/library/lux/data/format/tar.lux | 29 ++++++++-------- .../lux/tool/compiler/meta/cache/archive.lux | 2 +- .../lux/tool/compiler/meta/cache/artifact.lux | 2 +- .../lux/tool/compiler/meta/cache/module.lux | 2 +- .../library/lux/tool/compiler/meta/export.lux | 2 +- stdlib/source/library/lux/world/file.lux | 40 +++++++++++----------- stdlib/source/program/compositor.lux | 7 ++-- stdlib/source/specification/lux/world/file.lux | 8 ++--- .../test/lux/tool/compiler/meta/cache/purge.lux | 4 +-- .../source/test/lux/tool/compiler/meta/export.lux | 4 +-- .../source/test/lux/tool/compiler/meta/import.lux | 14 ++++---- stdlib/source/test/lux/world/file.lux | 14 ++++---- stdlib/source/test/lux/world/file/watch.lux | 2 +- 16 files changed, 72 insertions(+), 67 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 931e57ab3..5fa49c578 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -37,7 +37,7 @@ jobs: - uses: actions/setup-ruby@v1 with: ruby-version: '2.6' - - run: cd ./stdlib/ ../lux.sh with ruby with bibliotheca test + - run: cd ./stdlib/ && ../lux.sh with ruby with bibliotheca test test_stdlib_on_lua: runs-on: ubuntu-latest steps: diff --git a/documentation/bookmark/culture.md b/documentation/bookmark/culture.md index 5abdff8d5..4709870a2 100644 --- a/documentation/bookmark/culture.md +++ b/documentation/bookmark/culture.md @@ -1,3 +1,6 @@ # Reference -1. [Five Worlds](https://www.joelonsoftware.com/2002/05/06/five-worlds/) +0. [The Siren Song of Little Languages](https://www.wilfred.me.uk/blog/2019/03/24/the-siren-song-of-little-languages/) +0. [The Lisp Curse](http://www.winestockwebdesign.com/Essays/Lisp_Curse.html) +0. [Five Worlds](https://www.joelonsoftware.com/2002/05/06/five-worlds/) + diff --git a/lux-lua/commands.md b/lux-lua/commands.md index d09567831..6dd497307 100644 --- a/lux-lua/commands.md +++ b/lux-lua/commands.md @@ -34,7 +34,7 @@ cd ~/lux/lux-lua/ && mvn deploy:deploy-file \ -Durl=https://$NEXUS_USERNAME:$NEXUS_PASSWORD@oss.sonatype.org/content/repositories/snapshots/ \ -Dfile=target/program.jar \ -DgroupId=com.github.luxlang \ --DartifactId=lux-python \ +-DartifactId=lux-lua \ -Dversion=0.7.0-SNAPSHOT \ -Dpackaging=jar ``` diff --git a/stdlib/source/library/lux/data/format/tar.lux b/stdlib/source/library/lux/data/format/tar.lux index 4fb3522a6..debbba560 100644 --- a/stdlib/source/library/lux/data/format/tar.lux +++ b/stdlib/source/library/lux/data/format/tar.lux @@ -1,6 +1,7 @@ (.using [library [lux {"-" Mode and} + [ffi {"+"}] [abstract [monad {"+" do}]] [control @@ -11,7 +12,8 @@ ["<[0]>" binary {"+" Parser}]]] [data ["[0]" product] - ["[0]" binary {"+" Binary}] + ["[0]" binary {"+" Binary} + ["[1]!" \\unsafe]] ["[0]" text {"+" Char} ["%" format {"+" format}] [encoding @@ -122,10 +124,11 @@ (Parser Any) (do <>.monad [pre_end .bits_8 - end .bits_8 _ (let [expected (`` (char (~~ (static ..blank))))] (<>.assertion (exception.error ..wrong_character [expected pre_end]) (n.= expected pre_end))) + + end .bits_8 _ (let [expected (`` (char (~~ (static ..null))))] (<>.assertion (exception.error ..wrong_character [expected end]) (n.= expected end)))] @@ -230,20 +233,19 @@ (def: .public path_size Size 99) (def: (un_padded string) - (-> Binary (Try Binary)) - (case (binary.size string) - 0 {try.#Success string} + (-> Binary Binary) + (case (binary!.size string) + 0 string size (loop (again [end (-- size)]) (case end - 0 {try.#Success (# utf8.codec encoded "")} - _ (do try.monad - [last_char (binary.bits_8 end string)] + 0 (# utf8.codec encoded "") + _ (let [last_char (binary!.bits_8 end string)] (`` (case (.nat last_char) (pattern (char (~~ (static ..null)))) (again (-- end)) _ - (binary.slice 0 (++ end) string)))))))) + (binary!.slice 0 (++ end) string)))))))) (template [ ] [(abstract: .public @@ -260,7 +262,7 @@ (if (..ascii? value) (if (|> value (# utf8.codec encoded) - binary.size + binary!.size (n.> )) (exception.except [value]) {try.#Success (abstraction value)}) @@ -289,8 +291,7 @@ (n.= expected end))] (<>.lifted (do [! try.monad] - [ascii (..un_padded string) - text (# utf8.codec decoded ascii)] + [text (# utf8.codec decoded (..un_padded string))] ( text))))) (def: .public @@ -533,7 +534,7 @@ (def: .public (content content) (-> Binary (Try Content)) (do try.monad - [size (..big (binary.size content))] + [size (..big (binary!.size content))] (in (abstraction [size content])))) (def: from_content @@ -735,7 +736,7 @@ (def: .public writer (Writer Tar) - (let [end_of_archive (binary.empty ..end_of_archive_size)] + (let [end_of_archive (binary!.empty ..end_of_archive_size)] (function (_ tar) (format#composite (sequence#mix (function (_ next total) (format#composite total (..entry_writer next))) diff --git a/stdlib/source/library/lux/tool/compiler/meta/cache/archive.lux b/stdlib/source/library/lux/tool/compiler/meta/cache/archive.lux index 28abd457a..c31f86f25 100644 --- a/stdlib/source/library/lux/tool/compiler/meta/cache/archive.lux +++ b/stdlib/source/library/lux/tool/compiler/meta/cache/archive.lux @@ -21,4 +21,4 @@ (def: .public (cache! fs context it) (All (_ !) (-> (file.System !) Context Archive (! (Try Any)))) - (# fs write (archive.export ///.version it) (..descriptor fs context))) + (# fs write (..descriptor fs context) (archive.export ///.version it))) diff --git a/stdlib/source/library/lux/tool/compiler/meta/cache/artifact.lux b/stdlib/source/library/lux/tool/compiler/meta/cache/artifact.lux index ca2689c18..5917e328b 100644 --- a/stdlib/source/library/lux/tool/compiler/meta/cache/artifact.lux +++ b/stdlib/source/library/lux/tool/compiler/meta/cache/artifact.lux @@ -36,4 +36,4 @@ (def: .public (cache! fs context @module @artifact content) (All (_ !) (-> (file.System !) Context module.ID artifact.ID Binary (! (Try Any)))) - (# fs write content (..path fs context @module @artifact))) + (# fs write (..path fs context @module @artifact) content)) diff --git a/stdlib/source/library/lux/tool/compiler/meta/cache/module.lux b/stdlib/source/library/lux/tool/compiler/meta/cache/module.lux index 869aa2019..426a68589 100644 --- a/stdlib/source/library/lux/tool/compiler/meta/cache/module.lux +++ b/stdlib/source/library/lux/tool/compiler/meta/cache/module.lux @@ -80,7 +80,7 @@ (def: .public (cache! fs context @module content) (All (_ !) (-> (file.System !) Context module.ID Binary (! (Try Any)))) - (# fs write content (..descriptor fs context @module))) + (# fs write (..descriptor fs context @module) content)) (def: .public (cache fs context @module) (All (_ !) (-> (file.System !) Context module.ID (! (Try Binary)))) diff --git a/stdlib/source/library/lux/tool/compiler/meta/export.lux b/stdlib/source/library/lux/tool/compiler/meta/export.lux index 7eb36ad62..4fdc63159 100644 --- a/stdlib/source/library/lux/tool/compiler/meta/export.lux +++ b/stdlib/source/library/lux/tool/compiler/meta/export.lux @@ -71,4 +71,4 @@ (..library fs) (# ! each (binary.result tar.writer))) .let [/ (# fs separator)]] - (# fs write tar (format target / ..file)))) + (# fs write (format target / ..file) tar))) diff --git a/stdlib/source/library/lux/world/file.lux b/stdlib/source/library/lux/world/file.lux index d04f8c052..820ab92e0 100644 --- a/stdlib/source/library/lux/world/file.lux +++ b/stdlib/source/library/lux/world/file.lux @@ -70,7 +70,7 @@ )) (~~ (template [ ] - [(is (-> Path (! (Try Any))) + [(is (-> Path (! (Try Any))) )] [modify Instant] @@ -131,8 +131,8 @@ [delete])) (~~ (template [] - [(def: ( input path) - (async.future (# fs input path)))] + [(def: ( path input) + (async.future (# fs path input)))] [modify] [write] @@ -275,14 +275,14 @@ java/io/File::new java/io/File::delete)) - (def: (modify time_stamp path) + (def: (modify path time_stamp) (|> path ffi.as_string java/io/File::new (java/io/File::setLastModified (|> time_stamp instant.relative duration.millis ffi.as_long)))) (~~ (template [ ] - [(def: ( data path) + [(def: ( path data) (do (try.with io.monad) [stream (java/io/FileOutputStream::new (java/io/File::new (ffi.as_string path)) (ffi.as_boolean )) _ (java/io/OutputStream::write data stream) @@ -293,7 +293,7 @@ [#1 append] )) - (def: (move destination origin) + (def: (move origin destination) (|> origin ffi.as_string java/io/File::new @@ -487,14 +487,14 @@ (Fs::unlink path (..any_callback write!) node_fs) (Fs::rmdir path (..any_callback write!) node_fs))))) - (def: (modify time_stamp path) + (def: (modify path time_stamp) (with_async write! (Try Any) (let [when (|> time_stamp instant.relative duration.millis i.frac)] (Fs::utimes path when when (..any_callback write!) node_fs)))) (~~ (template [ ] - [(def: ( data path) + [(def: ( path data) (with_async write! (Try Any) ( path (Buffer::from data) (..any_callback write!) node_fs)))] @@ -503,7 +503,7 @@ [append Fs::appendFile] )) - (def: (move destination origin) + (def: (move origin destination) (with_async write! (Try Any) (Fs::rename origin destination (..any_callback write!) node_fs)))))))))) @@ -610,12 +610,12 @@ (os::remove path) (os::rmdir path)))) - (def: (modify time_stamp path) + (def: (modify path time_stamp) (let [when (|> time_stamp instant.relative duration.millis (i./ +1,000))] (os::utime path (..tuple [when when])))) (~~ (template [ ] - [(def: ( data path) + [(def: ( path data) (do (try.with io.monad) [file (..open path ) _ (PyFile::write data file)] @@ -625,7 +625,7 @@ [append "ab"] )) - (def: (move destination origin) + (def: (move origin destination) (os::rename origin destination)) ))) @@ -748,7 +748,7 @@ (RubyFile::delete path) (FileUtils::rmdir path)))) - (def: (modify moment path) + (def: (modify path moment) (let [moment (|> moment instant.relative duration.millis @@ -758,7 +758,7 @@ (RubyFile::utime moment moment path))) (~~ (template [ ] - [(def: ( data path) + [(def: ( path data) (do [! (try.with io.monad)] [file (RubyFile::open path ) data (RubyFile::write data file) @@ -770,7 +770,7 @@ ["ab" append] )) - (def: (move destination origin) + (def: (move origin destination) (do (try.with io.monad) [_ (FileUtils::move origin destination)] (in []))) @@ -1240,7 +1240,7 @@ (stm.commit! (..attempt! (..delete_mock_node! separator path) store))) - (def: (modify now path) + (def: (modify path now) (stm.commit! (..attempt! (function (_ |store|) (do try.monad @@ -1248,13 +1248,13 @@ (..update_mock_file! separator path now (the #mock_content file) |store|))) store))) - (def: (write content path) + (def: (write path content) (do async.monad [now (async.future instant.now)] (stm.commit! (..attempt! (..update_mock_file! separator path now content) store)))) - (def: (append content path) + (def: (append path content) (do async.monad [now (async.future instant.now)] (stm.commit! @@ -1268,7 +1268,7 @@ |store|))) store)))) - (def: (move destination origin) + (def: (move origin destination) (stm.commit! (do [! stm.monad] [|store| (stm.read store)] @@ -1331,4 +1331,4 @@ [? (# fs file? path)] (if ? (in (exception.except ..cannot_make_file [path])) - (# fs write content path)))) + (# fs write path content)))) diff --git a/stdlib/source/program/compositor.lux b/stdlib/source/program/compositor.lux index 0d59c7dd5..e803ead3f 100644 --- a/stdlib/source/program/compositor.lux +++ b/stdlib/source/program/compositor.lux @@ -76,7 +76,8 @@ {.#Some console} (console.write_line report console))) - ))] + (is (Async (Try Any)) + )))] (io.run! (# world/program.default exit +1)))) {try.#Success output} @@ -100,13 +101,13 @@ {try.#Success content} (case content {.#Left content} - (# fs write content package) + (# fs write package content) {.#Right content} (do [! (try.with async.monad)] [_ (# fs make_directory package) _ (monad.each ! (function (_ [name content]) - (# fs write content (file.rooted fs package name))) + (# fs write (file.rooted fs package name) content)) content)] (in []))) diff --git a/stdlib/source/specification/lux/world/file.lux b/stdlib/source/specification/lux/world/file.lux index c3164d544..1e1d5f557 100644 --- a/stdlib/source/specification/lux/world/file.lux +++ b/stdlib/source/specification/lux/world/file.lux @@ -71,7 +71,7 @@ (-> (/.System Async) Binary /.Path (Async Bit)) (do async.monad [file_pre! (# fs file? path) - made? (# fs write content path) + made? (# fs write path content) file_post! (# fs file? path)] (in (and (not file_pre!) (case made? @@ -84,7 +84,7 @@ (do async.monad [pre_file_size (# fs file_size path) pre_content (# fs read path) - appended? (# fs append appendix path) + appended? (# fs append path appendix) post_file_size (# fs file_size path) post_content (# fs read path)] (in (<| (try.else false) @@ -110,7 +110,7 @@ (def: (modified?&last_modified fs expected_time path) (-> (/.System Async) Instant /.Path (Async Bit)) (do async.monad - [modified? (# fs modify expected_time path) + [modified? (# fs modify path expected_time) last_modified (# fs last_modified path)] (in (<| (try.else false) (do [! try.monad] @@ -141,7 +141,7 @@ (let [origin (/.rooted fs parent child) destination (/.rooted fs parent alternate_child)] (do [! async.monad] - [moved? (# fs move destination origin) + [moved? (# fs move origin destination) lost? (|> origin (# fs file?) (# ! each not)) diff --git a/stdlib/source/test/lux/tool/compiler/meta/cache/purge.lux b/stdlib/source/test/lux/tool/compiler/meta/cache/purge.lux index f7e008720..b6f6b4f27 100644 --- a/stdlib/source/test/lux/tool/compiler/meta/cache/purge.lux +++ b/stdlib/source/test/lux/tool/compiler/meta/cache/purge.lux @@ -119,8 +119,8 @@ .let [dir (//module.path fs context id/0) file/0 (%.format dir / name/0) file/1 (%.format dir / name/1)] - _ (# fs write content/0 file/0) - _ (# fs write content/1 file/1) + _ (# fs write file/0 content/0) + _ (# fs write file/1 content/1) pre (# fs directory_files dir) _ (/.purge! fs context id/0) post (# fs directory_files dir)] diff --git a/stdlib/source/test/lux/tool/compiler/meta/export.lux b/stdlib/source/test/lux/tool/compiler/meta/export.lux index d25da0be5..c737eb0e3 100644 --- a/stdlib/source/test/lux/tool/compiler/meta/export.lux +++ b/stdlib/source/test/lux/tool/compiler/meta/export.lux @@ -62,11 +62,11 @@ [it (do (try.with !) [.let [fs (file.mock /)] _ (# fs make_directory source/0) - _ (# fs write content/0 file/0) + _ (# fs write file/0 content/0) _ (# fs make_directory source/1) _ (# fs make_directory (format source/1 / dir/0)) - _ (# fs write content/1 file/1) + _ (# fs write file/1 content/1) _ (# fs make_directory target) library_tar (/.library fs (list source/0 source/1)) diff --git a/stdlib/source/test/lux/tool/compiler/meta/import.lux b/stdlib/source/test/lux/tool/compiler/meta/import.lux index c01a790ce..f7b90c8bf 100644 --- a/stdlib/source/test/lux/tool/compiler/meta/import.lux +++ b/stdlib/source/test/lux/tool/compiler/meta/import.lux @@ -112,12 +112,12 @@ (in (do [! async.monad] [it/0 (do (try.with !) [.let [fs (file.mock /)] - _ (# fs write library_content library/0)] + _ (# fs write library/0 library_content)] (/.import fs (list library/0))) it/1 (do (try.with !) [.let [fs (file.mock /)] - _ (# fs write library_content/0 library/0) - _ (# fs write library_content/1 library/1)] + _ (# fs write library/0 library_content/0) + _ (# fs write library/1 library_content/1)] (/.import fs (list library/0 library/1)))] (_.cover' [/.import] (and (|> it/0 @@ -129,7 +129,7 @@ (in (do [! async.monad] [it (do (try.with !) [.let [fs (file.mock /)] - _ (# fs write library_content library/0) + _ (# fs write library/0 library_content) _ (/.import fs (list library/0 library/0))] (in false))] (_.cover' [/.duplicate] @@ -137,17 +137,17 @@ (in (do [! async.monad] [it/0 (do (try.with !) [.let [fs (file.mock /)] - _ (# fs write library_content/-0 library/0) + _ (# fs write library/0 library_content/-0) _ (/.import fs (list library/0))] (in false)) it/1 (do (try.with !) [.let [fs (file.mock /)] - _ (# fs write library_content/-1 library/0) + _ (# fs write library/0 library_content/-1) _ (/.import fs (list library/0))] (in false)) it/2 (do (try.with !) [.let [fs (file.mock /)] - _ (# fs write library_content/-2 library/0) + _ (# fs write library/0 library_content/-2) _ (/.import fs (list library/0))] (in false))] (_.cover' [/.useless_tar_entry] diff --git a/stdlib/source/test/lux/world/file.lux b/stdlib/source/test/lux/world/file.lux index a7e9de34a..ae9d7ff01 100644 --- a/stdlib/source/test/lux/world/file.lux +++ b/stdlib/source/test/lux/world/file.lux @@ -66,8 +66,8 @@ _ (in {try.#Failure ""})))) -(def: (write fs disk it @) - (-> (/.System Async) (Atom Disk) (-> Binary /.Path (IO (Try Any)))) +(def: (write fs disk @ it) + (-> (/.System Async) (Atom Disk) (-> /.Path Binary (IO (Try Any)))) (do [! io.monad] [now instant.now disk' (atom.read! disk)] @@ -203,13 +203,13 @@ _ (in {try.#Failure ""})))) - (def: (append it @) + (def: (append @ it) (do [! io.monad] [now instant.now disk' (atom.read! disk)] (case (dictionary.value @ disk') {.#None} - (..write mock disk it @) + (..write mock disk @ it) {.#Some {.#Left [_ old]}} (do ! @@ -220,7 +220,7 @@ _ (in {try.#Failure ""})))) - (def: (modify it @) + (def: (modify @ it) (do [! io.monad] [disk' (atom.read! disk)] (case (dictionary.value @ disk') @@ -231,10 +231,10 @@ _ (in {try.#Failure ""})))) - (def: (move it @) + (def: (move @ it) (do [! (try.with io.monad)] [data (..read disk @) - write (..write mock disk data it)] + write (..write mock disk it data)] (..delete mock disk @))) ))) diff --git a/stdlib/source/test/lux/world/file/watch.lux b/stdlib/source/test/lux/world/file/watch.lux index 53263b27a..a8bcda085 100644 --- a/stdlib/source/test/lux/world/file/watch.lux +++ b/stdlib/source/test/lux/world/file/watch.lux @@ -118,7 +118,7 @@ (-> (//.System Async) (/.Watcher Async) Binary //.Path (Async (Try Bit))) (do (try.with async.monad) [_ (async.after 1 {try.#Success "Delay to make sure the over_write time-stamp always changes."}) - _ (# fs write data expected_path) + _ (# fs write expected_path data) poll/2 (# watcher poll []) poll/2' (# watcher poll [])] (in (and (case poll/2 -- cgit v1.2.3