fix array JIO

This commit is contained in:
Daniella / Tove 2022-04-24 01:57:31 +02:00
parent 582c0861fb
commit f2b67a1b40

View file

@ -996,9 +996,10 @@ public class ISBPL {
addFunction(type, method.getName() + method.getParameterCount(), stack -> { addFunction(type, method.getName() + method.getParameterCount(), stack -> {
method.setAccessible(true); method.setAccessible(true);
Object o = stack.pop().object; Object o = stack.pop().object;
Class<?>[] parameterTypes = method.getParameterTypes();
Object[] params = new Object[method.getParameterCount()]; Object[] params = new Object[method.getParameterCount()];
for (int i = params.length - 1 ; i >= 0 ; i--) { for (int i = params.length - 1 ; i >= 0 ; i--) {
params[i] = fromISBPL(stack.pop()); params[i] = fromISBPL(stack.pop(), parameterTypes[i]);
} }
if(debug) if(debug)
System.err.println("Java Call: " + method + " - " + Arrays.toString(params)); System.err.println("Java Call: " + method + " - " + Arrays.toString(params));
@ -1018,9 +1019,10 @@ public class ISBPL {
addFunction(type, "new" + constructor.getParameterCount(), stack -> { addFunction(type, "new" + constructor.getParameterCount(), stack -> {
constructor.setAccessible(true); constructor.setAccessible(true);
stack.pop(); stack.pop();
Class<?>[] parameterTypes = constructor.getParameterTypes();
Object[] params = new Object[constructor.getParameterCount()]; Object[] params = new Object[constructor.getParameterCount()];
for (int i = params.length - 1 ; i >= 0 ; i--) { for (int i = params.length - 1 ; i >= 0 ; i--) {
params[i] = fromISBPL(stack.pop()); params[i] = fromISBPL(stack.pop(), parameterTypes[i]);
} }
if(debug) if(debug)
System.err.println("Java Call: new - " + Arrays.toString(params)); System.err.println("Java Call: new - " + Arrays.toString(params));
@ -1057,6 +1059,28 @@ public class ISBPL {
return o.object; return o.object;
} }
private Object fromISBPL(ISBPLObject o, Class<?> expectedType) {
ISBPLType type = o.type;
if (type.equals(getType("null"))) {
return null;
}
if (type.equals(getType("string")))
return toJavaString(o);
if (type.equals(getType("array"))) {
ISBPLObject[] isbplArray = ((ISBPLObject[]) o.object);
Object array = new Object[isbplArray.length];
if(expectedType.isArray())
array = Array.newInstance(expectedType.getComponentType(), isbplArray.length);
else
typeError("array", "matching-array");
for (int i = 0 ; i < isbplArray.length ; i++) {
Array.set(array, i, fromISBPL(isbplArray[i]));
}
return array;
}
return o.object;
}
public ISBPLObject toISBPL(Object object) { public ISBPLObject toISBPL(Object object) {
if(object == null) { if(object == null) {
return new ISBPLObject(getType("null"), 0); return new ISBPLObject(getType("null"), 0);