aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorEduardo Julian2015-12-06 20:14:25 -0400
committerEduardo Julian2015-12-06 20:14:25 -0400
commit08aa828cd4f83b719ef8d1af75463fadc67bcddb (patch)
treeb2cf7d694e865d3d9b0f6b7ed1851afe5805a175 /src
parentf317f31851f784b8846ec182377b9fd1ad3f0659 (diff)
- lux.Function is now generated directly from the compiler, not from the lux.lux file.
Diffstat (limited to 'src')
-rw-r--r--src/lux/compiler.clj19
-rw-r--r--src/lux/compiler/base.clj13
-rw-r--r--src/lux/compiler/host.clj17
3 files changed, 38 insertions, 11 deletions
diff --git a/src/lux/compiler.clj b/src/lux/compiler.clj
index baf6bf549..8fe64aa59 100644
--- a/src/lux/compiler.clj
+++ b/src/lux/compiler.clj
@@ -545,11 +545,14 @@
;; [Resources]
(defn compile-program [program-module]
(init!)
- (|case ((&/map% compile-module (&/|list "lux" program-module)) (&/init-state nil))
- (&/$Right ?state _)
- (do (println "Compilation complete!")
- (&&cache/clean ?state)
- (&packager-program/package program-module))
-
- (&/$Left ?message)
- (assert false ?message)))
+ (let [m-action (|do [_ &&host/compile-Function-class
+ _ (&/map% compile-module (&/|list "lux" program-module))]
+ (return nil))]
+ (|case (m-action (&/init-state nil))
+ (&/$Right ?state _)
+ (do (println "Compilation complete!")
+ (&&cache/clean ?state)
+ (&packager-program/package program-module))
+
+ (&/$Left ?message)
+ (assert false ?message))))
diff --git a/src/lux/compiler/base.clj b/src/lux/compiler/base.clj
index 0d9a29d79..910a9a05a 100644
--- a/src/lux/compiler/base.clj
+++ b/src/lux/compiler/base.clj
@@ -27,8 +27,8 @@
;; [Constants]
(def ^String version "0.3.1")
(def ^String input-dir "source")
-(def ^String output-dir "target/jvm/")
-(def ^String output-package (str output-dir "program.jar"))
+(def ^String output-dir "target/jvm")
+(def ^String output-package (str output-dir "/" "program.jar"))
(def ^String function-class "lux/Function")
;; Formats
@@ -56,10 +56,17 @@
(defn ^:private write-output [module name data]
(let [module* (&host/->module-class module)
- module-dir (str output-dir module*)]
+ module-dir (str output-dir "/" module*)]
(.mkdirs (File. module-dir))
(write-file (str module-dir "/" name ".class") data)))
+(defn class-exists? [^String module ^String class-name]
+ "(-> Text Text (IO Bool))"
+ (|do [_ (return nil)
+ :let [full-path (str output-dir "/" module "/" class-name ".class")
+ exists? (.exists (File. full-path))]]
+ (return exists?)))
+
;; [Exports]
(defn ^Class load-class! [^ClassLoader loader name]
;; (prn 'load-class! name)
diff --git a/src/lux/compiler/host.clj b/src/lux/compiler/host.clj
index 4b76f003e..bcbed07c9 100644
--- a/src/lux/compiler/host.clj
+++ b/src/lux/compiler/host.clj
@@ -599,6 +599,23 @@
(.visitEnd =interface))]]
(&&/save-class! interface-name (.toByteArray =interface))))
+(def compile-Function-class
+ (|do [? (&&/class-exists? "lux" "Function")]
+ (if ?
+ (return nil)
+ (&/with-scope "lux"
+ (let [object-class (&/V &/$GenericClass (&/T "java.lang.Object" (&/|list)))
+ interface-decl (&/T "Function" (&/|list))
+ ?supers (&/|list)
+ ?anns (&/|list)
+ ?methods (&/|list (&/T "apply"
+ (&/|list)
+ (&/|list)
+ (&/|list)
+ (&/|list (&/T "arg" object-class))
+ object-class))]
+ (compile-jvm-interface nil interface-decl ?supers ?anns ?methods))))))
+
(defn compile-jvm-try [compile ?body ?catches ?finally]
(|do [^MethodVisitor *writer* &/get-writer
:let [$from (new Label)