[Armedbear-cvs] r14698 - in branches/1.3.1: . src/org/armedbear/lisp test/lisp/abcl

mevenson at common-lisp.net mevenson at common-lisp.net
Sun Apr 27 14:12:39 UTC 2014


Author: mevenson
Date: Sun Apr 27 14:12:38 2014
New Revision: 14698

Log:
Backport r14694: Convert Lisp truth values to Java equivalents in JCALL/JSTATIC.

We now convert CL:T and CL:NIL to JAVA:+TRUE+ and JAVA:+FALSE+
respectively when invoking JVM methods through the JAVA package,
establishing the "natural" equivalence for boolean truth values.  This
may break some existing usage in that previously CL:NIL was converted
to a Java 'null' reference.  Users now need to specify JAVA:+NULL+
explicitly when desiring to pass 'null' Java references as an argument
in invoking JVM methods.

Addresses <http://abcl.org/trac/ticket/84> (#84) and
<http://abcl.org/trac/ticket/339> (#339).

Added:
   branches/1.3.1/test/lisp/abcl/java.lisp
      - copied unchanged from r14694, trunk/abcl/test/lisp/abcl/java.lisp
Modified:
   branches/1.3.1/abcl.asd
   branches/1.3.1/src/org/armedbear/lisp/Java.java
   branches/1.3.1/test/lisp/abcl/java-tests.lisp

Modified: branches/1.3.1/abcl.asd
==============================================================================
--- branches/1.3.1/abcl.asd	Sun Apr 27 14:11:37 2014	(r14697)
+++ branches/1.3.1/abcl.asd	Sun Apr 27 14:12:38 2014	(r14698)
@@ -17,7 +17,7 @@
 ;;; We guard with #+abcl for tests that other Lisps cannot load.  This
 ;;; could be possibly be done at finer granularity in the files
 ;;; themselves.
