aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEduardo Julian2016-05-21 20:43:20 -0400
committerEduardo Julian2016-05-21 20:43:20 -0400
commitaa4722d0c459a59ac896ef1b30ff0e141281d41c (patch)
tree0aa53a864d532d76ad3fec2adfeea40b719a7a8d
parent55442e41b5889692e2bbacc0f943bd3382e6e11e (diff)
- Merged _lux_alias into _lux_import.
-rw-r--r--src/lux/analyser.clj12
-rw-r--r--src/lux/analyser/lux.clj13
-rw-r--r--src/lux/analyser/module.clj31
3 files changed, 26 insertions, 30 deletions
diff --git a/src/lux/analyser.clj b/src/lux/analyser.clj
index 73d89e036..c5993ce83 100644
--- a/src/lux/analyser.clj
+++ b/src/lux/analyser.clj
@@ -152,18 +152,12 @@
(&/with-cursor cursor
(&&lux/analyse-def analyse optimize eval! compile-def ?name ?value ?meta)))
- "_lux_alias"
- (|let [(&/$Cons [_ (&/$TextS ?alias)]
- (&/$Cons [_ (&/$TextS ?module)]
- (&/$Nil))) parameters]
- (&/with-cursor cursor
- (&&lux/analyse-alias analyse ?alias ?module)))
-
"_lux_import"
(|let [(&/$Cons [_ (&/$TextS ?path)]
- (&/$Nil)) parameters]
+ (&/$Cons [_ (&/$TextS ?alias)]
+ (&/$Nil))) parameters]
(&/with-cursor cursor
- (&&lux/analyse-import analyse compile-module ?path)))
+ (&&lux/analyse-import analyse compile-module ?path ?alias)))
"_lux_program"
(|let [(&/$Cons [_ (&/$SymbolS "" ?args)]
diff --git a/src/lux/analyser/lux.clj b/src/lux/analyser/lux.clj
index a0891371b..0ce5c060a 100644
--- a/src/lux/analyser/lux.clj
+++ b/src/lux/analyser/lux.clj
@@ -578,7 +578,7 @@
(return &/$Nil))
)))
-(defn analyse-import [analyse compile-module path]
+(defn analyse-import [analyse compile-module path ex-alias]
(|do [_ &/ensure-statement
module-name &/get-module-name
_ (if (= module-name path)
@@ -591,15 +591,12 @@
_ (&&module/add-import path)
_ (if (not already-compiled?)
(compile-module path)
- (return nil))]
+ (return nil))
+ _ (if (= "" ex-alias)
+ (return nil)
+ (&&module/alias module-name ex-alias path))]
(return &/$Nil)))))
-(defn analyse-alias [analyse ex-alias ex-module]
- (|do [_ &/ensure-statement
- module-name &/get-module-name
- _ (&&module/alias module-name ex-alias ex-module)]
- (return &/$Nil)))
-
(defn ^:private coerce [new-type analysis]
"(-> Type Analysis Analysis)"
(|let [[[_type _cursor] _analysis] analysis]
diff --git a/src/lux/analyser/module.clj b/src/lux/analyser/module.clj
index 3ee9d28d4..4124503bd 100644
--- a/src/lux/analyser/module.clj
+++ b/src/lux/analyser/module.clj
@@ -137,19 +137,24 @@
(defn alias [module alias reference]
(fn [state]
- (if-let [real-name (->> state (&/get$ &/$modules) (&/|get module) (&/get$ $module-aliases) (&/|get alias))]
- ((&/fail-with-loc (str "[Analyser Error] Can't re-use alias \"" alias "\" @ " module))
- state)
- (return* (->> state
- (&/update$ &/$modules
- (fn [ms]
- (&/|update module
- #(&/update$ $module-aliases
- (fn [aliases]
- (&/|put alias reference aliases))
- %)
- ms))))
- nil))))
+ (let [_module_ (->> state (&/get$ &/$modules) (&/|get module))]
+ (if (&/|member? module (->> _module_ (&/get$ $imports)))
+ ((&/fail-with-loc (str "[Analyser Error] Can't create alias that is the same as a module nameL " (pr-str alias) " for " reference))
+ state)
+ (if-let [real-name (->> _module_ (&/get$ $module-aliases) (&/|get alias))]
+ ((&/fail-with-loc (str "[Analyser Error] Can't re-use alias \"" alias "\" @ " module))
+ state)
+ (return* (->> state
+ (&/update$ &/$modules
+ (fn [ms]
+ (&/|update module
+ #(&/update$ $module-aliases
+ (fn [aliases]
+ (&/|put alias reference aliases))
+ %)
+ ms))))
+ nil))))
+ ))
(defn find-def [module name]
(|do [current-module &/get-module-name]