aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorEduardo Julian2015-03-08 12:44:42 -0400
committerEduardo Julian2015-03-08 12:44:42 -0400
commit57f89f16e95749e4ee4ad98a4e3d7a7908fb9a2f (patch)
treef132d6aa08184c2772e335fabae82167e3a68c3a /src
parent33f318849c0702b254eccf79f6ef9b7015e4537b (diff)
- The implementation of monadic macros is finally finished.
Diffstat (limited to 'src')
-rw-r--r--src/lux.clj1
-rw-r--r--src/lux/analyser/lux.clj10
-rw-r--r--src/lux/compiler/lux.clj2
-rw-r--r--src/lux/macro.clj19
4 files changed, 15 insertions, 17 deletions
diff --git a/src/lux.clj b/src/lux.clj
index ce843d0cd..888618de6 100644
--- a/src/lux.clj
+++ b/src/lux.clj
@@ -3,7 +3,6 @@
:reload-all))
(comment
- ;; TODO: Make macros monadic.
;; TODO: Finish type system.
;; TODO: Re-implement compiler in language.
;; TODO: Adding metadata to global vars.
diff --git a/src/lux/analyser/lux.clj b/src/lux/analyser/lux.clj
index 570048dcd..75b6f375a 100644
--- a/src/lux/analyser/lux.clj
+++ b/src/lux/analyser/lux.clj
@@ -60,13 +60,9 @@
[::&&/global ?module ?name]
(exec [macro? (&&def/macro? ?module ?name)]
(if macro?
- (let [macro-class (&host/location (list ?module ?name))
- [macro-expansion state*] (&macro/expand loader macro-class ?args)
- ;; _ (prn 'macro-expansion)
- ;; _ (doseq [ast macro-expansion]
- ;; (prn '=> ast))
- ]
- (mapcat-m analyse macro-expansion))
+ (let [macro-class (&host/location (list ?module ?name))]
+ (exec [macro-expansion (&macro/expand loader macro-class ?args)]
+ (mapcat-m analyse macro-expansion)))
(exec [=args (mapcat-m analyse ?args)]
(return (list [::&&/Expression [::&&/call =fn =args] &type/+dont-care-type+])))))
diff --git a/src/lux/compiler/lux.clj b/src/lux/compiler/lux.clj
index f85d2f7a5..7e9e55b23 100644
--- a/src/lux/compiler/lux.clj
+++ b/src/lux/compiler/lux.clj
@@ -87,7 +87,7 @@
(return nil)))
(defn compile-captured [compile *type* ?scope ?captured-id ?source]
- (prn 'compile-captured ?scope ?captured-id)
+ ;; (prn 'compile-captured ?scope ?captured-id)
(exec [*writer* &/get-writer
:let [_ (doto *writer*
(.visitVarInsn Opcodes/ALOAD 0)
diff --git a/src/lux/macro.clj b/src/lux/macro.clj
index 071f95691..9f42d6402 100644
--- a/src/lux/macro.clj
+++ b/src/lux/macro.clj
@@ -1,6 +1,7 @@
(ns lux.macro
(:require [clojure.core.match :refer [match]]
- [lux.parser :as &parser]))
+ (lux [base :as & :refer [fail* return*]]
+ [parser :as &parser])))
;; [Utils]
(defn ^:private ->lux+ [->lux loader xs]
@@ -63,10 +64,12 @@
;; [Resources]
(defn expand [loader macro-class tokens]
- (let [output (-> (.loadClass loader macro-class)
- (.getField "_datum")
- (.get nil)
- (.apply (->lux+ ->lux loader tokens))
- (.apply nil))]
- [(->clojure+ ->clojure (aget output 0))
- (aget output 1)]))
+ (fn [state]
+ (let [output (-> (.loadClass loader macro-class)
+ (.getField "_datum")
+ (.get nil)
+ (.apply (->lux+ ->lux loader tokens))
+ (.apply state))]
+ (case (aget output 0)
+ "Ok" (return* (aget output 1 0) (->clojure+ ->clojure (aget output 1 1)))
+ "Error" (fail* (aget output 1))))))