aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/lux/analyser/lux.clj4
-rw-r--r--src/lux/analyser/module.clj55
-rw-r--r--src/lux/base.clj2
3 files changed, 37 insertions, 24 deletions
diff --git a/src/lux/analyser/lux.clj b/src/lux/analyser/lux.clj
index c50f26437..b4f87f140 100644
--- a/src/lux/analyser/lux.clj
+++ b/src/lux/analyser/lux.clj
@@ -268,14 +268,14 @@
(defn ^:private analyse-global [analyse exo-type module name]
(|do [[[r-module r-name] [endo-type ?meta ?value]] (&&module/find-def module name)
+ ;; This is a small shortcut to optimize analysis of typing code.
_ (if (and (clojure.lang.Util/identical &type/Type endo-type)
(clojure.lang.Util/identical &type/Type exo-type))
(return nil)
(&type/check exo-type endo-type))
_cursor &/cursor]
(return (&/|list (&&/|meta endo-type _cursor
- (&&/$var (&/$Global (&/T [r-module r-name])))
- )))))
+ (&&/$var (&/$Global (&/T [r-module r-name]))))))))
(defn ^:private analyse-local [analyse exo-type name]
(fn [state]
diff --git a/src/lux/analyser/module.clj b/src/lux/analyser/module.clj
index f35334399..ead4ffc67 100644
--- a/src/lux/analyser/module.clj
+++ b/src/lux/analyser/module.clj
@@ -159,31 +159,44 @@
nil))))
))
+(defn ^:private imports? [state imported-module source-module]
+ (->> state
+ (&/get$ &/$modules)
+ (&/|get source-module)
+ (&/get$ $imports)
+ (&/|any? (partial = imported-module))))
+
(defn find-def [module name]
(|do [current-module &/get-module-name]
(fn [state]
- (if-let [$module (->> state (&/get$ &/$modules) (&/|get module))]
- (if-let [$def (->> $module (&/get$ $defs) (&/|get name))]
- (|let [[?type ?meta ?value] $def]
- (if (.equals ^Object current-module module)
- (|case (&meta/meta-get &meta/alias-tag ?meta)
- (&/$Some (&/$IdentM [?r-module ?r-name]))
- ((find-def ?r-module ?r-name)
- state)
-
- _
- (return* state (&/T [(&/T [module name]) $def])))
- (|case (&meta/meta-get &meta/export?-tag ?meta)
- (&/$Some (&/$BoolM true))
- (return* state (&/T [(&/T [module name]) $def]))
-
- _
- ((&/fail-with-loc (str "[Analyser Error] Can't use unexported definition: " (str module &/+name-separator+ name)))
- state))))
- ((&/fail-with-loc (str "[Analyser Error] Definition does not exist: " (str module &/+name-separator+ name)))
+ (if (or (= "lux" module)
+ (= current-module module)
+ (imports? state module current-module))
+ (if-let [$module (->> state (&/get$ &/$modules) (&/|get module))]
+ (if-let [$def (->> $module (&/get$ $defs) (&/|get name))]
+ (|let [[?type ?meta ?value] $def]
+ (if (.equals ^Object current-module module)
+ (|case (&meta/meta-get &meta/alias-tag ?meta)
+ (&/$Some (&/$IdentM [?r-module ?r-name]))
+ ((find-def ?r-module ?r-name)
+ state)
+
+ _
+ (return* state (&/T [(&/T [module name]) $def])))
+ (|case (&meta/meta-get &meta/export?-tag ?meta)
+ (&/$Some (&/$BoolM true))
+ (return* state (&/T [(&/T [module name]) $def]))
+
+ _
+ ((&/fail-with-loc (str "[Analyser Error] Can't use unexported definition: " (str module &/+name-separator+ name)))
+ state))))
+ ((&/fail-with-loc (str "[Analyser Error] Definition does not exist: " (str module &/+name-separator+ name)))
+ state))
+ ((&/fail-with-loc (str "[Analyser Error] Module doesn't exist: " module))
state))
- ((&/fail-with-loc (str "[Analyser Error] Module doesn't exist: " module))
- state)))))
+ ((&/fail-with-loc (str "[Analyser Error] Unknown module: " module))
+ state))
+ )))
(defn ensure-type-def [def-data]
"(-> DefData (Lux Type))"
diff --git a/src/lux/base.clj b/src/lux/base.clj
index b5bd4e732..3c4438c63 100644
--- a/src/lux/base.clj
+++ b/src/lux/base.clj
@@ -1244,7 +1244,7 @@
<default>
($Cons x xs*)
- (<op> (p x) (|every? p xs*))))
+ (<op> (p x) (<name> p xs*))))
|every? true and
|any? false or)