aboutsummaryrefslogtreecommitdiff
path: root/lux-jvm/source/luxc/lang/translation/jvm/case.lux
diff options
context:
space:
mode:
authorEduardo Julian2020-06-01 20:16:32 -0400
committerEduardo Julian2020-06-01 20:16:32 -0400
commita6987ad82f107df49853e1601b73076d030d6fc8 (patch)
treeb5562ec12fcee4a87b0c6ca4d485e7ac82ffbfec /lux-jvm/source/luxc/lang/translation/jvm/case.lux
parent1546feb83e8e821ee8bbf3dea736a49a072bcd52 (diff)
Implemented an optimization for getting fields/slots from records in the new compiler.
Diffstat (limited to 'lux-jvm/source/luxc/lang/translation/jvm/case.lux')
-rw-r--r--lux-jvm/source/luxc/lang/translation/jvm/case.lux58
1 files changed, 42 insertions, 16 deletions
diff --git a/lux-jvm/source/luxc/lang/translation/jvm/case.lux b/lux-jvm/source/luxc/lang/translation/jvm/case.lux
index 0d8aaa91e..23f84ad4e 100644
--- a/lux-jvm/source/luxc/lang/translation/jvm/case.lux
+++ b/lux-jvm/source/luxc/lang/translation/jvm/case.lux
@@ -7,7 +7,9 @@
["ex" exception (#+ exception:)]]
[data
[number
- ["n" nat]]]
+ ["n" nat]]
+ [collection
+ ["." list ("#@." fold)]]]
[target
[jvm
["." type (#+ Type)
@@ -21,7 +23,8 @@
[archive (#+ Archive)]]
[language
[lux
- ["." synthesis (#+ Path Synthesis)]]]]]]
+ ["." synthesis (#+ Path Synthesis)
+ ["#/." case]]]]]]]
[luxc
[lang
[host
@@ -55,6 +58,24 @@
_.AALOAD
(_.CHECKCAST runtime.$Stack)))
+(def: (left-projection lefts)
+ (-> Nat Inst)
+ (.let [accessI (.case lefts
+ 0
+ _.AALOAD
+
+ lefts
+ (_.INVOKESTATIC //.$Runtime "tuple_left" (type.method [(list //.$Tuple runtime.$Index) //.$Value (list)])))]
+ (|>> (_.CHECKCAST //.$Tuple)
+ (_.int (.int lefts))
+ accessI)))
+
+(def: (right-projection lefts)
+ (-> Nat Inst)
+ (|>> (_.CHECKCAST //.$Tuple)
+ (_.int (.int lefts))
+ (_.INVOKESTATIC //.$Runtime "tuple_right" (type.method [(list //.$Tuple runtime.$Index) //.$Value (list)]))))
+
(def: (path' stack-depth @else @end phase archive path)
(-> Nat Label Label Phase Archive Path (Operation Inst))
(.case path
@@ -121,23 +142,13 @@
[synthesis.side/right (_.string "") .inc])
(^ (synthesis.member/left lefts))
- (operation@wrap (.let [accessI (.case lefts
- 0
- _.AALOAD
-
- lefts
- (_.INVOKESTATIC //.$Runtime "tuple_left" (type.method [(list //.$Tuple runtime.$Index) //.$Value (list)])))]
- (|>> peekI
- (_.CHECKCAST //.$Tuple)
- (_.int (.int lefts))
- accessI
- pushI)))
+ (operation@wrap (|>> peekI
+ (..left-projection lefts)
+ pushI))
(^ (synthesis.member/right lefts))
(operation@wrap (|>> peekI
- (_.CHECKCAST //.$Tuple)
- (_.int (.int lefts))
- (_.INVOKESTATIC //.$Runtime "tuple_right" (type.method [(list //.$Tuple runtime.$Index) //.$Value (list)]))
+ (..right-projection lefts)
pushI))
## Extra optimization
@@ -226,6 +237,21 @@
(_.ASTORE register)
exprI))))
+(def: #export (get phase archive [path recordS])
+ (Generator [(List synthesis.Member) Synthesis])
+ (do phase.monad
+ [recordG (phase archive recordS)]
+ (wrap (list@fold (function (_ step so-far)
+ (.let [next (.case step
+ (#.Left lefts)
+ (..left-projection lefts)
+
+ (#.Right lefts)
+ (..right-projection lefts))]
+ (|>> so-far next)))
+ recordG
+ path))))
+
(def: #export (case phase archive [valueS path])
(Generator [Synthesis Path])
(do phase.monad