From 14f18c100c2f8c3ec9c60c14330d926cd2d6f639 Mon Sep 17 00:00:00 2001 From: Eduardo Julian Date: Mon, 4 Apr 2022 22:47:56 -0400 Subject: Properly handling variance for arrays to avoid invalid subtyping. --- .github/workflows/setup_aedifex/action.yml | 5 +- .github/workflows/test.yml | 2 + documentation/bookmark/arithmetic.md | 12 --- documentation/bookmark/back_end/c++.md | 5 ++ documentation/bookmark/bloat.md | 4 + documentation/bookmark/business/management.md | 1 + documentation/bookmark/business/model.md | 4 + documentation/bookmark/business/negotiation.md | 1 + documentation/bookmark/community/onboarding.md | 4 + documentation/bookmark/composition/mixin.md | 8 ++ .../bookmark/composition/recursion_schemes.md | 20 +++++ documentation/bookmark/concurrency/Engine.md | 4 - documentation/bookmark/concurrency/disruptor.md | 4 + documentation/bookmark/concurrency/engine.md | 4 + .../bookmark/concurrency/lock_free_programming.md | 1 + .../bookmark/foreign_function_interface.md | 1 + documentation/bookmark/graphic/3D.md | 8 -- documentation/bookmark/graphic/3d.md | 8 ++ documentation/bookmark/graphic/svg.md | 4 + documentation/bookmark/math/arithmetic.md | 12 +++ documentation/bookmark/mixin.md | 8 -- documentation/bookmark/music/language.md | 4 + documentation/bookmark/recursion_schemes.md | 20 ----- documentation/bookmark/resource_management.md | 5 +- documentation/bookmark/text/unicode.md | 4 + documentation/bookmark/text/utf8.md | 9 ++ documentation/bookmark/type_theory/unit.md | 5 +- documentation/bookmark/unicode.md | 4 - documentation/bookmark/utf8.md | 9 -- lux-bootstrapper/src/lux/analyser/proc/jvm.clj | 21 +++-- .../src/lux/compiler/jvm/proc/host.clj | 22 ++++- lux-bootstrapper/src/lux/host.clj | 13 ++- lux-bootstrapper/src/lux/type.clj | 25 +++++- lux-bootstrapper/src/lux/type/host.clj | 16 +++- .../source/library/lux/data/collection/array.lux | 85 ++++++++++--------- stdlib/source/library/lux/ffi.jvm.lux | 12 +-- stdlib/source/library/lux/ffi.old.lux | 2 +- .../source/library/lux/target/jvm/reflection.lux | 4 +- .../language/lux/phase/extension/analysis/jvm.lux | 66 +++++++++------ stdlib/source/library/lux/type/variance.lux | 35 +++++++- stdlib/source/unsafe/lux/data/collection/array.lux | 96 +++++++++++----------- 41 files changed, 365 insertions(+), 212 deletions(-) delete mode 100644 documentation/bookmark/arithmetic.md create mode 100644 documentation/bookmark/bloat.md create mode 100644 documentation/bookmark/business/model.md create mode 100644 documentation/bookmark/community/onboarding.md create mode 100644 documentation/bookmark/composition/mixin.md create mode 100644 documentation/bookmark/composition/recursion_schemes.md delete mode 100644 documentation/bookmark/concurrency/Engine.md create mode 100644 documentation/bookmark/concurrency/disruptor.md create mode 100644 documentation/bookmark/concurrency/engine.md delete mode 100644 documentation/bookmark/graphic/3D.md create mode 100644 documentation/bookmark/graphic/3d.md create mode 100644 documentation/bookmark/graphic/svg.md create mode 100644 documentation/bookmark/math/arithmetic.md delete mode 100644 documentation/bookmark/mixin.md create mode 100644 documentation/bookmark/music/language.md delete mode 100644 documentation/bookmark/recursion_schemes.md create mode 100644 documentation/bookmark/text/unicode.md create mode 100644 documentation/bookmark/text/utf8.md delete mode 100644 documentation/bookmark/unicode.md delete mode 100644 documentation/bookmark/utf8.md diff --git a/.github/workflows/setup_aedifex/action.yml b/.github/workflows/setup_aedifex/action.yml index bc848c2f0..fa70014a3 100644 --- a/.github/workflows/setup_aedifex/action.yml +++ b/.github/workflows/setup_aedifex/action.yml @@ -1,3 +1,5 @@ +# https://cardinalby.github.io/blog/post/github-actions/dry-reusing-code-in-github-actions/ +# https://docs.github.com/en/actions/creating-actions/creating-a-composite-action name: 'Setup Aedifex' runs: using: "composite" @@ -8,7 +10,8 @@ runs: distribution: 'temurin' java-version: '17' - - uses: actions/checkout@v2 + # Presumably, whoever invokes this action already has done a checkout. + # - uses: actions/checkout@v2 - run: wget https://github.com/LuxLang/lux/releases/download/0.6.5/aedifex_do_not_touch_3.jar && mv aedifex_do_not_touch_3.jar aedifex.jar shell: bash diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index f8b31badd..740da5621 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -4,11 +4,13 @@ jobs: test_stdlib_on_jvm: runs-on: ubuntu-latest steps: + - uses: actions/checkout@v2 - uses: ./.github/workflows/setup_aedifex - run: cd ./stdlib/ && ../lux.sh with jvm with bibliotheca test test_stdlib_on_node_js: runs-on: ubuntu-latest steps: + - uses: actions/checkout@v2 - uses: ./.github/workflows/setup_aedifex # https://github.com/actions/setup-node - uses: actions/setup-node@v2 diff --git a/documentation/bookmark/arithmetic.md b/documentation/bookmark/arithmetic.md deleted file mode 100644 index e4a3ddd07..000000000 --- a/documentation/bookmark/arithmetic.md +++ /dev/null @@ -1,12 +0,0 @@ -# Saturation - -1. [Saturation arithmetic](https://en.wikipedia.org/wiki/Saturation_arithmetic) - -# Interval - -1. [Interval Arithmetic: Not All Intervals are Created Equal](https://samlikes.pizza/pluto_interval_blog.jl.html) -1. [Growing a Language, by Guy Steele](https://www.youtube.com/watch?v=_ahvzDzKdB0&t=2214s) -1. [Yet another alternative to floating-point numbers](https://wordsandbuttons.online/yet_another_alternative_to_floating_point_numbers.html) -1. [Interval arithmetic](https://en.wikipedia.org/wiki/Interval_arithmetic) -1. [How do you compute the midpoint of an interval?](https://hal.archives-ouvertes.fr/file/index/docid/576641/filename/computing-midpoint.pdf) - diff --git a/documentation/bookmark/back_end/c++.md b/documentation/bookmark/back_end/c++.md index 8cbb088d5..e86d2672d 100644 --- a/documentation/bookmark/back_end/c++.md +++ b/documentation/bookmark/back_end/c++.md @@ -1,5 +1,10 @@ +# Optimization + +0. [C and C++ coding style for best performance](https://www.ibm.com/docs/en/aix/7.1?topic=implementation-c-c-coding-style-best-performance) + # Reference +0. [Constant references are not always your friends](https://belaycpp.com/2022/02/15/constant-references-are-not-always-your-friends/) 0. [Unionizing for Profit: How to Exploit the Power of Unions in C++](https://dev-discuss.pytorch.org/t/unionizing-for-profit-how-to-exploit-the-power-of-unions-in-c/444) 0. [std::any: How, when, and why](https://devblogs.microsoft.com/cppblog/stdany-how-when-and-why/) 0. [Using C Libraries in your Modern C++ Embedded Project - Michael Caisse - CppCon 2021](https://www.youtube.com/watch?v=Ototzy-nP4M) diff --git a/documentation/bookmark/bloat.md b/documentation/bookmark/bloat.md new file mode 100644 index 000000000..e1091256c --- /dev/null +++ b/documentation/bookmark/bloat.md @@ -0,0 +1,4 @@ +# Reference + +0. [Nibbler: Debloating Binary Shared Libraries](https://cs.brown.edu/~vpk/papers/nibbler.acsac19.pdf) + diff --git a/documentation/bookmark/business/management.md b/documentation/bookmark/business/management.md index b7205f1d0..aa7b63070 100644 --- a/documentation/bookmark/business/management.md +++ b/documentation/bookmark/business/management.md @@ -1,4 +1,5 @@ # Reference +0. [First, Let’s Fire All the Managers](https://hbr.org/2011/12/first-lets-fire-all-the-managers) 0. [Value Add Disease](https://boz.com/articles/vad) diff --git a/documentation/bookmark/business/model.md b/documentation/bookmark/business/model.md new file mode 100644 index 000000000..7857523b8 --- /dev/null +++ b/documentation/bookmark/business/model.md @@ -0,0 +1,4 @@ +# Reference + +0. [Reciprocity as a Business Model: What motivates people to pay for services they receive?](https://briefthoughts.substack.com/p/reciprocity-as-a-business-model?s=r) + diff --git a/documentation/bookmark/business/negotiation.md b/documentation/bookmark/business/negotiation.md index 636bcbbfe..32b092b3d 100644 --- a/documentation/bookmark/business/negotiation.md +++ b/documentation/bookmark/business/negotiation.md @@ -1,4 +1,5 @@ # Reference +0. [A Better Way to Divide the Pie](https://insights.som.yale.edu/insights/better-way-to-divide-the-pie) 0. [Rethinking Negotiation: A smarter way to split the pie](https://hbr.org/2021/11/rethinking-negotiation) diff --git a/documentation/bookmark/community/onboarding.md b/documentation/bookmark/community/onboarding.md new file mode 100644 index 000000000..8407ed4cd --- /dev/null +++ b/documentation/bookmark/community/onboarding.md @@ -0,0 +1,4 @@ +# Reference + +0. [The Ultimate Guide to Onboarding Software Engineers](https://leadership.garden/onboarding-engineers/) + diff --git a/documentation/bookmark/composition/mixin.md b/documentation/bookmark/composition/mixin.md new file mode 100644 index 000000000..bdcc7ae9c --- /dev/null +++ b/documentation/bookmark/composition/mixin.md @@ -0,0 +1,8 @@ +# Reference + +1. [Prototypes: Object-Orientation, Functionally](http://fare.tunes.org/files/cs/poof.pdf) +1. [The Different Aspects of Monads and Mixins](http://ropas.snu.ac.kr/~bruno/papers/MixinAspects.pdf) +1. [THAT ABOUT WRAPS IT UP: Using FIX to Handle Errors Without Exceptions, and Other Programming Tricks](http://www.lfcs.inf.ed.ac.uk/reports/97/ECS-LFCS-97-375/ECS-LFCS-97-375.pdf) +1. [EffectiveAdvice: Disciplined Advice with Explicit Effects](http://www.cs.utexas.edu/~wcook/Drafts/2010/EffectiveAdvice.pdf) +1. [16. Object Reorientation: Generic Functions](http://www.gigamonkeys.com/book/object-reorientation-generic-functions.html) + diff --git a/documentation/bookmark/composition/recursion_schemes.md b/documentation/bookmark/composition/recursion_schemes.md new file mode 100644 index 000000000..31a013123 --- /dev/null +++ b/documentation/bookmark/composition/recursion_schemes.md @@ -0,0 +1,20 @@ +# Reference + +0. [An Introduction to Recursion Schemes](https://blog.sumtypeofway.com/posts/introduction-to-recursion-schemes.html) +0. [Recursion Schemes, Part II: A Mob of Morphisms](https://blog.sumtypeofway.com/posts/recursion-schemes-part-2.html) +0. [Recursion Schemes, Part III: Folds in Context](https://blog.sumtypeofway.com/posts/recursion-schemes-part-3.html) +0. [Recursion Schemes, Part IV: Time is of the Essence](https://blog.sumtypeofway.com/posts/recursion-schemes-part-4.html) +0. [Recursion Schemes, Part 4½: Better Living Through Base Functors](https://blog.sumtypeofway.com/posts/recursion-schemes-part-4-point-5.html) +0. [Recursion Schemes, Part V: Hello, Hylomorphisms](https://blog.sumtypeofway.com/posts/recursion-schemes-part-5.html) +0. [Recursion Schemes, Part VI: Comonads, Composition, and Generality](https://blog.sumtypeofway.com/posts/recursion-schemes-part-6.html) +0. [Probability Tree Diagrams. Recursion Schemes. Why Finding the Right Solution is Sometimes Hard?](https://rpeszek.github.io/posts/2021-07-18-prob-tree-scheme.html) +0. [Unifying Structured Recursion Schemes](https://www.cs.ox.ac.uk/people/nicolas.wu/papers/URS.pdf) +0. http://maartenfokkinga.github.io/utwente/mmf91m.pdf +0. http://comonad.com/reader/2009/recursion-schemes/ +0. [Peeling the Banana: Recursion Schemes from First Principles - Zainab Ali](https://www.youtube.com/watch?v=XZ9nPZbaYfE) +0. https://github.com/passy/awesome-recursion-schemes +0. [YOW! Lambda Jam 2018 - Amy Wong - Introduction to recursion scheme](https://www.youtube.com/watch?v=YnqPdlJd38o) +0. https://bartoszmilewski.com/2018/08/20/recursion-schemes-for-higher-algebras/ +0. https://chrilves.github.io/hugo/posts/recursion_schemes_intro/ +0. [Recursion Schemes: A Field Guide (Redux)](http://comonad.com/reader/2009/recursion-schemes/) + diff --git a/documentation/bookmark/concurrency/Engine.md b/documentation/bookmark/concurrency/Engine.md deleted file mode 100644 index 33d036863..000000000 --- a/documentation/bookmark/concurrency/Engine.md +++ /dev/null @@ -1,4 +0,0 @@ -# Reference - -1. [Literate Engines in Lisp](http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.45.6198) - diff --git a/documentation/bookmark/concurrency/disruptor.md b/documentation/bookmark/concurrency/disruptor.md new file mode 100644 index 000000000..159a380f6 --- /dev/null +++ b/documentation/bookmark/concurrency/disruptor.md @@ -0,0 +1,4 @@ +# Reference + +0. [LMAX Disruptor: High performance alternative to bounded queues for exchanging data between concurrent threads](https://lmax-exchange.github.io/disruptor/disruptor.html) + diff --git a/documentation/bookmark/concurrency/engine.md b/documentation/bookmark/concurrency/engine.md new file mode 100644 index 000000000..33d036863 --- /dev/null +++ b/documentation/bookmark/concurrency/engine.md @@ -0,0 +1,4 @@ +# Reference + +1. [Literate Engines in Lisp](http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.45.6198) + diff --git a/documentation/bookmark/concurrency/lock_free_programming.md b/documentation/bookmark/concurrency/lock_free_programming.md index 1ee123951..d904c8841 100644 --- a/documentation/bookmark/concurrency/lock_free_programming.md +++ b/documentation/bookmark/concurrency/lock_free_programming.md @@ -1,5 +1,6 @@ # Reference +0. [Nonblocking Algorithms and Scalable Multicore Programming: Exploring some alternatives to lock-based synchronization](https://queue.acm.org/detail.cfm?id=2492433) 0. [Design and Implementation of Highly Scalable Quantifiable Data Structures in C++ - CppCon 2021](https://www.youtube.com/watch?v=ECWsLj0pgbI) 0. [Building a Lock-free Multi-producer, Multi-consumer Queue for Tcmalloc - Matt Kulukundis - CppCon 21](https://www.youtube.com/watch?v=_qaKkHuHYE0) 0. [Fear and Loathing in Lock-Free Programming](https://medium.com/@tylerneely/fear-and-loathing-in-lock-free-programming-7158b1cdd50c) diff --git a/documentation/bookmark/foreign_function_interface.md b/documentation/bookmark/foreign_function_interface.md index eca9fe747..ce86904db 100644 --- a/documentation/bookmark/foreign_function_interface.md +++ b/documentation/bookmark/foreign_function_interface.md @@ -1,4 +1,5 @@ # Reference +0. [Rust - Python FFI From Scratch](https://i.hsfzxjy.site/2022-03-12-rust-python-ffi-from-scratch/) 0. [Porting libffi to pure WebAssembly](https://www.tweag.io/blog/2022-03-17-libffi-wasm32/) diff --git a/documentation/bookmark/graphic/3D.md b/documentation/bookmark/graphic/3D.md deleted file mode 100644 index a4d7702f0..000000000 --- a/documentation/bookmark/graphic/3D.md +++ /dev/null @@ -1,8 +0,0 @@ -# Reference - -0. [3D Graphics for Dummies - Chris Ryan - CppCon 2021](https://www.youtube.com/watch?v=EIijFV3VE1g) - -# Three.js - -0. [Three.js Fundamentals](https://threejsfundamentals.org/) - diff --git a/documentation/bookmark/graphic/3d.md b/documentation/bookmark/graphic/3d.md new file mode 100644 index 000000000..a4d7702f0 --- /dev/null +++ b/documentation/bookmark/graphic/3d.md @@ -0,0 +1,8 @@ +# Reference + +0. [3D Graphics for Dummies - Chris Ryan - CppCon 2021](https://www.youtube.com/watch?v=EIijFV3VE1g) + +# Three.js + +0. [Three.js Fundamentals](https://threejsfundamentals.org/) + diff --git a/documentation/bookmark/graphic/svg.md b/documentation/bookmark/graphic/svg.md new file mode 100644 index 000000000..36b7efe43 --- /dev/null +++ b/documentation/bookmark/graphic/svg.md @@ -0,0 +1,4 @@ +# Reference + +0. [Optimizing SVG Patterns to Their Smallest Size](https://css-tricks.com/optimizing-svg-patterns/) + diff --git a/documentation/bookmark/math/arithmetic.md b/documentation/bookmark/math/arithmetic.md new file mode 100644 index 000000000..93e4a97ee --- /dev/null +++ b/documentation/bookmark/math/arithmetic.md @@ -0,0 +1,12 @@ +# Saturation + +0. [Saturation arithmetic](https://en.wikipedia.org/wiki/Saturation_arithmetic) + +# Interval + +0. [Interval Arithmetic: Not All Intervals are Created Equal](https://samlikes.pizza/pluto_interval_blog.jl.html) +0. [Growing a Language, by Guy Steele](https://www.youtube.com/watch?v=_ahvzDzKdB0&t=2214s) +0. [Yet another alternative to floating-point numbers](https://wordsandbuttons.online/yet_another_alternative_to_floating_point_numbers.html) +0. [Interval arithmetic](https://en.wikipedia.org/wiki/Interval_arithmetic) +0. [How do you compute the midpoint of an interval?](https://hal.archives-ouvertes.fr/file/index/docid/576641/filename/computing-midpoint.pdf) + diff --git a/documentation/bookmark/mixin.md b/documentation/bookmark/mixin.md deleted file mode 100644 index bdcc7ae9c..000000000 --- a/documentation/bookmark/mixin.md +++ /dev/null @@ -1,8 +0,0 @@ -# Reference - -1. [Prototypes: Object-Orientation, Functionally](http://fare.tunes.org/files/cs/poof.pdf) -1. [The Different Aspects of Monads and Mixins](http://ropas.snu.ac.kr/~bruno/papers/MixinAspects.pdf) -1. [THAT ABOUT WRAPS IT UP: Using FIX to Handle Errors Without Exceptions, and Other Programming Tricks](http://www.lfcs.inf.ed.ac.uk/reports/97/ECS-LFCS-97-375/ECS-LFCS-97-375.pdf) -1. [EffectiveAdvice: Disciplined Advice with Explicit Effects](http://www.cs.utexas.edu/~wcook/Drafts/2010/EffectiveAdvice.pdf) -1. [16. Object Reorientation: Generic Functions](http://www.gigamonkeys.com/book/object-reorientation-generic-functions.html) - diff --git a/documentation/bookmark/music/language.md b/documentation/bookmark/music/language.md new file mode 100644 index 000000000..f7fb95dd6 --- /dev/null +++ b/documentation/bookmark/music/language.md @@ -0,0 +1,4 @@ +# Reference + +0. [glicol](https://glicol.org/) + diff --git a/documentation/bookmark/recursion_schemes.md b/documentation/bookmark/recursion_schemes.md deleted file mode 100644 index 31a013123..000000000 --- a/documentation/bookmark/recursion_schemes.md +++ /dev/null @@ -1,20 +0,0 @@ -# Reference - -0. [An Introduction to Recursion Schemes](https://blog.sumtypeofway.com/posts/introduction-to-recursion-schemes.html) -0. [Recursion Schemes, Part II: A Mob of Morphisms](https://blog.sumtypeofway.com/posts/recursion-schemes-part-2.html) -0. [Recursion Schemes, Part III: Folds in Context](https://blog.sumtypeofway.com/posts/recursion-schemes-part-3.html) -0. [Recursion Schemes, Part IV: Time is of the Essence](https://blog.sumtypeofway.com/posts/recursion-schemes-part-4.html) -0. [Recursion Schemes, Part 4½: Better Living Through Base Functors](https://blog.sumtypeofway.com/posts/recursion-schemes-part-4-point-5.html) -0. [Recursion Schemes, Part V: Hello, Hylomorphisms](https://blog.sumtypeofway.com/posts/recursion-schemes-part-5.html) -0. [Recursion Schemes, Part VI: Comonads, Composition, and Generality](https://blog.sumtypeofway.com/posts/recursion-schemes-part-6.html) -0. [Probability Tree Diagrams. Recursion Schemes. Why Finding the Right Solution is Sometimes Hard?](https://rpeszek.github.io/posts/2021-07-18-prob-tree-scheme.html) -0. [Unifying Structured Recursion Schemes](https://www.cs.ox.ac.uk/people/nicolas.wu/papers/URS.pdf) -0. http://maartenfokkinga.github.io/utwente/mmf91m.pdf -0. http://comonad.com/reader/2009/recursion-schemes/ -0. [Peeling the Banana: Recursion Schemes from First Principles - Zainab Ali](https://www.youtube.com/watch?v=XZ9nPZbaYfE) -0. https://github.com/passy/awesome-recursion-schemes -0. [YOW! Lambda Jam 2018 - Amy Wong - Introduction to recursion scheme](https://www.youtube.com/watch?v=YnqPdlJd38o) -0. https://bartoszmilewski.com/2018/08/20/recursion-schemes-for-higher-algebras/ -0. https://chrilves.github.io/hugo/posts/recursion_schemes_intro/ -0. [Recursion Schemes: A Field Guide (Redux)](http://comonad.com/reader/2009/recursion-schemes/) - diff --git a/documentation/bookmark/resource_management.md b/documentation/bookmark/resource_management.md index 3b353ccab..ef459b9f0 100644 --- a/documentation/bookmark/resource_management.md +++ b/documentation/bookmark/resource_management.md @@ -1,5 +1,6 @@ # Reference -1. [Understanding ResourceT](https://www.fpcomplete.com/blog/2017/06/understanding-resourcet/) -1. [Composable resource management in Scala](https://bszwej.medium.com/composable-resource-management-in-scala-ce902bda48b2) +0. [Vale's Higher RAII, the pattern that saved me a vital 5 hours in the 7DRL Challenge](https://verdagon.dev/blog/higher-raii-7drl) +0. [Understanding ResourceT](https://www.fpcomplete.com/blog/2017/06/understanding-resourcet/) +0. [Composable resource management in Scala](https://bszwej.medium.com/composable-resource-management-in-scala-ce902bda48b2) diff --git a/documentation/bookmark/text/unicode.md b/documentation/bookmark/text/unicode.md new file mode 100644 index 000000000..f58b09aac --- /dev/null +++ b/documentation/bookmark/text/unicode.md @@ -0,0 +1,4 @@ +# Reference + +0. [How Unicode helps to ruin your software](https://blog.typeable.io/posts/2021-08-17-unicode.html) + diff --git a/documentation/bookmark/text/utf8.md b/documentation/bookmark/text/utf8.md new file mode 100644 index 000000000..4def76b75 --- /dev/null +++ b/documentation/bookmark/text/utf8.md @@ -0,0 +1,9 @@ +# Reference + +0. [A Branchless UTF-8 Decoder](https://nullprogram.com/blog/2017/10/06/) +0. [skeeto/branchless-utf8](https://github.com/skeeto/branchless-utf8/blob/master/utf8.h) +0. [trivial-utf-8](https://gitlab.common-lisp.net/trivial-utf-8/trivial-utf-8) +0. [utf8: Unicode Text Processing](https://rdrr.io/cran/utf8/) +0. [Encoding character strings in R](https://rstudio-pubs-static.s3.amazonaws.com/279354_f552c4c41852439f910ad620763960b6.html) +0. [Any Encoding, Ever - ztd.text and Unicode for C++](https://thephd.dev/any-encoding-ever-ztd-text-unicode-cpp) + diff --git a/documentation/bookmark/type_theory/unit.md b/documentation/bookmark/type_theory/unit.md index cf23e396c..1a82ddf66 100644 --- a/documentation/bookmark/type_theory/unit.md +++ b/documentation/bookmark/type_theory/unit.md @@ -1,5 +1,6 @@ # Reference -1. https://en.wikipedia.org/wiki/Metric_prefix#Metric_units -1. [unittyped: An extendable library for type-safe computations including units.](https://hackage.haskell.org/package/unittyped) +0. [mp-units - A Units Library for C++](https://github.com/mpusz/units) +0. https://en.wikipedia.org/wiki/Metric_prefix#Metric_units +0. [unittyped: An extendable library for type-safe computations including units.](https://hackage.haskell.org/package/unittyped) diff --git a/documentation/bookmark/unicode.md b/documentation/bookmark/unicode.md deleted file mode 100644 index 706b3791d..000000000 --- a/documentation/bookmark/unicode.md +++ /dev/null @@ -1,4 +0,0 @@ -# Reference - -1. [How Unicode helps to ruin your software](https://blog.typeable.io/posts/2021-08-17-unicode.html) - diff --git a/documentation/bookmark/utf8.md b/documentation/bookmark/utf8.md deleted file mode 100644 index 3dd68e828..000000000 --- a/documentation/bookmark/utf8.md +++ /dev/null @@ -1,9 +0,0 @@ -# Reference - -1. [A Branchless UTF-8 Decoder](https://nullprogram.com/blog/2017/10/06/) -1. [skeeto/branchless-utf8](https://github.com/skeeto/branchless-utf8/blob/master/utf8.h) -1. [trivial-utf-8](https://gitlab.common-lisp.net/trivial-utf-8/trivial-utf-8) -1. [utf8: Unicode Text Processing](https://rdrr.io/cran/utf8/) -1. [Encoding character strings in R](https://rstudio-pubs-static.s3.amazonaws.com/279354_f552c4c41852439f910ad620763960b6.html) -1. [Any Encoding, Ever - ztd.text and Unicode for C++](https://thephd.dev/any-encoding-ever-ztd-text-unicode-cpp) - diff --git a/lux-bootstrapper/src/lux/analyser/proc/jvm.clj b/lux-bootstrapper/src/lux/analyser/proc/jvm.clj index 38310e60c..0cfa8c873 100644 --- a/lux-bootstrapper/src/lux/analyser/proc/jvm.clj +++ b/lux-bootstrapper/src/lux/analyser/proc/jvm.clj @@ -206,7 +206,7 @@ (&/$GenericArray param) (|do [=param (generic-class->type env param)] - (return (&/$Primitive &host-type/array-data-tag (&/|list =param)))) + (return (&type/Array =param))) (&/$GenericWildcard _) (return (&/$ExQ &/$End (&/$Parameter 1))) @@ -568,7 +568,7 @@ &&a-parser/parse-gclass) gtype-env &/get-type-env =gclass (&host-type/instance-gtype &type/existential gtype-env gclass) - :let [array-type (&/$Primitive &host-type/array-data-tag (&/|list =gclass))] + :let [array-type (&type/Array =gclass)] =length (&&/analyse-1 analyse length-type length) _ (&type/check exo-type array-type) _location &/location] @@ -578,11 +578,14 @@ (defn- analyse-jvm-aaload [analyse exo-type ?values] (|do [:let [(&/$Item array (&/$Item idx (&/$End))) ?values] =array (&&/analyse-1+ analyse array) - [arr-class arr-params] (ensure-object (&&/expr-type* =array)) + array-type (&type/normal (&&/expr-type* =array)) + [arr-class arr-params] (ensure-object array-type) _ (&/assert! (= &host-type/array-data-tag arr-class) (str "[Analyser Error] Expected array. Instead got: " arr-class)) - :let [(&/$Item inner-arr-type (&/$End)) arr-params] + :let [(&/$Item mutable_type (&/$End)) arr-params + (&/$Primitive "#Mutable" (&/$Item type_variance (&/$End))) mutable_type + (&/$Function write_type read_type) type_variance] =idx (&&/analyse-1 analyse idx-type idx) - _ (&type/check exo-type inner-arr-type) + _ (&type/check exo-type read_type) _location &/location] (return (&/|list (&&/|meta exo-type _location (&&/$proc (&/T ["jvm" "aaload"]) (&/|list =array =idx) (&/|list))))))) @@ -590,12 +593,14 @@ (defn- analyse-jvm-aastore [analyse exo-type ?values] (|do [:let [(&/$Item array (&/$Item idx (&/$Item elem (&/$End)))) ?values] =array (&&/analyse-1+ analyse array) - :let [array-type (&&/expr-type* =array)] + array-type (&type/normal (&&/expr-type* =array)) [arr-class arr-params] (ensure-object array-type) _ (&/assert! (= &host-type/array-data-tag arr-class) (str "[Analyser Error] Expected array. Instead got: " arr-class)) - :let [(&/$Item inner-arr-type (&/$End)) arr-params] + :let [(&/$Item mutable_type (&/$End)) arr-params + (&/$Primitive "#Mutable" (&/$Item type_variance (&/$End))) mutable_type + (&/$Function write_type read_type) type_variance] =idx (&&/analyse-1 analyse idx-type idx) - =elem (&&/analyse-1 analyse inner-arr-type elem) + =elem (&&/analyse-1 analyse write_type elem) _ (&type/check exo-type array-type) _location &/location] (return (&/|list (&&/|meta exo-type _location diff --git a/lux-bootstrapper/src/lux/compiler/jvm/proc/host.clj b/lux-bootstrapper/src/lux/compiler/jvm/proc/host.clj index a455be83a..619e4b6f9 100644 --- a/lux-bootstrapper/src/lux/compiler/jvm/proc/host.clj +++ b/lux-bootstrapper/src/lux/compiler/jvm/proc/host.clj @@ -777,7 +777,11 @@ ;; (&/$End) special-args ] ^MethodVisitor *writer* &/get-writer - array-type (&host/->java-sig (&a/expr-type* ?array)) + normal_array_type (&type/normal (&a/expr-type* ?array)) + :let [(&/$Primitive "#Array" (&/$Item mutable_type (&/$End))) normal_array_type + (&/$Primitive "#Mutable" (&/$Item type_variance (&/$End))) mutable_type + (&/$Function write_type read_type) type_variance] + array-type (&host/->java-sig (&/$Primitive "#Array" (&/|list read_type))) _ (compile ?array) :let [_ (.visitTypeInsn *writer* Opcodes/CHECKCAST array-type)] _ (compile ?idx) @@ -792,7 +796,11 @@ ;; (&/$End) special-args ] ^MethodVisitor *writer* &/get-writer - array-type (&host/->java-sig (&a/expr-type* ?array)) + normal_array_type (&type/normal (&a/expr-type* ?array)) + :let [(&/$Primitive "#Array" (&/$Item mutable_type (&/$End))) normal_array_type + (&/$Primitive "#Mutable" (&/$Item type_variance (&/$End))) mutable_type + (&/$Function write_type read_type) type_variance] + array-type (&host/->java-sig (&/$Primitive "#Array" (&/|list write_type))) _ (compile ?array) :let [_ (.visitTypeInsn *writer* Opcodes/CHECKCAST array-type)] :let [_ (.visitInsn *writer* Opcodes/DUP)] @@ -809,7 +817,15 @@ ;; (&/$End) special-args ] ^MethodVisitor *writer* &/get-writer - array-type (&host/->java-sig (&a/expr-type* ?array)) + normal_array_type (&type/normal (&a/expr-type* ?array)) + array-type (|case normal_array_type + (&/$Primitive ?name (&/$End)) + (&host/->java-sig normal_array_type) + + (&/$Primitive "#Array" (&/$Item mutable_type (&/$End))) + (|let [(&/$Primitive "#Mutable" (&/$Item type_variance (&/$End))) mutable_type + (&/$Function write_type read_type) type_variance] + (&host/->java-sig (&/$Primitive "#Array" (&/|list read_type))))) _ (compile ?array) :let [_ (.visitTypeInsn *writer* Opcodes/CHECKCAST array-type)] :let [_ (doto *writer* diff --git a/lux-bootstrapper/src/lux/host.clj b/lux-bootstrapper/src/lux/host.clj index 7b114a772..0abba888a 100644 --- a/lux-bootstrapper/src/lux/host.clj +++ b/lux-bootstrapper/src/lux/host.clj @@ -42,13 +42,19 @@ (def ->package ->module-class) (defn unfold-array - "(-> Type (, Int Type))" + "(-> Type [Nat Type])" [type] (|case type - (&/$Primitive "#Array" (&/$Item param (&/$End))) + (&/$Primitive "#Array" (&/$Item (&/$Primitive "#Mutable" (&/$Item (&/$Function _ param) + (&/$End))) + (&/$End))) (|let [[count inner] (unfold-array param)] (&/T [(inc count) inner])) + (&/$Primitive "#Array" (&/$Item param (&/$End))) + (|let [[count inner] (unfold-array param)] + (&/T [(inc count) inner])) + _ (&/T [0 type]))) @@ -59,7 +65,8 @@ [^objects type] (|case type (&/$Primitive ?name params) - (cond (= &host-type/array-data-tag ?name) (|do [:let [[level base] (unfold-array type)] + (cond (= &host-type/array-data-tag ?name) (|do [normal_type (&type/normal type) + :let [[level base] (unfold-array normal_type)] base-sig (|case base (&/$Primitive base-class _) (return (&host-generics/->type-signature base-class)) diff --git a/lux-bootstrapper/src/lux/type.clj b/lux-bootstrapper/src/lux/type.clj index e1e229ce9..657eb3077 100644 --- a/lux-bootstrapper/src/lux/type.clj +++ b/lux-bootstrapper/src/lux/type.clj @@ -40,8 +40,7 @@ (def Text (&/$Named (&/T [&/prelude "Text"]) (&/$Primitive "#Text" &/$End))) (def Ident (&/$Named (&/T [&/prelude "Ident"]) (&/$Product Text Text))) -(defn Array [elemT] - (&/$Primitive "#Array" (&/|list elemT))) +(def Array &&host/Array) (def Nothing (&/$Named (&/T [&/prelude "Nothing"]) @@ -924,3 +923,25 @@ _ (return type))) + +(defn normal + "(-> Type Type)" + [it] + (|case it + (&/$Named _ ?it) + (normal ?it) + + (&/$Primitive ?name ?parameters) + (|do [=parameters (&/map% normal ?parameters)] + (return (&/$Primitive ?name =parameters))) + + (&/$Apply ?parameter ?abstraction) + (|do [reification (apply-type ?abstraction ?parameter)] + (normal reification)) + + (&/$Var id) + (|do [referenced (deref id)] + (normal referenced)) + + _ + (return it))) diff --git a/lux-bootstrapper/src/lux/type/host.clj b/lux-bootstrapper/src/lux/type/host.clj index 692062f50..0ea72c98f 100644 --- a/lux-bootstrapper/src/lux/type/host.clj +++ b/lux-bootstrapper/src/lux/type/host.clj @@ -64,7 +64,11 @@ (&/$Parameter 1)))) ;; [Exports] +(def mutable-data-tag "#Mutable") (def array-data-tag "#Array") +(defn Array [item] + (&/$Primitive array-data-tag (&/|list (&/$Primitive mutable-data-tag (&/|list (&/$Function item item)))))) + (def null-data-tag "#Null") (def i64-data-tag "#I64") (def nat-data-tag "#Nat") @@ -135,7 +139,7 @@ (let [base (or arr-obase simple-base (jprim->lprim arr-pbase))] (if (.equals "void" base) Any - (reduce (fn [inner _] (&/$Primitive array-data-tag (&/|list inner))) + (reduce (fn [inner _] (Array inner)) (&/$Primitive base (try (-> (Class/forName base) .getTypeParameters seq count (repeat (&/$Primitive "java.lang.Object" &/$End)) &/->list) @@ -152,7 +156,7 @@ (instance? GenericArrayType refl-type) (|do [inner-type (instance-param existential matchings (.getGenericComponentType ^GenericArrayType refl-type))] - (return (&/$Primitive array-data-tag (&/|list inner-type)))) + (return (Array inner-type))) (instance? ParameterizedType refl-type) (|do [:let [refl-type* ^ParameterizedType refl-type] @@ -183,7 +187,11 @@ (if (type= Any class-type) "V" (|case class-type - (&/$Primitive "#Array" (&/$Item (&/$Primitive class-name _) (&/$End))) + (&/$Primitive "#Array" + (&/$Item (&/$Primitive "#Mutable" + (&/$Item (&/$Function _ (&/$Primitive class-name _)) + (&/$End))) + (&/$End))) (str "[" (&host-generics/->type-signature class-name)) (&/$Primitive class-name _) @@ -211,7 +219,7 @@ (|case gtype (&/$GenericArray component-type) (|do [inner-type (instance-gtype existential matchings component-type)] - (return (&/$Primitive array-data-tag (&/|list inner-type)))) + (return (Array inner-type))) (&/$GenericClass type-name type-params) ;; When referring to type-parameters during class or method diff --git a/stdlib/source/library/lux/data/collection/array.lux b/stdlib/source/library/lux/data/collection/array.lux index 4a931cfae..eb0cf93b0 100644 --- a/stdlib/source/library/lux/data/collection/array.lux +++ b/stdlib/source/library/lux/data/collection/array.lux @@ -9,13 +9,18 @@ [predicate {"+" Predicate}]] [data [collection - ["[0]" list]]]]] + ["[0]" list]]] + [type + [variance {"+"}]]]] ["!" \\unsafe]) (def: .public type_name Text !.type) +(type: .public Array' + !.Array') + (type: .public Array !.Array) @@ -24,73 +29,73 @@ (|>> !.empty)) (def: .public size - (All (_ a) (-> (Array a) Nat)) + (All (_ r w) (-> (Array' r w) Nat)) (|>> !.size)) (def: .public (item index array) - (All (_ a) - (-> Nat (Array a) (Maybe a))) + (All (_ r w) + (-> Nat (Array' r w) (Maybe r))) (if (!.lacks? index array) {.#None} {.#Some (!.item index array)})) (def: .public (has! index value array) - (All (_ a) - (-> Nat a (Array a) (Array a))) + (All (_ r w) + (-> Nat w (Array' r w) (Array' r w))) (!.has! index value array)) (def: .public (lacks! index array) - (All (_ a) - (-> Nat (Array a) (Array a))) + (All (_ r w) + (-> Nat (Array' r w) (Array' r w))) (!.lacks! index array)) (def: .public (lacks? index array) - (All (_ a) - (-> Nat (Array a) Bit)) + (All (_ r w) + (-> Nat (Array' r w) Bit)) (!.lacks? index array)) (def: .public (has? index array) - (All (_ a) - (-> Nat (Array a) Bit)) + (All (_ r w) + (-> Nat (Array' r w) Bit)) (!.has? index array)) (def: .public (revised! index $ array) - (All (_ a) - (-> Nat (-> a a) (Array a) (Array a))) + (All (_ r w) + (-> Nat (-> r w) (Array' r w) (Array' r w))) (!.revised! index $ array)) (def: .public (upsert! index default transform array) - (All (_ a) - (-> Nat a (-> a a) (Array a) (Array a))) + (All (_ r w) + (-> Nat r (-> r w) (Array' r w) (Array' r w))) (!.upsert! index default transform array)) (def: .public (copy! length src_start src_array dest_start dest_array) - (All (_ a) - (-> Nat Nat (Array a) Nat (Array a) - (Array a))) + (All (_ r w) + (-> Nat Nat (Array' w Nothing) Nat (Array' r w) + (Array' r w))) (!.copy! length src_start src_array dest_start dest_array)) (def: .public occupancy - (All (_ a) (-> (Array a) Nat)) + (All (_ r w) (-> (Array' r w) Nat)) (|>> !.occupancy)) (def: .public vacancy - (All (_ a) (-> (Array a) Nat)) + (All (_ r w) (-> (Array' r w) Nat)) (|>> !.vacancy)) (def: .public (only! ? it) - (All (_ a) - (-> (Predicate a) (Array a) (Array a))) + (All (_ r w) + (-> (Predicate r) (Array' r w) (Array' r w))) (!.only! ? it)) (def: .public (example ? it) - (All (_ a) - (-> (Predicate a) (Array a) (Maybe a))) + (All (_ r w) + (-> (Predicate r) (Array' r w) (Maybe r))) (!.example ? it)) (def: .public (example' ? it) - (All (_ a) - (-> (-> Nat a Bit) (Array a) (Maybe [Nat a]))) + (All (_ r w) + (-> (-> Nat r Bit) (Array' r w) (Maybe [Nat r]))) (!.example' ? it)) (def: .public clone @@ -102,11 +107,11 @@ (|>> !.of_list)) (def: .public (list default array) - (All (_ a) (-> (Maybe a) (Array a) (List a))) + (All (_ r w) (-> (Maybe r) (Array' r w) (List r))) (!.list default array)) (implementation: .public (equivalence //) - (All (_ a) (-> (Equivalence a) (Equivalence (Array a)))) + (All (_ r) (-> (Equivalence r) (Equivalence (Ex (_ w) (Array' r w))))) (def: (= left/* right/*) (!.= // left/* right/*))) @@ -120,7 +125,7 @@ (!.composite left/* right/*))) (implementation: .public mix - (Mix Array) + (Mix (All (_ r) (Array' r Nothing))) (def: (mix $ init it) (!.mix (function (_ index partial total) @@ -134,17 +139,17 @@ (def: (each $ input) (!.each $ input))) -(def: .public (every? ? it) - (All (_ a) - (-> (Predicate a) (Predicate (Array a)))) - (!.every? ? it)) +(template [ ] + [(def: .public ( ? it) + (All (_ r w) + (-> (Predicate r) (Predicate (Array' r w)))) + ( ? it))] -(def: .public (any? ? it) - (All (_ a) - (-> (Predicate a) (Predicate (Array a)))) - (!.any? ? it)) + [every? !.every?] + [any? !.any?] + ) (def: .public (one ? it) - (All (_ a b) - (-> (-> a (Maybe b)) (Array a) (Maybe b))) + (All (_ r r' w) + (-> (-> r (Maybe r')) (Array' r w) (Maybe r'))) (!.one ? it)) diff --git a/stdlib/source/library/lux/ffi.jvm.lux b/stdlib/source/library/lux/ffi.jvm.lux index 2428f6bb2..2441cf387 100644 --- a/stdlib/source/library/lux/ffi.jvm.lux +++ b/stdlib/source/library/lux/ffi.jvm.lux @@ -382,8 +382,7 @@ (` {.#Primitive (~ (code.text (..reflection (jvm.array elementT)))) {.#End}}) {.#None} - (` {.#Primitive (~ (code.text array.type_name)) - {.#Item (~ (value_type elementT)) {.#End}}}))])) + (` ((~! array.Array) (~ (value_type elementT)))))])) ... else (undefined) ))) @@ -1691,8 +1690,9 @@ [jvm.double "jvm array new double"] [jvm.char "jvm array new char"])) ... else - (in (list (` (.is (~ (value_type {#ManualPrM} (jvm.array type))) - ("jvm array new object" (~ g!size)))))))))) + (in (list (` (.as ((~! array.Array) (~ (value_type {#ManualPrM} type))) + (.is (~ (value_type {#ManualPrM} (jvm.array type))) + ("jvm array new object" (~ g!size))))))))))) (exception: .public (cannot_convert_to_jvm_type [type .Type]) (exception.report @@ -1743,9 +1743,9 @@ (text#= array.type_name name) (case params - {.#Item elementLT {.#End}} + {.#Item {.#Apply writeLT {.#Apply readLT _Mutable}} {.#End}} (# meta.monad each jvm.array - (lux_type->jvm_type context elementLT)) + (lux_type->jvm_type context readLT)) _ ) diff --git a/stdlib/source/library/lux/ffi.old.lux b/stdlib/source/library/lux/ffi.old.lux index ce9e50959..32844a7d7 100644 --- a/stdlib/source/library/lux/ffi.old.lux +++ b/stdlib/source/library/lux/ffi.old.lux @@ -1727,5 +1727,5 @@ (syntax: .public (type [type (..generic_type^ (list))]) (in (list (..class_type {#ManualPrM} (list) type)))) -(template: .public (as type term) +(template: .public (is type term) [(.as type term)]) diff --git a/stdlib/source/library/lux/target/jvm/reflection.lux b/stdlib/source/library/lux/target/jvm/reflection.lux index 55b6a4185..4fe60fd37 100644 --- a/stdlib/source/library/lux/target/jvm/reflection.lux +++ b/stdlib/source/library/lux/target/jvm/reflection.lux @@ -183,8 +183,8 @@ {.#Some reflection} ... TODO: Instead of having single lower/upper bounds, should ... allow for multiple ones. - (case [(array.read! 0 (java/lang/reflect/WildcardType::getLowerBounds reflection)) - (array.read! 0 (java/lang/reflect/WildcardType::getUpperBounds reflection))] + (case [(array.item 0 (java/lang/reflect/WildcardType::getLowerBounds reflection)) + (array.item 0 (java/lang/reflect/WildcardType::getUpperBounds reflection))] (^.template [ ] [ (case (ffi.as java/lang/reflect/GenericArrayType bound) diff --git a/stdlib/source/library/lux/tool/compiler/language/lux/phase/extension/analysis/jvm.lux b/stdlib/source/library/lux/tool/compiler/language/lux/phase/extension/analysis/jvm.lux index 95915309c..6d7804b9a 100644 --- a/stdlib/source/library/lux/tool/compiler/language/lux/phase/extension/analysis/jvm.lux +++ b/stdlib/source/library/lux/tool/compiler/language/lux/phase/extension/analysis/jvm.lux @@ -65,7 +65,9 @@ ["/[1]" // "_" [generation [jvm - ["[0]" runtime]]] + ["[0]" runtime] + ["[0]" function "_" + ["[1]" abstract]]]] ["/[1]" // "_" ["[0]" generation] ["[0]" directive] @@ -387,6 +389,9 @@ [(reflection.reflection reflection.char) [box.char jvm.char]]) (dictionary.of_list text.hash))) +(template: (lux_array_type :read: :write:) + [{.#Primitive (static array.type_name) (list {.#Apply :write: {.#Apply :read: _Mutable}})}]) + (def: (jvm_type luxT) (-> .Type (Operation (Type Value))) (case luxT @@ -401,7 +406,7 @@ {.#None} (/////analysis.except ..non_jvm_type luxT)) - (pattern {.#Primitive (static array.type_name) (list elemT)}) + (pattern (lux_array_type elemT _)) (phase#each jvm.array (jvm_type elemT)) {.#Primitive class parametersT} @@ -432,6 +437,9 @@ {.#Ex _} (phase#in (jvm.class ..object_class (list))) + + {.#Function _} + (phase#in function.class) _ (/////analysis.except ..non_jvm_type luxT))) @@ -467,13 +475,16 @@ (case args (pattern (list arrayC)) (<| typeA.with_var - (function (_ [@var :var:])) + (function (_ [@read :read:])) + typeA.with_var + (function (_ [@write :write:])) (do phase.monad [_ (typeA.inference ..int) - arrayA (<| (typeA.expecting (.type (array.Array :var:))) + arrayA (<| (typeA.expecting (.type (array.Array' :read: :write:))) (analyse archive arrayC)) - :var: (typeA.check (check.clean (list) :var:)) - arrayJT (jvm_array_type (.type (array.Array :var:)))] + :read: (typeA.check (check.clean (list) :read:)) + :write: (typeA.check (check.clean (list) :write:)) + arrayJT (jvm_array_type (.type (array.Array' :read: :write:)))] (in {/////analysis.#Extension extension_name (list (/////analysis.text (..signature arrayJT)) arrayA)}))) @@ -520,8 +531,7 @@ (def: (check_parameter objectT) (-> .Type (Operation (Type Parameter))) (case objectT - (pattern {.#Primitive (static array.type_name) - (list elementT)}) + (pattern (lux_array_type elementT _)) (/////analysis.except ..non_parameter objectT) {.#Primitive name parameters} @@ -573,6 +583,9 @@ {.#None} (/////analysis.except ..non_parameter objectT)) + {.#Function _} + (phase#in function.class) + _ (/////analysis.except ..non_parameter objectT))) @@ -613,9 +626,8 @@ ... else (phase#in (jvm.class name (list))))) - - (pattern {.#Primitive (static array.type_name) - (list elementT)}) + + (pattern (lux_array_type elementT _)) (|> elementT check_jvm (phase#each jvm.array)) @@ -701,15 +713,18 @@ (case args (pattern (list idxC arrayC)) (<| typeA.with_var - (function (_ [@var :var:])) + (function (_ [@read :read:])) + typeA.with_var + (function (_ [@write :write:])) (do phase.monad - [_ (typeA.inference :var:) - arrayA (<| (typeA.expecting (.type (array.Array :var:))) + [_ (typeA.inference :read:) + arrayA (<| (typeA.expecting (.type (array.Array' :read: :write:))) (analyse archive arrayC)) - :var: (typeA.check (check.clean (list) :var:)) - arrayJT (jvm_array_type (.type (array.Array :var:))) idxA (<| (typeA.expecting ..int) - (analyse archive idxC))] + (analyse archive idxC)) + :read: (typeA.check (check.clean (list) :read:)) + :write: (typeA.check (check.clean (list) :write:)) + arrayJT (jvm_array_type (.type (array.Array' :read: :write:)))] (in {/////analysis.#Extension extension_name (list (/////analysis.text (..signature arrayJT)) idxA arrayA)}))) @@ -745,17 +760,20 @@ (case args (pattern (list idxC valueC arrayC)) (<| typeA.with_var - (function (_ [@var :var:])) + (function (_ [@read :read:])) + typeA.with_var + (function (_ [@write :write:])) (do phase.monad - [_ (typeA.inference (.type (array.Array :var:))) - arrayA (<| (typeA.expecting (.type (array.Array :var:))) + [_ (typeA.inference (.type (array.Array' :read: :write:))) + arrayA (<| (typeA.expecting (.type (array.Array' :read: :write:))) (analyse archive arrayC)) - :var: (typeA.check (check.clean (list) :var:)) - arrayJT (jvm_array_type (.type (array.Array :var:))) idxA (<| (typeA.expecting ..int) (analyse archive idxC)) - valueA (<| (typeA.expecting :var:) - (analyse archive valueC))] + valueA (<| (typeA.expecting :write:) + (analyse archive valueC)) + :read: (typeA.check (check.clean (list) :read:)) + :write: (typeA.check (check.clean (list) :write:)) + arrayJT (jvm_array_type (.type (array.Array' :read: :write:)))] (in {/////analysis.#Extension extension_name (list (/////analysis.text (..signature arrayJT)) idxA valueA diff --git a/stdlib/source/library/lux/type/variance.lux b/stdlib/source/library/lux/type/variance.lux index 00d2d931e..93f80356a 100644 --- a/stdlib/source/library/lux/type/variance.lux +++ b/stdlib/source/library/lux/type/variance.lux @@ -1,6 +1,8 @@ (.using - [library - [lux "*"]]) + [library + [lux "*" + [meta + ["[0]" symbol]]]]) (type: .public (Co it) (-> Any it)) @@ -10,3 +12,32 @@ (type: .public (In it) (-> it it)) + +(type: .public (Mutable r w) + (Primitive "#Mutable" [(-> w r)])) + +(template [ ] + [(template: .public ( it) + [((.is (.All (_ r w) ) + (.|>> .as_expected)) + it)])] + + [read (.-> (..Mutable r w) r)] + [write (.-> w (..Mutable r w))] + ) + +(type: .public (Read_Only a) + (Mutable a Nothing)) + +(type: .public (Write_Only a) + (Mutable Any a)) + +(template [ ] + [(template: .public ( it) + [((.is (.All (_ r w) ) + (.|>>)) + it)])] + + [read_only (.-> (..Mutable r w) (..Read_Only r))] + [write_only (.-> (..Mutable r w) (..Write_Only w))] + ) diff --git a/stdlib/source/unsafe/lux/data/collection/array.lux b/stdlib/source/unsafe/lux/data/collection/array.lux index e66d3ca3b..0a44efcf8 100644 --- a/stdlib/source/unsafe/lux/data/collection/array.lux +++ b/stdlib/source/unsafe/lux/data/collection/array.lux @@ -6,17 +6,23 @@ ["[0]" functor]] [data [collection - ["[0]" list]]]]]) + ["[0]" list]]] + [type + ["[0]" variance]]]]) (def: .public type "#Array") -(type: .public (Array a) - {.#Primitive ..type {.#Item a {.#End}}}) +(template [ ] + [(type: .public + {.#Primitive ..type {.#Item {.#End}}})] + + [(variance.Mutable r w) (Array' r w)] + [(variance.Mutable a a) (Array a)] + ) (with_expansions [ (.Primitive "java.lang.Long") - (.Primitive "java.lang.Object") - (.type (..Array ))] + (.Primitive "java.lang.Object")] (for @.jvm (template: (jvm_int value) [(.|> value (.as ) @@ -33,7 +39,7 @@ (~~ (.static @.jvm)) (|> (~~ (..jvm_int size)) "jvm array new object" - (.is ) + (.is (..Array )) .as_expected) (~~ (.static @.js)) ("js array new" size) @@ -45,14 +51,13 @@ )])) (`` (template: .public (size ) - [((.is (.All (_ a) (.-> (..Array a) .Nat)) + [((.is (.All (_ r w) (.-> (..Array' r w) .Nat)) (.function (size array) (.for (~~ (.static @.old)) ("jvm arraylength" array) (~~ (.static @.jvm)) (.|> array - (.as ) "jvm array length object" "jvm conversion int-to-long" "jvm object cast" @@ -71,8 +76,8 @@ [( ( index array))]) (`` (template: .public (lacks? ) - [((.is (.All (_ a) - (.-> .Nat (..Array a) .Bit)) + [((.is (.All (_ r w) + (.-> .Nat (..Array' r w) .Bit)) (.function (lacks? index array) (.let [size (..size array)] (.if ("lux i64 <" (.int size) (.int index)) @@ -81,7 +86,6 @@ (~~ (.static @.jvm)) (.|> array - (.as ) ("jvm array read object" (~~ (jvm_int index))) "jvm object null?") @@ -98,15 +102,14 @@ [(.not (..lacks? index array))]) (`` (template: .public (item ) - [((.is (.All (_ a) - (.-> .Nat (..Array a) a)) + [((.is (.All (_ r w) + (.-> .Nat (..Array' r w) r)) (.function (item index array) (.for (~~ (.static @.old)) ("jvm aaload" array index) (~~ (.static @.jvm)) (.|> array - (.as ) ("jvm array read object" (~~ (jvm_int index))) .as_expected) @@ -119,16 +122,15 @@ )])) (`` (template: .public (has! ) - [((.is (.All (_ a) - (.-> .Nat a (..Array a) (..Array a))) + [((.is (.All (_ r w) + (.-> .Nat w (..Array' r w) (..Array' r w))) (.function (has! index value array) (.for (~~ (.static @.old)) ("jvm aastore" array index value) (~~ (.static @.jvm)) (.|> array - (.as ) - ("jvm array write object" (~~ (jvm_int index)) (.as value)) + ("jvm array write object" (~~ (jvm_int index)) value) .as_expected) (~~ (.static @.js)) ("js array write" index value array) @@ -140,8 +142,8 @@ )])) (`` (template: .public (lacks! ) - [((.is (.All (_ a) - (.-> .Nat (..Array a) (..Array a))) + [((.is (.All (_ r w) + (.-> .Nat (..Array' r w) (..Array' r w))) (.function (lacks! index array) (.let [size (..size array)] (.if ("lux i64 <" (.int size) (.int index)) @@ -149,7 +151,7 @@ (..has! index (.as_expected ("jvm object null")) array) (~~ (.static @.jvm)) - (..has! index (.as_expected (is ("jvm object null"))) array) + (..has! index (.as_expected (is ("jvm object null"))) array) (~~ (.static @.js)) ("js array delete" index array) (~~ (.static @.python)) ("python array delete" index array) @@ -162,8 +164,8 @@ ) (template: .public (revised! <$> ) - [((.is (.All (_ a) - (.-> .Nat (.-> a a) (..Array a) (..Array a))) + [((.is (.All (_ r w) + (.-> .Nat (.-> r w) (..Array' r w) (..Array' r w))) (.function (revised! index $ array) (.if (..lacks? index array) array @@ -171,8 +173,8 @@ <$> )]) (template: .public (upsert! <$> ) - [((.is (.All (_ a) - (.-> .Nat a (.-> a a) (..Array a) (..Array a))) + [((.is (.All (_ r w) + (.-> .Nat r (.-> r w) (..Array' r w) (..Array' r w))) (.function (upsert! index default $ array) (..has! index ($ (.if (..lacks? index array) @@ -182,9 +184,9 @@ <$> )]) (template: .public (copy! ) - [((.is (.All (_ a) - (.-> .Nat .Nat (..Array a) .Nat (..Array a) - (..Array a))) + [((.is (.All (_ r w) + (.-> .Nat .Nat (..Array' w .Nothing) .Nat (..Array' r w) + (..Array' r w))) (.function (copy! length src_start src_array dest_start dest_array) (.loop (again [offset 0]) (.if ("lux i64 <" (.int length) (.int offset)) @@ -200,7 +202,7 @@ (template [ ] [(template: .public ( ) - [((.is (.All (_ a) (.-> (..Array a) .Nat)) + [((.is (.All (_ r w) (.-> (..Array' r w) .Nat)) (.function (occupancy array) (.let [size (..size array)] (.loop (again [index 0 @@ -217,8 +219,8 @@ ) (template: .public (only! ) - [((.is (.All (_ a) - (.-> (.-> a .Bit) (..Array a) (..Array a))) + [((.is (.All (_ r w) + (.-> (.-> r .Bit) (..Array' r w) (..Array' r w))) (.function (only! ? it) (.let [size (..size it)] (.loop (again [index 0]) @@ -235,8 +237,8 @@ (template [ ] [(template: .public ( ) - [((.is (.All (_ a) - (.-> (..Array a) (.Maybe ))) + [((.is (.All (_ r w) + (.-> (..Array' r w) (.Maybe ))) (.function ( ? it) (.let [size (..size it)] (.loop (again [index 0]) @@ -250,8 +252,8 @@ {.#None}))))) )])] - [example (.-> a .Bit) (? it) a it] - [example' (.-> Nat a .Bit) (? index it) [Nat a] [index it]] + [example (.-> r .Bit) (? it) r it] + [example' (.-> Nat r .Bit) (? index it) [Nat r] [index it]] ) (template: .public (clone ) @@ -283,7 +285,7 @@ (-- 0)) (`` (template: (list|-default ) - [((.is (.All (_ a) (.-> (.List a) (..Array a) (.List a))) + [((.is (.All (_ r w) (.-> (.List r) (..Array' r w) (.List r))) (.function (list|-default empty array) (.loop (again [index ("lux i64 -" 1 (..size array)) output empty]) @@ -296,7 +298,7 @@ )])) (`` (template: (list|+default ) - [((.is (.All (_ a) (.-> a (..Array a) (.List a))) + [((.is (.All (_ r w) (.-> r (..Array' r w) (.List r))) (.function (list|+default default array) (.loop (again [index ("lux i64 -" 1 (..size array)) output (`` (.is (.List (~~ (.these (~~ (.type_of default))))) @@ -311,7 +313,7 @@ )])) (`` (template: .public (list ) - [((.is (.All (_ a) (.-> (.Maybe a) (..Array a) (.List a))) + [((.is (.All (_ r w) (.-> (.Maybe r) (..Array' r w) (.List r))) (.function (list default array) (.case default {.#Some default} @@ -322,7 +324,7 @@ )])) (template: .public (= ) - [((.is (.All (_ a) (.-> (.-> a a .Bit) (..Array a) (..Array a) .Bit)) + [((.is (.All (_ r w0 w1) (.-> (.-> r r .Bit) (..Array' r w0) (..Array' r w1) .Bit)) (.function (= //#= left/* right/*) (.let [size (..size left/*)] (.and ("lux i64 =" (..size right/*) size) @@ -339,7 +341,7 @@ )]) (template: .public (composite ) - [((.is (.All (_ a) (.-> (..Array a) (..Array a) (..Array a))) + [((.is (.All (_ a) (.-> (..Array' a .Nothing) (..Array' a .Nothing) (..Array a))) (.function (composite left/* right/*) (.let [|left| (..size left/*) |right| (..size right/*)] @@ -349,8 +351,8 @@ )]) (template: .public (mix <$> ) - [((.is (.All (_ a b) - (.-> (.-> Nat b a a) a (..Array b) a)) + [((.is (.All (_ r w s) + (.-> (.-> Nat r s s) s (..Array' r w) s)) (.function (mix $ init it) (.let [size (..size it)] (.loop (again [index 0 @@ -373,9 +375,9 @@ (template [ ] [(template: .public ( ) - [((.is (.All (_ a) - (.-> (.-> a .Bit) - (.-> (..Array a) .Bit))) + [((.is (.All (_ r w) + (.-> (.-> r .Bit) + (.-> (..Array' r w) .Bit))) (.function ( ? it) (.let [size (..size it)] (.loop (again [index 0]) @@ -392,8 +394,8 @@ ) (template: .public (one ) - [((.is (.All (_ a b) - (.-> (.-> a (.Maybe b)) (..Array a) (.Maybe b))) + [((.is (.All (_ r r' w) + (.-> (.-> r (.Maybe r')) (..Array' r w) (.Maybe r'))) (.function (one ? it) (.let [size (..size it)] (.loop (again [index 0]) -- cgit v1.2.3