aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source
diff options
context:
space:
mode:
authorEduardo Julian2019-06-20 22:54:40 -0400
committerEduardo Julian2019-06-20 22:54:40 -0400
commit29d99720a45bc953ae3c5c77d5a10366353cdd05 (patch)
tree50cc9efc0c7013f132c4cccd0f9d359ecbff4b0d /stdlib/source
parentb71b861008381626633bf28b033cd866d7e4e0b7 (diff)
Unified the unsigned integers.
Diffstat (limited to 'stdlib/source')
-rw-r--r--stdlib/source/lux/target/jvm/attribute.lux8
-rw-r--r--stdlib/source/lux/target/jvm/attribute/code.lux4
-rw-r--r--stdlib/source/lux/target/jvm/attribute/code/label.lux2
-rw-r--r--stdlib/source/lux/target/jvm/class.lux6
-rw-r--r--stdlib/source/lux/target/jvm/constant/pool.lux6
-rw-r--r--stdlib/source/lux/target/jvm/constant/tag.lux4
-rw-r--r--stdlib/source/lux/target/jvm/encoding.lux65
-rw-r--r--stdlib/source/lux/target/jvm/index.lux2
-rw-r--r--stdlib/source/lux/target/jvm/magic.lux2
-rw-r--r--stdlib/source/lux/target/jvm/modifier.lux6
-rw-r--r--stdlib/source/lux/target/jvm/version.lux2
11 files changed, 57 insertions, 50 deletions
diff --git a/stdlib/source/lux/target/jvm/attribute.lux b/stdlib/source/lux/target/jvm/attribute.lux
index 946f58477..e2db85282 100644
--- a/stdlib/source/lux/target/jvm/attribute.lux
+++ b/stdlib/source/lux/target/jvm/attribute.lux
@@ -34,7 +34,7 @@
(Equivalence (Info about))))
($_ equivalence.product
//index.equivalence
- //encoding.u4-equivalence
+ //encoding.equivalence
Equivalence<about>))
(def: (info-writer writer)
@@ -78,7 +78,7 @@
(case attribute
(^template [<tag>]
(<tag> [name length info])
- (|> length //encoding.from-u4 .nat (n/+ fixed-attribute-length)))
+ (|> length //encoding.nat .nat (n/+ fixed-attribute-length)))
([#Constant] [#Code])))
(def: constant-name "ConstantValue")
@@ -86,7 +86,7 @@
(def: (constant' @name index)
(-> (Index UTF8) Constant Attribute)
(#Constant {#name @name
- #length (//encoding.to-u4 /constant.length)
+ #length (//encoding.u4 /constant.length)
#info index}))
(def: #export (constant index)
@@ -101,7 +101,7 @@
(-> (Index UTF8) Code Attribute)
(#Code {#name @name
## https://docs.oracle.com/javase/specs/jvms/se8/html/jvms-4.html#jvms-4.7.3
- #length (//encoding.to-u4
+ #length (//encoding.u4
(/code.length ..length specification))
#info specification}))
diff --git a/stdlib/source/lux/target/jvm/attribute/code.lux b/stdlib/source/lux/target/jvm/attribute/code.lux
index 4cc47b5af..d30bfa806 100644
--- a/stdlib/source/lux/target/jvm/attribute/code.lux
+++ b/stdlib/source/lux/target/jvm/attribute/code.lux
@@ -54,8 +54,8 @@
(All [attribute]
(-> (Equivalence attribute) (Equivalence (Code attribute))))
($_ equivalence.product
- ///encoding.u2-equivalence
- ///encoding.u2-equivalence
+ ///encoding.equivalence
+ ///encoding.equivalence
binary.equivalence
(row.equivalence /exception.equivalence)
(row.equivalence attribute-equivalence)
diff --git a/stdlib/source/lux/target/jvm/attribute/code/label.lux b/stdlib/source/lux/target/jvm/attribute/code/label.lux
index 1a26aab43..c70e13a3e 100644
--- a/stdlib/source/lux/target/jvm/attribute/code/label.lux
+++ b/stdlib/source/lux/target/jvm/attribute/code/label.lux
@@ -12,7 +12,7 @@
(def: #export equivalence
(Equivalence Label)
- ////encoding.u2-equivalence)
+ ////encoding.equivalence)
(def: #export format
(Format Label)
diff --git a/stdlib/source/lux/target/jvm/class.lux b/stdlib/source/lux/target/jvm/class.lux
index 0e95c7063..6169556c5 100644
--- a/stdlib/source/lux/target/jvm/class.lux
+++ b/stdlib/source/lux/target/jvm/class.lux
@@ -56,9 +56,9 @@
(def: #export equivalence
(Equivalence Class)
($_ equivalence.product
- //encoding.u4-equivalence
- //encoding.u2-equivalence
- //encoding.u2-equivalence
+ //encoding.equivalence
+ //encoding.equivalence
+ //encoding.equivalence
//constant/pool.equivalence
//modifier.equivalence
//index.equivalence
diff --git a/stdlib/source/lux/target/jvm/constant/pool.lux b/stdlib/source/lux/target/jvm/constant/pool.lux
index c267eb7f4..7b29cc910 100644
--- a/stdlib/source/lux/target/jvm/constant/pool.lux
+++ b/stdlib/source/lux/target/jvm/constant/pool.lux
@@ -33,7 +33,7 @@
(template: (!add <tag> <=> <value>)
(function (_ pool)
- (with-expansions [<index> (as-is (index.index (encoding.to-u2 (n/+ offset idx))))
+ (with-expansions [<index> (as-is (index.index (encoding.u2 (n/+ offset idx))))
<try-again> (as-is (recur (.inc idx)))]
(loop [idx 0]
(case (row.nth idx pool)
@@ -53,7 +53,7 @@
<index>])))))
(template: (!raw-index <index>)
- (|> <index> index.number encoding.from-u2 .nat))
+ (|> <index> index.number encoding.nat .nat))
(exception: #export (invalid-index {index (Index Any)}
{maximum Nat})
@@ -89,7 +89,7 @@
(template: (!find <tag> <=> <%> <expected>)
(function (_ pool)
- (with-expansions [<index> (as-is (index.index (encoding.to-u2 (n/+ offset idx))))
+ (with-expansions [<index> (as-is (index.index (encoding.u2 (n/+ offset idx))))
<try-again> (as-is (recur (.inc idx)))]
(loop [idx 0]
(case (row.nth idx pool)
diff --git a/stdlib/source/lux/target/jvm/constant/tag.lux b/stdlib/source/lux/target/jvm/constant/tag.lux
index 71e75f40b..352fb8afe 100644
--- a/stdlib/source/lux/target/jvm/constant/tag.lux
+++ b/stdlib/source/lux/target/jvm/constant/tag.lux
@@ -8,7 +8,7 @@
[type
abstract]]
[///
- ["." encoding (#+ U1) ("u1/." u1-equivalence)]])
+ ["." encoding (#+ U1) ("u1/." equivalence)]])
(abstract: #export Tag
{}
@@ -23,7 +23,7 @@
(template [<code> <name>]
[(def: #export <name>
Tag
- (:abstraction (encoding.to-u1 <code>)))]
+ (:abstraction (encoding.u1 <code>)))]
[01 utf8]
[03 integer]
diff --git a/stdlib/source/lux/target/jvm/encoding.lux b/stdlib/source/lux/target/jvm/encoding.lux
index 33ac427c2..f5db7a81a 100644
--- a/stdlib/source/lux/target/jvm/encoding.lux
+++ b/stdlib/source/lux/target/jvm/encoding.lux
@@ -1,5 +1,5 @@
(.module:
- [lux #*
+ [lux (#- nat)
[abstract
[equivalence (#+ Equivalence)]]
[control
@@ -9,44 +9,51 @@
["." i64]]
[format
["." binary (#+ Format)]]]
+ [macro
+ ["." template]]
[type
abstract]])
-(template [<bytes> <name> <size> <to> <from> <equivalence>]
- [(abstract: #export <name>
- {}
+(abstract: #export (Unsigned brand)
+ {}
+ (I64 Any)
- (I64 Any)
+ (def: #export nat
+ (-> (Unsigned Any) (I64 Any))
+ (|>> :representation))
- (def: #export <size> Nat <bytes>)
+ (structure: #export equivalence
+ (All [brand] (Equivalence (Unsigned brand)))
+ (def: (= reference sample)
+ ("lux i64 =" (:representation reference) (:representation sample))))
+
+ (template [<bytes> <name> <size> <constructor> <max>]
+ [(with-expansions [<raw> (template.identifier [<name> "'"])]
+ (abstract: #export <raw> {} Any)
+ (type: #export <name> (Unsigned <raw>)))
- (def: #export <to>
+ (def: #export <size> Nat <bytes>)
+
+ (def: #export <max>
+ <name>
+ (|> <bytes> (n/* i64.bits-per-byte) i64.mask :abstraction))
+
+ (def: #export <constructor>
(-> (I64 Any) <name>)
- (let [mask (|> <bytes>
- (n/* i64.bits-per-byte)
- i64.mask)]
- (|>> (i64.and mask) :abstraction)))
-
- (def: #export <from>
- (-> <name> (I64 Any))
- (|>> :representation))
-
- (structure: #export <equivalence> (Equivalence <name>)
- (def: (= reference sample)
- ("lux i64 =" (:representation reference) (:representation sample))))
- )]
-
- [1 U1 u1-bytes to-u1 from-u1 u1-equivalence]
- [2 U2 u2-bytes to-u2 from-u2 u2-equivalence]
- [4 U4 u4-bytes to-u4 from-u4 u4-equivalence]
+ (|>> (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]
+ )
)
-(template [<name> <type> <format> <pre-write> <post-read>]
+(template [<name> <type> <format> <post-read>]
[(def: #export <name>
(Format <type>)
- (binary.adapt <post-read> <pre-write> <format>))]
+ (binary.adapt <post-read> ..nat <format>))]
- [u1-format U1 binary.bits/8 ..from-u1 ..to-u1]
- [u2-format U2 binary.bits/16 ..from-u2 ..to-u2]
- [u4-format U4 binary.bits/32 ..from-u4 ..to-u4]
+ [u1-format U1 binary.bits/8 ..u1]
+ [u2-format U2 binary.bits/16 ..u2]
+ [u4-format U4 binary.bits/32 ..u4]
)
diff --git a/stdlib/source/lux/target/jvm/index.lux b/stdlib/source/lux/target/jvm/index.lux
index 6e3d070ff..d8dd1d9a5 100644
--- a/stdlib/source/lux/target/jvm/index.lux
+++ b/stdlib/source/lux/target/jvm/index.lux
@@ -27,7 +27,7 @@
(All [kind] (Equivalence (Index kind)))
(:: equivalence.contravariant map-1
..number
- //encoding.u2-equivalence))
+ //encoding.equivalence))
(def: #export format
(All [kind] (Format (Index kind)))
diff --git a/stdlib/source/lux/target/jvm/magic.lux b/stdlib/source/lux/target/jvm/magic.lux
index 5b74dc572..c00d246a0 100644
--- a/stdlib/source/lux/target/jvm/magic.lux
+++ b/stdlib/source/lux/target/jvm/magic.lux
@@ -12,7 +12,7 @@
(def: #export code
Magic
- (//encoding.to-u4 (hex "CAFEBABE")))
+ (//encoding.u4 (hex "CAFEBABE")))
(def: #export format
(Format Magic)
diff --git a/stdlib/source/lux/target/jvm/modifier.lux b/stdlib/source/lux/target/jvm/modifier.lux
index 6790c5afe..417484c45 100644
--- a/stdlib/source/lux/target/jvm/modifier.lux
+++ b/stdlib/source/lux/target/jvm/modifier.lux
@@ -27,13 +27,13 @@
(template: (!wrap value)
(|> value
- //encoding.to-u2
+ //encoding.u2
:abstraction))
(template: (!unwrap value)
(|> value
:representation
- //encoding.from-u2))
+ //encoding.nat))
(def: #export code
(-> (Modifier Any) //encoding.U2)
@@ -46,7 +46,7 @@
(structure: #export equivalence
(All [of] (Equivalence (Modifier of)))
(def: (= reference sample)
- (:: //encoding.u2-equivalence =
+ (:: //encoding.equivalence =
(:representation reference)
(:representation sample))))
diff --git a/stdlib/source/lux/target/jvm/version.lux b/stdlib/source/lux/target/jvm/version.lux
index dd76a594d..ddfe7139c 100644
--- a/stdlib/source/lux/target/jvm/version.lux
+++ b/stdlib/source/lux/target/jvm/version.lux
@@ -12,7 +12,7 @@
(def: #export version
(-> Nat Version)
- //encoding.to-u2)
+ //encoding.u2)
(template [<number> <name>]
[(def: #export <name>