-- | Main types
{-# OPTIONS_GHC -Wno-orphans #-}
{-# Language
        DeriveFunctor, DeriveFoldable, DeriveTraversable,
        DeriveGeneric,
        StandaloneDeriving,
        TypeSynonymInstances, FlexibleInstances,
        TemplateHaskell,
        CPP #-}
module Csound.Dynamic.Types.Exp(
    E, RatedExp(..), isEmptyExp, RatedVar, ratedVar, ratedVarRate, ratedVarId,
    ratedExp, noRate, withRate, setRate,
    Exp, toPrimOr, toPrimOrTfm, PrimOr(..), MainExp(..), Name,
    InstrId(..), intInstrId, ratioInstrId, stringInstrId,
    VarType(..), Var(..), Info(..), OpcFixity(..), Rate(..),
    Signature(..), isInfix, isPrefix,
    Prim(..), Gen(..), GenId(..),
    Inline(..), InlineExp(..), PreInline(..),
    BoolExp, CondInfo, CondOp(..), isTrue, isFalse,
    NumExp, NumOp(..), Note,
    MultiOut,
    IsArrInit, ArrSize, ArrIndex
) where

#if __GLASGOW_HASKELL__ < 710
import Control.Applicative
#endif

import GHC.Generics (Generic, Generic1)
import Data.Traversable
import Data.Foldable hiding (concat)

import Data.Hashable

import Data.Map(Map)
import Data.Maybe(isNothing)
import qualified Data.IntMap as IM
import qualified Data.IntMap.Internal as IM
import Data.Fix
import Data.Eq.Deriving
import Data.Ord.Deriving
import Text.Show.Deriving
import Data.Hashable.Lifted

import qualified Csound.Dynamic.Tfm.DeduceTypes as R(Var(..))

type Name = String
type LineNum = Int

-- | An instrument identifier
data InstrId
    = InstrId
    { InstrId -> Maybe Int
instrIdFrac :: Maybe Int
    , InstrId -> Int
instrIdCeil :: Int }
    | InstrLabel String
    deriving (Int -> InstrId -> ShowS
[InstrId] -> ShowS
InstrId -> String
(Int -> InstrId -> ShowS)
-> (InstrId -> String) -> ([InstrId] -> ShowS) -> Show InstrId
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [InstrId] -> ShowS
$cshowList :: [InstrId] -> ShowS
show :: InstrId -> String
$cshow :: InstrId -> String
showsPrec :: Int -> InstrId -> ShowS
$cshowsPrec :: Int -> InstrId -> ShowS
Show, InstrId -> InstrId -> Bool
(InstrId -> InstrId -> Bool)
-> (InstrId -> InstrId -> Bool) -> Eq InstrId
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: InstrId -> InstrId -> Bool
$c/= :: InstrId -> InstrId -> Bool
== :: InstrId -> InstrId -> Bool
$c== :: InstrId -> InstrId -> Bool
Eq, Eq InstrId
Eq InstrId
-> (InstrId -> InstrId -> Ordering)
-> (InstrId -> InstrId -> Bool)
-> (InstrId -> InstrId -> Bool)
-> (InstrId -> InstrId -> Bool)
-> (InstrId -> InstrId -> Bool)
-> (InstrId -> InstrId -> InstrId)
-> (InstrId -> InstrId -> InstrId)
-> Ord InstrId
InstrId -> InstrId -> Bool
InstrId -> InstrId -> Ordering
InstrId -> InstrId -> InstrId
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
min :: InstrId -> InstrId -> InstrId
$cmin :: InstrId -> InstrId -> InstrId
max :: InstrId -> InstrId -> InstrId
$cmax :: InstrId -> InstrId -> InstrId
>= :: InstrId -> InstrId -> Bool
$c>= :: InstrId -> InstrId -> Bool
> :: InstrId -> InstrId -> Bool
$c> :: InstrId -> InstrId -> Bool
<= :: InstrId -> InstrId -> Bool
$c<= :: InstrId -> InstrId -> Bool
< :: InstrId -> InstrId -> Bool
$c< :: InstrId -> InstrId -> Bool
compare :: InstrId -> InstrId -> Ordering
$ccompare :: InstrId -> InstrId -> Ordering
$cp1Ord :: Eq InstrId
Ord, (forall x. InstrId -> Rep InstrId x)
-> (forall x. Rep InstrId x -> InstrId) -> Generic InstrId
forall x. Rep InstrId x -> InstrId
forall x. InstrId -> Rep InstrId x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep InstrId x -> InstrId
$cfrom :: forall x. InstrId -> Rep InstrId x
Generic)

-- | Constructs an instrument id with the integer.
intInstrId :: Int -> InstrId
intInstrId :: Int -> InstrId
intInstrId Int
n = Maybe Int -> Int -> InstrId
InstrId Maybe Int
forall a. Maybe a
Nothing Int
n

-- | Constructs an instrument id with fractional part.
ratioInstrId :: Int -> Int -> InstrId
ratioInstrId :: Int -> Int -> InstrId
ratioInstrId Int
beforeDot Int
afterDot = Maybe Int -> Int -> InstrId
InstrId (Int -> Maybe Int
forall a. a -> Maybe a
Just (Int -> Maybe Int) -> Int -> Maybe Int
forall a b. (a -> b) -> a -> b
$ Int
afterDot) Int
beforeDot

-- | Constructs an instrument id with the string label.
stringInstrId :: String -> InstrId
stringInstrId :: String -> InstrId
stringInstrId = String -> InstrId
InstrLabel

-- | The inner representation of csound expressions.
type E = Fix RatedExp

data RatedExp a = RatedExp
    { RatedExp a -> Maybe Rate
ratedExpRate      :: Maybe Rate
        -- ^ Rate (can be undefined or Nothing,
        -- it means that rate should be deduced automatically from the context)
    , RatedExp a -> Maybe Int
ratedExpDepends   :: Maybe LineNum
        -- ^ Dependency (it is used for expressions with side effects,
        -- value contains the privious statement)
    , RatedExp a -> Exp a
ratedExpExp       :: Exp a
        -- ^ Main expression
    } deriving (Int -> RatedExp a -> ShowS
[RatedExp a] -> ShowS
RatedExp a -> String
(Int -> RatedExp a -> ShowS)
-> (RatedExp a -> String)
-> ([RatedExp a] -> ShowS)
-> Show (RatedExp a)
forall a. Show a => Int -> RatedExp a -> ShowS
forall a. Show a => [RatedExp a] -> ShowS
forall a. Show a => RatedExp a -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [RatedExp a] -> ShowS
$cshowList :: forall a. Show a => [RatedExp a] -> ShowS
show :: RatedExp a -> String
$cshow :: forall a. Show a => RatedExp a -> String
showsPrec :: Int -> RatedExp a -> ShowS
$cshowsPrec :: forall a. Show a => Int -> RatedExp a -> ShowS
Show, RatedExp a -> RatedExp a -> Bool
(RatedExp a -> RatedExp a -> Bool)
-> (RatedExp a -> RatedExp a -> Bool) -> Eq (RatedExp a)
forall a. Eq a => RatedExp a -> RatedExp a -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: RatedExp a -> RatedExp a -> Bool
$c/= :: forall a. Eq a => RatedExp a -> RatedExp a -> Bool
== :: RatedExp a -> RatedExp a -> Bool
$c== :: forall a. Eq a => RatedExp a -> RatedExp a -> Bool
Eq, Eq (RatedExp a)
Eq (RatedExp a)
-> (RatedExp a -> RatedExp a -> Ordering)
-> (RatedExp a -> RatedExp a -> Bool)
-> (RatedExp a -> RatedExp a -> Bool)
-> (RatedExp a -> RatedExp a -> Bool)
-> (RatedExp a -> RatedExp a -> Bool)
-> (RatedExp a -> RatedExp a -> RatedExp a)
-> (RatedExp a -> RatedExp a -> RatedExp a)
-> Ord (RatedExp a)
RatedExp a -> RatedExp a -> Bool
RatedExp a -> RatedExp a -> Ordering
RatedExp a -> RatedExp a -> RatedExp a
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
forall a. Ord a => Eq (RatedExp a)
forall a. Ord a => RatedExp a -> RatedExp a -> Bool
forall a. Ord a => RatedExp a -> RatedExp a -> Ordering
forall a. Ord a => RatedExp a -> RatedExp a -> RatedExp a
min :: RatedExp a -> RatedExp a -> RatedExp a
$cmin :: forall a. Ord a => RatedExp a -> RatedExp a -> RatedExp a
max :: RatedExp a -> RatedExp a -> RatedExp a
$cmax :: forall a. Ord a => RatedExp a -> RatedExp a -> RatedExp a
>= :: RatedExp a -> RatedExp a -> Bool
$c>= :: forall a. Ord a => RatedExp a -> RatedExp a -> Bool
> :: RatedExp a -> RatedExp a -> Bool
$c> :: forall a. Ord a => RatedExp a -> RatedExp a -> Bool
<= :: RatedExp a -> RatedExp a -> Bool
$c<= :: forall a. Ord a => RatedExp a -> RatedExp a -> Bool
< :: RatedExp a -> RatedExp a -> Bool
$c< :: forall a. Ord a => RatedExp a -> RatedExp a -> Bool
compare :: RatedExp a -> RatedExp a -> Ordering
$ccompare :: forall a. Ord a => RatedExp a -> RatedExp a -> Ordering
$cp1Ord :: forall a. Ord a => Eq (RatedExp a)
Ord, a -> RatedExp b -> RatedExp a
(a -> b) -> RatedExp a -> RatedExp b
(forall a b. (a -> b) -> RatedExp a -> RatedExp b)
-> (forall a b. a -> RatedExp b -> RatedExp a) -> Functor RatedExp
forall a b. a -> RatedExp b -> RatedExp a
forall a b. (a -> b) -> RatedExp a -> RatedExp b
forall (f :: * -> *).
(forall a b. (a -> b) -> f a -> f b)
-> (forall a b. a -> f b -> f a) -> Functor f
<$ :: a -> RatedExp b -> RatedExp a
$c<$ :: forall a b. a -> RatedExp b -> RatedExp a
fmap :: (a -> b) -> RatedExp a -> RatedExp b
$cfmap :: forall a b. (a -> b) -> RatedExp a -> RatedExp b
Functor, RatedExp a -> Bool
(a -> m) -> RatedExp a -> m
(a -> b -> b) -> b -> RatedExp a -> b
(forall m. Monoid m => RatedExp m -> m)
-> (forall m a. Monoid m => (a -> m) -> RatedExp a -> m)
-> (forall m a. Monoid m => (a -> m) -> RatedExp a -> m)
-> (forall a b. (a -> b -> b) -> b -> RatedExp a -> b)
-> (forall a b. (a -> b -> b) -> b -> RatedExp a -> b)
-> (forall b a. (b -> a -> b) -> b -> RatedExp a -> b)
-> (forall b a. (b -> a -> b) -> b -> RatedExp a -> b)
-> (forall a. (a -> a -> a) -> RatedExp a -> a)
-> (forall a. (a -> a -> a) -> RatedExp a -> a)
-> (forall a. RatedExp a -> [a])
-> (forall a. RatedExp a -> Bool)
-> (forall a. RatedExp a -> Int)
-> (forall a. Eq a => a -> RatedExp a -> Bool)
-> (forall a. Ord a => RatedExp a -> a)
-> (forall a. Ord a => RatedExp a -> a)
-> (forall a. Num a => RatedExp a -> a)
-> (forall a. Num a => RatedExp a -> a)
-> Foldable RatedExp
forall a. Eq a => a -> RatedExp a -> Bool
forall a. Num a => RatedExp a -> a
forall a. Ord a => RatedExp a -> a
forall m. Monoid m => RatedExp m -> m
forall a. RatedExp a -> Bool
forall a. RatedExp a -> Int
forall a. RatedExp a -> [a]
forall a. (a -> a -> a) -> RatedExp a -> a
forall m a. Monoid m => (a -> m) -> RatedExp a -> m
forall b a. (b -> a -> b) -> b -> RatedExp a -> b
forall a b. (a -> b -> b) -> b -> RatedExp a -> b
forall (t :: * -> *).
(forall m. Monoid m => t m -> m)
-> (forall m a. Monoid m => (a -> m) -> t a -> m)
-> (forall m a. Monoid m => (a -> m) -> t a -> m)
-> (forall a b. (a -> b -> b) -> b -> t a -> b)
-> (forall a b. (a -> b -> b) -> b -> t a -> b)
-> (forall b a. (b -> a -> b) -> b -> t a -> b)
-> (forall b a. (b -> a -> b) -> b -> t a -> b)
-> (forall a. (a -> a -> a) -> t a -> a)
-> (forall a. (a -> a -> a) -> t a -> a)
-> (forall a. t a -> [a])
-> (forall a. t a -> Bool)
-> (forall a. t a -> Int)
-> (forall a. Eq a => a -> t a -> Bool)
-> (forall a. Ord a => t a -> a)
-> (forall a. Ord a => t a -> a)
-> (forall a. Num a => t a -> a)
-> (forall a. Num a => t a -> a)
-> Foldable t
product :: RatedExp a -> a
$cproduct :: forall a. Num a => RatedExp a -> a
sum :: RatedExp a -> a
$csum :: forall a. Num a => RatedExp a -> a
minimum :: RatedExp a -> a
$cminimum :: forall a. Ord a => RatedExp a -> a
maximum :: RatedExp a -> a
$cmaximum :: forall a. Ord a => RatedExp a -> a
elem :: a -> RatedExp a -> Bool
$celem :: forall a. Eq a => a -> RatedExp a -> Bool
length :: RatedExp a -> Int
$clength :: forall a. RatedExp a -> Int
null :: RatedExp a -> Bool
$cnull :: forall a. RatedExp a -> Bool
toList :: RatedExp a -> [a]
$ctoList :: forall a. RatedExp a -> [a]
foldl1 :: (a -> a -> a) -> RatedExp a -> a
$cfoldl1 :: forall a. (a -> a -> a) -> RatedExp a -> a
foldr1 :: (a -> a -> a) -> RatedExp a -> a
$cfoldr1 :: forall a. (a -> a -> a) -> RatedExp a -> a
foldl' :: (b -> a -> b) -> b -> RatedExp a -> b
$cfoldl' :: forall b a. (b -> a -> b) -> b -> RatedExp a -> b
foldl :: (b -> a -> b) -> b -> RatedExp a -> b
$cfoldl :: forall b a. (b -> a -> b) -> b -> RatedExp a -> b
foldr' :: (a -> b -> b) -> b -> RatedExp a -> b
$cfoldr' :: forall a b. (a -> b -> b) -> b -> RatedExp a -> b
foldr :: (a -> b -> b) -> b -> RatedExp a -> b
$cfoldr :: forall a b. (a -> b -> b) -> b -> RatedExp a -> b
foldMap' :: (a -> m) -> RatedExp a -> m
$cfoldMap' :: forall m a. Monoid m => (a -> m) -> RatedExp a -> m
foldMap :: (a -> m) -> RatedExp a -> m
$cfoldMap :: forall m a. Monoid m => (a -> m) -> RatedExp a -> m
fold :: RatedExp m -> m
$cfold :: forall m. Monoid m => RatedExp m -> m
Foldable, Functor RatedExp
Foldable RatedExp
Functor RatedExp
-> Foldable RatedExp
-> (forall (f :: * -> *) a b.
    Applicative f =>
    (a -> f b) -> RatedExp a -> f (RatedExp b))
-> (forall (f :: * -> *) a.
    Applicative f =>
    RatedExp (f a) -> f (RatedExp a))
-> (forall (m :: * -> *) a b.
    Monad m =>
    (a -> m b) -> RatedExp a -> m (RatedExp b))
-> (forall (m :: * -> *) a.
    Monad m =>
    RatedExp (m a) -> m (RatedExp a))
-> Traversable RatedExp
(a -> f b) -> RatedExp a -> f (RatedExp b)
forall (t :: * -> *).
Functor t
-> Foldable t
-> (forall (f :: * -> *) a b.
    Applicative f =>
    (a -> f b) -> t a -> f (t b))
-> (forall (f :: * -> *) a. Applicative f => t (f a) -> f (t a))
-> (forall (m :: * -> *) a b.
    Monad m =>
    (a -> m b) -> t a -> m (t b))
-> (forall (m :: * -> *) a. Monad m => t (m a) -> m (t a))
-> Traversable t
forall (m :: * -> *) a. Monad m => RatedExp (m a) -> m (RatedExp a)
forall (f :: * -> *) a.
Applicative f =>
RatedExp (f a) -> f (RatedExp a)
forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> RatedExp a -> m (RatedExp b)
forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> RatedExp a -> f (RatedExp b)
sequence :: RatedExp (m a) -> m (RatedExp a)
$csequence :: forall (m :: * -> *) a. Monad m => RatedExp (m a) -> m (RatedExp a)
mapM :: (a -> m b) -> RatedExp a -> m (RatedExp b)
$cmapM :: forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> RatedExp a -> m (RatedExp b)
sequenceA :: RatedExp (f a) -> f (RatedExp a)
$csequenceA :: forall (f :: * -> *) a.
Applicative f =>
RatedExp (f a) -> f (RatedExp a)
traverse :: (a -> f b) -> RatedExp a -> f (RatedExp b)
$ctraverse :: forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> RatedExp a -> f (RatedExp b)
$cp2Traversable :: Foldable RatedExp
$cp1Traversable :: Functor RatedExp
Traversable, (forall x. RatedExp a -> Rep (RatedExp a) x)
-> (forall x. Rep (RatedExp a) x -> RatedExp a)
-> Generic (RatedExp a)
forall x. Rep (RatedExp a) x -> RatedExp a
forall x. RatedExp a -> Rep (RatedExp a) x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
forall a x. Rep (RatedExp a) x -> RatedExp a
forall a x. RatedExp a -> Rep (RatedExp a) x
$cto :: forall a x. Rep (RatedExp a) x -> RatedExp a
$cfrom :: forall a x. RatedExp a -> Rep (RatedExp a) x
Generic, (forall a. RatedExp a -> Rep1 RatedExp a)
-> (forall a. Rep1 RatedExp a -> RatedExp a) -> Generic1 RatedExp
forall a. Rep1 RatedExp a -> RatedExp a
forall a. RatedExp a -> Rep1 RatedExp a
forall k (f :: k -> *).
(forall (a :: k). f a -> Rep1 f a)
-> (forall (a :: k). Rep1 f a -> f a) -> Generic1 f
$cto1 :: forall a. Rep1 RatedExp a -> RatedExp a
$cfrom1 :: forall a. RatedExp a -> Rep1 RatedExp a
Generic1)

-- | RatedVar is for pretty printing of the wiring ports.
type RatedVar = R.Var Rate

-- | Makes an rated variable.
ratedVar :: Rate -> Int -> RatedVar
ratedVar :: Rate -> Int -> RatedVar
ratedVar     = (Int -> Rate -> RatedVar) -> Rate -> Int -> RatedVar
forall a b c. (a -> b -> c) -> b -> a -> c
flip Int -> Rate -> RatedVar
forall a. Int -> a -> Var a
R.Var

-- | Querries a rate.
ratedVarRate :: RatedVar -> Rate
ratedVarRate :: RatedVar -> Rate
ratedVarRate = RatedVar -> Rate
forall a. Var a -> a
R.varType

-- | Querries an integral identifier.
ratedVarId :: RatedVar -> Int
ratedVarId :: RatedVar -> Int
ratedVarId   = RatedVar -> Int
forall a. Var a -> Int
R.varId

ratedExp :: Maybe Rate -> Exp E -> E
ratedExp :: Maybe Rate -> Exp E -> E
ratedExp Maybe Rate
r = RatedExp E -> E
forall (f :: * -> *). f (Fix f) -> Fix f
Fix (RatedExp E -> E) -> (Exp E -> RatedExp E) -> Exp E -> E
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Maybe Rate -> Maybe Int -> Exp E -> RatedExp E
forall a. Maybe Rate -> Maybe Int -> Exp a -> RatedExp a
RatedExp Maybe Rate
r Maybe Int
forall a. Maybe a
Nothing

noRate :: Exp E -> E
noRate :: Exp E -> E
noRate = Maybe Rate -> Exp E -> E
ratedExp Maybe Rate
forall a. Maybe a
Nothing

withRate :: Rate -> Exp E -> E
withRate :: Rate -> Exp E -> E
withRate Rate
r = Maybe Rate -> Exp E -> E
ratedExp (Rate -> Maybe Rate
forall a. a -> Maybe a
Just Rate
r)

-- rate coversion

setRate :: Rate -> E -> E
setRate :: Rate -> E -> E
setRate Rate
r E
a = RatedExp E -> E
forall (f :: * -> *). f (Fix f) -> Fix f
Fix (RatedExp E -> E) -> RatedExp E -> E
forall a b. (a -> b) -> a -> b
$ (\RatedExp E
x -> RatedExp E
x { ratedExpRate :: Maybe Rate
ratedExpRate = Rate -> Maybe Rate
forall a. a -> Maybe a
Just Rate
r }) (RatedExp E -> RatedExp E) -> RatedExp E -> RatedExp E
forall a b. (a -> b) -> a -> b
$ E -> RatedExp E
forall (f :: * -> *). Fix f -> f (Fix f)
unFix E
a

-- | It's a primitive value or something else. It's used for inlining
-- of the constants (primitive values).
newtype PrimOr a = PrimOr { PrimOr a -> Either Prim a
unPrimOr :: Either Prim a }
    deriving (Int -> PrimOr a -> ShowS
[PrimOr a] -> ShowS
PrimOr a -> String
(Int -> PrimOr a -> ShowS)
-> (PrimOr a -> String) -> ([PrimOr a] -> ShowS) -> Show (PrimOr a)
forall a. Show a => Int -> PrimOr a -> ShowS
forall a. Show a => [PrimOr a] -> ShowS
forall a. Show a => PrimOr a -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [PrimOr a] -> ShowS
$cshowList :: forall a. Show a => [PrimOr a] -> ShowS
show :: PrimOr a -> String
$cshow :: forall a. Show a => PrimOr a -> String
showsPrec :: Int -> PrimOr a -> ShowS
$cshowsPrec :: forall a. Show a => Int -> PrimOr a -> ShowS
Show, PrimOr a -> PrimOr a -> Bool
(PrimOr a -> PrimOr a -> Bool)
-> (PrimOr a -> PrimOr a -> Bool) -> Eq (PrimOr a)
forall a. Eq a => PrimOr a -> PrimOr a -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: PrimOr a -> PrimOr a -> Bool
$c/= :: forall a. Eq a => PrimOr a -> PrimOr a -> Bool
== :: PrimOr a -> PrimOr a -> Bool
$c== :: forall a. Eq a => PrimOr a -> PrimOr a -> Bool
Eq, Eq (PrimOr a)
Eq (PrimOr a)
-> (PrimOr a -> PrimOr a -> Ordering)
-> (PrimOr a -> PrimOr a -> Bool)
-> (PrimOr a -> PrimOr a -> Bool)
-> (PrimOr a -> PrimOr a -> Bool)
-> (PrimOr a -> PrimOr a -> Bool)
-> (PrimOr a -> PrimOr a -> PrimOr a)
-> (PrimOr a -> PrimOr a -> PrimOr a)
-> Ord (PrimOr a)
PrimOr a -> PrimOr a -> Bool
PrimOr a -> PrimOr a -> Ordering
PrimOr a -> PrimOr a -> PrimOr a
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
forall a. Ord a => Eq (PrimOr a)
forall a. Ord a => PrimOr a -> PrimOr a -> Bool
forall a. Ord a => PrimOr a -> PrimOr a -> Ordering
forall a. Ord a => PrimOr a -> PrimOr a -> PrimOr a
min :: PrimOr a -> PrimOr a -> PrimOr a
$cmin :: forall a. Ord a => PrimOr a -> PrimOr a -> PrimOr a
max :: PrimOr a -> PrimOr a -> PrimOr a
$cmax :: forall a. Ord a => PrimOr a -> PrimOr a -> PrimOr a
>= :: PrimOr a -> PrimOr a -> Bool
$c>= :: forall a. Ord a => PrimOr a -> PrimOr a -> Bool
> :: PrimOr a -> PrimOr a -> Bool
$c> :: forall a. Ord a => PrimOr a -> PrimOr a -> Bool
<= :: PrimOr a -> PrimOr a -> Bool
$c<= :: forall a. Ord a => PrimOr a -> PrimOr a -> Bool
< :: PrimOr a -> PrimOr a -> Bool
$c< :: forall a. Ord a => PrimOr a -> PrimOr a -> Bool
compare :: PrimOr a -> PrimOr a -> Ordering
$ccompare :: forall a. Ord a => PrimOr a -> PrimOr a -> Ordering
$cp1Ord :: forall a. Ord a => Eq (PrimOr a)
Ord, a -> PrimOr b -> PrimOr a
(a -> b) -> PrimOr a -> PrimOr b
(forall a b. (a -> b) -> PrimOr a -> PrimOr b)
-> (forall a b. a -> PrimOr b -> PrimOr a) -> Functor PrimOr
forall a b. a -> PrimOr b -> PrimOr a
forall a b. (a -> b) -> PrimOr a -> PrimOr b
forall (f :: * -> *).
(forall a b. (a -> b) -> f a -> f b)
-> (forall a b. a -> f b -> f a) -> Functor f
<$ :: a -> PrimOr b -> PrimOr a
$c<$ :: forall a b. a -> PrimOr b -> PrimOr a
fmap :: (a -> b) -> PrimOr a -> PrimOr b
$cfmap :: forall a b. (a -> b) -> PrimOr a -> PrimOr b
Functor, (forall x. PrimOr a -> Rep (PrimOr a) x)
-> (forall x. Rep (PrimOr a) x -> PrimOr a) -> Generic (PrimOr a)
forall x. Rep (PrimOr a) x -> PrimOr a
forall x. PrimOr a -> Rep (PrimOr a) x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
forall a x. Rep (PrimOr a) x -> PrimOr a
forall a x. PrimOr a -> Rep (PrimOr a) x
$cto :: forall a x. Rep (PrimOr a) x -> PrimOr a
$cfrom :: forall a x. PrimOr a -> Rep (PrimOr a) x
Generic, (forall a. PrimOr a -> Rep1 PrimOr a)
-> (forall a. Rep1 PrimOr a -> PrimOr a) -> Generic1 PrimOr
forall a. Rep1 PrimOr a -> PrimOr a
forall a. PrimOr a -> Rep1 PrimOr a
forall k (f :: k -> *).
(forall (a :: k). f a -> Rep1 f a)
-> (forall (a :: k). Rep1 f a -> f a) -> Generic1 f
$cto1 :: forall a. Rep1 PrimOr a -> PrimOr a
$cfrom1 :: forall a. PrimOr a -> Rep1 PrimOr a
Generic1)

-- | Constructs PrimOr values from the expressions. It does inlining in
-- case of primitive values.
toPrimOr :: E -> PrimOr E
toPrimOr :: E -> PrimOr E
toPrimOr E
a = Either Prim E -> PrimOr E
forall a. Either Prim a -> PrimOr a
PrimOr (Either Prim E -> PrimOr E) -> Either Prim E -> PrimOr E
forall a b. (a -> b) -> a -> b
$ case RatedExp E -> Exp E
forall a. RatedExp a -> Exp a
ratedExpExp (RatedExp E -> Exp E) -> RatedExp E -> Exp E
forall a b. (a -> b) -> a -> b
$ E -> RatedExp E
forall (f :: * -> *). Fix f -> f (Fix f)
unFix E
a of
    ExpPrim (PString Int
_) -> E -> Either Prim E
forall a b. b -> Either a b
Right E
a
    ExpPrim Prim
p  -> Prim -> Either Prim E
forall a b. a -> Either a b
Left Prim
p
    ReadVar Var
v | Bool
noDeps -> Prim -> Either Prim E
forall a b. a -> Either a b
Left (Rate -> Var -> Prim
PrimVar (Var -> Rate
varRate Var
v) Var
v)
    Exp E
_         -> E -> Either Prim E
forall a b. b -> Either a b
Right E
a
    where
        noDeps :: Bool
noDeps = Maybe Int -> Bool
forall a. Maybe a -> Bool
isNothing (Maybe Int -> Bool) -> Maybe Int -> Bool
forall a b. (a -> b) -> a -> b
$ RatedExp E -> Maybe Int
forall a. RatedExp a -> Maybe Int
ratedExpDepends (RatedExp E -> Maybe Int) -> RatedExp E -> Maybe Int
forall a b. (a -> b) -> a -> b
$ E -> RatedExp E
forall (f :: * -> *). Fix f -> f (Fix f)
unFix E
a

-- | Constructs PrimOr values from the expressions. It does inlining in
-- case of primitive values.
toPrimOrTfm :: Rate -> E -> PrimOr E
toPrimOrTfm :: Rate -> E -> PrimOr E
toPrimOrTfm Rate
r E
a = Either Prim E -> PrimOr E
forall a. Either Prim a -> PrimOr a
PrimOr (Either Prim E -> PrimOr E) -> Either Prim E -> PrimOr E
forall a b. (a -> b) -> a -> b
$ case RatedExp E -> Exp E
forall a. RatedExp a -> Exp a
ratedExpExp (RatedExp E -> Exp E) -> RatedExp E -> Exp E
forall a b. (a -> b) -> a -> b
$ E -> RatedExp E
forall (f :: * -> *). Fix f -> f (Fix f)
unFix E
a of
    ExpPrim (PString Int
_) -> E -> Either Prim E
forall a b. b -> Either a b
Right E
a
    ExpPrim Prim
p | (Rate
r Rate -> Rate -> Bool
forall a. Eq a => a -> a -> Bool
== Rate
Ir Bool -> Bool -> Bool
|| Rate
r Rate -> Rate -> Bool
forall a. Eq a => a -> a -> Bool
== Rate
Sr) -> Prim -> Either Prim E
forall a b. a -> Either a b
Left Prim
p
    ReadVar Var
v | Bool
noDeps -> Prim -> Either Prim E
forall a b. a -> Either a b
Left (Rate -> Var -> Prim
PrimVar (Var -> Rate
varRate Var
v) Var
v)
    Exp E
_         -> E -> Either Prim E
forall a b. b -> Either a b
Right E
a
    where
        noDeps :: Bool
noDeps = Maybe Int -> Bool
forall a. Maybe a -> Bool
isNothing (Maybe Int -> Bool) -> Maybe Int -> Bool
forall a b. (a -> b) -> a -> b
$ RatedExp E -> Maybe Int
forall a. RatedExp a -> Maybe Int
ratedExpDepends (RatedExp E -> Maybe Int) -> RatedExp E -> Maybe Int
forall a b. (a -> b) -> a -> b
$ E -> RatedExp E
forall (f :: * -> *). Fix f -> f (Fix f)
unFix E
a


-- Expressions with inlining.
type Exp a = MainExp (PrimOr a)

-- Csound expressions
data MainExp a
    = EmptyExp
    -- | Primitives
    | ExpPrim Prim
    -- | Application of the opcode: we have opcode information (Info) and the arguments [a]
    | Tfm Info [a]
    -- | Rate conversion
    | ConvertRate Rate Rate a
    -- | Selects a cell from the tuple, here argument is always a tuple (result of opcode that returns several outputs)
    | Select Rate Int a
    -- | if-then-else
    | If (CondInfo a) a a
    -- | Boolean expressions (rendered in infix notation in the Csound)
    | ExpBool (BoolExp a)
    -- | Numerical expressions (rendered in infix notation in the Csound)
    | ExpNum (NumExp a)
    -- | Reading/writing a named variable
    | InitVar Var a
    | ReadVar Var
    | WriteVar Var a
    -- | Arrays
    | InitArr Var (ArrSize a)
    | ReadArr Var (ArrIndex a)
    | WriteArr Var (ArrIndex a) a
    | WriteInitArr Var (ArrIndex a) a
    | TfmArr IsArrInit Var Info [a]
    -- | Imperative If-then-else
    | IfBegin Rate (CondInfo a)
--  | ElseIfBegin (CondInfo a) -- It's expressed with nested if-else
    | ElseBegin
    | IfEnd
    -- | looping constructions
    | UntilBegin (CondInfo a)
    | UntilEnd
    | WhileBegin (CondInfo a)
    | WhileRefBegin Var
    | WhileEnd
    -- | Verbatim stmt
    | Verbatim String
    -- | Dependency tracking
    | Starts
    | Seq a a
    | Ends a
    -- | read macros arguments
    | InitMacrosInt String Int
    | InitMacrosDouble String Double
    | InitMacrosString String String
    | ReadMacrosInt String
    | ReadMacrosDouble String
    | ReadMacrosString String
    deriving (Int -> MainExp a -> ShowS
[MainExp a] -> ShowS
MainExp a -> String
(Int -> MainExp a -> ShowS)
-> (MainExp a -> String)
-> ([MainExp a] -> ShowS)
-> Show (MainExp a)
forall a. Show a => Int -> MainExp a -> ShowS
forall a. Show a => [MainExp a] -> ShowS
forall a. Show a => MainExp a -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [MainExp a] -> ShowS
$cshowList :: forall a. Show a => [MainExp a] -> ShowS
show :: MainExp a -> String
$cshow :: forall a. Show a => MainExp a -> String
showsPrec :: Int -> MainExp a -> ShowS
$cshowsPrec :: forall a. Show a => Int -> MainExp a -> ShowS
Show, MainExp a -> MainExp a -> Bool
(MainExp a -> MainExp a -> Bool)
-> (MainExp a -> MainExp a -> Bool) -> Eq (MainExp a)
forall a. Eq a => MainExp a -> MainExp a -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: MainExp a -> MainExp a -> Bool
$c/= :: forall a. Eq a => MainExp a -> MainExp a -> Bool
== :: MainExp a -> MainExp a -> Bool
$c== :: forall a. Eq a => MainExp a -> MainExp a -> Bool
Eq, Eq (MainExp a)
Eq (MainExp a)
-> (MainExp a -> MainExp a -> Ordering)
-> (MainExp a -> MainExp a -> Bool)
-> (MainExp a -> MainExp a -> Bool)
-> (MainExp a -> MainExp a -> Bool)
-> (MainExp a -> MainExp a -> Bool)
-> (MainExp a -> MainExp a -> MainExp a)
-> (MainExp a -> MainExp a -> MainExp a)
-> Ord (MainExp a)
MainExp a -> MainExp a -> Bool
MainExp a -> MainExp a -> Ordering
MainExp a -> MainExp a -> MainExp a
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
forall a. Ord a => Eq (MainExp a)
forall a. Ord a => MainExp a -> MainExp a -> Bool
forall a. Ord a => MainExp a -> MainExp a -> Ordering
forall a. Ord a => MainExp a -> MainExp a -> MainExp a
min :: MainExp a -> MainExp a -> MainExp a
$cmin :: forall a. Ord a => MainExp a -> MainExp a -> MainExp a
max :: MainExp a -> MainExp a -> MainExp a
$cmax :: forall a. Ord a => MainExp a -> MainExp a -> MainExp a
>= :: MainExp a -> MainExp a -> Bool
$c>= :: forall a. Ord a => MainExp a -> MainExp a -> Bool
> :: MainExp a -> MainExp a -> Bool
$c> :: forall a. Ord a => MainExp a -> MainExp a -> Bool
<= :: MainExp a -> MainExp a -> Bool
$c<= :: forall a. Ord a => MainExp a -> MainExp a -> Bool
< :: MainExp a -> MainExp a -> Bool
$c< :: forall a. Ord a => MainExp a -> MainExp a -> Bool
compare :: MainExp a -> MainExp a -> Ordering
$ccompare :: forall a. Ord a => MainExp a -> MainExp a -> Ordering
$cp1Ord :: forall a. Ord a => Eq (MainExp a)
Ord, a -> MainExp b -> MainExp a
(a -> b) -> MainExp a -> MainExp b
(forall a b. (a -> b) -> MainExp a -> MainExp b)
-> (forall a b. a -> MainExp b -> MainExp a) -> Functor MainExp
forall a b. a -> MainExp b -> MainExp a
forall a b. (a -> b) -> MainExp a -> MainExp b
forall (f :: * -> *).
(forall a b. (a -> b) -> f a -> f b)
-> (forall a b. a -> f b -> f a) -> Functor f
<$ :: a -> MainExp b -> MainExp a
$c<$ :: forall a b. a -> MainExp b -> MainExp a
fmap :: (a -> b) -> MainExp a -> MainExp b
$cfmap :: forall a b. (a -> b) -> MainExp a -> MainExp b
Functor, MainExp a -> Bool
(a -> m) -> MainExp a -> m
(a -> b -> b) -> b -> MainExp a -> b
(forall m. Monoid m => MainExp m -> m)
-> (forall m a. Monoid m => (a -> m) -> MainExp a -> m)
-> (forall m a. Monoid m => (a -> m) -> MainExp a -> m)
-> (forall a b. (a -> b -> b) -> b -> MainExp a -> b)
-> (forall a b. (a -> b -> b) -> b -> MainExp a -> b)
-> (forall b a. (b -> a -> b) -> b -> MainExp a -> b)
-> (forall b a. (b -> a -> b) -> b -> MainExp a -> b)
-> (forall a. (a -> a -> a) -> MainExp a -> a)
-> (forall a. (a -> a -> a) -> MainExp a -> a)
-> (forall a. MainExp a -> [a])
-> (forall a. MainExp a -> Bool)
-> (forall a. MainExp a -> Int)
-> (forall a. Eq a => a -> MainExp a -> Bool)
-> (forall a. Ord a => MainExp a -> a)
-> (forall a. Ord a => MainExp a -> a)
-> (forall a. Num a => MainExp a -> a)
-> (forall a. Num a => MainExp a -> a)
-> Foldable MainExp
forall a. Eq a => a -> MainExp a -> Bool
forall a. Num a => MainExp a -> a
forall a. Ord a => MainExp a -> a
forall m. Monoid m => MainExp m -> m
forall a. MainExp a -> Bool
forall a. MainExp a -> Int
forall a. MainExp a -> [a]
forall a. (a -> a -> a) -> MainExp a -> a
forall m a. Monoid m => (a -> m) -> MainExp a -> m
forall b a. (b -> a -> b) -> b -> MainExp a -> b
forall a b. (a -> b -> b) -> b -> MainExp a -> b
forall (t :: * -> *).
(forall m. Monoid m => t m -> m)
-> (forall m a. Monoid m => (a -> m) -> t a -> m)
-> (forall m a. Monoid m => (a -> m) -> t a -> m)
-> (forall a b. (a -> b -> b) -> b -> t a -> b)
-> (forall a b. (a -> b -> b) -> b -> t a -> b)
-> (forall b a. (b -> a -> b) -> b -> t a -> b)
-> (forall b a. (b -> a -> b) -> b -> t a -> b)
-> (forall a. (a -> a -> a) -> t a -> a)
-> (forall a. (a -> a -> a) -> t a -> a)
-> (forall a. t a -> [a])
-> (forall a. t a -> Bool)
-> (forall a. t a -> Int)
-> (forall a. Eq a => a -> t a -> Bool)
-> (forall a. Ord a => t a -> a)
-> (forall a. Ord a => t a -> a)
-> (forall a. Num a => t a -> a)
-> (forall a. Num a => t a -> a)
-> Foldable t
product :: MainExp a -> a
$cproduct :: forall a. Num a => MainExp a -> a
sum :: MainExp a -> a
$csum :: forall a. Num a => MainExp a -> a
minimum :: MainExp a -> a
$cminimum :: forall a. Ord a => MainExp a -> a
maximum :: MainExp a -> a
$cmaximum :: forall a. Ord a => MainExp a -> a
elem :: a -> MainExp a -> Bool
$celem :: forall a. Eq a => a -> MainExp a -> Bool
length :: MainExp a -> Int
$clength :: forall a. MainExp a -> Int
null :: MainExp a -> Bool
$cnull :: forall a. MainExp a -> Bool
toList :: MainExp a -> [a]
$ctoList :: forall a. MainExp a -> [a]
foldl1 :: (a -> a -> a) -> MainExp a -> a
$cfoldl1 :: forall a. (a -> a -> a) -> MainExp a -> a
foldr1 :: (a -> a -> a) -> MainExp a -> a
$cfoldr1 :: forall a. (a -> a -> a) -> MainExp a -> a
foldl' :: (b -> a -> b) -> b -> MainExp a -> b
$cfoldl' :: forall b a. (b -> a -> b) -> b -> MainExp a -> b
foldl :: (b -> a -> b) -> b -> MainExp a -> b
$cfoldl :: forall b a. (b -> a -> b) -> b -> MainExp a -> b
foldr' :: (a -> b -> b) -> b -> MainExp a -> b
$cfoldr' :: forall a b. (a -> b -> b) -> b -> MainExp a -> b
foldr :: (a -> b -> b) -> b -> MainExp a -> b
$cfoldr :: forall a b. (a -> b -> b) -> b -> MainExp a -> b
foldMap' :: (a -> m) -> MainExp a -> m
$cfoldMap' :: forall m a. Monoid m => (a -> m) -> MainExp a -> m
foldMap :: (a -> m) -> MainExp a -> m
$cfoldMap :: forall m a. Monoid m => (a -> m) -> MainExp a -> m
fold :: MainExp m -> m
$cfold :: forall m. Monoid m => MainExp m -> m
Foldable, Functor MainExp
Foldable MainExp
Functor MainExp
-> Foldable MainExp
-> (forall (f :: * -> *) a b.
    Applicative f =>
    (a -> f b) -> MainExp a -> f (MainExp b))
-> (forall (f :: * -> *) a.
    Applicative f =>
    MainExp (f a) -> f (MainExp a))
-> (forall (m :: * -> *) a b.
    Monad m =>
    (a -> m b) -> MainExp a -> m (MainExp b))
-> (forall (m :: * -> *) a.
    Monad m =>
    MainExp (m a) -> m (MainExp a))
-> Traversable MainExp
(a -> f b) -> MainExp a -> f (MainExp b)
forall (t :: * -> *).
Functor t
-> Foldable t
-> (forall (f :: * -> *) a b.
    Applicative f =>
    (a -> f b) -> t a -> f (t b))
-> (forall (f :: * -> *) a. Applicative f => t (f a) -> f (t a))
-> (forall (m :: * -> *) a b.
    Monad m =>
    (a -> m b) -> t a -> m (t b))
-> (forall (m :: * -> *) a. Monad m => t (m a) -> m (t a))
-> Traversable t
forall (m :: * -> *) a. Monad m => MainExp (m a) -> m (MainExp a)
forall (f :: * -> *) a.
Applicative f =>
MainExp (f a) -> f (MainExp a)
forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> MainExp a -> m (MainExp b)
forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> MainExp a -> f (MainExp b)
sequence :: MainExp (m a) -> m (MainExp a)
$csequence :: forall (m :: * -> *) a. Monad m => MainExp (m a) -> m (MainExp a)
mapM :: (a -> m b) -> MainExp a -> m (MainExp b)
$cmapM :: forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> MainExp a -> m (MainExp b)
sequenceA :: MainExp (f a) -> f (MainExp a)
$csequenceA :: forall (f :: * -> *) a.
Applicative f =>
MainExp (f a) -> f (MainExp a)
traverse :: (a -> f b) -> MainExp a -> f (MainExp b)
$ctraverse :: forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> MainExp a -> f (MainExp b)
$cp2Traversable :: Foldable MainExp
$cp1Traversable :: Functor MainExp
Traversable, (forall x. MainExp a -> Rep (MainExp a) x)
-> (forall x. Rep (MainExp a) x -> MainExp a)
-> Generic (MainExp a)
forall x. Rep (MainExp a) x -> MainExp a
forall x. MainExp a -> Rep (MainExp a) x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
forall a x. Rep (MainExp a) x -> MainExp a
forall a x. MainExp a -> Rep (MainExp a) x
$cto :: forall a x. Rep (MainExp a) x -> MainExp a
$cfrom :: forall a x. MainExp a -> Rep (MainExp a) x
Generic, (forall a. MainExp a -> Rep1 MainExp a)
-> (forall a. Rep1 MainExp a -> MainExp a) -> Generic1 MainExp
forall a. Rep1 MainExp a -> MainExp a
forall a. MainExp a -> Rep1 MainExp a
forall k (f :: k -> *).
(forall (a :: k). f a -> Rep1 f a)
-> (forall (a :: k). Rep1 f a -> f a) -> Generic1 f
$cto1 :: forall a. Rep1 MainExp a -> MainExp a
$cfrom1 :: forall a. MainExp a -> Rep1 MainExp a
Generic1)

type IsArrInit = Bool
type ArrSize a = [a]
type ArrIndex a = [a]

isEmptyExp :: E -> Bool
isEmptyExp :: E -> Bool
isEmptyExp E
e = Maybe Int -> Bool
forall a. Maybe a -> Bool
isNothing (RatedExp E -> Maybe Int
forall a. RatedExp a -> Maybe Int
ratedExpDepends RatedExp E
re) Bool -> Bool -> Bool
&& (RatedExp E -> Exp E
forall a. RatedExp a -> Exp a
ratedExpExp RatedExp E
re Exp E -> Exp E -> Bool
forall a. Eq a => a -> a -> Bool
== Exp E
forall a. MainExp a
EmptyExp)
    where re :: RatedExp E
re = E -> RatedExp E
forall (f :: * -> *). Fix f -> f (Fix f)
unFix E
e

-- Named variable
data Var
    = Var
        { Var -> VarType
varType :: VarType    -- global / local
        , Var -> Rate
varRate :: Rate
        , Var -> String
varName :: Name }
    | VarVerbatim
        { varRate :: Rate
        , varName :: Name
        } deriving (Int -> Var -> ShowS
[Var] -> ShowS
Var -> String
(Int -> Var -> ShowS)
-> (Var -> String) -> ([Var] -> ShowS) -> Show Var
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Var] -> ShowS
$cshowList :: [Var] -> ShowS
show :: Var -> String
$cshow :: Var -> String
showsPrec :: Int -> Var -> ShowS
$cshowsPrec :: Int -> Var -> ShowS
Show, Var -> Var -> Bool
(Var -> Var -> Bool) -> (Var -> Var -> Bool) -> Eq Var
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Var -> Var -> Bool
$c/= :: Var -> Var -> Bool
== :: Var -> Var -> Bool
$c== :: Var -> Var -> Bool
Eq, Eq Var
Eq Var
-> (Var -> Var -> Ordering)
-> (Var -> Var -> Bool)
-> (Var -> Var -> Bool)
-> (Var -> Var -> Bool)
-> (Var -> Var -> Bool)
-> (Var -> Var -> Var)
-> (Var -> Var -> Var)
-> Ord Var
Var -> Var -> Bool
Var -> Var -> Ordering
Var -> Var -> Var
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
min :: Var -> Var -> Var
$cmin :: Var -> Var -> Var
max :: Var -> Var -> Var
$cmax :: Var -> Var -> Var
>= :: Var -> Var -> Bool
$c>= :: Var -> Var -> Bool
> :: Var -> Var -> Bool
$c> :: Var -> Var -> Bool
<= :: Var -> Var -> Bool
$c<= :: Var -> Var -> Bool
< :: Var -> Var -> Bool
$c< :: Var -> Var -> Bool
compare :: Var -> Var -> Ordering
$ccompare :: Var -> Var -> Ordering
$cp1Ord :: Eq Var
Ord, (forall x. Var -> Rep Var x)
-> (forall x. Rep Var x -> Var) -> Generic Var
forall x. Rep Var x -> Var
forall x. Var -> Rep Var x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep Var x -> Var
$cfrom :: forall x. Var -> Rep Var x
Generic)

-- Variables can be global (then we have to prefix them with `g` in the rendering) or local.
data VarType = LocalVar | GlobalVar
    deriving (Int -> VarType -> ShowS
[VarType] -> ShowS
VarType -> String
(Int -> VarType -> ShowS)
-> (VarType -> String) -> ([VarType] -> ShowS) -> Show VarType
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [VarType] -> ShowS
$cshowList :: [VarType] -> ShowS
show :: VarType -> String
$cshow :: VarType -> String
showsPrec :: Int -> VarType -> ShowS
$cshowsPrec :: Int -> VarType -> ShowS
Show, VarType -> VarType -> Bool
(VarType -> VarType -> Bool)
-> (VarType -> VarType -> Bool) -> Eq VarType
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: VarType -> VarType -> Bool
$c/= :: VarType -> VarType -> Bool
== :: VarType -> VarType -> Bool
$c== :: VarType -> VarType -> Bool
Eq, Eq VarType
Eq VarType
-> (VarType -> VarType -> Ordering)
-> (VarType -> VarType -> Bool)
-> (VarType -> VarType -> Bool)
-> (VarType -> VarType -> Bool)
-> (VarType -> VarType -> Bool)
-> (VarType -> VarType -> VarType)
-> (VarType -> VarType -> VarType)
-> Ord VarType
VarType -> VarType -> Bool
VarType -> VarType -> Ordering
VarType -> VarType -> VarType
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
min :: VarType -> VarType -> VarType
$cmin :: VarType -> VarType -> VarType
max :: VarType -> VarType -> VarType
$cmax :: VarType -> VarType -> VarType
>= :: VarType -> VarType -> Bool
$c>= :: VarType -> VarType -> Bool
> :: VarType -> VarType -> Bool
$c> :: VarType -> VarType -> Bool
<= :: VarType -> VarType -> Bool
$c<= :: VarType -> VarType -> Bool
< :: VarType -> VarType -> Bool
$c< :: VarType -> VarType -> Bool
compare :: VarType -> VarType -> Ordering
$ccompare :: VarType -> VarType -> Ordering
$cp1Ord :: Eq VarType
Ord, (forall x. VarType -> Rep VarType x)
-> (forall x. Rep VarType x -> VarType) -> Generic VarType
forall x. Rep VarType x -> VarType
forall x. VarType -> Rep VarType x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep VarType x -> VarType
$cfrom :: forall x. VarType -> Rep VarType x
Generic)

-- Opcode information.
data Info = Info
    -- Opcode name
    { Info -> String
infoName          :: Name
    -- Opcode type signature
    , Info -> Signature
infoSignature     :: Signature
    -- Opcode can be infix or prefix
    , Info -> OpcFixity
infoOpcFixity     :: OpcFixity
    } deriving (Int -> Info -> ShowS
[Info] -> ShowS
Info -> String
(Int -> Info -> ShowS)
-> (Info -> String) -> ([Info] -> ShowS) -> Show Info
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Info] -> ShowS
$cshowList :: [Info] -> ShowS
show :: Info -> String
$cshow :: Info -> String
showsPrec :: Int -> Info -> ShowS
$cshowsPrec :: Int -> Info -> ShowS
Show, Info -> Info -> Bool
(Info -> Info -> Bool) -> (Info -> Info -> Bool) -> Eq Info
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Info -> Info -> Bool
$c/= :: Info -> Info -> Bool
== :: Info -> Info -> Bool
$c== :: Info -> Info -> Bool
Eq, Eq Info
Eq Info
-> (Info -> Info -> Ordering)
-> (Info -> Info -> Bool)
-> (Info -> Info -> Bool)
-> (Info -> Info -> Bool)
-> (Info -> Info -> Bool)
-> (Info -> Info -> Info)
-> (Info -> Info -> Info)
-> Ord Info
Info -> Info -> Bool
Info -> Info -> Ordering
Info -> Info -> Info
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
min :: Info -> Info -> Info
$cmin :: Info -> Info -> Info
max :: Info -> Info -> Info
$cmax :: Info -> Info -> Info
>= :: Info -> Info -> Bool
$c>= :: Info -> Info -> Bool
> :: Info -> Info -> Bool
$c> :: Info -> Info -> Bool
<= :: Info -> Info -> Bool
$c<= :: Info -> Info -> Bool
< :: Info -> Info -> Bool
$c< :: Info -> Info -> Bool
compare :: Info -> Info -> Ordering
$ccompare :: Info -> Info -> Ordering
$cp1Ord :: Eq Info
Ord, (forall x. Info -> Rep Info x)
-> (forall x. Rep Info x -> Info) -> Generic Info
forall x. Rep Info x -> Info
forall x. Info -> Rep Info x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep Info x -> Info
$cfrom :: forall x. Info -> Rep Info x
Generic)

