From a59fc865aee240afe21b82ffef2681bb9a6ea693 Mon Sep 17 00:00:00 2001 From: Eduardo Julian Date: Sun, 29 Jul 2018 02:30:13 -0400 Subject: Adapted new-luxc to some of the latest changes to Lux. --- .../luxc/lang/translation/jvm/runtime.jvm.lux | 152 ++++++++++----------- 1 file changed, 76 insertions(+), 76 deletions(-) (limited to 'new-luxc/source/luxc/lang/translation/jvm/runtime.jvm.lux') diff --git a/new-luxc/source/luxc/lang/translation/jvm/runtime.jvm.lux b/new-luxc/source/luxc/lang/translation/jvm/runtime.jvm.lux index 86efad1ab..28bce7d28 100644 --- a/new-luxc/source/luxc/lang/translation/jvm/runtime.jvm.lux +++ b/new-luxc/source/luxc/lang/translation/jvm/runtime.jvm.lux @@ -23,9 +23,9 @@ ["." // (#+ ByteCode)]) (def: $Object $.Type ($t.class "java.lang.Object" (list))) -(def: $Object-Array $.Type ($t.array +1 $Object)) +(def: $Object-Array $.Type ($t.array 1 $Object)) (def: $String $.Type ($t.class "java.lang.String" (list))) -(def: #export $Stack $.Type ($t.array +1 $Object)) +(def: #export $Stack $.Type ($t.array 1 $Object)) (def: #export $Tuple $.Type $Object-Array) (def: #export $Variant $.Type $Object-Array) (def: #export $Tag $.Type $t.int) @@ -53,7 +53,7 @@ (def: #export leftI Inst - (|>> (_.int 0) + (|>> (_.int +0) _.NULL _.DUP2_X1 _.POP2 @@ -61,7 +61,7 @@ (def: #export rightI Inst - (|>> (_.int 1) + (|>> (_.int +1) (_.string "") _.DUP2_X1 _.POP2 @@ -71,7 +71,7 @@ (def: #export noneI Inst - (|>> (_.int 0) + (|>> (_.int +0) _.NULL (_.string //.unit) variantI)) @@ -97,7 +97,7 @@ (def: #export partials-field Text "partials") (def: #export apply-method Text "apply") -(def: #export num-apply-variants Nat +8) +(def: #export num-apply-variants Nat 8) (def: #export (apply-signature arity) (-> Arity Method) @@ -105,9 +105,9 @@ (def: adt-methods Def - (let [store-tagI (|>> _.DUP (_.int 0) (_.ILOAD +0) (_.wrap #$.Int) _.AASTORE) - store-flagI (|>> _.DUP (_.int 1) (_.ALOAD +1) _.AASTORE) - store-valueI (|>> _.DUP (_.int 2) (_.ALOAD +2) _.AASTORE) + (let [store-tagI (|>> _.DUP (_.int +0) (_.ILOAD 0) (_.wrap #$.Int) _.AASTORE) + store-flagI (|>> _.DUP (_.int +1) (_.ALOAD 1) _.AASTORE) + store-valueI (|>> _.DUP (_.int +2) (_.ALOAD 2) _.AASTORE) force-textMT ($t.method (list $Object) (#.Some $String) (list))] (|>> ($d.method #$.Public $.staticM "force_text" force-textMT (<| _.with-label (function (_ @is-null)) @@ -117,10 +117,10 @@ _.with-label (function (_ @is-first)) _.with-label (function (_ @elem-end)) _.with-label (function (_ @fold-end)) - (let [on-normal-objectI (|>> (_.ALOAD +0) + (let [on-normal-objectI (|>> (_.ALOAD 0) (_.INVOKEVIRTUAL "java.lang.Object" "toString" ($t.method (list) (#.Some $String) (list)) #0)) on-null-objectI (_.string "NULL") - arrayI (|>> (_.ALOAD +0) + arrayI (|>> (_.ALOAD 0) (_.CHECKCAST ($t.descriptor $Object-Array))) recurseI (_.INVOKESTATIC //.runtime-class "force_text" force-textMT #0) force-elemI (|>> _.DUP arrayI _.SWAP _.AALOAD recurseI) @@ -140,10 +140,10 @@ force-elemI merge-with-totalI (_.label @elem-end) ## TSI ) - inc-idxI (|>> (_.int 1) _.IADD) + inc-idxI (|>> (_.int +1) _.IADD) on-array-objectI (|>> (_.string "[") ## T arrayI _.ARRAYLENGTH ## TS - (_.int 0) ## TSI + (_.int +0) ## TSI (_.label @array-loop) ## TSI _.DUP2 (_.IF_ICMPGT @within-bounds) ## TSI @@ -151,9 +151,9 @@ (_.label @within-bounds) foldI inc-idxI (_.GOTO @array-loop) (_.label @fold-end))]) - (|>> (_.ALOAD +0) + (|>> (_.ALOAD 0) (_.IFNULL @is-null) - (_.ALOAD +0) + (_.ALOAD 0) (_.INSTANCEOF ($t.descriptor $Object-Array)) (_.IFEQ @normal-object) on-array-objectI _.ARETURN @@ -163,7 +163,7 @@ ($t.method (list $t.int $Object $Object) (#.Some $Variant) (list)) - (|>> (_.int 3) + (|>> (_.int +3) (_.array $Object) store-tagI store-flagI @@ -174,13 +174,13 @@ Inst (_.INVOKESTATIC //.runtime-class "force_text" ($t.method (list $Object) (#.Some $String) (list)) #0)) -(def: frac-shiftI Inst (_.double (math.pow 32.0 2.0))) +(def: frac-shiftI Inst (_.double (math.pow +32.0 +2.0))) (def: frac-methods Def (|>> ($d.method #$.Public $.staticM "decode_frac" ($t.method (list $String) (#.Some $Object-Array) (list)) (try-methodI - (|>> (_.ALOAD +0) + (|>> (_.ALOAD 0) (_.INVOKESTATIC "java.lang.Double" "parseDouble" ($t.method (list $String) (#.Some $t.double) (list)) #0) (_.wrap #$.Double)))) )) @@ -191,14 +191,14 @@ Def (|>> ($d.method #$.Public $.staticM "text_clip" ($t.method (list $String $t.int $t.int) (#.Some $Variant) (list)) (try-methodI - (|>> (_.ALOAD +0) - (_.ILOAD +1) - (_.ILOAD +2) + (|>> (_.ALOAD 0) + (_.ILOAD 1) + (_.ILOAD 2) (_.INVOKEVIRTUAL "java.lang.String" "substring" ($t.method (list $t.int $t.int) (#.Some $String) (list)) #0)))) ($d.method #$.Public $.staticM "text_char" ($t.method (list $String $t.int) (#.Some $Variant) (list)) (try-methodI - (|>> (_.ALOAD +0) - (_.ILOAD +1) + (|>> (_.ALOAD 0) + (_.ILOAD 1) (_.INVOKEVIRTUAL "java.lang.String" "codePointAt" ($t.method (list $t.int) (#.Some $t.int) (list)) #0) _.I2L (_.wrap #$.Long)))) @@ -206,10 +206,10 @@ (def: pm-methods Def - (let [tuple-sizeI (|>> (_.ALOAD +0) _.ARRAYLENGTH) - tuple-elemI (|>> (_.ALOAD +0) (_.ILOAD +1) _.AALOAD) - expected-last-sizeI (|>> (_.ILOAD +1) (_.int 1) _.IADD) - tuple-tailI (|>> (_.ALOAD +0) tuple-sizeI (_.int 1) _.ISUB _.AALOAD (_.CHECKCAST ($t.descriptor $Tuple)))] + (let [tuple-sizeI (|>> (_.ALOAD 0) _.ARRAYLENGTH) + tuple-elemI (|>> (_.ALOAD 0) (_.ILOAD 1) _.AALOAD) + expected-last-sizeI (|>> (_.ILOAD 1) (_.int +1) _.IADD) + tuple-tailI (|>> (_.ALOAD 0) tuple-sizeI (_.int +1) _.ISUB _.AALOAD (_.CHECKCAST ($t.descriptor $Tuple)))] (|>> ($d.method #$.Public $.staticM "pm_fail" ($t.method (list) #.None (list)) (|>> (_.NEW "java.lang.IllegalStateException") _.DUP @@ -223,26 +223,26 @@ (_.INVOKESPECIAL "java.lang.IllegalStateException" "" ($t.method (list $String) #.None (list)) #0) _.ATHROW)) ($d.method #$.Public $.staticM "pm_push" ($t.method (list $Stack $Object) (#.Some $Stack) (list)) - (|>> (_.int 2) + (|>> (_.int +2) (_.ANEWARRAY "java.lang.Object") _.DUP - (_.int 0) - (_.ALOAD +0) + (_.int +0) + (_.ALOAD 0) _.AASTORE _.DUP - (_.int 1) - (_.ALOAD +1) + (_.int +1) + (_.ALOAD 1) _.AASTORE _.ARETURN)) ($d.method #$.Public $.staticM "pm_pop" ($t.method (list $Stack) (#.Some $Stack) (list)) - (|>> (_.ALOAD +0) - (_.int 0) + (|>> (_.ALOAD 0) + (_.int +0) _.AALOAD (_.CHECKCAST ($t.descriptor $Stack)) _.ARETURN)) ($d.method #$.Public $.staticM "pm_peek" ($t.method (list $Stack) (#.Some $Object) (list)) - (|>> (_.ALOAD +0) - (_.int 1) + (|>> (_.ALOAD 0) + (_.int +1) _.AALOAD _.ARETURN)) ($d.method #$.Public $.staticM "pm_variant" ($t.method (list $Variant $Tag $Flag) (#.Some $Object) (list)) @@ -256,33 +256,33 @@ (function (_ idx) (|>> (_.int (.int idx)) _.AALOAD))) tagI (: Inst - (|>> (variant-partI +0) (_.unwrap #$.Int))) - flagI (variant-partI +1) - datumI (variant-partI +2) - shortenI (|>> (_.ALOAD +0) tagI ## Get tag - (_.ILOAD +1) _.ISUB ## Shorten tag - (_.ALOAD +0) flagI ## Get flag - (_.ALOAD +0) datumI ## Get value + (|>> (variant-partI 0) (_.unwrap #$.Int))) + flagI (variant-partI 1) + datumI (variant-partI 2) + shortenI (|>> (_.ALOAD 0) tagI ## Get tag + (_.ILOAD 1) _.ISUB ## Shorten tag + (_.ALOAD 0) flagI ## Get flag + (_.ALOAD 0) datumI ## Get value variantI ## Build sum _.ARETURN) - update-tagI (|>> _.ISUB (_.ISTORE +1)) - update-variantI (|>> (_.ALOAD +0) datumI (_.CHECKCAST ($t.descriptor $Variant)) (_.ASTORE +0)) + update-tagI (|>> _.ISUB (_.ISTORE 1)) + update-variantI (|>> (_.ALOAD 0) datumI (_.CHECKCAST ($t.descriptor $Variant)) (_.ASTORE 0)) failureI (|>> _.NULL _.ARETURN) - return-datumI (|>> (_.ALOAD +0) datumI _.ARETURN)]) + return-datumI (|>> (_.ALOAD 0) datumI _.ARETURN)]) (|>> (_.label @begin) - (_.ILOAD +1) ## tag - (_.ALOAD +0) tagI ## tag, sumT + (_.ILOAD 1) ## tag + (_.ALOAD 0) tagI ## tag, sumT _.DUP2 (_.IF_ICMPEQ @then) _.DUP2 (_.IF_ICMPGT @further) _.DUP2 (_.IF_ICMPLT @shorten) ## _.POP2 failureI (_.label @then) ## tag, sumT - (_.ALOAD +2) ## tag, sumT, wants-last? - (_.ALOAD +0) flagI ## tag, sumT, wants-last?, is-last? + (_.ALOAD 2) ## tag, sumT, wants-last? + (_.ALOAD 0) flagI ## tag, sumT, wants-last?, is-last? (_.IF_ACMPEQ @just-return) ## tag, sumT (_.label @further) ## tag, sumT - (_.ALOAD +0) flagI ## tag, sumT, last? + (_.ALOAD 0) flagI ## tag, sumT, last? (_.IFNULL @wrong) ## tag, sumT update-tagI update-variantI @@ -291,7 +291,7 @@ ## _.POP2 return-datumI (_.label @shorten) ## tag, sumT - (_.ALOAD +2) (_.IFNULL @wrong) + (_.ALOAD 2) (_.IFNULL @wrong) ## _.POP2 shortenI (_.label @wrong) ## tag, sumT @@ -306,8 +306,8 @@ expected-last-sizeI _.DUP2 (_.IF_ICMPGT @not-recursive) ## Recursive - updated-idxI (_.ISTORE +1) - tuple-tailI (_.ASTORE +0) + updated-idxI (_.ISTORE 1) + tuple-tailI (_.ASTORE 0) (_.GOTO @begin) (_.label @not-recursive) ## _.POP2 @@ -317,8 +317,8 @@ (<| _.with-label (function (_ @begin)) _.with-label (function (_ @tail)) _.with-label (function (_ @slice)) - (let [updated-idxI (|>> (_.ILOAD +1) (_.int 1) _.IADD tuple-sizeI _.ISUB) - sliceI (|>> (_.ALOAD +0) (_.ILOAD +1) tuple-sizeI + (let [updated-idxI (|>> (_.ILOAD 1) (_.int +1) _.IADD tuple-sizeI _.ISUB) + sliceI (|>> (_.ALOAD 0) (_.ILOAD 1) tuple-sizeI (_.INVOKESTATIC "java.util.Arrays" "copyOfRange" ($t.method (list $Object-Array $t.int $t.int) (#.Some $Object-Array) (list)) #0))]) (|>> (_.label @begin) tuple-sizeI @@ -326,8 +326,8 @@ _.DUP2 (_.IF_ICMPEQ @tail) (_.IF_ICMPGT @slice) ## Must recurse - tuple-tailI (_.ASTORE +0) - updated-idxI (_.ISTORE +1) + tuple-tailI (_.ASTORE 0) + updated-idxI (_.ISTORE 1) (_.GOTO @begin) (_.label @slice) sliceI @@ -357,9 +357,9 @@ _.with-label (function (_ @handler)) (|>> (_.try @from @to @handler "java.lang.Throwable") (_.label @from) - (_.ALOAD +0) + (_.ALOAD 0) _.NULL - (_.INVOKEVIRTUAL //.function-class apply-method (apply-signature +1) #0) + (_.INVOKEVIRTUAL //.function-class apply-method (apply-signature 1) #0) rightI _.ARETURN (_.label @to) @@ -405,21 +405,21 @@ _.RETURN))) ($d.method #$.Public $.staticM "schedule" ($t.method (list $t.long $Function) (#.Some $Object) (list)) - (let [delayI (_.LLOAD +0) + (let [delayI (_.LLOAD 0) immediacy-checkI (|>> delayI - (_.long 0) + (_.long +0) _.LCMP) time-unit-class "java.util.concurrent.TimeUnit" time-unitT ($t.class time-unit-class (list)) futureT ($t.class "java.util.concurrent.ScheduledFuture" (list)) executorI (_.GETSTATIC //.runtime-class executor-field executorT) schedule-laterI (|>> executorI - (runnableI (_.ALOAD +2)) + (runnableI (_.ALOAD 2)) delayI (_.GETSTATIC time-unit-class "MILLISECONDS" time-unitT) (_.INVOKEVIRTUAL executor-class "schedule" ($t.method (list $Runnable $t.long time-unitT) (#.Some futureT) (list)) #0)) schedule-immediatelyI (|>> executorI - (runnableI (_.ALOAD +2)) + (runnableI (_.ALOAD 2)) (_.INVOKEVIRTUAL executor-class "execute" ($t.method (list $Runnable) #.None (list)) #0))] (<| _.with-label (function (_ @immediately)) (|>> immediacy-checkI @@ -446,27 +446,27 @@ (def: translate-function (Operation ByteCode) - (let [applyI (|> (list.n/range +2 num-apply-variants) + (let [applyI (|> (list.n/range 2 num-apply-variants) (list/map (function (_ arity) ($d.method #$.Public $.noneM apply-method (apply-signature arity) - (let [preI (|> (list.n/range +0 (dec arity)) + (let [preI (|> (list.n/range 0 (dec arity)) (list/map _.ALOAD) _.fuse)] (|>> preI (_.INVOKEVIRTUAL //.function-class apply-method (apply-signature (dec arity)) #0) (_.CHECKCAST //.function-class) (_.ALOAD arity) - (_.INVOKEVIRTUAL //.function-class apply-method (apply-signature +1) #0) + (_.INVOKEVIRTUAL //.function-class apply-method (apply-signature 1) #0) _.ARETURN))))) - (list& ($d.abstract-method #$.Public $.noneM apply-method (apply-signature +1))) + (list& ($d.abstract-method #$.Public $.noneM apply-method (apply-signature 1))) $d.fuse) bytecode ($d.abstract #$.V1_6 #$.Public $.noneC //.function-class (list) ["java.lang.Object" (list)] (list) (|>> ($d.field #$.Public $.finalF partials-field $t.int) ($d.method #$.Public $.noneM "" ($t.method (list $t.int) #.None (list)) - (|>> (_.ALOAD +0) + (|>> (_.ALOAD 0) (_.INVOKESPECIAL "java.lang.Object" "" ($t.method (list) #.None (list)) #0) - (_.ALOAD +0) - (_.ILOAD +1) + (_.ALOAD 0) + (_.ILOAD 1) (_.PUTFIELD //.function-class partials-field $t.int) _.RETURN)) applyI))] @@ -480,17 +480,17 @@ bytecode ($d.class #$.V1_6 #$.Public $.finalC //.runnable-class (list) ["java.lang.Object" (list)] (list ["java.lang.Runnable" (list)]) (|>> ($d.field #$.Public $.finalF procedure-field $Function) ($d.method #$.Public $.noneM "" ($t.method (list $Function) #.None (list)) - (|>> (_.ALOAD +0) + (|>> (_.ALOAD 0) (_.INVOKESPECIAL "java.lang.Object" "" ($t.method (list) #.None (list)) #0) - (_.ALOAD +0) - (_.ALOAD +1) + (_.ALOAD 0) + (_.ALOAD 1) (_.PUTFIELD //.runnable-class procedure-field $Function) _.RETURN)) ($d.method #$.Public $.noneM "run" ($t.method (list) #.None (list)) - (|>> (_.ALOAD +0) + (|>> (_.ALOAD 0) (_.GETFIELD //.runnable-class procedure-field $Function) _.NULL - (_.INVOKEVIRTUAL //.function-class apply-method (apply-signature +1) #0) + (_.INVOKEVIRTUAL //.function-class apply-method (apply-signature 1) #0) _.RETURN)) ))] (do phase.Monad -- cgit v1.2.3