From def9629b35a434b3441aa15b89746b21d6c298ec Mon Sep 17 00:00:00 2001 From: Eduardo Julian Date: Thu, 11 Jun 2020 00:28:20 -0400 Subject: Updated test for function optimization. --- stdlib/source/poly/lux/data/format/json.lux | 40 +++++++++++++++-------------- 1 file changed, 21 insertions(+), 19 deletions(-) (limited to 'stdlib/source/poly') diff --git a/stdlib/source/poly/lux/data/format/json.lux b/stdlib/source/poly/lux/data/format/json.lux index e23d5648c..d3a32b27a 100644 --- a/stdlib/source/poly/lux/data/format/json.lux +++ b/stdlib/source/poly/lux/data/format/json.lux @@ -56,22 +56,25 @@ (def: low-mask Nat (|> 1 (i64.left-shift 32) dec)) (def: high-mask Nat (|> low-mask (i64.left-shift 32))) -(structure: nat-codec (codec.Codec JSON Nat) +(structure: nat-codec + (codec.Codec JSON Nat) + (def: (encode input) (let [high (|> input (i64.and high-mask) (i64.logic-right-shift 32)) low (i64.and low-mask input)] (#/.Array (row (|> high .int int.frac #/.Number) (|> low .int int.frac #/.Number))))) - (def: (decode input) - (<| (.run input) - .array - (do p.monad - [high .number - low .number]) - (wrap (n.+ (|> high frac.int .nat (i64.left-shift 32)) - (|> low frac.int .nat)))))) + (def: decode + (.run (.array + (do p.monad + [high .number + low .number] + (wrap (n.+ (|> high frac.int .nat (i64.left-shift 32)) + (|> low frac.int .nat)))))))) -(structure: int-codec (codec.Codec JSON Int) +(structure: int-codec + (codec.Codec JSON Int) + (def: encode (|>> .nat (:: nat-codec encode))) (def: decode (|>> (:: nat-codec decode) (:: e.functor map .int)))) @@ -85,7 +88,8 @@ (#.Some value) (writer value)))) (structure: qty-codec - (All [unit] (codec.Codec JSON (unit.Qty unit))) + (All [unit] + (codec.Codec JSON (unit.Qty unit))) (def: encode (|>> unit.out (:: ..int-codec encode))) @@ -322,11 +326,9 @@ #dictionary (Dictionary Text Frac)}) (derived: (..codec Record)))} - (with-gensyms [g!inputs] - (wrap (list (` (: (codec.Codec /.JSON (~ inputT)) - (structure (def: (~' encode) - (..codec//encode (~ inputT))) - (def: ((~' decode) (~ g!inputs)) - ((~! .run) (~ g!inputs) - (..codec//decode (~ inputT)))) - ))))))) + (wrap (list (` (: (codec.Codec /.JSON (~ inputT)) + (structure (def: (~' encode) + (..codec//encode (~ inputT))) + (def: (~' decode) + ((~! .run) (..codec//decode (~ inputT)))) + )))))) -- cgit v1.2.3