isPrefix, isInfix :: Info -> Bool

isPrefix :: Info -> Bool
isPrefix = (OpcFixity
Prefix OpcFixity -> OpcFixity -> Bool
forall a. Eq a => a -> a -> Bool
==) (OpcFixity -> Bool) -> (Info -> OpcFixity) -> Info -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Info -> OpcFixity
infoOpcFixity
isInfix :: Info -> Bool
isInfix  = (OpcFixity
Infix  OpcFixity -> OpcFixity -> Bool
forall a. Eq a => a -> a -> Bool
==) (OpcFixity -> Bool) -> (Info -> OpcFixity) -> Info -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Info -> OpcFixity
infoOpcFixity

-- Opcode fixity
data OpcFixity = Prefix | Infix | Opcode
    deriving (Int -> OpcFixity -> ShowS
[OpcFixity] -> ShowS
OpcFixity -> String
(Int -> OpcFixity -> ShowS)
-> (OpcFixity -> String)
-> ([OpcFixity] -> ShowS)
-> Show OpcFixity
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [OpcFixity] -> ShowS
$cshowList :: [OpcFixity] -> ShowS
show :: OpcFixity -> String
$cshow :: OpcFixity -> String
showsPrec :: Int -> OpcFixity -> ShowS
$cshowsPrec :: Int -> OpcFixity -> ShowS
Show, OpcFixity -> OpcFixity -> Bool
(OpcFixity -> OpcFixity -> Bool)
-> (OpcFixity -> OpcFixity -> Bool) -> Eq OpcFixity
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: OpcFixity -> OpcFixity -> Bool
$c/= :: OpcFixity -> OpcFixity -> Bool
== :: OpcFixity -> OpcFixity -> Bool
$c== :: OpcFixity -> OpcFixity -> Bool
Eq, Eq OpcFixity
Eq OpcFixity
-> (OpcFixity -> OpcFixity -> Ordering)
-> (OpcFixity -> OpcFixity -> Bool)
-> (OpcFixity -> OpcFixity -> Bool)
-> (OpcFixity -> OpcFixity -> Bool)
-> (OpcFixity -> OpcFixity -> Bool)
-> (OpcFixity -> OpcFixity -> OpcFixity)
-> (OpcFixity -> OpcFixity -> OpcFixity)
-> Ord OpcFixity
OpcFixity -> OpcFixity -> Bool
OpcFixity -> OpcFixity -> Ordering
OpcFixity -> OpcFixity -> OpcFixity
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
min :: OpcFixity -> OpcFixity -> OpcFixity
$cmin :: OpcFixity -> OpcFixity -> OpcFixity
max :: OpcFixity -> OpcFixity -> OpcFixity
$cmax :: OpcFixity -> OpcFixity -> OpcFixity
>= :: OpcFixity -> OpcFixity -> Bool
$c>= :: OpcFixity -> OpcFixity -> Bool
> :: OpcFixity -> OpcFixity -> Bool
$c> :: OpcFixity -> OpcFixity -> Bool
<= :: OpcFixity -> OpcFixity -> Bool
$c<= :: OpcFixity -> OpcFixity -> Bool
< :: OpcFixity -> OpcFixity -> Bool
$c< :: OpcFixity -> OpcFixity -> Bool
compare :: OpcFixity -> OpcFixity -> Ordering
$ccompare :: OpcFixity -> OpcFixity -> Ordering
$cp1Ord :: Eq OpcFixity
Ord, (forall x. OpcFixity -> Rep OpcFixity x)
-> (forall x. Rep OpcFixity x -> OpcFixity) -> Generic OpcFixity
forall x. Rep OpcFixity x -> OpcFixity
forall x. OpcFixity -> Rep OpcFixity x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep OpcFixity x -> OpcFixity
$cfrom :: forall x. OpcFixity -> Rep OpcFixity x
Generic)

