module E2ASM.Assembler.Register
( Position(..)
, Extension(..)
, Register
, mkRegister
, r0
) where


import qualified Data.Word as W


data Position
  = Whole
  | Higher
  | Lower
  | Byte
  deriving (Eq, Show)

data Extension
  = Zero
  | Sign
  deriving (Eq, Show)


data Register
  = Register W.Word8 Position Extension
  deriving (Eq, Show)


maxRegister :: Integral n => n
maxRegister = 32


mkRegister :: Integral n => n -> Position -> Extension -> Maybe Register
mkRegister n p e =
  if n < maxRegister then
    Just $ Register (fromIntegral n) p e
  else
    Nothing


r0 :: Register
r0 = Register 0 Whole Zero
