aboutsummaryrefslogtreecommitdiff
path: root/lux-jvm/source/luxc/lang/translation/jvm/primitive.lux
diff options
context:
space:
mode:
Diffstat (limited to 'lux-jvm/source/luxc/lang/translation/jvm/primitive.lux')
-rw-r--r--lux-jvm/source/luxc/lang/translation/jvm/primitive.lux33
1 files changed, 25 insertions, 8 deletions
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))