Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
0dea01a
Merge pull request #28 from felixwiemuth/dev-master-merged
aslanix Feb 19, 2024
c15e976
Atoms are now converted to tagged records in AtomFolding.hs
AStenbaek Aug 7, 2025
d2ea71f
added ADTTag to records in the compiler
AStenbaek Aug 8, 2025
722c85c
Records now have tags of whether or not they are ADTs
AStenbaek Aug 8, 2025
84aef99
updated IR2Raw test to have the ADTTag
AStenbaek Aug 8, 2025
b8b6623
Added support for ADT naming
AStenbaek Aug 8, 2025
36f8058
Added tests for named datatypes
AStenbaek Aug 8, 2025
4c51524
Added tests for custom named atomic datatypes
AStenbaek Aug 8, 2025
739ca5f
Added support for datatypes with constructors
AStenbaek Aug 12, 2025
eac4175
Added printing support for ADT representation
AStenbaek Aug 13, 2025
3946cc1
Made the printing code for ADTs a tiny bit more readable
AStenbaek Aug 13, 2025
d1a5c75
Matching added for type constructors
AStenbaek Aug 13, 2025
d454c79
ADT constructors have been added
AStenbaek Aug 13, 2025
c573aa3
fixed some printing for adt constructors
AStenbaek Aug 13, 2025
4b1f2e0
Added missing case for pretty-printing in Direct.hs
AStenbaek Aug 20, 2025
9a51a78
cc-based analysis
aslanix Sep 20, 2025
8945a4a
checkpoint
AStenbaek Sep 19, 2025
1ba80b8
Refactored implementation of ADTs to use tuples instead of records.
AStenbaek Sep 21, 2025
906dc93
Changed the name of ADTTag datatype to SynVariantTag in the compiler
AStenbaek Sep 28, 2025
901044d
updated runtime to use SynVariant naming instead of ADT.
AStenbaek Sep 28, 2025
cc89735
Renamed DataType to SyntacticVariant
AStenbaek Sep 28, 2025
94d3055
renaming from Atom SyntacticVariant
AStenbaek Oct 12, 2025
c753e9f
Removed the Atom leftovers from much of the compiler
AStenbaek Oct 12, 2025
e342e53
Further removing of atoms
AStenbaek Oct 12, 2025
62af7cb
Eliminated atoms from runtime
AStenbaek Oct 12, 2025
ca0a701
Merge branch 'TroupeLang:master' into ADT-frontend
AStenbaek Oct 12, 2025
50495d4
Merge branch 'dev-integrity' into ADT-frontend
AStenbaek Oct 12, 2025
62a6282
Added a negative test
AStenbaek Oct 13, 2025
3e3ca7c
added another negative test
AStenbaek Oct 13, 2025
edfc383
cleaned some code and fixed missing match case warnings
AStenbaek Oct 13, 2025
5b9c548
fixed some formatter silliness
AStenbaek Oct 13, 2025
2df8fb6
More cleaning of SynVarFolding.hs
AStenbaek Oct 13, 2025
83210bf
checkpoint
AStenbaek Oct 13, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions compiler/app/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

module Main (main) where

import qualified AtomFolding as AF
import qualified SynVarFolding as SF
import Parser
import qualified Core as Core
import RetDFCPS
Expand Down Expand Up @@ -107,7 +107,7 @@ process flags fname input = do
putStrLn (showIndent 2 prog)

--------------------------------------------------
prog' <- case runExcept (C.trans compileMode (AF.visitProg prog)) of
prog' <- case runExcept (C.trans compileMode (SF.visitProg prog)) of
Right p -> return p
Left s -> die s
when verbose $ do printSep "PATTERN MATCH ELIMINATION"
Expand Down
8 changes: 4 additions & 4 deletions compiler/src/AddAmbientMethods.hs
Original file line number Diff line number Diff line change
Expand Up @@ -21,27 +21,27 @@ printDecl :: FunDecl
printDecl = FunDecl "print"
[Lambda [VarPattern "x"] $
Let [ValDecl (VarPattern "out") (App (Var "getStdout") [Var "authority"]) NoPos]
(App (Var "fprintln") [Tuple [Var "out", Var "x"]])
(App (Var "fprintln") [Tuple [Var "out", Var "x"] False])
] NoPos

printWithLabelsDecl :: FunDecl
printWithLabelsDecl = FunDecl "printWithLabels"
[Lambda [VarPattern "x"] $
Let [ValDecl (VarPattern "out") (App (Var "getStdout") [Var "authority"]) NoPos]
(App (Var "fprintlnWithLabels") [Tuple [Var "out", Var "x"]])
(App (Var "fprintlnWithLabels") [Tuple [Var "out", Var "x"] False])
] NoPos


printStringDecl :: FunDecl
printStringDecl = FunDecl "printString"
[Lambda [VarPattern "x"] $
Let [ValDecl (VarPattern "out") (App (Var "getStdout") [Var "authority"]) NoPos]
(App (Var "fwrite") [Tuple [Var "out", Bin Concat (Var "x") (Lit (LString "\\n"))]])
(App (Var "fwrite") [Tuple [Var "out", Bin Concat (Var "x") (Lit (LString "\\n"))] False])
] NoPos



