• 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
        • Bv
        • Imp-language
        • 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
          • 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
    • Atj-shallow-code-generation

    Atj-gen-shallow-main-class

    Generate the main (i.e. non-test) Java class declaration, in the shallow embedding approach.

    Signature
    (atj-gen-shallow-main-class pkgs fns-to-translate call-graph guards$ 
                                no-aij-types$ java-class$ verbose$ wrld) 
     
      → 
    (mv class pkg-class-names fn-method-names)
    Arguments
    pkgs — Guard (string-listp pkgs).
    fns-to-translate — Guard (symbol-listp fns-to-translate).
    call-graph — Guard (symbol-symbollist-alistp call-graph).
    guards$ — Guard (booleanp guards$).
    no-aij-types$ — Guard (booleanp no-aij-types$).
    java-class$ — Guard (stringp java-class$).
    verbose$ — Guard (booleanp verbose$).
    wrld — Guard (plist-worldp wrld).
    Returns
    class — Type (jclassp class).
    pkg-class-names — Type (string-string-alistp pkg-class-names), given (string-listp pkgs).
    fn-method-names — Type (symbol-string-alistp fn-method-names), given (symbol-listp fns-to-translate).

    This is a public class. [JLS14:7.6] says that a Java implementation may require public classes to be in files with the same names (plus extension). The code that we generate satisfies this requirement.

    The class contains the static initializer, the initialization method, the classes that contain methods for the ACL2 functions, the mv classes, and the fields for quoted constants, and the methods to convert between lists and primitive arrays.

    It is critical that the static initializer comes textually before the fields for the quoted constants, so that the ACL2 environment is initialized before the field initializers, which construct ACL2 values, are executed; [JLS14:12.4.1] says that the class initialization code is executed in textual order.

    If :guards is t, we exclude the ACL2 functions that model Java primitive and primitive array operations from the list of functions to be translated to Java. We organize the resulting functions by packages, and we proceed to generate the Java nested classes.

    We also return the alist from ACL2 package names to Java class names and the alist from ACL2 function symbols to Java method names, which must be eventually passed to the functions that generate the Java test class.

    We initialize the symbols of the atj-qconstants structure with t and nil, because their Java representations are sometimes generated even when these two symbols are not used in any of the ACL2 functions that are translated to Java.

    If the :no-aij-types input is t, we remove the functions natively implemented in AIJ from the functions to translate to Java. Those functions are only allowed inside other functions that do not manipulate AIJ types in this case, but not in their full generality, which would involve AIJ types.

    If the :no-aij-types input is t, we do not generate the array write methods (these are actually never generated currently, but there is stand-in code for generating them below, so we condition it under :no-aij-types being nil), the array conversion methods, the fields for the constants, the static initializer, and the initialization methods. All of these are AIJ-specific.

    Definitions and Theorems

    Function: atj-gen-shallow-main-class

    (defun atj-gen-shallow-main-class
           (pkgs fns-to-translate call-graph guards$
                 no-aij-types$ java-class$ verbose$ wrld)
     (declare (xargs :guard (and (string-listp pkgs)
                                 (symbol-listp fns-to-translate)
                                 (symbol-symbollist-alistp call-graph)
                                 (booleanp guards$)
                                 (booleanp no-aij-types$)
                                 (stringp java-class$)
                                 (booleanp verbose$)
                                 (plist-worldp wrld))))
     (declare (xargs :guard (no-duplicatesp-equal pkgs)))
     (let ((__function__ 'atj-gen-shallow-main-class))
      (declare (ignorable __function__))
      (b*
       (((unless (no-duplicatesp-eq fns-to-translate))
         (raise
          "Internal error: ~
                    the list ~x0 of function names has duplicates."
          fns-to-translate)
         (mv (ec-call (jclass-fix :irrelevant))
             nil nil))
        (jprimarr-write-methods (if no-aij-types$ nil nil))
        (jprimarr-conv-methods
         (if no-aij-types$ nil
          (atj-gen-shallow-all-jprimarr-conv-methods fns-to-translate)))
        (fns
         (if guards$ (set-difference-eq
                          fns-to-translate
                          (union-eq *atj-jprim-fns* *atj-jprimarr-fns*))
           fns-to-translate))
        (fns (if no-aij-types$ (set-difference-eq fns *aij-natives*)
               fns))
        (mv-typess (atj-all-mv-output-types fns guards$ wrld))
        (pkg-class-names (atj-pkgs-to-classes pkgs java-class$))
        (fn-method-names (atj-fns-to-methods fns))
        (fns-by-pkg (organize-symbols-by-pkg fns))
        (qconsts (make-atj-qconstants :integers nil
                                      :rationals nil
                                      :numbers nil
                                      :chars nil
                                      :strings nil
                                      :symbols (list t nil)
                                      :pairs nil
                                      :next-index 1))
        (fns-that-may-throw
           (atj-shallow-fns-that-may-throw fns-to-translate call-graph))
        ((mv methods-by-pkg qconsts mv-typess)
         (atj-gen-shallow-all-pkg-methods
              pkgs fns-by-pkg fns fns-that-may-throw
              qconsts pkg-class-names
              fn-method-names mv-typess
              guards$ no-aij-types$ verbose$ wrld))
        ((unless (atj-gen-shallow-mv-classes-guard mv-typess))
         (raise
          "Internal error: ~
                    not all lists of types in ~x0 have length 2 or more."
          mv-typess)
         (mv (ec-call (jclass-fix :irrelevant))
             nil nil))
        (mv-classes (atj-gen-shallow-mv-classes mv-typess))
        ((atj-qconstants qconsts) qconsts)
        (qsymbols qconsts.symbols)
        (qsymbols-by-pkg (organize-symbols-by-pkg qsymbols))
        (fields-by-pkg (if no-aij-types$ nil
                         (atj-gen-shallow-all-pkg-fields
                              pkgs qsymbols
                              qsymbols-by-pkg methods-by-pkg)))
        ((run-when verbose$)
         (cw "~%Generate the Java classes for the ACL2 packages:~%"))
        (pkg-classes
          (atj-gen-shallow-pkg-classes pkgs fields-by-pkg methods-by-pkg
                                       pkg-class-names verbose$))
        ((run-when verbose$)
         (cw "~%Generate the main Java class.~%"))
        (qinteger-fields
             (atj-gen-shallow-number-fields qconsts.integers))
        (qrational-fields
             (atj-gen-shallow-number-fields qconsts.rationals))
        (qnumber-fields (atj-gen-shallow-number-fields qconsts.numbers))
        (qchar-fields (atj-gen-shallow-char-fields qconsts.chars))
        (qstring-fields (atj-gen-shallow-string-fields qconsts.strings))
        (qcons-fields
             (atj-gen-shallow-cons-fields (strip-cars qconsts.pairs)
                                          qconsts.pairs))
        (all-qconst-fields (append qinteger-fields qrational-fields
                                   qnumber-fields qchar-fields
                                   qstring-fields qcons-fields))
        (all-qconst-fields (if no-aij-types$ nil
                             (mergesort-jfields all-qconst-fields)))
        (static-init (atj-gen-static-initializer java-class$))
        (init-method (atj-gen-init-method))
        (body-class
         (append
          (and (not no-aij-types$)
               (list (jcbody-element-init static-init)))
          (and
           (not no-aij-types$)
           (list (jcbody-element-member (jcmember-method init-method))))
          (jclasses-to-jcbody-elements pkg-classes)
          (jfields-to-jcbody-elements all-qconst-fields)
          (jclasses-to-jcbody-elements mv-classes)
          (jmethods-to-jcbody-elements jprimarr-write-methods)
          (jmethods-to-jcbody-elements jprimarr-conv-methods)))
        (body-class (atj-post-translate-jcbody-elements body-class)))
       (mv (make-jclass :access (jaccess-public)
                        :abstract? nil
                        :static? nil
                        :final? nil
                        :strictfp? nil
                        :name java-class$
                        :superclass? nil
                        :superinterfaces nil
                        :body body-class)
           pkg-class-names fn-method-names))))

    Theorem: jclassp-of-atj-gen-shallow-main-class.class

    (defthm jclassp-of-atj-gen-shallow-main-class.class
      (b* (((mv common-lisp::?class
                ?pkg-class-names ?fn-method-names)
            (atj-gen-shallow-main-class pkgs fns-to-translate
                                        call-graph guards$ no-aij-types$
                                        java-class$ verbose$ wrld)))
        (jclassp class))
      :rule-classes :rewrite)

    Theorem: string-string-alistp-of-atj-gen-shallow-main-class.pkg-class-names

    (defthm
     string-string-alistp-of-atj-gen-shallow-main-class.pkg-class-names
     (implies
      (string-listp pkgs)
      (b* (((mv common-lisp::?class
                ?pkg-class-names ?fn-method-names)
            (atj-gen-shallow-main-class pkgs fns-to-translate
                                        call-graph guards$ no-aij-types$
                                        java-class$ verbose$ wrld)))
        (string-string-alistp pkg-class-names)))
     :rule-classes :rewrite)

    Theorem: symbol-string-alistp-of-atj-gen-shallow-main-class.fn-method-names

    (defthm
     symbol-string-alistp-of-atj-gen-shallow-main-class.fn-method-names
     (implies
      (symbol-listp fns-to-translate)
      (b* (((mv common-lisp::?class
                ?pkg-class-names ?fn-method-names)
            (atj-gen-shallow-main-class pkgs fns-to-translate
                                        call-graph guards$ no-aij-types$
                                        java-class$ verbose$ wrld)))
        (symbol-string-alistp fn-method-names)))
     :rule-classes :rewrite)