-- | The Csound rates.
data Rate   -- rate:
    ----------------------------
    = Xr    -- audio or control (and I use it for opcodes that produce no output, ie procedures)
    | Ar    -- audio
    | Kr    -- control
    | Ir    -- init (constants)
    | Sr    -- strings
    | Fr    -- spectrum (for pvs opcodes)
    | Wr    -- special spectrum
    | Tvar  -- I don't understand what it is (fix me) used with Fr
    deriving (Int -> Rate -> ShowS
[Rate] -> ShowS
Rate -> String
(Int -> Rate -> ShowS)
-> (Rate -> String) -> ([Rate] -> ShowS) -> Show Rate
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Rate] -> ShowS
$cshowList :: [Rate] -> ShowS
show :: Rate -> String
$cshow :: Rate -> String
showsPrec :: Int -> Rate -> ShowS
$cshowsPrec :: Int -> Rate -> ShowS
Show, Rate -> Rate -> Bool
(Rate -> Rate -> Bool) -> (Rate -> Rate -> Bool) -> Eq Rate
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Rate -> Rate -> Bool
$c/= :: Rate -> Rate -> Bool
== :: Rate -> Rate -> Bool
$c== :: Rate -> Rate -> Bool
Eq, Eq Rate
Eq Rate
-> (Rate -> Rate -> Ordering)
-> (Rate -> Rate -> Bool)
-> (Rate -> Rate -> Bool)
-> (Rate -> Rate -> Bool)
-> (Rate -> Rate -> Bool)
-> (Rate -> Rate -> Rate)
-> (Rate -> Rate -> Rate)
-> Ord Rate
Rate -> Rate -> Bool
Rate -> Rate -> Ordering
Rate -> Rate -> Rate
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
min :: Rate -> Rate -> Rate
$cmin :: Rate -> Rate -> Rate
max :: Rate -> Rate -> Rate
$cmax :: Rate -> Rate -> Rate
>= :: Rate -> Rate -> Bool
$c>= :: Rate -> Rate -> Bool
> :: Rate -> Rate -> Bool
$c> :: Rate -> Rate -> Bool
<= :: Rate -> Rate -> Bool
$c<= :: Rate -> Rate -> Bool
< :: Rate -> Rate -> Bool
$c< :: Rate -> Rate -> Bool
compare :: Rate -> Rate -> Ordering
$ccompare :: Rate -> Rate -> Ordering
$cp1Ord :: Eq Rate
Ord, Int -> Rate
Rate -> Int
Rate -> [Rate]
Rate -> Rate
Rate -> Rate -> [Rate]
Rate -> Rate -> Rate -> [Rate]
(Rate -> Rate)
-> (Rate -> Rate)
-> (Int -> Rate)
-> (Rate -> Int)
-> (Rate -> [Rate])
-> (Rate -> Rate -> [Rate])
-> (Rate -> Rate -> [Rate])
-> (Rate -> Rate -> Rate -> [Rate])
-> Enum Rate
forall a.
(a -> a)
-> (a -> a)
-> (Int -> a)
-> (a -> Int)
-> (a -> [a])
-> (a -> a -> [a])
-> (a -> a -> [a])
-> (a -> a -> a -> [a])
-> Enum a
enumFromThenTo :: Rate -> Rate -> Rate -> [Rate]
$cenumFromThenTo :: Rate -> Rate -> Rate -> [Rate]
enumFromTo :: Rate -> Rate -> [Rate]
$cenumFromTo :: Rate -> Rate -> [Rate]
enumFromThen :: Rate -> Rate -> [Rate]
$cenumFromThen :: Rate -> Rate -> [Rate]
enumFrom :: Rate -> [Rate]
$cenumFrom :: Rate -> [Rate]
fromEnum :: Rate -> Int
$cfromEnum :: Rate -> Int
toEnum :: Int -> Rate
$ctoEnum :: Int -> Rate
pred :: Rate -> Rate
$cpred :: Rate -> Rate
succ :: Rate -> Rate
$csucc :: Rate -> Rate
Enum, Rate
Rate -> Rate -> Bounded Rate
forall a. a -> a -> Bounded a
maxBound :: Rate
$cmaxBound :: Rate
minBound :: Rate
$cminBound :: Rate
Bounded, (forall x. Rate -> Rep Rate x)
-> (forall x. Rep Rate x -> Rate) -> Generic Rate
forall x. Rep Rate x -> Rate
forall x. Rate -> Rep Rate x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep Rate x -> Rate
$cfrom :: forall x. Rate -> Rep Rate x
Generic)

