[Armedbear-cvs] r14694 - in trunk/abcl: . src/org/armedbear/lisp test/lisp/abcl

mevenson at common-lisp.net mevenson at common-lisp.net
Fri Apr 25 07:55:54 UTC 2014


Author: mevenson
Date: Fri Apr 25 07:55:53 2014
New Revision: 14694

Log:
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:
   trunk/abcl/test/lisp/abcl/java.lisp
Modified:
   trunk/abcl/abcl.asd
   trunk/abcl/src/org/armedbear/lisp/Java.java
   trunk/abcl/test/lisp/abcl/java-tests.lisp

Modified: trunk/abcl/abcl.asd
==============================================================================
--- trunk/abcl/abcl.asd	Tue Apr 22 12:14:21 2014	(r14693)
+++ trunk/abcl/abcl.asd	Fri Apr 25 07:55:53 2014	(r14694)
@@ -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: trunk/abcl/src/org/armedbear/lisp/Java.java
==============================================================================
--- trunk/abcl/src/org/armedbear/lisp/Java.java	Tue Apr 22 12:14:21 2014	(r14693)
+++ trunk/abcl/src/org/armedbear/lisp/Java.java	Fri Apr 25 07:55:53 2014	(r14694)
@@ -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: trunk/abcl/test/lisp/abcl/java-tests.lisp
==============================================================================
--- trunk/abcl/test/lisp/abcl/java-tests.lisp	Tue Apr 22 12:14:21 2014	(r14693)
+++ trunk/abcl/test/lisp/abcl/java-tests.lisp	Fri Apr 25 07:55:53 2014	(r14694)
@@ -446,3 +446,4 @@
 
 ;;#+allegro
 ;;(jlinker-end)
+

Added: trunk/abcl/test/lisp/abcl/java.lisp
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ trunk/abcl/test/lisp/abcl/java.lisp	Fri Apr 25 07:55:53 2014	(r14694)
@@ -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