• Top
    • Documentation
    • Books
    • Boolean-reasoning
    • Projects
    • Debugging
    • Community
    • 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
        • C
        • Soft
        • Bv
        • Imp-language
        • Ethereum
        • Event-macros
        • Java
          • Atj
            • Atj-implementation
              • Atj-types
              • Atj-java-primitive-array-model
              • Atj-java-abstract-syntax
              • Atj-input-processing
              • Atj-java-pretty-printer
              • Atj-code-generation
                • Atj-gen-test-method
                • Atj-shallow-code-generation
                  • Atj-gen-shallow-term-fns
                  • String-jmethodlist-alistp
                  • Atj-gen-shallow-fndef-method
                  • String-jfieldlist-alistp
                  • Atj-gen-shallow-test-code
                  • Atj-adapt-expr-to-type
                  • Atj-gen-shallow-fn-call
                  • Atj-check-marked-annotated-mv-let-call
                  • Atj-gen-shallow-main-class
                  • Atj-gen-shallow-fnnative-method
                  • Atj-gen-shallow-synonym-method
                  • Atj-gen-shallow-if-call
                    • Atj-gen-shallow-and-call
                    • Atj-gen-shallow-pkg-methods
                    • Atj-convert-expr-to-jprim
                    • Atj-gen-shallow-or-call
                    • Atj-convert-expr-from-jprimarr-method
                    • Atj-adapt-expr-to-types
                    • Atj-gen-shallow-all-pkg-methods
                    • Atj-convert-expr-to-jprimarr-method
                    • Atj-gen-shallow-fndef-all-methods
                    • Atj-convert-expr-from-jprim
                    • Atj-gen-shallow-mv-class
                    • Atj-gen-shallow-main-cunit
                    • Atj-gen-shallow-fndef-methods
                    • Atj-gen-shallow-mv-class-name
                    • Atj-shallow-fns-that-may-throw
                    • Atj-gen-shallow-term
                    • Atj-gen-shallow-let-bindings
                    • Atj-gen-shallow-fn-methods
                    • Atj-gen-shallow-jprimarr-new-init-call
                    • Atj-gen-shallow-fnname
                    • Atj-gen-shallow-all-fn-methods
                    • Atj-gen-shallow-not-call
                    • Atj-fnnative-method-name
                    • Atj-gen-shallow-mv-let
                    • Atj-gen-shallow-jprim-constr-call
                    • Atj-gen-shallow-jprimarr-write-call
                    • Atj-gen-shallow-fnnative-all-methods
                    • Atj-gen-shallow-pkg-class
                    • Atj-gen-shallow-jprimarr-length-call
                    • Atj-gen-shallow-pkg-fields
                    • Atj-all-mv-output-types
                    • Atj-gen-shallow-mv-call
                    • Atj-gen-shallow-jprim-binop-call
                    • Atj-gen-shallow-jprim-conv-call
                    • Atj-gen-shallow-primarray-write-method
                    • Atj-gen-shallow-mv-fields
                    • Atj-gen-shallow-jprimarr-read-call
                    • Atj-gen-shallow-jprimarr-new-len-call
                    • Atj-gen-shallow-jprimarr-conv-tolist-call
                    • Atj-gen-shallow-jprimarr-conv-fromlist-call
                    • Atj-gen-shallow-synonym-all-methods
                    • Atj-gen-shallow-jprim-deconstr-call
                    • Atj-gen-shallow-all-pkg-fields
                    • Atj-gen-shallow-test-code-asgs
                    • Atj-gen-shallow-lambda
                    • Atj-gen-shallow-jprim-unop-call
                    • Atj-jprim-binop-fn-to-jbinop
                    • Atj-gen-shallow-mv-asgs
                    • Atj-gen-shallow-env-class
                    • Atj-gen-shallow-mv-params
                    • Atj-gen-shallow-fnnative-methods
                    • Atj-gen-shallow-pkg-classes
                    • Atj-gen-shallow-env-cunit
                    • Atj-gen-shallow-all-synonym-methods
                    • Atj-convert-expr-to-jprimarr
                    • Atj-convert-expr-from-jprimarr
                    • Atj-jprim-constr-fn-of-qconst-to-expr
                    • Atj-gen-shallow-test-code-mv-asgs
                    • Atj-gen-shallow-synonym-methods
                    • Atj-gen-shallow-synonym-method-params
                    • Atj-convert-expr-to-jprimarr-method-name
                    • Atj-convert-expr-from-jprimarr-method-name
                    • Atj-jexpr-list-to-3-jexprs
                    • Atj-jblock-list-to-3-jblocks
                    • Atj-gen-shallow-test-code-comps
                    • Atj-jprim-conv-fn-to-jtype
                    • Atj-gen-shallow-terms
                    • Atj-gen-shallow-mv-field-name
                    • Atj-adapt-exprs-to-types
                    • Atj-jblock-list-to-2-jblocks
                    • Atj-gen-shallow-primarray-write-methods
                    • Atj-gen-shallow-mv-classes
                    • Atj-gen-shallow-jtype
                    • Atj-gen-shallow-build-method
                    • Atj-jexpr-list-to-2-jexprs
                    • Atj-jprimarr-write-to-method-name
                    • Atj-gen-shallow-all-jprimarr-conv-methods
                    • Atj-jprimarr-new-len-fn-to-comp-jtype
                    • Atj-jprimarr-new-init-fn-to-comp-jtype
                    • Atj-jprim-unop-fn-to-junop
                    • *atj-gen-cond-exprs*
                    • Atj-primarray-write-method-name
                    • Atj-gen-shallow-jprimarr-fromlist-methods
                    • Atj-gen-shallow-jprimarr-tolist-methods
                    • Atj-gen-shallow-mv-classes-guard
                    • *atj-mv-singleton-field-name*
                    • *atj-mv-factory-method-name*
                  • Atj-common-code-generation
                  • Atj-shallow-quoted-constant-generation
                  • Atj-pre-translation
                  • Atj-gen-everything
                  • Atj-name-translation
                  • Atj-gen-test-cunit
                  • Atj-gen-test-class
                  • Atj-gen-main-file
                  • Atj-post-translation
                  • Atj-deep-code-generation
                  • Atj-gen-test-methods
                  • Atj-gen-test-file
                  • Atj-gen-env-file
                  • Atj-gen-output-subdir
                • Atj-java-primitives
                • Atj-java-primitive-arrays
                • Atj-type-macros
                • Atj-java-syntax-operations
                • Atj-fn
                • Atj-library-extensions
                • Atj-java-input-types
                • Atj-test-structures
                • Aij-notions
                • Atj-macro-definition
              • Atj-tutorial
            • Aij
            • Language
          • Riscv
          • Bitcoin
          • Zcash
          • Yul
          • ACL2-programming-language
          • Prime-fields
          • Json
          • Syntheto
          • File-io-light
          • Cryptography
          • Number-theory
          • Axe
          • Lists-light
          • Builtins
          • Solidity
          • Helpers
          • Htclient
          • Typed-lists-light
          • Arithmetic-light
        • X86isa
        • Axe
        • Execloader
      • Math
      • Testing-utilities
    • Atj-shallow-code-generation

    Atj-gen-shallow-if-call

    Generate a shallowly embedded ACL2 if call.

    Signature
    (atj-gen-shallow-if-call test-block then-block else-block 
                             test-expr then-expr else-expr test-term 
                             types jvar-tmp-base jvar-tmp-index) 
     
      → 
    (mv block expr new-jvar-tmp-index)
    Arguments
    test-block — Guard (jblockp test-block).
    then-block — Guard (jblockp then-block).
    else-block — Guard (jblockp else-block).
    test-expr — Guard (jexprp test-expr).
    then-expr — Guard (jexprp then-expr).
    else-expr — Guard (jexprp else-expr).
    test-term — Guard (pseudo-termp test-term).
    types — Guard (atj-type-listp types).
    jvar-tmp-base — Guard (stringp jvar-tmp-base).
    jvar-tmp-index — Guard (posp jvar-tmp-index).
    Returns
    block — Type (jblockp block).
    expr — Type (jexprp expr).
    new-jvar-tmp-index — Type (posp new-jvar-tmp-index), given (posp jvar-tmp-index).

    This is called after translating the arguments of if to Java. The resulting blocks and expressions are passed as parameters here, along with the original ACL2 term that is the if test.

    If the test has type :aboolean, which may only happen if :guards is t, in which case ACL2 booleans are mapped to Java booleans, we return the resulting expression. If instead the test has a different type, which must be an :acl2 type, we convert the resulting expression to a Java boolean by comparing it with nil for inequality.

    Consider a call (if test then else). If the Java code generated for test consists of the block <test-block> and expression <test-expr>, and similarly for then and else, we generate the Java block

    <test-block>
    <type> <tmp>;
    if (<test>) {
        <then-block>
        <tmp> = <then-expr>;
    } else {
        <else-block>
        <tmp> = <else-expr>;
    }

    and the Java expression <tmp>, where <test> is <test-expr> if <test-expr> is boolean or <test-expr> != NIL otherwise, and where <tmp> consists of the base name in the parameter jvar-tmp-base followed by the numeric index in the parameter jvar-tmp-index.

    In other words, we first compute the test and create a local variable to store the final result. Based on the test, we execute either branch (for non-strictness), storing the result into the variable.

    The type <type> of the result variable is derived from the ATJ types passed as parameters. See atj-gen-shallow-fn-call for details.

    If the flag *atj-gen-cond-exprs* is set, and if both <then-block> and <else-block> are empty, we generate the Java block

    <test-block>

    and the Java expression

    <test> ? <then-expr> : <else-expr>

    Definitions and Theorems

    Function: atj-gen-shallow-if-call

    (defun atj-gen-shallow-if-call
           (test-block then-block else-block
                       test-expr then-expr else-expr test-term
                       types jvar-tmp-base jvar-tmp-index)
     (declare (xargs :guard (and (jblockp test-block)
                                 (jblockp then-block)
                                 (jblockp else-block)
                                 (jexprp test-expr)
                                 (jexprp then-expr)
                                 (jexprp else-expr)
                                 (pseudo-termp test-term)
                                 (atj-type-listp types)
                                 (stringp jvar-tmp-base)
                                 (posp jvar-tmp-index))))
     (declare (xargs :guard (consp types)))
     (let ((__function__ 'atj-gen-shallow-if-call))
      (declare (ignorable __function__))
      (b*
       (((mv & & test-types)
         (atj-type-unwrap-term test-term))
        (test-expr
             (if (equal test-types
                        (list (atj-type-acl2 (atj-atype-boolean))))
                 test-expr
               (jexpr-binary (jbinop-ne)
                             test-expr (atj-gen-symbol nil t nil))))
        ((when (and *atj-gen-cond-exprs* (null then-block)
                    (null else-block)))
         (b* ((block (jblock-fix test-block))
              (expr (jexpr-cond test-expr then-expr else-expr)))
           (mv block expr jvar-tmp-index)))
        (jtype (atj-gen-shallow-jtype types))
        ((mv result-locvar-block
             jvar-tmp jvar-tmp-index)
         (atj-gen-jlocvar-indexed
              jtype jvar-tmp-base jvar-tmp-index nil))
        (if-block
          (jblock-ifelse test-expr
                         (append then-block
                                 (jblock-asg-name jvar-tmp then-expr))
                         (append else-block
                                 (jblock-asg-name jvar-tmp else-expr))))
        (block (append (jblock-fix test-block)
                       result-locvar-block if-block))
        (expr (jexpr-name jvar-tmp)))
       (mv block expr jvar-tmp-index))))

    Theorem: jblockp-of-atj-gen-shallow-if-call.block

    (defthm jblockp-of-atj-gen-shallow-if-call.block
     (b*
      (((mv common-lisp::?block
            ?expr ?new-jvar-tmp-index)
        (atj-gen-shallow-if-call test-block then-block else-block
                                 test-expr then-expr else-expr test-term
                                 types jvar-tmp-base jvar-tmp-index)))
      (jblockp block))
     :rule-classes :rewrite)

    Theorem: jexprp-of-atj-gen-shallow-if-call.expr

    (defthm jexprp-of-atj-gen-shallow-if-call.expr
     (b*
      (((mv common-lisp::?block
            ?expr ?new-jvar-tmp-index)
        (atj-gen-shallow-if-call test-block then-block else-block
                                 test-expr then-expr else-expr test-term
                                 types jvar-tmp-base jvar-tmp-index)))
      (jexprp expr))
     :rule-classes :rewrite)

    Theorem: posp-of-atj-gen-shallow-if-call.new-jvar-tmp-index

    (defthm posp-of-atj-gen-shallow-if-call.new-jvar-tmp-index
      (implies (posp jvar-tmp-index)
               (b* (((mv common-lisp::?block
                         ?expr ?new-jvar-tmp-index)
                     (atj-gen-shallow-if-call
                          test-block then-block else-block
                          test-expr then-expr else-expr test-term
                          types jvar-tmp-base jvar-tmp-index)))
                 (posp new-jvar-tmp-index)))
      :rule-classes :rewrite)