addAmbientMethods :: Prog -> Prog
addAmbientMethods (Prog imports atoms t) =
let t' = Let [FunDecs [printDecl,printWithLabelsDecl,printStringDecl]] t
in Prog imports atoms t'
in Prog imports atoms t'
83 changes: 0 additions & 83 deletions compiler/src/AtomFolding.hs

This file was deleted.

6 changes: 5 additions & 1 deletion compiler/src/Basics.hs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,12 @@ import GHC.Generics(Generic)
import Data.Serialize (Serialize)

type VarName = String
type AtomName = String
type SyntacticVariantName = String
type SyntacticVariantConstructorName = String
type SyntacticVariantConstructor = (SyntacticVariantConstructorName, [VarName])
type SyntacticVariantDef = (SyntacticVariantName, [SyntacticVariantConstructor])
type FieldName = String
type SynVariantTag = 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
Expand Down
28 changes: 14 additions & 14 deletions compiler/src/CPSOpt.hs
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ instance Substitutable SimpleTerm where
case simpleTerm of
Bin op v1 v2 -> Bin op (fwd v1) (fwd v2)
Un op v -> Un op (fwd v)
Tuple vs -> Tuple (map fwd vs)
Record fields -> Record $ fwdFields fields
Tuple vs tag -> Tuple (map fwd vs) tag
Record fields -> Record (fwdFields fields)
WithRecord x fields -> WithRecord (fwd x) $ fwdFields fields
ProjField x f -> ProjField (fwd x) f
ProjIdx x idx -> ProjIdx (fwd x) idx
Expand Down Expand Up @@ -145,7 +145,7 @@ instance CensusCollectible SimpleTerm where
Bin _ v1 v2 -> updateCensus [v1,v2]
Un _ v -> updateCensus v
ValSimpleTerm sv -> updateCensus sv
Tuple vs -> updateCensus vs
Tuple vs _ -> updateCensus vs
Record fs -> let (_,vs) = unzip fs in updateCensus vs
WithRecord v fs -> updateCensus v >> (let (_,vs) = unzip fs in updateCensus vs )
ProjField v _ -> updateCensus v
Expand Down Expand Up @@ -326,30 +326,30 @@ simplifySimpleTerm t =
v <- look operand
-- TODO should write out all cases
case (op,v) of
(Basics.IsTuple, St (Tuple _)) -> _ret __trueLit
(Basics.IsTuple, St (Record _)) -> _ret __falseLit
(Basics.IsTuple, St (Tuple _ _)) -> _ret __trueLit
(Basics.IsTuple, St (Record _)) -> _ret __falseLit
(Basics.IsTuple, St (WithRecord _ _)) -> _ret __falseLit
(Basics.IsTuple, St (List _)) -> _ret __falseLit
(Basics.IsTuple, St (ListCons _ _)) -> _ret __falseLit
(Basics.IsTuple, St (ValSimpleTerm _)) -> _ret __falseLit


(Basics.IsRecord, St (Record _)) -> _ret __trueLit
(Basics.IsRecord, St (Record _)) -> _ret __trueLit
(Basics.IsRecord, St (WithRecord _ _)) -> _ret __trueLit
(Basics.IsRecord, St (Tuple _)) -> _ret __falseLit
(Basics.IsRecord, St (Tuple _ _)) -> _ret __falseLit
(Basics.IsRecord, St (List _)) -> _ret __falseLit
(Basics.IsRecord, St (ListCons _ _)) -> _ret __falseLit
(Basics.IsRecord, St (ValSimpleTerm _)) -> _ret __falseLit


(Basics.IsList, St (List _)) -> _ret __trueLit
(Basics.IsList, St (ListCons _ _)) -> _ret __trueLit
(Basics.IsList, St (Record _)) -> _ret __falseLit
(Basics.IsList, St (Record _)) -> _ret __falseLit
(Basics.IsList, St (WithRecord _ _)) -> _ret __falseLit
(Basics.IsList, St (Tuple _)) -> _ret __falseLit
(Basics.IsList, St (Tuple _ _)) -> _ret __falseLit
(Basics.IsList, St (ValSimpleTerm _)) -> _ret __falseLit

(Basics.TupleLength, St (Tuple xs)) ->
(Basics.TupleLength, St (Tuple xs _)) ->
_ret $ lit (C.LInt (fromIntegral (length xs)) NoPos)
-- 2023-08 Revision: Added this case
(Basics.ListLength, St (List xs)) ->
Expand All @@ -366,7 +366,7 @@ simplifySimpleTerm t =
ProjIdx x idx -> do
t <- look x
case t of
St (Tuple vs) | fromIntegral (length vs) > idx ->
St (Tuple vs _) | fromIntegral (length vs) > idx ->
_subst (vs !! fromIntegral idx)
_ -> _nochange