-- Opcode type signature. Opcodes can produce single output (SingleRate) or multiple outputs (MultiRate).
-- In Csound opcodes are often have several signatures. That is one opcode name can produce signals of the
-- different rate (it depends on the type of the outputs). Here we assume (to make things easier) that
-- opcodes that MultiRate-opcodes can produce only the arguments of the same type.
data Signature
    -- For SingleRate-opcodes type signature is the Map from output rate to the rate of the arguments.
    -- With it we can deduce the type of the argument from the type of the output.
    = SingleRate (Map Rate [Rate])
    -- For MultiRate-opcodes Map degenerates to the singleton. We have only one link.
    -- It contains rates for outputs and inputs.
    | MultiRate
        { Signature -> [Rate]
outMultiRate :: [Rate]
        , Signature -> [Rate]
inMultiRate  :: [Rate] }
    deriving (Int -> Signature -> ShowS
[Signature] -> ShowS
Signature -> String
(Int -> Signature -> ShowS)
-> (Signature -> String)
-> ([Signature] -> ShowS)
-> Show Signature
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Signature] -> ShowS
$cshowList :: [Signature] -> ShowS
show :: Signature -> String
$cshow :: Signature -> String
showsPrec :: Int -> Signature -> ShowS
$cshowsPrec :: Int -> Signature -> ShowS
Show, Signature -> Signature -> Bool
(Signature -> Signature -> Bool)
-> (Signature -> Signature -> Bool) -> Eq Signature
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Signature -> Signature -> Bool
$c/= :: Signature -> Signature -> Bool
== :: Signature -> Signature -> Bool
$c== :: Signature -> Signature -> Bool
Eq, Eq Signature
Eq Signature
-> (Signature -> Signature -> Ordering)
-> (Signature -> Signature -> Bool)
-> (Signature -> Signature -> Bool)
-> (Signature -> Signature -> Bool)
-> (Signature -> Signature -> Bool)
-> (Signature -> Signature -> Signature)
-> (Signature -> Signature -> Signature)
-> Ord Signature
Signature -> Signature -> Bool
Signature -> Signature -> Ordering
Signature -> Signature -> Signature
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
min :: Signature -> Signature -> Signature
$cmin :: Signature -> Signature -> Signature
max :: Signature -> Signature -> Signature
$cmax :: Signature -> Signature -> Signature
>= :: Signature -> Signature -> Bool
$c>= :: Signature -> Signature -> Bool
> :: Signature -> Signature -> Bool
$c> :: Signature -> Signature -> Bool
<= :: Signature -> Signature -> Bool
$c<= :: Signature -> Signature -> Bool
< :: Signature -> Signature -> Bool
$c< :: Signature -> Signature -> Bool
compare :: Signature -> Signature -> Ordering
$ccompare :: Signature -> Signature -> Ordering
$cp1Ord :: Eq Signature
Ord)

