diff options
Diffstat (limited to '')
-rw-r--r-- | src/lux/analyser.clj | 12 | ||||
-rw-r--r-- | src/lux/analyser/lux.clj | 13 | ||||
-rw-r--r-- | src/lux/analyser/module.clj | 31 |
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] |