Add machine words and instructions

This commit is contained in:
Joscha 2019-11-05 21:13:51 +00:00
parent 3c53c65313
commit c29f41db06
4 changed files with 167 additions and 0 deletions

23
src/Mima/Util.hs Normal file
View file

@ -0,0 +1,23 @@
module Mima.Util
( ToText(..)
, toHex
) where
import qualified Data.Text as T
import qualified Numeric as N
-- | A class for types that can be converted to 'T.Text'.
--
-- This class does not mean to convert elements to text in a
-- standardized way. It is just to reduce the clutter of functions
-- with names like @somethingToText@.
--
-- Only create an instance of this class when there is an obvious,
-- preferrable way of converting something to text! If there are
-- multiple "obvious" options, create no instance of this class and
-- instead name the functions individually.
class ToText a where
toText :: a -> T.Text
toHex :: (Integral a, Show a) => Int -> a -> T.Text
toHex digits a = T.justifyRight digits '0' $ T.pack $ N.showHex a ""