Expand Down Expand Up @@ -409,7 +409,7 @@ failFree st = case st of
Bin op _ _ -> op `elem` [Basics.Eq, Basics.Neq] -- Equality comparisons are safe (return boolean)
Un _ _ -> False -- Unary operations can fail (e.g., head on empty list, arithmetic on non-numbers)
ValSimpleTerm _ -> True
Tuple _ -> True
Tuple _ _ -> True
Record _ -> True
WithRecord _ _ -> True
ProjField _ _ -> False -- Field projection can fail if field doesn't exist
Expand Down Expand Up @@ -545,5 +545,5 @@ iter kt =
iter kt'

rewrite :: Prog -> Prog
rewrite (Prog atoms kterm) =
Prog atoms (iter kterm)
rewrite (Prog kterm) =
Prog (iter kterm)
23 changes: 12 additions & 11 deletions compiler/src/CaseElimination.hs
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@ trans mode (S.Prog imports atms tm) = do
S.Let [ S.ValDecl (S.VarPattern "authority") (S.Var "$$authorityarg") _srcRT ]
tm
Export -> tm
atms' <- transAtoms atms
atms' <- transSynVars atms
tm'' <- transTerm tm'
return (T.Prog imports atms' tm'')

transAtoms :: S.Atoms -> Trans T.Atoms
transAtoms (S.Atoms atms) = return (T.Atoms atms)
transSynVars :: S.SyntacticVariants -> Trans T.SyntacticVariants
transSynVars (S.SyntacticVariants atms) = return (T.SyntacticVariants atms)

transLit :: S.Lit -> T.Lit
transLit (S.LInt n pi) = T.LInt n pi
Expand All @@ -41,7 +41,7 @@ transLit (S.LLabel s) = T.LLabel s
transLit (S.LDCLabel dc) = T.LDCLabel dc
transLit (S.LUnit) = T.LUnit
transLit (S.LBool b) = T.LBool b
transLit (S.LAtom a) = T.LAtom a
transLit (S.LSyntacticVariant a) = T.LSyntacticVariant a


transLambda_aux :: S.Lambda -> ReaderT T.Term Trans Lambda
Expand Down Expand Up @@ -95,8 +95,8 @@ transHandler (S.Handler pat1 mbpat2 guard body) = do
Just pat2 -> pat2
Nothing -> S.Wildcard
lambdaPats = [S.VarPattern argInput]
callFailure = S.Tuple [S.Lit (S.LInt 1 _srcRT), S.Lit S.LUnit ]
body' = S.Tuple[ S.Lit (S.LInt 0 _srcRT), S.Abs ( S.Lambda [S.Wildcard] body ) ]
callFailure = S.Tuple [S.Lit (S.LInt 1 _srcRT), S.Lit S.LUnit ] False
body' = S.Tuple[ S.Lit (S.LInt 0 _srcRT), S.Abs ( S.Lambda [S.Wildcard] body ) ] False
guardCheck = case guard of
Nothing -> body'
Just g -> S.If g body' callFailure
Expand Down Expand Up @@ -188,7 +188,8 @@ compilePattern succ (v, S.RecordPattern fieldPatterns mode) = do

compileField succ (f, Nothing) = do
ifHasField f $ compilePattern succ (T.ProjField v f, S.VarPattern f)

compilePattern _ (_, (S.SyntacticVariantPattern nm _)) =
lift $ throwError $ "Unexpected syntactic variant pattern: \"" ++ nm ++ "\""


-- | Tranform a declaration, compiling patterns into terms.
Expand All @@ -211,7 +212,7 @@ transDecl (S.FunDecs fundecs) succ = do
let lams' = map (transLambda_aux . (\(S.Lambda args e) -> S.Lambda [S.TuplePattern args] e)) lams
names = map (((f ++ "_pat") ++) . show) [1..(length lams)]
args = map (((f ++ "_arg") ++) . show) [1..(argLength lams)]
args' = Tuple (map Var args)
args' = Tuple (map Var args) False
errorMsg = Error (Lit (LString $ "pattern match failure in function " ++ f)) pos
(fst, decls) <- foldr (\(n, l) acc -> do
(fail, decls) <- acc
Expand Down Expand Up @@ -257,9 +258,9 @@ transTerm (S.If t1 t2 t3) = do
t2' <- transTerm t2
t3' <- transTerm t3
return (If t1' t2' t3')
transTerm (S.Tuple tms) = do
transTerm (S.Tuple tms tag) = do
tms' <- mapM transTerm tms
return (T.Tuple tms')
return (T.Tuple tms' tag)
transTerm (S.Record fields) = do
fields' <- transFields fields
return (T.Record fields')
Expand Down Expand Up @@ -302,4 +303,4 @@ transFields = mapM $ \case
(f, Nothing) -> return (f, T.Var f)
(f, Just t) -> do
t' <- transTerm t
return (f, t')
return (f, t')
Loading
Loading