aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source/unsafe
diff options
context:
space:
mode:
authorEduardo Julian2022-03-14 06:14:57 -0400
committerEduardo Julian2022-03-14 06:14:57 -0400
commit4965597043aca57a05760113f1851e96dad1eaf8 (patch)
tree8126d3e6394e38bc52918eea95a67546350bb95e /stdlib/source/unsafe
parentcfd438517a46e025b15345e3570b02f5ea6165c0 (diff)
Leaner syntax for the "for" macro.
Diffstat (limited to 'stdlib/source/unsafe')
-rw-r--r--stdlib/source/unsafe/lux/data/binary.lux244
-rw-r--r--stdlib/source/unsafe/lux/data/collection/array.lux191
2 files changed, 217 insertions, 218 deletions
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>)
- @.jvm (as_is <jvm>)
-
- @.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>)
+ @.jvm (as_is <jvm>)
+
+ @.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 @@
<jvm> (.: ..Binary <jvm>)]
(template: .public (empty size)
[(: ..Binary
- (for [(~~ (.static @.old)) <jvm>
- (~~ (.static @.jvm)) <jvm>
-
- (~~ (.static @.js))
- (.|> <size>
- .int
- "lux i64 f64"
- []
- ("js object new" ("js constant" "ArrayBuffer"))
- []
- ("js object new" ("js constant" "Uint8Array"))
- (.:as ..Binary))
-
- (~~ (.static @.python))
- (.|> <size>
- []
- ("python apply" (.:as ffi.Function ("python constant" "bytearray")))
- (.:as ..Binary))
-
- (~~ (.static @.scheme))
- (..make-bytevector <size>)]
+ (for (~~ (.static @.old)) <jvm>
+ (~~ (.static @.jvm)) <jvm>
+
+ (~~ (.static @.js))
+ (.|> <size>
+ .int
+ "lux i64 f64"
+ []
+ ("js object new" ("js constant" "ArrayBuffer"))
+ []
+ ("js object new" ("js constant" "Uint8Array"))
+ (.:as ..Binary))
+
+ (~~ (.static @.python))
+ (.|> <size>
+ []
+ ("python apply" (.:as ffi.Function ("python constant" "bytearray")))
+ (.:as ..Binary))
+
+ (~~ (.static @.scheme))
+ (..make-bytevector <size>)
... Default
(array.empty <size>)))])))
@@ -90,23 +90,23 @@
<jvm> (ffi.length <it>)]
(template: .public (size it)
[(.: .Nat
- (.for [(~~ (.static @.old)) <jvm>
- (~~ (.static @.jvm)) <jvm>
+ (.for (~~ (.static @.old)) <jvm>
+ (~~ (.static @.jvm)) <jvm>
- (~~ (.static @.js))
- (.|> <it>
- ("js object get" "length")
- (.:as .Frac)
- "lux f64 i64"
- .nat)
+ (~~ (.static @.js))
+ (.|> <it>
+ ("js object get" "length")
+ (.:as .Frac)
+ "lux f64 i64"
+ .nat)
- (~~ (.static @.python))
- (.|> <it>
- (.:as (array.Array (.I64 .Any)))
- "python array length")
+ (~~ (.static @.python))
+ (.|> <it>
+ (.:as (array.Array (.I64 .Any)))
+ "python array length")
- (~~ (.static @.scheme))
- (..bytevector-length [<it>])]
+ (~~ (.static @.scheme))
+ (..bytevector-length [<it>])
... Default
(array.size <it>)))])))
@@ -126,23 +126,23 @@
(template: .public (bytes/1 index it)
[(.<| (.:as .I64)
(.: (.I64 .Any))
- (`` (.for [(~~ (.static @.old)) (~~ <jvm>)
- (~~ (.static @.jvm)) (~~ <jvm>)
+ (`` (.for (~~ (.static @.old)) (~~ <jvm>)
+ (~~ (.static @.jvm)) (~~ <jvm>)
- (~~ (.static @.js))
- (.|> <it>
- (.:as (array.Array .Frac))
- ("js array read" <index>)
- "lux f64 i64"
- .i64)
+ (~~ (.static @.js))
+ (.|> <it>
+ (.:as (array.Array .Frac))
+ ("js array read" <index>)
+ "lux f64 i64"
+ .i64)
- (~~ (.static @.python))
- (.|> <it>
- (.:as (array.Array .I64))
- ("python array read" <index>))
+ (~~ (.static @.python))
+ (.|> <it>
+ (.:as (array.Array .I64))
+ ("python array read" <index>))
- (~~ (.static @.scheme))
- (..bytevector-u8-ref [<it> <index>])]
+ (~~ (.static @.scheme))
+ (..bytevector-u8-ref [<it> <index>])
... Default
(.if (array.lacks? <index> <it>)
@@ -188,43 +188,43 @@
<it> (.: ..Binary it)
<index> (.: .Nat index)
<value> (.: (.I64 .Any) value)
- <jvm_value> (`` (.for [(~~ (.static @.old))
- (.:as .Int <value>)
+ <jvm_value> (`` (.for (~~ (.static @.old))
+ (.:as .Int <value>)
- (~~ (.static @.jvm))
- (.:as (.Primitive "java.lang.Long") <value>)]
+ (~~ (.static @.jvm))
+ (.:as (.Primitive "java.lang.Long") <value>)
<value>))
<jvm_value> <jvm_value>
<jvm_value> (ffi.long_to_byte <jvm_value>)
<jvm> (ffi.write! <index> <jvm_value> <it>)]
(`` (template: .public (with/1! index value it)
[(.: ..Binary
- (.for [(~~ (.static @.old)) <jvm>
- (~~ (.static @.jvm)) <jvm>
-
- (~~ (.static @.js))
- (.|> <it>
- (.: ..Binary)
- (.:as (array.Array .Frac))
- ("js array write" <index>
- (.|> <value>
- .int
- ("lux i64 and" (.int <byte>))
- "lux i64 f64"))
- (.:as ..Binary))
-
- (~~ (.static @.python))
- (.|> <it>
- (.: ..Binary)
- (.:as (array.Array (.I64 .Any)))
- ("python array write" <index> (.|> <value> ("lux i64 and" <byte>) (.: (.I64 .Any))))
- (.:as ..Binary))
-
- (~~ (.static @.scheme))
- (.let [it' <it>]
- (.exec
- (..bytevector-u8-set! [it' <index> <value>])
- it'))]
+ (.for (~~ (.static @.old)) <jvm>
+ (~~ (.static @.jvm)) <jvm>
+
+ (~~ (.static @.js))
+ (.|> <it>
+ (.: ..Binary)
+ (.:as (array.Array .Frac))
+ ("js array write" <index>
+ (.|> <value>
+ .int
+ ("lux i64 and" (.int <byte>))
+ "lux i64 f64"))
+ (.:as ..Binary))
+
+ (~~ (.static @.python))
+ (.|> <it>
+ (.: ..Binary)
+ (.:as (array.Array (.I64 .Any)))
+ ("python array write" <index> (.|> <value> ("lux i64 and" <byte>) (.: (.I64 .Any))))
+ (.:as ..Binary))
+
+ (~~ (.static @.scheme))
+ (.let [it' <it>]
+ (.exec
+ (..bytevector-u8-set! [it' <index> <value>])
+ it'))
... Default
(array.has! <index> (.|> <value> .int ("lux i64 and" (.int <byte>))) <it>)))])))
@@ -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 @@
<jvm> (java/util/Arrays::equals <reference> <sample>)
<jvm> (ffi.of_boolean <jvm>)]
(`` (template: .public (= reference' sample')
- [(.for [(~~ (.static @.old)) <jvm>
- (~~ (.static @.jvm)) <jvm>]
+ [(.for (~~ (.static @.old)) <jvm>
+ (~~ (.static @.jvm)) <jvm>
(.let [reference <reference>
sample <sample>
limit (..size reference)]
@@ -299,8 +299,8 @@
<jvm> (.exec
<jvm>
target)]
- (.for [(~~ (.static @.old)) <jvm>
- (~~ (.static @.jvm)) <jvm>]
+ (.for (~~ (.static @.old)) <jvm>
+ (~~ (.static @.jvm)) <jvm>
... Default
(.loop [index 0]
@@ -320,8 +320,8 @@
<jvm>)]
(inline: .public (slice offset size binary)
(-> .Nat .Nat ..Binary ..Binary)
- (.for [(~~ (.static @.old)) <jvm>
- (~~ (.static @.jvm)) <jvm>]
+ (.for (~~ (.static @.old)) <jvm>
+ (~~ (.static @.jvm)) <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 [<index_type> (.Primitive "java.lang.Long")
<elem_type> (.Primitive "java.lang.Object")
<array_type> (.type (..Array <elem_type>))]
- (for [@.jvm
- (template: (int! value)
- [(.|> value
- (.:as <index_type>)
- "jvm object cast"
- "jvm conversion long-to-int")])]
+ (for @.jvm (template: (int! value)
+ [(.|> value
+ (.: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)])))
+ (.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))))
<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)])))
+ (.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))))
<array>)]))
(template: (lacks?' <read!> <null?> 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 <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))])
+ (.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>)]))
@@ -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 <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)])))
+ (.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))))
<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)])))
+ (.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))))
<index> <value> <array>)]))
(`` (template: .public (lacks! <index> <array>)
@@ -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 (: <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)])
+ (.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))))
<index> <array>)]))
)