diff options
Diffstat (limited to '')
-rw-r--r-- | stdlib/source/lux/data/binary.lux | 212 |
1 files changed, 106 insertions, 106 deletions
diff --git a/stdlib/source/lux/data/binary.lux b/stdlib/source/lux/data/binary.lux index 3853e6aa5..4d3eb962a 100644 --- a/stdlib/source/lux/data/binary.lux +++ b/stdlib/source/lux/data/binary.lux @@ -55,64 +55,64 @@ (def: byte (-> (I64 Any) (primitive "java.lang.Byte")) - (`` (for {(~~ (static @.old)) - (|>> .int host.long-to-byte) - - (~~ (static @.jvm)) - (|>> .int (:coerce (primitive "java.lang.Long")) host.long-to-byte)}))))] - (`` (for {(~~ (static @.old)) - (as-is <for-jvm>) - - (~~ (static @.jvm)) - (as-is <for-jvm>) - - (~~ (static @.js)) - (as-is (host.import: ArrayBuffer - (new [host.Number])) - - (host.import: Uint8Array - (new [ArrayBuffer]) - (length host.Number)) - - (type: #export Binary Uint8Array))}))) + (for {@.old + (|>> .int host.long-to-byte) + + @.jvm + (|>> .int (:coerce (primitive "java.lang.Long")) host.long-to-byte)})))] + (for {@.old + (as-is <for-jvm>) + + @.jvm + (as-is <for-jvm>) + + @.js + (as-is (host.import: ArrayBuffer + (new [host.Number])) + + (host.import: Uint8Array + (new [ArrayBuffer]) + (length host.Number)) + + (type: #export Binary Uint8Array))})) (template: (!size binary) - (`` (for {(~~ (static @.old)) - (host.array-length binary) + (for {@.old + (host.array-length binary) - (~~ (static @.jvm)) - (host.array-length binary) + @.jvm + (host.array-length binary) - (~~ (static @.js)) - (.frac-to-nat (Uint8Array::length binary))}))) + @.js + (.frac-to-nat (Uint8Array::length binary))})) (template: (!read idx binary) - (`` (for {(~~ (static @.old)) - (..i64 (host.array-read idx binary)) + (for {@.old + (..i64 (host.array-read idx binary)) - (~~ (static @.jvm)) - (..i64 (host.array-read idx binary)) + @.jvm + (..i64 (host.array-read idx binary)) - (~~ (static @.js)) - (|> binary - (: ..Binary) - (:coerce (array.Array .Frac)) - ("js array read" idx) - .frac-to-nat)}))) + @.js + (|> binary + (: ..Binary) + (:coerce (array.Array .Frac)) + ("js array read" idx) + .frac-to-nat)})) (template: (!write idx value binary) - (`` (for {(~~ (static @.old)) - (host.array-write idx (..byte value) binary) + (for {@.old + (host.array-write idx (..byte value) binary) - (~~ (static @.jvm)) - (host.array-write idx (..byte value) binary) + @.jvm + (host.array-write idx (..byte value) binary) - (~~ (static @.js)) - (|> binary - (: ..Binary) - (:coerce (array.Array .Frac)) - ("js array write" idx (.nat-to-frac value)) - (:coerce ..Binary))}))) + @.js + (|> binary + (: ..Binary) + (:coerce (array.Array .Frac)) + ("js array write" idx (.nat-to-frac value)) + (:coerce ..Binary))})) (def: #export size (-> Binary Nat) @@ -120,14 +120,14 @@ (def: #export create (-> Nat Binary) - (`` (for {(~~ (static @.old)) - (|>> (host.array byte)) + (for {@.old + (|>> (host.array byte)) - (~~ (static @.jvm)) - (|>> (host.array byte)) + @.jvm + (|>> (host.array byte)) - (~~ (static @.js)) - (|>> .nat-to-frac [] ArrayBuffer::new Uint8Array::new)}))) + @.js + (|>> .nat-to-frac [] ArrayBuffer::new Uint8Array::new)})) (def: #export (fold f init binary) (All [a] (-> (-> I64 a a) a Binary a)) @@ -223,57 +223,57 @@ (Equivalence Binary) (def: (= reference sample) - (`` (for {(~~ (static @.old)) - (java/util/Arrays::equals reference sample) - - (~~ (static @.jvm)) - (java/util/Arrays::equals reference sample)} - (let [limit (!size reference)] - (and (n.= limit - (!size sample)) - (loop [idx 0] - (if (n.< limit idx) - (and (n.= (!read idx reference) - (!read idx sample)) - (recur (inc idx))) - true)))))))) - -(`` (for {(~~ (static @.old)) - (as-is) - - (~~ (static @.jvm)) - (as-is)} - - ## Default - (exception: #export (cannot-copy-bytes {source-input Nat} - {target-output Nat}) - (exception.report - ["Source input space" (%.nat source-input)] - ["Target output space" (%.nat target-output)])))) + (for {@.old + (java/util/Arrays::equals reference sample) + + @.jvm + (java/util/Arrays::equals reference sample)} + (let [limit (!size reference)] + (and (n.= limit + (!size sample)) + (loop [idx 0] + (if (n.< limit idx) + (and (n.= (!read idx reference) + (!read idx sample)) + (recur (inc idx))) + true))))))) + +(for {@.old + (as-is) + + @.jvm + (as-is)} + + ## Default + (exception: #export (cannot-copy-bytes {source-input Nat} + {target-output Nat}) + (exception.report + ["Source input space" (%.nat source-input)] + ["Target output space" (%.nat target-output)]))) (def: #export (copy bytes source-offset source target-offset target) (-> Nat Nat Binary Nat Binary (Try Binary)) (with-expansions [<for-jvm> (as-is (do try.monad [_ (java/lang/System::arraycopy source (.int source-offset) target (.int target-offset) (.int bytes))] (wrap target)))] - (`` (for {(~~ (static @.old)) - <for-jvm> - - (~~ (static @.jvm)) - <for-jvm>} - - ## Default - (let [source-input (n.- source-offset (!size source)) - target-output (n.- target-offset (!size target))] - (if (n.<= target-output source-input) - (loop [idx 0] - (if (n.< source-input idx) - (exec (!write (n.+ target-offset idx) - (!read (n.+ source-offset idx) source) - target) - (recur (inc idx))) - (#try.Success target))) - (exception.throw ..cannot-copy-bytes [source-input target-output]))))))) + (for {@.old + <for-jvm> + + @.jvm + <for-jvm>} + + ## Default + (let [source-input (n.- source-offset (!size source)) + target-output (n.- target-offset (!size target))] + (if (n.<= target-output source-input) + (loop [idx 0] + (if (n.< source-input idx) + (exec (!write (n.+ target-offset idx) + (!read (n.+ source-offset idx) source) + target) + (recur (inc idx))) + (#try.Success target))) + (exception.throw ..cannot-copy-bytes [source-input target-output])))))) (def: #export (slice from to binary) (-> Nat Nat Binary (Try Binary)) @@ -282,15 +282,15 @@ (if (and (n.< size from) (n.< size to)) (with-expansions [<for-jvm> (as-is (#try.Success (java/util/Arrays::copyOfRange binary (.int from) (.int (inc to)))))] - (`` (for {(~~ (static @.old)) - <for-jvm> - - (~~ (static @.jvm)) - <for-jvm>} - - ## Default - (let [how-many (n.- from to)] - (..copy how-many from binary 0 (..create how-many)))))) + (for {@.old + <for-jvm> + + @.jvm + <for-jvm>} + + ## Default + (let [how-many (n.- from to)] + (..copy how-many from binary 0 (..create how-many))))) (exception.throw ..slice-out-of-bounds [size from to])) (exception.throw ..inverted-slice [size from to])))) |