instance Hashable Signature where
    hashWithSalt :: Int -> Signature -> Int
hashWithSalt Int
s Signature
x = case Signature
x of
        SingleRate Map Rate [Rate]
m -> Int
s Int -> Int -> Int
forall a. Hashable a => Int -> a -> Int
`hashWithSalt` (Int
0 :: Int) Int -> Int -> Int
forall a. Hashable a => Int -> a -> Int
`hashWithSalt` (Maybe [Rate] -> Int
forall a. Hashable a => a -> Int
hash (Maybe [Rate] -> Int) -> Maybe [Rate] -> Int
forall a b. (a -> b) -> a -> b
$ ([Rate] -> [Rate]) -> Maybe [Rate] -> Maybe [Rate]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (\[Rate]
b -> (Int -> [Rate] -> [Rate]
forall a. Int -> [a] -> [a]
take Int
5 [Rate]
b)) (Maybe [Rate] -> Maybe [Rate]) -> Maybe [Rate] -> Maybe [Rate]
forall a b. (a -> b) -> a -> b
$ [[Rate]] -> Maybe [Rate]
forall a. [a] -> Maybe a
head' ([[Rate]] -> Maybe [Rate]) -> [[Rate]] -> Maybe [Rate]
forall a b. (a -> b) -> a -> b
$ Map Rate [Rate] -> [[Rate]]
forall (t :: * -> *) a. Foldable t => t a -> [a]
toList Map Rate [Rate]
m)
        MultiRate [Rate]
a [Rate]
b -> Int
s Int -> Int -> Int
forall a. Hashable a => Int -> a -> Int
`hashWithSalt` (Int
1 :: Int) Int -> Int -> Int
forall a. Hashable a => Int -> a -> Int
`hashWithSalt` ([Rate] -> Int
forall a. Hashable a => a -> Int
hash ([Rate] -> Int) -> [Rate] -> Int
forall a b. (a -> b) -> a -> b
$ Int -> [Rate] -> [Rate]
forall a. Int -> [a] -> [a]
take Int
5 [Rate]
a) Int -> Int -> Int
forall a. Hashable a => Int -> a -> Int
`hashWithSalt` ([Rate] -> Int
forall a. Hashable a => a -> Int
hash ([Rate] -> Int) -> [Rate] -> Int
forall a b. (a -> b) -> a -> b
$ Int -> [Rate] -> [Rate]
forall a. Int -> [a] -> [a]
take Int
5 [Rate]
b)
        where
            head' :: [a] -> Maybe a
head' [a]
xs = case [a]
xs of
                [] -> Maybe a
forall a. Maybe a
Nothing
                a
value:[a]
_ -> a -> Maybe a
forall a. a -> Maybe a
Just a
value

-- Primitive values
data Prim
    -- instrument p-arguments
    = P Int
    | PString Int       -- >> p-string (read p-string notes at the bottom of the file):
    | PrimInt Int
    | PrimDouble Double
    | PrimString String
    | PrimInstrId InstrId
    | PrimVar
        { Prim -> Rate
primVarTargetRate :: Rate
        , Prim -> Var
primVar           :: Var }
    deriving (Int -> Prim -> ShowS
[Prim] -> ShowS
Prim -> String
(Int -> Prim -> ShowS)
-> (Prim -> String) -> ([Prim] -> ShowS) -> Show Prim
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Prim] -> ShowS
$cshowList :: [Prim] -> ShowS
show :: Prim -> String
$cshow :: Prim -> String
showsPrec :: Int -> Prim -> ShowS
$cshowsPrec :: Int -> Prim -> ShowS
Show, Prim -> Prim -> Bool
(Prim -> Prim -> Bool) -> (Prim -> Prim -> Bool) -> Eq Prim
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Prim -> Prim -> Bool
$c/= :: Prim -> Prim -> Bool
== :: Prim -> Prim -> Bool
$c== :: Prim -> Prim -> Bool
Eq, Eq Prim
Eq Prim
-> (Prim -> Prim -> Ordering)
-> (Prim -> Prim -> Bool)
-> (Prim -> Prim -> Bool)
-> (Prim -> Prim -> Bool)
-> (Prim -> Prim -> Bool)
-> (Prim -> Prim -> Prim)
-> (Prim -> Prim -> Prim)
-> Ord Prim
Prim -> Prim -> Bool
Prim -> Prim -> Ordering
Prim -> Prim -> Prim
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
min :: Prim -> Prim -> Prim
$cmin :: Prim -> Prim -> Prim
max :: Prim -> Prim -> Prim
$cmax :: Prim -> Prim -> Prim
>= :: Prim -> Prim -> Bool
$c>= :: Prim -> Prim -> Bool
> :: Prim -> Prim -> Bool
$c> :: Prim -> Prim -> Bool
<= :: Prim -> Prim -> Bool
$c<= :: Prim -> Prim -> Bool
< :: Prim -> Prim -> Bool
$c< :: Prim -> Prim -> Bool
compare :: Prim -> Prim -> Ordering
$ccompare :: Prim -> Prim -> Ordering
$cp1Ord :: Eq Prim
Ord, (forall x. Prim -> Rep Prim x)
-> (forall x. Rep Prim x -> Prim) -> Generic Prim
forall x. Rep Prim x -> Prim
forall x. Prim -> Rep Prim x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep Prim x -> Prim
$cfrom :: forall x. Prim -> Rep Prim x
Generic)

-- Gen routine.
data Gen = Gen
    { Gen -> Int
genSize    :: Int
    , Gen -> GenId
genId      :: GenId
    , Gen -> [Double]
genArgs    :: [Double]
    , Gen -> Maybe String
genFile    :: Maybe String
    } deriving (Int -> Gen -> ShowS
[Gen] -> ShowS
Gen -> String
(Int -> Gen -> ShowS)
-> (Gen -> String) -> ([Gen] -> ShowS) -> Show Gen
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Gen] -> ShowS
$cshowList :: [Gen] -> ShowS
show :: Gen -> String
$cshow :: Gen -> String
showsPrec :: Int -> Gen -> ShowS
$cshowsPrec :: Int -> Gen -> ShowS
Show, Gen -> Gen -> Bool
(Gen -> Gen -> Bool) -> (Gen -> Gen -> Bool) -> Eq Gen
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Gen -> Gen -> Bool
$c/= :: Gen -> Gen -> Bool
== :: Gen -> Gen -> Bool
$c== :: Gen -> Gen -> Bool
Eq, Eq Gen
Eq Gen
-> (Gen -> Gen -> Ordering)
-> (Gen -> Gen -> Bool)
-> (Gen -> Gen -> Bool)
-> (Gen -> Gen -> Bool)
-> (Gen -> Gen -> Bool)
-> (Gen -> Gen -> Gen)
-> (Gen -> Gen -> Gen)
-> Ord Gen
Gen -> Gen -> Bool
Gen -> Gen -> Ordering
Gen -> Gen -> Gen
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
min :: Gen -> Gen -> Gen
$cmin :: Gen -> Gen -> Gen
max :: Gen -> Gen -> Gen
$cmax :: Gen -> Gen -> Gen
>= :: Gen -> Gen -> Bool
$c>= :: Gen -> Gen -> Bool
> :: Gen -> Gen -> Bool
$c> :: Gen -> Gen -> Bool
<= :: Gen -> Gen -> Bool
$c<= :: Gen -> Gen -> Bool
< :: Gen -> Gen -> Bool
$c< :: Gen -> Gen -> Bool
compare :: Gen -> Gen -> Ordering
$ccompare :: Gen -> Gen -> Ordering
$cp1Ord :: Eq Gen
Ord, (forall x. Gen -> Rep Gen x)
-> (forall x. Rep Gen x -> Gen) -> Generic Gen
forall x. Rep Gen x -> Gen
forall x. Gen -> Rep Gen x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep Gen x -> Gen
$cfrom :: forall x. Gen -> Rep Gen x
Generic)

data GenId = IntGenId Int | StringGenId String
    deriving (Int -> GenId -> ShowS
[GenId] -> ShowS
GenId -> String
(Int -> GenId -> ShowS)
-> (GenId -> String) -> ([GenId] -> ShowS) -> Show GenId
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [GenId] -> ShowS
$cshowList :: [GenId] -> ShowS
show :: GenId -> String
$cshow :: GenId -> String
showsPrec :: Int -> GenId -> ShowS
$cshowsPrec :: Int -> GenId -> ShowS
Show, GenId -> GenId -> Bool
(GenId -> GenId -> Bool) -> (GenId -> GenId -> Bool) -> Eq GenId
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: GenId -> GenId -> Bool
$c/= :: GenId -> GenId -> Bool
== :: GenId -> GenId -> Bool
$c== :: GenId -> GenId -> Bool
Eq, Eq GenId
Eq GenId
-> (GenId -> GenId -> Ordering)
-> (GenId -> GenId -> Bool)
-> (GenId -> GenId -> Bool)
-> (GenId -> GenId -> Bool)
-> (GenId -> GenId -> Bool)
-> (GenId -> GenId -> GenId)
-> (GenId -> GenId -> GenId)
-> Ord GenId
GenId -> GenId -> Bool
GenId -> GenId -> Ordering
GenId -> GenId -> GenId
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
min :: GenId -> GenId -> GenId
$cmin :: GenId -> GenId -> GenId
max :: GenId -> GenId -> GenId
$cmax :: GenId -> GenId -> GenId
>= :: GenId -> GenId -> Bool
$c>= :: GenId -> GenId -> Bool
> :: GenId -> GenId -> Bool
$c> :: GenId -> GenId -> Bool
<= :: GenId -> GenId -> Bool
$c<= :: GenId -> GenId -> Bool
< :: GenId -> GenId -> Bool
$c< :: GenId -> GenId -> Bool
compare :: GenId -> GenId -> Ordering
$ccompare :: GenId -> GenId -> Ordering
$cp1Ord :: Eq GenId
Ord, (forall x. GenId -> Rep GenId x)
-> (forall x. Rep GenId x -> GenId) -> Generic GenId
forall x. Rep GenId x -> GenId
forall x. GenId -> Rep GenId x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep GenId x -> GenId
$cfrom :: forall x. GenId -> Rep GenId x
Generic)

