aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source/lux/target/jvm/encoding/unsigned.lux
diff options
context:
space:
mode:
Diffstat (limited to 'stdlib/source/lux/target/jvm/encoding/unsigned.lux')
-rw-r--r--stdlib/source/lux/target/jvm/encoding/unsigned.lux27
1 files changed, 17 insertions, 10 deletions
diff --git a/stdlib/source/lux/target/jvm/encoding/unsigned.lux b/stdlib/source/lux/target/jvm/encoding/unsigned.lux
index 15dd7a07e..86495f38e 100644
--- a/stdlib/source/lux/target/jvm/encoding/unsigned.lux
+++ b/stdlib/source/lux/target/jvm/encoding/unsigned.lux
@@ -17,18 +17,18 @@
(abstract: #export (Unsigned brand)
{}
- (I64 Any)
+ Nat
(def: #export nat
- (-> (Unsigned Any) (I64 Any))
+ (-> (Unsigned Any) Nat)
(|>> :representation))
(structure: #export equivalence
(All [brand] (Equivalence (Unsigned brand)))
(def: (= reference sample)
- ("lux i64 =" (:representation reference) (:representation sample))))
+ (n/= (:representation reference) (:representation sample))))
- (template [<bytes> <name> <size> <constructor> <max>]
+ (template [<bytes> <name> <size> <constructor> <max> <+>]
[(with-expansions [<raw> (template.identifier [<name> "'"])]
(abstract: #export <raw> {} Any)
(type: #export <name> (Unsigned <raw>)))
@@ -40,19 +40,26 @@
(|> <bytes> (n/* i64.bits-per-byte) i64.mask :abstraction))
(def: #export <constructor>
- (-> (I64 Any) <name>)
- (|>> (i64.and (:representation <max>)) :abstraction))]
+ (-> Nat <name>)
+ (|>> (i64.and (:representation <max>)) :abstraction))
- [1 U1 u1-bytes u1 max-u1]
- [2 U2 u2-bytes u2 max-u2]
- [4 U4 u4-bytes u4 max-u4]
+ (def: #export (<+> parameter subject)
+ (-> <name> <name> <name>)
+ (:abstraction
+ (i64.and (:representation <max>)
+ (n/+ (:representation parameter)
+ (:representation subject)))))]
+
+ [1 U1 u1-bytes u1 max-u1 u1/+]
+ [2 U2 u2-bytes u2 max-u2 u2/+]
+ [4 U4 u4-bytes u4 max-u4 u4/+]
)
)
(template [<parser-name> <writer-name> <type> <parser> <writer> <post-read>]
[(def: #export <parser-name>
(Parser <type>)
- (<>@map <post-read> <parser>))
+ (<>@map (|>> .nat <post-read>) <parser>))
(def: #export <writer-name>
(Writer <type>)