-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
refactor: Rename UserName to QualName #56
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,9 +7,9 @@ import Brat.Error (Error(..), ErrorMsg(..), dumbErr) | |
import Brat.FC (FC) | ||
import Brat.Graph | ||
import Brat.Naming (fresh, split, Name, Namespace, FreshMonad(..)) | ||
import Brat.QualName (QualName) | ||
import Brat.Syntax.Common | ||
import Brat.Syntax.Value | ||
import Brat.UserName (UserName) | ||
import Hasochism | ||
import Util | ||
|
||
|
@@ -54,8 +54,8 @@ data Context = Ctx { globalVEnv :: VEnv | |
, store :: Store | ||
, constructors :: ConstructorMap Brat | ||
, kconstructors :: ConstructorMap Kernel | ||
, typeConstructors :: M.Map (Mode, UserName) [(PortName, TypeKind)] | ||
, aliasTable :: M.Map UserName Alias | ||
, typeConstructors :: M.Map (Mode, QualName) [(PortName, TypeKind)] | ||
, aliasTable :: M.Map QualName Alias | ||
} | ||
|
||
data CheckingSig ty where | ||
|
@@ -64,24 +64,24 @@ data CheckingSig ty where | |
Throw :: Error -> CheckingSig a | ||
LogHole :: TypedHole -> CheckingSig () | ||
AskFC :: CheckingSig FC | ||
VLup :: UserName -> CheckingSig (Maybe [(Src, BinderType Brat)]) | ||
KLup :: UserName -> CheckingSig (Maybe (Src, BinderType Kernel)) | ||
VLup :: QualName -> CheckingSig (Maybe [(Src, BinderType Brat)]) | ||
KLup :: QualName -> CheckingSig (Maybe (Src, BinderType Kernel)) | ||
-- Lookup type constructors | ||
TLup :: (Mode, UserName) -> CheckingSig (Maybe [(PortName, TypeKind)]) | ||
TLup :: (Mode, QualName) -> CheckingSig (Maybe [(PortName, TypeKind)]) | ||
-- Lookup term constructor - ask whether a constructor builds a certain type | ||
CLup :: FC -- File context for error reporting | ||
-> UserName -- Value constructor | ||
-> UserName -- Type constructor | ||
-> QualName -- Value constructor | ||
-> QualName -- Type constructor | ||
-> CheckingSig (CtorArgs Brat) | ||
-- Lookup kernel constructors | ||
KCLup :: FC -- File context for error reporting | ||
-> UserName -- Value constructor | ||
-> UserName -- Type constructor | ||
-> QualName -- Value constructor | ||
-> QualName -- Type constructor | ||
-> CheckingSig (CtorArgs Kernel) | ||
-- Lookup an end in the Store | ||
ELup :: End -> CheckingSig (Maybe (Val Z)) | ||
-- Lookup an alias in the table | ||
ALup :: UserName -> CheckingSig (Maybe Alias) | ||
ALup :: QualName -> CheckingSig (Maybe Alias) | ||
TypeOf :: End -> CheckingSig EndType | ||
AddNode :: Name -> Node -> CheckingSig () | ||
Wire :: Wire -> CheckingSig () | ||
|
@@ -90,7 +90,7 @@ data CheckingSig ty where | |
Declare :: End -> Modey m -> BinderType m -> CheckingSig () | ||
Define :: End -> Val Z -> CheckingSig () | ||
|
||
localAlias :: (UserName, Alias) -> Checking v -> Checking v | ||
localAlias :: (QualName, Alias) -> Checking v -> Checking v | ||
localAlias _ (Ret v) = Ret v | ||
localAlias con@(name, alias) (Req (ALup u) k) | ||
| u == name = localAlias con $ k (Just alias) | ||
|
@@ -124,7 +124,7 @@ captureOuterLocals c = do | |
helper (outerLocals, M.empty) c | ||
where | ||
helper :: (VEnv, VEnv) -> Checking v | ||
-> Checking (v, M.Map UserName [(Src, BinderType Brat)]) | ||
-> Checking (v, M.Map QualName [(Src, BinderType Brat)]) | ||
helper (_, captured) (Ret v) = Ret (v, captured) | ||
helper (avail, captured) (Req (VLup x) k) | j@(Just new) <- M.lookup x avail = | ||
helper (avail, M.insert x new captured) (k j) | ||
|
@@ -139,29 +139,29 @@ throwLeft :: Either ErrorMsg a -> Checking a | |
throwLeft (Right x) = pure x | ||
throwLeft (Left msg) = err msg | ||
|
||
vlup :: UserName -> Checking [(Src, BinderType Brat)] | ||
vlup :: QualName -> Checking [(Src, BinderType Brat)] | ||
vlup s = do | ||
req (VLup s) >>= \case | ||
Just vty -> pure vty | ||
Nothing -> err $ VarNotFound (show s) | ||
|
||
alup :: UserName -> Checking Alias | ||
alup :: QualName -> Checking Alias | ||
alup s = do | ||
req (ALup s) >>= \case | ||
Just vty -> pure vty | ||
Nothing -> err $ VarNotFound (show s) | ||
|
||
clup :: UserName -- Value constructor | ||
-> UserName -- Type constructor | ||
clup :: QualName -- Value constructor | ||
-> QualName -- Type constructor | ||
-> Checking (CtorArgs Brat) | ||
clup vcon tycon = req AskFC >>= \fc -> req (CLup fc vcon tycon) | ||
|
||
kclup :: UserName -- Value constructor | ||
-> UserName -- Type constructor | ||
kclup :: QualName -- Value constructor | ||
-> QualName -- Type constructor | ||
-> Checking (CtorArgs Kernel) | ||
kclup vcon tycon = req AskFC >>= \fc -> req (KCLup fc vcon tycon) | ||
|
||
tlup :: (Mode, UserName) -> Checking [(PortName, TypeKind)] | ||
tlup :: (Mode, QualName) -> Checking [(PortName, TypeKind)] | ||
tlup (m, c) = req (TLup (m, c)) >>= \case | ||
Nothing -> req (TLup (otherMode, c)) >>= \case | ||
Nothing -> err $ UnrecognisedTypeCon (show c) | ||
|
@@ -172,7 +172,7 @@ tlup (m, c) = req (TLup (m, c)) >>= \case | |
Brat -> Kernel | ||
Kernel -> Brat | ||
|
||
lookupAndUse :: UserName -> KEnv | ||
lookupAndUse :: QualName -> KEnv | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Similarly, if it's something that might be used then will it really be a QualName? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. variables are parsed as qualified names, so they can include prefixes There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Even kernel names? Can declare a variable of type qubit whose name has a prefix? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah I see, we could be more strict about kernel variables, you're right |
||
-> Either Error (Maybe ((Src, BinderType Kernel), KEnv)) | ||
lookupAndUse x kenv = case M.lookup x kenv of | ||
Nothing -> Right Nothing | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oooh, that's odd. We can have qualified names of variables?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think when we have functions imported from other modules they should be qualified, like
kernel.CX
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah right yes thank you. Ok - so
vlup
is really the misnamed one - it does not necessarily look up variables; it just looks up names. Really should benlup
orqnlup
or justlup
(orblup
to distinguish fromklup
? Hey, that one's actually pronouncable in one syllable... 😁 😀 )