aboutsummaryrefslogtreecommitdiff
path: root/luxc/src
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--luxc/src/lux.clj16
-rw-r--r--luxc/src/lux/compiler.clj12
-rw-r--r--luxc/src/lux/compiler/cache.clj2
-rw-r--r--luxc/src/lux/compiler/io.clj12
-rw-r--r--luxc/src/lux/compiler/jvm.clj20
-rw-r--r--luxc/src/lux/compiler/jvm/case.clj4
-rw-r--r--luxc/src/lux/compiler/jvm/proc/host.clj2
-rw-r--r--luxc/src/lux/compiler/jvm/rt.clj28
-rw-r--r--luxc/src/lux/lib/loader.clj16
-rw-r--r--luxc/src/lux/repl.clj8
10 files changed, 54 insertions, 66 deletions
diff --git a/luxc/src/lux.clj b/luxc/src/lux.clj
index f35373fa8..dc6066669 100644
--- a/luxc/src/lux.clj
+++ b/luxc/src/lux.clj
@@ -11,19 +11,23 @@
(defn- separate-paths
"(-> Text (List Text))"
- [resources-dirs]
- (-> resources-dirs
+ [paths]
+ (-> paths
(string/replace unit-separator "\n")
string/split-lines
+ rest
&/->list))
(defn -main [& args]
(|case (&/->list args)
- (&/$Cons "release" (&/$Cons program-module (&/$Cons resources-dirs (&/$Cons source-dirs (&/$Cons target-dir (&/$Nil))))))
- (&compiler/compile-program &/$Build program-module (separate-paths resources-dirs) (separate-paths source-dirs) target-dir)
+ (&/$Cons "release" (&/$Cons program-module (&/$Cons dependencies (&/$Cons source-dirs (&/$Cons target-dir (&/$Nil))))))
+ (&compiler/compile-program &/$Build program-module
+ (separate-paths dependencies)
+ (separate-paths source-dirs)
+ target-dir)
- (&/$Cons "repl" (&/$Cons resources-dirs (&/$Cons source-dirs (&/$Cons target-dir (&/$Nil)))))
- (&repl/repl (separate-paths resources-dirs)
+ (&/$Cons "repl" (&/$Cons dependencies (&/$Cons source-dirs (&/$Cons target-dir (&/$Nil)))))
+ (&repl/repl (separate-paths dependencies)
(separate-paths source-dirs)
target-dir)
diff --git a/luxc/src/lux/compiler.clj b/luxc/src/lux/compiler.clj
index 5fc77ce6c..2f46d2506 100644
--- a/luxc/src/lux/compiler.clj
+++ b/luxc/src/lux/compiler.clj
@@ -8,12 +8,12 @@
[parallel :as &&parallel]
[jvm :as &&jvm])))
-(defn init! [resources-dirs ^String target-dir]
+(defn init! [dependencies ^String target-dir]
(do (reset! &&core/!output-dir target-dir)
(&&parallel/setup!)
- (&&io/init-libs!)
+ (&&io/init-libs! dependencies)
(.mkdirs (new java.io.File target-dir))
- (&&jvm/init! resources-dirs target-dir)))
+ (&&jvm/init!)))
(def all-compilers
&&jvm/all-compilers)
@@ -24,6 +24,6 @@
(defn compile-module [source-dirs name]
(&&jvm/compile-module source-dirs name))
-(defn compile-program [mode program-module resources-dir source-dirs target-dir]
- (init! resources-dir target-dir)
- (&&jvm/compile-program mode program-module resources-dir source-dirs target-dir))
+(defn compile-program [mode program-module dependencies source-dirs target-dir]
+ (init! dependencies target-dir)
+ (&&jvm/compile-program mode program-module dependencies source-dirs))
diff --git a/luxc/src/lux/compiler/cache.clj b/luxc/src/lux/compiler/cache.clj
index a0f88aa09..01e05c8de 100644
--- a/luxc/src/lux/compiler/cache.clj
+++ b/luxc/src/lux/compiler/cache.clj
@@ -97,7 +97,7 @@
(defn ^:private process-def-entry [load-def-value module ^String _def-entry]
(let [parts (.split _def-entry &&core/datum-separator)]
(case (alength parts)
- 2 (let [[_name _alias] parts
+ 2 (let [[_name ^String _alias] parts
[__module __name] (.split _alias &/+name-separator+)]
(&a-module/define-alias module _name (&/T [__module __name])))
4 (let [[_name _exported? _type _anns] parts
diff --git a/luxc/src/lux/compiler/io.clj b/luxc/src/lux/compiler/io.clj
index 8820bfb05..d3658edd3 100644
--- a/luxc/src/lux/compiler/io.clj
+++ b/luxc/src/lux/compiler/io.clj
@@ -7,16 +7,12 @@
(def ^:private !libs (atom nil))
;; [Resources]
-(defn init-libs! []
- (reset! !libs (&lib/load)))
+(defn init-libs! [dependencies]
+ (reset! !libs (&lib/load dependencies)))
(defn read-file [source-dirs module-name]
- (|do [jvm? &/jvm?
- js? &/js?
- :let [^String host-file-name (cond jvm? (str module-name ".old.lux")
- js? (str module-name ".js.lux")
- :else (assert false "[I/O Error] Unknown host platform."))
- ^String lux-file-name (str module-name ".lux")]]
+ (let [^String host-file-name (str module-name ".old.lux")
+ ^String lux-file-name (str module-name ".lux")]
(|case (&/|some (fn [^String source-dir]
(let [host-file (new java.io.File source-dir host-file-name)
lux-file (new java.io.File source-dir lux-file-name)]
diff --git a/luxc/src/lux/compiler/jvm.clj b/luxc/src/lux/compiler/jvm.clj
index 8b70862ab..bcde7a8ea 100644
--- a/luxc/src/lux/compiler/jvm.clj
+++ b/luxc/src/lux/compiler/jvm.clj
@@ -118,15 +118,9 @@
))
(defn init!
- "(-> (List Text) Null)"
- [resources-dirs ^String target-dir]
- (do (reset! !source->last-line {})
- (let [class-loader (ClassLoader/getSystemClassLoader)
- addURL (doto (.getDeclaredMethod java.net.URLClassLoader "addURL" (into-array [java.net.URL]))
- (.setAccessible true))]
- (doseq [^String resources-dir (&/->seq resources-dirs)]
- (.invoke addURL class-loader
- (to-array [(->> resources-dir (new java.io.File) .toURI .toURL)]))))))
+ "(-> Null)"
+ []
+ (reset! !source->last-line {}))
(defn eval! [expr]
(&/with-eval
@@ -180,7 +174,7 @@
(let [+field-flags+ (+ Opcodes/ACC_PUBLIC Opcodes/ACC_FINAL Opcodes/ACC_STATIC)
+datum-sig+ "Ljava/lang/Object;"]
- (defn compile-module [source-dirs name]
+ (defn compile-module [compile-module source-dirs name]
(|do [[file-name file-content] (&&io/read-file source-dirs name)
:let [file-hash (hash file-content)
compile-module!! (&&parallel/parallel-compilation (partial compile-module source-dirs))]]
@@ -242,13 +236,13 @@
]))))
(let [!err! *err*]
- (defn compile-program [mode program-module resources-dir source-dirs target-dir]
+ (defn compile-program [mode program-module dependencies source-dirs]
(let [m-action (|do [_ (&&cache/pre-load-cache! source-dirs
&&jvm-cache/load-def-value
&&jvm-cache/install-all-defs-in-module
&&jvm-cache/uninstall-all-defs-in-module)
- _ (compile-module source-dirs "lux")]
- (compile-module source-dirs program-module))]
+ _ (compile-module dependencies source-dirs "lux")]
+ (compile-module dependencies source-dirs program-module))]
(|case (m-action (&/init-state "{old}" mode (jvm-host)))
(&/$Right ?state _)
(do (println "Compilation complete!")
diff --git a/luxc/src/lux/compiler/jvm/case.clj b/luxc/src/lux/compiler/jvm/case.clj
index 01b5b924c..b7cdb7571 100644
--- a/luxc/src/lux/compiler/jvm/case.clj
+++ b/luxc/src/lux/compiler/jvm/case.clj
@@ -111,9 +111,9 @@
(&o/$TuplePM (&/$Left lefts))
(let [accessI (if (= 0 lefts)
- #(doto %
+ #(doto ^MethodVisitor %
(.visitInsn Opcodes/AALOAD))
- #(doto %
+ #(doto ^MethodVisitor %
(.visitMethodInsn Opcodes/INVOKESTATIC "lux/LuxRT" "tuple_left" "([Ljava/lang/Object;I)Ljava/lang/Object;")))]
(doto writer
stack-peek
diff --git a/luxc/src/lux/compiler/jvm/proc/host.clj b/luxc/src/lux/compiler/jvm/proc/host.clj
index 0d10d3569..293563d78 100644
--- a/luxc/src/lux/compiler/jvm/proc/host.clj
+++ b/luxc/src/lux/compiler/jvm/proc/host.clj
@@ -88,7 +88,7 @@
*writer*))
;; [Resources]
-(defn ^:private compile-annotation [writer ann]
+(defn ^:private compile-annotation [^ClassWriter writer ann]
(doto ^AnnotationVisitor (.visitAnnotation writer (&host-generics/->type-signature (:name ann)) true)
(-> (.visit param-name param-value)
(->> (|let [[param-name param-value] param])
diff --git a/luxc/src/lux/compiler/jvm/rt.clj b/luxc/src/lux/compiler/jvm/rt.clj
index 689da2eb9..059e33a97 100644
--- a/luxc/src/lux/compiler/jvm/rt.clj
+++ b/luxc/src/lux/compiler/jvm/rt.clj
@@ -68,33 +68,33 @@
;; Runtime infrastructure
(defn ^:private compile-LuxRT-adt-methods [^ClassWriter =class]
- (|let [lefts #(doto %
+ (|let [lefts #(doto ^MethodVisitor %
(.visitVarInsn Opcodes/ILOAD 1))
- tuple-size #(doto %
+ tuple-size #(doto ^MethodVisitor %
(.visitVarInsn Opcodes/ALOAD 0)
(.visitInsn Opcodes/ARRAYLENGTH))
- last-right #(doto %
+ last-right #(doto ^MethodVisitor %
tuple-size
(.visitLdcInsn (int 1))
(.visitInsn Opcodes/ISUB))
- sub-lefts #(doto %
+ sub-lefts #(doto ^MethodVisitor %
lefts
last-right
(.visitInsn Opcodes/ISUB))
- sub-tuple #(doto %
+ sub-tuple #(doto ^MethodVisitor %
(.visitVarInsn Opcodes/ALOAD 0)
last-right
(.visitInsn Opcodes/AALOAD)
(.visitTypeInsn Opcodes/CHECKCAST "[Ljava/lang/Object;"))
recurI (fn [$begin]
- #(doto %
+ #(doto ^MethodVisitor %
sub-lefts (.visitVarInsn Opcodes/ISTORE 1)
sub-tuple (.visitVarInsn Opcodes/ASTORE 0)
(.visitJumpInsn Opcodes/GOTO $begin)))
_ (let [$begin (new Label)
$recursive (new Label)
left-index lefts
- left-access #(doto %
+ left-access #(doto ^MethodVisitor %
(.visitVarInsn Opcodes/ALOAD 0)
left-index
(.visitInsn Opcodes/AALOAD))]
@@ -111,15 +111,15 @@
_ (let [$begin (new Label)
$not-last (new Label)
$must-copy (new Label)
- right-index #(doto %
+ right-index #(doto ^MethodVisitor %
lefts
(.visitLdcInsn (int 1))
(.visitInsn Opcodes/IADD))
- right-access #(doto %
+ right-access #(doto ^MethodVisitor %
(.visitVarInsn Opcodes/ALOAD 0)
(.visitInsn Opcodes/SWAP)
(.visitInsn Opcodes/AALOAD))
- sub-right #(doto %
+ sub-right #(doto ^MethodVisitor %
(.visitVarInsn Opcodes/ALOAD 0)
right-index
tuple-size
@@ -289,12 +289,12 @@
^:private compile-LuxRT-frac-methods "decode_frac" "java/lang/Double" "parseDouble" "(Ljava/lang/String;)D" &&/wrap-double
)
-(defn peekI [writer]
+(defn peekI [^MethodVisitor writer]
(doto writer
(.visitLdcInsn (int 0))
(.visitInsn Opcodes/AALOAD)))
-(defn popI [writer]
+(defn popI [^MethodVisitor writer]
(doto writer
(.visitLdcInsn (int 1))
(.visitInsn Opcodes/AALOAD)
@@ -386,12 +386,12 @@
_ (let [$from (new Label)
$to (new Label)
$handler (new Label)
- make-string-writerI (fn [_method_]
+ make-string-writerI (fn [^MethodVisitor _method_]
(doto _method_
(.visitTypeInsn Opcodes/NEW "java/io/StringWriter")
(.visitInsn Opcodes/DUP)
(.visitMethodInsn Opcodes/INVOKESPECIAL "java/io/StringWriter" "<init>" "()V")))
- make-print-writerI (fn [_method_]
+ make-print-writerI (fn [^MethodVisitor _method_]
(doto _method_
;; W
(.visitTypeInsn Opcodes/NEW "java/io/PrintWriter") ;; WP
diff --git a/luxc/src/lux/lib/loader.clj b/luxc/src/lux/lib/loader.clj
index 19c5111ec..5afae6ae2 100644
--- a/luxc/src/lux/lib/loader.clj
+++ b/luxc/src/lux/lib/loader.clj
@@ -9,14 +9,6 @@
java.util.jar.JarInputStream))
;; [Utils]
-(defn ^:private fetch-libs []
- (->> ^java.net.URLClassLoader (ClassLoader/getSystemClassLoader)
- (.getURLs)
- seq
- (map #(.getFile ^java.net.URL %))
- (filter #(.endsWith ^String % ".jar"))
- (map #(new File ^String %))))
-
(let [init-capacity (* 100 1024)
buffer-size 1024]
(defn ^:private ^"[B" read-stream [^InputStream is]
@@ -43,7 +35,9 @@
lib-data))))
;; [Exports]
-(defn load []
- (->> (fetch-libs)
- (map unpackage)
+(defn load [dependencies]
+ (prn `load (&/->seq dependencies))
+ (->> dependencies
+ &/->seq
+ (map #(->> ^String % (new File) unpackage))
(reduce merge {})))
diff --git a/luxc/src/lux/repl.clj b/luxc/src/lux/repl.clj
index 9cf2c5982..6f167d8b1 100644
--- a/luxc/src/lux/repl.clj
+++ b/luxc/src/lux/repl.clj
@@ -19,8 +19,8 @@
(defn ^:private repl-cursor [repl-line]
(&/T [repl-module repl-line 0]))
-(defn ^:private init [resources-dirs source-dirs target-dir]
- (do (&compiler/init! resources-dirs target-dir)
+(defn ^:private init [source-dirs]
+ (do (&compiler/init!)
(|case ((|do [_ (&compiler/compile-module source-dirs "lux")
_ (&cache/delete repl-module)
_ (&module/create-module repl-module 0)
@@ -47,9 +47,9 @@
))
;; [Values]
-(defn repl [resources-dirs source-dirs target-dir]
+(defn repl [dependencies source-dirs target-dir]
(with-open [input (->> System/in (new InputStreamReader) (new BufferedReader))]
- (loop [state (init resources-dirs source-dirs target-dir)
+ (loop [state (init source-dirs)
repl-line 0
multi-line? false]
(let [_ (if (not multi-line?)