diff options
author | Eduardo Julian | 2019-05-01 22:33:17 -0400 |
---|---|---|
committer | Eduardo Julian | 2019-05-01 22:33:17 -0400 |
commit | b52409599fc5e93ad20e1aa61e44b75f5d6d2789 (patch) | |
tree | db39a8208b316c0e47d9d0fffce12108e2e7b82a | |
parent | 868c300ada4095e0e32ad4495b61aed02b23bfc0 (diff) |
Now inlining the pattern-matching POP and PEEK operations.
Diffstat (limited to '')
-rw-r--r-- | luxc/src/lux/compiler/jvm/case.clj | 13 | ||||
-rw-r--r-- | luxc/src/lux/compiler/jvm/rt.clj | 28 | ||||
-rw-r--r-- | new-luxc/source/luxc/lang/translation/jvm/case.lux | 18 | ||||
-rw-r--r-- | new-luxc/source/luxc/lang/translation/jvm/runtime.lux | 20 |
4 files changed, 29 insertions, 50 deletions
diff --git a/luxc/src/lux/compiler/jvm/case.clj b/luxc/src/lux/compiler/jvm/case.clj index aa262a102..01b5b924c 100644 --- a/luxc/src/lux/compiler/jvm/case.clj +++ b/luxc/src/lux/compiler/jvm/case.clj @@ -11,7 +11,8 @@ [host :as &host] [optimizer :as &o]) [lux.analyser.case :as &a-case] - [lux.compiler.jvm.base :as &&]) + [lux.compiler.jvm.base :as &&] + [lux.compiler.jvm.rt :as &rt]) (:import (org.objectweb.asm Opcodes Label ClassWriter @@ -38,10 +39,11 @@ (defn ^:private stack-peek [^MethodVisitor writer] (doto writer (.visitInsn Opcodes/DUP) - (.visitMethodInsn Opcodes/INVOKESTATIC "lux/LuxRT" "pm_stack_peek" "([Ljava/lang/Object;)Ljava/lang/Object;"))) + &rt/peekI)) -(defn ^:private compile-pattern* [^MethodVisitor writer bodies stack-depth $else pm] +(defn ^:private compile-pattern* "(-> MethodVisitor Case-Pattern (List Label) Int Label MethodVisitor)" + [^MethodVisitor writer bodies stack-depth $else pm] (|case pm (&o/$ExecPM _body-idx) (|case (&/|at _body-idx bodies) @@ -54,14 +56,13 @@ (assert false)) (&o/$PopPM) - (doto writer - (.visitMethodInsn Opcodes/INVOKESTATIC "lux/LuxRT" "pm_stack_pop" "([Ljava/lang/Object;)[Ljava/lang/Object;")) + (&rt/popI writer) (&o/$BindPM _var-id) (doto writer stack-peek (.visitVarInsn Opcodes/ASTORE _var-id) - (.visitMethodInsn Opcodes/INVOKESTATIC "lux/LuxRT" "pm_stack_pop" "([Ljava/lang/Object;)[Ljava/lang/Object;")) + &rt/popI) (&o/$BitPM _value) (doto writer diff --git a/luxc/src/lux/compiler/jvm/rt.clj b/luxc/src/lux/compiler/jvm/rt.clj index b64d7312b..4a8b470ac 100644 --- a/luxc/src/lux/compiler/jvm/rt.clj +++ b/luxc/src/lux/compiler/jvm/rt.clj @@ -289,6 +289,17 @@ ^:private compile-LuxRT-frac-methods "decode_frac" "java/lang/Double" "parseDouble" "(Ljava/lang/String;)D" &&/wrap-double ) +(defn popI [writer] + (doto writer + (.visitLdcInsn (int 0)) + (.visitInsn Opcodes/AALOAD) + (.visitTypeInsn Opcodes/CHECKCAST "[Ljava/lang/Object;"))) + +(defn peekI [writer] + (doto writer + (.visitLdcInsn (int 1)) + (.visitInsn Opcodes/AALOAD))) + (defn ^:private compile-LuxRT-pm-methods [^ClassWriter =class] (|let [_ (doto (.visitMethod =class (+ Opcodes/ACC_PUBLIC Opcodes/ACC_STATIC) "pm_fail" "()V" nil nil) (.visitCode) @@ -313,23 +324,6 @@ (.visitInsn Opcodes/AASTORE) (.visitInsn Opcodes/ARETURN) (.visitMaxs 0 0) - (.visitEnd)) - _ (doto (.visitMethod =class (+ Opcodes/ACC_PUBLIC Opcodes/ACC_STATIC) "pm_stack_pop" "([Ljava/lang/Object;)[Ljava/lang/Object;" nil nil) - (.visitCode) - (.visitVarInsn Opcodes/ALOAD 0) - (.visitLdcInsn (int 0)) - (.visitInsn Opcodes/AALOAD) - (.visitTypeInsn Opcodes/CHECKCAST "[Ljava/lang/Object;") - (.visitInsn Opcodes/ARETURN) - (.visitMaxs 0 0) - (.visitEnd)) - _ (doto (.visitMethod =class (+ Opcodes/ACC_PUBLIC Opcodes/ACC_STATIC) "pm_stack_peek" "([Ljava/lang/Object;)Ljava/lang/Object;" nil nil) - (.visitCode) - (.visitVarInsn Opcodes/ALOAD 0) - (.visitLdcInsn (int 1)) - (.visitInsn Opcodes/AALOAD) - (.visitInsn Opcodes/ARETURN) - (.visitMaxs 0 0) (.visitEnd))] nil)) diff --git a/new-luxc/source/luxc/lang/translation/jvm/case.lux b/new-luxc/source/luxc/lang/translation/jvm/case.lux index 3c50f6124..63d440c72 100644 --- a/new-luxc/source/luxc/lang/translation/jvm/case.lux +++ b/new-luxc/source/luxc/lang/translation/jvm/case.lux @@ -36,21 +36,7 @@ (def: peekI Inst (|>> _.DUP - (_.INVOKESTATIC //.runtime-class - "pm_peek" - ($t.method (list runtime.$Stack) - (#.Some $Object) - (list)) - #0))) - -(def: popI - Inst - (|>> (_.INVOKESTATIC //.runtime-class - "pm_pop" - ($t.method (list runtime.$Stack) - (#.Some runtime.$Stack) - (list)) - #0))) + runtime.peekI)) (def: pushI Inst @@ -65,7 +51,7 @@ (-> Phase Nat Label Label Path (Operation Inst)) (.case path #synthesis.Pop - (operation@wrap popI) + (operation@wrap runtime.popI) (#synthesis.Bind register) (operation@wrap (|>> peekI diff --git a/new-luxc/source/luxc/lang/translation/jvm/runtime.lux b/new-luxc/source/luxc/lang/translation/jvm/runtime.lux index fa250e2bf..175a60e80 100644 --- a/new-luxc/source/luxc/lang/translation/jvm/runtime.lux +++ b/new-luxc/source/luxc/lang/translation/jvm/runtime.lux @@ -132,6 +132,15 @@ (_.wrap #$t.Double)))) )) +(def: #export popI + (|>> (_.int +0) + _.AALOAD + (_.CHECKCAST ($t.descriptor $Stack)))) + +(def: #export peekI + (|>> (_.int +1) + _.AALOAD)) + (def: pm-methods Def (let [tuple-sizeI (|>> (_.ALOAD 0) _.ARRAYLENGTH) @@ -171,17 +180,6 @@ (_.ALOAD 1) _.AASTORE _.ARETURN)) - ($d.method #$.Public $.staticM "pm_pop" ($t.method (list $Stack) (#.Some $Stack) (list)) - (|>> (_.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) - _.AALOAD - _.ARETURN)) ($d.method #$.Public $.staticM "pm_variant" ($t.method (list $Variant $Tag $Flag) (#.Some $Object) (list)) (<| _.with-label (function (_ @loop)) _.with-label (function (_ @just-return)) |