From de8af6044d590354563f4ea8849d98e8637c034a Mon Sep 17 00:00:00 2001 From: Eduardo Julian Date: Wed, 16 Feb 2022 04:41:41 -0400 Subject: FIXED loop binding initialization in several back-ends. --- stdlib/source/unsafe/lux/data/binary.lux | 129 ++++++++++++++++--------------- 1 file changed, 65 insertions(+), 64 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 d91893c38..ffc2b5e84 100644 --- a/stdlib/source/unsafe/lux/data/binary.lux +++ b/stdlib/source/unsafe/lux/data/binary.lux @@ -30,14 +30,8 @@ @.jvm (as_is ) @.js - (as_is (ffi.import: ArrayBuffer - ["[1]::[0]" - (new [ffi.Number])]) - - (ffi.import: Uint8Array - ["[1]::[0]" - (new [ArrayBuffer]) - (length ffi.Number)]) + (as_is (ffi.import: ArrayBuffer) + (ffi.import: Uint8Array) (type: .public Binary Uint8Array)) @@ -71,8 +65,11 @@ (|> .int "lux i64 f64" - ArrayBuffer::new - Uint8Array::new) + [] + ("js object new" ("js constant" "ArrayBuffer")) + [] + ("js object new" ("js constant" "Uint8Array")) + (:as ..Binary)) @.python (|> @@ -94,8 +91,8 @@ @.js (|> - Uint8Array::length - (: Frac) + ("js object get" "length") + (:as Frac) "lux f64 i64" .nat) @@ -123,64 +120,68 @@ (:as I64) ("lux i64 and" ))] (template: .public (bytes/1 index it) - [(: 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))))))])) + [(<| (:as .I64) + (: (.I64 .Any)) + (`` (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') - it (: ..Binary it')] - (: I64 - ($_ "lux i64 or" - ("lux i64 left-shift" 8 (..bytes/1 index it)) - (..bytes/1 ("lux i64 +" 1 index) it))))]) + [(<| (let [index (: Nat index') + it (: ..Binary it')]) + (:as .I64) + (: (.I64 .Any)) + ($_ "lux i64 or" + ("lux i64 left-shift" 8 (..bytes/1 index it)) + (..bytes/1 ("lux i64 +" 1 index) it)))]) (template: .public (bytes/4 index' it') - [(let [index (: Nat index') - it (: ..Binary it')] - (: I64 - ($_ "lux i64 or" - ("lux i64 left-shift" 24 (..bytes/1 index it)) - ("lux i64 left-shift" 16 (..bytes/1 ("lux i64 +" 1 index) it)) - ("lux i64 left-shift" 8 (..bytes/1 ("lux i64 +" 2 index) it)) - (..bytes/1 ("lux i64 +" 3 index) it))))]) + [(<| (let [index (: Nat index') + it (: ..Binary it')]) + (:as .I64) + (: (.I64 .Any)) + ($_ "lux i64 or" + ("lux i64 left-shift" 24 (..bytes/1 index it)) + ("lux i64 left-shift" 16 (..bytes/1 ("lux i64 +" 1 index) it)) + ("lux i64 left-shift" 8 (..bytes/1 ("lux i64 +" 2 index) it)) + (..bytes/1 ("lux i64 +" 3 index) it)))]) (template: .public (bytes/8 index' it') - [(let [index (: Nat index') - it (: ..Binary it')] - (: I64 - ($_ "lux i64 or" - ("lux i64 left-shift" 56 (..bytes/1 index it)) - ("lux i64 left-shift" 48 (..bytes/1 ("lux i64 +" 1 index) it)) - ("lux i64 left-shift" 40 (..bytes/1 ("lux i64 +" 2 index) it)) - ("lux i64 left-shift" 32 (..bytes/1 ("lux i64 +" 3 index) it)) - ("lux i64 left-shift" 24 (..bytes/1 ("lux i64 +" 4 index) it)) - ("lux i64 left-shift" 16 (..bytes/1 ("lux i64 +" 5 index) it)) - ("lux i64 left-shift" 8 (..bytes/1 ("lux i64 +" 6 index) it)) - (..bytes/1 ("lux i64 +" 7 index) it))))]) + [(<| (let [index (: Nat index') + it (: ..Binary it')]) + (:as .I64) + (: (.I64 .Any)) + ($_ "lux i64 or" + ("lux i64 left-shift" 56 (..bytes/1 index it)) + ("lux i64 left-shift" 48 (..bytes/1 ("lux i64 +" 1 index) it)) + ("lux i64 left-shift" 40 (..bytes/1 ("lux i64 +" 2 index) it)) + ("lux i64 left-shift" 32 (..bytes/1 ("lux i64 +" 3 index) it)) + ("lux i64 left-shift" 24 (..bytes/1 ("lux i64 +" 4 index) it)) + ("lux i64 left-shift" 16 (..bytes/1 ("lux i64 +" 5 index) it)) + ("lux i64 left-shift" 8 (..bytes/1 ("lux i64 +" 6 index) it)) + (..bytes/1 ("lux i64 +" 7 index) it)))]) (with_expansions [ (hex "FF") (: ..Binary it) -- cgit v1.2.3