From 299908a885d00ec735070a937f9720410fe224a9 Mon Sep 17 00:00:00 2001 From: Eduardo Julian Date: Thu, 17 Oct 2019 20:07:19 -0400 Subject: Ported JVM pattern-matching & loop generation to the new JVM bytecode machinery. --- new-luxc/source/luxc/lang/translation/jvm/case.lux | 12 +++++++++--- new-luxc/source/luxc/lang/translation/jvm/loop.lux | 8 ++++---- new-luxc/source/luxc/lang/translation/jvm/runtime.lux | 9 --------- 3 files changed, 13 insertions(+), 16 deletions(-) (limited to 'new-luxc/source/luxc/lang') diff --git a/new-luxc/source/luxc/lang/translation/jvm/case.lux b/new-luxc/source/luxc/lang/translation/jvm/case.lux index 484604323..7ea571450 100644 --- a/new-luxc/source/luxc/lang/translation/jvm/case.lux +++ b/new-luxc/source/luxc/lang/translation/jvm/case.lux @@ -39,17 +39,23 @@ (def: peekI Inst (|>> _.DUP - runtime.peekI)) + (_.int +0) + _.AALOAD)) (def: pushI Inst - (|>> (_.INVOKESTATIC //.$Runtime "pm_push" (type.method [(list runtime.$Stack //.$Value) runtime.$Stack (list)])))) + (_.INVOKESTATIC //.$Runtime "pm_push" (type.method [(list runtime.$Stack //.$Value) runtime.$Stack (list)]))) + +(def: popI + (|>> (_.int +1) + _.AALOAD + (_.CHECKCAST runtime.$Stack))) (def: (path' phase stack-depth @else @end path) (-> Phase Nat Label Label Path (Operation Inst)) (.case path #synthesis.Pop - (operation@wrap runtime.popI) + (operation@wrap ..popI) (#synthesis.Bind register) (operation@wrap (|>> peekI diff --git a/new-luxc/source/luxc/lang/translation/jvm/loop.lux b/new-luxc/source/luxc/lang/translation/jvm/loop.lux index 5b4f981f6..bc5ca5b98 100644 --- a/new-luxc/source/luxc/lang/translation/jvm/loop.lux +++ b/new-luxc/source/luxc/lang/translation/jvm/loop.lux @@ -22,14 +22,14 @@ ["_" inst]]]]] ["." //]) -(def: (constant? register changeS) +(def: (invariant? register changeS) (-> Register Synthesis Bit) (case changeS (^ (synthesis.variable/local var)) (n.= register var) _ - #0)) + false)) (def: #export (recur translate argsS) (-> Phase (List Synthesis) (Operation Inst)) @@ -48,13 +48,13 @@ ## should be the case. valuesI+ (monad.map @ (function (_ [register argS]) (: (Operation Inst) - (if (constant? register argS) + (if (invariant? register argS) (wrap function.identity) (translate argS)))) pairs) #let [storesI+ (list/map (function (_ [register argS]) (: Inst - (if (constant? register argS) + (if (invariant? register argS) function.identity (_.ASTORE register)))) (list.reverse pairs))]] diff --git a/new-luxc/source/luxc/lang/translation/jvm/runtime.lux b/new-luxc/source/luxc/lang/translation/jvm/runtime.lux index c0e48f30d..ce271c4c9 100644 --- a/new-luxc/source/luxc/lang/translation/jvm/runtime.lux +++ b/new-luxc/source/luxc/lang/translation/jvm/runtime.lux @@ -132,15 +132,6 @@ (_.wrap type.double)))) )) -(def: #export popI - (|>> (_.int +1) - _.AALOAD - (_.CHECKCAST $Stack))) - -(def: #export peekI - (|>> (_.int +0) - _.AALOAD)) - (def: (illegal-state-exception message) (-> Text Inst) (let [IllegalStateException (type.class "java.lang.IllegalStateException" (list))] -- cgit v1.2.3