-
Notifications
You must be signed in to change notification settings - Fork 16
feat: syntactic variants #53
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
base: dev-integrity
Are you sure you want to change the base?
Changes from 17 commits
0dea01a
c15e976
d2ea71f
722c85c
84aef99
b8b6623
36f8058
4c51524
739ca5f
eac4175
3946cc1
d1a5c75
d454c79
c573aa3
4b1f2e0
9a51a78
8945a4a
1ba80b8
906dc93
901044d
cc89735
94d3055
c753e9f
e342e53
62af7cb
ca0a701
50495d4
62a6282
3e3ca7c
edfc383
5b9c548
2df8fb6
83210bf
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 |
|---|---|---|
|
|
@@ -10,7 +10,12 @@ import Data.Serialize (Serialize) | |
|
|
||
| type VarName = String | ||
| type AtomName = String | ||
| type DataTypeName = String | ||
| type TypeConstructorName = String | ||
| type TypeConstructor = (TypeConstructorName, [VarName]) | ||
|
||
| type DataTypeDef = (DataTypeName, [TypeConstructor]) | ||
| type FieldName = String | ||
| type ADTTag = Bool | ||
|
|
||
| -- | Eq and Neq: deep equality check on the two parameters, including the types (any type inequality results in false being returned). | ||
| data BinOp = Plus | Minus | Mult | Div | Mod | Eq | Neq | Le | Lt | Ge | Gt | And | Or | RaisedTo | FlowsTo | Concat| IntDiv | BinAnd | BinOr | BinXor | BinShiftLeft | BinShiftRight | BinZeroShiftRight | HasField | LatticeJoin | LatticeMeet | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -34,6 +34,7 @@ import ShowIndent | |
|
|
||
| import TroupePositionInfo | ||
| import DCLabels | ||
| import Data.List (find) | ||
|
|
||
| -------------------------------------------------- | ||
| -- AST is the same as Direct, but lambda are unary (or nullary) | ||
|
|
@@ -57,7 +58,7 @@ data Lit | |
| | LDCLabel DCLabelExp | ||
| | LUnit | ||
| | LBool Bool | ||
| | LAtom AtomName | ||
| | LAtom TypeConstructorName | ||
|
||
| deriving (Show, Generic) | ||
| instance Serialize Lit | ||
| instance Eq Lit where | ||
|
|
@@ -107,8 +108,8 @@ data Term | |
| | Let Decl Term | ||
| | If Term Term Term | ||
| | AssertElseError Term Term Term PosInf | ||
| | Tuple [Term] | ||
| | Record Fields | ||
| | Tuple [Term] ADTTag | ||
| | Record Fields | ||
| | WithRecord Term Fields | ||
| | ProjField Term FieldName | ||
| | ProjIdx Term Word | ||
|
|
@@ -157,8 +158,8 @@ lowerProg (D.Prog imports atms term) = Prog imports (trans atms) (lower term) | |
|
|
||
| -- the rest of the declarations in this part are not exported | ||
|
|
||
| trans :: D.Atoms -> Atoms | ||
| trans (D.Atoms atms) = Atoms atms | ||
| trans :: D.DataTypes -> Atoms | ||
| trans (D.DataTypes atms) = Atoms [] -- (concat $ map snd atms) | ||
|
|
||
| lowerLam (D.Lambda vs t) = | ||
| case vs of | ||
|
|
@@ -172,7 +173,7 @@ lowerLit (D.LLabel s) = LLabel s | |
| lowerLit (D.LDCLabel dc) = LDCLabel dc | ||
| lowerLit D.LUnit = LUnit | ||
| lowerLit (D.LBool b) = LBool b | ||
| lowerLit (D.LAtom n) = LAtom n | ||
| lowerLit (D.LDataType n) = LAtom n | ||
|
|
||
| lower :: D.Term -> Core.Term | ||
| lower (D.Lit l) = Lit (lowerLit l) | ||
|
|
@@ -198,7 +199,7 @@ lower (D.Let decls e) = | |
| -- lower (D.Case t patTermLst) = Case (lower t) (map (\(p,t) -> (lowerDeclPat p, lower t)) patTermLst) | ||
| lower (D.If e1 e2 e3) = If (lower e1) (lower e2) (lower e3) | ||
| lower (D.AssertElseError e1 e2 e3 p) = AssertElseError (lower e1 ) (lower e2) (lower e3) p | ||
| lower (D.Tuple terms) = Tuple (map lower terms) | ||
| lower (D.Tuple terms tag) = Tuple (map lower terms) tag | ||
| lower (D.Record fields) = Record (map (\(f, t) -> (f, lower t)) fields) | ||
| lower (D.WithRecord e fields) = WithRecord (lower e) (map (\(f, t) -> (f, lower t)) fields) | ||
| lower (D.ProjField t f) = ProjField (lower t) f | ||
|
|
@@ -330,8 +331,8 @@ rename (AssertElseError t1 t2 t3 p) m = do | |
| return $ AssertElseError t1' t2' t3' p | ||
|
|
||
|
|
||
| rename (Tuple terms) m = | ||
| Tuple <$> mapM (flip rename m) terms | ||
| rename (Tuple terms tag) m = | ||
| (\x -> Tuple x tag) <$> mapM (flip rename m) terms | ||
|
|
||
| rename (Record fields) m = | ||
| Record <$> mapM renameField fields | ||
|
|
@@ -438,10 +439,14 @@ ppTerm' (Lit literal) = ppLit literal | |
|
|
||
| ppTerm' (Error t _) = text "error " PP.<> ppTerm' t | ||
|
|
||
| ppTerm' (Tuple ts) = | ||
| ppTerm' (Tuple ts False) = | ||
| PP.parens $ | ||
| PP.hcat $ | ||
| PP.punctuate (text ",") (map (ppTerm 0) ts) | ||
| ppTerm' (Tuple ts True) = | ||
| case ts of [Lit (LString nm)] -> text nm | ||
| [Lit (LString nm), t] -> text nm PP.<> PP.space PP.<> ppTerm 0 t | ||
| otherwise -> text "error: MissingADT" | ||
|
|
||
| ppTerm' (List ts) = | ||
| PP.brackets $ | ||
|
|
@@ -561,7 +566,7 @@ ppLit (LDCLabel dc) = ppDCLabelExpLit dc | |
|
|
||
| termPrec :: Term -> Precedence | ||
| termPrec (Lit _) = maxPrec | ||
| termPrec (Tuple _) = maxPrec | ||
| termPrec (Tuple _ _) = maxPrec | ||
| termPrec (List _ ) = maxPrec | ||
| termPrec (Var _) = maxPrec | ||
| termPrec (App _ _) = appPrec | ||
|
|
||
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.
Suggestion for naming:
TypeConstructorName->VariantConstructorName