aboutsummaryrefslogtreecommitdiff
path: root/lux-jvm/source/luxc/lang/translation/jvm/structure.lux
diff options
context:
space:
mode:
authorEduardo Julian2020-10-09 01:16:47 -0400
committerEduardo Julian2020-10-09 01:16:47 -0400
commitbae39f32cddb816a6123697269c20dbf4a65ac19 (patch)
treed9ee53073ebe0d83e29dbd24e0dda8d5dd95dc47 /lux-jvm/source/luxc/lang/translation/jvm/structure.lux
parent79aa92dfd81d569fe6120b8e5c00d41528801153 (diff)
Also using BIPUSH and SIPUSH during JVM generation.
Diffstat (limited to 'lux-jvm/source/luxc/lang/translation/jvm/structure.lux')
-rw-r--r--lux-jvm/source/luxc/lang/translation/jvm/structure.lux62
1 files changed, 45 insertions, 17 deletions
diff --git a/lux-jvm/source/luxc/lang/translation/jvm/structure.lux b/lux-jvm/source/luxc/lang/translation/jvm/structure.lux
index 049c1549a..c61f96bb8 100644
--- a/lux-jvm/source/luxc/lang/translation/jvm/structure.lux
+++ b/lux-jvm/source/luxc/lang/translation/jvm/structure.lux
@@ -1,12 +1,14 @@
(.module:
[lux (#- Type)
+ ["." host (#+ import:)]
[abstract
["." monad (#+ do)]]
[control
- ["ex" exception (#+ exception:)]]
+ ["." exception (#+ exception:)]]
[data
[number
- ["n" nat]]
+ ["n" nat]
+ ["i" int]]
[text
["%" format (#+ format)]]
[collection
@@ -34,8 +36,9 @@
["#." runtime]])
(exception: #export (not-a-tuple {size Nat})
- (ex.report ["Expected size" ">= 2"]
- ["Actual size" (%.nat size)]))
+ (exception.report
+ ["Expected size" ">= 2"]
+ ["Actual size" (%.nat size)]))
(def: #export (tuple generate archive members)
(Generator (List Synthesis))
@@ -57,26 +60,51 @@
(_.array //runtime.$Value)
membersI))))
-(def: (flagI right?)
+(import: #long java/lang/Byte
+ (#static MAX_VALUE byte)
+ (#static MIN_VALUE byte))
+
+(import: #long java/lang/Short
+ (#static MAX_VALUE short)
+ (#static MIN_VALUE short))
+
+(def: #export (tagI lefts right?)
+ (-> Nat Bit Inst)
+ (case (if right?
+ (.inc lefts)
+ lefts)
+ 0 _.ICONST_0
+ 1 _.ICONST_1
+ 2 _.ICONST_2
+ 3 _.ICONST_3
+ 4 _.ICONST_4
+ 5 _.ICONST_5
+ tag (let [tag (.int tag)]
+ (cond (and (i.>= (java/lang/Byte::MIN_VALUE) tag)
+ (i.<= (java/lang/Byte::MAX_VALUE) tag))
+ (_.BIPUSH tag)
+
+ (and (i.>= (java/lang/Short::MIN_VALUE) tag)
+ (i.<= (java/lang/Short::MAX_VALUE) tag))
+ (_.SIPUSH tag)
+
+ ## else
+ (_.int tag)))))
+
+(def: #export leftI _.NULL)
+(def: #export rightI (_.string ""))
+
+(def: #export (flagI right?)
(-> Bit Inst)
(if right?
- (_.string "")
- _.NULL))
+ ..rightI
+ ..leftI))
(def: #export (variant generate archive [lefts right? member])
(Generator [Nat Bit Synthesis])
(do phase.monad
[memberI (generate archive member)
- #let [tagI (case (if right?
- (.inc lefts)
- lefts)
- 0 _.ICONST_0
- 1 _.ICONST_1
- 2 _.ICONST_2
- 3 _.ICONST_3
- 4 _.ICONST_4
- 5 _.ICONST_5
- tag (_.int (.int tag)))]]
+ #let [tagI (..tagI lefts right?)]]
(wrap (|>> tagI
(flagI right?)
memberI