aboutsummaryrefslogtreecommitdiff
path: root/new-luxc/source/luxc/analyser/reference.lux
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--new-luxc/source/luxc/analyser/reference.lux51
1 files changed, 51 insertions, 0 deletions
diff --git a/new-luxc/source/luxc/analyser/reference.lux b/new-luxc/source/luxc/analyser/reference.lux
new file mode 100644
index 000000000..ea0505c3b
--- /dev/null
+++ b/new-luxc/source/luxc/analyser/reference.lux
@@ -0,0 +1,51 @@
+(;module:
+ lux
+ (lux (control monad)
+ [macro #+ Monad<Lux>]
+ (type ["TC" check]))
+ (luxc ["&" base]
+ (lang ["la" analysis #+ Analysis])
+ ["&;" env]))
+
+## [Analysers]
+(def: (analyse-definition def-name)
+ (-> Ident (Lux Analysis))
+ (do Monad<Lux>
+ [actual (macro;find-def-type def-name)
+ expected macro;expected-type
+ _ (&;within-type-env
+ (TC;check expected actual))]
+ (wrap (#la;Absolute def-name))))
+
+(def: (analyse-variable var-name)
+ (-> Text (Lux (Maybe Analysis)))
+ (do Monad<Lux>
+ [?var (&env;find var-name)]
+ (case ?var
+ (#;Some [actual ref])
+ (do @
+ [expected macro;expected-type
+ _ (&;within-type-env
+ (TC;check expected actual))]
+ (wrap (#;Some (#la;Relative ref))))
+
+ #;None
+ (wrap #;None))))
+
+(def: #export (analyse-reference reference)
+ (-> Ident (Lux Analysis))
+ (case reference
+ ["" simple-name]
+ (do Monad<Lux>
+ [?var (analyse-variable simple-name)]
+ (case ?var
+ (#;Some analysis)
+ (wrap analysis)
+
+ #;None
+ (do @
+ [this-module macro;current-module-name]
+ (analyse-definition [this-module simple-name]))))
+
+ _
+ (analyse-definition reference)))