@@ -27,6 +27,7 @@ import Control.Monad.Trans.Error (Error(..))
27import Debug.Trace
27import Debug.Trace
28import qualified Data.Map.Strict as Map
28import qualified Data.Map.Strict as Map
29import Data.Char
29import Data.Char
30+import Numeric (showIntAtBase)
30import qualified Data.Text as T
31import qualified Data.Text as T
31import Data.List
32import Data.List
32import Data.Maybe (listToMaybe)
33import Data.Maybe (listToMaybe)
@@ -542,6 +543,43 @@ constIsType (B32V _) = False
542constIsType (B64V _) = False
543constIsType (B64V _) = False
543constIsType _ = True
544constIsType _ = True
546+-- | Get the docstring for a Const
547+constDocs :: Const -> String
548+constDocs c@(AType (ATInt ITBig)) = "Arbitrary-precision integers"
549+constDocs c@(AType (ATInt ITNative)) = "Fixed-precision integers of undefined size"
550+constDocs c@(AType (ATInt ITChar)) = "Characters in some unspecified encoding"
551+constDocs c@(AType ATFloat) = "Double-precision floating-point numbers"
552+constDocs StrType = "Strings in some unspecified encoding"
553+constDocs PtrType = "Foreign pointers"
554+constDocs ManagedPtrType = "Managed pointers"
555+constDocs BufferType = "Copy-on-write buffers"
556+constDocs c@(AType (ATInt (ITFixed IT8))) = "Eight bits (unsigned)"
557+constDocs c@(AType (ATInt (ITFixed IT16))) = "Sixteen bits (unsigned)"
558+constDocs c@(AType (ATInt (ITFixed IT32))) = "Thirty-two bits (unsigned)"
559+constDocs c@(AType (ATInt (ITFixed IT64))) = "Sixty-four bits (unsigned)"
560+constDocs c@(AType (ATInt (ITVec IT8 16))) = "Vectors of sixteen eight-bit values"
561+constDocs c@(AType (ATInt (ITVec IT16 8))) = "Vectors of eight sixteen-bit values"
562+constDocs c@(AType (ATInt (ITVec IT32 4))) = "Vectors of four thirty-two-bit values"
563+constDocs c@(AType (ATInt (ITVec IT64 2))) = "Vectors of two sixty-four-bit values"
564+constDocs (Fl f) = "A float"
565+constDocs (I i) = "A fixed-precision integer"
566+constDocs (BI i) = "An arbitrary-precision integer"
567+constDocs (Str s) = "A string of length " ++ show (length s)
568+constDocs (Ch c) = "A character"
569+constDocs (B8 w) = "The eight-bit value 0x" ++
570+ showIntAtBase 16 intToDigit w ""
571+constDocs (B16 w) = "The sixteen-bit value 0x" ++
572+ showIntAtBase 16 intToDigit w ""
573+constDocs (B32 w) = "The thirty-two-bit value 0x" ++
574+ showIntAtBase 16 intToDigit w ""
575+constDocs (B64 w) = "The sixty-four-bit value 0x" ++
576+ showIntAtBase 16 intToDigit w ""
577+constDocs (B8V v) = "A vector of eight-bit values"
578+constDocs (B16V v) = "A vector of sixteen-bit values"
579+constDocs (B32V v) = "A vector of thirty-two-bit values"
580+constDocs (B64V v) = "A vector of sixty-four-bit values"
581+constDocs prim = "Undocumented"
545data Raw = Var Name
583data Raw = Var Name
546 | RBind Name (Binder Raw) Raw
584 | RBind Name (Binder Raw) Raw
547 | RApp Raw Raw
585 | RApp Raw Raw