diff options
Diffstat (limited to 'stdlib/source/unsafe/lux/data/collection/array.lux')
-rw-r--r-- | stdlib/source/unsafe/lux/data/collection/array.lux | 584 |
1 files changed, 292 insertions, 292 deletions
diff --git a/stdlib/source/unsafe/lux/data/collection/array.lux b/stdlib/source/unsafe/lux/data/collection/array.lux index d3435b6ee..9d82fc7dd 100644 --- a/stdlib/source/unsafe/lux/data/collection/array.lux +++ b/stdlib/source/unsafe/lux/data/collection/array.lux @@ -19,197 +19,197 @@ <array_type> (.type (..Array <elem_type>))] (for @.jvm (template: (int! value) [(.|> value - (.:as <index_type>) + (.as <index_type>) "jvm object cast" "jvm conversion long-to-int")]) (as_is)) (`` (template: .public (empty <size>) - [((.: (.All (_ a) (.-> .Nat (..Array a))) - (.function (empty size) - (.for (~~ (.static @.old)) - (.:expected ("jvm anewarray" "(java.lang.Object )" size)) - - (~~ (.static @.jvm)) - (|> (~~ (..int! size)) - "jvm array new object" - (.: <array_type>) - .: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)))) + [((.is (.All (_ a) (.-> .Nat (..Array a))) + (.function (empty size) + (.for (~~ (.static @.old)) + (.as_expected ("jvm anewarray" "(java.lang.Object )" size)) + + (~~ (.static @.jvm)) + (|> (~~ (..int! size)) + "jvm array new object" + (.is <array_type>) + .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)))) <size>)])) (`` (template: .public (size <array>) - [((.: (.All (_ a) (.-> (..Array a) .Nat)) - (.function (size array) - (.for (~~ (.static @.old)) - ("jvm arraylength" array) - - (~~ (.static @.jvm)) - (.|> array - (.:as <array_type>) - "jvm array length object" - "jvm conversion int-to-long" - "jvm object cast" - (.: <index_type>) - (.:as .Nat)) - - (~~ (.static @.js)) ("js array length" array) - (~~ (.static @.python)) ("python array length" array) - (~~ (.static @.lua)) ("lua array length" array) - (~~ (.static @.ruby)) ("ruby array length" array) - (~~ (.static @.php)) ("php array length" array) - (~~ (.static @.scheme)) ("scheme array length" array)))) + [((.is (.All (_ a) (.-> (..Array a) .Nat)) + (.function (size array) + (.for (~~ (.static @.old)) + ("jvm arraylength" array) + + (~~ (.static @.jvm)) + (.|> array + (.as <array_type>) + "jvm array length object" + "jvm conversion int-to-long" + "jvm object cast" + (.is <index_type>) + (.as .Nat)) + + (~~ (.static @.js)) ("js array length" array) + (~~ (.static @.python)) ("python array length" array) + (~~ (.static @.lua)) ("lua array length" array) + (~~ (.static @.ruby)) ("ruby array length" array) + (~~ (.static @.php)) ("php array length" array) + (~~ (.static @.scheme)) ("scheme array length" array)))) <array>)])) (template: (lacks?' <read!> <null?> index array) [(<null?> (<read!> index array))]) (`` (template: .public (lacks? <index> <array>) - [((.: (.All (_ a) - (.-> .Nat (..Array a) .Bit)) - (.function (lacks? index array) - (.let [size (..size array)] - (.if ("lux i64 <" (.int size) (.int index)) - (.for (~~ (.static @.old)) - ("jvm object null?" ("jvm aaload" array index)) - - (~~ (.static @.jvm)) - (.|> array - (.:as <array_type>) - ("jvm array read object" (~~ (int! index))) - "jvm object null?") - - (~~ (.static @.js)) (~~ (lacks?' "js array read" "js object undefined?" index array)) - (~~ (.static @.python)) (~~ (lacks?' "python array read" "python object none?" index array)) - (~~ (.static @.lua)) (~~ (lacks?' "lua array read" "lua object nil?" index array)) - (~~ (.static @.ruby)) (~~ (lacks?' "ruby array read" "ruby object nil?" index array)) - (~~ (.static @.php)) (~~ (lacks?' "php array read" "php object null?" index array)) - (~~ (.static @.scheme)) (~~ (lacks?' "scheme array read" "scheme object nil?" index array))) - .true)))) + [((.is (.All (_ a) + (.-> .Nat (..Array a) .Bit)) + (.function (lacks? index array) + (.let [size (..size array)] + (.if ("lux i64 <" (.int size) (.int index)) + (.for (~~ (.static @.old)) + ("jvm object null?" ("jvm aaload" array index)) + + (~~ (.static @.jvm)) + (.|> array + (.as <array_type>) + ("jvm array read object" (~~ (int! index))) + "jvm object null?") + + (~~ (.static @.js)) (~~ (lacks?' "js array read" "js object undefined?" index array)) + (~~ (.static @.python)) (~~ (lacks?' "python array read" "python object none?" index array)) + (~~ (.static @.lua)) (~~ (lacks?' "lua array read" "lua object nil?" index array)) + (~~ (.static @.ruby)) (~~ (lacks?' "ruby array read" "ruby object nil?" index array)) + (~~ (.static @.php)) (~~ (lacks?' "php array read" "php object null?" index array)) + (~~ (.static @.scheme)) (~~ (lacks?' "scheme array read" "scheme object nil?" index array))) + .true)))) <index> <array>)])) (template: .public (has? index array) [(.not (..lacks? index array))]) (`` (template: .public (item <index> <array>) - [((.: (.All (_ a) - (.-> .Nat (..Array a) a)) - (.function (item index array) - (.for (~~ (.static @.old)) - ("jvm aaload" array index) - - (~~ (.static @.jvm)) - (.|> array - (.:as <array_type>) - ("jvm array read object" (~~ (int! index))) - .:expected) - - (~~ (.static @.js)) ("js array read" index array) - (~~ (.static @.python)) ("python array read" index array) - (~~ (.static @.lua)) ("lua array read" index array) - (~~ (.static @.ruby)) ("ruby array read" index array) - (~~ (.static @.php)) ("php array read" index array) - (~~ (.static @.scheme)) ("scheme array read" index array)))) + [((.is (.All (_ a) + (.-> .Nat (..Array a) a)) + (.function (item index array) + (.for (~~ (.static @.old)) + ("jvm aaload" array index) + + (~~ (.static @.jvm)) + (.|> array + (.as <array_type>) + ("jvm array read object" (~~ (int! index))) + .as_expected) + + (~~ (.static @.js)) ("js array read" index array) + (~~ (.static @.python)) ("python array read" index array) + (~~ (.static @.lua)) ("lua array read" index array) + (~~ (.static @.ruby)) ("ruby array read" index array) + (~~ (.static @.php)) ("php array read" index array) + (~~ (.static @.scheme)) ("scheme array read" index array)))) <index> <array>)])) (`` (template: .public (has! <index> <value> <array>) - [((.: (.All (_ a) - (.-> .Nat a (..Array a) (..Array a))) - (.function (has! index value array) - (.for (~~ (.static @.old)) - ("jvm aastore" array index value) - - (~~ (.static @.jvm)) - (.|> array - (.:as <array_type>) - ("jvm array write object" (~~ (int! index)) (.:as <elem_type> value)) - .:expected) - - (~~ (.static @.js)) ("js array write" index value array) - (~~ (.static @.python)) ("python array write" index value array) - (~~ (.static @.lua)) ("lua array write" index value array) - (~~ (.static @.ruby)) ("ruby array write" index value array) - (~~ (.static @.php)) ("php array write" index value array) - (~~ (.static @.scheme)) ("scheme array write" index value array)))) + [((.is (.All (_ a) + (.-> .Nat a (..Array a) (..Array a))) + (.function (has! index value array) + (.for (~~ (.static @.old)) + ("jvm aastore" array index value) + + (~~ (.static @.jvm)) + (.|> array + (.as <array_type>) + ("jvm array write object" (~~ (int! index)) (.as <elem_type> value)) + .as_expected) + + (~~ (.static @.js)) ("js array write" index value array) + (~~ (.static @.python)) ("python array write" index value array) + (~~ (.static @.lua)) ("lua array write" index value array) + (~~ (.static @.ruby)) ("ruby array write" index value array) + (~~ (.static @.php)) ("php array write" index value array) + (~~ (.static @.scheme)) ("scheme array write" index value array)))) <index> <value> <array>)])) (`` (template: .public (lacks! <index> <array>) - [((.: (.All (_ a) - (.-> .Nat (..Array a) (..Array a))) - (.function (lacks! index array) - (.let [size (..size array)] - (.if ("lux i64 <" (.int size) (.int index)) - (.for (~~ (.static @.old)) - (..has! index (.:expected ("jvm object null")) array) - - (~~ (.static @.jvm)) - (..has! index (.:expected (: <elem_type> ("jvm object null"))) array) - - (~~ (.static @.js)) ("js array delete" index array) - (~~ (.static @.python)) ("python array delete" index array) - (~~ (.static @.lua)) ("lua array delete" index array) - (~~ (.static @.ruby)) ("ruby array delete" index array) - (~~ (.static @.php)) ("php array delete" index array) - (~~ (.static @.scheme)) ("scheme array delete" index array)) - array)))) + [((.is (.All (_ a) + (.-> .Nat (..Array a) (..Array a))) + (.function (lacks! index array) + (.let [size (..size array)] + (.if ("lux i64 <" (.int size) (.int index)) + (.for (~~ (.static @.old)) + (..has! index (.as_expected ("jvm object null")) array) + + (~~ (.static @.jvm)) + (..has! index (.as_expected (is <elem_type> ("jvm object null"))) array) + + (~~ (.static @.js)) ("js array delete" index array) + (~~ (.static @.python)) ("python array delete" index array) + (~~ (.static @.lua)) ("lua array delete" index array) + (~~ (.static @.ruby)) ("ruby array delete" index array) + (~~ (.static @.php)) ("php array delete" index array) + (~~ (.static @.scheme)) ("scheme array delete" index array)) + array)))) <index> <array>)])) ) (template: .public (revised! <index> <$> <array>) - [((.: (.All (_ a) - (.-> .Nat (.-> a a) (..Array a) (..Array a))) - (.function (revised! index $ array) - (.if (..lacks? index array) - array - (..has! index ($ (..item index array)) array)))) + [((.is (.All (_ a) + (.-> .Nat (.-> a a) (..Array a) (..Array a))) + (.function (revised! index $ array) + (.if (..lacks? index array) + array + (..has! index ($ (..item index array)) array)))) <index> <$> <array>)]) (template: .public (upsert! <index> <default> <$> <array>) - [((.: (.All (_ a) - (.-> .Nat a (.-> a a) (..Array a) (..Array a))) - (.function (upsert! index default $ array) - (..has! index - ($ (.if (..lacks? index array) - default - (..item index array))) - array))) + [((.is (.All (_ a) + (.-> .Nat a (.-> a a) (..Array a) (..Array a))) + (.function (upsert! index default $ array) + (..has! index + ($ (.if (..lacks? index array) + default + (..item index array))) + array))) <index> <default> <$> <array>)]) (template: .public (copy! <length> <src_start> <src_array> <dest_start> <dest_array>) - [((.: (.All (_ a) - (.-> .Nat .Nat (..Array a) .Nat (..Array a) - (..Array a))) - (.function (copy! length src_start src_array dest_start dest_array) - (.loop [offset 0] - (.if ("lux i64 <" (.int length) (.int offset)) - (.exec - (.if (..lacks? ("lux i64 +" offset src_start) src_array) - (..lacks! ("lux i64 +" offset dest_start) dest_array) - (..has! ("lux i64 +" offset dest_start) - (..item ("lux i64 +" offset src_start) src_array) - dest_array)) - (again ("lux i64 +" 1 offset))) - dest_array)))) + [((.is (.All (_ a) + (.-> .Nat .Nat (..Array a) .Nat (..Array a) + (..Array a))) + (.function (copy! length src_start src_array dest_start dest_array) + (.loop [offset 0] + (.if ("lux i64 <" (.int length) (.int offset)) + (.exec + (.if (..lacks? ("lux i64 +" offset src_start) src_array) + (..lacks! ("lux i64 +" offset dest_start) dest_array) + (..has! ("lux i64 +" offset dest_start) + (..item ("lux i64 +" offset src_start) src_array) + dest_array)) + (again ("lux i64 +" 1 offset))) + dest_array)))) <length> <src_start> <src_array> <dest_start> <dest_array>)]) (template [<name> <when_lacks> <when_has>] [(template: .public (<name> <array>) - [((.: (.All (_ a) (.-> (..Array a) .Nat)) - (.function (occupancy array) - (.let [size (..size array)] - (.loop [index 0 - it 0] - (.if ("lux i64 <" (.int size) (.int index)) - (.if (..lacks? index array) - (again ("lux i64 +" 1 index) <when_lacks>) - (again ("lux i64 +" 1 index) <when_has>)) - it))))) + [((.is (.All (_ a) (.-> (..Array a) .Nat)) + (.function (occupancy array) + (.let [size (..size array)] + (.loop [index 0 + it 0] + (.if ("lux i64 <" (.int size) (.int index)) + (.if (..lacks? index array) + (again ("lux i64 +" 1 index) <when_lacks>) + (again ("lux i64 +" 1 index) <when_has>)) + it))))) <array>)])] [occupancy it ("lux i64 +" 1 it)] @@ -217,37 +217,37 @@ ) (template: .public (only! <?> <it>) - [((.: (.All (_ a) - (.-> (.-> a .Bit) (..Array a) (..Array a))) - (.function (only! ? it) - (.let [size (..size it)] - (.loop [index 0] - (.if ("lux i64 <" (.int size) (.int index)) - (.exec - (.if (..lacks? index it) - it - (.if (? (..item index it)) - it - (..lacks! index it))) - (again ("lux i64 +" 1 index))) - it))))) + [((.is (.All (_ a) + (.-> (.-> a .Bit) (..Array a) (..Array a))) + (.function (only! ? it) + (.let [size (..size it)] + (.loop [index 0] + (.if ("lux i64 <" (.int size) (.int index)) + (.exec + (.if (..lacks? index it) + it + (.if (? (..item index it)) + it + (..lacks! index it))) + (again ("lux i64 +" 1 index))) + it))))) <?> <it>)]) (template [<name> <predicate> <test> <type> <term>] [(template: .public (<name> <?> <it>) - [((.: (.All (_ a) - (.-> <predicate> (..Array a) (.Maybe <type>))) - (.function (<name> ? it) - (.let [size (..size it)] - (.loop [index 0] - (.if ("lux i64 <" (.int size) (.int index)) - (.if (..lacks? index it) - (again ("lux i64 +" 1 index)) - (.let [it (..item index it)] - (.if <test> - {.#Some <term>} - (again ("lux i64 +" 1 index))))) - {.#None}))))) + [((.is (.All (_ a) + (.-> <predicate> (..Array a) (.Maybe <type>))) + (.function (<name> ? it) + (.let [size (..size it)] + (.loop [index 0] + (.if ("lux i64 <" (.int size) (.int index)) + (.if (..lacks? index it) + (again ("lux i64 +" 1 index)) + (.let [it (..item index it)] + (.if <test> + {.#Some <term>} + (again ("lux i64 +" 1 index))))) + {.#None}))))) <?> <it>)])] [example (.-> a .Bit) (? it) a it] @@ -255,27 +255,27 @@ ) (template: .public (clone <it>) - [((.: (.All (_ a) (.-> (..Array a) (..Array a))) - (.function (clone it) - (.let [size (..size it)] - (..copy! size 0 it 0 (..empty size))))) + [((.is (.All (_ a) (.-> (..Array a) (..Array a))) + (.function (clone it) + (.let [size (..size it)] + (..copy! size 0 it 0 (..empty size))))) <it>)]) (template: .public (of_list <input>) - [((.: (.All (_ a) (.-> (.List a) (..Array a))) - (.function (of_list input) - (.let [size (list.size input) - output (..empty size)] - (.loop [index 0 - input input] - (.case input - {.#End} - output - - {.#Item head tail} - (.exec - (..has! index head output) - (again ("lux i64 +" 1 index) tail))))))) + [((.is (.All (_ a) (.-> (.List a) (..Array a))) + (.function (of_list input) + (.let [size (list.size input) + output (..empty size)] + (.loop [index 0 + input input] + (.case input + {.#End} + output + + {.#Item head tail} + (.exec + (..has! index head output) + (again ("lux i64 +" 1 index) tail))))))) <input>)]) (def: underflow @@ -283,108 +283,108 @@ (-- 0)) (`` (template: (list|-default <empty> <array>) - [((.: (.All (_ a) (.-> (.List a) (..Array a) (.List a))) - (.function (list|-default empty array) - (.loop [index ("lux i64 -" 1 (..size array)) - output empty] - (.if ("lux i64 =" (~~ (.static ..underflow)) index) - output - (again ("lux i64 -" 1 index) - (.if (..lacks? index array) - output - {.#Item (..item index array) output})))))) + [((.is (.All (_ a) (.-> (.List a) (..Array a) (.List a))) + (.function (list|-default empty array) + (.loop [index ("lux i64 -" 1 (..size array)) + output empty] + (.if ("lux i64 =" (~~ (.static ..underflow)) index) + output + (again ("lux i64 -" 1 index) + (.if (..lacks? index array) + output + {.#Item (..item index array) output})))))) <empty> <array>)])) (`` (template: (list|+default <default> <array>) - [((.: (.All (_ a) (.-> a (..Array a) (.List a))) - (.function (list|+default default array) - (.loop [index ("lux i64 -" 1 (..size array)) - output (`` (.: (.List (~~ (.as_is (~~ (.:of default))))) - {.#End}))] - (.if ("lux i64 =" (~~ (.static ..underflow)) index) - output - (again ("lux i64 -" 1 index) - {.#Item (.if (..lacks? index array) - default - (..item index array)) - output}))))) + [((.is (.All (_ a) (.-> a (..Array a) (.List a))) + (.function (list|+default default array) + (.loop [index ("lux i64 -" 1 (..size array)) + output (`` (.is (.List (~~ (.as_is (~~ (.type_of default))))) + {.#End}))] + (.if ("lux i64 =" (~~ (.static ..underflow)) index) + output + (again ("lux i64 -" 1 index) + {.#Item (.if (..lacks? index array) + default + (..item index array)) + output}))))) <default> <array>)])) (`` (template: .public (list <default> <array>) - [((.: (.All (_ a) (.-> (.Maybe a) (..Array a) (.List a))) - (.function (list default array) - (.case default - {.#Some default} - (~~ (..list|+default default array)) - - {.#None} - (~~ (..list|-default {.#End} array))))) + [((.is (.All (_ a) (.-> (.Maybe a) (..Array a) (.List a))) + (.function (list default array) + (.case default + {.#Some default} + (~~ (..list|+default default array)) + + {.#None} + (~~ (..list|-default {.#End} array))))) <default> <array>)])) (template: .public (= <//#=> <left/*> <right/*>) - [((.: (.All (_ a) (.-> (.-> a a .Bit) (..Array a) (..Array a) .Bit)) - (.function (= //#= left/* right/*) - (.let [size (..size left/*)] - (.and ("lux i64 =" (..size right/*) size) - (.loop [index 0] - (.if ("lux i64 <" (.int size) (.int index)) - (.if (..lacks? index left/*) - (..lacks? index right/*) - (.if (..lacks? index right/*) - .false - (.and (//#= (..item index left/*) - (..item index right/*)) - (again ("lux i64 +" 1 index))))) - true)))))) + [((.is (.All (_ a) (.-> (.-> a a .Bit) (..Array a) (..Array a) .Bit)) + (.function (= //#= left/* right/*) + (.let [size (..size left/*)] + (.and ("lux i64 =" (..size right/*) size) + (.loop [index 0] + (.if ("lux i64 <" (.int size) (.int index)) + (.if (..lacks? index left/*) + (..lacks? index right/*) + (.if (..lacks? index right/*) + .false + (.and (//#= (..item index left/*) + (..item index right/*)) + (again ("lux i64 +" 1 index))))) + true)))))) <//#=> <left/*> <right/*>)]) (template: .public (composite <left/*> <right/*>) - [((.: (.All (_ a) (.-> (..Array a) (..Array a) (..Array a))) - (.function (composite left/* right/*) - (.let [|left| (..size left/*) - |right| (..size right/*)] - (.|> (..empty ("lux i64 +" |left| |right|)) - (..copy! |left| 0 left/* 0) - (..copy! |right| 0 right/* |left|))))) + [((.is (.All (_ a) (.-> (..Array a) (..Array a) (..Array a))) + (.function (composite left/* right/*) + (.let [|left| (..size left/*) + |right| (..size right/*)] + (.|> (..empty ("lux i64 +" |left| |right|)) + (..copy! |left| 0 left/* 0) + (..copy! |right| 0 right/* |left|))))) <left/*> <right/*>)]) (template: .public (mix <$> <init> <it>) - [((.: (.All (_ a b) - (.-> (.-> Nat b a a) a (..Array b) a)) - (.function (mix $ init it) - (.let [size (..size it)] - (.loop [index 0 - so_far init] - (.if ("lux i64 <" (.int size) (.int index)) - (.if (..lacks? index it) - (again ("lux i64 +" 1 index) so_far) - (again ("lux i64 +" 1 index) ($ index (..item index it) so_far))) - so_far))))) + [((.is (.All (_ a b) + (.-> (.-> Nat b a a) a (..Array b) a)) + (.function (mix $ init it) + (.let [size (..size it)] + (.loop [index 0 + so_far init] + (.if ("lux i64 <" (.int size) (.int index)) + (.if (..lacks? index it) + (again ("lux i64 +" 1 index) so_far) + (again ("lux i64 +" 1 index) ($ index (..item index it) so_far))) + so_far))))) <$> <init> <it>)]) (template: .public (each <$> <input>) - [((.: (functor.Functor ..Array) - (.function (each $ input) - (..mix (.function (_ index item output) - (..has! index ($ item) output)) - (..empty (..size input)) - input))) + [((.is (functor.Functor ..Array) + (.function (each $ input) + (..mix (.function (_ index item output) + (..has! index ($ item) output)) + (..empty (..size input)) + input))) <$> <input>)]) (template [<name> <init> <op>] [(template: .public (<name> <?> <it>) - [((.: (.All (_ a) - (.-> (.-> a .Bit) - (.-> (..Array a) .Bit))) - (.function (<name> ? it) - (.let [size (..size it)] - (.loop [index 0] - (.if ("lux i64 <" (.int size) (.int index)) - (.if (..lacks? index it) - (again ("lux i64 +" 1 index)) - (<op> (? (..item index it)) - (again ("lux i64 +" 1 index)))) - <init>))))) + [((.is (.All (_ a) + (.-> (.-> a .Bit) + (.-> (..Array a) .Bit))) + (.function (<name> ? it) + (.let [size (..size it)] + (.loop [index 0] + (.if ("lux i64 <" (.int size) (.int index)) + (.if (..lacks? index it) + (again ("lux i64 +" 1 index)) + (<op> (? (..item index it)) + (again ("lux i64 +" 1 index)))) + <init>))))) <?> <it>)])] [every? .true and] @@ -392,20 +392,20 @@ ) (template: .public (one <?> <it>) - [((.: (.All (_ a b) - (.-> (.-> a (.Maybe b)) (..Array a) (.Maybe b))) - (.function (one ? it) - (.let [size (..size it)] - (.loop [index 0] - (.if ("lux i64 <" (.int size) (.int index)) - (with_expansions [<again> (again ("lux i64 +" 1 index))] - (.if (..lacks? index it) - <again> - (.case (? (..item index it)) - {.#None} - <again> - - output - output))) - {.#None}))))) + [((.is (.All (_ a b) + (.-> (.-> a (.Maybe b)) (..Array a) (.Maybe b))) + (.function (one ? it) + (.let [size (..size it)] + (.loop [index 0] + (.if ("lux i64 <" (.int size) (.int index)) + (with_expansions [<again> (again ("lux i64 +" 1 index))] + (.if (..lacks? index it) + <again> + (.case (? (..item index it)) + {.#None} + <again> + + output + output))) + {.#None}))))) <?> <it>)]) |