aboutsummaryrefslogtreecommitdiff
path: root/lux-jvm
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
parent79aa92dfd81d569fe6120b8e5c00d41528801153 (diff)
Also using BIPUSH and SIPUSH during JVM generation.
Diffstat (limited to 'lux-jvm')
-rw-r--r--lux-jvm/source/luxc/lang/translation/jvm/case.lux15
-rw-r--r--lux-jvm/source/luxc/lang/translation/jvm/primitive.lux33
-rw-r--r--lux-jvm/source/luxc/lang/translation/jvm/structure.lux62
3 files changed, 78 insertions, 32 deletions
diff --git a/lux-jvm/source/luxc/lang/translation/jvm/case.lux b/lux-jvm/source/luxc/lang/translation/jvm/case.lux
index d77e747fd..eea77aaf0 100644
--- a/lux-jvm/source/luxc/lang/translation/jvm/case.lux
+++ b/lux-jvm/source/luxc/lang/translation/jvm/case.lux
@@ -30,7 +30,8 @@
["$" jvm (#+ Label Inst Operation Phase Generator)
["_" inst]]]]]
["." //
- ["." runtime]])
+ ["." runtime]
+ ["." structure]])
(def: (pop-altI stack-depth)
(-> Nat Inst)
@@ -151,14 +152,14 @@
bodyI
(_.GOTO @end))))
- (^template [<pattern> <flag> <prepare>]
- (^ (<pattern> idx))
+ (^template [<pattern> <right?>]
+ (^ (<pattern> lefts))
(operation@wrap (<| _.with-label (function (_ @success))
_.with-label (function (_ @fail))
(|>> peekI
(_.CHECKCAST //.$Variant)
- (_.int (.int (<prepare> idx)))
- <flag>
+ (structure.tagI lefts <right?>)
+ (structure.flagI <right?>)
(_.INVOKESTATIC //.$Runtime "pm_variant" (type.method [(list //.$Variant runtime.$Tag runtime.$Flag) runtime.$Value (list)]))
_.DUP
(_.IFNULL @fail)
@@ -168,8 +169,8 @@
(_.GOTO @else)
(_.label @success)
pushI))))
- ([synthesis.side/left _.NULL function.identity]
- [synthesis.side/right (_.string "") .inc])
+ ([synthesis.side/left false]
+ [synthesis.side/right true])
## Extra optimization
(^template [<path> <projection>]
diff --git a/lux-jvm/source/luxc/lang/translation/jvm/primitive.lux b/lux-jvm/source/luxc/lang/translation/jvm/primitive.lux
index 469e730de..24eeef49e 100644
--- a/lux-jvm/source/luxc/lang/translation/jvm/primitive.lux
+++ b/lux-jvm/source/luxc/lang/translation/jvm/primitive.lux
@@ -22,6 +22,14 @@
(function (_ value)
(operation@wrap (_.GETSTATIC Boolean (if value "TRUE" "FALSE") Boolean)))))
+(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 (i64 value)
(-> (I64 Any) (Operation Inst))
(case (.int value)
@@ -42,9 +50,18 @@
[+4 _.ICONST_4]
[+5 _.ICONST_5])
- _
- (let [loadI (|> value .int _.long)]
- (operation@wrap (|>> loadI (_.wrap type.long))))))
+ value
+ (let [constantI (cond (and (i.>= (java/lang/Byte::MIN_VALUE) value)
+ (i.<= (java/lang/Byte::MAX_VALUE) value))
+ (|>> (_.BIPUSH value) _.I2L)
+
+ (and (i.>= (java/lang/Short::MIN_VALUE) value)
+ (i.<= (java/lang/Short::MAX_VALUE) value))
+ (|>> (_.SIPUSH value) _.I2L)
+
+ ## else
+ (|> value .int _.long))]
+ (operation@wrap (|>> constantI (_.wrap type.long))))))
(import: #long java/lang/Double
(#static doubleToRawLongBits #manual [double] int))
@@ -78,11 +95,11 @@
[+5.0 _.ICONST_5])
_
- (let [loadI (if (i.= ..d0-bits
- (java/lang/Double::doubleToRawLongBits (:coerce java/lang/Double value)))
- _.DCONST_0
- (_.double value))]
- (operation@wrap (|>> loadI (_.wrap type.double))))))
+ (let [constantI (if (i.= ..d0-bits
+ (java/lang/Double::doubleToRawLongBits (:coerce java/lang/Double value)))
+ _.DCONST_0
+ (_.double value))]
+ (operation@wrap (|>> constantI (_.wrap type.double))))))
(def: #export (text value)
(-> Text (Operation Inst))
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