• Top
    • Documentation
    • Books
    • Boolean-reasoning
    • Projects
    • Debugging
    • Std
    • Community
    • Proof-automation
    • ACL2
    • Macro-libraries
    • 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
            • Atc-implementation
              • Atc-abstract-syntax
              • Atc-pretty-printer
              • Atc-event-and-code-generation
              • Fty-pseudo-term-utilities
              • Atc-term-recognizers
              • Atc-input-processing
              • Atc-shallow-embedding
                • Defstruct
                • Defobject
                  • Defobject-implementation
                    • Defobject-info
                    • Defobject-gen-everything
                    • Defobject-process-name
                    • Defobject-info-option
                    • Defobject-term-to-expr
                      • Term-checkers-common
                      • Defobject-process-init
                      • Defobject-process-init-term
                      • Defobject-table-record-event
                      • Defobject-process-type
                      • Defobject-process-inputs
                      • Defobject-table-lookup
                      • Defobject-process-init-terms
                      • Defobject-process-inputs-and-gen-everything
                      • Defobject-fn
                      • Defobject-table-definition
                      • *defobject-table*
                      • Defobject-macro-definition
                  • Atc-let-designations
                  • Pointer-types
                  • Atc-conditional-expressions
                • Atc-process-inputs-and-gen-everything
                • Atc-table
                • Atc-fn
                • Atc-pretty-printing-options
                • Atc-types
                • Atc-macro-definition
              • Atc-tutorial
            • Language
            • 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
    • Defobject-implementation

    Defobject-term-to-expr

    Turn a constant expression term into the represented expression.

    Signature
    (defobject-term-to-expr term) → (mv erp expr type)
    Arguments
    term — Guard (pseudo-termp term).
    Returns
    expr — Type (exprp expr).
    type — Type (typep type).

    If the term is not a constant expression term, stop with an error. If it is, also return the type of the expression.

    In essence, this generates C code for a term used in the initializer of the external object.

    Definitions and Theorems

    Function: defobject-term-to-expr

    (defun defobject-term-to-expr (term)
     (declare (xargs :guard (pseudo-termp term)))
     (let ((__function__ 'defobject-term-to-expr))
      (declare (ignorable __function__))
      (b*
       (((reterr) (irr-expr) (irr-type))
        ((erp okp & out-type const)
         (atc-check-iconst term))
        ((when okp)
         (retok (expr-const (const-int const))
                out-type))
        ((erp okp & arg in-type out-type op)
         (atc-check-unop term))
        ((when okp)
         (b*
          (((erp arg-expr type)
            (defobject-term-to-expr arg))
           ((unless (equal type in-type))
            (reterr
             (msg
              "The unary operator ~x0 ~
                                is applied to a term ~x1 returning ~x2, ~
                                but a ~x3 operand is expected."
              op arg type in-type))))
          (retok (make-expr-unary :op op :arg arg-expr)
                 out-type)))
        ((erp okp &
              arg1 arg2 in-type1 in-type2 out-type op)
         (atc-check-binop term))
        ((when okp)
         (b*
          (((erp arg1-expr type1)
            (defobject-term-to-expr arg1))
           ((erp arg2-expr type2)
            (defobject-term-to-expr arg2))
           ((unless (and (equal type1 in-type1)
                         (equal type2 in-type2)))
            (reterr
             (msg
              "The binary operator ~x0 ~
                                is applied to a term ~x1 returning ~x2
                                and to a term ~x3 returning ~x4,
                                but a ~x5 and a ~x6 operand is expected."
              op arg1
              type1 arg2 type2 in-type1 in-type2))))
          (retok (make-expr-binary :op op
                                   :arg1 arg1-expr
                                   :arg2 arg2-expr)
                 out-type)))
        ((erp okp & arg in-type out-type tyname)
         (atc-check-conv term))
        ((when okp)
         (b*
          (((erp arg-expr type)
            (defobject-term-to-expr arg))
           ((unless (equal type in-type))
            (reterr
             (msg
              "The conversion from ~x0 to ~x1 ~
                                is applied to a term ~x2 returning ~x3, ~
                                but a ~x0 operand is expected."
              in-type out-type arg type))))
          (retok (make-expr-cast :type tyname
                                 :arg arg-expr)
                 out-type))))
       (reterr
        (msg
         "The term ~x0 used as an array element initializer ~
                      does not have the required form."
         term)))))

    Theorem: exprp-of-defobject-term-to-expr.expr

    (defthm exprp-of-defobject-term-to-expr.expr
      (b* (((mv acl2::?erp ?expr ?type)
            (defobject-term-to-expr term)))
        (exprp expr))
      :rule-classes :rewrite)

    Theorem: typep-of-defobject-term-to-expr.type

    (defthm typep-of-defobject-term-to-expr.type
      (b* (((mv acl2::?erp ?expr ?type)
            (defobject-term-to-expr term)))
        (typep type))
      :rule-classes :rewrite)