fix array null elements, add constructors
This commit is contained in:
parent
20d45e71ae
commit
6e2f22fe69
2 changed files with 38 additions and 1 deletions
|
@ -203,7 +203,11 @@ public class ISBPL {
|
||||||
func = (Stack<ISBPLObject> stack) -> {
|
func = (Stack<ISBPLObject> stack) -> {
|
||||||
ISBPLObject i = stack.pop();
|
ISBPLObject i = stack.pop();
|
||||||
i.checkType(getType("int"));
|
i.checkType(getType("int"));
|
||||||
stack.push(new ISBPLObject(getType("array"), new ISBPLObject[((int) i.object)]));
|
ISBPLObject[] arr = new ISBPLObject[((int) i.object)];
|
||||||
|
for (int j = 0 ; j < arr.length ; j++) {
|
||||||
|
arr[j] = new ISBPLObject(getType("null"), 0);
|
||||||
|
}
|
||||||
|
stack.push(new ISBPLObject(getType("array"), arr));
|
||||||
};
|
};
|
||||||
break;
|
break;
|
||||||
case "_array":
|
case "_array":
|
||||||
|
@ -907,6 +911,11 @@ public class ISBPL {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
break;
|
break;
|
||||||
|
case "null":
|
||||||
|
func = (stack) -> {
|
||||||
|
stack.push(new ISBPLObject(getType("null"), 0));
|
||||||
|
};
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
func = natives.get(name);
|
func = natives.get(name);
|
||||||
break;
|
break;
|
||||||
|
@ -978,12 +987,35 @@ public class ISBPL {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
for (Constructor<?> constructor : clazz.getDeclaredConstructors()) {
|
||||||
|
addFunction(type, "new" + constructor.getParameterCount(), stack -> {
|
||||||
|
constructor.setAccessible(true);
|
||||||
|
Object[] params = new Object[constructor.getParameterCount()];
|
||||||
|
for (int i = params.length - 1 ; i >= 0 ; i--) {
|
||||||
|
params[i] = fromISBPL(stack.pop());
|
||||||
|
}
|
||||||
|
if(debug)
|
||||||
|
System.err.println("Java Call: new - " + Arrays.toString(params));
|
||||||
|
try {
|
||||||
|
Object r = constructor.newInstance(params);
|
||||||
|
stack.push(toISBPL(r));
|
||||||
|
}
|
||||||
|
catch (IllegalAccessException ignored) { }
|
||||||
|
catch (InvocationTargetException | InstantiationException e) {
|
||||||
|
stack.push(toISBPL(e));
|
||||||
|
throw new ISBPLError("Java", "Java error");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return new ISBPLObject(type, null);
|
return new ISBPLObject(type, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
private Object fromISBPL(ISBPLObject o) {
|
private Object fromISBPL(ISBPLObject o) {
|
||||||
ISBPLType type = o.type;
|
ISBPLType type = o.type;
|
||||||
|
if (type.equals(getType("null"))) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
if (type.equals(getType("string")))
|
if (type.equals(getType("string")))
|
||||||
return toJavaString(o);
|
return toJavaString(o);
|
||||||
if (type.equals(getType("array"))) {
|
if (type.equals(getType("array"))) {
|
||||||
|
@ -998,6 +1030,9 @@ public class ISBPL {
|
||||||
}
|
}
|
||||||
|
|
||||||
public ISBPLObject toISBPL(Object object) {
|
public ISBPLObject toISBPL(Object object) {
|
||||||
|
if(object == null) {
|
||||||
|
return new ISBPLObject(getType("null"), 0);
|
||||||
|
}
|
||||||
ISBPLObject o = toISBPL(object.getClass());
|
ISBPLObject o = toISBPL(object.getClass());
|
||||||
if (object instanceof String) {
|
if (object instanceof String) {
|
||||||
object = toISBPLString(((String) object));
|
object = toISBPLString(((String) object));
|
||||||
|
|
|
@ -83,6 +83,8 @@ def TYPE_BYTE "byte" mktype =TYPE_BYTE
|
||||||
def TYPE_FLOAT "float" mktype =TYPE_FLOAT
|
def TYPE_FLOAT "float" mktype =TYPE_FLOAT
|
||||||
def TYPE_LONG "long" mktype =TYPE_LONG
|
def TYPE_LONG "long" mktype =TYPE_LONG
|
||||||
def TYPE_DOUBLE "double" mktype =TYPE_DOUBLE
|
def TYPE_DOUBLE "double" mktype =TYPE_DOUBLE
|
||||||
|
def TYPE_NULL "null" mktype =TYPE_NULL
|
||||||
|
native null
|
||||||
def TYPE_FUNCTION "func" mktype =TYPE_FUNCTION
|
def TYPE_FUNCTION "func" mktype =TYPE_FUNCTION
|
||||||
def TYPE_ARRAY "array" mktype =TYPE_ARRAY
|
def TYPE_ARRAY "array" mktype =TYPE_ARRAY
|
||||||
def TYPE_STRING "string" mktype =TYPE_STRING
|
def TYPE_STRING "string" mktype =TYPE_STRING
|
||||||
|
|
Loading…
Add table
Reference in a new issue