aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEduardo Julian2015-05-14 08:23:10 -0400
committerEduardo Julian2015-05-14 08:23:10 -0400
commitc4ac3e692ae96d6898d8efb42faf4dfadd43f4ae (patch)
treed6d33dd608fb73cb753d412f43efcfe70a97b22e
parent279598fd1d5aace000231e4e85e5f9967634ce81 (diff)
- Removed the apparently unnecessary total-locals.
Diffstat (limited to '')
-rw-r--r--source/lux.lux46
-rw-r--r--source/program.lux2
-rw-r--r--src/lux.clj2
-rw-r--r--src/lux/compiler/base.clj101
-rw-r--r--src/lux/compiler/lambda.clj9
5 files changed, 36 insertions, 124 deletions
diff --git a/source/lux.lux b/source/lux.lux
index 3b7bb9702..1385cf8a5 100644
--- a/source/lux.lux
+++ b/source/lux.lux
@@ -1876,7 +1876,7 @@
[Int:Ord Int _jvm_llt _jvm_lgt _jvm_leq]
[Real:Ord Real _jvm_dlt _jvm_dgt _jvm_deq])
-(defmacro #export (alias-lux tokens state)
+(defmacro #export (lux tokens state)
(case state
{#source source #modules modules #module-aliases module-aliases
#envs envs #types types #host host
@@ -2005,12 +2005,42 @@
_
(let [dummy ($symbol ["" ""])]
(#Right [state (list (` (_lux_case (~ struct)
- (~ dummy)
- (using (~ dummy) (~ body)))))])))
+ (~ dummy)
+ (using (~ dummy) (~ body)))))])))
_
(#Left "Wrong syntax for defsig")))
+(defmacro #export (when tokens)
+ (case tokens
+ (\ (list test body))
+ (return (list (` (if (~ test)
+ (#Some (~ body))
+ #None))))
+
+ _
+ (fail "Wrong syntax for when")))
+
+(def #export (flip f)
+ (All [a b c]
+ (-> (-> a b c) (-> b a c)))
+ (lambda [y x]
+ (f x y)))
+
+## (def #export (curry f)
+## (All [a b c]
+## (-> (-> (, a b) c)
+## (-> a b c)))
+## (lambda [x y]
+## (f [x y])))
+
+## (def #export (uncurry f)
+## (All [a b c]
+## (-> (-> a b c)
+## (-> (, a b) c)))
+## (lambda [[x y]]
+## (f x y)))
+
## (defmacro (loop tokens)
## (_lux_case tokens
## (#Cons [bindings (#Cons [body #Nil])])
@@ -2054,13 +2084,3 @@
## (` (lambda [func record]
## (set@' (~ tag) (func (get@' (~ tag) record)) record))))]
## (return (list output))))
-
-## (do-template [<name> <member> <type>]
-## (def (<name> pair)
-## (All [a b] (-> (, a b) <type>))
-## (case pair
-## [f s]
-## <member>))
-
-## [first f a]
-## [second s b])
diff --git a/source/program.lux b/source/program.lux
index 20f7863ab..a9451580f 100644
--- a/source/program.lux
+++ b/source/program.lux
@@ -1,4 +1,4 @@
-(;alias-lux)
+(;lux)
(def (filter p xs)
(All [a] (-> (-> a Bool) (List a) (List a)))
diff --git a/src/lux.clj b/src/lux.clj
index 62e9d14f9..5b32955a3 100644
--- a/src/lux.clj
+++ b/src/lux.clj
@@ -9,7 +9,5 @@
(System/exit 0))
(comment
- ;; TODO: Finish total-locals
-
;; cd output && jar cvf program.jar * && java -cp "program.jar" program && cd ..
)
diff --git a/src/lux/compiler/base.clj b/src/lux/compiler/base.clj
index c0a54ba53..a7886ab48 100644
--- a/src/lux/compiler/base.clj
+++ b/src/lux/compiler/base.clj
@@ -30,104 +30,3 @@
:let [_ (write-class name bytecode)
_ (load-class! loader (string/replace name #"/" "."))]]
(return nil)))
-
-(defn total-locals [expr]
- (matchv ::M/objects [expr]
- [[?struct ?type]]
- (matchv ::M/objects [?struct]
- [["case" [?variant ?base-register ?num-registers ?branches]]]
- (+ ?num-registers (&/fold max 0 (&/|map (comp total-locals second) ?branches)))
-
- [["tuple" ?members]]
- (&/fold max 0 (&/|map total-locals ?members))
-
- [["variant" [?tag ?value]]]
- (total-locals ?value)
-
- [["call" [?fn ?args]]]
- (&/fold max 0 (&/|map total-locals (&/|cons ?fn ?args)))
-
- [["jvm-iadd" [?x ?y]]]
- (&/fold max 0 (&/|map total-locals (&/|list ?x ?y)))
-
- [["jvm-isub" [?x ?y]]]
- (&/fold max 0 (&/|map total-locals (&/|list ?x ?y)))
-
- [["jvm-imul" [?x ?y]]]
- (&/fold max 0 (&/|map total-locals (&/|list ?x ?y)))
-
- [["jvm-idiv" [?x ?y]]]
- (&/fold max 0 (&/|map total-locals (&/|list ?x ?y)))
-
- [["jvm-irem" [?x ?y]]]
- (&/fold max 0 (&/|map total-locals (&/|list ?x ?y)))
-
- [["jvm-ladd" [?x ?y]]]
- (&/fold max 0 (&/|map total-locals (&/|list ?x ?y)))
-
- [["jvm-lsub" [?x ?y]]]
- (&/fold max 0 (&/|map total-locals (&/|list ?x ?y)))
-
- [["jvm-lmul" [?x ?y]]]
- (&/fold max 0 (&/|map total-locals (&/|list ?x ?y)))
-
- [["jvm-ldiv" [?x ?y]]]
- (&/fold max 0 (&/|map total-locals (&/|list ?x ?y)))
-
- [["jvm-lrem" [?x ?y]]]
- (&/fold max 0 (&/|map total-locals (&/|list ?x ?y)))
-
- [["jvm-fadd" [?x ?y]]]
- (&/fold max 0 (&/|map total-locals (&/|list ?x ?y)))
-
- [["jvm-fsub" [?x ?y]]]
- (&/fold max 0 (&/|map total-locals (&/|list ?x ?y)))
-
- [["jvm-fmul" [?x ?y]]]
- (&/fold max 0 (&/|map total-locals (&/|list ?x ?y)))
-
- [["jvm-fdiv" [?x ?y]]]
- (&/fold max 0 (&/|map total-locals (&/|list ?x ?y)))
-
- [["jvm-frem" [?x ?y]]]
- (&/fold max 0 (&/|map total-locals (&/|list ?x ?y)))
-
- [["jvm-dadd" [?x ?y]]]
- (&/fold max 0 (&/|map total-locals (&/|list ?x ?y)))
-
- [["jvm-dsub" [?x ?y]]]
- (&/fold max 0 (&/|map total-locals (&/|list ?x ?y)))
-
- [["jvm-dmul" [?x ?y]]]
- (&/fold max 0 (&/|map total-locals (&/|list ?x ?y)))
-
- [["jvm-ddiv" [?x ?y]]]
- (&/fold max 0 (&/|map total-locals (&/|list ?x ?y)))
-
- [["jvm-drem" [?x ?y]]]
- (&/fold max 0 (&/|map total-locals (&/|list ?x ?y)))
-
- [["|do" ?exprs]]
- (&/fold max 0 (&/|map total-locals ?exprs))
-
- [["jvm-new" [?class ?classes ?args]]]
- (&/fold max 0 (&/|map total-locals ?args))
-
- [["jvm-invokestatic" [?class ?method ?classes ?args]]]
- (&/fold max 0 (&/|map total-locals ?args))
-
- [["jvm-invokevirtual" [?class ?method ?classes ?object ?args]]]
- (&/fold max 0 (&/|map total-locals ?args))
-
- [["jvm-aastore" [?array ?idx ?elem]]]
- (&/fold max 0 (&/|map total-locals (&/|list ?array ?elem)))
-
- [["jvm-aaload" [?array ?idx]]]
- (total-locals ?array)
-
- ;; [["lambda" _]]
- ;; 0
-
- [_]
- 0
- )))
diff --git a/src/lux/compiler/lambda.clj b/src/lux/compiler/lambda.clj
index 625599617..42ed5459e 100644
--- a/src/lux/compiler/lambda.clj
+++ b/src/lux/compiler/lambda.clj
@@ -59,13 +59,8 @@
(&/with-writer (doto (.visitMethod ^ClassWriter class Opcodes/ACC_PUBLIC "impl" impl-signature nil nil)
(.visitCode))
(|do [^MethodVisitor *writer* &/get-writer
- :let [num-locals (&&/total-locals impl-body)
- $start (new Label)
- $end (new Label)
- _ (doto *writer*
- (-> (.visitLocalVariable (str &&/local-prefix idx) "Ljava/lang/Object;" nil $start $end (+ 2 idx))
- (->> (dotimes [idx num-locals])))
- (.visitLabel $start))]
+ :let [$start (new Label)
+ $end (new Label)]
ret (compile impl-body)
:let [_ (doto *writer*
(.visitLabel $end)