aboutsummaryrefslogtreecommitdiff
path: root/src/lux/analyser/module.clj
diff options
context:
space:
mode:
authorEduardo Julian2015-05-01 16:38:41 -0400
committerEduardo Julian2015-05-01 16:38:41 -0400
commitf3cc638b9dd31d06b9cf3e51dff8fb6352f22c7c (patch)
tree0c8dfba719163a102571bbdc637ef0e956ae079b /src/lux/analyser/module.clj
parent10081333a9e116d087825ec7be31099ab4bbe97d (diff)
- declare-macro has returned.
- Method-invocation special forms now take the wanted method as an unprefixed symbol, instead of as text. - Some fixes in lux.analyser.host. - Lambda analysis now just returns the origin exo-type instead of the endo-type. - Made some changes to the type of the CompilerState.
Diffstat (limited to 'src/lux/analyser/module.clj')
-rw-r--r--src/lux/analyser/module.clj32
1 files changed, 31 insertions, 1 deletions
diff --git a/src/lux/analyser/module.clj b/src/lux/analyser/module.clj
index ac5968026..6f82d9b6f 100644
--- a/src/lux/analyser/module.clj
+++ b/src/lux/analyser/module.clj
@@ -2,7 +2,8 @@
(:require [clojure.core.match :as M :refer [matchv]]
clojure.core.match.array
(lux [base :as & :refer [|do return return* fail fail*]]
- [type :as &type])
+ [type :as &type]
+ [host :as &host])
[lux.analyser.base :as &&]))
;; [Exports]
@@ -54,6 +55,35 @@
(return true))
(return false))))
+(defn declare-macro [module name]
+ (fn [state]
+ (if-let [$module (->> state (&/get$ &/$MODULES) (&/|get module))]
+ (if-let [$def (&/|get name $module)]
+ (matchv ::M/objects [$def]
+ [["lux;ValueD" ?type]]
+ (do ;; (prn 'declare-macro/?type (aget ?type 0))
+ (&/run-state (|do [_ (&type/check &type/Macro ?type)
+ loader &/loader
+ :let [macro (-> (.loadClass loader (&host/location (&/|list module name)))
+ (.getField "_datum")
+ (.get nil))]]
+ (fn [state*]
+ (return* (&/update$ &/$MODULES
+ (fn [$modules]
+ (&/|put module (&/|put name (&/V "lux;MacroD" (&/V "lux;Some" macro)) $module)
+ $modules))
+ state*)
+ nil)))
+ state))
+
+ [["lux;MacroD" _]]
+ (fail* (str "[Analyser Error] Can't re-declare a macro: " (str module &/+name-separator+ name)))
+
+ [["lux;TypeD" _]]
+ (fail* (str "[Analyser Error] Definition doesn't have macro type: " module ";" name)))
+ (fail* (str "[Analyser Error] Definition doesn't exist: " (str module &/+name-separator+ name))))
+ (fail* (str "[Analyser Error] Module doesn't exist: " module)))))
+
(defn install-macro [module name macro]
(fn [state]
(if-let [$module (->> state (&/get$ &/$MODULES) (&/|get module))]