Commit 7d0c38f2 authored by mevenson@1c010e3e-69d0-11dd-93a8-456734b0d56f's avatar mevenson@1c010e3e-69d0-11dd-93a8-456734b0d56f
Browse files

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).
parent 31b0243f
......@@ -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"))
......
......@@ -457,16 +457,20 @@ public final class Java
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 @@ public final class Java
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 @@ public final class Java
}
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 @@ public final class Java
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;
}
......
......@@ -446,3 +446,4 @@
;;#+allegro
;;(jlinker-end)
(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)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment