diff options
author | Eduardo Julian | 2022-03-14 01:09:08 -0400 |
---|---|---|
committer | Eduardo Julian | 2022-03-14 01:09:08 -0400 |
commit | b8681fd206d5b5076b9737ee54f0cb0405a898d6 (patch) | |
tree | 6ba25cc4f31ad07b4279828568e9019f26334eca | |
parent | 6766be5427b1788a44e07151e3fabe33ec4f8b37 (diff) |
Can now add type-vars to imported procedures from scripting languages.
57 files changed, 1204 insertions, 1886 deletions
diff --git a/documentation/bookmark/Feature toggle.md b/documentation/bookmark/Feature toggle.md deleted file mode 100644 index 7e55a519b..000000000 --- a/documentation/bookmark/Feature toggle.md +++ /dev/null @@ -1,4 +0,0 @@ -# Reference - -1. [Feature Toggles (aka Feature Flags)](https://martinfowler.com/articles/feature-toggles.html) - diff --git a/documentation/bookmark/Package.md b/documentation/bookmark/Package.md deleted file mode 100644 index b58cc3221..000000000 --- a/documentation/bookmark/Package.md +++ /dev/null @@ -1,5 +0,0 @@ -# Repository - -1. [WebAssembly Package Manager](https://wapm.io/) -1. [About GitHub Packages](https://docs.github.com/en/free-pro-team@latest/packages/publishing-and-managing-packages/about-github-packages#supported-clients-and-formats) - diff --git a/documentation/bookmark/api/rest.md b/documentation/bookmark/api/rest.md deleted file mode 100644 index 50186c599..000000000 --- a/documentation/bookmark/api/rest.md +++ /dev/null @@ -1,4 +0,0 @@ -# Reference - -0. [Standards.REST](https://standards.rest/) - diff --git a/documentation/bookmark/application_binary_interface.md b/documentation/bookmark/application_binary_interface.md index 454bcafb2..a5c7a78fe 100644 --- a/documentation/bookmark/application_binary_interface.md +++ b/documentation/bookmark/application_binary_interface.md @@ -1,4 +1,5 @@ # Reference +0. [To Save C, We Must Save ABI](https://thephd.dev/to-save-c-we-must-save-abi-fixing-c-function-abi) 0. [Making Libraries Consumable for Non-C++ Developers - Aaron R Robinson - CppCon 2021](https://www.youtube.com/watch?v=4r09pv9v1w0) diff --git a/documentation/bookmark/application_programming_interface.md b/documentation/bookmark/application_programming_interface.md new file mode 100644 index 000000000..47c8613a6 --- /dev/null +++ b/documentation/bookmark/application_programming_interface.md @@ -0,0 +1,4 @@ +# Reference + +0. [Aligning on Your API Design Using Jobs to be Done](https://blog.stoplight.io/aligning-on-your-api-design-using-jobs-to-be-done) + diff --git a/documentation/bookmark/application_programming_interface/rest.md b/documentation/bookmark/application_programming_interface/rest.md new file mode 100644 index 000000000..bb063dc6d --- /dev/null +++ b/documentation/bookmark/application_programming_interface/rest.md @@ -0,0 +1,5 @@ +# Reference + +0. [How to design better APIs: 15 language-agnostic, actionable tips on REST API design.](https://r.bluethl.net/how-to-design-better-apis) +0. [Standards.REST](https://standards.rest/) + diff --git a/documentation/bookmark/back_end/c.md b/documentation/bookmark/back_end/c.md index 8e08e7326..17c3b9ee9 100644 --- a/documentation/bookmark/back_end/c.md +++ b/documentation/bookmark/back_end/c.md @@ -1,5 +1,6 @@ # Reference +0. [Functional C](https://ris.utwente.nl/ws/portalfiles/portal/5128727/book.pdf) 0. [Cello: High Level C](https://libcello.org/) 0. [C as a scripting language thanks to TinyCC](https://ciesie.com/post/tinycc_dynamic_compilation/) 0. [mlibc: Portable C standard library](https://github.com/managarm/mlibc) diff --git a/documentation/bookmark/back_end/rust.md b/documentation/bookmark/back_end/rust.md new file mode 100644 index 000000000..ed0ef7b1e --- /dev/null +++ b/documentation/bookmark/back_end/rust.md @@ -0,0 +1,4 @@ +# Reference + +0. [CXX — safe interop between Rust and C++](https://cxx.rs/) + diff --git a/documentation/bookmark/commercialization.md b/documentation/bookmark/commercialization.md new file mode 100644 index 000000000..fde647857 --- /dev/null +++ b/documentation/bookmark/commercialization.md @@ -0,0 +1,4 @@ +# Reference + +0. [New sponsors-only repositories, custom amounts, and more](https://github.blog/2022-02-02-new-sponsors-only-repositories-custom-amounts-and-more/) + diff --git a/documentation/bookmark/commercialization/licensing.md b/documentation/bookmark/commercialization/licensing.md new file mode 100644 index 000000000..a67c974aa --- /dev/null +++ b/documentation/bookmark/commercialization/licensing.md @@ -0,0 +1,6 @@ +# Reference + +0. [Universal Basic Cop-Out](https://writing.kemitchell.com/2022/02/04/Universal-Basic-Cop-Out.html) +0. [The Tyranny of Openness: What Happened to Peer Production?](https://osf.io/9utyk/?view_only=44b5c10772d5470892b701dfe4b2c833) +0. [Shared Source Initiative](https://en.wikipedia.org/wiki/Shared_Source_Initiative) + diff --git a/documentation/bookmark/commercialization/marketplace.md b/documentation/bookmark/commercialization/marketplace.md new file mode 100644 index 000000000..4cc16d3ad --- /dev/null +++ b/documentation/bookmark/commercialization/marketplace.md @@ -0,0 +1,4 @@ +# Reference + +0. [sdkbin: The marketplace for software developers.](https://sdkbin.com/) + diff --git a/documentation/bookmark/compilation/just_in_time.md b/documentation/bookmark/compilation/just_in_time.md new file mode 100644 index 000000000..dea94f107 --- /dev/null +++ b/documentation/bookmark/compilation/just_in_time.md @@ -0,0 +1,4 @@ +# Reference + +0. [Trace-based compilation in execution environments without interpreters](https://dl.acm.org/doi/10.1145/1852761.1852771) + diff --git a/documentation/bookmark/feature_toggle.md b/documentation/bookmark/feature_toggle.md new file mode 100644 index 000000000..ec99c1c35 --- /dev/null +++ b/documentation/bookmark/feature_toggle.md @@ -0,0 +1,5 @@ +# Reference + +0. [When Feature Flags Do And Don’t Make Sense](https://software.rajivprab.com/2019/12/19/when-feature-flags-do-and-dont-make-sense/) +0. [Feature Toggles (aka Feature Flags)](https://martinfowler.com/articles/feature-toggles.html) + diff --git a/documentation/bookmark/floating_point.md b/documentation/bookmark/floating_point.md index c18d7fa7e..a344106c2 100644 --- a/documentation/bookmark/floating_point.md +++ b/documentation/bookmark/floating_point.md @@ -15,6 +15,7 @@ # Comparison +0. [Comparing Floating-Point Numbers Is Tricky](https://www.youtube.com/watch?v=iW7H1KfSJ8s) 0. [Approximate Equality for Floating Point](https://github.com/apple/swift-evolution/blob/master/proposals/0259-approximately-equal.md) # Random generation diff --git a/documentation/bookmark/game/algorithm/collision_detection.md b/documentation/bookmark/game/algorithm/collision_detection.md new file mode 100644 index 000000000..89a53bb94 --- /dev/null +++ b/documentation/bookmark/game/algorithm/collision_detection.md @@ -0,0 +1,4 @@ +# Reference + +0. [GJK: Collision detection algorithm in 2D/3D](https://blog.winter.dev/2020/gjk-algorithm/) + diff --git a/documentation/bookmark/game/engine.md b/documentation/bookmark/game/engine.md index 53d2e2d56..5b0555f3b 100644 --- a/documentation/bookmark/game/engine.md +++ b/documentation/bookmark/game/engine.md @@ -2,6 +2,7 @@ ## General +0. [The Machinery](https://ourmachinery.com/) 0. [Open 3D Engine](https://www.o3de.org/) ## Specialized diff --git a/documentation/bookmark/game/mechanic/boss.md b/documentation/bookmark/game/mechanic/boss.md index 25522da6c..be2f952ee 100644 --- a/documentation/bookmark/game/mechanic/boss.md +++ b/documentation/bookmark/game/mechanic/boss.md @@ -1,5 +1,6 @@ # Reference +0. [What Makes A Good Colossal Boss?](https://www.youtube.com/watch?v=k1hFnjUFSsY) 0. [What Makes A Great First Boss? ~ Design Doc](https://www.youtube.com/watch?v=0NGBo3HUrn0) 0. [Ally Brinken & Michelle Webb - Who's the Boss (And How and Why)?](https://www.youtube.com/watch?v=6JjEXyfXt3U) diff --git a/documentation/bookmark/gpu_programming.md b/documentation/bookmark/gpu_programming.md index 02444379e..1f36ccfb0 100644 --- a/documentation/bookmark/gpu_programming.md +++ b/documentation/bookmark/gpu_programming.md @@ -1,5 +1,6 @@ # Reference +0. [GPU.js: GPU accelerated JavaScript](https://gpu.rocks/#/) 0. [cudaFlow: Modern C++ Programming Model for GPU Task Graph Parallelism - CppCon 2021](https://www.youtube.com/watch?v=-tIQbIhTAv8) 0. [GPU Accelerated Computing on Cross-Vendor Graphics Cards with Vulkan Kompute - Alejandro Saucedo](https://www.youtube.com/watch?v=DBcXrJtJaIQ) 0. [Generic GPU Kernels](https://mikeinnes.github.io/2017/08/24/cudanative.html) diff --git a/documentation/bookmark/hardware.md b/documentation/bookmark/heterogeneous_computing.md index 5378d55f5..c025e91ad 100644 --- a/documentation/bookmark/hardware.md +++ b/documentation/bookmark/heterogeneous_computing.md @@ -1,4 +1,6 @@ # Reference +0. [Level up Your Java Performance with TornadoVM](https://www.infoq.com/articles/java-performance-tornadovm/) +0. [TornadoVM](https://www.tornadovm.org/) 0. [Heterogeneous Modern C++ with SYCL 2020 - Michael Wong, Nevin Liber, Tom Deakin & Gordon Brown](https://www.youtube.com/watch?v=5awOtaJw8XM) diff --git a/documentation/bookmark/math/geometry/differential.md b/documentation/bookmark/math/geometry/differential.md new file mode 100644 index 000000000..73c9f465f --- /dev/null +++ b/documentation/bookmark/math/geometry/differential.md @@ -0,0 +1,4 @@ +# Reference + +0. [Visual Differential Geometry and Forms: A Mathematical Drama in Five Acts](https://press.princeton.edu/books/hardcover/9780691203690/visual-differential-geometry-and-forms) + diff --git a/documentation/bookmark/optimization/dead_code_elimination.md b/documentation/bookmark/optimization/dead_code_elimination.md new file mode 100644 index 000000000..03a4bd9ca --- /dev/null +++ b/documentation/bookmark/optimization/dead_code_elimination.md @@ -0,0 +1,5 @@ +# Reference + +0. [PartialExecuter: Reducing WebAssembly size by exploring all executions in LLVM](https://leaningtech.com/reducing-webassembly-size-by-exploring-all-executions-in-llvm/) +0. [Dead code elimination](https://en.wikipedia.org/wiki/Dead_code_elimination) + diff --git a/documentation/bookmark/security.md b/documentation/bookmark/security.md index 301a2e163..bb88f8a3f 100644 --- a/documentation/bookmark/security.md +++ b/documentation/bookmark/security.md @@ -1,3 +1,7 @@ +# ID + +0. [Code Smell 120 - Sequential IDs](https://maximilianocontieri.com/code-smell-120-sequential-ids) + # Anti-Debugging 0. [JavaScript AntiDebugging Tricks](https://x-c3ll.github.io/posts/javascript-antidebugging/) diff --git a/documentation/bookmark/testing.md b/documentation/bookmark/testing.md index 6d12ee5a2..c28708d0e 100644 --- a/documentation/bookmark/testing.md +++ b/documentation/bookmark/testing.md @@ -23,6 +23,10 @@ 0. [Cross-Branch Testing](https://www.hillelwayne.com/post/cross-branch-testing/) +# Coverage + +0. [Modified condition/decision coverage](https://en.wikipedia.org/wiki/Modified_condition/decision_coverage) + # Reference 0. [Test Anything Protocol](http://testanything.org/) diff --git a/documentation/bookmark/text/ascii.md b/documentation/bookmark/text/ascii.md new file mode 100644 index 000000000..a1f7792a1 --- /dev/null +++ b/documentation/bookmark/text/ascii.md @@ -0,0 +1,4 @@ +# Reference + +0. [Writing semantic ASCII](https://smitop.com/post/ascii/) + diff --git a/documentation/bookmark/tool/package_manager.md b/documentation/bookmark/tool/package_manager.md new file mode 100644 index 000000000..410aa2faf --- /dev/null +++ b/documentation/bookmark/tool/package_manager.md @@ -0,0 +1,6 @@ +# Repository + +0. [Meta Package Manager: one CLI for all package managers](https://github.com/kdeldycke/meta-package-manager) +0. [WebAssembly Package Manager](https://wapm.io/) +0. [About GitHub Packages](https://docs.github.com/en/free-pro-team@latest/packages/publishing-and-managing-packages/about-github-packages#supported-clients-and-formats) + diff --git a/documentation/bookmark/type_theory/gradual.md b/documentation/bookmark/type_theory/gradual.md new file mode 100644 index 000000000..0ad15b912 --- /dev/null +++ b/documentation/bookmark/type_theory/gradual.md @@ -0,0 +1,4 @@ +# Reference + +0. [Putting gradual types to work](https://arxiv.org/abs/2101.12299) + diff --git a/documentation/bookmark/user_interface/accessibility.md b/documentation/bookmark/user_interface/accessibility.md index d4f38e0c1..0880d713d 100644 --- a/documentation/bookmark/user_interface/accessibility.md +++ b/documentation/bookmark/user_interface/accessibility.md @@ -1,5 +1,6 @@ # Reference +0. [Inclusive Design Principles](https://inclusivedesignprinciples.org/) 0. [Making Accessibility More Accessible](https://austingil.com/making-accessibility-more-accessible/) 0. [Detecting Hover-Capable Devices](https://css-irl.info/detecting-hover-capable-devices/) 0. [Nobody talks about the real reason to use Tabs over Spaces](https://www.reddit.com/r/javascript/comments/c8drjo/nobody_talks_about_the_real_reason_to_use_tabs/?st=jxuy98ok&sh=8487bdfa) diff --git a/documentation/bookmark/user_interface/color.md b/documentation/bookmark/user_interface/color.md index a4de0c8e3..16dc073bd 100644 --- a/documentation/bookmark/user_interface/color.md +++ b/documentation/bookmark/user_interface/color.md @@ -1,8 +1,10 @@ # Reference -1. [Building a color scheme: A foundational overview of how to establish a dynamic and configurable color scheme](https://web.dev/building-a-color-scheme/) -1. [Web-safe colors](https://en.wikipedia.org/wiki/Web_colors#Web-safe_colors) -1. [CSS Gradient Fixer](https://www.da.vidbuchanan.co.uk/widgets/css-gradient-fixer/) -1. [Towards richer colors on the Web](https://darker.ink/writings/Towards-richer-colors-on-the-Web) -1. [How software gets color wrong](https://bottosson.github.io/posts/colorwrong/) +0. [CSS System Colors](https://blog.jim-nielsen.com/2021/css-system-colors/) +0. [LUTious Color: Grading for Games](https://www.youtube.com/watch?v=-fb3QXR5spE) +0. [Building a color scheme: A foundational overview of how to establish a dynamic and configurable color scheme](https://web.dev/building-a-color-scheme/) +0. [Web-safe colors](https://en.wikipedia.org/wiki/Web_colors#Web-safe_colors) +0. [CSS Gradient Fixer](https://www.da.vidbuchanan.co.uk/widgets/css-gradient-fixer/) +0. [Towards richer colors on the Web](https://darker.ink/writings/Towards-richer-colors-on-the-Web) +0. [How software gets color wrong](https://bottosson.github.io/posts/colorwrong/) diff --git a/documentation/bookmark/web/api/barcode.md b/documentation/bookmark/web/api/barcode.md new file mode 100644 index 000000000..fb0ddd869 --- /dev/null +++ b/documentation/bookmark/web/api/barcode.md @@ -0,0 +1,4 @@ +# Reference + +0. [Barcode Detection API](https://developer.mozilla.org/en-US/docs/Web/API/Barcode_Detection_API) + diff --git a/lux-mode/lux-mode.el b/lux-mode/lux-mode.el index 016c0170c..ff17f0a44 100644 --- a/lux-mode/lux-mode.el +++ b/lux-mode/lux-mode.el @@ -461,7 +461,7 @@ Called by `imenu--generic-function'." in-module in-local)) (typeRE (concat global_prefix (+class identifier_h|type) (-class identifier_t) "*")) - (labelRE (concat global_prefix (+class identifier_h|label) (-class identifier_t) "*")) + (labelRE (concat global_prefix (+class identifier_h|label) (-class identifier_t) "+")) (literalRE (altRE bitRE ;; Bit literals natRE ;; Nat literals int&fracRE ;; Int literals && Frac literals diff --git a/stdlib/source/library/lux/control/concurrency/thread.lux b/stdlib/source/library/lux/control/concurrency/thread.lux index 5e76521ed..0f5c30601 100644 --- a/stdlib/source/library/lux/control/concurrency/thread.lux +++ b/stdlib/source/library/lux/control/concurrency/thread.lux @@ -56,9 +56,9 @@ @.python (ffi.import: threading/Timer - ["[1]::[0]" - (new [ffi.Float ffi.Function]) - (start [] "io" "?" Any)])] + "[1]::[0]" + (new [ffi.Float ffi.Function]) + (start [] "io" "?" Any))] ... Default (type: Thread @@ -129,15 +129,14 @@ @.jvm <jvm> @.js - (..setTimeout [(ffi.closure [] (..execute! action)) - (n.frac milli_seconds)]) + (..setTimeout (ffi.function [] (..execute! action)) + (n.frac milli_seconds)) @.python (do io.monad - [_ (|> (ffi.lambda [] (..execute! action)) - [(|> milli_seconds n.frac (f./ +1,000.0))] - threading/Timer::new - (threading/Timer::start []))] + [_ (|> (ffi.function [] (..execute! action)) + (threading/Timer::new (|> milli_seconds n.frac (f./ +1,000.0))) + threading/Timer::start)] (in []))] ... Default diff --git a/stdlib/source/library/lux/data/text.lux b/stdlib/source/library/lux/data/text.lux index 01e39705f..2f6d9fe7e 100644 --- a/stdlib/source/library/lux/data/text.lux +++ b/stdlib/source/library/lux/data/text.lux @@ -238,11 +238,11 @@ ("js object do" "replaceAll" template [pattern replacement]))) @.python (:as Text - ("python object do" "replace" template pattern replacement)) + ("python object do" "replace" template [pattern replacement])) ... TODO @.lua @.ruby (:as Text - ("ruby object do" "gsub" template pattern replacement)) + ("ruby object do" "gsub" template [pattern replacement])) @.php (:as Text ("php apply" (:expected ("php constant" "str_replace")) @@ -365,13 +365,13 @@ ("js object do" "toLowerCase" value [])) @.python (:as Text - ("python object do" "lower" value)) + ("python object do" "lower" value [])) @.lua (:as Text - ("lua apply" ("lua constant" "string.lower") value)) + ("lua apply" ("lua constant" "string.lower") [value])) @.ruby (:as Text - ("ruby object do" "downcase" value))])) + ("ruby object do" "downcase" value []))])) (def: .public (upper_cased value) (-> Text Text) @@ -388,10 +388,10 @@ ("js object do" "toUpperCase" value [])) @.python (:as Text - ("python object do" "upper" value)) + ("python object do" "upper" value [])) @.lua (:as Text - ("lua apply" ("lua constant" "string.upper") value)) + ("lua apply" ("lua constant" "string.upper") [value])) @.ruby (:as Text - ("ruby object do" "upcase" value))])) + ("ruby object do" "upcase" value []))])) diff --git a/stdlib/source/library/lux/data/text/buffer.lux b/stdlib/source/library/lux/data/text/buffer.lux index a07e65250..18b4e74c7 100644 --- a/stdlib/source/library/lux/data/text/buffer.lux +++ b/stdlib/source/library/lux/data/text/buffer.lux @@ -37,9 +37,9 @@ (`` (for [@.old (as_is <jvm>) @.jvm (as_is <jvm>) @.js (as_is (import: (JS_Array a) - ["[1]::[0]" - (push [a] a) - (join [Text] Text)])) + "[1]::[0]" + (push [a] a) + (join [Text] Text))) @.lua (as_is (import: (table/concat [(array.Array Text) Text] Text)) ...https://www.lua.org/manual/5.3/manual.html#pdf-table.concat (import: (table/insert [(array.Array Text) Text] "?" Nothing)) @@ -82,7 +82,7 @@ then! (: (-> (JS_Array Text) (JS_Array Text)) (function (_ array) (exec - (JS_Array::push [chunk] array) + (JS_Array::push chunk array) array)))] (:abstraction [(n.+ (//.size chunk) capacity) (|>> transform then!)])) @@ -90,7 +90,7 @@ then! (: (-> (array.Array Text) (array.Array Text)) (function (_ array) (exec - (table/insert [array chunk]) + (table/insert array chunk) array)))] (:abstraction [(n.+ (//.size chunk) capacity) (|>> transform then!)]))] @@ -123,9 +123,9 @@ (|> (array.empty 0) (:as (JS_Array Text)) transform - (JS_Array::join [""]))) + (JS_Array::join ""))) @.lua (let [[capacity transform] (:representation buffer)] - (table/concat [(transform (array.empty 0)) ""]))] + (table/concat (transform (array.empty 0)) ""))] ... default (sequence#mix (function (_ chunk total) (format total chunk)) diff --git a/stdlib/source/library/lux/data/text/encoding/utf8.lux b/stdlib/source/library/lux/data/text/encoding/utf8.lux index ac4a452be..915d6b895 100644 --- a/stdlib/source/library/lux/data/text/encoding/utf8.lux +++ b/stdlib/source/library/lux/data/text/encoding/utf8.lux @@ -20,36 +20,36 @@ @.js (as_is (ffi.import: Uint8Array - ["[1]::[0]"]) + "[1]::[0]") ... On Node (ffi.import: Buffer - ["[1]::[0]" - ("static" from "as" from|encoded [ffi.String ffi.String] Buffer) - ("static" from "as" from|decoded [Uint8Array] Buffer) - (toString [ffi.String] ffi.String)]) + "[1]::[0]" + ("static" from "as" from|encoded [ffi.String ffi.String] Buffer) + ("static" from "as" from|decoded [Uint8Array] Buffer) + (toString [ffi.String] ffi.String)) ... On the browser (ffi.import: TextEncoder - ["[1]::[0]" - (new [ffi.String]) - (encode [ffi.String] Uint8Array)]) + "[1]::[0]" + (new [ffi.String]) + (encode [ffi.String] Uint8Array)) (ffi.import: TextDecoder - ["[1]::[0]" - (new [ffi.String]) - (decode [Uint8Array] ffi.String)])) + "[1]::[0]" + (new [ffi.String]) + (decode [Uint8Array] ffi.String))) @.ruby - (as_is (ffi.import: String "as" RubyString - ["[1]::[0]" - (encode [Text] RubyString) - (force_encoding [Text] Text) - (bytes [] Binary)]) + (as_is (ffi.import: String + "[1]::[0]" + (encode [Text] String) + (force_encoding [Text] Text) + (bytes [] Binary)) - (ffi.import: Array "as" RubyArray - ["[1]::[0]" - (pack [Text] RubyString)])) + (ffi.import: Array + "[1]::[0]" + (pack [Text] String))) @.php (as_is (ffi.import: Almost_Binary) @@ -78,27 +78,27 @@ (:as Binary ("js object do" "getBytes" value ["utf8"])) ffi.on_node_js? - (|> (Buffer::from|encoded [value "utf8"]) + (|> (Buffer::from|encoded value "utf8") ... This coercion is valid as per NodeJS's documentation: ... https://nodejs.org/api/buffer.html#buffer_buffers_and_typedarrays (:as Uint8Array)) ... On the browser - (|> (TextEncoder::new [(//.name //.utf_8)]) + (|> (TextEncoder::new (//.name //.utf_8)) (TextEncoder::encode [value])) ) @.python - (:as Binary ("python apply" (:expected ("python constant" "bytearray")) value "utf-8")) + (:as Binary ("python apply" (:expected ("python constant" "bytearray")) [value "utf-8"])) @.lua ("lua utf8 encode" value) @.ruby (|> value - (:as RubyString) - (RubyString::encode ["UTF-8"]) - (RubyString::bytes [])) + (:as String) + (String::encode "UTF-8") + (String::bytes)) @.php (|> (..unpack [..php_byte_array_format value]) @@ -122,27 +122,27 @@ {try.#Success}) ffi.on_node_js? - (|> (Buffer::from|decoded [value]) - (Buffer::toString ["utf8"]) + (|> (Buffer::from|decoded value) + (Buffer::toString "utf8") {try.#Success}) ... On the browser - (|> (TextDecoder::new [(//.name //.utf_8)]) - (TextDecoder::decode [value]) + (|> (TextDecoder::new (//.name //.utf_8)) + (TextDecoder::decode value) {try.#Success})) @.python - (try (:as Text ("python object do" "decode" (:expected value) "utf-8"))) + (try (:as Text ("python object do" "decode" (:expected value) ["utf-8"]))) @.lua {try.#Success ("lua utf8 decode" value)} @.ruby (|> value - (:as RubyArray) - (RubyArray::pack ["C*"]) - (:as RubyString) - (RubyString::force_encoding ["UTF-8"]) + (:as Array) + (Array::pack "C*") + (:as String) + (String::force_encoding "UTF-8") {try.#Success}) @.php diff --git a/stdlib/source/library/lux/debug.lux b/stdlib/source/library/lux/debug.lux index 6940b2f5e..a807c8ba1 100644 --- a/stdlib/source/library/lux/debug.lux +++ b/stdlib/source/library/lux/debug.lux @@ -71,11 +71,11 @@ @.js (as_is (import: JSON - ["[1]::[0]" - ("static" stringify [.Any] ffi.String)]) + "[1]::[0]" + ("static" stringify [.Any] ffi.String)) (import: Array - ["[1]::[0]" - ("static" isArray [.Any] ffi.Boolean)])) + "[1]::[0]" + ("static" isArray [.Any] ffi.Boolean))) @.python (as_is (type: PyType @@ -89,16 +89,17 @@ (import: (tostring [.Any] ffi.String)) (import: math - ["[1]::[0]" - ("static" type [.Any] "?" ffi.String)])) + "[1]::[0]" + ("static" type [.Any] "?" ffi.String))) @.ruby - (as_is (import: Class) + (as_is (import: Class + "[1]::[0]") (import: Object - ["[1]::[0]" - (class [] Class) - (to_s [] ffi.String)])) + "[1]::[0]" + (class [] Class) + (to_s [] ffi.String))) @.php (as_is (import: (gettype [.Any] ffi.String)) @@ -256,7 +257,7 @@ ["nil" [(new> "nil" [])]]) "number" - (case (math::type [value]) + (case (math::type value) {.#Some "integer"} (|> value (:as .Int) %.int) {.#Some "float"} (|> value (:as .Frac) %.frac) @@ -282,12 +283,12 @@ (template.let [(class_of <literal>) [(|> <literal> (:as ..Object) - (Object::class []))] + Object::class)] (to_s <object>) [(|> <object> (:as ..Object) - (Object::to_s []))]] + Object::to_s)]] (let [value_class (class_of value)] (`` (cond (~~ (template [<literal> <type> <format>] [(same? (class_of <literal>) value_class) diff --git a/stdlib/source/library/lux/ffi.js.lux b/stdlib/source/library/lux/ffi.js.lux deleted file mode 100644 index 8cae0a976..000000000 --- a/stdlib/source/library/lux/ffi.js.lux +++ /dev/null @@ -1,406 +0,0 @@ -(.using - [library - [lux {"-" Symbol} - ["[0]" meta] - [abstract - [monad {"+" do}]] - [control - ["[0]" io] - ["[0]" maybe] - ["<>" parser ("[1]#[0]" monad) - ["<[0]>" code {"+" Parser}]]] - [data - ["[0]" product] - ["[0]" text - ["%" format]] - [collection - ["[0]" list ("[1]#[0]" functor)]]] - [type - abstract] - [macro {"+" with_symbols} - [syntax {"+" syntax:}] - ["[0]" code] - ["[0]" template]]]]) - -(abstract: .public (Object brand) Any) - -(template [<name>] - [(with_expansions [<brand> (template.symbol [<name> "'"])] - (abstract: <brand> - Any - - (type: .public <name> - (Object <brand>))))] - - [Function] - [Symbol] - [Null] - [Undefined] - ) - -(template [<name> <type>] - [(type: .public <name> - <type>)] - - [Boolean Bit] - [Number Frac] - [String Text] - ) - -(type: Nullable - [Bit Code]) - -(def: nullable - (Parser Nullable) - (let [token (' "?")] - (<| (<>.and (<>.parses? (<code>.this! token))) - (<>.after (<>.not (<code>.this! token))) - <code>.any))) - -(type: Constructor - (List Nullable)) - -(def: constructor - (Parser Constructor) - (<code>.form (<>.after (<code>.this! (' new)) - (<code>.tuple (<>.some ..nullable))))) - -(type: Field - [Bit Text Nullable]) - -(def: static! - (Parser Any) - (<code>.this! (' "static"))) - -(def: field - (Parser Field) - (<code>.form ($_ <>.and - (<>.parses? ..static!) - <code>.local_symbol - ..nullable))) - -(def: constant_import - (Parser Field) - (<code>.form ($_ <>.and - (<>#in true) - <code>.local_symbol - ..nullable))) - -(type: Common_Method - (Record - [#name Text - #alias (Maybe Text) - #inputs (List Nullable) - #io? Bit - #try? Bit - #output Nullable])) - -(type: Static_Method Common_Method) -(type: Virtual_Method Common_Method) - -(type: Method - (Variant - {#Static Static_Method} - {#Virtual Virtual_Method})) - -(def: common_method - (Parser Common_Method) - ($_ <>.and - <code>.local_symbol - (<>.maybe (<>.after (<code>.this! (' "as")) <code>.local_symbol)) - (<code>.tuple (<>.some ..nullable)) - (<>.parses? (<code>.this! (' "io"))) - (<>.parses? (<code>.this! (' "try"))) - ..nullable)) - -(def: static_method - (<>.after ..static! ..common_method)) - -(def: method - (Parser Method) - (<code>.form (<>.or ..static_method - ..common_method))) - -(type: Member - (Variant - {#Constructor Constructor} - {#Field Field} - {#Method Method})) - -(def: member - (Parser Member) - ($_ <>.or - ..constructor - ..field - ..method - )) - -(def: input_variables - (-> (List Nullable) (List [Bit Code])) - (|>> list.enumeration - (list#each (function (_ [idx [nullable? type]]) - [nullable? (|> idx %.nat code.local_symbol)])))) - -(def: (nullable_type [nullable? type]) - (-> Nullable Code) - (if nullable? - (` (.Maybe (~ type))) - type)) - -(def: (with_null g!temp [nullable? input]) - (-> Code [Bit Code] Code) - (if nullable? - (` (case (~ input) - {.#Some (~ g!temp)} - (~ g!temp) - - {.#None} - ("js object null"))) - input)) - -(def: .public (null _) - (-> Any Nothing) - (:expected ("js object null"))) - -(def: .public null? - (-> Any Bit) - (|>> "js object null?")) - -(def: (without_null g!temp [nullable? outputT] output) - (-> Code Nullable Code Code) - (if nullable? - (` (let [(~ g!temp) (~ output)] - (if ("js object null?" (~ g!temp)) - {.#None} - {.#Some (~ g!temp)}))) - (` (let [(~ g!temp) (~ output)] - (if (not ("js object null?" (~ g!temp))) - (~ g!temp) - (.panic! "Null is an invalid value.")))))) - -(type: Class_Declaration - [Text (List Text)]) - -(type: Import - (Variant - {#Class [Class_Declaration Text (List Member)]} - {#Function Static_Method} - {#Constant Field})) - -(def: class_declaration - (Parser Class_Declaration) - (<>.either (<>.and <code>.local_symbol - (<>#in (list))) - (<code>.form (<>.and <code>.local_symbol - (<>.some <code>.local_symbol))))) - -(def: import - (Parser Import) - ($_ <>.or - (<>.and ..class_declaration - (<code>.tuple (<>.and <code>.text - (<>.some member)))) - (<code>.form ..common_method) - ..constant_import)) - -(def: (with_io with? without) - (-> Bit Code Code) - (if with? - (` ((~! io.io) (~ without))) - without)) - -(def: (io_type io? rawT) - (-> Bit Code Code) - (if io? - (` ((~! io.IO) (~ rawT))) - rawT)) - -(def: (with_try with? without_try) - (-> Bit Code Code) - (if with? - (` (.try (~ without_try))) - without_try)) - -(def: (try_type try? rawT) - (-> Bit Code Code) - (if try? - (` (.Either .Text (~ rawT))) - rawT)) - -(def: (make_function g!method g!temp source inputsT io? try? outputT) - (-> Code Code Text (List Nullable) Bit Bit Nullable Code) - (let [g!inputs (input_variables inputsT)] - (` (def: ((~ g!method) - [(~+ (list#each product.right g!inputs))]) - (-> [(~+ (list#each nullable_type inputsT))] - (~ (|> (nullable_type outputT) - (try_type try?) - (io_type io?)))) - (:expected - (~ (<| (with_io io?) - (with_try try?) - (without_null g!temp outputT) - (` ("js apply" - ("js constant" (~ (code.text source))) - (~+ (list#each (with_null g!temp) g!inputs))))))))))) - -(syntax: .public (import: [import ..import]) - (with_symbols [g!temp g!_] - (case import - {#Class [[class_name class_parameters] format members]} - (with_symbols [g!object] - (let [qualify (: (-> Text Code) - (function (_ member_name) - (|> format - (text.replaced "[1]" class_name) - (text.replaced "[0]" member_name) - code.local_symbol))) - class_parameters (list#each code.local_symbol class_parameters) - declaration (` ((~ (code.local_symbol class_name)) - (~+ class_parameters))) - real_class (text.replaced "/" "." class_name)] - (in (list& (` (type: (~ declaration) - (..Object (Primitive (~ (code.text real_class)))))) - (list#each (function (_ member) - (case member - {#Constructor inputsT} - (let [g!inputs (input_variables inputsT)] - (` (def: ((~ (qualify "new")) - [(~+ (list#each product.right g!inputs))]) - (All ((~ g!_) (~+ class_parameters)) - (-> [(~+ (list#each nullable_type inputsT))] - (~ declaration))) - (:expected - ("js object new" - ("js constant" (~ (code.text real_class))) - [(~+ (list#each (with_null g!temp) g!inputs))]))))) - - {#Field [static? field fieldT]} - (if static? - (` ((~! syntax:) ((~ (qualify field)) []) - (# (~! meta.monad) (~' in) - (list (` (.:as (~ (nullable_type fieldT)) - ("js constant" (~ (code.text (%.format real_class "." field)))))))))) - (` (def: ((~ (qualify field)) - (~ g!object)) - (All ((~ g!_) (~+ class_parameters)) - (-> (~ declaration) - (~ (nullable_type fieldT)))) - (:expected - (~ (without_null g!temp fieldT (` ("js object get" (~ (code.text field)) (~ g!object))))))))) - - {#Method method} - (case method - {#Static [method alias inputsT io? try? outputT]} - (..make_function (qualify (maybe.else method alias)) - g!temp - (%.format real_class "." method) - inputsT - io? - try? - outputT) - - {#Virtual [method alias inputsT io? try? outputT]} - (let [g!inputs (input_variables inputsT)] - (` (def: ((~ (qualify (maybe.else method alias))) - [(~+ (list#each product.right g!inputs))] - (~ g!object)) - (All ((~ g!_) (~+ class_parameters)) - (-> [(~+ (list#each nullable_type inputsT))] - (~ declaration) - (~ (|> (nullable_type outputT) - (try_type try?) - (io_type io?))))) - (:expected - (~ (<| (with_io io?) - (with_try try?) - (without_null g!temp outputT) - (` ("js object do" - (~ (code.text method)) - (~ g!object) - [(~+ (list#each (with_null g!temp) g!inputs))]))))))))))) - members))))) - - {#Function [name alias inputsT io? try? outputT]} - (in (list (..make_function (code.local_symbol (maybe.else name alias)) - g!temp - name - inputsT - io? - try? - outputT))) - - {#Constant [_ name :output:]} - (in (list (` (.def: (~ (code.local_symbol name)) - (~ (nullable_type :output:)) - (.:expected - (~ (<| (without_null g!temp :output:) - (` ("js constant" (~ (code.text name))))))))))) - ))) - -(template: .public (type_of object) - [("js type-of" object)]) - -(syntax: .public (constant [type <code>.any - [head tail] (<code>.tuple (<>.and <code>.local_symbol (<>.some <code>.local_symbol)))]) - (with_symbols [g!_] - (let [constant (` ("js constant" (~ (code.text head))))] - (case tail - {.#End} - (in (list (` (: (.Maybe (~ type)) - (case (..type_of (~ constant)) - "undefined" - {.#None} - - (~ g!_) - {.#Some (:as (~ type) (~ constant))}))))) - - {.#Item [next tail]} - (let [separator "."] - (in (list (` (: (.Maybe (~ type)) - (case (..type_of (~ constant)) - "undefined" - {.#None} - - (~ g!_) - (..constant (~ type) [(~ (code.local_symbol (%.format head "." next))) - (~+ (list#each code.local_symbol tail))]))))))))))) - -(template: (!defined? <constant>) - [(.case (..constant Any <constant>) - {.#None} - .false - - {.#Some _} - .true)]) - -(template [<name> <constant>] - [(def: .public <name> - Bit - (!defined? <constant>))] - - [on_browser? [window]] - [on_nashorn? [java lang Object]] - ) - -(def: .public on_node_js? - Bit - (case (..constant (Object Any) [process]) - {.#Some process} - (case (:as Text - ("js apply" ("js constant" "Object.prototype.toString.call") process)) - "[object process]" - true - - _ - false) - - {.#None} - false)) - -(template: .public (closure <inputs> <output>) - [(.:as ..Function - (`` ("js function" - (~~ (template.amount <inputs>)) - (.function (_ [<inputs>]) - <output>))))]) diff --git a/stdlib/source/library/lux/ffi.lua.lux b/stdlib/source/library/lux/ffi.lua.lux deleted file mode 100644 index 151d1cf3c..000000000 --- a/stdlib/source/library/lux/ffi.lua.lux +++ /dev/null @@ -1,314 +0,0 @@ -(.using - [library - [lux "*" - ["@" target] - ["[0]" meta] - [abstract - [monad {"+" do}]] - [control - ["[0]" io] - ["[0]" maybe] - ["<>" parser ("[1]#[0]" monad) - ["<[0]>" code {"+" Parser}]]] - [data - ["[0]" product] - ["[0]" text - ["%" format]] - [collection - ["[0]" list ("[1]#[0]" functor mix)]]] - [type - abstract] - [macro {"+" with_symbols} - [syntax {"+" syntax:}] - ["[0]" code] - ["[0]" template]]]]) - -(abstract: .public (Object brand) Any) - -(template [<name>] - [(with_expansions [<brand> (template.symbol [<name> "'"])] - (abstract: <brand> Any) - (type: .public <name> - (..Object <brand>)))] - - [Nil] - [Function] - [Table] - ) - -(template [<name> <type>] - [(type: .public <name> - <type>)] - - [Boolean Bit] - [Integer Int] - [Float Frac] - [String Text] - ) - -(type: Nilable - [Bit Code]) - -(def: nilable - (Parser Nilable) - (let [token (' "?")] - (<| (<>.and (<>.parses? (<code>.this! token))) - (<>.after (<>.not (<code>.this! token))) - <code>.any))) - -(type: Field - [Bit Text Nilable]) - -(def: static! - (Parser Any) - (<code>.this! (' "static"))) - -(def: field - (Parser Field) - (<code>.form ($_ <>.and - (<>.parses? ..static!) - <code>.local_symbol - ..nilable))) - -(def: constant - (Parser Field) - (<code>.form ($_ <>.and - (<>#in true) - <code>.local_symbol - ..nilable))) - -(type: Common_Method - (Record - [#name Text - #alias (Maybe Text) - #inputs (List Nilable) - #io? Bit - #try? Bit - #output Nilable])) - -(type: Static_Method Common_Method) -(type: Virtual_Method Common_Method) - -(type: Method - (Variant - {#Static Static_Method} - {#Virtual Virtual_Method})) - -(def: common_method - (Parser Common_Method) - ($_ <>.and - <code>.local_symbol - (<>.maybe (<>.after (<code>.this! (' "as")) <code>.local_symbol)) - (<code>.tuple (<>.some ..nilable)) - (<>.parses? (<code>.this! (' "io"))) - (<>.parses? (<code>.this! (' "try"))) - ..nilable)) - -(def: static_method - (<>.after ..static! ..common_method)) - -(def: method - (Parser Method) - (<code>.form (<>.or ..static_method - ..common_method))) - -(type: Member - (Variant - {#Field Field} - {#Method Method})) - -(def: member - (Parser Member) - ($_ <>.or - ..field - ..method - )) - -(def: input_variables - (-> (List Nilable) (List [Bit Code])) - (|>> list.enumeration - (list#each (function (_ [idx [nilable? type]]) - [nilable? (|> idx %.nat code.local_symbol)])))) - -(def: (nilable_type [nilable? type]) - (-> Nilable Code) - (if nilable? - (` (.Maybe (~ type))) - type)) - -(def: (with_nil g!temp [nilable? input]) - (-> Code [Bit Code] Code) - (if nilable? - (` (case (~ input) - {.#Some (~ g!temp)} - (~ g!temp) - - {.#None} - ("lua object nil"))) - input)) - -(def: (without_nil g!temp [nilable? outputT] output) - (-> Code Nilable Code Code) - (if nilable? - (` (let [(~ g!temp) (~ output)] - (if ("lua object nil?" (~ g!temp)) - {.#None} - {.#Some (~ g!temp)}))) - (` (let [(~ g!temp) (~ output)] - (if (not ("lua object nil?" (~ g!temp))) - (~ g!temp) - (.panic! "Nil is an invalid value!")))))) - -(type: Import - (Variant - {#Class [Text Text (List Member)]} - {#Function Static_Method} - {#Constant Field})) - -(def: import - ($_ <>.or - (<>.and <code>.local_symbol - (<>.else ["" (list)] - (<code>.tuple (<>.and <code>.text - (<>.some member))))) - (<code>.form ..common_method) - ..constant - )) - -(def: (with_io with? without) - (-> Bit Code Code) - (if with? - (` ((~! io.io) (~ without))) - without)) - -(def: (io_type io? rawT) - (-> Bit Code Code) - (if io? - (` ((~! io.IO) (~ rawT))) - rawT)) - -(def: (with_try with? without_try) - (-> Bit Code Code) - (if with? - (` (.try (~ without_try))) - without_try)) - -(def: (try_type try? rawT) - (-> Bit Code Code) - (if try? - (` (.Either .Text (~ rawT))) - rawT)) - -(def: (make_function g!method g!temp source inputsT io? try? outputT) - (-> Code Code Code (List Nilable) Bit Bit Nilable Code) - (let [g!inputs (input_variables inputsT)] - (` (def: ((~ g!method) - [(~+ (list#each product.right g!inputs))]) - (-> [(~+ (list#each nilable_type inputsT))] - (~ (|> (nilable_type outputT) - (try_type try?) - (io_type io?)))) - (:expected - (~ (<| (with_io io?) - (with_try try?) - (without_nil g!temp outputT) - (` ("lua apply" - (:as ..Function (~ source)) - (~+ (list#each (with_nil g!temp) g!inputs))))))))))) - -(syntax: .public (import: [import ..import]) - (with_symbols [g!temp] - (case import - {#Class [class format members]} - (with_symbols [g!object] - (let [qualify (: (-> Text Code) - (function (_ member_name) - (|> format - (text.replaced "[1]" class) - (text.replaced "[0]" member_name) - code.local_symbol))) - g!type (code.local_symbol class) - real_class (text.replaced "/" "." class) - imported (case (text.all_split_by "/" class) - {.#Item head tail} - (list#mix (function (_ sub super) - (` ("lua object get" (~ (code.text sub)) - (:as (..Object .Any) (~ super))))) - (` ("lua import" (~ (code.text head)))) - tail) - - {.#End} - (` ("lua import" (~ (code.text class)))))] - (in (list& (` (type: (~ g!type) - (..Object (Primitive (~ (code.text real_class)))))) - (list#each (function (_ member) - (case member - {#Field [static? field fieldT]} - (if static? - (` ((~! syntax:) ((~ (qualify field)) []) - (# (~! meta.monad) (~' in) - (list (` (.:as (~ (nilable_type fieldT)) - ("lua object get" (~ (code.text field)) - (:as (..Object .Any) (~ imported))))))))) - (` (def: ((~ (qualify field)) - (~ g!object)) - (-> (~ g!type) - (~ (nilable_type fieldT))) - (:expected - (~ (without_nil g!temp fieldT (` ("lua object get" (~ (code.text field)) - (:as (..Object .Any) (~ g!object)))))))))) - - {#Method method} - (case method - {#Static [method alias inputsT io? try? outputT]} - (..make_function (qualify (maybe.else method alias)) - g!temp - (` ("lua object get" (~ (code.text method)) - (:as (..Object .Any) (~ imported)))) - inputsT - io? - try? - outputT) - - {#Virtual [method alias inputsT io? try? outputT]} - (let [g!inputs (input_variables inputsT)] - (` (def: ((~ (qualify (maybe.else method alias))) - [(~+ (list#each product.right g!inputs))] - (~ g!object)) - (-> [(~+ (list#each nilable_type inputsT))] - (~ g!type) - (~ (|> (nilable_type outputT) - (try_type try?) - (io_type io?)))) - (:expected - (~ (<| (with_io io?) - (with_try try?) - (without_nil g!temp outputT) - (` ("lua object do" - (~ (code.text method)) - (~ g!object) - (~+ (list#each (with_nil g!temp) g!inputs))))))))))))) - members))))) - - {#Function [name alias inputsT io? try? outputT]} - (in (list (..make_function (code.local_symbol (maybe.else name alias)) - g!temp - (` ("lua constant" (~ (code.text (text.replaced "/" "." name))))) - inputsT - io? - try? - outputT))) - - {#Constant [_ name fieldT]} - (in (list (` ((~! syntax:) ((~ (code.local_symbol name)) []) - (# (~! meta.monad) (~' in) - (list (` (.:as (~ (nilable_type fieldT)) - ("lua constant" (~ (code.text (text.replaced "/" "." name)))))))))))) - ))) - -(template: .public (closure <inputs> <output>) - [(.:as ..Function - (`` ("lua function" - (~~ (template.amount <inputs>)) - (.function (_ [<inputs>]) - <output>))))]) diff --git a/stdlib/source/library/lux/ffi.lux b/stdlib/source/library/lux/ffi.lux new file mode 100644 index 000000000..7d1f709a4 --- /dev/null +++ b/stdlib/source/library/lux/ffi.lux @@ -0,0 +1,665 @@ +(.using + [library + [lux {"-" Symbol Alias Global global function} + ["@" target] + ["[0]" meta] + [abstract + [monad {"+" do}]] + [control + ["[0]" io] + ["[0]" maybe ("[1]#[0]" functor)] + ["<>" parser ("[1]#[0]" monad) + ["<[0]>" code {"+" Parser}]]] + [data + ["[0]" text ("[1]#[0]" equivalence) + ["%" format]] + [collection + ["[0]" list ("[1]#[0]" functor mix)]]] + [macro {"+" with_symbols} + [syntax {"+" syntax:}] + ["[0]" code] + ["[0]" template]] + [type + abstract]]]) + +(with_expansions [<constant> (for [@.js "js constant" + @.python "python constant" + @.lua "lua constant" + @.ruby "ruby constant"]) + <apply> (for [@.js "js apply" + @.python "python apply" + @.lua "lua apply" + @.ruby "ruby apply"]) + <new> (for [@.js "js object new" + @.python "python apply"] + (as_is)) + <do> (for [@.js "js object do" + @.python "python object do" + @.lua "lua object do" + @.ruby "ruby object do"]) + <get> (for [@.js "js object get" + @.python "python object get" + @.lua "lua object get" + @.ruby "ruby object get"] + (as_is)) + <import> (for [@.python "python import" + @.lua "lua import" + @.ruby "ruby import"] + (as_is)) + <function> (for [@.js "js function" + @.python "python function" + @.lua "lua function"] + (as_is))] + (abstract: .public (Object brand) Any) + + (with_expansions [<un_common> (for [@.js (as_is [Symbol] + [Null] + [Undefined]) + @.python (as_is [None] + [Dict]) + @.lua (as_is [Nil] + [Table]) + @.ruby (as_is [Nil])]) + <un_common> <un_common>] + (template [<name>] + [(with_expansions [<brand> (template.symbol [<name> "'"])] + (abstract: <brand> + Any + + (type: .public <name> + (Object <brand>))))] + + [Function] + <un_common> + )) + + (with_expansions [<un_common> (for [@.js (as_is [Number Frac]) + @.python (as_is [Integer Int] + [Float Frac]) + @.lua (as_is [Integer Int] + [Float Frac]) + @.ruby (as_is [Integer Int] + [Float Frac])]) + <un_common> <un_common>] + (template [<name> <type>] + [(type: .public <name> + <type>)] + + [Boolean Bit] + [String Text] + <un_common> + )) + + (type: Alias + (Maybe Text)) + + (def: alias + (Parser Alias) + (<>.maybe (<>.after (<code>.this! (' "as")) <code>.local_symbol))) + + (type: Optional + (Record + [#optional? Bit + #mandatory Code])) + + (def: optional + (Parser Optional) + (let [token "?"] + (<| (<>.and (<>.parses? (<code>.text! token))) + (<>.after (<>.not (<code>.text! token))) + <code>.any))) + + (type: (Named a) + (Record + [#name Text + #alias Alias + #anonymous a])) + + (template [<case> <name>] + [(def: <case> + (All (_ a) (-> (Parser a) (Parser (Named a)))) + (|>> ($_ <>.and + <name> + ..alias + )))] + + [named <code>.local_symbol] + [anonymous (<>#in "")] + ) + + (type: Output + Optional) + + (def: output + (Parser Output) + ..optional) + + (type: Global + (Named Output)) + + (def: variables + (Parser (List Text)) + (<>.else (list) (<code>.tuple (<>.some <code>.local_symbol)))) + + (def: (generalized $ it) + (All (_ a) + (-> (-> (List Text) a a) + (-> (Parser a) (Parser a)))) + (do <>.monad + [variables ..variables + it it] + (in ($ variables it)))) + + (type: Input + (Record + [#variables (List Text) + #parameters (List Optional) + #io? Bit + #try? Bit])) + + (def: input + (Parser Input) + ($_ <>.and + (<>#in (list)) + (<code>.tuple (<>.some ..optional)) + (<>.parses? (<code>.text! "io")) + (<>.parses? (<code>.text! "try")))) + + (type: Constructor + (Named Input)) + + (def: constructor + (Parser Constructor) + (<| <code>.form + (..generalized (with@ [#anonymous #variables])) + (<>.after (<code>.this! (' new))) + (..anonymous ..input))) + + (type: (Member a) + (Record + [#static? Bit + #member a])) + + (def: static! + (Parser Any) + (<code>.text! "static")) + + (def: (member it) + (All (_ a) + (-> (Parser a) + (Parser (Member a)))) + (do [! <>.monad] + [static? (<>.parses? ..static!)] + (# ! each + (|>> [#static? static? + #member]) + it))) + + (type: Field + (Member (Named Output))) + + (def: field + (Parser Field) + (<| <code>.form + ..member + ..named + ..output)) + + (type: Procedure + (Record + [#input Input + #output Optional])) + + (def: procedure + (Parser (Named Procedure)) + (<| (..generalized (with@ [#anonymous #input #variables])) + ..named + ($_ <>.and + ..input + ..optional + ))) + + (type: Method + (Member (Named Procedure))) + + (def: method + (Parser Method) + (<| <code>.form + ..member + ..procedure)) + + (`` (`` (type: Sub + (Variant + (~~ (for [@.lua (~~ (as_is)) + @.ruby (~~ (as_is))] + {#Constructor Constructor})) + {#Field Field} + {#Method Method})))) + + (`` (`` (def: sub + (Parser Sub) + ($_ <>.or + (~~ (for [@.lua (~~ (as_is)) + @.ruby (~~ (as_is))] + ..constructor)) + ..field + ..method + )))) + + (def: parameters + (-> (List Optional) (List Optional)) + (|>> list.enumeration + (list#each (.function (_ [idx [optional? type]]) + [#optional? optional? + #mandatory (|> idx %.nat code.local_symbol)])))) + + (def: (output_type it) + (-> Optional Code) + (if (value@ #optional? it) + (` (.Maybe (~ (value@ #mandatory it)))) + (value@ #mandatory it))) + + (`` (template [<lux_it> <host_it> + <lux_?> <host_?>] + [(def: .public (<lux_it> _) + (-> Any Nothing) + (:expected (<host_it>))) + + (def: .public <lux_?> + (-> Any Bit) + (|>> <host_?>)) + + (template.with_locals [g!it] + (as_is (def: g!it' (' g!it)) + (def: (host_optional it) + (-> Optional Code) + (.if (.value@ #optional? it) + (` (.case (~ (value@ #mandatory it)) + {.#Some (~ g!it')} + (~ g!it') + + {.#None} + (<host_it>))) + (value@ #mandatory it))) + + (def: (lux_optional it output) + (-> Optional Code Code) + (` (.let [(~ g!it') (~ output)] + (~ (if (value@ #optional? it) + (` (.if (<host_?> (~ g!it')) + {.#None} + {.#Some (~ g!it')})) + (` (.if (.not (<host_?> (~ g!it'))) + (~ g!it') + (.panic! "Invalid output."))))))))))] + + (~~ (for [@.js [null "js object null" + null? "js object null?"] + @.python [none "python object none" + none? "python object none?"] + @.lua [nil "lua object nil" + nil? "lua object nil?"] + @.ruby [nil "ruby object nil" + nil? "ruby object nil?"]])) + )) + + (type: Declaration + [Text (List Text)]) + + (type: Namespace + Text) + + (type: Class + (Record + [#declaration Declaration + #class_alias Alias + #namespace Namespace + #members (List Sub)])) + + (def: class + (Parser Class) + ($_ <>.and + (<>.either (<>.and <code>.local_symbol + (<>#in (list))) + (<code>.form (<>.and <code>.local_symbol + (<>.some <code>.local_symbol)))) + ..alias + <code>.text + (<>.some ..sub))) + + (type: Import + (Variant + {#Class Class} + {#Procedure (Named Procedure)} + {#Global Global})) + + (def: import + (Parser Import) + ($_ <>.or + ..class + (<code>.form ..procedure) + (<code>.form (..named ..output)))) + + (def: (input_type input :it:) + (-> Input Code Code) + (let [:it: (if (value@ #try? input) + (` (.Either .Text (~ :it:))) + :it:)] + (if (value@ #io? input) + (` ((~! io.IO) (~ :it:))) + :it:))) + + (def: (input_term input term) + (-> Input Code Code) + (let [term (if (value@ #try? input) + (` (.try (~ term))) + term)] + (if (value@ #io? input) + (` ((~! io.io) (~ term))) + term))) + + (def: (procedure_definition import! source it) + (-> (List Code) Code (Named Procedure) Code) + (let [g!it (|> (value@ #alias it) + (maybe.else (value@ #name it)) + code.local_symbol) + g!variables (list#each code.local_symbol (value@ [#anonymous #input #variables] it)) + input (value@ [#anonymous #input] it) + :parameters: (value@ #parameters input) + g!parameters (..parameters :parameters:) + :output: (value@ [#anonymous #output] it) + :input:/* (case :parameters: + {.#End} + (list (` [])) + + parameters + (list#each ..output_type :parameters:))] + (` (.def: ((~ g!it) (~+ (case g!parameters + {.#End} (list g!it) + _ (list#each (value@ #mandatory) g!parameters)))) + (.All ((~ g!it) (~+ g!variables)) + (-> (~+ :input:/*) + (~ (|> :output: + ..output_type + (..input_type input))))) + (.exec + (~+ import!) + (.:expected + (~ (<| (..input_term input) + (..lux_optional :output:) + (` (<apply> (.:expected (~ source)) + [(~+ (list#each ..host_optional g!parameters))])))))))))) + + (def: (namespaced namespace class alias member) + (-> Namespace Text Alias Text Text) + (|> namespace + (text.replaced "[1]" (maybe.else class alias)) + (text.replaced "[0]" member))) + + (def: class_separator ".") + + (def: host_path + (text.replaced .module_separator ..class_separator)) + + (for [@.js (as_is)] + (def: (imported class) + (-> Text Code) + (case (text.all_split_by .module_separator class) + {.#Item head tail} + (list#mix (.function (_ sub super) + (` (<get> (~ (code.text sub)) + (.:as (..Object .Any) + (~ super))))) + (` (<import> (~ (code.text head)))) + tail) + + {.#End} + (` (<import> (~ (code.text class))))))) + + (def: (global_definition import! it) + (-> (List Code) Global Code) + (let [g!name (|> (value@ #alias it) + (maybe.else (value@ #name it)) + code.local_symbol) + :output: (value@ #anonymous it)] + (` (.def: (~ g!name) + (~ (..output_type :output:)) + (.exec + (~+ import!) + (.:expected + (~ (<| (lux_optional :output:) + (` (<constant> (~ (code.text (..host_path (value@ #name it)))))))))))))) + + (for [@.lua (as_is) + @.ruby (as_is)] + (def: (constructor_definition [class_name class_parameters] alias namespace it) + (-> Declaration Alias Namespace Constructor Code) + (let [g!it (|> it + (value@ #alias) + (maybe.else "new") + (..namespaced namespace class_name alias) + code.local_symbol) + input (value@ #anonymous it) + g!input_variables (list#each code.local_symbol (value@ #variables input)) + :parameters: (value@ #parameters input) + g!parameters (..parameters :parameters:) + g!class_variables (list#each code.local_symbol class_parameters) + g!class (` ((~ (code.local_symbol (maybe.else class_name alias))) (~+ g!class_variables))) + :output: [#optional? false #mandatory g!class]] + (` (.def: ((~ g!it) (~+ (case g!parameters + {.#End} (list g!it) + _ (list#each (value@ #mandatory) g!parameters)))) + (.All ((~ g!it) (~+ g!class_variables) (~+ g!input_variables)) + (.-> (~+ (list#each ..output_type :parameters:)) + (~ (|> :output: + ..output_type + (..input_type input))))) + (.:expected + (~ (<| (..input_term input) + (..lux_optional :output:) + (` (<new> (~ (for [@.js (` (<constant> (~ (code.text (..host_path class_name))))) + @.python (` (.:as ..Function + (~ (..imported class_name))))])) + [(~+ (list#each ..host_optional g!parameters))])))))))))) + + (def: (static_field_definition import! [class_name class_parameters] alias namespace it) + (-> (List Code) Declaration Alias Namespace (Named Output) Code) + (let [field (value@ #name it) + g!it (|> (value@ #alias it) + (maybe.else field) + (..namespaced namespace class_name alias) + code.local_symbol) + :field: (value@ #anonymous it)] + (` ((~! syntax:) ((~ g!it) []) + (.# (~! meta.monad) (~' in) + (.list (`' (.exec + (~+ import!) + (.:as (~ (..output_type :field:)) + (~ (<| (lux_optional :field:) + (for [@.js (` (<constant> (~ (code.text (%.format (..host_path class_name) "." field))))) + @.ruby (` (<constant> (~ (code.text (%.format (..host_path class_name) "::" field)))))] + (` (<get> (~ (code.text field)) + (~ (..imported class_name)))))))))))))))) + + (def: (virtual_field_definition [class_name class_parameters] alias namespace it) + (-> Declaration Alias Namespace (Named Output) Code) + (let [name (value@ #name it) + g!it (|> (value@ #alias it) + (maybe.else name) + (..namespaced namespace class_name alias) + code.local_symbol) + path (%.format (..host_path class_name) "." name) + :field: (value@ #anonymous it) + g!variables (list#each code.local_symbol class_parameters) + g!class (` ((~ (code.local_symbol (maybe.else class_name alias))) (~+ g!variables)))] + (` (.def: ((~ g!it) (~ g!it)) + (.All ((~ g!it) (~+ g!variables)) + (.-> (~ g!class) + (~ (..output_type :field:)))) + (.:expected + (~ (<| (lux_optional :field:) + (` (<get> (~ (code.text name)) (~ g!it)))))))))) + + (def: (field_definition import! class alias namespace it) + (-> (List Code) Declaration Alias Namespace Field Code) + (if (value@ #static? it) + (..static_field_definition import! class alias namespace (value@ #member it)) + (..virtual_field_definition class alias namespace (value@ #member it)))) + + (def: (static_method_definition import! [class_name class_parameters] alias namespace it) + (-> (List Code) Declaration Alias Namespace (Named Procedure) Code) + (let [method (value@ #name it) + name (|> (value@ #alias it) + (maybe.else (value@ #name it)) + (..namespaced namespace class_name alias))] + (|> it + (with@ #alias {.#Some name}) + (..procedure_definition import! + (for [@.js (` (<constant> (~ (code.text (%.format (..host_path class_name) "." method))))) + @.ruby (` (<constant> (~ (code.text (%.format (..host_path class_name) "::" method)))))] + (` (<get> (~ (code.text method)) + (.:as (..Object .Any) + (~ (..imported class_name)))))))))) + + (def: (virtual_method_definition [class_name class_parameters] alias namespace it) + (-> Declaration Alias Namespace (Named Procedure) Code) + (let [method (value@ #name it) + g!it (|> (value@ #alias it) + (maybe.else method) + (..namespaced namespace class_name alias) + code.local_symbol) + procedure (value@ #anonymous it) + input (value@ #input procedure) + g!input_variables (list#each code.local_symbol (value@ #variables input)) + :parameters: (value@ #parameters input) + g!parameters (..parameters :parameters:) + g!class_variables (list#each code.local_symbol class_parameters) + g!class (` ((~ (code.local_symbol (maybe.else class_name alias))) (~+ g!class_variables))) + :output: (value@ #output procedure)] + (` (.def: ((~ g!it) (~+ (list#each (value@ #mandatory) g!parameters)) (~ g!it)) + (.All ((~ g!it) (~+ g!class_variables) (~+ g!input_variables)) + (.-> (~+ (list#each ..output_type :parameters:)) + (~ g!class) + (~ (|> :output: + ..output_type + (..input_type input))))) + (.:expected + (~ (<| (..input_term input) + (..lux_optional :output:) + (` (<do> (~ (code.text method)) + (~ g!it) + [(~+ (list#each ..host_optional g!parameters))]))))))))) + + (def: (method_definition import! class alias namespace it) + (-> (List Code) Declaration Alias Namespace Method Code) + (if (value@ #static? it) + (static_method_definition import! class alias namespace (value@ #member it)) + (virtual_method_definition class alias namespace (value@ #member it)))) + + (syntax: .public (import: [host_module (<>.maybe <code>.text) + it ..import]) + (let [host_module_import! (: (List Code) + (case host_module + {.#Some host_module} + (list (` (<import> (~ (code.text host_module))))) + + {.#None} + (list)))] + (case it + {#Global it} + (in (list (..global_definition host_module_import! it))) + + {#Procedure it} + (in (list (..procedure_definition host_module_import! + (` (<constant> (~ (code.text (..host_path (value@ #name it)))))) + it))) + + {#Class it} + (let [class (value@ #declaration it) + alias (value@ #class_alias it) + [class_name class_parameters] class + namespace (value@ #namespace it) + g!class_variables (list#each code.local_symbol class_parameters) + declaration (` ((~ (code.local_symbol (maybe.else class_name alias))) + (~+ g!class_variables)))] + (in (list& (` (.type: (~ declaration) + (..Object (.Primitive (~ (code.text (..host_path class_name))) + [(~+ g!class_variables)])))) + (list#each (.function (_ member) + (`` (`` (case member + (~~ (for [@.lua (~~ (as_is)) + @.ruby (~~ (as_is))] + (~~ (as_is {#Constructor it} + (..constructor_definition class alias namespace it))))) + + {#Field it} + (..field_definition host_module_import! class alias namespace it) + + {#Method it} + (..method_definition host_module_import! class alias namespace it))))) + (value@ #members it))))) + ))) + + (for [@.ruby (as_is)] + (template: .public (function <inputs> <output>) + [(.:as ..Function + (`` (<function> (~~ (template.amount <inputs>)) + (.function (_ [<inputs>]) + <output>))))])) + + (for [@.js (as_is (template: .public (type_of object) + [("js type-of" object)]) + + (syntax: .public (global [type <code>.any + [head tail] (<code>.tuple (<>.and <code>.local_symbol (<>.some <code>.local_symbol)))]) + (with_symbols [g!_] + (let [global (` ("js constant" (~ (code.text head))))] + (case tail + {.#End} + (in (list (` (: (.Maybe (~ type)) + (case (..type_of (~ global)) + "undefined" + {.#None} + + (~ g!_) + {.#Some (:as (~ type) (~ global))}))))) + + {.#Item [next tail]} + (let [separator "."] + (in (list (` (: (.Maybe (~ type)) + (case (..type_of (~ global)) + "undefined" + {.#None} + + (~ g!_) + (..global (~ type) [(~ (code.local_symbol (%.format head "." next))) + (~+ (list#each code.local_symbol tail))]))))))))))) + + (template: (!defined? <global>) + [(.case (..global Any <global>) + {.#None} + .false + + {.#Some _} + .true)]) + + (template [<name> <global>] + [(def: .public <name> + Bit + (!defined? <global>))] + + [on_browser? [window]] + [on_nashorn? [java lang Object]] + ) + + (def: .public on_node_js? + Bit + (|> (..global (Object Any) [process]) + (maybe#each (|>> [] + ("js apply" ("js constant" "Object.prototype.toString.call")) + (:as Text) + (text#= "[object process]"))) + (maybe.else false))) + )] + (as_is)) + ) diff --git a/stdlib/source/library/lux/ffi.py.lux b/stdlib/source/library/lux/ffi.py.lux deleted file mode 100644 index 440f8f68b..000000000 --- a/stdlib/source/library/lux/ffi.py.lux +++ /dev/null @@ -1,350 +0,0 @@ -(.using - [library - [lux {"-" Alias} - ["@" target] - ["[0]" meta] - [abstract - [monad {"+" do}]] - [control - ["[0]" io] - ["[0]" maybe] - ["<>" parser - ["<[0]>" code {"+" Parser}]]] - [data - ["[0]" product] - ["[0]" text - ["%" format]] - [collection - ["[0]" list ("[1]#[0]" monad mix)]]] - [macro {"+" with_symbols} - [syntax {"+" syntax:}] - ["[0]" code] - ["[0]" template]] - [type - abstract]]]) - -(abstract: .public (Object brand) Any) - -(template [<name>] - [(with_expansions [<brand> (template.symbol [<name> "'"])] - (abstract: <brand> Any) - (type: .public <name> - (..Object <brand>)))] - - [None] - [Dict] - [Function] - ) - -(template [<name> <type>] - [(type: .public <name> - <type>)] - - [Boolean Bit] - [Integer Int] - [Float Frac] - [String Text] - ) - -(type: Noneable - [Bit Code]) - -(def: noneable - (Parser Noneable) - (let [token (' "?")] - (<| (<>.and (<>.parses? (<code>.this! token))) - (<>.after (<>.not (<code>.this! token))) - <code>.any))) - -(type: Constructor - (List Noneable)) - -(def: constructor - (Parser Constructor) - (<code>.form (<>.after (<code>.this! (' new)) - (<code>.tuple (<>.some ..noneable))))) - -(type: Field - [Bit Text Noneable]) - -(def: static! - (Parser Any) - (<code>.this! (' "static"))) - -(def: field - (Parser Field) - (<code>.form ($_ <>.and - (<>.parses? ..static!) - <code>.local_symbol - ..noneable))) - -(type: Alias - (Maybe Text)) - -(def: alias - (Parser Alias) - (<>.maybe (<>.after (<code>.this! (' "as")) <code>.local_symbol))) - -(type: Constant - [Text - Alias - Noneable]) - -(def: constant - (Parser Constant) - (<code>.form - ($_ <>.and - <code>.local_symbol - ..alias - ..noneable - ))) - -(type: Common_Method - (Record - [#name Text - #alias Alias - #inputs (List Noneable) - #io? Bit - #try? Bit - #output Noneable])) - -(type: Static_Method Common_Method) -(type: Virtual_Method Common_Method) - -(type: Method - (Variant - {#Static Static_Method} - {#Virtual Virtual_Method})) - -(def: common_method - (Parser Common_Method) - ($_ <>.and - <code>.local_symbol - ..alias - (<code>.tuple (<>.some ..noneable)) - (<>.parses? (<code>.this! (' "io"))) - (<>.parses? (<code>.this! (' "try"))) - ..noneable)) - -(def: static_method - (<>.after ..static! ..common_method)) - -(def: method - (Parser Method) - (<code>.form (<>.or ..static_method - ..common_method))) - -(type: Member - (Variant - {#Constructor Constructor} - {#Field Field} - {#Method Method})) - -(def: member - (Parser Member) - ($_ <>.or - ..constructor - ..field - ..method - )) - -(def: input_variables - (-> (List Noneable) (List [Bit Code])) - (|>> list.enumeration - (list#each (function (_ [idx [noneable? type]]) - [noneable? (|> idx %.nat code.local_symbol)])))) - -(def: (noneable_type [noneable? type]) - (-> Noneable Code) - (if noneable? - (` (.Maybe (~ type))) - type)) - -(def: (with_none g!temp [noneable? input]) - (-> Code [Bit Code] Code) - (if noneable? - (` (case (~ input) - {.#Some (~ g!temp)} - (~ g!temp) - - {.#None} - ("python object none"))) - input)) - -(def: (without_none g!temp [noneable? outputT] output) - (-> Code Noneable Code Code) - (if noneable? - (` (let [(~ g!temp) (~ output)] - (if ("python object none?" (~ g!temp)) - {.#None} - {.#Some (~ g!temp)}))) - (` (.let [(~ g!temp) (~ output)] - (.if (.not ("python object none?" (~ g!temp))) - (~ g!temp) - (.panic! "None is an invalid value!")))))) - -(type: Import - (Variant - {#Class [Text Text (List Member)]} - {#Function Static_Method} - {#Constant Constant})) - -(def: import - (Parser Import) - ($_ <>.or - (<>.and <code>.local_symbol - (<>.else ["" (list)] - (<code>.tuple (<>.and <code>.text - (<>.some member))))) - (<code>.form ..common_method) - ..constant)) - -(def: (with_io with? without) - (-> Bit Code Code) - (if with? - (` ((~! io.io) (~ without))) - without)) - -(def: (io_type io? rawT) - (-> Bit Code Code) - (if io? - (` ((~! io.IO) (~ rawT))) - rawT)) - -(def: (with_try with? without_try) - (-> Bit Code Code) - (if with? - (` (.try (~ without_try))) - without_try)) - -(def: (try_type try? rawT) - (-> Bit Code Code) - (if try? - (` (.Either .Text (~ rawT))) - rawT)) - -(def: (make_function g!method g!temp source inputsT io? try? outputT) - (-> Code Code Code (List Noneable) Bit Bit Noneable Code) - (let [g!inputs (input_variables inputsT)] - (` (.def: ((~ g!method) - [(~+ (list#each product.right g!inputs))]) - (-> [(~+ (list#each noneable_type inputsT))] - (~ (|> (noneable_type outputT) - (try_type try?) - (io_type io?)))) - (.:expected - (~ (<| (with_io io?) - (with_try try?) - (without_none g!temp outputT) - (` ("python apply" - (:as ..Function (~ source)) - (~+ (list#each (with_none g!temp) g!inputs))))))))))) - -(syntax: .public (import: [import ..import]) - (with_symbols [g!temp] - (case import - {#Class [class format members]} - (with_symbols [g!object] - (let [qualify (: (-> Text Code) - (function (_ member_name) - (|> format - (text.replaced "[1]" class) - (text.replaced "[0]" member_name) - code.local_symbol))) - g!type (code.local_symbol class) - real_class (text.replaced "/" "." class) - imported (case (text.all_split_by "/" class) - {.#Item head tail} - (list#mix (function (_ sub super) - (` ("python object get" (~ (code.text sub)) - (.:as (..Object .Any) (~ super))))) - (` ("python import" (~ (code.text head)))) - tail) - - {.#End} - (` ("python import" (~ (code.text class)))))] - (in (list& (` (.type: (~ g!type) - (..Object (.Primitive (~ (code.text real_class)))))) - (list#each (function (_ member) - (case member - {#Constructor inputsT} - (let [g!inputs (input_variables inputsT)] - (` (.def: ((~ (qualify "new")) - [(~+ (list#each product.right g!inputs))]) - (.-> [(~+ (list#each noneable_type inputsT))] - (~ g!type)) - (.:expected - ("python apply" - (.:as ..Function (~ imported)) - (~+ (list#each (with_none g!temp) g!inputs))))))) - - {#Field [static? field fieldT]} - (if static? - (` ((~! syntax:) ((~ (qualify field)) []) - (# (~! meta.monad) (~' in) - (list (` (.:as (~ (noneable_type fieldT)) - ("python object get" (~ (code.text field)) - (:as (..Object .Any) (~ imported))))))))) - (` (.def: ((~ (qualify field)) - (~ g!object)) - (.-> (~ g!type) - (~ (noneable_type fieldT))) - (.:expected - (~ (without_none g!temp fieldT (` ("python object get" (~ (code.text field)) - (.:as (..Object .Any) (~ g!object)))))))))) - - {#Method method} - (case method - {#Static [method alias inputsT io? try? outputT]} - (..make_function (qualify (maybe.else method alias)) - g!temp - (` ("python object get" (~ (code.text method)) - (.:as (..Object .Any) (~ imported)))) - inputsT - io? - try? - outputT) - - {#Virtual [method alias inputsT io? try? outputT]} - (let [g!inputs (input_variables inputsT)] - (` (.def: ((~ (qualify (maybe.else method alias))) - [(~+ (list#each product.right g!inputs))] - (~ g!object)) - (.-> [(~+ (list#each noneable_type inputsT))] - (~ g!type) - (~ (|> (noneable_type outputT) - (try_type try?) - (io_type io?)))) - (.:expected - (~ (<| (with_io io?) - (with_try try?) - (without_none g!temp outputT) - (` ("python object do" - (~ (code.text method)) - (~ g!object) - (~+ (list#each (with_none g!temp) g!inputs))))))))))))) - members))))) - - {#Function [name alias inputsT io? try? outputT]} - (in (list (..make_function (code.local_symbol (maybe.else name alias)) - g!temp - (` ("python constant" (~ (code.text name)))) - inputsT - io? - try? - outputT))) - - {#Constant [name alias :constant:]} - (in (list (` (.def: (~ (code.local_symbol (maybe.else name alias))) - (~ (noneable_type :constant:)) - (.:expected - (~ (without_none g!temp :constant: - (` ("python constant" (~ (code.text name))))))))))) - ))) - -(template: .public (lambda <inputs> <output>) - [(.:as ..Function - (`` ("python function" - (~~ (template.amount <inputs>)) - (.function (_ [<inputs>]) - <output>))))]) diff --git a/stdlib/source/library/lux/ffi.rb.lux b/stdlib/source/library/lux/ffi.rb.lux deleted file mode 100644 index 21dae9b6f..000000000 --- a/stdlib/source/library/lux/ffi.rb.lux +++ /dev/null @@ -1,336 +0,0 @@ -(.using - [library - [lux {"-" Alias} - ["@" target] - ["[0]" meta] - [abstract - [monad {"+" do}]] - [control - ["[0]" io] - ["[0]" maybe] - ["<>" parser ("[1]#[0]" monad) - ["<[0]>" code {"+" Parser}]]] - [data - ["[0]" product] - ["[0]" text - ["%" format]] - [collection - ["[0]" list ("[1]#[0]" functor)]]] - [type - abstract] - [macro {"+" with_symbols} - [syntax {"+" syntax:}] - ["[0]" code] - ["[0]" template]]]]) - -(abstract: .public (Object brand) Any) - -(template [<name>] - [(with_expansions [<brand> (template.symbol [<name> "'"])] - (abstract: <brand> Any) - (type: .public <name> - (..Object <brand>)))] - - [Nil] - [Function] - ) - -(template [<name> <type>] - [(type: .public <name> - <type>)] - - [Boolean Bit] - [Integer Int] - [Float Frac] - [String Text] - ) - -(type: Nilable - [Bit Code]) - -(def: nilable - (Parser Nilable) - (let [token (' "?")] - (<| (<>.and (<>.parses? (<code>.this! token))) - (<>.after (<>.not (<code>.this! token))) - <code>.any))) - -(type: Alias - Text) - -(def: alias - (Parser Alias) - (<>.after (<code>.this! (' "as")) <code>.local_symbol)) - -(type: Field - [Bit Text (Maybe Alias) Nilable]) - -(def: static! - (Parser Any) - (<code>.this! (' "static"))) - -(def: field - (Parser Field) - (<code>.form ($_ <>.and - (<>.parses? ..static!) - <code>.local_symbol - (<>.maybe ..alias) - ..nilable))) - -(def: constant - (Parser Field) - (<code>.form ($_ <>.and - (<>#in true) - <code>.local_symbol - (<>.maybe ..alias) - ..nilable))) - -(type: Common_Method - (Record - [#name Text - #alias (Maybe Alias) - #inputs (List Nilable) - #io? Bit - #try? Bit - #output Nilable])) - -(type: Static_Method Common_Method) -(type: Virtual_Method Common_Method) - -(type: Method - (Variant - {#Static Static_Method} - {#Virtual Virtual_Method})) - -(def: common_method - (Parser Common_Method) - ($_ <>.and - <code>.local_symbol - (<>.maybe ..alias) - (<code>.tuple (<>.some ..nilable)) - (<>.parses? (<code>.this! (' "io"))) - (<>.parses? (<code>.this! (' "try"))) - ..nilable)) - -(def: static_method - (<>.after ..static! ..common_method)) - -(def: method - (Parser Method) - (<code>.form (<>.or ..static_method - ..common_method))) - -(type: Member - (Variant - {#Field Field} - {#Method Method})) - -(def: member - (Parser Member) - ($_ <>.or - ..field - ..method - )) - -(def: input_variables - (-> (List Nilable) (List [Bit Code])) - (|>> list.enumeration - (list#each (function (_ [idx [nilable? type]]) - [nilable? (|> idx %.nat code.local_symbol)])))) - -(def: (nilable_type [nilable? type]) - (-> Nilable Code) - (if nilable? - (` (.Maybe (~ type))) - type)) - -(def: (with_nil g!temp [nilable? input]) - (-> Code [Bit Code] Code) - (if nilable? - (` (case (~ input) - {.#Some (~ g!temp)} - (~ g!temp) - - {.#None} - ("ruby object nil"))) - input)) - -(def: (without_nil g!temp [nilable? outputT] output) - (-> Code Nilable Code Code) - (if nilable? - (` (let [(~ g!temp) (~ output)] - (if ("ruby object nil?" (~ g!temp)) - {.#None} - {.#Some (~ g!temp)}))) - (` (let [(~ g!temp) (~ output)] - (if (not ("ruby object nil?" (~ g!temp))) - (~ g!temp) - (.panic! "Nil is an invalid value!")))))) - -(type: Import - (Variant - {#Class Text (Maybe Alias) Text (List Member)} - {#Function Static_Method} - {#Constant Field})) - -(def: import - (Parser [(Maybe Text) Import]) - ($_ <>.and - (<>.maybe <code>.text) - ($_ <>.or - ($_ <>.and - <code>.local_symbol - (<>.maybe ..alias) - (<>.else ["" (list)] - (<code>.tuple (<>.and <code>.text - (<>.some member))))) - (<code>.form ..common_method) - ..constant - ))) - -(def: (with_io with? without) - (-> Bit Code Code) - (if with? - (` ((~! io.io) (~ without))) - without)) - -(def: (io_type io? rawT) - (-> Bit Code Code) - (if io? - (` ((~! io.IO) (~ rawT))) - rawT)) - -(def: (with_try with? without_try) - (-> Bit Code Code) - (if with? - (` (.try (~ without_try))) - without_try)) - -(def: (try_type try? rawT) - (-> Bit Code Code) - (if try? - (` (.Either .Text (~ rawT))) - rawT)) - -(def: (make_function g!method g!temp source inputsT io? try? outputT) - (-> Code Code Code (List Nilable) Bit Bit Nilable Code) - (let [g!inputs (input_variables inputsT)] - (` (def: ((~ g!method) - [(~+ (list#each product.right g!inputs))]) - (-> [(~+ (list#each nilable_type inputsT))] - (~ (|> (nilable_type outputT) - (try_type try?) - (io_type io?)))) - (:expected - (~ (<| (with_io io?) - (with_try try?) - (without_nil g!temp outputT) - (` ("ruby apply" - (:as ..Function (~ source)) - (~+ (list#each (with_nil g!temp) g!inputs))))))))))) - -(syntax: .public (import: [[?module import] ..import]) - (with_symbols [g!temp] - (case import - {#Class [class alias format members]} - (with_symbols [g!object] - (let [qualify (: (-> Text Code) - (function (_ member_name) - (|> format - (text.replaced "[1]" (maybe.else class alias)) - (text.replaced "[0]" member_name) - code.local_symbol))) - g!type (code.local_symbol (maybe.else class alias)) - module_import (: (List Code) - (case ?module - {.#Some module} - (list (` ("ruby import" (~ (code.text module))))) - - {.#None} - (list))) - class_import (` ("ruby constant" (~ (code.text class))))] - (in (list& (` (type: (~ g!type) - (..Object (Primitive (~ (code.text class)))))) - (list#each (function (_ member) - (case member - {#Field [static? field alias fieldT]} - (if static? - (` ((~! syntax:) ((~ (qualify (maybe.else field alias))) []) - (# (~! meta.monad) (~' in) - (list (` (.:as (~ (nilable_type fieldT)) - (.exec - (~+ module_import) - ("ruby constant" (~ (code.text (%.format class "::" field))))))))))) - (` (def: ((~ (qualify field)) - (~ g!object)) - (-> (~ g!type) - (~ (nilable_type fieldT))) - (:expected - (~ (without_nil g!temp fieldT (` ("ruby object get" (~ (code.text field)) - (:as (..Object .Any) (~ g!object)))))))))) - - {#Method method} - (case method - {#Static [method alias inputsT io? try? outputT]} - (..make_function (qualify (maybe.else method alias)) - g!temp - (` ("ruby object get" (~ (code.text method)) - (:as (..Object .Any) - (.exec - (~+ module_import) - ("ruby constant" (~ (code.text (%.format class "::" method)))))))) - inputsT - io? - try? - outputT) - - {#Virtual [method alias inputsT io? try? outputT]} - (let [g!inputs (input_variables inputsT)] - (` (def: ((~ (qualify (maybe.else method alias))) - [(~+ (list#each product.right g!inputs))] - (~ g!object)) - (-> [(~+ (list#each nilable_type inputsT))] - (~ g!type) - (~ (|> (nilable_type outputT) - (try_type try?) - (io_type io?)))) - (:expected - (~ (<| (with_io io?) - (with_try try?) - (without_nil g!temp outputT) - (` ("ruby object do" - (~ (code.text method)) - (~ g!object) - (~+ (list#each (with_nil g!temp) g!inputs))))))))))))) - members))))) - - {#Function [name alias inputsT io? try? outputT]} - (let [imported (` (.exec - (~+ (case ?module - {.#Some module} - (list (` ("ruby import" (~ (code.text module))))) - - {.#None} - (list))) - ("ruby constant" (~ (code.text name)))))] - (in (list (..make_function (code.local_symbol (maybe.else name alias)) - g!temp - imported - inputsT - io? - try? - outputT)))) - - {#Constant [_ name alias fieldT]} - (let [imported (` (.exec - (~+ (case ?module - {.#Some module} - (list (` ("ruby import" (~ (code.text module))))) - - {.#None} - (list))) - ("ruby constant" (~ (code.text name)))))] - (in (list (` ((~! syntax:) ((~ (code.local_symbol (maybe.else name alias))) []) - (# (~! meta.monad) (~' in) - (list (` (.:as (~ (nilable_type fieldT)) (~ imported)))))))))) - ))) diff --git a/stdlib/source/library/lux/ffi/node_js.js.lux b/stdlib/source/library/lux/ffi/node_js.js.lux index 2828c1fea..08e649fa9 100644 --- a/stdlib/source/library/lux/ffi/node_js.js.lux +++ b/stdlib/source/library/lux/ffi/node_js.js.lux @@ -9,7 +9,7 @@ (template [<name> <path>] [(def: <name> (Maybe (-> Text Any)) - (ffi.constant (-> Text Any) <path>))] + (ffi.global (-> Text Any) <path>))] [normal_require [require]] [global_require [global require]] diff --git a/stdlib/source/library/lux/math.lux b/stdlib/source/library/lux/math.lux index a96ab07c4..ec1e0c5d9 100644 --- a/stdlib/source/library/lux/math.lux +++ b/stdlib/source/library/lux/math.lux @@ -1,11 +1,11 @@ (.using - [library - [lux "*" - ["@" target] - [math - [number - ["n" nat] - ["i" int]]]]]) + [library + [lux "*" + ["@" target] + [math + [number + ["n" nat] + ["i" int]]]]]) (template [<name> <value>] [(def: .public <name> @@ -93,7 +93,8 @@ (as_is (template [<name> <method>] [(def: .public <name> (-> Frac Frac) - (|>> ("js apply" ("js constant" <method>)) + (|>> [] + ("js apply" ("js constant" <method>)) (:as Frac)))] [cos "Math.cos"] @@ -116,13 +117,14 @@ (def: .public (pow param subject) (-> Frac Frac Frac) - (:as Frac ("js apply" ("js constant" "Math.pow") subject param)))) + (:as Frac ("js apply" ("js constant" "Math.pow") [subject param])))) @.python (as_is (template [<name> <method>] [(def: .public <name> (-> Frac Frac) - (|>> ("python object do" <method> ("python import" "math")) + (|>> [] + ("python object do" <method> ("python import" "math")) (:as Frac)))] [cos "cos"] @@ -144,7 +146,7 @@ (def: .public (pow param subject) (-> Frac Frac Frac) - (:as Frac ("python object do" "pow" ("python import" "math") subject param))) + (:as Frac ("python object do" "pow" ("python import" "math") [subject param]))) (def: .public (root/3 it) (-> Frac Frac) @@ -160,7 +162,8 @@ (as_is (template [<name> <method>] [(def: .public <name> (-> Frac Frac) - (|>> ("lua apply" ("lua constant" <method>)) + (|>> [] + ("lua apply" ("lua constant" <method>)) (:as Frac)))] [cos "math.cos"] @@ -198,7 +201,8 @@ (as_is (template [<name> <method>] [(def: .public <name> (-> Frac Frac) - (|>> ("ruby apply" ("ruby constant" <method>)) + (|>> [] + ("ruby apply" ("ruby constant" <method>)) (:as Frac)))] [cos "Math.cos"] @@ -217,11 +221,11 @@ ) (template [<name> <method>] - [(def: .public <name> + [(def: .public (<name> it) (-> Frac Frac) - (|>> ("ruby object do" <method>) - (:as Int) - ("lux i64 f64")))] + (|> ("ruby object do" <method> it []) + (:as Int) + ("lux i64 f64")))] [ceil "ceil"] [floor "floor"] @@ -229,7 +233,7 @@ (def: .public (pow param subject) (-> Frac Frac Frac) - (:as Frac ("ruby object do" "**" subject param)))) + (:as Frac ("ruby object do" "**" subject [param])))) @.php (as_is (template [<name> <method>] diff --git a/stdlib/source/library/lux/time/instant.lux b/stdlib/source/library/lux/time/instant.lux index 7dfbf3577..d435afeb3 100644 --- a/stdlib/source/library/lux/time/instant.lux +++ b/stdlib/source/library/lux/time/instant.lux @@ -1,34 +1,34 @@ (.using - [library - [lux "*" - ["@" target] - [abstract - [equivalence {"+" Equivalence}] - [order {"+" Order}] - [enum {"+" Enum}] - [codec {"+" Codec}] - [monad {"+" Monad do}]] - [control - [io {"+" IO io}] - ["[0]" maybe] - ["[0]" try] - ["[0]" exception {"+" exception:}] - ["<>" parser - ["<[0]>" text {"+" Parser}]]] - [data - ["[0]" text ("[1]#[0]" monoid)]] - [math - [number - ["i" int] - ["f" frac]]] - [type - abstract]]] - ["[0]" // {"+" Time} - ["[0]" duration {"+" Duration}] - ["[0]" year {"+" Year}] - ["[0]" month {"+" Month}] - ["[0]" day {"+" Day}] - ["[0]" date {"+" Date}]]) + [library + [lux "*" + ["@" target] + [abstract + [equivalence {"+" Equivalence}] + [order {"+" Order}] + [enum {"+" Enum}] + [codec {"+" Codec}] + [monad {"+" Monad do}]] + [control + [io {"+" IO io}] + ["[0]" maybe] + ["[0]" try] + ["[0]" exception {"+" exception:}] + ["<>" parser + ["<[0]>" text {"+" Parser}]]] + [data + ["[0]" text ("[1]#[0]" monoid)]] + [math + [number + ["i" int] + ["f" frac]]] + [type + abstract]]] + ["[0]" // {"+" Time} + ["[0]" duration {"+" Duration}] + ["[0]" year {"+" Year}] + ["[0]" month {"+" Month}] + ["[0]" day {"+" Day}] + ["[0]" date {"+" Date}]]) (abstract: .public Instant Int @@ -160,17 +160,16 @@ (:as Frac) "lux f64 i64")) @.python (let [time ("python import" "time")] - (|> ("python object do" "time" time) + (|> ("python object do" "time" time []) (:as Frac) (f.* +1,000.0) "lux f64 i64")) - @.lua (|> ("lua constant" "os.time") - "lua apply" + @.lua (|> ("lua apply" ("lua constant" "os.time") []) (:as Int) (i.* +1,000)) @.ruby (let [% ("ruby constant" "Time") - % ("ruby object do" "now" %)] - (|> ("ruby object do" "to_f" %) + % ("ruby object do" "now" % [])] + (|> ("ruby object do" "to_f" % []) (:as Frac) (f.* +1,000.0) "lux f64 i64")) diff --git a/stdlib/source/library/lux/tool/compiler/language/lux/phase/extension/analysis/js.lux b/stdlib/source/library/lux/tool/compiler/language/lux/phase/extension/analysis/js.lux index 78bf307b0..9cb9fcf96 100644 --- a/stdlib/source/library/lux/tool/compiler/language/lux/phase/extension/analysis/js.lux +++ b/stdlib/source/library/lux/tool/compiler/language/lux/phase/extension/analysis/js.lux @@ -173,7 +173,7 @@ (def: js::apply Handler (custom - [($_ <>.and <code>.any (<>.some <code>.any)) + [($_ <>.and <code>.any (<code>.tuple (<>.some <code>.any))) (function (_ extension phase archive [abstractionC inputsC]) (do [! phase.monad] [abstractionA (analysis/type.expecting Any diff --git a/stdlib/source/library/lux/tool/compiler/language/lux/phase/extension/analysis/lua.lux b/stdlib/source/library/lux/tool/compiler/language/lux/phase/extension/analysis/lua.lux index f6e024d3b..e65c2db5e 100644 --- a/stdlib/source/library/lux/tool/compiler/language/lux/phase/extension/analysis/lua.lux +++ b/stdlib/source/library/lux/tool/compiler/language/lux/phase/extension/analysis/lua.lux @@ -137,7 +137,7 @@ (def: object::do Handler (custom - [($_ <>.and <code>.text <code>.any (<>.some <code>.any)) + [($_ <>.and <code>.text <code>.any (<code>.tuple (<>.some <code>.any))) (function (_ extension phase archive [methodC objectC inputsC]) (do [! phase.monad] [objectA (analysis/type.expecting ..Object @@ -194,7 +194,7 @@ (def: lua::apply Handler (custom - [($_ <>.and <code>.any (<>.some <code>.any)) + [($_ <>.and <code>.any (<code>.tuple (<>.some <code>.any))) (function (_ extension phase archive [abstractionC inputsC]) (do [! phase.monad] [abstractionA (analysis/type.expecting ..Function diff --git a/stdlib/source/library/lux/tool/compiler/language/lux/phase/extension/analysis/python.lux b/stdlib/source/library/lux/tool/compiler/language/lux/phase/extension/analysis/python.lux index b1e865767..86affb036 100644 --- a/stdlib/source/library/lux/tool/compiler/language/lux/phase/extension/analysis/python.lux +++ b/stdlib/source/library/lux/tool/compiler/language/lux/phase/extension/analysis/python.lux @@ -145,7 +145,7 @@ (def: object::do Handler (custom - [($_ <>.and <code>.text <code>.any (<>.some <code>.any)) + [($_ <>.and <code>.text <code>.any (<code>.tuple (<>.some <code>.any))) (function (_ extension phase archive [methodC objectC inputsC]) (do [! phase.monad] [objectA (analysis/type.expecting ..Object @@ -187,7 +187,7 @@ (def: python::apply Handler (custom - [($_ <>.and <code>.any (<>.some <code>.any)) + [($_ <>.and <code>.any (<code>.tuple (<>.some <code>.any))) (function (_ extension phase archive [abstractionC inputsC]) (do [! phase.monad] [abstractionA (analysis/type.expecting ..Function diff --git a/stdlib/source/library/lux/tool/compiler/language/lux/phase/extension/analysis/ruby.lux b/stdlib/source/library/lux/tool/compiler/language/lux/phase/extension/analysis/ruby.lux index eae384992..91259acc3 100644 --- a/stdlib/source/library/lux/tool/compiler/language/lux/phase/extension/analysis/ruby.lux +++ b/stdlib/source/library/lux/tool/compiler/language/lux/phase/extension/analysis/ruby.lux @@ -6,7 +6,7 @@ ["[0]" monad {"+" do}]] [control ["<>" parser - ["<c>" code {"+" Parser}]]] + ["<[0]>" code {"+" Parser}]]] [data [collection ["[0]" array {"+" Array}] @@ -29,7 +29,7 @@ (def: array::new Handler (custom - [<c>.any + [<code>.any (function (_ extension phase archive lengthC) (<| analysis/type.with_var (function (_ [@var :var:])) @@ -42,7 +42,7 @@ (def: array::length Handler (custom - [<c>.any + [<code>.any (function (_ extension phase archive arrayC) (<| analysis/type.with_var (function (_ [@var :var:])) @@ -55,7 +55,7 @@ (def: array::read Handler (custom - [(<>.and <c>.any <c>.any) + [(<>.and <code>.any <code>.any) (function (_ extension phase archive [indexC arrayC]) (<| analysis/type.with_var (function (_ [@var :var:])) @@ -70,7 +70,7 @@ (def: array::write Handler (custom - [($_ <>.and <c>.any <c>.any <c>.any) + [($_ <>.and <code>.any <code>.any <code>.any) (function (_ extension phase archive [indexC valueC arrayC]) (<| analysis/type.with_var (function (_ [@var :var:])) @@ -87,7 +87,7 @@ (def: array::delete Handler (custom - [($_ <>.and <c>.any <c>.any) + [($_ <>.and <code>.any <code>.any) (function (_ extension phase archive [indexC arrayC]) (<| analysis/type.with_var (function (_ [@var :var:])) @@ -125,7 +125,7 @@ (def: object::get Handler (custom - [($_ <>.and <c>.text <c>.any) + [($_ <>.and <code>.text <code>.any) (function (_ extension phase archive [fieldC objectC]) (do phase.monad [objectA (<| (analysis/type.expecting ..Object) @@ -137,7 +137,7 @@ (def: object::do Handler (custom - [($_ <>.and <c>.text <c>.any (<>.some <c>.any)) + [($_ <>.and <code>.text <code>.any (<code>.tuple (<>.some <code>.any))) (function (_ extension phase archive [methodC objectC inputsC]) (do [! phase.monad] [objectA (<| (analysis/type.expecting ..Object) @@ -161,7 +161,7 @@ (def: ruby::constant Handler (custom - [<c>.text + [<code>.text (function (_ extension phase archive name) (do phase.monad [_ (analysis/type.inference Any)] @@ -170,7 +170,7 @@ (def: ruby::apply Handler (custom - [($_ <>.and <c>.any (<>.some <c>.any)) + [($_ <>.and <code>.any (<code>.tuple (<>.some <code>.any))) (function (_ extension phase archive [abstractionC inputsC]) (do [! phase.monad] [abstractionA (<| (analysis/type.expecting ..Function) @@ -182,7 +182,7 @@ (def: ruby::import Handler (custom - [<c>.text + [<code>.text (function (_ extension phase archive name) (do phase.monad [_ (analysis/type.inference Bit)] diff --git a/stdlib/source/library/lux/world/console.lux b/stdlib/source/library/lux/world/console.lux index cf75af0a5..8fc8dcf69 100644 --- a/stdlib/source/library/lux/world/console.lux +++ b/stdlib/source/library/lux/world/console.lux @@ -96,42 +96,42 @@ (for [@.old (as_is <jvm>) @.jvm (as_is <jvm>) @.js (as_is (ffi.import: Buffer - ["[1]::[0]" - (toString [] ffi.String)]) + "[1]::[0]" + (toString [] ffi.String)) (ffi.import: Readable_Stream - ["[1]::[0]" - (read [] "?" Buffer) - (unshift "as" unshift|String [ffi.String] ffi.Boolean) - (unshift "as" unshift|Buffer [Buffer] ffi.Boolean)]) + "[1]::[0]" + (read [] "?" Buffer) + (unshift "as" unshift|String [ffi.String] ffi.Boolean) + (unshift "as" unshift|Buffer [Buffer] ffi.Boolean)) (ffi.import: Writable_Stream - ["[1]::[0]" - (write [ffi.String ffi.Function] ffi.Boolean) - (once [ffi.String ffi.Function] Any)]) + "[1]::[0]" + (write [ffi.String ffi.Function] ffi.Boolean) + (once [ffi.String ffi.Function] Any)) (ffi.import: process - ["[1]::[0]" - ("static" stdout Writable_Stream) - ("static" stdin Readable_Stream)]) + "[1]::[0]" + ("static" stdout Writable_Stream) + ("static" stdin Readable_Stream)) (exception: .public cannot_read) (template: (!read <type> <query>) [(let [it (process::stdin)] - (case (Readable_Stream::read [] it) + (case (Readable_Stream::read it) {.#Some buffer} - (let [input (Buffer::toString [] buffer)] + (let [input (Buffer::toString buffer)] (case (: (Maybe [<type> Text]) <query>) {.#Some [head tail]} (exec - (Readable_Stream::unshift|String [tail] it) + (Readable_Stream::unshift|String tail it) (async#in {try.#Success head})) {.#None} (exec - (Readable_Stream::unshift|Buffer [buffer] it) + (Readable_Stream::unshift|Buffer buffer it) (async#in (exception.except ..cannot_read []))))) {.#None} @@ -154,7 +154,7 @@ (let [[read! write!] (: [(async.Async (Try [])) (async.Resolver (Try []))] (async.async []))] (exec - (Writable_Stream::write [it (ffi.closure [] (io.run! (write! {try.#Success []})))] + (Writable_Stream::write it (ffi.function [] (io.run! (write! {try.#Success []}))) (process::stdout)) read!))) diff --git a/stdlib/source/library/lux/world/file.lux b/stdlib/source/library/lux/world/file.lux index 606cadc3f..cf1a5fc83 100644 --- a/stdlib/source/library/lux/world/file.lux +++ b/stdlib/source/library/lux/world/file.lux @@ -303,29 +303,29 @@ @.js (as_is (ffi.import: Buffer - ["[1]::[0]" - ("static" from [Binary] ..Buffer)]) + "[1]::[0]" + ("static" from [Binary] ..Buffer)) (ffi.import: FileDescriptor - ["[1]::[0]"]) + "[1]::[0]") (ffi.import: Stats - ["[1]::[0]" - (size ffi.Number) - (mtimeMs ffi.Number) - (isFile [] ffi.Boolean) - (isDirectory [] ffi.Boolean)]) + "[1]::[0]" + (size ffi.Number) + (mtimeMs ffi.Number) + (isFile [] ffi.Boolean) + (isDirectory [] ffi.Boolean)) (ffi.import: FsConstants - ["[1]::[0]" - (F_OK ffi.Number) - (R_OK ffi.Number) - (W_OK ffi.Number) - (X_OK ffi.Number)]) + "[1]::[0]" + (F_OK ffi.Number) + (R_OK ffi.Number) + (W_OK ffi.Number) + (X_OK ffi.Number)) (ffi.import: Error - ["[1]::[0]" - (toString [] ffi.String)]) + "[1]::[0]" + (toString [] ffi.String)) (template: (with_async <write> <type> <body>) [(template.with_locals [<read>] @@ -336,41 +336,41 @@ <read>)))]) (ffi.import: Fs - ["[1]::[0]" - (constants FsConstants) - (readFile [ffi.String ffi.Function] Any) - (appendFile [ffi.String Buffer ffi.Function] Any) - (writeFile [ffi.String Buffer ffi.Function] Any) - (stat [ffi.String ffi.Function] Any) - (access [ffi.String ffi.Number ffi.Function] Any) - (rename [ffi.String ffi.String ffi.Function] Any) - (utimes [ffi.String ffi.Number ffi.Number ffi.Function] Any) - (readdir [ffi.String ffi.Function] Any) - (mkdir [ffi.String ffi.Function] Any) - (unlink [ffi.String ffi.Function] Any) - (rmdir [ffi.String ffi.Function] Any)]) + "[1]::[0]" + (constants FsConstants) + (readFile [ffi.String ffi.Function] Any) + (appendFile [ffi.String Buffer ffi.Function] Any) + (writeFile [ffi.String Buffer ffi.Function] Any) + (stat [ffi.String ffi.Function] Any) + (access [ffi.String ffi.Number ffi.Function] Any) + (rename [ffi.String ffi.String ffi.Function] Any) + (utimes [ffi.String ffi.Number ffi.Number ffi.Function] Any) + (readdir [ffi.String ffi.Function] Any) + (mkdir [ffi.String ffi.Function] Any) + (unlink [ffi.String ffi.Function] Any) + (rmdir [ffi.String ffi.Function] Any)) (def: (any_callback write!) (-> (async.Resolver (Try Any)) ffi.Function) - (<| (ffi.closure [error]) + (<| (ffi.function [error]) io.run! write! (if (ffi.null? error) {try.#Success []} - {try.#Failure (Error::toString [] (:as Error error))}))) + {try.#Failure (Error::toString (:as Error error))}))) (def: (value_callback write!) (All (_ a) (-> (async.Resolver (Try a)) ffi.Function)) - (<| (ffi.closure [error datum]) + (<| (ffi.function [error datum]) io.run! write! (if (ffi.null? error) {try.#Success (:expected datum)} - {try.#Failure (Error::toString [] (:as Error error))}))) + {try.#Failure (Error::toString (:as Error error))}))) (ffi.import: JsPath - ["[1]::[0]" - (sep ffi.String)]) + "[1]::[0]" + (sep ffi.String)) (def: .public default (Maybe (System Async)) @@ -390,11 +390,11 @@ [(def: (<name> path) (do async.monad [?stats (with_async write! (Try Stats) - (Fs::stat [path (..value_callback write!)] + (Fs::stat path (..value_callback write!) node_fs))] (in (case ?stats {try.#Success stats} - (<method> [] stats) + (<method> stats) {try.#Failure _} false))))] @@ -406,9 +406,9 @@ (def: (make_directory path) (do async.monad [outcome (with_async write! (Try Any) - (Fs::access [path - (|> node_fs Fs::constants FsConstants::F_OK) - (..any_callback write!)] + (Fs::access path + (|> node_fs Fs::constants FsConstants::F_OK) + (..any_callback write!) node_fs))] (case outcome {try.#Success _} @@ -416,20 +416,20 @@ {try.#Failure _} (with_async write! (Try Any) - (Fs::mkdir [path (..any_callback write!)] node_fs))))) + (Fs::mkdir path (..any_callback write!) node_fs))))) (~~ (template [<name> <method>] [(def: (<name> path) (do [! (try.with async.monad)] [subs (with_async write! (Try (Array ffi.String)) - (Fs::readdir [path (..value_callback write!)] node_fs))] + (Fs::readdir path (..value_callback write!) node_fs))] (|> subs (array.list {.#None}) (list#each (|>> (format path js_separator))) (monad.each ! (function (_ sub) - (# ! each (|>> (<method> []) [sub]) + (# ! each (|>> <method> [sub]) (with_async write! (Try Stats) - (Fs::stat [sub (..value_callback write!)] node_fs))))) + (Fs::stat sub (..value_callback write!) node_fs))))) (# ! each (|>> (list.only product.right) (list#each product.left))))))] @@ -440,7 +440,7 @@ (def: (file_size path) (do (try.with async.monad) [stats (with_async write! (Try Stats) - (Fs::stat [path (..value_callback write!)] + (Fs::stat path (..value_callback write!) node_fs))] (in (|> stats Stats::size @@ -449,7 +449,7 @@ (def: (last_modified path) (do (try.with async.monad) [stats (with_async write! (Try Stats) - (Fs::stat [path (..value_callback write!)] + (Fs::stat path (..value_callback write!) node_fs))] (in (|> stats Stats::mtimeMs @@ -466,35 +466,35 @@ false) {try.#Success}) (with_async write! (Try Any) - (Fs::access [path - (|> node_fs Fs::constants FsConstants::X_OK) - (..any_callback write!)] + (Fs::access path + (|> node_fs Fs::constants FsConstants::X_OK) + (..any_callback write!) node_fs)))) (def: (read path) (with_async write! (Try Binary) - (Fs::readFile [path (..value_callback write!)] + (Fs::readFile path (..value_callback write!) node_fs))) (def: (delete path) (do (try.with async.monad) [stats (with_async write! (Try Stats) - (Fs::stat [path (..value_callback write!)] node_fs))] + (Fs::stat path (..value_callback write!) node_fs))] (with_async write! (Try Any) - (if (Stats::isFile [] stats) - (Fs::unlink [path (..any_callback write!)] node_fs) - (Fs::rmdir [path (..any_callback write!)] node_fs))))) + (if (Stats::isFile stats) + (Fs::unlink path (..any_callback write!) node_fs) + (Fs::rmdir path (..any_callback write!) node_fs))))) (def: (modify time_stamp path) (with_async write! (Try Any) (let [when (|> time_stamp instant.relative duration.millis i.frac)] - (Fs::utimes [path when when (..any_callback write!)] + (Fs::utimes path when when (..any_callback write!) node_fs)))) (~~ (template [<name> <method>] [(def: (<name> data path) (with_async write! (Try Any) - (<method> [path (Buffer::from data) (..any_callback write!)] + (<method> path (Buffer::from data) (..any_callback write!) node_fs)))] [write Fs::writeFile] @@ -503,7 +503,7 @@ (def: (move destination origin) (with_async write! (Try Any) - (Fs::rename [origin destination (..any_callback write!)] + (Fs::rename origin destination (..any_callback write!) node_fs)))))))))) @.python @@ -511,36 +511,36 @@ (Primitive "python_tuple[2]" [left right])) (ffi.import: PyFile - ["[1]::[0]" - (read [] "io" "try" Binary) - (write [Binary] "io" "try" "?" Any) - (close [] "io" "try" "?" Any)]) + "[1]::[0]" + (read [] "io" "try" Binary) + (write [Binary] "io" "try" "?" Any) + (close [] "io" "try" "?" Any)) (ffi.import: (open [ffi.String ffi.String] "io" "try" PyFile)) (ffi.import: (tuple [[ffi.Integer ffi.Integer]] (Tuple/2 ffi.Integer ffi.Integer))) (ffi.import: os - ["[1]::[0]" - ("static" F_OK ffi.Integer) - ("static" R_OK ffi.Integer) - ("static" W_OK ffi.Integer) - ("static" X_OK ffi.Integer) - - ("static" mkdir [ffi.String] "io" "try" "?" Any) - ("static" access [ffi.String ffi.Integer] "io" "try" ffi.Boolean) - ("static" remove [ffi.String] "io" "try" "?" Any) - ("static" rmdir [ffi.String] "io" "try" "?" Any) - ("static" rename [ffi.String ffi.String] "io" "try" "?" Any) - ("static" utime [ffi.String (Tuple/2 ffi.Integer ffi.Integer)] "io" "try" "?" Any) - ("static" listdir [ffi.String] "io" "try" (Array ffi.String))]) + "[1]::[0]" + ("static" F_OK ffi.Integer) + ("static" R_OK ffi.Integer) + ("static" W_OK ffi.Integer) + ("static" X_OK ffi.Integer) + + ("static" mkdir [ffi.String] "io" "try" "?" Any) + ("static" access [ffi.String ffi.Integer] "io" "try" ffi.Boolean) + ("static" remove [ffi.String] "io" "try" "?" Any) + ("static" rmdir [ffi.String] "io" "try" "?" Any) + ("static" rename [ffi.String ffi.String] "io" "try" "?" Any) + ("static" utime [ffi.String (Tuple/2 ffi.Integer ffi.Integer)] "io" "try" "?" Any) + ("static" listdir [ffi.String] "io" "try" (Array ffi.String))) (ffi.import: os/path - ["[1]::[0]" - ("static" isfile [ffi.String] "io" "try" ffi.Boolean) - ("static" isdir [ffi.String] "io" "try" ffi.Boolean) - ("static" sep ffi.String) - ("static" getsize [ffi.String] "io" "try" ffi.Integer) - ("static" getmtime [ffi.String] "io" "try" ffi.Float)]) + "[1]::[0]" + ("static" isfile [ffi.String] "io" "try" ffi.Boolean) + ("static" isdir [ffi.String] "io" "try" ffi.Boolean) + ("static" sep ffi.String) + ("static" getsize [ffi.String] "io" "try" ffi.Integer) + ("static" getmtime [ffi.String] "io" "try" ffi.Float)) (def: python_separator (os/path::sep)) @@ -571,7 +571,7 @@ (# ! each (|>> (array.list {.#None}) (list#each (|>> (format path ..python_separator))) (monad.each ! (function (_ sub) - (# ! each (|>> [sub]) (<method> [sub])))) + (# ! each (|>> [sub]) (<method> sub)))) (# ! each (|>> (list.only product.right) (list#each product.left))))) (# ! conjoint))))] @@ -592,80 +592,80 @@ instant.absolute)))) (def: (can_execute? path) - (os::access [path (os::X_OK)])) + (os::access path (os::X_OK))) (def: (read path) (do (try.with io.monad) - [file (..open [path "rb"]) - data (PyFile::read [] file) - _ (PyFile::close [] file)] + [file (..open path "rb") + data (PyFile::read file) + _ (PyFile::close file)] (in data))) (def: (delete path) (do (try.with io.monad) - [? (os/path::isfile [path])] + [? (os/path::isfile path)] (if ? - (os::remove [path]) - (os::rmdir [path])))) + (os::remove path) + (os::rmdir path)))) (def: (modify time_stamp path) (let [when (|> time_stamp instant.relative duration.millis (i./ +1,000))] - (os::utime [path (..tuple [when when])]))) + (os::utime path (..tuple [when when])))) (~~ (template [<name> <mode>] [(def: (<name> data path) (do (try.with io.monad) - [file (..open [path <mode>]) - _ (PyFile::write [data] file)] - (PyFile::close [] file)))] + [file (..open path <mode>) + _ (PyFile::write data file)] + (PyFile::close file)))] [write "w+b"] [append "ab"] )) (def: (move destination origin) - (os::rename [origin destination])) + (os::rename origin destination)) ))) @.ruby - (as_is (ffi.import: Time "as" RubyTime - ["[1]::[0]" - ("static" at [Frac] RubyTime) - (to_f [] Frac)]) + (as_is (ffi.import: Time + "[1]::[0]" + ("static" at [Frac] Time) + (to_f [] Frac)) - (ffi.import: Stat "as" RubyStat - ["[1]::[0]" - (executable? [] Bit) - (size Int) - (mtime [] RubyTime)]) + (ffi.import: Stat + "[1]::[0]" + (executable? [] Bit) + (size Int) + (mtime [] Time)) (ffi.import: File "as" RubyFile - ["[1]::[0]" - ("static" SEPARATOR ffi.String) - ("static" open [Path ffi.String] "io" "try" RubyFile) - ("static" stat [Path] "io" "try" RubyStat) - ("static" delete [Path] "io" "try" Int) - ("static" file? [Path] "io" "try" Bit) - ("static" directory? [Path] "io" "try" Bit) - ("static" utime [RubyTime RubyTime Path] "io" "try" Int) - - (read [] "io" "try" Binary) - (write [Binary] "io" "try" Int) - (flush [] "io" "try" "?" Any) - (close [] "io" "try" "?" Any)]) - - (ffi.import: Dir "as" RubyDir - ["[1]::[0]" - ("static" open [Path] "io" "try" RubyDir) - - (children [] "io" "try" (Array Path)) - (close [] "io" "try" "?" Any)]) - - (ffi.import: "fileutils" FileUtils "as" RubyFileUtils - ["[1]::[0]" - ("static" move [Path Path] "io" "try" "?" Any) - ("static" rmdir [Path] "io" "try" "?" Any) - ("static" mkdir [Path] "io" "try" "?" Any)]) + "[1]::[0]" + ("static" SEPARATOR ffi.String) + ("static" open [Path ffi.String] "io" "try" RubyFile) + ("static" stat [Path] "io" "try" Stat) + ("static" delete [Path] "io" "try" Int) + ("static" file? [Path] "io" "try" Bit) + ("static" directory? [Path] "io" "try" Bit) + ("static" utime [Time Time Path] "io" "try" Int) + + (read [] "io" "try" Binary) + (write [Binary] "io" "try" Int) + (flush [] "io" "try" "?" Any) + (close [] "io" "try" "?" Any)) + + (ffi.import: Dir + "[1]::[0]" + ("static" open [Path] "io" "try" Dir) + + (children [] "io" "try" (Array Path)) + (close [] "io" "try" "?" Any)) + + (ffi.import: "fileutils" FileUtils + "[1]::[0]" + ("static" move [Path Path] "io" "try" "?" Any) + ("static" rmdir [Path] "io" "try" "?" Any) + ("static" mkdir [Path] "io" "try" "?" Any)) (def: ruby_separator Text @@ -687,13 +687,13 @@ )) (def: make_directory - RubyFileUtils::mkdir) + FileUtils::mkdir) (~~ (template [<name> <test>] [(def: (<name> path) (do [! (try.with io.monad)] - [self (RubyDir::open [path]) - children (RubyDir::children [] self) + [self (Dir::open path) + children (Dir::children self) output (loop [input (|> children (array.list {.#None}) (list#each (|>> (format path ..ruby_separator)))) @@ -709,7 +709,7 @@ (again tail (if verdict {.#Item head output} output))))) - _ (RubyDir::close [] self)] + _ (Dir::close self)] (in output)))] [directory_files RubyFile::file?] @@ -722,29 +722,29 @@ (|>> RubyFile::stat (# ! each (`` (|>> (~~ (template.spliced <pipeline>))))))))] - [file_size [RubyStat::size .nat]] - [last_modified [(RubyStat::mtime []) - (RubyTime::to_f []) + [file_size [Stat::size .nat]] + [last_modified [Stat::mtime + Time::to_f (f.* +1,000.0) f.int duration.of_millis instant.absolute]] - [can_execute? [(RubyStat::executable? [])]] + [can_execute? [Stat::executable?]] )) (def: (read path) (do (try.with io.monad) - [file (RubyFile::open [path "rb"]) - data (RubyFile::read [] file) - _ (RubyFile::close [] file)] + [file (RubyFile::open path "rb") + data (RubyFile::read file) + _ (RubyFile::close file)] (in data))) (def: (delete path) (do (try.with io.monad) [? (RubyFile::file? path)] (if ? - (RubyFile::delete [path]) - (RubyFileUtils::rmdir [path])))) + (RubyFile::delete path) + (FileUtils::rmdir path)))) (def: (modify moment path) (let [moment (|> moment @@ -752,16 +752,16 @@ duration.millis i.frac (f./ +1,000.0) - RubyTime::at)] - (RubyFile::utime [moment moment path]))) + Time::at)] + (RubyFile::utime moment moment path))) (~~ (template [<mode> <name>] [(def: (<name> data path) (do [! (try.with io.monad)] - [file (RubyFile::open [path <mode>]) - data (RubyFile::write [data] file) - _ (RubyFile::flush [] file) - _ (RubyFile::close [] file)] + [file (RubyFile::open path <mode>) + data (RubyFile::write data file) + _ (RubyFile::flush file) + _ (RubyFile::close file)] (in [])))] ["wb" write] @@ -770,7 +770,7 @@ (def: (move destination origin) (do (try.with io.monad) - [_ (RubyFileUtils::move [origin destination])] + [_ (FileUtils::move origin destination)] (in []))) ))) diff --git a/stdlib/source/library/lux/world/program.lux b/stdlib/source/library/lux/world/program.lux index 95118c399..7ec1fbd68 100644 --- a/stdlib/source/library/lux/world/program.lux +++ b/stdlib/source/library/lux/world/program.lux @@ -1,39 +1,41 @@ -(.using - [library - [lux "*" - ["@" target] - ["[0]" ffi {"+" import:}] - [abstract - ["[0]" monad {"+" Monad do}]] - [control - ["[0]" function] - ["[0]" io {"+" IO}] - ["[0]" maybe ("[1]#[0]" functor)] - ["[0]" try {"+" Try}] - ["[0]" exception {"+" exception:}] - [concurrency - ["[0]" atom] - ["[0]" async {"+" Async}]] - [parser - ["[0]" environment {"+" Environment}]]] - [data - ["[0]" bit ("[1]#[0]" equivalence)] - ["[0]" text - ["%" format {"+" format}]] - [collection - ["[0]" array {"+" Array}] - ["[0]" dictionary {"+" Dictionary}] - ["[0]" list ("[1]#[0]" functor)]]] - ["[0]" macro - ["[0]" template]] - [math - [number - ["i" int]]] - [type - abstract]]] - [// - [file {"+" Path}] - [shell {"+" Exit}]]) +(.`` (.`` (.using + [library + [lux "*" + ["@" target] + [abstract + ["[0]" monad {"+" Monad do}]] + [control + ["[0]" function] + ["[0]" io {"+" IO}] + ["[0]" maybe ("[1]#[0]" functor)] + ["[0]" try {"+" Try}] + ["[0]" exception {"+" exception:}] + [concurrency + ["[0]" atom] + ["[0]" async {"+" Async}]] + [parser + ["[0]" environment {"+" Environment}]]] + [data + ["[0]" bit ("[1]#[0]" equivalence)] + ["[0]" text + ["%" format {"+" format}]] + [collection + ["[0]" array {"+" Array}] + ["[0]" dictionary {"+" Dictionary}] + ["[0]" list ("[1]#[0]" functor)]]] + ["[0]" ffi {"+" import:} + (~~ (.for ["JavaScript" (~~ (.as_is ["[0]" node_js]))] + (~~ (.as_is))))] + ["[0]" macro + ["[0]" template]] + [math + [number + ["i" int]]] + [type + abstract]]] + [// + [file {"+" Path}] + [shell {"+" Exit}]]))) (exception: .public (unknown_environment_variable [name Text]) (exception.report @@ -148,13 +150,13 @@ (|>> %.int panic! io.io)) (import: NodeJs_Process - ["[1]::[0]" - (exit [ffi.Number] "io" Nothing) - (cwd [] "io" Path)]) + "[1]::[0]" + (exit [ffi.Number] "io" Nothing) + (cwd [] "io" Path)) (def: (exit_node_js! code) (-> Exit (IO Nothing)) - (case (ffi.constant ..NodeJs_Process [process]) + (case (ffi.global ..NodeJs_Process [process]) {.#Some process} (NodeJs_Process::exit (i.frac code) process) @@ -162,81 +164,60 @@ (..default_exit! code))) (import: Browser_Window - ["[1]::[0]" - (close [] Nothing)]) + "[1]::[0]" + (close [] Nothing)) (import: Browser_Location - ["[1]::[0]" - (reload [] Nothing)]) + "[1]::[0]" + (reload [] Nothing)) (def: (exit_browser! code) (-> Exit (IO Nothing)) - (case [(ffi.constant ..Browser_Window [window]) - (ffi.constant ..Browser_Location [location])] + (case [(ffi.global ..Browser_Window [window]) + (ffi.global ..Browser_Location [location])] [{.#Some window} {.#Some location}] (exec - (Browser_Window::close [] window) - (Browser_Location::reload [] location) + (Browser_Window::close window) + (Browser_Location::reload location) (..default_exit! code)) [{.#Some window} {.#None}] (exec - (Browser_Window::close [] window) + (Browser_Window::close window) (..default_exit! code)) [{.#None} {.#Some location}] (exec - (Browser_Location::reload [] location) + (Browser_Location::reload location) (..default_exit! code)) [{.#None} {.#None}] (..default_exit! code))) (import: Object - ["[1]::[0]" - ("static" entries [Object] (Array (Array ffi.String)))]) + "[1]::[0]" + ("static" entries [Object] (Array (Array ffi.String)))) (import: NodeJs_OS - ["[1]::[0]" - (homedir [] "io" Path)]) - - (template [<name> <path>] - [(def: (<name> _) - (-> [] (Maybe (-> ffi.String Any))) - (ffi.constant (-> ffi.String Any) <path>))] - - [normal_require [require]] - [global_require [global require]] - [process_load [global process mainModule constructor _load]] - ) - - (def: (require _) - (-> [] (-> ffi.String Any)) - (case [(normal_require []) (global_require []) (process_load [])] - (^or [{.#Some require} _ _] - [_ {.#Some require} _] - [_ _ {.#Some require}]) - require - - _ - (undefined)))) + "[1]::[0]" + (homedir [] "io" Path))) @.python (as_is (import: os - ["[1]::[0]" - ("static" getcwd [] "io" ffi.String) - ("static" _exit [ffi.Integer] "io" Nothing)]) + "[1]::[0]" + ("static" getcwd [] "io" ffi.String) + ("static" _exit [ffi.Integer] "io" Nothing)) (import: os/path - ["[1]::[0]" - ("static" expanduser [ffi.String] "io" ffi.String)]) + "[1]::[0]" + ("static" expanduser [ffi.String] "io" ffi.String)) (import: os/environ - ["[1]::[0]" - ("static" keys [] "io" (Array ffi.String)) - ("static" get [ffi.String] "io" "?" ffi.String)])) + "[1]::[0]" + ("static" keys [] "io" (Array ffi.String)) + ("static" get [ffi.String] "io" "?" ffi.String))) @.lua (as_is (ffi.import: LuaFile - ["[1]::[0]" - (read [ffi.String] "io" "?" ffi.String) - (close [] "io" ffi.Boolean)]) + "[1]::[0]" + (read [ffi.String] "io" "?" ffi.String) + (close [] "io" ffi.Boolean)) (ffi.import: (io/popen [ffi.String] "io" "try" "?" LuaFile)) (ffi.import: (os/getenv [ffi.String] "io" "?" ffi.String)) @@ -251,8 +232,8 @@ (case outcome {.#Some file} (do ! - [?output (LuaFile::read ["*l"] file) - _ (LuaFile::close [] file)] + [?output (LuaFile::read "*l" file) + _ (LuaFile::close file)] (in (maybe.else default ?output))) {.#None} @@ -260,22 +241,22 @@ {try.#Failure _} (in default))))) - @.ruby (as_is (ffi.import: Env "as" RubyEnv - ["[1]::[0]" - ("static" keys [] (Array Text)) - ("static" fetch [Text] "io" "?" Text)]) - - (ffi.import: "fileutils" FileUtils "as" RubyFileUtils - ["[1]::[0]" - ("static" pwd Path)]) + @.ruby (as_is (ffi.import: Env + "[1]::[0]" + ("static" keys [] (Array Text)) + ("static" fetch [Text] "io" "?" Text)) + + (ffi.import: "fileutils" FileUtils + "[1]::[0]" + ("static" pwd Path)) - (ffi.import: Dir "as" RubyDir - ["[1]::[0]" - ("static" home Path)]) + (ffi.import: Dir + "[1]::[0]" + ("static" home Path)) - (ffi.import: Kernel "as" RubyKernel - ["[1]::[0]" - ("static" exit [Int] "io" Nothing)])) + (ffi.import: Kernel + "[1]::[0]" + ("static" exit [Int] "io" Nothing))) ... @.php ... (as_is (ffi.import: (exit [Int] "io" Nothing)) @@ -315,7 +296,7 @@ (for [@.old <jvm> @.jvm <jvm> @.js (io.io (if ffi.on_node_js? - (case (ffi.constant Object [process env]) + (case (ffi.global Object [process env]) {.#Some process/env} (|> (Object::entries [process/env]) (array.list {.#None}) @@ -327,7 +308,7 @@ @.python (# io.monad each (array.list {.#None}) (os/environ::keys [])) ... Lua offers no way to get all the environment variables available. @.lua (io.io (list)) - @.ruby (io.io (array.list {.#None} (RubyEnv::keys []))) + @.ruby (io.io (array.list {.#None} (Env::keys []))) ... @.php (do io.monad ... [environment (..getenv/0 [])] ... (in (|> environment @@ -362,7 +343,7 @@ @.jvm <jvm> @.js (io.io (if ffi.on_node_js? (case (do maybe.monad - [process/env (ffi.constant Object [process env])] + [process/env (ffi.global Object [process env])] (array.read! (:as Nat name) (:as (Array Text) process/env))) {.#Some value} @@ -373,7 +354,7 @@ (exception.except ..unknown_environment_variable [name]))) @.python (!fetch os/environ::get |>) @.lua (!fetch os/getenv |>) - @.ruby (!fetch RubyEnv::fetch |>) + @.ruby (!fetch Env::fetch |>) ])))) (def: home @@ -386,13 +367,14 @@ (for [@.old <jvm> @.jvm <jvm> @.js (if ffi.on_node_js? - (|> (..require [] "os") + (|> (node_js.require "os") + maybe.trusted (:as NodeJs_OS) - (NodeJs_OS::homedir [])) + NodeJs_OS::homedir) <default>) - @.python (os/path::expanduser ["~"]) + @.python (os/path::expanduser "~") @.lua (..run_command "~" "echo ~") - @.ruby (io.io (RubyDir::home)) + @.ruby (io.io (Dir::home)) ... @.php (do io.monad ... [output (..getenv/1 ["HOME"])] ... (in (if (bit#= false (:as Bit output)) @@ -412,9 +394,9 @@ (for [@.old <jvm> @.jvm <jvm> @.js (if ffi.on_node_js? - (case (ffi.constant ..NodeJs_Process [process]) + (case (ffi.global ..NodeJs_Process [process]) {.#Some process} - (NodeJs_Process::cwd [] process) + (NodeJs_Process::cwd process) {.#None} (io.io <default>)) @@ -426,7 +408,7 @@ (if (same? default on_windows) (..run_command default "pwd") (in on_windows))) - @.ruby (io.io (RubyFileUtils::pwd)) + @.ruby (io.io (FileUtils::pwd)) ... @.php (do io.monad ... [output (..getcwd [])] ... (in (if (bit#= false (:as Bit output)) @@ -450,9 +432,9 @@ ... else (..default_exit! code)) - @.python (os::_exit [code]) - @.lua (os/exit [code]) - @.ruby (RubyKernel::exit [code]) + @.python (os::_exit code) + @.lua (os/exit code) + @.ruby (Kernel::exit code) ... @.php (..exit [code]) ... @.scheme (..exit [code]) ])))) diff --git a/stdlib/source/test/lux/ffi.js.lux b/stdlib/source/test/lux/ffi.js.lux index 2b3cb7f96..b697c4b66 100644 --- a/stdlib/source/test/lux/ffi.js.lux +++ b/stdlib/source/test/lux/ffi.js.lux @@ -20,30 +20,30 @@ ["[1][0]" export]]) (/.import: Uint8Array - ["[1]::[0]"]) + "[1]::[0]") ... On Nashorn (/.import: java/lang/String - ["[1]::[0]" - (new [Uint8Array /.String]) - (getBytes [/.String] Uint8Array)]) + "[1]::[0]" + (new [Uint8Array /.String]) + (getBytes [/.String] Uint8Array)) ... On Node (/.import: Buffer - ["[1]::[0]" - ("static" from [/.String /.String] Buffer) - (toString [/.String] /.String)]) + "[1]::[0]" + ("static" from [/.String /.String] Buffer) + (toString [/.String] /.String)) ... On the browser (/.import: TextEncoder - ["[1]::[0]" - (new [/.String]) - (encode [/.String] Uint8Array)]) + "[1]::[0]" + (new [/.String]) + (encode [/.String] Uint8Array)) (/.import: TextDecoder - ["[1]::[0]" - (new [/.String]) - (decode [Uint8Array] /.String)]) + "[1]::[0]" + (new [/.String]) + (decode [Uint8Array] /.String)) (def: .public test Test @@ -96,12 +96,12 @@ (not (/.null? 0)) (not (/.null? "0")) (not (/.null? (|>>))))) - (_.cover [/.constant] - (|> (/.constant /.Function [parseFloat]) + (_.cover [/.global] + (|> (/.global /.Function [parseFloat]) "js object null?" not)) - (_.cover [/.closure] - (|> (/.closure [input/0] input/0) + (_.cover [/.function] + (|> (/.function [input/0] input/0) "js object null?" not)) (_.cover [/.on_browser? /.on_node_js? /.on_nashorn?] @@ -127,19 +127,19 @@ (let [encoding "utf8"] (text#= string (cond /.on_nashorn? - (let [binary (java/lang/String::getBytes [encoding] (:as java/lang/String string))] - (|> (java/lang/String::new [binary encoding]) + (let [binary (java/lang/String::getBytes encoding (:as java/lang/String string))] + (|> (java/lang/String::new binary encoding) (:as Text))) /.on_node_js? - (|> (Buffer::from [string encoding]) - (Buffer::toString [encoding])) + (|> (Buffer::from string encoding) + (Buffer::toString encoding)) ... On the browser - (let [binary (|> (TextEncoder::new [encoding]) - (TextEncoder::encode [string]))] - (|> (TextDecoder::new [encoding]) - (TextDecoder::decode [binary]))) + (let [binary (|> (TextEncoder::new encoding) + (TextEncoder::encode string))] + (|> (TextDecoder::new encoding) + (TextDecoder::decode binary))) )))) $/export.test diff --git a/stdlib/source/test/lux/ffi.lua.lux b/stdlib/source/test/lux/ffi.lua.lux index 682e34763..8639e374d 100644 --- a/stdlib/source/test/lux/ffi.lua.lux +++ b/stdlib/source/test/lux/ffi.lua.lux @@ -48,9 +48,9 @@ [/.Nil] [/.Table] )))) - (_.cover [/.Function /.closure] + (_.cover [/.Function /.function] (exec - (|> (/.closure [input/0] input/0) + (|> (/.function [input/0] input/0) (: /.Function) (: (Ex (_ a) (/.Object a)))) true)) diff --git a/stdlib/source/test/lux/ffi.py.lux b/stdlib/source/test/lux/ffi.py.lux index efa966c7d..911ea1c82 100644 --- a/stdlib/source/test/lux/ffi.py.lux +++ b/stdlib/source/test/lux/ffi.py.lux @@ -14,9 +14,9 @@ ["[1][0]" export]]) (/.import: os - ["[1]::[0]" - ("static" R_OK /.Integer) - ("static" W_OK /.Integer)]) + "[1]::[0]" + ("static" R_OK /.Integer) + ("static" W_OK /.Integer)) (def: .public test Test @@ -51,9 +51,9 @@ [/.None] [/.Dict] )))) - (_.cover [/.Function /.lambda] + (_.cover [/.Function /.function] (exec - (|> (/.lambda [input/0] input/0) + (|> (/.function [input/0] input/0) (: /.Function) (: (Ex (_ a) (/.Object a)))) true)) diff --git a/stdlib/source/test/lux/ffi.rb.lux b/stdlib/source/test/lux/ffi.rb.lux index b7e488547..75a89c833 100644 --- a/stdlib/source/test/lux/ffi.rb.lux +++ b/stdlib/source/test/lux/ffi.rb.lux @@ -12,8 +12,8 @@ ["[1][0]" export]]) (/.import: File - ["[1]::[0]" - ("static" SEPARATOR /.String)]) + "[1]::[0]" + ("static" SEPARATOR /.String)) (def: .public test Test diff --git a/stdlib/source/test/lux/target/js.lux b/stdlib/source/test/lux/target/js.lux index ae190fade..16366a141 100644 --- a/stdlib/source/test/lux/target/js.lux +++ b/stdlib/source/test/lux/target/js.lux @@ -34,7 +34,7 @@ ... Note: I have to call "eval" this way ... in order to avoid a quirk of calling eval in Node ... when the code is running under "use strict";. - (try (let [return ("js apply" (function.identity ("js constant" "eval")) (/.code code))] + (try (let [return ("js apply" (function.identity ("js constant" "eval")) [(/.code code)])] (if ("js object null?" return) {.#None} {.#Some return})))) diff --git a/stdlib/source/test/lux/target/python.lux b/stdlib/source/test/lux/target/python.lux index cb9a3551c..afcc8a43e 100644 --- a/stdlib/source/test/lux/target/python.lux +++ b/stdlib/source/test/lux/target/python.lux @@ -429,8 +429,8 @@ )))) (ffi.import: Dict - ["[1]::[0]" - (get [ffi.String] Any)]) + "[1]::[0]" + (get [ffi.String] Any)) (ffi.import: (dict [] ..Dict)) @@ -441,7 +441,7 @@ environment (..dict [])] (exec ("python exec" (/.code (it (/.var $output))) (:expected environment)) - (Dict::get [$output] environment)))) + (Dict::get $output environment)))) (def: test|access Test diff --git a/stdlib/source/unsafe/lux/data/binary.lux b/stdlib/source/unsafe/lux/data/binary.lux index cf25b655f..1e3ef2118 100644 --- a/stdlib/source/unsafe/lux/data/binary.lux +++ b/stdlib/source/unsafe/lux/data/binary.lux @@ -32,9 +32,9 @@ @.js (as_is (ffi.import: ArrayBuffer - ["[1]::[0]"]) + "[1]::[0]") (ffi.import: Uint8Array - ["[1]::[0]"]) + "[1]::[0]") (type: .public Binary Uint8Array)) @@ -76,6 +76,7 @@ (~~ (.static @.python)) (.|> <size> + [] ("python apply" (.:as ffi.Function ("python constant" "bytearray"))) (.:as ..Binary)) |