aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source/lux/tool
diff options
context:
space:
mode:
authorEduardo Julian2020-10-09 01:16:47 -0400
committerEduardo Julian2020-10-09 01:16:47 -0400
commitbae39f32cddb816a6123697269c20dbf4a65ac19 (patch)
treed9ee53073ebe0d83e29dbd24e0dda8d5dd95dc47 /stdlib/source/lux/tool
parent79aa92dfd81d569fe6120b8e5c00d41528801153 (diff)
Also using BIPUSH and SIPUSH during JVM generation.
Diffstat (limited to 'stdlib/source/lux/tool')
-rw-r--r--stdlib/source/lux/tool/compiler/language/lux/phase/generation/jvm/case.lux32
-rw-r--r--stdlib/source/lux/tool/compiler/language/lux/phase/generation/jvm/function/field/variable/partial/count.lux4
-rw-r--r--stdlib/source/lux/tool/compiler/language/lux/phase/generation/jvm/primitive.lux28
-rw-r--r--stdlib/source/lux/tool/compiler/language/lux/phase/generation/jvm/runtime.lux2
-rw-r--r--stdlib/source/lux/tool/compiler/language/lux/phase/generation/jvm/structure.lux55
5 files changed, 74 insertions, 47 deletions
diff --git a/stdlib/source/lux/tool/compiler/language/lux/phase/generation/jvm/case.lux b/stdlib/source/lux/tool/compiler/language/lux/phase/generation/jvm/case.lux
index 889ac0265..a81e9f244 100644
--- a/stdlib/source/lux/tool/compiler/language/lux/phase/generation/jvm/case.lux
+++ b/stdlib/source/lux/tool/compiler/language/lux/phase/generation/jvm/case.lux
@@ -19,6 +19,7 @@
["#." type]
["#." runtime (#+ Operation Phase Generator)]
["#." value]
+ ["#." structure]
[////
["." synthesis (#+ Path Synthesis)]
["." generation]
@@ -106,8 +107,8 @@
bodyG
(_.goto @end))))
- (^template [<pattern> <flag> <prepare>]
- (^ (<pattern> idx))
+ (^template [<pattern> <right?>]
+ (^ (<pattern> lefts))
(operation@wrap
(do _.monad
[@success _.new-label
@@ -115,8 +116,8 @@
($_ _.compose
..peek
(_.checkcast //type.variant)
- (..int (<prepare> idx))
- <flag>
+ (//structure.tag lefts <right?>)
+ (//structure.flag <right?>)
//runtime.case
_.dup
(_.ifnull @fail)
@@ -126,21 +127,18 @@
(_.goto @else)
(_.set-label @success)
//runtime.push))))
- ([synthesis.side/left //runtime.left-flag function.identity]
- [synthesis.side/right //runtime.right-flag .inc])
+ ([synthesis.side/left false]
+ [synthesis.side/right true])
- (^ (synthesis.member/left lefts))
- (operation@wrap ($_ _.compose
- ..peek
- (..left-projection lefts)
- //runtime.push))
+ (^template [<pattern> <projection>]
+ (^ (<pattern> lefts))
+ (operation@wrap ($_ _.compose
+ ..peek
+ (<projection> lefts)
+ //runtime.push)))
+ ([synthesis.member/left ..left-projection]
+ [synthesis.member/right ..right-projection])
- (^ (synthesis.member/right lefts))
- (operation@wrap ($_ _.compose
- ..peek
- (..right-projection lefts)
- //runtime.push))
-
## Extra optimization
(^ (synthesis.path/seq
(synthesis.member/left 0)
diff --git a/stdlib/source/lux/tool/compiler/language/lux/phase/generation/jvm/function/field/variable/partial/count.lux b/stdlib/source/lux/tool/compiler/language/lux/phase/generation/jvm/function/field/variable/partial/count.lux
index 579a63992..2701862f1 100644
--- a/stdlib/source/lux/tool/compiler/language/lux/phase/generation/jvm/function/field/variable/partial/count.lux
+++ b/stdlib/source/lux/tool/compiler/language/lux/phase/generation/jvm/function/field/variable/partial/count.lux
@@ -7,7 +7,7 @@
["_" bytecode (#+ Bytecode)]
[encoding
[name (#+ External)]
- ["." unsigned]]
+ ["." signed]]
["." type]]]]
["." ///// #_
["#." abstract]])
@@ -17,7 +17,7 @@
(def: #export initial
(Bytecode Any)
- (|> 0 unsigned.u1 try.assume _.bipush))
+ (|> +0 signed.s1 try.assume _.bipush))
(def: this
_.aload-0)
diff --git a/stdlib/source/lux/tool/compiler/language/lux/phase/generation/jvm/primitive.lux b/stdlib/source/lux/tool/compiler/language/lux/phase/generation/jvm/primitive.lux
index 798288768..8f281fb3a 100644
--- a/stdlib/source/lux/tool/compiler/language/lux/phase/generation/jvm/primitive.lux
+++ b/stdlib/source/lux/tool/compiler/language/lux/phase/generation/jvm/primitive.lux
@@ -6,7 +6,9 @@
[target
[jvm
["_" bytecode (#+ Bytecode)]
- ["." type]]]]
+ ["." type]
+ [encoding
+ ["." signed]]]]]
["." // #_
["#." runtime]])
@@ -46,10 +48,26 @@
[+4 _.iconst-4]
[+5 _.iconst-5])
- _
- (do _.monad
- [_ (|> value .int _.long)]
- ..wrap-i64)))
+ value
+ (case (signed.s1 value)
+ (#try.Success value)
+ (do _.monad
+ [_ (_.bipush value)
+ _ _.i2l]
+ ..wrap-i64)
+
+ (#try.Failure _)
+ (case (signed.s2 value)
+ (#try.Success value)
+ (do _.monad
+ [_ (_.sipush value)
+ _ _.i2l]
+ ..wrap-i64)
+
+ (#try.Failure _)
+ (do _.monad
+ [_ (_.long value)]
+ ..wrap-i64)))))
(def: wrap-f64
(_.invokestatic $Double "valueOf" (type.method [(list type.double) $Double (list)])))
diff --git a/stdlib/source/lux/tool/compiler/language/lux/phase/generation/jvm/runtime.lux b/stdlib/source/lux/tool/compiler/language/lux/phase/generation/jvm/runtime.lux
index 224fba5b9..679599858 100644
--- a/stdlib/source/lux/tool/compiler/language/lux/phase/generation/jvm/runtime.lux
+++ b/stdlib/source/lux/tool/compiler/language/lux/phase/generation/jvm/runtime.lux
@@ -177,7 +177,7 @@
(Bytecode Any)
($_ _.compose
_.iconst-0
- _.aconst-null
+ ..left-flag
..unit
..variant))
diff --git a/stdlib/source/lux/tool/compiler/language/lux/phase/generation/jvm/structure.lux b/stdlib/source/lux/tool/compiler/language/lux/phase/generation/jvm/structure.lux
index d48874257..79eafb572 100644
--- a/stdlib/source/lux/tool/compiler/language/lux/phase/generation/jvm/structure.lux
+++ b/stdlib/source/lux/tool/compiler/language/lux/phase/generation/jvm/structure.lux
@@ -10,7 +10,9 @@
[target
[jvm
["_" bytecode (#+ Bytecode)]
- ["." type]]]]
+ ["." type]
+ [encoding
+ ["." signed]]]]]
["." // #_
["#." runtime (#+ Operation Phase Generator)]
["#." primitive]
@@ -23,15 +25,11 @@
(def: $Object
(type.class "java.lang.Object" (list)))
-(def: unitG
- (Bytecode Any)
- (//primitive.text /////synthesis.unit))
-
(def: #export (tuple generate archive membersS)
(Generator (Tuple Synthesis))
(case membersS
#.Nil
- (:: phase.monad wrap ..unitG)
+ (:: phase.monad wrap //runtime.unit)
(#.Cons singletonS #.Nil)
(generate archive singletonS)
@@ -53,29 +51,42 @@
_ (_.anewarray $Object)]
(monad.seq @ membersI))))))
-(def: (flagG right?)
+(def: #export (tag lefts right?)
+ (-> Nat Bit (Bytecode Any))
+ (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 (case (signed.s1 (.int tag))
+ (#try.Success value)
+ (_.bipush value)
+
+ (#try.Failure _)
+ (case (signed.s2 (.int tag))
+ (#try.Success value)
+ (_.sipush value)
+
+ (#try.Failure _)
+ (_.int (.i64 tag))))))
+
+(def: #export (flag right?)
(-> Bit (Bytecode Any))
(if right?
- ..unitG
- _.aconst-null))
+ //runtime.right-flag
+ //runtime.left-flag))
(def: #export (variant generate archive [lefts right? valueS])
(Generator (Variant Synthesis))
(do phase.monad
- [valueI (generate archive valueS)
- #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 (.i64 tag)))]]
+ [valueI (generate archive valueS)]
(wrap (do _.monad
- [_ tagI
- _ (flagG right?)
+ [_ (..tag lefts right?)
+ _ (..flag right?)
_ valueI]
(_.invokestatic //runtime.class "variant"
(type.method [(list type.int $Object $Object)