• 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
        • 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
          • Riscv
          • 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-synonym-method

    Generate a Java method with the given types for an ACL2 function synonym.

    Signature
    (atj-gen-shallow-synonym-method 
         fn fns-that-may-throw fn-type 
         pkg-class-names fn-method-names wrld) 
     
      → 
    method
    Arguments
    fn — Guard (symbolp fn).
    fns-that-may-throw — Guard (symbol-listp fns-that-may-throw).
    fn-type — Guard (atj-function-type-p fn-type).
    pkg-class-names — Guard (string-string-alistp pkg-class-names).
    fn-method-names — Guard (symbol-string-alistp fn-method-names).
    wrld — Guard (plist-worldp wrld).
    Returns
    method — Type (jmethodp method).

    This is used to mimic, as far as name references are concerned, the importing of a function symbol in a package.

    For instance, the built-in cons is in the "COMMON-LISP" package (i.e. that is its symbol-package-name), but that symbol is imported by the "ACL2" package, making it referenceable as acl2::cons besides the ``canonical'' common-lisp::cons. In particular, in the "ACL2" package it can be referenced as just cons, which makes ACL2 code much more readable.

    In the shallow embedding, we translate these two ACL2 packages to two different Java classes, and the method that corresponds to cons is declared in the class for "COMMON-LISP", where the method can be referenced by simple name, without qualifying it with the class name. But in classes for other packages, e.g. the class for "ACL2", it would have to be qualified.

    To avoid this verbosity, we generate a ``synonym'' of the method for cons in each class of a package that imports cons, e.g. in the class for "ACL2". This function generates this synonym method, which is just defined to call the method in the class of its proper package. This makes the generated Java code much more readable. It is hoped that the JVM JIT may optimize the indirection away.

    The fn parameter is the name of the ACL2 function in question, e.g. cons in the example above.

    We pass the symbol-package-name of fn to atj-gen-shallow-fnname to ensure that the result is the simple name of the method, which goes into the generated method declaration.

    Recall that, for each ACL2 function, we generate as many overloaded Java methods as the number of primary and secondary types of the function. Accordingly, we must generate the same number of overloaded methods for the function synonyms. This function generates the overloaded method for the function type passed as argument.

    Definitions and Theorems

    Function: atj-gen-shallow-synonym-method

    (defun atj-gen-shallow-synonym-method
           (fn fns-that-may-throw fn-type
               pkg-class-names fn-method-names wrld)
     (declare (xargs :guard (and (symbolp fn)
                                 (symbol-listp fns-that-may-throw)
                                 (atj-function-type-p fn-type)
                                 (string-string-alistp pkg-class-names)
                                 (symbol-string-alistp fn-method-names)
                                 (plist-worldp wrld))))
     (let ((__function__ 'atj-gen-shallow-synonym-method))
      (declare (ignorable __function__))
      (b*
       ((in-types (atj-function-type->inputs fn-type))
        (out-types (atj-function-type->outputs fn-type))
        ((unless (consp out-types))
         (raise
          "Internal error: ~
                    the function ~x0 has no output types ~x1."
          fn out-types)
         (ec-call (jmethod-fix :irrelevant)))
        (out-jtype (atj-gen-shallow-jtype out-types))
        (fn-pkg (symbol-package-name fn))
        (method-name (atj-gen-shallow-fnname
                          fn
                          pkg-class-names fn-method-names fn-pkg))
        (method-param-names
             (atj-gen-shallow-synonym-method-params (arity+ fn wrld)))
        ((unless (= (len method-param-names)
                    (len in-types)))
         (raise
          "Internal error: ~
                    the number ~x0 of input types of ~x1 ~
                    differs from the arity ~x2 of ~x1."
          (len in-types)
          fn (len method-param-names))
         (ec-call (jmethod-fix :irrelevant)))
        (method-params
            (atj-gen-paramlist method-param-names
                               (atj-type-list-to-jitype-list in-types)))
        (class (atj-get-pkg-class-name fn-pkg pkg-class-names))
        (method-body
             (jblock-return
                  (jexpr-smethod (jtype-class class)
                                 method-name
                                 (jexpr-name-list method-param-names))))
        (throws (and (member-eq fn fns-that-may-throw)
                     (list *aij-class-undef-pkg-exc*))))
       (make-jmethod :access (jaccess-public)
                     :abstract? nil
                     :static? t
                     :final? nil
                     :synchronized? nil
                     :native? nil
                     :strictfp? nil
                     :result (jresult-type out-jtype)
                     :name method-name
                     :params method-params
                     :throws throws
                     :body method-body))))

    Theorem: jmethodp-of-atj-gen-shallow-synonym-method

    (defthm jmethodp-of-atj-gen-shallow-synonym-method
      (b* ((method (atj-gen-shallow-synonym-method
                        fn fns-that-may-throw fn-type
                        pkg-class-names fn-method-names wrld)))
        (jmethodp method))
      :rule-classes :rewrite)