prlg/app/IR.hs
2022-11-12 17:47:51 +01:00

34 lines
611 B
Haskell

module IR where
import qualified Data.Map as M
data PrlgStr
= CallS String [PrlgStr]
| LiteralS String
deriving (Show)
data Id =
Id
{ str :: Int
, arity :: Int
}
deriving (Show, Eq, Ord)
data PrlgInt
= CallI Id [PrlgInt]
| LiteralI Int
| VarI Int Int
| VoidI
deriving (Show)
data StrTable =
StrTable Int (M.Map String Int) (M.Map Int String)
deriving (Show)
emptystrtable = StrTable 0 M.empty M.empty
strtablize t@(StrTable nxt fwd rev) str =
case fwd M.!? str of
Just i -> (t, i)
_ -> (StrTable (nxt + 1) (M.insert str nxt fwd) (M.insert nxt str rev), nxt)