• Top
    • Documentation
    • Books
    • Boolean-reasoning
    • Projects
      • Apt
      • Zfc
      • Acre
      • Milawa
      • Smtlink
      • Abnf
      • Vwsim
      • Isar
      • Wp-gen
      • Dimacs-reader
      • Pfcs
      • Legacy-defrstobj
      • Proof-checker-array
      • Soft
      • C
        • Syntax-for-tools
        • Atc
        • Language
          • Abstract-syntax
          • Integer-ranges
          • Implementation-environments
          • Dynamic-semantics
          • Static-semantics
          • Grammar
          • Integer-formats
            • Short-bits
            • Long-bits
            • Int-bits
            • Def-integer-bits-linear-rule
            • Llong-bits
            • Def-integer-bits
              • Char-bits
            • Types
            • Portable-ascii-identifiers
            • Values
            • Integer-operations
            • Computation-states
            • Object-designators
            • Operations
            • Errors
            • Tag-environments
            • Function-environments
            • Character-sets
            • Flexible-array-member-removal
            • Arithmetic-operations
            • Pointer-operations
            • Bytes
            • Keywords
            • Real-operations
            • Array-operations
            • Scalar-operations
            • Structure-operations
          • Representation
          • Transformation-tools
          • Insertion-sort
          • Pack
        • Farray
        • Rp-rewriter
        • Instant-runoff-voting
        • Imp-language
        • Sidekick
        • Leftist-trees
        • Java
        • Taspi
        • Bitcoin
        • Riscv
        • Des
        • Ethereum
        • X86isa
        • Sha-2
        • Yul
        • Zcash
        • Proof-checker-itp13
        • Regex
        • ACL2-programming-language
        • Json
        • Jfkr
        • Equational
        • Cryptography
        • Poseidon
        • Where-do-i-place-my-book
        • Axe
        • Bigmems
        • Builtins
        • Execloader
        • Aleo
        • Solidity
        • Paco
        • Concurrent-programs
        • Bls12-377-curves
      • Debugging
      • Std
      • Proof-automation
      • Macro-libraries
      • ACL2
      • Interfacing-tools
      • Hardware-verification
      • Software-verification
      • Math
      • Testing-utilities
    • Integer-formats

    Def-integer-bits

    Macro to generate the nullary functions, and some theorems about them, for the size in bits of the C integer types.

    Macro: def-integer-bits

    (defmacro def-integer-bits (type bits minbits)
     (declare
        (xargs :guard (and (member-eq type '(char short int long llong))
                           (posp bits)
                           (posp minbits)
                           (>= bits minbits))))
     (b* ((type-bits (pack type '-bits))
          (type-bits-bound (pack type-bits '-bound))
          (type-bits-multiple-of-char-bits
               (pack type '-bits-multiple-of-char-bits))
          (short-substring (if (eq type 'char)
                               "signed, unsigned, and plain"
                             "signed and unsigned")))
      (cons
       'define
       (cons
        type-bits
        (cons
         'nil
         (cons
          ':returns
          (cons
           (cons type-bits
                 '(posp :rule-classes :type-prescription))
           (cons
            ':short
            (cons
             (str::cat "Size of " short-substring " @('"
                       (str::downcase-string (symbol-name type))
                       "') values, in bits.")
             (cons
              bits
              (cons
               '///
               (append
                (and
                 (not (eq type 'char))
                 (cons
                  (cons
                   'defrule
                   (cons
                     type-bits-multiple-of-char-bits
                     (cons (cons 'integerp
                                 (cons (cons '/
                                             (cons (cons type-bits 'nil)
                                                   '((char-bits))))
                                       'nil))
                           '(:rule-classes :type-prescription
                                           :enable char-bits))))
                  'nil))
                (cons
                 (cons
                      'in-theory
                      (cons (cons 'disable
                                  (cons (cons ':e (cons type-bits 'nil))
                                        'nil))
                            'nil))
                 (cons
                  (cons
                   'defret
                   (cons
                       type-bits-bound
                       (cons (cons '>=
                                   (cons type-bits (cons minbits 'nil)))
                             '(:rule-classes :linear))))
                  'nil))))))))))))))