From 60daee098f92a44c3b404a9f5801f2e8126ad650 Mon Sep 17 00:00:00 2001 From: Eduardo Julian Date: Tue, 5 Apr 2022 18:32:42 -0400 Subject: No longer depending on the ASM library for JVM bytecode generation. --- .../library/lux/control/concurrency/atom.lux | 16 +++++---- .../library/lux/tool/compiler/default/platform.lux | 22 +++++------- .../lux/phase/extension/analysis/python.lux | 40 ++++++++++++++-------- stdlib/source/library/lux/world/file.lux | 2 +- stdlib/source/test/lux/target/python.lux | 6 ++-- stdlib/source/unsafe/lux/data/collection/array.lux | 30 ++++++++-------- 6 files changed, 62 insertions(+), 54 deletions(-) (limited to 'stdlib') diff --git a/stdlib/source/library/lux/control/concurrency/atom.lux b/stdlib/source/library/lux/control/concurrency/atom.lux index 08533b6a5..39207767c 100644 --- a/stdlib/source/library/lux/control/concurrency/atom.lux +++ b/stdlib/source/library/lux/control/concurrency/atom.lux @@ -44,7 +44,7 @@ (with_expansions [ (as_expected (java/util/concurrent/atomic/AtomicReference::new value))] (for @.old @.jvm - (array.has! 0 value (array.empty 1)))))) + (array.has! 0 (variance.write value) (array.empty 1)))))) (def: .public (read! atom) (All (_ r w) (-> (Atom' r w) (IO r))) @@ -63,12 +63,14 @@ (representation atom))) @.jvm (ffi.of_boolean (java/util/concurrent/atomic/AtomicReference::compareAndSet current new (representation atom))) - (let [old (array.item 0 (representation atom))] - (if (same? old current) - (exec - (array.has! 0 new (representation atom)) - true) - false))))) + (if (|> (representation atom) + (array.item 0) + variance.read + (same? current)) + (exec + (array.has! 0 (variance.write new) (representation atom)) + true) + false)))) ) (def: .public (update! f atom) diff --git a/stdlib/source/library/lux/tool/compiler/default/platform.lux b/stdlib/source/library/lux/tool/compiler/default/platform.lux index 1facd15f6..9201b9cc2 100644 --- a/stdlib/source/library/lux/tool/compiler/default/platform.lux +++ b/stdlib/source/library/lux/tool/compiler/default/platform.lux @@ -115,10 +115,8 @@ (let [system (the #&file_system platform) write_artifact! (is (-> [artifact.ID (Maybe Text) Binary] (Action Any)) (function (_ [artifact_id custom content]) - (with_expansions [ (cache/artifact.cache! system context @module artifact_id content)] - (for @.old (as (Async (Try Any)) - ) - ))))] + (is (Async (Try Any)) + (cache/artifact.cache! system context @module artifact_id content))))] (do [! ..monad] [_ (is (Async (Try Any)) (cache/module.enable! async.monad system context @module)) @@ -135,15 +133,13 @@ (is (Action (List Any))))) document (# async.monad in (document.marked? key (the [archive.#module module.#document] entry)))] - (with_expansions [ (|> [(|> entry - (the archive.#module) - (has module.#document document)) - (the archive.#registry entry)] - (_.result (..writer format)) - (cache/module.cache! system context @module))] - (for @.old (as (Async (Try Any)) - ) - ))))) + (is (Async (Try Any)) + (|> [(|> entry + (the archive.#module) + (has module.#document document)) + (the archive.#registry entry)] + (_.result (..writer format)) + (cache/module.cache! system context @module)))))) ... TODO: Inline ASAP (def: initialize_buffer! 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 f07d818d5..fa87792da 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 @@ -9,7 +9,7 @@ ["<[0]>" code {"+" Parser}]]] [data [collection - ["[0]" array {"+" Array}] + ["[0]" array] ["[0]" dictionary] ["[0]" list]]] ["[0]" type @@ -32,11 +32,13 @@ [.any (function (_ extension phase archive lengthC) (<| analysis/type.with_var - (function (_ [@var :var:])) + (function (_ [@read :read:])) + analysis/type.with_var + (function (_ [@write :write:])) (do phase.monad [lengthA (analysis/type.expecting Nat (phase archive lengthC)) - _ (analysis/type.inference (type (Array :var:)))] + _ (analysis/type.inference (type (array.Array' :read: :write:)))] (in {analysis.#Extension extension (list lengthA)}))))])) (def: array::length @@ -45,9 +47,11 @@ [.any (function (_ extension phase archive arrayC) (<| analysis/type.with_var - (function (_ [@var :var:])) + (function (_ [@read :read:])) + analysis/type.with_var + (function (_ [@write :write:])) (do phase.monad - [arrayA (analysis/type.expecting (type (Array :var:)) + [arrayA (analysis/type.expecting (type (array.Array' :read: :write:)) (phase archive arrayC)) _ (analysis/type.inference Nat)] (in {analysis.#Extension extension (list arrayA)}))))])) @@ -58,13 +62,15 @@ [(<>.and .any .any) (function (_ extension phase archive [indexC arrayC]) (<| analysis/type.with_var - (function (_ [@var :var:])) + (function (_ [@read :read:])) + analysis/type.with_var + (function (_ [@write :write:])) (do phase.monad [indexA (analysis/type.expecting Nat (phase archive indexC)) - arrayA (analysis/type.expecting (type (Array :var:)) + arrayA (analysis/type.expecting (type (array.Array' :read: :write:)) (phase archive arrayC)) - _ (analysis/type.inference :var:)] + _ (analysis/type.inference :read:)] (in {analysis.#Extension extension (list indexA arrayA)}))))])) (def: array::write @@ -73,15 +79,17 @@ [($_ <>.and .any .any .any) (function (_ extension phase archive [indexC valueC arrayC]) (<| analysis/type.with_var - (function (_ [@var :var:])) + (function (_ [@read :read:])) + analysis/type.with_var + (function (_ [@write :write:])) (do phase.monad [indexA (analysis/type.expecting Nat (phase archive indexC)) - valueA (analysis/type.expecting :var: + valueA (analysis/type.expecting :write: (phase archive valueC)) - arrayA (analysis/type.expecting (type (Array :var:)) + arrayA (analysis/type.expecting (type (array.Array' :read: :write:)) (phase archive arrayC)) - _ (analysis/type.inference (type (Array :var:)))] + _ (analysis/type.inference (type (array.Array' :read: :write:)))] (in {analysis.#Extension extension (list indexA valueA arrayA)}))))])) (def: array::delete @@ -90,13 +98,15 @@ [($_ <>.and .any .any) (function (_ extension phase archive [indexC arrayC]) (<| analysis/type.with_var - (function (_ [@var :var:])) + (function (_ [@read :read:])) + analysis/type.with_var + (function (_ [@write :write:])) (do phase.monad [indexA (analysis/type.expecting Nat (phase archive indexC)) - arrayA (analysis/type.expecting (type (Array :var:)) + arrayA (analysis/type.expecting (type (array.Array' :read: :write:)) (phase archive arrayC)) - _ (analysis/type.inference (type (Array :var:)))] + _ (analysis/type.inference (type (array.Array' :read: :write:)))] (in {analysis.#Extension extension (list indexA arrayA)}))))])) (def: bundle::array diff --git a/stdlib/source/library/lux/world/file.lux b/stdlib/source/library/lux/world/file.lux index c0c76d6de..d04f8c052 100644 --- a/stdlib/source/library/lux/world/file.lux +++ b/stdlib/source/library/lux/world/file.lux @@ -1,6 +1,6 @@ (.`` (.`` (.using [library - [lux "*" + [lux {"-" open} ["@" target] [abstract ["[0]" monad {"+" Monad do}]] diff --git a/stdlib/source/test/lux/target/python.lux b/stdlib/source/test/lux/target/python.lux index 1f53986c0..bddebfde0 100644 --- a/stdlib/source/test/lux/target/python.lux +++ b/stdlib/source/test/lux/target/python.lux @@ -22,7 +22,7 @@ ["[0]" list ("[1]#[0]" functor)]]] [macro ["[0]" code]] - ["[0]" math + [math ["[0]" random {"+" Random} ("[1]#[0]" monad)] [number ["n" nat] @@ -118,7 +118,7 @@ [/.* f.* |>] [/./ f./ |>] [/.% f.mod |>] - [/.** math.pow f.abs] + [/.** f.pow f.abs] )) (~~ (template [ ] [(_.cover [] @@ -316,7 +316,7 @@ (expression (function.constant true) (/.__import__/1 (/.string "math")))) (_.cover [/.do] - (expression (|>> (as Frac) (f.= (math.ceil float))) + (expression (|>> (as Frac) (f.= (f.ceil float))) (|> (/.__import__/1 (/.string "math")) (/.do "ceil" (list (/.float float)))))) (_.cover [/.is] diff --git a/stdlib/source/unsafe/lux/data/collection/array.lux b/stdlib/source/unsafe/lux/data/collection/array.lux index 0a44efcf8..7ad2f8a84 100644 --- a/stdlib/source/unsafe/lux/data/collection/array.lux +++ b/stdlib/source/unsafe/lux/data/collection/array.lux @@ -33,21 +33,21 @@ (`` (template: .public (empty ) [((.is (.All (_ a) (.-> .Nat (..Array a))) (.function (empty size) - (.for (~~ (.static @.old)) - (.as_expected ("jvm anewarray" "(java.lang.Object )" size)) - - (~~ (.static @.jvm)) - (|> (~~ (..jvm_int size)) - "jvm array new object" - (.is (..Array )) - .as_expected) - - (~~ (.static @.js)) ("js array new" size) - (~~ (.static @.python)) ("python array new" size) - (~~ (.static @.lua)) ("lua array new" size) - (~~ (.static @.ruby)) ("ruby array new" size) - (~~ (.static @.php)) ("php array new" size) - (~~ (.static @.scheme)) ("scheme array new" size)))) + (.as_expected + (.for (~~ (.static @.old)) + ("jvm anewarray" "(java.lang.Object )" size) + + (~~ (.static @.jvm)) + (|> (~~ (..jvm_int size)) + "jvm array new object" + (.is (..Array ))) + + (~~ (.static @.js)) ("js array new" size) + (~~ (.static @.python)) ("python array new" size) + (~~ (.static @.lua)) ("lua array new" size) + (~~ (.static @.ruby)) ("ruby array new" size) + (~~ (.static @.php)) ("php array new" size) + (~~ (.static @.scheme)) ("scheme array new" size))))) )])) (`` (template: .public (size ) -- cgit v1.2.3