module Transformations.Simplifier.SimplifiedAst where

import Data.List.NonEmpty (NonEmpty)
import Trees.Common

data Program = Program [Declaration] IdCnt
  deriving (Int -> Program -> ShowS
[Program] -> ShowS
Program -> String
(Int -> Program -> ShowS)
-> (Program -> String) -> ([Program] -> ShowS) -> Show Program
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> Program -> ShowS
showsPrec :: Int -> Program -> ShowS
$cshow :: Program -> String
show :: Program -> String
$cshowList :: [Program] -> ShowS
showList :: [Program] -> ShowS
Show, Program -> Program -> Bool
(Program -> Program -> Bool)
-> (Program -> Program -> Bool) -> Eq Program
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: Program -> Program -> Bool
== :: Program -> Program -> Bool
$c/= :: Program -> Program -> Bool
/= :: Program -> Program -> Bool
Eq)

data Declaration
  = DeclVar Identifier' Expression
  | DeclFun Identifier' IsRec Fun
  deriving (Int -> Declaration -> ShowS
[Declaration] -> ShowS
Declaration -> String
(Int -> Declaration -> ShowS)
-> (Declaration -> String)
-> ([Declaration] -> ShowS)
-> Show Declaration
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> Declaration -> ShowS
showsPrec :: Int -> Declaration -> ShowS
$cshow :: Declaration -> String
show :: Declaration -> String
$cshowList :: [Declaration] -> ShowS
showList :: [Declaration] -> ShowS
Show, Declaration -> Declaration -> Bool
(Declaration -> Declaration -> Bool)
-> (Declaration -> Declaration -> Bool) -> Eq Declaration
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: Declaration -> Declaration -> Bool
== :: Declaration -> Declaration -> Bool
$c/= :: Declaration -> Declaration -> Bool
/= :: Declaration -> Declaration -> Bool
Eq)

declId :: Declaration -> Identifier'
declId :: Declaration -> Identifier'
declId (DeclVar Identifier'
ident Expression
_) = Identifier'
ident
declId (DeclFun Identifier'
ident Bool
_ Fun
_) = Identifier'
ident

data Expression
  = ExprId Identifier'
  | ExprPrimVal PrimitiveValue
  | ExprBinOp BinaryOperator Expression Expression
  | ExprUnOp UnaryOperator Expression
  | ExprApp Expression Expression
  | ExprIte Expression Expression Expression
  | ExprLetIn Declaration Expression
  | ExprFun Fun
  deriving (Int -> Expression -> ShowS
[Expression] -> ShowS
Expression -> String
(Int -> Expression -> ShowS)
-> (Expression -> String)
-> ([Expression] -> ShowS)
-> Show Expression
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> Expression -> ShowS
showsPrec :: Int -> Expression -> ShowS
$cshow :: Expression -> String
show :: Expression -> String
$cshowList :: [Expression] -> ShowS
showList :: [Expression] -> ShowS
Show, Expression -> Expression -> Bool
(Expression -> Expression -> Bool)
-> (Expression -> Expression -> Bool) -> Eq Expression
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: Expression -> Expression -> Bool
== :: Expression -> Expression -> Bool
$c/= :: Expression -> Expression -> Bool
/= :: Expression -> Expression -> Bool
Eq)

data Fun = Fun (NonEmpty Identifier') Expression
  deriving (Int -> Fun -> ShowS
[Fun] -> ShowS
Fun -> String
(Int -> Fun -> ShowS)
-> (Fun -> String) -> ([Fun] -> ShowS) -> Show Fun
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> Fun -> ShowS
showsPrec :: Int -> Fun -> ShowS
$cshow :: Fun -> String
show :: Fun -> String
$cshowList :: [Fun] -> ShowS
showList :: [Fun] -> ShowS
Show, Fun -> Fun -> Bool
(Fun -> Fun -> Bool) -> (Fun -> Fun -> Bool) -> Eq Fun
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: Fun -> Fun -> Bool
== :: Fun -> Fun -> Bool
$c/= :: Fun -> Fun -> Bool
/= :: Fun -> Fun -> Bool
Eq)