aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorEduardo Julian2015-05-03 17:27:30 -0400
committerEduardo Julian2015-05-03 17:27:30 -0400
commitbee6b4914135d3703524f505eed32a8779cdb5aa (patch)
tree73524d2628a97f20b3e3324350320296c3b6f700 /src
parent99dd3b322777d5abdaa976aa9445c168c234e139 (diff)
- Optimized the compiler by eliminating reflection.
Diffstat (limited to 'src')
-rw-r--r--src/lux/analyser/case.clj2
-rw-r--r--src/lux/analyser/lux.clj9
-rw-r--r--src/lux/analyser/module.clj2
-rw-r--r--src/lux/base.clj17
-rw-r--r--src/lux/compiler.clj7
-rw-r--r--src/lux/compiler/base.clj4
-rw-r--r--src/lux/compiler/case.clj8
-rw-r--r--src/lux/compiler/host.clj58
-rw-r--r--src/lux/compiler/lambda.clj41
-rw-r--r--src/lux/compiler/lux.clj24
-rw-r--r--src/lux/host.clj23
-rw-r--r--src/lux/parser.clj2
-rw-r--r--src/lux/reader.clj12
-rw-r--r--src/lux/type.clj2
14 files changed, 78 insertions, 133 deletions
diff --git a/src/lux/analyser/case.clj b/src/lux/analyser/case.clj
index 2e1dd5278..ea767d11c 100644
--- a/src/lux/analyser/case.clj
+++ b/src/lux/analyser/case.clj
@@ -124,7 +124,7 @@
(&&/analyse-1 analyse exo-type body))]
(return (&/|cons pattern+body patterns))))
-(let [compare-kv #(compare (aget %1 0) (aget %2 0))]
+(let [compare-kv #(.compareTo ^String (aget ^objects %1 0) ^String (aget ^objects %2 0))]
(defn ^:private merge-total [struct test+body]
(|let [[test ?body] test+body]
(matchv ::M/objects [struct test]
diff --git a/src/lux/analyser/lux.clj b/src/lux/analyser/lux.clj
index b52b816a7..47c18aded 100644
--- a/src/lux/analyser/lux.clj
+++ b/src/lux/analyser/lux.clj
@@ -235,9 +235,7 @@
(&type/set-var ?id ex)))
type** (&type/clean $var ?type*)]
(return (&/T ?expr* type**)))
-
- [_ _]
- (assert false (prn-str 'analyse-apply*/output (aget output 0)))))))
+ ))))
[["lux;LambdaT" [?input-t ?output-t]]]
;; (|do [=arg (&&/analyse-1 analyse ?input-t ?arg)]
@@ -264,10 +262,7 @@
(matchv ::M/objects [$def]
[["lux;MacroD" macro]]
(|do [macro-expansion #(-> macro (.apply ?args) (.apply %))]
- (do ;; (when (or (= "type`" ?name)
- ;; (= "deftype" ?name))
- ;; (prn 'macro-expansion (str ?module ";" ?name) (->> macro-expansion (&/|map &/show-ast) (&/|interpose " ") (&/fold str ""))))
- (&/flat-map% (partial analyse exo-type) macro-expansion)))
+ (&/flat-map% (partial analyse exo-type) macro-expansion))
[_]
(|do [output (analyse-apply* analyse exo-type =fn ?args)]
diff --git a/src/lux/analyser/module.clj b/src/lux/analyser/module.clj
index 921417c17..d2e0a745b 100644
--- a/src/lux/analyser/module.clj
+++ b/src/lux/analyser/module.clj
@@ -63,7 +63,7 @@
[["lux;ValueD" ?type]]
(do ;; (prn 'declare-macro/?type (aget ?type 0))
(&/run-state (|do [_ (&type/check &type/Macro ?type)
- loader &/loader
+ ^ClassLoader loader &/loader
:let [macro (-> (.loadClass loader (&host/location (&/|list module name)))
(.getField "_datum")
(.get nil))]]
diff --git a/src/lux/base.clj b/src/lux/base.clj
index 4b8045e8c..d06920d6f 100644
--- a/src/lux/base.clj
+++ b/src/lux/base.clj
@@ -40,10 +40,10 @@
(defn R [& kvs]
(to-array kvs))
-(defn get$ [slot record]
+(defn get$ [slot ^objects record]
(aget record slot))
-(defn set$ [slot value record]
+(defn set$ [slot value ^objects record]
(let [record* (aclone record)
size (alength record)]
(aset record* slot value)
@@ -157,25 +157,14 @@
(V "lux;Right" (T state value))))
(defn bind [m-value step]
- (when (not (fn? m-value))
- (prn 'bind (aget m-value 0)))
- (when (not (fn? step))
- (prn 'bind (aget step 0)))
- ;; (prn 'bind m-value step)
(fn [state]
(let [inputs (m-value state)]
(matchv ::M/objects [inputs]
[["lux;Right" [?state ?datum]]]
- (let [next-fn (step ?datum)]
- (when (not (fn? next-fn))
- (prn 'bind (aget next-fn 0) (aget next-fn 1)))
- (next-fn ?state))
+ ((step ?datum) ?state)
[["lux;Left" _]]
inputs
-
- ;; [_]
- ;; (assert false (pr-str 'bind/inputs (aget inputs 0)))
))))
(defmacro |do [steps return]
diff --git a/src/lux/compiler.clj b/src/lux/compiler.clj
index 4f8ed727f..9aa734f3c 100644
--- a/src/lux/compiler.clj
+++ b/src/lux/compiler.clj
@@ -176,9 +176,6 @@
[["jvm-dgt" [?x ?y]]]
(&&host/compile-jvm-dgt compile-expression ?type ?x ?y)
- [["|do" ?exprs]]
- (&&host/compile-|do compile-expression ?type ?exprs)
-
[["jvm-null" _]]
(&&host/compile-jvm-null compile-expression ?type)
@@ -333,7 +330,7 @@
(-> (.visitField (+ Opcodes/ACC_PUBLIC Opcodes/ACC_FINAL Opcodes/ACC_STATIC) "_eval" "Ljava/lang/Object;" nil nil)
(doto (.visitEnd))))]
_ (&/with-writer (.visitMethod =class Opcodes/ACC_PUBLIC "<clinit>" "()V" nil nil)
- (|do [*writer* &/get-writer
+ (|do [^MethodVisitor *writer* &/get-writer
:let [_ (.visitCode *writer*)]
_ (compile-expression expr)
:let [_ (doto *writer*
@@ -346,7 +343,7 @@
.visitEnd))]
_ (&&/save-class! class-name bytecode)
loader &/loader]
- (-> (.loadClass loader class-name)
+ (-> (.loadClass ^ClassLoader loader class-name)
(.getField "_eval")
(.get nil)
return)))
diff --git a/src/lux/compiler/base.clj b/src/lux/compiler/base.clj
index 1023e086e..dd7e0ae13 100644
--- a/src/lux/compiler/base.clj
+++ b/src/lux/compiler/base.clj
@@ -15,14 +15,14 @@
(def closure-prefix "c")
(def apply-signature "(Ljava/lang/Object;)Ljava/lang/Object;")
-(defn write-file [file data]
+(defn write-file [^String file ^bytes data]
(with-open [stream (java.io.BufferedOutputStream. (java.io.FileOutputStream. file))]
(.write stream data)))
(defn write-class [name data]
(write-file (str "output/" name ".class") data))
-(defn load-class! [loader name]
+(defn load-class! [^ClassLoader loader name]
(.loadClass loader name))
(defn save-class! [name bytecode]
diff --git a/src/lux/compiler/case.clj b/src/lux/compiler/case.clj
index 4e33bd7b1..738d6bc35 100644
--- a/src/lux/compiler/case.clj
+++ b/src/lux/compiler/case.clj
@@ -19,8 +19,8 @@
(let [+tag-sig+ (&host/->type-signature "java.lang.String")
+oclass+ (&host/->class "java.lang.Object")
+equals-sig+ (str "(" (&host/->type-signature "java.lang.Object") ")Z")
- compare-kv #(compare (aget %1 0) (aget %2 0))]
- (defn ^:private compile-match [writer ?match $target $else]
+ compare-kv #(.compareTo ^String (aget ^objects %1 0) ^String (aget ^objects %2 0))]
+ (defn ^:private compile-match [^MethodVisitor writer ?match $target $else]
;; (prn 'compile-match (aget ?match 0) $target $else)
(matchv ::M/objects [?match]
[["StoreTestAC" ?idx]]
@@ -153,7 +153,7 @@
(&/T mappings (&/|reverse patterns*))))
(let [ex-class (&host/->class "java.lang.IllegalStateException")]
- (defn ^:private compile-pattern-matching [writer compile mappings patterns $end]
+ (defn ^:private compile-pattern-matching [^MethodVisitor writer compile mappings patterns $end]
;; (prn 'compile-pattern-matching ?matches $end)
(let [entries (&/|map (fn [?branch+?body]
(|let [[?branch ?body] ?branch+?body
@@ -188,7 +188,7 @@
;; [Resources]
(defn compile-case [compile *type* ?value ?matches]
;; (prn 'compile-case ?value ?matches)
- (|do [*writer* &/get-writer
+ (|do [^MethodVisitor *writer* &/get-writer
:let [$end (new Label)]
_ (compile ?value)
_ (|let [[mappings patterns] (separate-bodies ?matches)]
diff --git a/src/lux/compiler/host.clj b/src/lux/compiler/host.clj
index c51714c31..ff5d50e23 100644
--- a/src/lux/compiler/host.clj
+++ b/src/lux/compiler/host.clj
@@ -27,7 +27,7 @@
"float" [(&host/->class "java.lang.Float") "floatValue" "()F"]
"double" [(&host/->class "java.lang.Double") "doubleValue" "()D"]
"char" [(&host/->class "java.lang.Character") "charValue" "()C"]}]
- (defn ^:private prepare-arg! [*writer* class-name]
+ (defn ^:private prepare-arg! [^MethodVisitor *writer* class-name]
(if-let [[class method sig] (get class+method+sig class-name)]
(doto *writer*
(.visitTypeInsn Opcodes/CHECKCAST class)
@@ -42,7 +42,7 @@
float-class "java.lang.Float"
double-class "java.lang.Double"
char-class "java.lang.Character"]
- (defn prepare-return! [*writer* *type*]
+ (defn prepare-return! [^MethodVisitor *writer* *type*]
(matchv ::M/objects [*type*]
[["lux;VariantT" ["lux;Nil" _]]]
(.visitInsn *writer* Opcodes/ACONST_NULL)
@@ -79,7 +79,7 @@
(do-template [<name> <opcode> <wrapper-class> <value-method> <value-method-sig> <wrapper-method> <wrapper-method-sig>]
(defn <name> [compile *type* ?x ?y]
(|do [:let [+wrapper-class+ (&host/->class <wrapper-class>)]
- *writer* &/get-writer
+ ^MethodVisitor *writer* &/get-writer
_ (compile ?x)
:let [_ (doto *writer*
(.visitTypeInsn Opcodes/CHECKCAST +wrapper-class+)
@@ -121,7 +121,7 @@
(do-template [<name> <opcode> <wrapper-class> <value-method> <value-method-sig>]
(defn <name> [compile *type* ?x ?y]
(|do [:let [+wrapper-class+ (&host/->class <wrapper-class>)]
- *writer* &/get-writer
+ ^MethodVisitor *writer* &/get-writer
_ (compile ?x)
:let [_ (doto *writer*
(.visitTypeInsn Opcodes/CHECKCAST +wrapper-class+)
@@ -149,7 +149,7 @@
(do-template [<name> <cmpcode> <ifcode> <wrapper-class> <value-method> <value-method-sig>]
(defn <name> [compile *type* ?x ?y]
(|do [:let [+wrapper-class+ (&host/->class <wrapper-class>)]
- *writer* &/get-writer
+ ^MethodVisitor *writer* &/get-writer
_ (compile ?x)
:let [_ (doto *writer*
(.visitTypeInsn Opcodes/CHECKCAST +wrapper-class+)
@@ -184,7 +184,7 @@
)
(defn compile-jvm-invokestatic [compile *type* ?class ?method ?classes ?args]
- (|do [*writer* &/get-writer
+ (|do [^MethodVisitor *writer* &/get-writer
:let [method-sig (str "(" (reduce str "" (map &host/->type-signature ?classes)) ")" (&host/->java-sig *type*))]
_ (&/map% (fn [[class-name arg]]
(|do [ret (compile arg)
@@ -199,7 +199,7 @@
(do-template [<name> <op>]
(defn <name> [compile *type* ?class ?method ?classes ?object ?args]
;; (prn 'compile-jvm-invokevirtual ?classes *type*)
- (|do [*writer* &/get-writer
+ (|do [^MethodVisitor *writer* &/get-writer
:let [method-sig (str "(" (&/fold str "" (&/|map &host/->type-signature ?classes)) ")" (&host/->java-sig *type*))]
_ (compile ?object)
:let [_ (.visitTypeInsn *writer* Opcodes/CHECKCAST (&host/->class ?class))]
@@ -220,12 +220,12 @@
)
(defn compile-jvm-null [compile *type*]
- (|do [*writer* &/get-writer
+ (|do [^MethodVisitor *writer* &/get-writer
:let [_ (.visitInsn *writer* Opcodes/ACONST_NULL)]]
(return nil)))
(defn compile-jvm-null? [compile *type* ?object]
- (|do [*writer* &/get-writer
+ (|do [^MethodVisitor *writer* &/get-writer
_ (compile ?object)
:let [$then (new Label)
$end (new Label)
@@ -239,7 +239,7 @@
(return nil)))
(defn compile-jvm-new [compile *type* ?class ?classes ?args]
- (|do [*writer* &/get-writer
+ (|do [^MethodVisitor *writer* &/get-writer
:let [init-sig (str "(" (reduce str "" (map &host/->type-signature ?classes)) ")V")
class* (&host/->class ?class)
_ (doto *writer*
@@ -255,14 +255,14 @@
(return nil)))
(defn compile-jvm-new-array [compile *type* ?class ?length]
- (|do [*writer* &/get-writer
+ (|do [^MethodVisitor *writer* &/get-writer
:let [_ (doto *writer*
(.visitLdcInsn (int ?length))
(.visitTypeInsn Opcodes/ANEWARRAY (&host/->class ?class)))]]
(return nil)))
(defn compile-jvm-aastore [compile *type* ?array ?idx ?elem]
- (|do [*writer* &/get-writer
+ (|do [^MethodVisitor *writer* &/get-writer
_ (compile ?array)
:let [_ (doto *writer*
(.visitInsn Opcodes/DUP)
@@ -272,7 +272,7 @@
(return nil)))
(defn compile-jvm-aaload [compile *type* ?array ?idx]
- (|do [*writer* &/get-writer
+ (|do [^MethodVisitor *writer* &/get-writer
_ (compile ?array)
:let [_ (doto *writer*
(.visitLdcInsn (int ?idx))
@@ -280,25 +280,25 @@
(return nil)))
(defn compile-jvm-getstatic [compile *type* ?class ?field]
- (|do [*writer* &/get-writer
+ (|do [^MethodVisitor *writer* &/get-writer
:let [_ (.visitFieldInsn *writer* Opcodes/GETSTATIC (&host/->class ?class) ?field (&host/->java-sig *type*))]]
(return nil)))
(defn compile-jvm-getfield [compile *type* ?class ?field ?object]
- (|do [*writer* &/get-writer
+ (|do [^MethodVisitor *writer* &/get-writer
_ (compile ?object)
:let [_ (.visitTypeInsn *writer* Opcodes/CHECKCAST (&host/->class ?class))]
:let [_ (.visitFieldInsn *writer* Opcodes/GETFIELD (&host/->class ?class) ?field (&host/->java-sig *type*))]]
(return nil)))
(defn compile-jvm-putstatic [compile *type* ?class ?field ?value]
- (|do [*writer* &/get-writer
+ (|do [^MethodVisitor *writer* &/get-writer
_ (compile ?value)
:let [_ (.visitFieldInsn *writer* Opcodes/PUTSTATIC (&host/->class ?class) ?field (&host/->java-sig *type*))]]
(return nil)))
(defn compile-jvm-putfield [compile *type* ?class ?field ?object ?value]
- (|do [*writer* &/get-writer
+ (|do [^MethodVisitor *writer* &/get-writer
_ (compile ?object)
_ (compile ?value)
:let [_ (.visitTypeInsn *writer* Opcodes/CHECKCAST (&host/->class ?class))]
@@ -344,18 +344,8 @@
;; (prn 'SAVED_CLASS full-name)
(&&/save-class! full-name (.toByteArray =interface))))
-(defn compile-|do [compile *type* ?exprs]
- (|do [*writer* &/get-writer
- _ (&/map% (fn [expr]
- (|do [ret (compile expr)
- :let [_ (.visitInsn *writer* Opcodes/POP)]]
- (return ret)))
- (butlast ?exprs))
- _ (compile (last ?exprs))]
- (return nil)))
-
(defn compile-jvm-try [compile *type* ?body ?catches ?finally]
- (|do [*writer* &/get-writer
+ (|do [^MethodVisitor *writer* &/get-writer
:let [$from (new Label)
$to (new Label)
$end (new Label)
@@ -403,14 +393,14 @@
(return nil)))
(defn compile-jvm-throw [compile *type* ?ex]
- (|do [*writer* &/get-writer
+ (|do [^MethodVisitor *writer* &/get-writer
_ (compile ?ex)
:let [_ (.visitInsn *writer* Opcodes/ATHROW)]]
(return nil)))
(do-template [<name> <op>]
(defn <name> [compile *type* ?monitor]
- (|do [*writer* &/get-writer
+ (|do [^MethodVisitor *writer* &/get-writer
_ (compile ?monitor)
:let [_ (doto *writer*
(.visitInsn <op>)
@@ -423,7 +413,7 @@
(do-template [<name> <op> <from-class> <from-method> <from-sig> <to-class> <to-sig>]
(defn <name> [compile *type* ?value]
- (|do [*writer* &/get-writer
+ (|do [^MethodVisitor *writer* &/get-writer
:let [_ (doto *writer*
(.visitTypeInsn Opcodes/NEW (&host/->class <to-class>))
(.visitInsn Opcodes/DUP))]
@@ -456,7 +446,7 @@
(do-template [<name> <op> <from1-method> <from1-sig> <from1-class> <from2-method> <from2-sig> <from2-class> <to-class> <to-sig>]
(defn <name> [compile *type* ?x ?y]
- (|do [*writer* &/get-writer
+ (|do [^MethodVisitor *writer* &/get-writer
:let [_ (doto *writer*
(.visitTypeInsn Opcodes/NEW (&host/->class <to-class>))
(.visitInsn Opcodes/DUP))]
@@ -482,12 +472,12 @@
)
(defn compile-jvm-program [compile *type* ?body]
- (|do [*writer* &/get-writer]
+ (|do [^ClassWriter *writer* &/get-writer]
(&/with-writer (doto (.visitMethod *writer* (+ Opcodes/ACC_PUBLIC Opcodes/ACC_STATIC) "main" "([Ljava/lang/String;)V" nil nil)
(.visitCode))
(|do [*writer* &/get-writer
_ (compile ?body)
- :let [_ (doto *writer*
+ :let [_ (doto ^MethodVisitor *writer*
(.visitInsn Opcodes/POP)
(.visitInsn Opcodes/RETURN)
(.visitMaxs 0 0)
diff --git a/src/lux/compiler/lambda.clj b/src/lux/compiler/lambda.clj
index 276329a75..962a32ab6 100644
--- a/src/lux/compiler/lambda.clj
+++ b/src/lux/compiler/lambda.clj
@@ -32,7 +32,7 @@
<init>-return))
(defn ^:private add-lambda-<init> [class class-name env]
- (doto (.visitMethod class Opcodes/ACC_PUBLIC "<init>" (lambda-<init>-signature env) nil nil)
+ (doto (.visitMethod ^ClassWriter class Opcodes/ACC_PUBLIC "<init>" (lambda-<init>-signature env) nil nil)
(.visitCode)
(.visitVarInsn Opcodes/ALOAD 0)
(.visitMethodInsn Opcodes/INVOKESPECIAL "java/lang/Object" "<init>" "()V")
@@ -50,7 +50,7 @@
(.visitEnd)))
(defn ^:private add-lambda-apply [class class-name env]
- (doto (.visitMethod class Opcodes/ACC_PUBLIC "apply" &&/apply-signature nil nil)
+ (doto (.visitMethod ^ClassWriter class Opcodes/ACC_PUBLIC "apply" &&/apply-signature nil nil)
(.visitCode)
(.visitVarInsn Opcodes/ALOAD 0)
(.visitVarInsn Opcodes/ALOAD 1)
@@ -60,9 +60,9 @@
(.visitEnd)))
(defn ^:private add-lambda-impl [class compile impl-signature impl-body]
- (&/with-writer (doto (.visitMethod class Opcodes/ACC_PUBLIC "impl" impl-signature nil nil)
+ (&/with-writer (doto (.visitMethod ^ClassWriter class Opcodes/ACC_PUBLIC "impl" impl-signature nil nil)
(.visitCode))
- (|do [*writer* &/get-writer
+ (|do [^MethodVisitor *writer* &/get-writer
:let [num-locals (&&/total-locals impl-body)
$start (new Label)
$end (new Label)
@@ -80,28 +80,10 @@
(defn ^:private instance-closure [compile lambda-class closed-over init-signature]
;; (prn 'instance-closure lambda-class (&/|length closed-over) init-signature)
- (|do [*writer* &/get-writer
+ (|do [^MethodVisitor *writer* &/get-writer
:let [_ (doto *writer*
(.visitTypeInsn Opcodes/NEW lambda-class)
- (.visitInsn Opcodes/DUP))
- ;; _ (prn 'closed-over/pre
- ;; (&/->seq (&/|map #(matchv ::M/objects [(&/|second %1)]
- ;; [[["captured" [_ ?cid _]] _]]
- ;; ?cid)
- ;; closed-over)))
- ;; _ (prn 'closed-over/post
- ;; (->> closed-over
- ;; &/->seq
- ;; (sort #(matchv ::M/objects [(&/|second %1) (&/|second %2)]
- ;; [[["captured" [_ ?cid1 _]] _]
- ;; [["captured" [_ ?cid2 _]] _]]
- ;; (< ?cid1 ?cid2)))
- ;; &/->list
- ;; (&/|map #(matchv ::M/objects [(&/|second %1)]
- ;; [[["captured" [_ ?cid _]] _]]
- ;; ?cid))
- ;; &/->seq))
- ]
+ (.visitInsn Opcodes/DUP))]
_ (->> closed-over
&/->seq
(sort #(matchv ::M/objects [(&/|second %1) (&/|second %2)]
@@ -112,16 +94,7 @@
(&/map% (fn [?name+?captured]
(matchv ::M/objects [?name+?captured]
[[?name [["captured" [_ _ ?source]] _]]]
- (do ;; (prn '?source (aget ?source 1 0 0)
- ;; (cond (= "captured" (aget ?source 1 0 0))
- ;; ["captured" (aget ?source 1 0 1 1)]
-
- ;; (= "local" (aget ?source 1 0 0))
- ;; ["local" (aget ?source 1 0 1)]
-
- ;; :else
- ;; '???))
- (compile ?source))))))
+ (compile ?source)))))
:let [_ (.visitMethodInsn *writer* Opcodes/INVOKESPECIAL lambda-class "<init>" init-signature)]]
(return nil)))
diff --git a/src/lux/compiler/lux.clj b/src/lux/compiler/lux.clj
index 35a706f05..ad2c9d0c6 100644
--- a/src/lux/compiler/lux.clj
+++ b/src/lux/compiler/lux.clj
@@ -25,14 +25,14 @@
(let [+class+ (&host/->class "java.lang.Boolean")
+sig+ (&host/->type-signature "java.lang.Boolean")]
(defn compile-bool [compile *type* ?value]
- (|do [*writer* &/get-writer
+ (|do [^MethodVisitor *writer* &/get-writer
:let [_ (.visitFieldInsn *writer* Opcodes/GETSTATIC (&host/->class "java.lang.Boolean") (if ?value "TRUE" "FALSE") (&host/->type-signature "java.lang.Boolean"))]]
(return nil))))
(do-template [<name> <class> <sig> <caster>]
(let [+class+ (&host/->class <class>)]
(defn <name> [compile *type* value]
- (|do [*writer* &/get-writer
+ (|do [^MethodVisitor *writer* &/get-writer
:let [_ (doto *writer*
(.visitTypeInsn Opcodes/NEW +class+)
(.visitInsn Opcodes/DUP)
@@ -46,12 +46,12 @@
)
(defn compile-text [compile *type* ?value]
- (|do [*writer* &/get-writer
+ (|do [^MethodVisitor *writer* &/get-writer
:let [_ (.visitLdcInsn *writer* ?value)]]
(return nil)))
(defn compile-tuple [compile *type* ?elems]
- (|do [*writer* &/get-writer
+ (|do [^MethodVisitor *writer* &/get-writer
:let [num-elems (&/|length ?elems)
_ (doto *writer*
(.visitLdcInsn (int num-elems))
@@ -69,7 +69,7 @@
(defn compile-record [compile *type* ?elems]
;; (prn 'compile-record (str "{{" (->> ?elems &/|keys (&/|interpose " ") (&/fold str "")) "}}"))
- (|do [*writer* &/get-writer
+ (|do [^MethodVisitor *writer* &/get-writer
:let [elems* (->> ?elems
&/->seq
(sort #(compare (&/|first %1) (&/|first %2)))
@@ -91,7 +91,7 @@
(return nil)))
(defn compile-variant [compile *type* ?tag ?value]
- (|do [*writer* &/get-writer
+ (|do [^MethodVisitor *writer* &/get-writer
:let [_ (doto *writer*
(.visitLdcInsn (int 2))
(.visitTypeInsn Opcodes/ANEWARRAY (&host/->class "java.lang.Object"))
@@ -106,13 +106,13 @@
(return nil)))
(defn compile-local [compile *type* ?idx]
- (|do [*writer* &/get-writer
+ (|do [^MethodVisitor *writer* &/get-writer
:let [_ (.visitVarInsn *writer* Opcodes/ALOAD (int ?idx))]]
(return nil)))
(defn compile-captured [compile *type* ?scope ?captured-id ?source]
;; (prn 'compile-captured ?scope ?captured-id)
- (|do [*writer* &/get-writer
+ (|do [^MethodVisitor *writer* &/get-writer
:let [_ (doto *writer*
(.visitVarInsn Opcodes/ALOAD 0)
(.visitFieldInsn Opcodes/GETFIELD
@@ -122,19 +122,19 @@
(return nil)))
(defn compile-global [compile *type* ?owner-class ?name]
- (|do [*writer* &/get-writer
+ (|do [^MethodVisitor *writer* &/get-writer
:let [_ (.visitFieldInsn *writer* Opcodes/GETSTATIC (&host/->class (&host/location (&/|list ?owner-class ?name))) "_datum" "Ljava/lang/Object;")]]
(return nil)))
(defn compile-apply [compile *type* ?fn ?arg]
- (|do [*writer* &/get-writer
+ (|do [^MethodVisitor *writer* &/get-writer
_ (compile ?fn)
_ (compile ?arg)
:let [_ (.visitMethodInsn *writer* Opcodes/INVOKEINTERFACE (&host/->class &host/function-class) "apply" &&/apply-signature)]]
(return nil)))
(defn compile-def [compile ?name ?body ?def-data]
- (|do [*writer* &/get-writer
+ (|do [^ClassWriter *writer* &/get-writer
module-name &/get-module-name
:let [outer-class (&host/->class module-name)
datum-sig (&host/->type-signature "java.lang.Object")
@@ -147,7 +147,7 @@
(doto (.visitEnd))))]
;; :let [_ (prn 'compile-def/pre-body)]
_ (&/with-writer (.visitMethod =class Opcodes/ACC_PUBLIC "<clinit>" "()V" nil nil)
- (|do [**writer** &/get-writer
+ (|do [^MethodVisitor **writer** &/get-writer
:let [_ (.visitCode **writer**)]
;; :let [_ (prn 'compile-def/pre-body2)]
_ (compile ?body)
diff --git a/src/lux/host.clj b/src/lux/host.clj
index 9d6f72fab..2d7cbbbdf 100644
--- a/src/lux/host.clj
+++ b/src/lux/host.clj
@@ -4,14 +4,15 @@
[clojure.core.match :as M :refer [match matchv]]
clojure.core.match.array
(lux [base :as & :refer [|do return* return fail fail* |let]]
- [type :as &type])))
+ [type :as &type]))
+ (:import (java.lang.reflect Field Method Modifier)))
;; [Constants]
(def prefix "lux.")
(def function-class (str prefix "Function"))
;; [Utils]
-(defn ^:private class->type [class]
+(defn ^:private class->type [^Class class]
(if-let [[_ base arr-level] (re-find #"^([^\[]+)(\[\])*$"
(str (if-let [pkg (.getPackage class)]
(str (.getName pkg) ".")
@@ -23,7 +24,7 @@
base)))
)))
-(defn ^:private method->type [method]
+(defn ^:private method->type [^Method method]
(|do [;; =args (&/map% class->type (&/->list (seq (.getParameterTypes method))))
=return (class->type (.getReturnType method))]
(return =return)))
@@ -46,10 +47,10 @@
(defn full-class-name [class-name]
;; (prn 'full-class-name class-name)
- (|do [=class (full-class class-name)]
+ (|do [^Class =class (full-class class-name)]
(return (.getName =class))))
-(defn ->class [class]
+(defn ^String ->class [class]
(string/replace class #"\." "/"))
(def ->package ->class)
@@ -73,7 +74,7 @@
(str "L" class* ";")))
))
-(defn ->java-sig [type]
+(defn ->java-sig [^objects type]
(matchv ::M/objects [type]
[["lux;DataT" ?name]]
(->type-signature ?name)
@@ -104,10 +105,10 @@
(do-template [<name> <static?>]
(defn <name> [target field]
(let [target (Class/forName target)]
- (if-let [type* (first (for [=field (.getFields target)
+ (if-let [type* (first (for [^Field =field (.getFields target)
:when (and (= target (.getDeclaringClass =field))
(= field (.getName =field))
- (= <static?> (java.lang.reflect.Modifier/isStatic (.getModifiers =field))))]
+ (= <static?> (Modifier/isStatic (.getModifiers =field))))]
(.getType =field)))]
(|do [=type (class->type type*)]
(return =type))
@@ -120,18 +121,18 @@
(do-template [<name> <static?>]
(defn <name> [target method-name args]
(let [target (Class/forName target)]
- (if-let [method (first (for [=method (.getMethods target)
+ (if-let [method (first (for [^Method =method (.getMethods target)
;; :let [_ (prn '<name> '=method =method (mapv #(.getName %) (.getParameterTypes =method)))]
:when (and (= target (.getDeclaringClass =method))
(= method-name (.getName =method))
- (= <static?> (java.lang.reflect.Modifier/isStatic (.getModifiers =method)))
+ (= <static?> (Modifier/isStatic (.getModifiers =method)))
(&/fold #(and %1 %2)
true
(&/|map (fn [xy]
(|let [[x y] xy]
(= x y)))
(&/zip2 args
- (&/|map #(.getName %) (&/->list (seq (.getParameterTypes =method))))))))]
+ (&/|map #(.getName ^Class %) (&/->list (seq (.getParameterTypes =method))))))))]
=method))]
(method->type method)
(fail (str "[Analyser Error] Method does not exist: " target method-name)))))
diff --git a/src/lux/parser.clj b/src/lux/parser.clj
index 85074be7d..cb89f63a2 100644
--- a/src/lux/parser.clj
+++ b/src/lux/parser.clj
@@ -62,7 +62,7 @@
[["lux;Meta" [meta ["Real" ?value]]]]
(return (&/|list (&/V "lux;Meta" (&/T meta (&/V "lux;Real" (Float/parseFloat ?value))))))
- [["lux;Meta" [meta ["Char" ?value]]]]
+ [["lux;Meta" [meta ["Char" ^String ?value]]]]
(return (&/|list (&/V "lux;Meta" (&/T meta (&/V "lux;Char" (.charAt ?value 0))))))
[["lux;Meta" [meta ["Text" ?value]]]]
diff --git a/src/lux/reader.clj b/src/lux/reader.clj
index d163bcae3..d66a671aa 100644
--- a/src/lux/reader.clj
+++ b/src/lux/reader.clj
@@ -32,8 +32,8 @@
;; [Exports]
(defn read-regex [regex]
(with-line
- (fn [file-name line-num column-num line]
- (if-let [[match] (re-find regex line)]
+ (fn [file-name line-num column-num ^String line]
+ (if-let [[^String match] (re-find regex line)]
(let [match-length (.length match)
line* (.substring line match-length)
;; _ (prn 'with-line line*)
@@ -46,8 +46,8 @@
(defn read-regex2 [regex]
(with-line
- (fn [file-name line-num column-num line]
- (if-let [[match tok1 tok2] (re-find regex line)]
+ (fn [file-name line-num column-num ^String line]
+ (if-let [[^String match tok1 tok2] (re-find regex line)]
(let [match-length (.length match)
line* (.substring line match-length)
;; _ (prn 'with-line line*)
@@ -58,9 +58,9 @@
(&/V "lux;Some" (&/V "lux;Meta" (&/T (&/T file-name line-num (+ column-num match-length)) line*)))))))
(&/V "No" (str "[Reader Error] Pattern failed: " regex))))))
-(defn read-text [text]
+(defn read-text [^String text]
(with-line
- (fn [file-name line-num column-num line]
+ (fn [file-name line-num column-num ^String line]
;; (prn 'read-text text line)
(if (.startsWith line text)
(let [match-length (.length text)
diff --git a/src/lux/type.clj b/src/lux/type.clj
index 766e28a39..c8ee06059 100644
--- a/src/lux/type.clj
+++ b/src/lux/type.clj
@@ -342,7 +342,7 @@
[_]
(fail (str "[Type Error] Not type-var: " (show-type tvar)))))
-(defn show-type [type]
+(defn show-type [^objects type]
;; (prn 'show-type (aget type 0))
(matchv ::M/objects [type]
[["lux;DataT" name]]