-- Csound note
type Note = [Prim]

------------------------------------------------------------
-- types for arithmetic and boolean expressions

data Inline a b = Inline
    { Inline a b -> InlineExp a
inlineExp :: InlineExp a
    , Inline a b -> IntMap b
inlineEnv :: IM.IntMap b
    } deriving (Int -> Inline a b -> ShowS
[Inline a b] -> ShowS
Inline a b -> String
(Int -> Inline a b -> ShowS)
-> (Inline a b -> String)
-> ([Inline a b] -> ShowS)
-> Show (Inline a b)
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
forall a b. (Show a, Show b) => Int -> Inline a b -> ShowS
forall a b. (Show a, Show b) => [Inline a b] -> ShowS
forall a b. (Show a, Show b) => Inline a b -> String
showList :: [Inline a b] -> ShowS
$cshowList :: forall a b. (Show a, Show b) => [Inline a b] -> ShowS
show :: Inline a b -> String
$cshow :: forall a b. (Show a, Show b) => Inline a b -> String
showsPrec :: Int -> Inline a b -> ShowS
$cshowsPrec :: forall a b. (Show a, Show b) => Int -> Inline a b -> ShowS
Show, Inline a b -> Inline a b -> Bool
(Inline a b -> Inline a b -> Bool)
-> (Inline a b -> Inline a b -> Bool) -> Eq (Inline a b)
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
forall a b. (Eq a, Eq b) => Inline a b -> Inline a b -> Bool
/= :: Inline a b -> Inline a b -> Bool
$c/= :: forall a b. (Eq a, Eq b) => Inline a b -> Inline a b -> Bool
== :: Inline a b -> Inline a b -> Bool
$c== :: forall a b. (Eq a, Eq b) => Inline a b -> Inline a b -> Bool
Eq, Eq (Inline a b)
Eq (Inline a b)
-> (Inline a b -> Inline a b -> Ordering)
-> (Inline a b -> Inline a b -> Bool)
-> (Inline a b -> Inline a b -> Bool)
-> (Inline a b -> Inline a b -> Bool)
-> (Inline a b -> Inline a b -> Bool)
-> (Inline a b -> Inline a b -> Inline a b)
-> (Inline a b -> Inline a b -> Inline a b)
-> Ord (Inline a b)
Inline a b -> Inline a b -> Bool
Inline a b -> Inline a b -> Ordering
Inline a b -> Inline a b -> Inline a b
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
forall a b. (Ord a, Ord b) => Eq (Inline a b)
forall a b. (Ord a, Ord b) => Inline a b -> Inline a b -> Bool
forall a b. (Ord a, Ord b) => Inline a b -> Inline a b -> Ordering
forall a b.
(Ord a, Ord b) =>
Inline a b -> Inline a b -> Inline a b
min :: Inline a b -> Inline a b -> Inline a b
$cmin :: forall a b.
(Ord a, Ord b) =>
Inline a b -> Inline a b -> Inline a b
max :: Inline a b -> Inline a b -> Inline a b
$cmax :: forall a b.
(Ord a, Ord b) =>
Inline a b -> Inline a b -> Inline a b
>= :: Inline a b -> Inline a b -> Bool
$c>= :: forall a b. (Ord a, Ord b) => Inline a b -> Inline a b -> Bool
> :: Inline a b -> Inline a b -> Bool
$c> :: forall a b. (Ord a, Ord b) => Inline a b -> Inline a b -> Bool
<= :: Inline a b -> Inline a b -> Bool
$c<= :: forall a b. (Ord a, Ord b) => Inline a b -> Inline a b -> Bool
< :: Inline a b -> Inline a b -> Bool
$c< :: forall a b. (Ord a, Ord b) => Inline a b -> Inline a b -> Bool
compare :: Inline a b -> Inline a b -> Ordering
$ccompare :: forall a b. (Ord a, Ord b) => Inline a b -> Inline a b -> Ordering
$cp1Ord :: forall a b. (Ord a, Ord b) => Eq (Inline a b)
Ord, a -> Inline a b -> Inline a a
(a -> b) -> Inline a a -> Inline a b
(forall a b. (a -> b) -> Inline a a -> Inline a b)
-> (forall a b. a -> Inline a b -> Inline a a)
-> Functor (Inline a)
forall a b. a -> Inline a b -> Inline a a
forall a b. (a -> b) -> Inline a a -> Inline a b
forall a a b. a -> Inline a b -> Inline a a
forall a a b. (a -> b) -> Inline a a -> Inline a b
forall (f :: * -> *).
(forall a b. (a -> b) -> f a -> f b)
-> (forall a b. a -> f b -> f a) -> Functor f
<$ :: a -> Inline a b -> Inline a a
$c<$ :: forall a a b. a -> Inline a b -> Inline a a
fmap :: (a -> b) -> Inline a a -> Inline a b
$cfmap :: forall a a b. (a -> b) -> Inline a a -> Inline a b
Functor, Inline a a -> Bool
(a -> m) -> Inline a a -> m
(a -> b -> b) -> b -> Inline a a -> b
(forall m. Monoid m => Inline a m -> m)
-> (forall m a. Monoid m => (a -> m) -> Inline a a -> m)
-> (forall m a. Monoid m => (a -> m) -> Inline a a -> m)
-> (forall a b. (a -> b -> b) -> b -> Inline a a -> b)
-> (forall a b. (a -> b -> b) -> b -> Inline a a -> b)
-> (forall b a. (b -> a -> b) -> b -> Inline a a -> b)
-> (forall b a. (b -> a -> b) -> b -> Inline a a -> b)
-> (forall a. (a -> a -> a) -> Inline a a -> a)
-> (forall a. (a -> a -> a) -> Inline a a -> a)
-> (forall a. Inline a a -> [a])
-> (forall a. Inline a a -> Bool)
-> (forall a. Inline a a -> Int)
-> (forall a. Eq a => a -> Inline a a -> Bool)
-> (forall a. Ord a => Inline a a -> a)
-> (forall a. Ord a => Inline a a -> a)
-> (forall a. Num a => Inline a a -> a)
-> (forall a. Num a => Inline a a -> a)
-> Foldable (Inline a)
forall a. Eq a => a -> Inline a a -> Bool
forall a. Num a => Inline a a -> a
forall a. Ord a => Inline a a -> a
forall m. Monoid m => Inline a m -> m
forall a. Inline a a -> Bool
forall a. Inline a a -> Int
forall a. Inline a a -> [a]
forall a. (a -> a -> a) -> Inline a a -> a
forall a a. Eq a => a -> Inline a a -> Bool
forall a a. Num a => Inline a a -> a
forall a a. Ord a => Inline a a -> a
forall m a. Monoid m => (a -> m) -> Inline a a -> m
forall a m. Monoid m => Inline a m -> m
forall a a. Inline a a -> Bool
forall a a. Inline a a -> Int
forall a a. Inline a a -> [a]
forall b a. (b -> a -> b) -> b -> Inline a a -> b
forall a b. (a -> b -> b) -> b -> Inline a a -> b
forall a a. (a -> a -> a) -> Inline a a -> a
forall a m a. Monoid m => (a -> m) -> Inline a a -> m
forall a b a. (b -> a -> b) -> b -> Inline a a -> b
forall a a b. (a -> b -> b) -> b -> Inline a a -> b
forall (t :: * -> *).
(forall m. Monoid m => t m -> m)
-> (forall m a. Monoid m => (a -> m) -> t a -> m)
-> (forall m a. Monoid m => (a -> m) -> t a -> m)
-> (forall a b. (a -> b -> b) -> b -> t a -> b)
-> (forall a b. (a -> b -> b) -> b -> t a -> b)
-> (forall b a. (b -> a -> b) -> b -> t a -> b)
-> (forall b a. (b -> a -> b) -> b -> t a -> b)
-> (forall a. (a -> a -> a) -> t a -> a)
-> (forall a. (a -> a -> a) -> t a -> a)
-> (forall a. t a -> [a])
-> (forall a. t a -> Bool)
-> (forall a. t a -> Int)
-> (forall a. Eq a => a -> t a -> Bool)
-> (forall a. Ord a => t a -> a)
-> (forall a. Ord a => t a -> a)
-> (forall a. Num a => t a -> a)
-> (forall a. Num a => t a -> a)
-> Foldable t
product :: Inline a a -> a
$cproduct :: forall a a. Num a => Inline a a -> a
sum :: Inline a a -> a
$csum :: forall a a. Num a => Inline a a -> a
minimum :: Inline a a -> a
$cminimum :: forall a a. Ord a => Inline a a -> a
maximum :: Inline a a -> a
$cmaximum :: forall a a. Ord a => Inline a a -> a
elem :: a -> Inline a a -> Bool
$celem :: forall a a. Eq a => a -> Inline a a -> Bool
length :: Inline a a -> Int
$clength :: forall a a. Inline a a -> Int
null :: Inline a a -> Bool
$cnull :: forall a a. Inline a a -> Bool
toList :: Inline a a -> [a]
$ctoList :: forall a a. Inline a a -> [a]
foldl1 :: (a -> a -> a) -> Inline a a -> a
$cfoldl1 :: forall a a. (a -> a -> a) -> Inline a a -> a
foldr1 :: (a -> a -> a) -> Inline a a -> a
$cfoldr1 :: forall a a. (a -> a -> a) -> Inline a a -> a
foldl' :: (b -> a -> b) -> b -> Inline a a -> b
$cfoldl' :: forall a b a. (b -> a -> b) -> b -> Inline a a -> b
foldl :: (b -> a -> b) -> b -> Inline a a -> b
$cfoldl :: forall a b a. (b -> a -> b) -> b -> Inline a a -> b
foldr' :: (a -> b -> b) -> b -> Inline a a -> b
$cfoldr' :: forall a a b. (a -> b -> b) -> b -> Inline a a -> b
foldr :: (a -> b -> b) -> b -> Inline a a -> b
$cfoldr :: forall a a b. (a -> b -> b) -> b -> Inline a a -> b
foldMap' :: (a -> m) -> Inline a a -> m
$cfoldMap' :: forall a m a. Monoid m => (a -> m) -> Inline a a -> m
foldMap :: (a -> m) -> Inline a a -> m
$cfoldMap :: forall a m a. Monoid m => (a -> m) -> Inline a a -> m
fold :: Inline a m -> m
$cfold :: forall a m. Monoid m => Inline a m -> m
Foldable, Functor (Inline a)
Foldable (Inline a)
Functor (Inline a)
-> Foldable (Inline a)
-> (forall (f :: * -> *) a b.
    Applicative f =>
    (a -> f b) -> Inline a a -> f (Inline a b))
-> (forall (f :: * -> *) a.
    Applicative f =>
    Inline a (f a) -> f (Inline a a))
-> (forall (m :: * -> *) a b.
    Monad m =>
    (a -> m b) -> Inline a a -> m (Inline a b))
-> (forall (m :: * -> *) a.
    Monad m =>
    Inline a (m a) -> m (Inline a a))
-> Traversable (Inline a)
(a -> f b) -> Inline a a -> f (Inline a b)
forall a. Functor (Inline a)
forall a. Foldable (Inline a)
forall a (m :: * -> *) a.
Monad m =>
Inline a (m a) -> m (Inline a a)
forall a (f :: * -> *) a.
Applicative f =>
Inline a (f a) -> f (Inline a a)
forall a (m :: * -> *) a b.
Monad m =>
(a -> m b) -> Inline a a -> m (Inline a b)
forall a (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> Inline a a -> f (Inline a b)
forall (t :: * -> *).
Functor t
-> Foldable t
-> (forall (f :: * -> *) a b.
    Applicative f =>
    (a -> f b) -> t a -> f (t b))
-> (forall (f :: * -> *) a. Applicative f => t (f a) -> f (t a))
-> (forall (m :: * -> *) a b.
    Monad m =>
    (a -> m b) -> t a -> m (t b))
-> (forall (m :: * -> *) a. Monad m => t (m a) -> m (t a))
-> Traversable t
forall (m :: * -> *) a. Monad m => Inline a (m a) -> m (Inline a a)
forall (f :: * -> *) a.
Applicative f =>
Inline a (f a) -> f (Inline a a)
forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> Inline a a -> m (Inline a b)
forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> Inline a a -> f (Inline a b)
sequence :: Inline a (m a) -> m (Inline a a)
$csequence :: forall a (m :: * -> *) a.
Monad m =>
Inline a (m a) -> m (Inline a a)
mapM :: (a -> m b) -> Inline a a -> m (Inline a b)
$cmapM :: forall a (m :: * -> *) a b.
Monad m =>
(a -> m b) -> Inline a a -> m (Inline a b)
sequenceA :: Inline a (f a) -> f (Inline a a)
$csequenceA :: forall a (f :: * -> *) a.
Applicative f =>
Inline a (f a) -> f (Inline a a)
traverse :: (a -> f b) -> Inline a a -> f (Inline a b)
$ctraverse :: forall a (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> Inline a a -> f (Inline a b)
$cp2Traversable :: forall a. Foldable (Inline a)
$cp1Traversable :: forall a. Functor (Inline a)
Traversable, (forall a. Inline a a -> Rep1 (Inline a) a)
-> (forall a. Rep1 (Inline a) a -> Inline a a)
-> Generic1 (Inline a)
forall a. Rep1 (Inline a) a -> Inline a a
forall a. Inline a a -> Rep1 (Inline a) a
forall a a. Rep1 (Inline a) a -> Inline a a
forall a a. Inline a a -> Rep1 (Inline a) a
forall k (f :: k -> *).
(forall (a :: k). f a -> Rep1 f a)
-> (forall (a :: k). Rep1 f a -> f a) -> Generic1 f
$cto1 :: forall a a. Rep1 (Inline a) a -> Inline a a
$cfrom1 :: forall a a. Inline a a -> Rep1 (Inline a) a
Generic1)

instance (Hashable a, Hashable b) => Hashable (Inline a b) where
    hashWithSalt :: Int -> Inline a b -> Int
hashWithSalt Int
s (Inline InlineExp a
a IntMap b
m) = Int
s Int -> Int -> Int
forall a. Hashable a => Int -> a -> Int
`hashWithSalt` (InlineExp a -> Int
forall a. Hashable a => a -> Int
hash InlineExp a
a) Int -> Int -> Int
forall a. Hashable a => Int -> a -> Int
`hashWithSalt` ([(Int, b)] -> Int
forall a. Hashable a => a -> Int
hash ([(Int, b)] -> Int) -> [(Int, b)] -> Int
forall a b. (a -> b) -> a -> b
$ IntMap b -> [(Int, b)]
forall a. IntMap a -> [(Int, a)]
IM.toList IntMap b
m)

-- Inlined expression.
data InlineExp a
    = InlinePrim Int
    | InlineExp a [InlineExp a]
    deriving (Int -> InlineExp a -> ShowS
[InlineExp a] -> ShowS
InlineExp a -> String
(Int -> InlineExp a -> ShowS)
-> (InlineExp a -> String)
-> ([InlineExp a] -> ShowS)
-> Show (InlineExp a)
forall a. Show a => Int -> InlineExp a -> ShowS
forall a. Show a => [InlineExp a] -> ShowS
forall a. Show a => InlineExp a -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [InlineExp a] -> ShowS
$cshowList :: forall a. Show a => [InlineExp a] -> ShowS
show :: InlineExp a -> String
$cshow :: forall a. Show a => InlineExp a -> String
showsPrec :: Int -> InlineExp a -> ShowS
$cshowsPrec :: forall a. Show a => Int -> InlineExp a -> ShowS
Show, InlineExp a -> InlineExp a -> Bool
(InlineExp a -> InlineExp a -> Bool)
-> (InlineExp a -> InlineExp a -> Bool) -> Eq (InlineExp a)
forall a. Eq a => InlineExp a -> InlineExp a -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: InlineExp a -> InlineExp a -> Bool
$c/= :: forall a. Eq a => InlineExp a -> InlineExp a -> Bool
== :: InlineExp a -> InlineExp a -> Bool
$c== :: forall a. Eq a => InlineExp a -> InlineExp a -> Bool
Eq, Eq (InlineExp a)
Eq (InlineExp a)
-> (InlineExp a -> InlineExp a -> Ordering)
-> (InlineExp a -> InlineExp a -> Bool)
-> (InlineExp a -> InlineExp a -> Bool)
-> (InlineExp a -> InlineExp a -> Bool)
-> (InlineExp a -> InlineExp a -> Bool)
-> (InlineExp a -> InlineExp a -> InlineExp a)
-> (InlineExp a -> InlineExp a -> InlineExp a)
-> Ord (InlineExp a)
InlineExp a -> InlineExp a -> Bool
InlineExp a -> InlineExp a -> Ordering
InlineExp a -> InlineExp a -> InlineExp a
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
forall a. Ord a => Eq (InlineExp a)
forall a. Ord a => InlineExp a -> InlineExp a -> Bool
forall a. Ord a => InlineExp a -> InlineExp a -> Ordering
forall a. Ord a => InlineExp a -> InlineExp a -> InlineExp a
min :: InlineExp a -> InlineExp a -> InlineExp a
$cmin :: forall a. Ord a => InlineExp a -> InlineExp a -> InlineExp a
max :: InlineExp a -> InlineExp a -> InlineExp a
$cmax :: forall a. Ord a => InlineExp a -> InlineExp a -> InlineExp a
>= :: InlineExp a -> InlineExp a -> Bool
$c>= :: forall a. Ord a => InlineExp a -> InlineExp a -> Bool
> :: InlineExp a -> InlineExp a -> Bool
$c> :: forall a. Ord a => InlineExp a -> InlineExp a -> Bool
<= :: InlineExp a -> InlineExp a -> Bool
$c<= :: forall a. Ord a => InlineExp a -> InlineExp a -> Bool
< :: InlineExp a -> InlineExp a -> Bool
$c< :: forall a. Ord a => InlineExp a -> InlineExp a -> Bool
compare :: InlineExp a -> InlineExp a -> Ordering
$ccompare :: forall a. Ord a => InlineExp a -> InlineExp a -> Ordering
$cp1Ord :: forall a. Ord a => Eq (InlineExp a)
Ord, (forall x. InlineExp a -> Rep (InlineExp a) x)
-> (forall x. Rep (InlineExp a) x -> InlineExp a)
-> Generic (InlineExp a)
forall x. Rep (InlineExp a) x -> InlineExp a
forall x. InlineExp a -> Rep (InlineExp a) x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
forall a x. Rep (InlineExp a) x -> InlineExp a
forall a x. InlineExp a -> Rep (InlineExp a) x
$cto :: forall a x. Rep (InlineExp a) x -> InlineExp a
$cfrom :: forall a x. InlineExp a -> Rep (InlineExp a) x
Generic)

-- Expression as a tree (to be inlined)
data PreInline a b = PreInline a [b]
    deriving (Int -> PreInline a b -> ShowS
[PreInline a b] -> ShowS
PreInline a b -> String
(Int -> PreInline a b -> ShowS)
-> (PreInline a b -> String)
-> ([PreInline a b] -> ShowS)
-> Show (PreInline a b)
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
forall a b. (Show a, Show b) => Int -> PreInline a b -> ShowS
forall a b. (Show a, Show b) => [PreInline a b] -> ShowS
forall a b. (Show a, Show b) => PreInline a b -> String
showList :: [PreInline a b] -> ShowS
$cshowList :: forall a b. (Show a, Show b) => [PreInline a b] -> ShowS
show :: PreInline a b -> String
$cshow :: forall a b. (Show a, Show b) => PreInline a b -> String
showsPrec :: Int -> PreInline a b -> ShowS
$cshowsPrec :: forall a b. (Show a, Show b) => Int -> PreInline a b -> ShowS
Show, PreInline a b -> PreInline a b -> Bool
(PreInline a b -> PreInline a b -> Bool)
-> (PreInline a b -> PreInline a b -> Bool) -> Eq (PreInline a b)
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
forall a b. (Eq a, Eq b) => PreInline a b -> PreInline a b -> Bool
/= :: PreInline a b -> PreInline a b -> Bool
$c/= :: forall a b. (Eq a, Eq b) => PreInline a b -> PreInline a b -> Bool
== :: PreInline a b -> PreInline a b -> Bool
$c== :: forall a b. (Eq a, Eq b) => PreInline a b -> PreInline a b -> Bool
Eq, Eq (PreInline a b)
Eq (PreInline a b)
-> (PreInline a b -> PreInline a b -> Ordering)
-> (PreInline a b -> PreInline a b -> Bool)
-> (PreInline a b -> PreInline a b -> Bool)
-> (PreInline a b -> PreInline a b -> Bool)
-> (PreInline a b -> PreInline a b -> Bool)
-> (PreInline a b -> PreInline a b -> PreInline a b)
-> (PreInline a b -> PreInline a b -> PreInline a b)
-> Ord (PreInline a b)
PreInline a b -> PreInline a b -> Bool
PreInline a b -> PreInline a b -> Ordering
PreInline a b -> PreInline a b -> PreInline a b
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
forall a b. (Ord a, Ord b) => Eq (PreInline a b)
forall a b.
(Ord a, Ord b) =>
PreInline a b -> PreInline a b -> Bool
forall a b.
(Ord a, Ord b) =>
PreInline a b -> PreInline a b -> Ordering
forall a b.
(Ord a, Ord b) =>
PreInline a b -> PreInline a b -> PreInline a b
min :: PreInline a b -> PreInline a b -> PreInline a b
$cmin :: forall a b.
(Ord a, Ord b) =>
PreInline a b -> PreInline a b -> PreInline a b
max :: PreInline a b -> PreInline a b -> PreInline a b
$cmax :: forall a b.
(Ord a, Ord b) =>
PreInline a b -> PreInline a b -> PreInline a b
>= :: PreInline a b -> PreInline a b -> Bool
$c>= :: forall a b.
(Ord a, Ord b) =>
PreInline a b -> PreInline a b -> Bool
> :: PreInline a b -> PreInline a b -> Bool
$c> :: forall a b.
(Ord a, Ord b) =>
PreInline a b -> PreInline a b -> Bool
<= :: PreInline a b -> PreInline a b -> Bool
$c<= :: forall a b.
(Ord a, Ord b) =>
PreInline a b -> PreInline a b -> Bool
< :: PreInline a b -> PreInline a b -> Bool
$c< :: forall a b.
(Ord a, Ord b) =>
PreInline a b -> PreInline a b -> Bool
compare :: PreInline a b -> PreInline a b -> Ordering
$ccompare :: forall a b.
(Ord a, Ord b) =>
PreInline a b -> PreInline a b -> Ordering
$cp1Ord :: forall a b. (Ord a, Ord b) => Eq (PreInline a b)
Ord, a -> PreInline a b -> PreInline a a
(a -> b) -> PreInline a a -> PreInline a b
(forall a b. (a -> b) -> PreInline a a -> PreInline a b)
-> (forall a b. a -> PreInline a b -> PreInline a a)
-> Functor (PreInline a)
forall a b. a -> PreInline a b -> PreInline a a
forall a b. (a -> b) -> PreInline a a -> PreInline a b
forall a a b. a -> PreInline a b -> PreInline a a
forall a a b. (a -> b) -> PreInline a a -> PreInline a b
forall (f :: * -> *).
(forall a b. (a -> b) -> f a -> f b)
-> (forall a b. a -> f b -> f a) -> Functor f
<$ :: a -> PreInline a b -> PreInline a a
$c<$ :: forall a a b. a -> PreInline a b -> PreInline a a
fmap :: (a -> b) -> PreInline a a -> PreInline a b
$cfmap :: forall a a b. (a -> b) -> PreInline a a -> PreInline a b
Functor, PreInline a a -> Bool
(a -> m) -> PreInline a a -> m
(a -> b -> b) -> b -> PreInline a a -> b
(forall m. Monoid m => PreInline a m -> m)
-> (forall m a. Monoid m => (a -> m) -> PreInline a a -> m)
-> (forall m a. Monoid m => (a -> m) -> PreInline a a -> m)
-> (forall a b. (a -> b -> b) -> b -> PreInline a a -> b)
-> (forall a b. (a -> b -> b) -> b -> PreInline a a -> b)
-> (forall b a. (b -> a -> b) -> b -> PreInline a a -> b)
-> (forall b a. (b -> a -> b) -> b -> PreInline a a -> b)
-> (forall a. (a -> a -> a) -> PreInline a a -> a)
-> (forall a. (a -> a -> a) -> PreInline a a -> a)
-> (forall a. PreInline a a -> [a])
-> (forall a. PreInline a a -> Bool)
-> (forall a. PreInline a a -> Int)
-> (forall a. Eq a => a -> PreInline a a -> Bool)
-> (forall a. Ord a => PreInline a a -> a)
-> (forall a. Ord a => PreInline a a -> a)
-> (forall a. Num a => PreInline a a -> a)
-> (forall a. Num a => PreInline a a -> a)
-> Foldable (PreInline a)
forall a. Eq a => a -> PreInline a a -> Bool
forall a. Num a => PreInline a a -> a
forall a. Ord a => PreInline a a -> a
forall m. Monoid m => PreInline a m -> m
forall a. PreInline a a -> Bool
forall a. PreInline a a -> Int
forall a. PreInline a a -> [a]
forall a. (a -> a -> a) -> PreInline a a -> a
forall a a. Eq a => a -> PreInline a a -> Bool
forall a a. Num a => PreInline a a -> a
forall a a. Ord a => PreInline a a -> a
forall m a. Monoid m => (a -> m) -> PreInline a a -> m
forall a m. Monoid m => PreInline a m -> m
forall a a. PreInline a a -> Bool
forall a a. PreInline a a -> Int
forall a a. PreInline a a -> [a]
forall b a. (b -> a -> b) -> b -> PreInline a a -> b
forall a b. (a -> b -> b) -> b -> PreInline a a -> b
forall a a. (a -> a -> a) -> PreInline a a -> a
forall a m a. Monoid m => (a -> m) -> PreInline a a -> m
forall a b a. (b -> a -> b) -> b -> PreInline a a -> b
forall a a b. (a -> b -> b) -> b -> PreInline a a -> b
forall (t :: * -> *).
(forall m. Monoid m => t m -> m)
-> (forall m a. Monoid m => (a -> m) -> t a -> m)
-> (forall m a. Monoid m => (a -> m) -> t a -> m)
-> (forall a b. (a -> b -> b) -> b -> t a -> b)
-> (forall a b. (a -> b -> b) -> b -> t a -> b)
-> (forall b a. (b -> a -> b) -> b -> t a -> b)
-> (forall b a. (b -> a -> b) -> b -> t a -> b)
-> (forall a. (a -> a -> a) -> t a -> a)
-> (forall a. (a -> a -> a) -> t a -> a)
-> (forall a. t a -> [a])
-> (forall a. t a -> Bool)
-> (forall a. t a -> Int)
-> (forall a. Eq a => a -> t a -> Bool)
-> (forall a. Ord a => t a -> a)
-> (forall a. Ord a => t a -> a)
-> (forall a. Num a => t a -> a)
-> (forall a. Num a => t a -> a)
-> Foldable t
product :: PreInline a a -> a
$cproduct :: forall a a. Num a => PreInline a a -> a
sum :: PreInline a a -> a
$csum :: forall a a. Num a => PreInline a a -> a
minimum :: PreInline a a -> a
$cminimum :: forall a a. Ord a => PreInline a a -> a
maximum :: PreInline a a -> a
$cmaximum :: forall a a. Ord a => PreInline a a -> a
elem :: a -> PreInline a a -> Bool
$celem :: forall a a. Eq a => a -> PreInline a a -> Bool
length :: PreInline a a -> Int
$clength :: forall a a. PreInline a a -> Int
null :: PreInline a a -> Bool
$cnull :: forall a a. PreInline a a -> Bool
toList :: PreInline a a -> [a]
$ctoList :: forall a a. PreInline a a -> [a]
foldl1 :: (a -> a -> a) -> PreInline a a -> a
$cfoldl1 :: forall a a. (a -> a -> a) -> PreInline a a -> a
foldr1 :: (a -> a -> a) -> PreInline a a -> a
$cfoldr1 :: forall a a. (a -> a -> a) -> PreInline a a -> a
foldl' :: (b -> a -> b) -> b -> PreInline a a -> b
$cfoldl' :: forall a b a. (b -> a -> b) -> b -> PreInline a a -> b
foldl :: (b -> a -> b) -> b -> PreInline a a -> b
$cfoldl :: forall a b a. (b -> a -> b) -> b -> PreInline a a -> b
foldr' :: (a -> b -> b) -> b -> PreInline a a -> b
$cfoldr' :: forall a a b. (a -> b -> b) -> b -> PreInline a a -> b
foldr :: (a -> b -> b) -> b -> PreInline a a -> b
$cfoldr :: forall a a b. (a -> b -> b) -> b -> PreInline a a -> b
foldMap' :: (a -> m) -> PreInline a a -> m
$cfoldMap' :: forall a m a. Monoid m => (a -> m) -> PreInline a a -> m
foldMap :: (a -> m) -> PreInline a a -> m
$cfoldMap :: forall a m a. Monoid m => (a -> m) -> PreInline a a -> m
fold :: PreInline a m -> m
$cfold :: forall a m. Monoid m => PreInline a m -> m
Foldable, Functor (PreInline a)
Foldable (PreInline a)
Functor (PreInline a)
-> Foldable (PreInline a)
-> (forall (f :: * -> *) a b.
    Applicative f =>
    (a -> f b) -> PreInline a a -> f (PreInline a b))
-> (forall (f :: * -> *) a.
    Applicative f =>
    PreInline a (f a) -> f (PreInline a a))
-> (forall (m :: * -> *) a b.
    Monad m =>
    (a -> m b) -> PreInline a a -> m (PreInline a b))
-> (forall (m :: * -> *) a.
    Monad m =>
    PreInline a (m a) -> m (PreInline a a))
-> Traversable (PreInline a)
(a -> f b) -> PreInline a a -> f (PreInline a b)
forall a. Functor (PreInline a)
forall a. Foldable (PreInline a)
forall a (m :: * -> *) a.
Monad m =>
PreInline a (m a) -> m (PreInline a a)
forall a (f :: * -> *) a.
Applicative f =>
PreInline a (f a) -> f (PreInline a a)
forall a (m :: * -> *) a b.
Monad m =>
(a -> m b) -> PreInline a a -> m (PreInline a b)
forall a (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> PreInline a a -> f (PreInline a b)
forall (t :: * -> *).
Functor t
-> Foldable t
-> (forall (f :: * -> *) a b.
    Applicative f =>
    (a -> f b) -> t a -> f (t b))
-> (forall (f :: * -> *) a. Applicative f => t (f a) -> f (t a))
-> (forall (m :: * -> *) a b.
    Monad m =>
    (a -> m b) -> t a -> m (t b))
-> (forall (m :: * -> *) a. Monad m => t (m a) -> m (t a))
-> Traversable t
forall (m :: * -> *) a.
Monad m =>
PreInline a (m a) -> m (PreInline a a)
forall (f :: * -> *) a.
Applicative f =>
PreInline a (f a) -> f (PreInline a a)
forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> PreInline a a -> m (PreInline a b)
forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> PreInline a a -> f (PreInline a b)
sequence :: PreInline a (m a) -> m (PreInline a a)
$csequence :: forall a (m :: * -> *) a.
Monad m =>
PreInline a (m a) -> m (PreInline a a)
mapM :: (a -> m b) -> PreInline a a -> m (PreInline a b)
$cmapM :: forall a (m :: * -> *) a b.
Monad m =>
(a -> m b) -> PreInline a a -> m (PreInline a b)
sequenceA :: PreInline a (f a) -> f (PreInline a a)
$csequenceA :: forall a (f :: * -> *) a.
Applicative f =>
PreInline a (f a) -> f (PreInline a a)
traverse :: (a -> f b) -> PreInline a a -> f (PreInline a b)
$ctraverse :: forall a (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> PreInline a a -> f (PreInline a b)
$cp2Traversable :: forall a. Foldable (PreInline a)
$cp1Traversable :: forall a. Functor (PreInline a)
Traversable, (forall x. PreInline a b -> Rep (PreInline a b) x)
-> (forall x. Rep (PreInline a b) x -> PreInline a b)
-> Generic (PreInline a b)
forall x. Rep (PreInline a b) x -> PreInline a b
forall x. PreInline a b -> Rep (PreInline a b) x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
forall a b x. Rep (PreInline a b) x -> PreInline a b
forall a b x. PreInline a b -> Rep (PreInline a b) x
$cto :: forall a b x. Rep (PreInline a b) x -> PreInline a b
$cfrom :: forall a b x. PreInline a b -> Rep (PreInline a b) x
Generic, (forall a. PreInline a a -> Rep1 (PreInline a) a)
-> (forall a. Rep1 (PreInline a) a -> PreInline a a)
-> Generic1 (PreInline a)
forall a. Rep1 (PreInline a) a -> PreInline a a
forall a. PreInline a a -> Rep1 (PreInline a) a
forall a a. Rep1 (PreInline a) a -> PreInline a a
forall a a. PreInline a a -> Rep1 (PreInline a) a
forall k (f :: k -> *).
(forall (a :: k). f a -> Rep1 f a)
-> (forall (a :: k). Rep1 f a -> f a) -> Generic1 f
$cto1 :: forall a a. Rep1 (PreInline a) a -> PreInline a a
$cfrom1 :: forall a a. PreInline a a -> Rep1 (PreInline a) a
Generic1)

-- booleans

type BoolExp a = PreInline CondOp a
type CondInfo a = Inline CondOp a

-- Conditional operators
data CondOp
    = TrueOp | FalseOp | And | Or
    | Equals | NotEquals | Less | Greater | LessEquals | GreaterEquals
    deriving (Int -> CondOp -> ShowS
[CondOp] -> ShowS
CondOp -> String
(Int -> CondOp -> ShowS)
-> (CondOp -> String) -> ([CondOp] -> ShowS) -> Show CondOp
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [CondOp] -> ShowS
$cshowList :: [CondOp] -> ShowS
show :: CondOp -> String
$cshow :: CondOp -> String
showsPrec :: Int -> CondOp -> ShowS
$cshowsPrec :: Int -> CondOp -> ShowS
Show, CondOp -> CondOp -> Bool
(CondOp -> CondOp -> Bool)
-> (CondOp -> CondOp -> Bool) -> Eq CondOp
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: CondOp -> CondOp -> Bool
$c/= :: CondOp -> CondOp -> Bool
== :: CondOp -> CondOp -> Bool
$c== :: CondOp -> CondOp -> Bool
Eq, Eq CondOp
Eq CondOp
-> (CondOp -> CondOp -> Ordering)
-> (CondOp -> CondOp -> Bool)
-> (CondOp -> CondOp -> Bool)
-> (CondOp -> CondOp -> Bool)
-> (CondOp -> CondOp -> Bool)
-> (CondOp -> CondOp -> CondOp)
-> (CondOp -> CondOp -> CondOp)
-> Ord CondOp
CondOp -> CondOp -> Bool
CondOp -> CondOp -> Ordering
CondOp -> CondOp -> CondOp
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
min :: CondOp -> CondOp -> CondOp
$cmin :: CondOp -> CondOp -> CondOp
max :: CondOp -> CondOp -> CondOp
$cmax :: CondOp -> CondOp -> CondOp
>= :: CondOp -> CondOp -> Bool
$c>= :: CondOp -> CondOp -> Bool
> :: CondOp -> CondOp -> Bool
$c> :: CondOp -> CondOp -> Bool
<= :: CondOp -> CondOp -> Bool
$c<= :: CondOp -> CondOp -> Bool
< :: CondOp -> CondOp -> Bool
$c< :: CondOp -> CondOp -> Bool
compare :: CondOp -> CondOp -> Ordering
$ccompare :: CondOp -> CondOp -> Ordering
$cp1Ord :: Eq CondOp
Ord, (forall x. CondOp -> Rep CondOp x)
-> (forall x. Rep CondOp x -> CondOp) -> Generic CondOp
forall x. Rep CondOp x -> CondOp
forall x. CondOp -> Rep CondOp x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep CondOp x -> CondOp
$cfrom :: forall x. CondOp -> Rep CondOp x
Generic)

isTrue, isFalse :: CondInfo a -> Bool

isTrue :: CondInfo a -> Bool
isTrue  = CondOp -> CondInfo a -> Bool
forall a. CondOp -> CondInfo a -> Bool
isCondOp CondOp
TrueOp
isFalse :: CondInfo a -> Bool
isFalse = CondOp -> CondInfo a -> Bool
forall a. CondOp -> CondInfo a -> Bool
isCondOp CondOp
FalseOp

isCondOp :: CondOp -> CondInfo a -> Bool
isCondOp :: CondOp -> CondInfo a -> Bool
isCondOp CondOp
op = Bool -> (CondOp -> Bool) -> Maybe CondOp -> Bool
forall b a. b -> (a -> b) -> Maybe a -> b
maybe Bool
False (CondOp
op CondOp -> CondOp -> Bool
forall a. Eq a => a -> a -> Bool
== ) (Maybe CondOp -> Bool)
-> (CondInfo a -> Maybe CondOp) -> CondInfo a -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. CondInfo a -> Maybe CondOp
forall a. CondInfo a -> Maybe CondOp
getCondInfoOp

getCondInfoOp :: CondInfo a -> Maybe CondOp
getCondInfoOp :: CondInfo a -> Maybe CondOp
getCondInfoOp CondInfo a
x = case CondInfo a -> InlineExp CondOp
forall a b. Inline a b -> InlineExp a
inlineExp CondInfo a
x of
    InlineExp CondOp
op [InlineExp CondOp]
_ -> CondOp -> Maybe CondOp
forall a. a -> Maybe a
Just CondOp
op
    InlineExp CondOp
_ -> Maybe CondOp
forall a. Maybe a
Nothing

-- Numeric expressions (or Csound infix operators)

type NumExp a = PreInline NumOp a

data NumOp = Add | Sub | Neg | Mul | Div | Pow | Mod
    deriving (Int -> NumOp -> ShowS
[NumOp] -> ShowS
NumOp -> String
(Int -> NumOp -> ShowS)
-> (NumOp -> String) -> ([NumOp] -> ShowS) -> Show NumOp
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [NumOp] -> ShowS
$cshowList :: [NumOp] -> ShowS
show :: NumOp -> String
$cshow :: NumOp -> String
showsPrec :: Int -> NumOp -> ShowS
$cshowsPrec :: Int -> NumOp -> ShowS
Show, NumOp -> NumOp -> Bool
(NumOp -> NumOp -> Bool) -> (NumOp -> NumOp -> Bool) -> Eq NumOp
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: NumOp -> NumOp -> Bool
$c/= :: NumOp -> NumOp -> Bool
== :: NumOp -> NumOp -> Bool
$c== :: NumOp -> NumOp -> Bool
Eq, Eq NumOp
Eq NumOp
-> (NumOp -> NumOp -> Ordering)
-> (NumOp -> NumOp -> Bool)
-> (NumOp -> NumOp -> Bool)
-> (NumOp -> NumOp -> Bool)
-> (NumOp -> NumOp -> Bool)
-> (NumOp -> NumOp -> NumOp)
-> (NumOp -> NumOp -> NumOp)
-> Ord NumOp
NumOp -> NumOp -> Bool
NumOp -> NumOp -> Ordering
NumOp -> NumOp -> NumOp
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
min :: NumOp -> NumOp -> NumOp
$cmin :: NumOp -> NumOp -> NumOp
max :: NumOp -> NumOp -> NumOp
$cmax :: NumOp -> NumOp -> NumOp
>= :: NumOp -> NumOp -> Bool
$c>= :: NumOp -> NumOp -> Bool
> :: NumOp -> NumOp -> Bool
$c> :: NumOp -> NumOp -> Bool
<= :: NumOp -> NumOp -> Bool
$c<= :: NumOp -> NumOp -> Bool
< :: NumOp -> NumOp -> Bool
$c< :: NumOp -> NumOp -> Bool
compare :: NumOp -> NumOp -> Ordering
$ccompare :: NumOp -> NumOp -> Ordering
$cp1Ord :: Eq NumOp
Ord, (forall x. NumOp -> Rep NumOp x)
-> (forall x. Rep NumOp x -> NumOp) -> Generic NumOp
forall x. Rep NumOp x -> NumOp
forall x. NumOp -> Rep NumOp x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep NumOp x -> NumOp
$cfrom :: forall x. NumOp -> Rep NumOp x
Generic)

-------------------------------------------------------
-- instances for cse that ghc was not able to derive for me

instance Foldable PrimOr where foldMap :: (a -> m) -> PrimOr a -> m
foldMap = (a -> m) -> PrimOr a -> m
forall (t :: * -> *) m a.
(Traversable t, Monoid m) =>
(a -> m) -> t a -> m
foldMapDefault

instance Traversable PrimOr where
    traverse :: (a -> f b) -> PrimOr a -> f (PrimOr b)
traverse a -> f b
f PrimOr a
x = case PrimOr a -> Either Prim a
forall a. PrimOr a -> Either Prim a
unPrimOr PrimOr a
x of
        Left  Prim
p -> PrimOr b -> f (PrimOr b)
forall (f :: * -> *) a. Applicative f => a -> f a
pure (PrimOr b -> f (PrimOr b)) -> PrimOr b -> f (PrimOr b)
forall a b. (a -> b) -> a -> b
$ Either Prim b -> PrimOr b
forall a. Either Prim a -> PrimOr a
PrimOr (Either Prim b -> PrimOr b) -> Either Prim b -> PrimOr b
forall a b. (a -> b) -> a -> b
$ Prim -> Either Prim b
forall a b. a -> Either a b
Left Prim
p
        Right a
a -> Either Prim b -> PrimOr b
forall a. Either Prim a -> PrimOr a
PrimOr (Either Prim b -> PrimOr b)
-> (b -> Either Prim b) -> b -> PrimOr b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. b -> Either Prim b
forall a b. b -> Either a b
Right (b -> PrimOr b) -> f b -> f (PrimOr b)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> a -> f b
f a
a

----------------------------------------------------------

-- | Multiple output. Specify the number of outputs to get the result.
type MultiOut a = Int -> a


------------------------------------------------------
-- hashable instances

instance (Hashable a, Hashable b) => Hashable (PreInline a b)
instance (Hashable a) => Hashable (InlineExp a)
instance Hashable CondOp
instance Hashable NumOp

instance Hashable Gen
instance Hashable GenId
instance Hashable Prim
instance Hashable Rate

instance Hashable OpcFixity
instance Hashable Info
instance Hashable VarType
instance Hashable Var

instance Hashable a => Hashable (MainExp a)
instance Hashable a => Hashable (PrimOr a)
instance Hashable a => Hashable (RatedExp a)
instance Hashable InstrId

deriving instance Generic1 IM.IntMap
instance Hashable1 IM.IntMap
instance Hashable a => Hashable1 (PreInline a)
instance Hashable a => Hashable1 (Inline a)
instance Hashable1 RatedExp
instance Hashable1 MainExp
instance Hashable1 PrimOr

$(deriveEq1 ''PrimOr)
$(deriveEq1 ''PreInline)
$(deriveEq1 ''Inline)
$(deriveEq1 ''MainExp)
$(deriveEq1 ''RatedExp)

$(deriveOrd1 ''PrimOr)
$(deriveOrd1 ''PreInline)
$(deriveOrd1 ''Inline)
$(deriveOrd1 ''MainExp)
$(deriveOrd1 ''RatedExp)

$(deriveShow1 ''PrimOr)
$(deriveShow1 ''PreInline)
$(deriveShow1 ''Inline)
$(deriveShow1 ''MainExp)
$(deriveShow1 ''RatedExp)

--------------------------------------------------------------
-- comments
--
-- p-string
--
--    separate p-param for strings (we need it to read strings from global table)
--    Csound doesn't permits us to use more than four string params so we need to
--    keep strings in the global table and use `strget` to read them