aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source/poly
diff options
context:
space:
mode:
authorEduardo Julian2020-06-11 00:28:20 -0400
committerEduardo Julian2020-06-11 00:28:20 -0400
commitdef9629b35a434b3441aa15b89746b21d6c298ec (patch)
tree1b7f6ef8cc76a0d9f4e3c74d4d20239a43955873 /stdlib/source/poly
parentbbb6356a4a4f853dc48a54f1668c6712f0ef659f (diff)
Updated test for function optimization.
Diffstat (limited to 'stdlib/source/poly')
-rw-r--r--stdlib/source/poly/lux/data/format/json.lux40
1 files changed, 21 insertions, 19 deletions
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))))
+ ))))))