diff options
author | Eduardo Julian | 2018-07-31 20:22:15 -0400 |
---|---|---|
committer | Eduardo Julian | 2018-07-31 20:22:15 -0400 |
commit | 7e44ee8a2cfb14e35f6283a9eb8d6a2ddc8bd99a (patch) | |
tree | 98a12aa5a9fd347c1070612a2a1dae69dae879b1 /luxc/src | |
parent | eea58ee669f69fddf2cef9e1675c41959e2e0a55 (diff) |
Now implementing process functionality in stdlib instead of the compiler.
Diffstat (limited to 'luxc/src')
-rw-r--r-- | luxc/src/lux/analyser/proc/common.clj | 19 | ||||
-rw-r--r-- | luxc/src/lux/compiler/jvm.clj | 3 | ||||
-rw-r--r-- | luxc/src/lux/compiler/jvm/proc/common.clj | 28 | ||||
-rw-r--r-- | luxc/src/lux/compiler/jvm/rt.clj | 90 |
4 files changed, 2 insertions, 138 deletions
diff --git a/luxc/src/lux/analyser/proc/common.clj b/luxc/src/lux/analyser/proc/common.clj index 38f6bc6c3..df6fb0051 100644 --- a/luxc/src/lux/analyser/proc/common.clj +++ b/luxc/src/lux/analyser/proc/common.clj @@ -322,22 +322,6 @@ (return (&/|list (&&/|meta exo-type _cursor (&&/$proc (&/T ["box" "write"]) (&/|list valueA boxA) (&/|list))))))))))) -(defn ^:private analyse-process-parallelism [analyse exo-type ?values] - (|do [:let [(&/$Nil) ?values] - _ (&type/check exo-type &type/Nat) - _cursor &/cursor] - (return (&/|list (&&/|meta exo-type _cursor - (&&/$proc (&/T ["process" "parallelism"]) (&/|list) (&/|list))))))) - -(defn ^:private analyse-process-schedule [analyse exo-type ?values] - (|do [:let [(&/$Cons ?milliseconds (&/$Cons ?procedure (&/$Nil))) ?values] - =milliseconds (&&/analyse-1 analyse &type/Nat ?milliseconds) - =procedure (&&/analyse-1 analyse (&/$Apply &type/Any &type/IO) ?procedure) - _ (&type/check exo-type &type/Any) - _cursor &/cursor] - (return (&/|list (&&/|meta exo-type _cursor - (&&/$proc (&/T ["process" "schedule"]) (&/|list =milliseconds =procedure) (&/|list))))))) - (defn analyse-proc [analyse exo-type proc ?values] (try (case proc "lux is" (analyse-lux-is analyse exo-type ?values) @@ -397,9 +381,6 @@ "lux frac max" (analyse-frac-max analyse exo-type ?values) "lux frac int" (analyse-frac-int analyse exo-type ?values) - "lux process parallelism" (analyse-process-parallelism analyse exo-type ?values) - "lux process schedule" (analyse-process-schedule analyse exo-type ?values) - ;; else (&/fail-with-loc (str "[Analyser Error] Unknown host procedure: " proc))) (catch Exception ex diff --git a/luxc/src/lux/compiler/jvm.clj b/luxc/src/lux/compiler/jvm.clj index 60a2c7d2e..8e2966b52 100644 --- a/luxc/src/lux/compiler/jvm.clj +++ b/luxc/src/lux/compiler/jvm.clj @@ -197,8 +197,7 @@ (.visitSource file-name nil))] _ (if (= "lux" name) (|do [_ &&rt/compile-Function-class - _ &&rt/compile-LuxRT-class - _ &&rt/compile-LuxRunnable-class] + _ &&rt/compile-LuxRT-class] (return nil)) (return nil))] (fn [state] diff --git a/luxc/src/lux/compiler/jvm/proc/common.clj b/luxc/src/lux/compiler/jvm/proc/common.clj index 6f05b3e52..6e89155bc 100644 --- a/luxc/src/lux/compiler/jvm/proc/common.clj +++ b/luxc/src/lux/compiler/jvm/proc/common.clj @@ -505,28 +505,6 @@ (.visitLdcInsn &/unit-tag))]] (return nil))) -(defn ^:private compile-process-parallelism [compile ?values special-args] - (|do [:let [(&/$Nil) ?values] - ^MethodVisitor *writer* &/get-writer - :let [_ (doto *writer* - (.visitFieldInsn Opcodes/GETSTATIC "lux/LuxRT" "concurrency_level" "I") - (.visitInsn Opcodes/I2L) - &&/wrap-long)]] - (return nil))) - -(defn ^:private compile-process-schedule [compile ?values special-args] - (|do [:let [(&/$Cons ?milliseconds (&/$Cons ?procedure (&/$Nil))) ?values] - ^MethodVisitor *writer* &/get-writer - _ (compile ?milliseconds) - :let [_ (doto *writer* - &&/unwrap-long)] - _ (compile ?procedure) - :let [_ (doto *writer* - (.visitTypeInsn Opcodes/CHECKCAST "lux/Function"))] - :let [_ (doto *writer* - (.visitMethodInsn Opcodes/INVOKESTATIC "lux/LuxRT" "schedule" "(JLlux/Function;)Ljava/lang/Object;"))]] - (return nil))) - (defn compile-proc [compile category proc ?values special-args] (case category "lux" @@ -607,11 +585,5 @@ "write" (compile-box-write compile ?values special-args) ) - "process" - (case proc - "parallelism" (compile-process-parallelism compile ?values special-args) - "schedule" (compile-process-schedule compile ?values special-args) - ) - ;; else (&/fail-with-loc (str "[Compiler Error] Unknown procedure: " [category proc])))) diff --git a/luxc/src/lux/compiler/jvm/rt.clj b/luxc/src/lux/compiler/jvm/rt.clj index 0f9c4cb86..7dd08dc62 100644 --- a/luxc/src/lux/compiler/jvm/rt.clj +++ b/luxc/src/lux/compiler/jvm/rt.clj @@ -66,36 +66,6 @@ (&&/save-class! (second (string/split &&/function-class #"/")) (.toByteArray (doto =class .visitEnd))))) -;; Custom Runnable -(def compile-LuxRunnable-class - (|do [_ (return nil) - :let [=class (doto (new ClassWriter ClassWriter/COMPUTE_MAXS) - (.visit &host/bytecode-version (+ Opcodes/ACC_PUBLIC Opcodes/ACC_FINAL Opcodes/ACC_SUPER) - "lux/LuxRunnable" nil "java/lang/Object" (into-array String ["java/lang/Runnable"]))) - _ (doto (.visitField =class Opcodes/ACC_PUBLIC "procedure" "Llux/Function;" nil nil) - (.visitEnd)) - _ (doto (.visitMethod =class Opcodes/ACC_PUBLIC init-method "(Llux/Function;)V" nil nil) - (.visitCode) - (.visitVarInsn Opcodes/ALOAD 0) - (.visitMethodInsn Opcodes/INVOKESPECIAL "java/lang/Object" init-method "()V") - (.visitVarInsn Opcodes/ALOAD 0) - (.visitVarInsn Opcodes/ALOAD 1) - (.visitFieldInsn Opcodes/PUTFIELD "lux/LuxRunnable" "procedure" "Llux/Function;") - (.visitInsn Opcodes/RETURN) - (.visitMaxs 0 0) - (.visitEnd)) - _ (doto (.visitMethod =class Opcodes/ACC_PUBLIC "run" "()V" nil nil) - (.visitCode) - (.visitVarInsn Opcodes/ALOAD 0) - (.visitFieldInsn Opcodes/GETFIELD "lux/LuxRunnable" "procedure" "Llux/Function;") - (.visitInsn Opcodes/ACONST_NULL) - (.visitMethodInsn Opcodes/INVOKEVIRTUAL "lux/Function" &&/apply-method (&&/apply-signature 1)) - (.visitInsn Opcodes/RETURN) - (.visitMaxs 0 0) - (.visitEnd))]] - (&&/save-class! "LuxRunnable" - (.toByteArray (doto =class .visitEnd))))) - ;; Runtime infrastructure (defn ^:private compile-LuxRT-adt-methods [^ClassWriter =class] (|let [_ (let [$begin (new Label) @@ -415,63 +385,6 @@ (.visitEnd))) nil)) -(defn ^:private compile-LuxRT-process-methods [^ClassWriter =class] - (do (doto (.visitField =class - (+ Opcodes/ACC_PUBLIC Opcodes/ACC_FINAL Opcodes/ACC_STATIC) - "concurrency_level" "I" nil nil) - (.visitEnd)) - (doto (.visitField =class - (+ Opcodes/ACC_PUBLIC Opcodes/ACC_FINAL Opcodes/ACC_STATIC) - "executor" "Ljava/util/concurrent/ScheduledThreadPoolExecutor;" nil nil) - (.visitEnd)) - (doto (.visitMethod =class Opcodes/ACC_STATIC "<clinit>" "()V" nil nil) - (.visitCode) - ;; concurrency_level - (.visitMethodInsn Opcodes/INVOKESTATIC "java/lang/Runtime" "getRuntime" "()Ljava/lang/Runtime;") - (.visitMethodInsn Opcodes/INVOKEVIRTUAL "java/lang/Runtime" "availableProcessors" "()I") - (.visitFieldInsn Opcodes/PUTSTATIC "lux/LuxRT" "concurrency_level" "I") - ;; executor - (.visitTypeInsn Opcodes/NEW "java/util/concurrent/ScheduledThreadPoolExecutor") - (.visitInsn Opcodes/DUP) - (.visitFieldInsn Opcodes/GETSTATIC "lux/LuxRT" "concurrency_level" "I") - (.visitMethodInsn Opcodes/INVOKESPECIAL "java/util/concurrent/ScheduledThreadPoolExecutor" "<init>" "(I)V") - (.visitFieldInsn Opcodes/PUTSTATIC "lux/LuxRT" "executor" "Ljava/util/concurrent/ScheduledThreadPoolExecutor;") - ;; DONE - (.visitInsn Opcodes/RETURN) - (.visitMaxs 0 0) - (.visitEnd)) - (let [$immediately (new Label)] - (doto (.visitMethod =class (+ Opcodes/ACC_PUBLIC Opcodes/ACC_STATIC) "schedule" "(JLlux/Function;)Ljava/lang/Object;" nil nil) - (.visitCode) - (.visitVarInsn Opcodes/LLOAD 0) - (.visitLdcInsn (long 0)) - (.visitInsn Opcodes/LCMP) - (.visitJumpInsn Opcodes/IFEQ $immediately) - ;; Schedule for later - (.visitFieldInsn Opcodes/GETSTATIC "lux/LuxRT" "executor" "Ljava/util/concurrent/ScheduledThreadPoolExecutor;") - (.visitTypeInsn Opcodes/NEW "lux/LuxRunnable") - (.visitInsn Opcodes/DUP) - (.visitVarInsn Opcodes/ALOAD 2) - (.visitMethodInsn Opcodes/INVOKESPECIAL "lux/LuxRunnable" "<init>" "(Llux/Function;)V") - (.visitVarInsn Opcodes/LLOAD 0) - (.visitFieldInsn Opcodes/GETSTATIC "java/util/concurrent/TimeUnit" "MILLISECONDS" "Ljava/util/concurrent/TimeUnit;") - (.visitMethodInsn Opcodes/INVOKEVIRTUAL "java/util/concurrent/ScheduledThreadPoolExecutor" "schedule" "(Ljava/lang/Runnable;JLjava/util/concurrent/TimeUnit;)Ljava/util/concurrent/ScheduledFuture;") - (.visitLdcInsn &/unit-tag) - (.visitInsn Opcodes/ARETURN) - ;; Run immediately - (.visitLabel $immediately) - (.visitFieldInsn Opcodes/GETSTATIC "lux/LuxRT" "executor" "Ljava/util/concurrent/ScheduledThreadPoolExecutor;") - (.visitTypeInsn Opcodes/NEW "lux/LuxRunnable") - (.visitInsn Opcodes/DUP) - (.visitVarInsn Opcodes/ALOAD 2) - (.visitMethodInsn Opcodes/INVOKESPECIAL "lux/LuxRunnable" "<init>" "(Llux/Function;)V") - (.visitMethodInsn Opcodes/INVOKEINTERFACE "java/util/concurrent/Executor" "execute" "(Ljava/lang/Runnable;)V") - (.visitLdcInsn &/unit-tag) - (.visitInsn Opcodes/ARETURN) - (.visitMaxs 0 0) - (.visitEnd))) - nil)) - (def compile-LuxRT-class (|do [_ (return nil) :let [full-name &&/lux-utils-class @@ -577,7 +490,6 @@ (compile-LuxRT-adt-methods) (compile-LuxRT-int-methods) (compile-LuxRT-frac-methods) - (compile-LuxRT-text-methods) - (compile-LuxRT-process-methods))]] + (compile-LuxRT-text-methods))]] (&&/save-class! (second (string/split &&/lux-utils-class #"/")) (.toByteArray (doto =class .visitEnd))))) |