-(defsystem :abcl-test-lisp :version "1.2" :components
+(defsystem :abcl-test-lisp :version "1.3.0" :components
 	   ((:module abcl-rt 
                      :pathname "test/lisp/abcl/" :serial t :components
 		     ((:file "rt-package") 
@@ -59,6 +59,8 @@
                       (:file "weak-hash-tables")
                       #+abcl 
                       (:file "zip")
+                      #+abcl 
+                      (:file "java")
                       #+abcl
                       (:file "pathname-tests" :depends-on 
                              ("utilities"))

Modified: branches/1.3.1/src/org/armedbear/lisp/Java.java
==============================================================================
--- branches/1.3.1/src/org/armedbear/lisp/Java.java	Sun Apr 27 14:11:37 2014	(r14697)
+++ branches/1.3.1/src/org/armedbear/lisp/Java.java	Sun Apr 27 14:12:38 2014	(r14698)
@@ -457,16 +457,20 @@
                     if (m == null)
                         error(new LispError("no such method"));
                 }
-            } else
+            } else {
               type_error(methodRef, Symbol.STRING);
+            }
             Object[] methodArgs = new Object[args.length-2];
             Class[] argTypes = m.getParameterTypes();
             for (int i = 2; i < args.length; i++) {
                 LispObject arg = args[i];
-                if (arg == NIL)
-                    methodArgs[i-2] = null;
-                else
-                    methodArgs[i-2] = arg.javaInstance(argTypes[i-2]);
+                if (arg.equals(NIL)) {
+                  methodArgs[i-2] = false;
+                } else if (arg.equals(T)) {
+                  methodArgs[i-2] = true;
+                } else {
+                  methodArgs[i-2] = arg.javaInstance(argTypes[i-2]);
+                }
             }
             m.setAccessible(true);
             Object result = m.invoke(null, methodArgs);
@@ -562,10 +566,12 @@
                 Object[] initargs = new Object[args.length-1];
                 for (int i = 1; i < args.length; i++) {
                     LispObject arg = args[i];
-                    if (arg == NIL)
-                        initargs[i-1] = null;
-                    else {
-                        initargs[i-1] = arg.javaInstance(argTypes[i-1]);
+                    if (arg.equals(NIL)) {
+                      initargs[i-1] = false ;
+                    } else if (arg.equals(T)) {
+                      initargs[i-1] = true;
+                    } else {
+                      initargs[i-1] = arg.javaInstance(argTypes[i-1]);
                     }
                 }
                 return JavaObject.getInstance(constructor.newInstance(initargs));
@@ -878,11 +884,14 @@
 	    }
             methodArgs = new Object[argTypes.length];
             for (int i = 2; i < args.length; i++) {
-                LispObject arg = args[i];
-                if (arg == NIL)
-                    methodArgs[i-2] = null;
-                else
-                    methodArgs[i-2] = arg.javaInstance(argTypes[i-2]);
+              LispObject arg = args[i];
+              if (arg.equals(NIL)) {
+                methodArgs[i-2] = false;
+              } else if (arg.equals(T)) {
+                methodArgs[i-2] = true;
+              } else {
+                methodArgs[i-2] = arg.javaInstance(argTypes[i-2]);
+              }
             }
             if (!method.isAccessible()) {
                  // Possible for static member classes: see #229
@@ -923,12 +932,14 @@
 	int argCount = args.length - offs;
         Object[] javaArgs = new Object[argCount];
         for (int i = 0; i < argCount; ++i) {
-            Object x = args[i + offs];
-            if (x == NIL) {
-                javaArgs[i] = null;
-            } else {
-                javaArgs[i] = ((LispObject) x).javaInstance();
-            }
+          Object x = args[i + offs];
+          if (x.equals(NIL)) {
+            javaArgs[i] = false;
+          } else if (x.equals(T)) {
+            javaArgs[i] = true;
+          } else {
+            javaArgs[i] = ((LispObject) x).javaInstance();
+          }
         }
 	return javaArgs;
     }

Modified: branches/1.3.1/test/lisp/abcl/java-tests.lisp
==============================================================================
--- branches/1.3.1/test/lisp/abcl/java-tests.lisp	Sun Apr 27 14:11:37 2014	(r14697)
+++ branches/1.3.1/test/lisp/abcl/java-tests.lisp	Sun Apr 27 14:12:38 2014	(r14698)
@@ -446,3 +446,4 @@
 
 ;;#+allegro
 ;;(jlinker-end)
+

Copied: branches/1.3.1/test/lisp/abcl/java.lisp (from r14694, trunk/abcl/test/lisp/abcl/java.lisp)
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ branches/1.3.1/test/lisp/abcl/java.lisp	Sun Apr 27 14:12:38 2014	(r14698, copy of r14694, trunk/abcl/test/lisp/abcl/java.lisp)
@@ -0,0 +1,18 @@
+(in-package #:abcl.test.lisp)
+
+(deftest java.truth.1
+  (let ((java.lang.boolean.compare 
+         (java:jmethod "java.lang.Boolean" "compare" "boolean" "boolean"))
+        (java.lang.boolean.equals 
+         (java:jmethod "java.lang.Boolean" "equals" "java.lang.Object")))
+    (values 
+     (java:jstatic java.lang.Boolean.compare "java.lang.Boolean" java:+true+ t)
+     (java:jstatic java.lang.Boolean.compare "java.lang.Boolean" java:+false+ nil)
+     (java:jcall java.lang.Boolean.equals java:+true+ t)
+     (java:jcall java.lang.Boolean.equals java:+false+ nil)
+     (java:jstatic java.lang.Boolean.compare "java.lang.Boolean" java:+false+ t)
+     (java:jstatic java.lang.Boolean.compare "java.lang.Boolean" java:+false+ t)
+     (java:jcall java.lang.Boolean.equals java:+true+ nil)
+     (java:jcall java.lang.Boolean.equals java:+false+ t)))
+  0 0 t t -1 -1 nil nil)
+




More information about the armedbear-cvs mailing list