lambda expression moved to ? keyword, improvements to JIO
This commit is contained in:
parent
9ef6c19237
commit
59f206210a
2 changed files with 83 additions and 2 deletions
|
@ -133,6 +133,13 @@ public class ISBPL {
|
|||
case "{":
|
||||
return (idx, words, file, stack) -> {
|
||||
AtomicInteger i = new AtomicInteger(idx);
|
||||
ISBPLCallable block = readBlock(i, words, file, true);
|
||||
stack.push(new ISBPLObject(getType("func"), block));
|
||||
return i.get();
|
||||
};
|
||||
case "?":
|
||||
return (idx, words, file, stack) -> {
|
||||
AtomicInteger i = new AtomicInteger(idx + 1);
|
||||
ISBPLCallable block = readBlock(i, words, file, false);
|
||||
stack.push(new ISBPLObject(getType("func"), block));
|
||||
return i.get();
|
||||
|
@ -1107,7 +1114,27 @@ public class ISBPL {
|
|||
return o.object;
|
||||
}
|
||||
|
||||
private Object fromISBPL(ISBPLObject o, Class<?> expectedType) {
|
||||
public Object primitiveDefault(Class<?> expectedType) {
|
||||
if(expectedType == long.class)
|
||||
return 0L;
|
||||
if(expectedType == int.class)
|
||||
return 0;
|
||||
if(expectedType == double.class)
|
||||
return 0.0d;
|
||||
if(expectedType == float.class)
|
||||
return 0.0f;
|
||||
if(expectedType == short.class)
|
||||
return (short) 0;
|
||||
if(expectedType == boolean.class)
|
||||
return false;
|
||||
if(expectedType == char.class)
|
||||
return (char) 0;
|
||||
if(expectedType == byte.class)
|
||||
return (byte) 0;
|
||||
return null;
|
||||
}
|
||||
|
||||
public Object fromISBPL(ISBPLObject o, Class<?> expectedType) {
|
||||
ISBPLType type = o.type;
|
||||
if (type.equals(getType("null"))) {
|
||||
return null;
|
||||
|
@ -1126,7 +1153,8 @@ public class ISBPL {
|
|||
else
|
||||
typeError("array", "matching-array");
|
||||
for (int i = 0 ; i < isbplArray.length ; i++) {
|
||||
Array.set(array, i, fromISBPL(isbplArray[i], expectedType.getComponentType()));
|
||||
Object obj = fromISBPL(isbplArray[i], expectedType.getComponentType());
|
||||
Array.set(array, i, obj == null && expectedType.getComponentType().isPrimitive() ? primitiveDefault(expectedType.getComponentType()) : obj);
|
||||
}
|
||||
return array;
|
||||
}
|
||||
|
@ -1161,6 +1189,18 @@ public class ISBPL {
|
|||
if (object instanceof String) {
|
||||
return toISBPLString(((String) object));
|
||||
}
|
||||
if (object instanceof Integer)
|
||||
return new ISBPLObject(getType("int"), object);
|
||||
if (object instanceof Character)
|
||||
return new ISBPLObject(getType("char"), object);
|
||||
if (object instanceof Byte)
|
||||
return new ISBPLObject(getType("byte"), object);
|
||||
if (object instanceof Float)
|
||||
return new ISBPLObject(getType("float"), object);
|
||||
if (object instanceof Long)
|
||||
return new ISBPLObject(getType("long"), object);
|
||||
if (object instanceof Double)
|
||||
return new ISBPLObject(getType("double"), object);
|
||||
if (object.getClass().isArray()) {
|
||||
ISBPLObject[] isbplArray = new ISBPLObject[Array.getLength(object)];
|
||||
for (int i = 0 ; i < isbplArray.length ; i++) {
|
||||
|
|
41
file.isbpl
41
file.isbpl
|
@ -6,3 +6,44 @@ def TYPE_FILE "file" mktype =TYPE_FILE
|
|||
native read
|
||||
native flength
|
||||
native write
|
||||
|
||||
def _.file.&read &read =_.file.&read
|
||||
func _.file.read {
|
||||
_.file.&read fcall
|
||||
}
|
||||
def _.file.&flength &flength =_.file.&flength
|
||||
func _.file.flength {
|
||||
_.file.&flength fcall
|
||||
}
|
||||
def _.file.&write &write =_.file.&write
|
||||
func _.file.write {
|
||||
_.file.&write fcall
|
||||
}
|
||||
def _.file.&_file &_file =_.file.&_file
|
||||
func _.file._file {
|
||||
_.file.&_file fcall
|
||||
}
|
||||
def _.file.&isfile &isfile =_.file.&isfile
|
||||
func _.file.isfile {
|
||||
_.file.&isfile fcall
|
||||
}
|
||||
|
||||
def File "java.io.File" JIO class =File
|
||||
def FileInputStream "java.io.FileInputStream" JIO class =FileInputStream
|
||||
|
||||
"open" {
|
||||
new1
|
||||
} File gettype defmethod
|
||||
|
||||
"read" {
|
||||
def this =this
|
||||
def stream this FileInputStream new1 =stream
|
||||
def bytes this length0 TYPE_LONG settype _int anew =bytes
|
||||
def i 0 =i
|
||||
while { i bytes alen lt } {
|
||||
bytes i stream read0 _char aput
|
||||
i inc
|
||||
}
|
||||
stream close0
|
||||
bytes
|
||||
} File gettype defmethod
|
||||
|
|
Loading…
Add table
Reference in a new issue