diff options
Diffstat (limited to '')
-rw-r--r-- | luxc/src/lux/analyser.clj | 4 | ||||
-rw-r--r-- | luxc/src/lux/analyser/base.clj | 16 | ||||
-rw-r--r-- | luxc/src/lux/analyser/function.clj (renamed from luxc/src/lux/analyser/lambda.clj) | 4 | ||||
-rw-r--r-- | luxc/src/lux/analyser/lux.clj | 36 | ||||
-rw-r--r-- | luxc/src/lux/analyser/proc/jvm.clj | 1 | ||||
-rw-r--r-- | luxc/src/lux/compiler/jvm.clj | 4 | ||||
-rw-r--r-- | luxc/src/lux/compiler/jvm/function.clj (renamed from luxc/src/lux/compiler/jvm/lambda.clj) | 48 | ||||
-rw-r--r-- | luxc/src/lux/compiler/jvm/lux.clj | 4 | ||||
-rw-r--r-- | luxc/src/lux/optimizer.clj | 4 |
9 files changed, 60 insertions, 61 deletions
diff --git a/luxc/src/lux/analyser.clj b/luxc/src/lux/analyser.clj index 4090cfea8..c47eaddfa 100644 --- a/luxc/src/lux/analyser.clj +++ b/luxc/src/lux/analyser.clj @@ -119,13 +119,13 @@ (&/with-analysis-meta cursor exo-type (&&lux/analyse-case analyse exo-type ?value ?branches))) - "_lux_lambda" + "_lux_function" (|let [(&/$Cons [_ (&/$SymbolS "" ?self)] (&/$Cons [_ (&/$SymbolS "" ?arg)] (&/$Cons ?body (&/$Nil)))) parameters] (&/with-analysis-meta cursor exo-type - (&&lux/analyse-lambda analyse exo-type ?self ?arg ?body))) + (&&lux/analyse-function analyse exo-type ?self ?arg ?body))) "_lux_proc" (|let [(&/$Cons [_ (&/$TupleS (&/$Cons [_ (&/$TextS ?category)] diff --git a/luxc/src/lux/analyser/base.clj b/luxc/src/lux/analyser/base.clj index f4718a67e..46eafa051 100644 --- a/luxc/src/lux/analyser/base.clj +++ b/luxc/src/lux/analyser/base.clj @@ -17,7 +17,7 @@ ("tuple" 1) ("apply" 2) ("case" 2) - ("lambda" 4) + ("function" 4) ("ann" 2) ("var" 1) ("captured" 1) @@ -104,13 +104,13 @@ (&/T [_pattern (de-meta _body)]))) branches)) - ($lambda _register-offset scope captured body) - ($lambda _register-offset scope - (&/|map (fn [branch] - (|let [[_name _captured] branch] - (&/T [_name (de-meta _captured)]))) - captured) - (de-meta body)) + ($function _register-offset scope captured body) + ($function _register-offset scope + (&/|map (fn [branch] + (|let [[_name _captured] branch] + (&/T [_name (de-meta _captured)]))) + captured) + (de-meta body)) ($ann value-expr type-expr) (de-meta value-expr) diff --git a/luxc/src/lux/analyser/lambda.clj b/luxc/src/lux/analyser/function.clj index fdea7521a..aaaaed9f9 100644 --- a/luxc/src/lux/analyser/lambda.clj +++ b/luxc/src/lux/analyser/function.clj @@ -1,4 +1,4 @@ -(ns lux.analyser.lambda +(ns lux.analyser.function (:require clojure.core.match clojure.core.match.array (lux [base :as & :refer [|let |do return |case]] @@ -7,7 +7,7 @@ [env :as &env]))) ;; [Resource] -(defn with-lambda [self self-type arg arg-type body] +(defn with-function [self self-type arg arg-type body] (&/with-closure (|do [scope-name &/get-scope-name] (&env/with-local self self-type diff --git a/luxc/src/lux/analyser/lux.clj b/luxc/src/lux/analyser/lux.clj index 989ccb591..04ef66683 100644 --- a/luxc/src/lux/analyser/lux.clj +++ b/luxc/src/lux/analyser/lux.clj @@ -8,7 +8,7 @@ [type :as &type] [host :as &host]) (lux.analyser [base :as &&] - [lambda :as &&lambda] + [function :as &&function] [case :as &&case] [env :as &&env] [module :as &&module] @@ -302,7 +302,7 @@ (|let [scopes (&/|map #(&/get$ &/$name %) (&/|reverse inner)) [=local inner*] (&/fold2 (fn [register+new-inner frame in-scope] (|let [[register new-inner] register+new-inner - [register* frame*] (&&lambda/close-over in-scope name register frame)] + [register* frame*] (&&function/close-over in-scope name register frame)] (&/T [register* (&/$Cons frame* new-inner)]))) (&/T [(or (->> bottom-outer (&/get$ &/$locals) (&/get$ &/$mappings) (&/|get name)) (->> bottom-outer (&/get$ &/$closure) (&/get$ &/$mappings) (&/|get name))) @@ -464,25 +464,25 @@ =func** (&type/clean $output =func*)] (return =func**)))) -(defn analyse-lambda* [analyse exo-type ?self ?arg ?body] +(defn analyse-function* [analyse exo-type ?self ?arg ?body] (|case exo-type (&/$VarT id) (|do [? (&type/bound? id)] (if ? (|do [exo-type* (&type/deref id)] - (analyse-lambda* analyse exo-type* ?self ?arg ?body)) + (analyse-function* analyse exo-type* ?self ?arg ?body)) ;; Inference (&type/with-var (fn [$input] (&type/with-var (fn [$output] - (|do [[[lambda-type lambda-cursor] lambda-analysis] (analyse-lambda* analyse (&/$LambdaT $input $output) ?self ?arg ?body) + (|do [[[function-type function-cursor] function-analysis] (analyse-function* analyse (&/$LambdaT $input $output) ?self ?arg ?body) =input (&type/resolve-type $input) =output (&type/resolve-type $output) inferred-type (clean-func-inference $input $output =input (embed-inferred-input =input =output)) _ (&type/check exo-type inferred-type)] - (return (&&/|meta inferred-type lambda-cursor - lambda-analysis))) + (return (&&/|meta inferred-type function-cursor + function-analysis))) )))))) _ @@ -494,23 +494,23 @@ :let [(&/$ExT $var-id) $var] exo-type** (&type/apply-type exo-type* $var)] (&/with-scope-type-var $var-id - (analyse-lambda* analyse exo-type** ?self ?arg ?body))) + (analyse-function* analyse exo-type** ?self ?arg ?body))) (&/$ExQ _) (&type/with-var (fn [$var] (|do [exo-type** (&type/apply-type exo-type* $var) - =expr (analyse-lambda* analyse exo-type** ?self ?arg ?body)] + =expr (analyse-function* analyse exo-type** ?self ?arg ?body)] (&&/clean-analysis $var =expr)))) (&/$LambdaT ?arg-t ?return-t) - (|do [[=scope =captured =body] (&&lambda/with-lambda ?self exo-type* + (|do [[=scope =captured =body] (&&function/with-function ?self exo-type* ?arg ?arg-t (&&/analyse-1 analyse ?return-t ?body)) _cursor &/cursor register-offset &&env/next-local-idx] (return (&&/|meta exo-type* _cursor - (&&/$lambda register-offset =scope =captured =body)))) + (&&/$function register-offset =scope =captured =body)))) _ (&/fail ""))) @@ -518,14 +518,14 @@ (&/fail-with-loc (str err "\n" "[Analyser Error] Functions require function types: " (&type/show-type exo-type))))) )) -(defn analyse-lambda** [analyse exo-type ?self ?arg ?body] +(defn analyse-function** [analyse exo-type ?self ?arg ?body] (|case exo-type (&/$UnivQ _) (|do [$var &type/existential :let [(&/$ExT $var-id) $var] exo-type* (&type/apply-type exo-type $var) [_ _expr] (&/with-scope-type-var $var-id - (analyse-lambda** analyse exo-type* ?self ?arg ?body)) + (analyse-function** analyse exo-type* ?self ?arg ?body)) _cursor &/cursor] (return (&&/|meta exo-type _cursor _expr))) @@ -533,17 +533,17 @@ (|do [? (&type/bound? id)] (if ? (|do [exo-type* (&type/actual-type exo-type)] - (analyse-lambda* analyse exo-type* ?self ?arg ?body)) + (analyse-function* analyse exo-type* ?self ?arg ?body)) ;; Inference - (analyse-lambda* analyse exo-type ?self ?arg ?body))) + (analyse-function* analyse exo-type ?self ?arg ?body))) _ (|do [exo-type* (&type/actual-type exo-type)] - (analyse-lambda* analyse exo-type* ?self ?arg ?body)) + (analyse-function* analyse exo-type* ?self ?arg ?body)) )) -(defn analyse-lambda [analyse exo-type ?self ?arg ?body] - (|do [output (analyse-lambda** analyse exo-type ?self ?arg ?body)] +(defn analyse-function [analyse exo-type ?self ?arg ?body] + (|do [output (analyse-function** analyse exo-type ?self ?arg ?body)] (return (&/|list output)))) (defn analyse-def [analyse optimize eval! compile-def ?name ?value ?meta] diff --git a/luxc/src/lux/analyser/proc/jvm.clj b/luxc/src/lux/analyser/proc/jvm.clj index ec14aabb0..3fc3e2e8c 100644 --- a/luxc/src/lux/analyser/proc/jvm.clj +++ b/luxc/src/lux/analyser/proc/jvm.clj @@ -12,7 +12,6 @@ [lux.type.host :as &host-type] [lux.host.generics :as &host-generics] (lux.analyser [base :as &&] - [lambda :as &&lambda] [env :as &&env] [parser :as &&a-parser]) [lux.compiler.jvm.base :as &c!base]) diff --git a/luxc/src/lux/compiler/jvm.clj b/luxc/src/lux/compiler/jvm.clj index 150ec54f4..b612c9f35 100644 --- a/luxc/src/lux/compiler/jvm.clj +++ b/luxc/src/lux/compiler/jvm.clj @@ -24,7 +24,7 @@ (lux.compiler.jvm [base :as &&] [lux :as &&lux] [case :as &&case] - [lambda :as &&lambda] + [function :as &&function] [rt :as &&rt] [cache :as &&jvm-cache]) (lux.compiler.jvm.proc [common :as &&proc-common] @@ -105,7 +105,7 @@ (&&lux/compile-if (partial compile-expression $begin) _test _then _else) (&o/$function _register-offset ?arity ?scope ?env ?body) - (&&lambda/compile-function compile-expression &/$None ?arity ?scope ?env ?body) + (&&function/compile-function compile-expression &/$None ?arity ?scope ?env ?body) (&o/$ann ?value-ex ?type-ex) (compile-expression $begin ?value-ex) diff --git a/luxc/src/lux/compiler/jvm/lambda.clj b/luxc/src/lux/compiler/jvm/function.clj index 87d977012..83c1fb95c 100644 --- a/luxc/src/lux/compiler/jvm/lambda.clj +++ b/luxc/src/lux/compiler/jvm/function.clj @@ -1,4 +1,4 @@ -(ns lux.compiler.jvm.lambda +(ns lux.compiler.jvm.function (:require (clojure [string :as string] [set :as set] [template :refer [do-template]]) @@ -21,7 +21,7 @@ ;; [Utils] (def ^:private field-sig (&host-generics/->type-signature "java.lang.Object")) -(def ^:private lambda-return-sig (&host-generics/->type-signature "java.lang.Object")) +(def ^:private function-return-sig (&host-generics/->type-signature "java.lang.Object")) (def ^:private <init>-return "V") (defn ^:private ^String reset-signature [function-class] @@ -67,10 +67,10 @@ (-> (consecutive-applys (+ start &&/num-apply-variants) (- amount &&/num-apply-variants)) (->> (when (> amount &&/num-apply-variants))))))) -(defn ^:private lambda-impl-signature [arity] - (str "(" (&/fold str "" (&/|repeat arity field-sig)) ")" lambda-return-sig)) +(defn ^:private function-impl-signature [arity] + (str "(" (&/fold str "" (&/|repeat arity field-sig)) ")" function-return-sig)) -(defn ^:private lambda-<init>-signature [env arity] +(defn ^:private function-<init>-signature [env arity] (if (> arity 1) (str "(" (&/fold str "" (&/|repeat (&/|length env) field-sig)) "I" (&/fold str "" (&/|repeat (dec arity) field-sig)) ")" <init>-return) @@ -86,9 +86,9 @@ (.visitVarInsn Opcodes/ILOAD (inc closure-length)) (.visitMethodInsn Opcodes/INVOKESPECIAL &&/function-class "<init>" "(I)V")))) -(defn ^:private add-lambda-<init> [^ClassWriter class class-name arity env] +(defn ^:private add-function-<init> [^ClassWriter class class-name arity env] (let [closure-length (&/|length env)] - (doto (.visitMethod class Opcodes/ACC_PUBLIC "<init>" (lambda-<init>-signature env arity) nil nil) + (doto (.visitMethod class Opcodes/ACC_PUBLIC "<init>" (function-<init>-signature env arity) nil nil) (.visitCode) ;; Do normal object initialization (.visitVarInsn Opcodes/ALOAD 0) @@ -107,9 +107,9 @@ (.visitEnd)))) (let [impl-flags (+ Opcodes/ACC_PUBLIC Opcodes/ACC_FINAL)] - (defn ^:private add-lambda-impl [^ClassWriter class class-name compile arity impl-body] + (defn ^:private add-function-impl [^ClassWriter class class-name compile arity impl-body] (let [$begin (new Label)] - (&/with-writer (doto (.visitMethod class impl-flags "impl" (lambda-impl-signature arity) nil nil) + (&/with-writer (doto (.visitMethod class impl-flags "impl" (function-impl-signature arity) nil nil) (.visitCode) (.visitLabel $begin)) (|do [^MethodVisitor *writer* &/get-writer @@ -120,10 +120,10 @@ (.visitEnd))]] (return ret)))))) -(defn ^:private instance-closure [compile lambda-class arity closed-over] +(defn ^:private instance-closure [compile function-class arity closed-over] (|do [^MethodVisitor *writer* &/get-writer :let [_ (doto *writer* - (.visitTypeInsn Opcodes/NEW lambda-class) + (.visitTypeInsn Opcodes/NEW function-class) (.visitInsn Opcodes/DUP))] _ (&/map% (fn [?name+?captured] (|case ?name+?captured @@ -134,10 +134,10 @@ (doto *writer* (.visitLdcInsn (int 0)) (fill-nulls! (dec arity))))] - :let [_ (.visitMethodInsn *writer* Opcodes/INVOKESPECIAL lambda-class "<init>" (lambda-<init>-signature closed-over arity))]] + :let [_ (.visitMethodInsn *writer* Opcodes/INVOKESPECIAL function-class "<init>" (function-<init>-signature closed-over arity))]] (return nil))) -(defn ^:private add-lambda-reset [^ClassWriter class-writer class-name arity env] +(defn ^:private add-function-reset [^ClassWriter class-writer class-name arity env] (if (> arity 1) (doto (.visitMethod class-writer Opcodes/ACC_PUBLIC "reset" (reset-signature class-name) nil nil) (.visitCode) @@ -147,7 +147,7 @@ (->> (dotimes [cidx (&/|length env)]))) (.visitLdcInsn (int 0)) (fill-nulls! (dec arity)) - (.visitMethodInsn Opcodes/INVOKESPECIAL class-name "<init>" (lambda-<init>-signature env arity)) + (.visitMethodInsn Opcodes/INVOKESPECIAL class-name "<init>" (function-<init>-signature env arity)) (.visitInsn Opcodes/ARETURN) (.visitMaxs 0 0) (.visitEnd)) @@ -158,7 +158,7 @@ (.visitMaxs 0 0) (.visitEnd)))) -(defn ^:private add-lambda-apply-n [^ClassWriter class-writer +degree+ class-name arity env compile impl-body] +(defn ^:private add-function-apply-n [^ClassWriter class-writer +degree+ class-name arity env compile impl-body] (if (> arity 1) (let [num-partials (dec arity) $default (new Label) @@ -185,7 +185,7 @@ (->> (dotimes [idx stage]))) (consecutive-args 1 +degree+) (fill-nulls! (- (- num-partials +degree+) stage)) - (.visitMethodInsn Opcodes/INVOKESPECIAL class-name "<init>" (lambda-<init>-signature env arity)) + (.visitMethodInsn Opcodes/INVOKESPECIAL class-name "<init>" (function-<init>-signature env arity)) (.visitJumpInsn Opcodes/GOTO $end)) (->> (cond (= stage arity-over-extent) (doto method-writer @@ -196,7 +196,7 @@ (-> (get-field! class-name (str &&/partial-prefix idx)) (->> (dotimes [idx stage]))) (consecutive-args 1 +degree+) - (.visitMethodInsn Opcodes/INVOKEVIRTUAL class-name "impl" (lambda-impl-signature arity)) + (.visitMethodInsn Opcodes/INVOKEVIRTUAL class-name "impl" (function-impl-signature arity)) (.visitJumpInsn Opcodes/GOTO $end)) (> stage arity-over-extent) @@ -209,7 +209,7 @@ (-> (get-field! class-name (str &&/partial-prefix idx)) (->> (dotimes [idx stage]))) (consecutive-args 1 args-to-completion) - (.visitMethodInsn Opcodes/INVOKEVIRTUAL class-name "impl" (lambda-impl-signature arity)) + (.visitMethodInsn Opcodes/INVOKEVIRTUAL class-name "impl" (function-impl-signature arity)) (consecutive-applys (+ 1 args-to-completion) args-left) (.visitJumpInsn Opcodes/GOTO $end))) @@ -234,7 +234,7 @@ )) ;; [Exports] -(let [lambda-flags (+ Opcodes/ACC_PUBLIC Opcodes/ACC_FINAL Opcodes/ACC_SUPER) +(let [function-flags (+ Opcodes/ACC_PUBLIC Opcodes/ACC_FINAL Opcodes/ACC_SUPER) datum-flags (+ Opcodes/ACC_PRIVATE Opcodes/ACC_FINAL)] (defn compile-function [compile ?prev-writer arity ?scope ?env ?body] (|do [[file-name _ _] &/cursor @@ -247,7 +247,7 @@ (&/$None) (&/T [(doto (new ClassWriter ClassWriter/COMPUTE_MAXS) - (.visit &host/bytecode-version lambda-flags + (.visit &host/bytecode-version function-flags class-name nil &&/function-class (into-array String []))) true])) _ (doto =class @@ -264,13 +264,13 @@ (->> (dotimes [idx (dec arity)]))) (-> (.visitSource file-name nil) (when save?)) - (add-lambda-<init> class-name arity ?env) - (add-lambda-reset class-name arity ?env) + (add-function-<init> class-name arity ?env) + (add-function-reset class-name arity ?env) )] _ (if (> arity 1) - (add-lambda-impl =class class-name compile arity ?body) + (add-function-impl =class class-name compile arity ?body) (return nil)) - _ (&/map% #(add-lambda-apply-n =class % class-name arity ?env compile ?body) + _ (&/map% #(add-function-apply-n =class % class-name arity ?env compile ?body) (&/|range* 1 (min arity &&/num-apply-variants))) :let [_ (.visitEnd =class)] _ (if save? diff --git a/luxc/src/lux/compiler/jvm/lux.clj b/luxc/src/lux/compiler/jvm/lux.clj index e14615946..882c9b74c 100644 --- a/luxc/src/lux/compiler/jvm/lux.clj +++ b/luxc/src/lux/compiler/jvm/lux.clj @@ -16,7 +16,7 @@ [module :as &a-module] [meta :as &a-meta]) (lux.compiler.jvm [base :as &&] - [lambda :as &&lambda])) + [function :as &&function])) (:import (org.objectweb.asm Opcodes Label ClassWriter @@ -286,7 +286,7 @@ (-> (.visitField field-flags &/value-field datum-sig nil nil) (doto (.visitEnd))) (.visitSource file-name nil))] - instancer (&&lambda/compile-function compile (&/$Some =class) _arity _scope _captured ?body+) + instancer (&&function/compile-function compile (&/$Some =class) _arity _scope _captured ?body+) _ (&/with-writer (.visitMethod =class Opcodes/ACC_STATIC "<clinit>" "()V" nil nil) (|do [^MethodVisitor **writer** &/get-writer :let [_ (.visitCode **writer**)] diff --git a/luxc/src/lux/optimizer.clj b/luxc/src/lux/optimizer.clj index 9fc50646e..36caf3362 100644 --- a/luxc/src/lux/optimizer.clj +++ b/luxc/src/lux/optimizer.clj @@ -1142,9 +1142,9 @@ _ (normal-case-optim))) - (&a/$lambda _register-offset scope captured body) + (&a/$function _register-offset scope captured body) (|let [inner-func? (|case body - [_ (&a/$lambda _ _ _ _)] + [_ (&a/$function _ _ _ _)] true _ |