Generate the main (i.e. non-test) Java class declaration, in the shallow embedding approach.
(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)
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
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
If the
If the
Function:
(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:
(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:
(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:
(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)