aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEduardo Julian2015-01-19 01:36:16 -0400
committerEduardo Julian2015-01-19 01:36:16 -0400
commita1d619ac4679f246a92ee5e557ed1341f5629221 (patch)
treecf013485e6d55ec63581c25f0eef4be632fcafed
parent555d0181fa1d76f02d1b86843123eda494c0fbec (diff)
[Enhancement]
.class files are now stored inside an "output" directory.
-rw-r--r--src/lux.clj1
-rw-r--r--src/lux/compiler.clj20
-rw-r--r--src/lux/util.clj2
-rw-r--r--test2.lux28
4 files changed, 33 insertions, 18 deletions
diff --git a/src/lux.clj b/src/lux.clj
index 517396182..f21a336e0 100644
--- a/src/lux.clj
+++ b/src/lux.clj
@@ -38,6 +38,7 @@
)
;; jar cvf test2.jar *.class test2 && java -cp "test2.jar" test2
+ ;; cd output && jar cvf test2.jar * && java -cp "test2.jar" test2 && cd ..
)
;; (def (workday? d)
diff --git a/src/lux/compiler.clj b/src/lux/compiler.clj
index a7ebcf8c1..2a347aa46 100644
--- a/src/lux/compiler.clj
+++ b/src/lux/compiler.clj
@@ -30,6 +30,9 @@
;; (Thread/sleep 2000)
)
+(defn ^:private write-class [name data]
+ (write-file (str "output/" name ".class") data))
+
(let [;; loader (proxy [ClassLoader] [])
]
(defn load-class! [name file-name]
@@ -39,6 +42,7 @@
(.loadClass @loader name)
;; (println "SUCCESFUL LOAD!")
;; (.defineClass loader name bytecode 0 (alength bytecode))
+ ;; (-> (java.io.File. "./") .toURL vector into-array java.net.URLClassLoader. (.loadClass "test2/Function"))
))
(def ^:private +variant-class+ "test2.Variant")
@@ -838,7 +842,7 @@
(.visitEnd)))
_ (.visitEnd =class)
bytecode (.toByteArray =class)]
- (write-file (str current-class ".class") bytecode)
+ (write-class current-class bytecode)
(load-class! (string/replace current-class #"/" ".") (str current-class ".class")))
))
@@ -861,7 +865,7 @@
(.visitEnd)))
(.visitEnd))
bytecode (.toByteArray =class)]
- (write-file (str current-class ".class") bytecode)
+ (write-class current-class bytecode)
(load-class! (string/replace current-class #"/" ".") (str current-class ".class")))
))
@@ -1007,7 +1011,7 @@
(.visitEnd))
_ (.visitEnd =class)
bytecode (.toByteArray =class)]
- (write-file (str current-class ".class") bytecode)
+ (write-class current-class bytecode)
(load-class! (string/replace current-class #"/" ".") (str current-class ".class"))
;; (apply prn 'LAMBDA ?scope ?args (->> (:mappings ?frame)
;; (map second)
@@ -1056,8 +1060,8 @@
(.visitMaxs 0 0)
(.visitEnd))
(.visitEnd =class)
- (.mkdirs (java.io.File. parent-dir))
- (write-file (str parent-dir "/" ?name ".class") (.toByteArray =class))
+ (.mkdirs (java.io.File. (str "output/" parent-dir)))
+ (write-class (str parent-dir "/" ?name) (.toByteArray =class))
(load-class! (string/replace (str parent-dir "/" ?name) #"/" ".") (str parent-dir "/" ?name ".class"))))
(defcompiler ^:private compile-definterface
@@ -1072,8 +1076,8 @@
signature (str "(" (reduce str "" (map ->type-signature ?args)) ")" (->type-signature ?return))]]
(.visitMethod =interface (+ Opcodes/ACC_PUBLIC Opcodes/ACC_ABSTRACT) ?method signature nil nil))
(.visitEnd =interface)
- (.mkdirs (java.io.File. parent-dir))
- (write-file (str parent-dir "/" ?name ".class") (.toByteArray =interface))
+ (.mkdirs (java.io.File. (str "output/" parent-dir)))
+ (write-class (str parent-dir "/" ?name) (.toByteArray =interface))
(load-class! (string/replace (str parent-dir "/" ?name) #"/" ".") (str parent-dir "/" ?name ".class"))))
(defcompiler ^:private compile-variant
@@ -1209,7 +1213,7 @@
;;;
(.visitEnd =class)
(let [bytecode (.toByteArray =class)]
- (write-file (str class-name ".class") bytecode)
+ (write-class class-name bytecode)
(load-class! (string/replace class-name #"/" ".") (str class-name ".class"))
bytecode)
)
diff --git a/src/lux/util.clj b/src/lux/util.clj
index 5496e8699..757648c31 100644
--- a/src/lux/util.clj
+++ b/src/lux/util.clj
@@ -162,4 +162,4 @@
(defonce loader (atom nil))
(defn reset-loader! []
- (reset! loader (-> (java.io.File. "./") .toURL vector into-array java.net.URLClassLoader.)))
+ (reset! loader (-> (java.io.File. "./output/") .toURL vector into-array java.net.URLClassLoader.)))
diff --git a/test2.lux b/test2.lux
index 15bcecdbc..d036bbde4 100644
--- a/test2.lux
+++ b/test2.lux
@@ -388,15 +388,6 @@
(lambda [state]
(#Ok [state state])))
-(def monadic-dup
- (exec [foo get-state
- bar get-state
- baz (return 1000)]
- (return (+ (+ foo bar) baz))))
-
-(def (run-state monad state)
- (monad state))
-
(def list-map #Nil)
(def (put key val map)
@@ -424,6 +415,25 @@
[?key ?val]
(fold concat "" (list "#" ?key " " (show ?val)))))
+(def (within slot monad)
+ (lambda [state]
+ (let =return (monad (get slot state))
+ (case =return
+ (#Ok ?state ?value)
+ (#Ok (put slot ?state state) ?value)
+
+ _
+ =return))))
+
+(def monadic-dup
+ (exec [foo get-state
+ bar get-state
+ baz (return 1000)]
+ (return (+ (+ foo bar) baz))))
+
+(def (run-state monad state)
+ (monad state))
+
(def (interpose elem list)
(case list
(#Cons x (#Cons y list'))