From 4965597043aca57a05760113f1851e96dad1eaf8 Mon Sep 17 00:00:00 2001 From: Eduardo Julian Date: Mon, 14 Mar 2022 06:14:57 -0400 Subject: Leaner syntax for the "for" macro. --- stdlib/source/unsafe/lux/data/binary.lux | 244 ++++++++++----------- stdlib/source/unsafe/lux/data/collection/array.lux | 191 ++++++++-------- 2 files changed, 217 insertions(+), 218 deletions(-) (limited to 'stdlib/source/unsafe') diff --git a/stdlib/source/unsafe/lux/data/binary.lux b/stdlib/source/unsafe/lux/data/binary.lux index 1e3ef2118..e7936fd06 100644 --- a/stdlib/source/unsafe/lux/data/binary.lux +++ b/stdlib/source/unsafe/lux/data/binary.lux @@ -27,30 +27,30 @@ ["[1]::[0]" ("static" copyOfRange [[byte] int int] [byte]) ("static" equals [[byte] [byte]] boolean)]))] - (for [@.old (as_is ) - @.jvm (as_is ) - - @.js - (as_is (ffi.import: ArrayBuffer - "[1]::[0]") - (ffi.import: Uint8Array - "[1]::[0]") - - (type: .public Binary - Uint8Array)) - - @.python - (type: .public Binary - (Primitive "bytearray")) - - @.scheme - (as_is (type: .public Binary - (Primitive "bytevector")) - - (ffi.import: (make-bytevector [Nat] Binary)) - (ffi.import: (bytevector-u8-ref [Binary Nat] I64)) - (ffi.import: (bytevector-u8-set! [Binary Nat (I64 Any)] Any)) - (ffi.import: (bytevector-length [Binary] Nat)))] + (for @.old (as_is ) + @.jvm (as_is ) + + @.js + (as_is (ffi.import: ArrayBuffer + "[1]::[0]") + (ffi.import: Uint8Array + "[1]::[0]") + + (type: .public Binary + Uint8Array)) + + @.python + (type: .public Binary + (Primitive "bytearray")) + + @.scheme + (as_is (type: .public Binary + (Primitive "bytevector")) + + (ffi.import: (make-bytevector [Nat] Binary)) + (ffi.import: (bytevector-u8-ref [Binary Nat] I64)) + (ffi.import: (bytevector-u8-set! [Binary Nat (I64 Any)] Any)) + (ffi.import: (bytevector-length [Binary] Nat))) ... Default (type: .public Binary @@ -61,27 +61,27 @@ (.: ..Binary )] (template: .public (empty size) [(: ..Binary - (for [(~~ (.static @.old)) - (~~ (.static @.jvm)) - - (~~ (.static @.js)) - (.|> - .int - "lux i64 f64" - [] - ("js object new" ("js constant" "ArrayBuffer")) - [] - ("js object new" ("js constant" "Uint8Array")) - (.:as ..Binary)) - - (~~ (.static @.python)) - (.|> - [] - ("python apply" (.:as ffi.Function ("python constant" "bytearray"))) - (.:as ..Binary)) - - (~~ (.static @.scheme)) - (..make-bytevector )] + (for (~~ (.static @.old)) + (~~ (.static @.jvm)) + + (~~ (.static @.js)) + (.|> + .int + "lux i64 f64" + [] + ("js object new" ("js constant" "ArrayBuffer")) + [] + ("js object new" ("js constant" "Uint8Array")) + (.:as ..Binary)) + + (~~ (.static @.python)) + (.|> + [] + ("python apply" (.:as ffi.Function ("python constant" "bytearray"))) + (.:as ..Binary)) + + (~~ (.static @.scheme)) + (..make-bytevector ) ... Default (array.empty )))]))) @@ -90,23 +90,23 @@ (ffi.length )] (template: .public (size it) [(.: .Nat - (.for [(~~ (.static @.old)) - (~~ (.static @.jvm)) + (.for (~~ (.static @.old)) + (~~ (.static @.jvm)) - (~~ (.static @.js)) - (.|> - ("js object get" "length") - (.:as .Frac) - "lux f64 i64" - .nat) + (~~ (.static @.js)) + (.|> + ("js object get" "length") + (.:as .Frac) + "lux f64 i64" + .nat) - (~~ (.static @.python)) - (.|> - (.:as (array.Array (.I64 .Any))) - "python array length") + (~~ (.static @.python)) + (.|> + (.:as (array.Array (.I64 .Any))) + "python array length") - (~~ (.static @.scheme)) - (..bytevector-length [])] + (~~ (.static @.scheme)) + (..bytevector-length []) ... Default (array.size )))]))) @@ -126,23 +126,23 @@ (template: .public (bytes/1 index it) [(.<| (.:as .I64) (.: (.I64 .Any)) - (`` (.for [(~~ (.static @.old)) (~~ ) - (~~ (.static @.jvm)) (~~ ) + (`` (.for (~~ (.static @.old)) (~~ ) + (~~ (.static @.jvm)) (~~ ) - (~~ (.static @.js)) - (.|> - (.:as (array.Array .Frac)) - ("js array read" ) - "lux f64 i64" - .i64) + (~~ (.static @.js)) + (.|> + (.:as (array.Array .Frac)) + ("js array read" ) + "lux f64 i64" + .i64) - (~~ (.static @.python)) - (.|> - (.:as (array.Array .I64)) - ("python array read" )) + (~~ (.static @.python)) + (.|> + (.:as (array.Array .I64)) + ("python array read" )) - (~~ (.static @.scheme)) - (..bytevector-u8-ref [ ])] + (~~ (.static @.scheme)) + (..bytevector-u8-ref [ ]) ... Default (.if (array.lacks? ) @@ -188,43 +188,43 @@ (.: ..Binary it) (.: .Nat index) (.: (.I64 .Any) value) - (`` (.for [(~~ (.static @.old)) - (.:as .Int ) + (`` (.for (~~ (.static @.old)) + (.:as .Int ) - (~~ (.static @.jvm)) - (.:as (.Primitive "java.lang.Long") )] + (~~ (.static @.jvm)) + (.:as (.Primitive "java.lang.Long") ) )) (ffi.long_to_byte ) (ffi.write! )] (`` (template: .public (with/1! index value it) [(.: ..Binary - (.for [(~~ (.static @.old)) - (~~ (.static @.jvm)) - - (~~ (.static @.js)) - (.|> - (.: ..Binary) - (.:as (array.Array .Frac)) - ("js array write" - (.|> - .int - ("lux i64 and" (.int )) - "lux i64 f64")) - (.:as ..Binary)) - - (~~ (.static @.python)) - (.|> - (.: ..Binary) - (.:as (array.Array (.I64 .Any))) - ("python array write" (.|> ("lux i64 and" ) (.: (.I64 .Any)))) - (.:as ..Binary)) - - (~~ (.static @.scheme)) - (.let [it' ] - (.exec - (..bytevector-u8-set! [it' ]) - it'))] + (.for (~~ (.static @.old)) + (~~ (.static @.jvm)) + + (~~ (.static @.js)) + (.|> + (.: ..Binary) + (.:as (array.Array .Frac)) + ("js array write" + (.|> + .int + ("lux i64 and" (.int )) + "lux i64 f64")) + (.:as ..Binary)) + + (~~ (.static @.python)) + (.|> + (.: ..Binary) + (.:as (array.Array (.I64 .Any))) + ("python array write" (.|> ("lux i64 and" ) (.: (.I64 .Any)))) + (.:as ..Binary)) + + (~~ (.static @.scheme)) + (.let [it' ] + (.exec + (..bytevector-u8-set! [it' ]) + it')) ... Default (array.has! (.|> .int ("lux i64 and" (.int ))) )))]))) @@ -248,19 +248,19 @@ (`` (template: .public (with/8! index' value' it) [(.let [index (.: .Nat index') value (.: (.I64 .Any) value')] - (.for [(~~ (.static @.scheme)) (.let [write_high (.: (.-> ..Binary ..Binary) - (.|>> (..with/1! index ("lux i64 right-shift" 56 value)) - (..with/1! ("lux i64 +" 1 index) ("lux i64 right-shift" 48 value)) - (..with/1! ("lux i64 +" 2 index) ("lux i64 right-shift" 40 value)) - (..with/1! ("lux i64 +" 3 index) ("lux i64 right-shift" 32 value)))) - write_low (.: (.-> ..Binary ..Binary) - (.|>> (..with/1! ("lux i64 +" 4 index) ("lux i64 right-shift" 24 value)) - (..with/1! ("lux i64 +" 5 index) ("lux i64 right-shift" 16 value)) - (..with/1! ("lux i64 +" 6 index) ("lux i64 right-shift" 8 value)) - (..with/1! ("lux i64 +" 7 index) value)))] - (.|> it - write_high - write_low))] + (.for (~~ (.static @.scheme)) (.let [write_high (.: (.-> ..Binary ..Binary) + (.|>> (..with/1! index ("lux i64 right-shift" 56 value)) + (..with/1! ("lux i64 +" 1 index) ("lux i64 right-shift" 48 value)) + (..with/1! ("lux i64 +" 2 index) ("lux i64 right-shift" 40 value)) + (..with/1! ("lux i64 +" 3 index) ("lux i64 right-shift" 32 value)))) + write_low (.: (.-> ..Binary ..Binary) + (.|>> (..with/1! ("lux i64 +" 4 index) ("lux i64 right-shift" 24 value)) + (..with/1! ("lux i64 +" 5 index) ("lux i64 right-shift" 16 value)) + (..with/1! ("lux i64 +" 6 index) ("lux i64 right-shift" 8 value)) + (..with/1! ("lux i64 +" 7 index) value)))] + (.|> it + write_high + write_low)) (.|> it (..with/1! index ("lux i64 right-shift" 56 value)) (..with/1! ("lux i64 +" 1 index) ("lux i64 right-shift" 48 value)) @@ -276,8 +276,8 @@ (java/util/Arrays::equals ) (ffi.of_boolean )] (`` (template: .public (= reference' sample') - [(.for [(~~ (.static @.old)) - (~~ (.static @.jvm)) ] + [(.for (~~ (.static @.old)) + (~~ (.static @.jvm)) (.let [reference sample limit (..size reference)] @@ -299,8 +299,8 @@ (.exec target)] - (.for [(~~ (.static @.old)) - (~~ (.static @.jvm)) ] + (.for (~~ (.static @.old)) + (~~ (.static @.jvm)) ... Default (.loop [index 0] @@ -320,8 +320,8 @@ )] (inline: .public (slice offset size binary) (-> .Nat .Nat ..Binary ..Binary) - (.for [(~~ (.static @.old)) - (~~ (.static @.jvm)) ] + (.for (~~ (.static @.old)) + (~~ (.static @.jvm)) ... Default (..copy! size offset binary 0 (..empty size)))))) diff --git a/stdlib/source/unsafe/lux/data/collection/array.lux b/stdlib/source/unsafe/lux/data/collection/array.lux index 83b7e5202..d3435b6ee 100644 --- a/stdlib/source/unsafe/lux/data/collection/array.lux +++ b/stdlib/source/unsafe/lux/data/collection/array.lux @@ -17,55 +17,54 @@ (with_expansions [ (.Primitive "java.lang.Long") (.Primitive "java.lang.Object") (.type (..Array ))] - (for [@.jvm - (template: (int! value) - [(.|> value - (.:as ) - "jvm object cast" - "jvm conversion long-to-int")])] + (for @.jvm (template: (int! value) + [(.|> value + (.:as ) + "jvm object cast" + "jvm conversion long-to-int")]) (as_is)) (`` (template: .public (empty ) [((.: (.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" - (.: ) - .: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)]))) + (.for (~~ (.static @.old)) + (.:expected ("jvm anewarray" "(java.lang.Object )" size)) + + (~~ (.static @.jvm)) + (|> (~~ (..int! size)) + "jvm array new object" + (.: ) + .: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)))) )])) (`` (template: .public (size ) [((.: (.All (_ a) (.-> (..Array a) .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" - (.: ) - (.: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)]))) + (.for (~~ (.static @.old)) + ("jvm arraylength" array) + + (~~ (.static @.jvm)) + (.|> array + (.:as ) + "jvm array length object" + "jvm conversion int-to-long" + "jvm object cast" + (.: ) + (.: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)))) )])) (template: (lacks?' index array) @@ -77,21 +76,21 @@ (.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 ) - ("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))]) + (.for (~~ (.static @.old)) + ("jvm object null?" ("jvm aaload" array index)) + + (~~ (.static @.jvm)) + (.|> array + (.:as ) + ("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)))) )])) @@ -102,42 +101,42 @@ [((.: (.All (_ a) (.-> .Nat (..Array a) a)) (.function (item index array) - (.for [(~~ (.static @.old)) - ("jvm aaload" array index) - - (~~ (.static @.jvm)) - (.|> array - (.:as ) - ("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)]))) + (.for (~~ (.static @.old)) + ("jvm aaload" array index) + + (~~ (.static @.jvm)) + (.|> array + (.:as ) + ("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)))) )])) (`` (template: .public (has! ) [((.: (.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 ) - ("jvm array write object" (~~ (int! index)) (.:as 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)]))) + (.for (~~ (.static @.old)) + ("jvm aastore" array index value) + + (~~ (.static @.jvm)) + (.|> array + (.:as ) + ("jvm array write object" (~~ (int! index)) (.:as 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)))) )])) (`` (template: .public (lacks! ) @@ -146,18 +145,18 @@ (.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 (: ("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)]) + (.for (~~ (.static @.old)) + (..has! index (.:expected ("jvm object null")) array) + + (~~ (.static @.jvm)) + (..has! index (.:expected (: ("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)))) )])) ) -- cgit v1.2.3