From b68f2b6aead6224c14902c80fc00c27705eece6c Mon Sep 17 00:00:00 2001 From: Eduardo Julian Date: Wed, 16 Feb 2022 02:32:09 -0400 Subject: FIXED generating artifact IDs in the context of "lux in-module". --- stdlib/source/unsafe/lux/data/binary.lux | 243 ++++++++++++++++--------------- 1 file changed, 126 insertions(+), 117 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 868dd82f3..d91893c38 100644 --- a/stdlib/source/unsafe/lux/data/binary.lux +++ b/stdlib/source/unsafe/lux/data/binary.lux @@ -59,12 +59,11 @@ (type: .public Binary (array.Array (I64 Any))))) -(template: .public (empty size) - [(with_expansions [ (: Nat size) - (|> - (ffi.array byte) - (: ..Binary))] - (: ..Binary +(with_expansions [ (: Nat size) + (ffi.array byte ) + (: ..Binary )] + (template: .public (empty size) + [(: ..Binary (for [@.old @.jvm @@ -84,12 +83,12 @@ (..make-bytevector )] ... Default - (array.empty ))))]) + (array.empty )))])) -(template: .public (size it) - [(with_expansions [ (: ..Binary it) - (ffi.length )] - (: Nat +(with_expansions [ (: ..Binary it) + (ffi.length )] + (template: .public (size it) + [(: Nat (for [@.old @.jvm @@ -109,47 +108,47 @@ (..bytevector-length [])] ... Default - (array.size ))))]) + (array.size )))])) (def: byte_mask Nat (i64.mask i64.bits_per_byte)) -(with_expansions [ (.static ..byte_mask)] +(with_expansions [ (.static ..byte_mask) + (: ..Binary it) + (: Nat index) + (ffi.read! ) + (ffi.byte_to_long ) + (|> + (:as I64) + ("lux i64 and" ))] (template: .public (bytes/1 index it) - [(with_expansions [ (: ..Binary it) - (: Nat index) - (|> - (ffi.read! ) - ffi.byte_to_long - (:as I64) - ("lux i64 and" ))] - (: I64 - (`` (for [@.old (~~ ) - @.jvm (~~ ) - - @.js - (|> - (:as (array.Array .Frac)) - ("js array read" ) - "lux f64 i64" - .i64) - - @.python - (|> - (:as (array.Array .I64)) - ("python array read" )) - - @.scheme - (..bytevector-u8-ref [ ])] - - ... Default - (.case (array.read! ) - {.#Some it} - it - - {.#None} - (.i64 (: (I64 Any) 0)))))))])) + [(: I64 + (`` (for [@.old (~~ ) + @.jvm (~~ ) + + @.js + (|> + (:as (array.Array .Frac)) + ("js array read" ) + "lux f64 i64" + .i64) + + @.python + (|> + (:as (array.Array .I64)) + ("python array read" )) + + @.scheme + (..bytevector-u8-ref [ ])] + + ... Default + (.case (array.read! ) + {.#Some it} + it + + {.#None} + (.i64 (: (I64 Any) 0))))))])) (template: .public (bytes/2 index' it') [(let [index (: Nat index') @@ -183,48 +182,49 @@ ("lux i64 left-shift" 8 (..bytes/1 ("lux i64 +" 6 index) it)) (..bytes/1 ("lux i64 +" 7 index) it))))]) -(with_expansions [ (hex "FF")] +(with_expansions [ (hex "FF") + (: ..Binary it) + (: Nat index) + (: (I64 Any) value) + (for [@.old + (:as Int ) + + @.jvm + (:as (Primitive "java.lang.Long") )] + ) + (ffi.long_to_byte ) + (ffi.write! )] (template: .public (with/1! index value it) - [(with_expansions [ (: ..Binary it) - (: Nat index) - (: (I64 Any) value) - (for [@.old - (|> (:as Int) ffi.long_to_byte) - - @.jvm - (|> (:as (Primitive "java.lang.Long")) ffi.long_to_byte)] - ) - (ffi.write! )] - (: ..Binary - (for [@.old - @.jvm - - @.js - (|> - (: ..Binary) - (:as (array.Array .Frac)) - ("js array write" - (|> - .int - ("lux i64 and" (.int )) - "lux i64 f64")) - (:as ..Binary)) - - @.python - (|> - (: ..Binary) - (:as (array.Array (I64 Any))) - ("python array write" (|> ("lux i64 and" ) (: (I64 Any)))) - (:as ..Binary)) - - @.scheme - (let [it' ] - (exec - (..bytevector-u8-set! [it' ]) - it'))] - - ... Default - (array.write! (|> .int ("lux i64 and" (.int ))) ))))])) + [(: ..Binary + (for [@.old + @.jvm + + @.js + (|> + (: ..Binary) + (:as (array.Array .Frac)) + ("js array write" + (|> + .int + ("lux i64 and" (.int )) + "lux i64 f64")) + (:as ..Binary)) + + @.python + (|> + (: ..Binary) + (:as (array.Array (I64 Any))) + ("python array write" (|> ("lux i64 and" ) (: (I64 Any)))) + (:as ..Binary)) + + @.scheme + (let [it' ] + (exec + (..bytevector-u8-set! [it' ]) + it'))] + + ... Default + (array.write! (|> .int ("lux i64 and" (.int ))) )))])) (template: .public (with/2! index' value' it) [(let [index (: Nat index') @@ -268,28 +268,33 @@ (..with/1! ("lux i64 +" 6 index) ("lux i64 right-shift" 8 value)) (..with/1! ("lux i64 +" 7 index) value))))]) -(def: .public (= reference sample) - (-> ..Binary ..Binary Bit) - (with_expansions [ (java/util/Arrays::equals reference sample)] - (for [@.old - @.jvm ] - (let [limit (..size reference)] - (and ("lux i64 =" limit (..size sample)) - (loop [index 0] - (if ("lux i64 =" limit index) - (and ("lux i64 =" - (..bytes/1 index reference) - (..bytes/1 index sample)) - (again (++ index))) - true))))))) - -(def: .public (copy! bytes source_offset source target_offset target) +(with_expansions [ (: ..Binary reference') + (: ..Binary sample') + (java/util/Arrays::equals )] + (template: .public (= reference' sample') + [(for [@.old + @.jvm ] + (let [reference + sample + limit (..size reference)] + (and ("lux i64 =" limit (..size sample)) + (loop [index 0] + (if ("lux i64 =" limit index) + (and ("lux i64 =" + (..bytes/1 index reference) + (..bytes/1 index sample)) + (again (++ index))) + true)))))])) + +... TODO: Turn into a template ASAP. +(inline: .public (copy! bytes source_offset source target_offset target) (-> Nat Nat ..Binary Nat ..Binary ..Binary) - (with_expansions [ (as_is (exec - (java/lang/System::arraycopy source (.int source_offset) - target (.int target_offset) - (.int bytes)) - target))] + (with_expansions [ (java/lang/System::arraycopy source (.int source_offset) + target (.int target_offset) + (.int bytes)) + (exec + + target)] (for [@.old @.jvm ] @@ -303,12 +308,16 @@ (again (++ index))) target))))) -(def: .public (slice offset size binary) - (-> Nat Nat ..Binary ..Binary) - (let [limit ("lux i64 +" size offset)] - (with_expansions [ (as_is (java/util/Arrays::copyOfRange binary (.int offset) (.int limit)))] - (for [@.old - @.jvm ] - - ... Default - (..copy! size offset binary 0 (..empty size)))))) +... TODO: Turn into a template ASAP. +(with_expansions [ (java/util/Arrays::copyOfRange binary + (.int offset) + (.int limit)) + (let [limit ("lux i64 +" size offset)] + )] + (inline: .public (slice offset size binary) + (-> Nat Nat ..Binary ..Binary) + (for [@.old + @.jvm ] + + ... Default + (..copy! size offset binary 0 (..empty size))))) -- cgit v1.2.3