(;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)
expectedT meta;expected-type
_ (&;with-type-env
(tc;check expectedT 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 @
[expectedT meta;expected-type
_ (&;with-type-env
(tc;check expectedT 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 analysis)
(wrap analysis)
#;None
(do @
[this-module meta;current-module-name]
(analyse-definition [this-module simple-name]))))
_
(analyse-definition reference)))