(;module:
lux
(lux (control monad)
[meta]
(meta [code]
(type ["tc" check])))
(luxc ["&" base]
(lang ["la" analysis #+ Analysis]
[";L" variable #+ Variable])
["&;" scope]))
## [Analysers]
(def: (analyse-definition def-name)
(-> Ident (Meta Analysis))
(do meta;Monad
[actualT (meta;find-def-type def-name)
_ (&;infer actualT)]
(wrap (code;symbol def-name))))
(def: (analyse-variable var-name)
(-> Text (Meta (Maybe Analysis)))
(do meta;Monad
[?var (&scope;find var-name)]
(case ?var
(#;Some [actualT ref])
(do @
[_ (&;infer actualT)]
(wrap (#;Some (` ((~ (code;int (variableL;from-ref ref))))))))
#;None
(wrap #;None))))
(def: #export (analyse-reference reference)
(-> Ident (Meta Analysis))
(case reference
["" simple-name]
(do meta;Monad
[?var (analyse-variable simple-name)]
(case ?var
(#;Some varA)
(wrap varA)
#;None
(do @
[this-module meta;current-module-name]
(analyse-definition [this-module simple-name]))))
_
(analyse-definition reference)))