aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source/lux/lang/compiler
diff options
context:
space:
mode:
authorEduardo Julian2018-07-04 20:11:57 -0400
committerEduardo Julian2018-07-04 20:11:57 -0400
commit7179bb2ea733a99c326642abbf48638d540ff651 (patch)
treedb6564d6d7cf130ff28d9d4e589c47282a851378 /stdlib/source/lux/lang/compiler
parent08bcad002a638a8eb3ff963f004cb4ea584e4287 (diff)
- Test (and fix) that global-reference analysis only allows you to see definitions within your current module, or exports from imported modules.
Diffstat (limited to 'stdlib/source/lux/lang/compiler')
-rw-r--r--stdlib/source/lux/lang/compiler/analysis/reference.lux44
1 files changed, 32 insertions, 12 deletions
diff --git a/stdlib/source/lux/lang/compiler/analysis/reference.lux b/stdlib/source/lux/lang/compiler/analysis/reference.lux
index 6f4908f9d..5652e21fc 100644
--- a/stdlib/source/lux/lang/compiler/analysis/reference.lux
+++ b/stdlib/source/lux/lang/compiler/analysis/reference.lux
@@ -1,29 +1,49 @@
(.module:
lux
- (lux (control monad)
+ (lux (control monad
+ ["ex" exception #+ exception:])
[macro]
(macro [code])
- (lang (type ["tc" check])))
+ (lang (type ["tc" check]))
+ (data [text "text/" Eq<Text>]
+ text/format))
[///]
[// #+ Analysis Operation]
[//type]
[////reference]
[////scope])
+(exception: #export (foreign-module-has-not-been-imported {current Text} {foreign Text})
+ (ex.report ["Current" current]
+ ["Foreign" foreign]))
+
+(exception: #export (definition-has-not-been-expored {definition Ident})
+ (ex.report ["Definition" (%ident definition)]))
+
## [Analysers]
(def: (definition def-name)
(-> Ident (Operation Analysis))
- (do ///.Monad<Operation>
- [[actualT def-anns _] (macro.find-def def-name)]
- (case (macro.get-symbol-ann (ident-for #.alias) def-anns)
- (#.Some real-def-name)
- (definition real-def-name)
+ (with-expansions [<return> (wrap (|> def-name ////reference.constant #//.Reference))]
+ (do ///.Monad<Operation>
+ [[actualT def-anns _] (macro.find-def def-name)]
+ (case (macro.get-symbol-ann (ident-for #.alias) def-anns)
+ (#.Some real-def-name)
+ (definition real-def-name)
- _
- (do @
- [_ (//type.infer actualT)]
- (:: @ map (|>> ////reference.constant #//.Reference)
- (macro.normalize def-name))))))
+ _
+ (do @
+ [_ (//type.infer actualT)
+ (^@ def-name [::module ::name]) (macro.normalize def-name)
+ current macro.current-module-name]
+ (if (text/= current ::module)
+ <return>
+ (if (macro.export? def-anns)
+ (do @
+ [imported! (macro.imported-by? ::module current)]
+ (if imported!
+ <return>
+ (///.throw foreign-module-has-not-been-imported [current ::module])))
+ (///.throw definition-has-not-been-expored def-name))))))))
(def: (variable var-name)
(-> Text (Operation (Maybe Analysis)))