• Top
    • Documentation
    • Books
    • Boolean-reasoning
    • Projects
    • Debugging
    • Std
    • Proof-automation
    • Macro-libraries
    • ACL2
    • Interfacing-tools
    • Hardware-verification
    • Software-verification
      • Kestrel-books
        • Crypto-hdwallet
        • Apt
        • Error-checking
        • Fty-extensions
        • Isar
        • Kestrel-utilities
        • Set
        • Soft
        • C
          • Syntax-for-tools
          • Atc
          • Language
            • Abstract-syntax
            • Integer-ranges
            • Implementation-environments
            • Dynamic-semantics
              • Exec
              • Exec-arrsub
              • Exec-expr-pure
              • Exec-expr-asg
              • Init-value-to-value
              • Exec-memberp
              • Apconvert-expr-value
              • Exec-address
              • Exec-member
              • Init-scope
              • Exec-unary
              • Exec-fun
              • Exec-block-item
              • Eval-iconst
              • Exec-binary-strict-pure
              • Exec-expr-pure-list
              • Eval-binary-strict-pure
              • Exec-block-item-list
              • Exec-indir
              • Exec-expr-call-or-pure
              • Exec-stmt-while
              • Exec-stmt
              • Exec-ident
              • Eval-cast
                • Exec-cast
                • Eval-unary
                • Exec-const
                • Exec-initer
                • Exec-expr-call-or-asg
                • Eval-const
                • Exec-expr-call
              • Static-semantics
              • Grammar
              • Integer-formats
              • 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
          • Bv
          • Imp-language
          • Event-macros
          • Java
          • Bitcoin
          • Ethereum
          • Yul
          • Zcash
          • ACL2-programming-language
          • Prime-fields
          • Json
          • Syntheto
          • File-io-light
          • Cryptography
          • Number-theory
          • Lists-light
          • Axe
          • Builtins
          • Solidity
          • Helpers
          • Htclient
          • Typed-lists-light
          • Arithmetic-light
        • X86isa
        • Axe
        • Execloader
      • Math
      • Testing-utilities
    • Dynamic-semantics

    Eval-cast

    Evaluate a type cast on a value.

    Signature
    (eval-cast tyname arg) → val
    Arguments
    tyname — Guard (tynamep tyname).
    arg — Guard (valuep arg).
    Returns
    val — Type (value-resultp val).

    For now we only support casts between integer types. None involving pointers.

    We reject casts to void, because a scalar type is required [C17:6.5.4/2].

    Definitions and Theorems

    Function: eval-cast

    (defun eval-cast (tyname arg)
      (declare (xargs :guard (and (tynamep tyname) (valuep arg))))
      (let ((__function__ 'eval-cast))
        (declare (ignorable __function__))
        (b* ((type (tyname-to-type tyname))
             ((unless (type-nonchar-integerp type))
              (error (list :cast-not-supported :to type)))
             ((unless (value-integerp arg))
              (error (list :cast-not-supported
                           :from (value-fix arg))))
             (err (error (list :cast-undefined
                               :from (value-fix arg)
                               :to type)))
             (val (convert-integer-value arg type))
             ((when (errorp val)) err))
          val)))

    Theorem: value-resultp-of-eval-cast

    (defthm value-resultp-of-eval-cast
      (b* ((val (eval-cast tyname arg)))
        (value-resultp val))
      :rule-classes :rewrite)

    Theorem: eval-cast-of-tyname-fix-tyname

    (defthm eval-cast-of-tyname-fix-tyname
      (equal (eval-cast (tyname-fix tyname) arg)
             (eval-cast tyname arg)))

    Theorem: eval-cast-tyname-equiv-congruence-on-tyname

    (defthm eval-cast-tyname-equiv-congruence-on-tyname
      (implies (tyname-equiv tyname tyname-equiv)
               (equal (eval-cast tyname arg)
                      (eval-cast tyname-equiv arg)))
      :rule-classes :congruence)

    Theorem: eval-cast-of-value-fix-arg

    (defthm eval-cast-of-value-fix-arg
      (equal (eval-cast tyname (value-fix arg))
             (eval-cast tyname arg)))

    Theorem: eval-cast-value-equiv-congruence-on-arg

    (defthm eval-cast-value-equiv-congruence-on-arg
      (implies (value-equiv arg arg-equiv)
               (equal (eval-cast tyname arg)
                      (eval-cast tyname arg-equiv)))
      :rule-classes :congruence)