mirror of
https://github.com/anoma/juvix.git
synced 2024-11-30 14:13:27 +03:00
parent
fcd52a443f
commit
d60bcccffb
@ -882,15 +882,45 @@ goModule onlyTypes infoTable Internal.Module {..} =
|
||||
names :: HashSet Text
|
||||
names =
|
||||
HashSet.fromList $
|
||||
map (^. Internal.functionInfoName . namePretty) (filter (not . (^. Internal.functionInfoIsLocal)) (HashMap.elems (infoTable ^. Internal.infoFunctions)))
|
||||
++ map (^. Internal.constructorInfoName . namePretty) (HashMap.elems (infoTable ^. Internal.infoConstructors))
|
||||
++ map (^. Internal.inductiveInfoName . namePretty) (HashMap.elems (infoTable ^. Internal.infoInductives))
|
||||
++ map (^. Internal.axiomInfoDef . Internal.axiomName . namePretty) (HashMap.elems (infoTable ^. Internal.infoAxioms))
|
||||
map quote $
|
||||
map (^. Internal.functionInfoName . namePretty) (filter (not . (^. Internal.functionInfoIsLocal)) (HashMap.elems (infoTable ^. Internal.infoFunctions)))
|
||||
++ map (^. Internal.constructorInfoName . namePretty) (HashMap.elems (infoTable ^. Internal.infoConstructors))
|
||||
++ map (^. Internal.inductiveInfoName . namePretty) (HashMap.elems (infoTable ^. Internal.infoInductives))
|
||||
++ map (^. Internal.axiomInfoDef . Internal.axiomName . namePretty) (HashMap.elems (infoTable ^. Internal.infoAxioms))
|
||||
|
||||
quote :: Text -> Text
|
||||
quote txt = case Text.uncons txt of
|
||||
Just (c, txt') | not (isLetter c) -> txt'
|
||||
_ -> txt
|
||||
quote = quote' . Text.filter isLatin1 . Text.filter (isLetter .||. isDigit .||. (== '_') .||. (== '\''))
|
||||
|
||||
quote' :: Text -> Text
|
||||
quote' txt
|
||||
| HashSet.member txt reservedNames = quote' (prime txt)
|
||||
| txt == "_" = "v"
|
||||
| otherwise = case Text.uncons txt of
|
||||
Just (c, _) | not (isLetter c) -> quote' ("v_" <> txt)
|
||||
_ -> case Text.unsnoc txt of
|
||||
Just (_, c) | not (isAlphaNum c || c == '\'') -> quote' (txt <> "'")
|
||||
_ -> txt
|
||||
|
||||
reservedNames :: HashSet Text
|
||||
reservedNames =
|
||||
HashSet.fromList
|
||||
[ "begin",
|
||||
"bool",
|
||||
"case",
|
||||
"else",
|
||||
"end",
|
||||
"if",
|
||||
"imports",
|
||||
"in",
|
||||
"int",
|
||||
"let",
|
||||
"list",
|
||||
"nat",
|
||||
"of",
|
||||
"option",
|
||||
"theory",
|
||||
"then"
|
||||
]
|
||||
|
||||
filterTypeArgs :: Int -> Internal.Expression -> [a] -> [a]
|
||||
filterTypeArgs paramsNum ty args =
|
||||
|
@ -53,7 +53,7 @@ qfst : {A : Type} → Queue A → List A
|
||||
| (queue x _) := x;
|
||||
|
||||
qsnd : {A : Type} → Queue A → List A
|
||||
| (queue _ x) := x;
|
||||
| (queue _ v) := v;
|
||||
|
||||
pop_front {A} (q : Queue A) : Queue A :=
|
||||
let
|
||||
|
@ -55,10 +55,10 @@ datatype 'A Queue
|
||||
= queue "'A list" "'A list"
|
||||
|
||||
fun qfst :: "'A Queue \<Rightarrow> 'A list" where
|
||||
"qfst (queue x ω) = x"
|
||||
"qfst (queue x v) = x"
|
||||
|
||||
fun qsnd :: "'A Queue \<Rightarrow> 'A list" where
|
||||
"qsnd (queue ω x) = x"
|
||||
"qsnd (queue v v') = v'"
|
||||
|
||||
fun pop_front :: "'A Queue \<Rightarrow> 'A Queue" where
|
||||
"pop_front q =
|
||||
@ -66,7 +66,7 @@ fun pop_front :: "'A Queue \<Rightarrow> 'A Queue" where
|
||||
q' = queue (tl (qfst q)) (qsnd q)
|
||||
in case qfst q' of
|
||||
[] \<Rightarrow> queue (rev (qsnd q')) [] |
|
||||
ω \<Rightarrow> q')"
|
||||
v \<Rightarrow> q')"
|
||||
|
||||
fun push_back :: "'A Queue \<Rightarrow> 'A \<Rightarrow> 'A Queue" where
|
||||
"push_back q x =
|
||||
@ -80,8 +80,8 @@ fun is_empty :: "'A Queue \<Rightarrow> bool" where
|
||||
[] \<Rightarrow>
|
||||
(case qsnd q of
|
||||
[] \<Rightarrow> True |
|
||||
ω \<Rightarrow> False) |
|
||||
ω \<Rightarrow> False)"
|
||||
v \<Rightarrow> False) |
|
||||
v \<Rightarrow> False)"
|
||||
|
||||
definition empty :: "'A Queue" where
|
||||
"empty = queue [] []"
|
||||
|
Loading…
Reference in New Issue
Block a user