From a6987ad82f107df49853e1601b73076d030d6fc8 Mon Sep 17 00:00:00 2001 From: Eduardo Julian Date: Mon, 1 Jun 2020 20:16:32 -0400 Subject: Implemented an optimization for getting fields/slots from records in the new compiler. --- lux-jvm/source/luxc/lang/translation/jvm/case.lux | 58 ++++++++++++++++------- 1 file changed, 42 insertions(+), 16 deletions(-) (limited to 'lux-jvm/source/luxc/lang/translation/jvm/case.lux') 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 -- cgit v1.2.3