fix bug in multi
This commit is contained in:
parent
3e914cc4c5
commit
e639991c17
2 changed files with 58 additions and 55 deletions
111
ISBPL.java
111
ISBPL.java
|
@ -28,6 +28,9 @@ public class ISBPL {
|
|||
throw new Error(e);
|
||||
}
|
||||
}
|
||||
|
||||
public static PrintStream gOutputStream = System.out;
|
||||
public static PrintStream gErrorStream = System.err;
|
||||
|
||||
static boolean debug = false, printCalls = false;
|
||||
public ISBPLDebugger.IPC debuggerIPC = new ISBPLDebugger.IPC();
|
||||
|
@ -100,7 +103,7 @@ public class ISBPL {
|
|||
array.checkTypeMulti(getType("array"), getType("string"));
|
||||
String[] allowed;
|
||||
if(debug)
|
||||
System.out.println("try with " + array);
|
||||
ISBPL.gOutputStream.println("try with " + array);
|
||||
if(array.type.name.equals("string")) {
|
||||
allowed = new String[] { toJavaString(array) };
|
||||
}
|
||||
|
@ -246,7 +249,7 @@ public class ISBPL {
|
|||
}
|
||||
stack.push(new ISBPLObject(getType("int"), type.id));
|
||||
if(debug)
|
||||
System.err.println("Constructing type " + type);
|
||||
ISBPL.gErrorStream.println("Constructing type " + type);
|
||||
return i.get();
|
||||
};
|
||||
case "string!":
|
||||
|
@ -445,14 +448,14 @@ public class ISBPL {
|
|||
func = (Stack<ISBPLObject> stack) -> {
|
||||
ISBPLObject c = stack.pop();
|
||||
c.checkType(getType("char"));
|
||||
System.out.print(((char) c.object));
|
||||
ISBPL.gOutputStream.print(((char) c.object));
|
||||
};
|
||||
break;
|
||||
case "eputchar":
|
||||
func = (Stack<ISBPLObject> stack) -> {
|
||||
ISBPLObject c = stack.pop();
|
||||
c.checkType(getType("char"));
|
||||
System.err.print(((char) c.object));
|
||||
ISBPL.gErrorStream.print(((char) c.object));
|
||||
};
|
||||
break;
|
||||
case "_file":
|
||||
|
@ -1088,7 +1091,7 @@ public class ISBPL {
|
|||
for (Object o : clazz.getEnumConstants()) {
|
||||
addFunction(type, o.toString(), stack -> {
|
||||
if(debug)
|
||||
System.err.println("Java GetEnum: " + o);
|
||||
ISBPL.gErrorStream.println("Java GetEnum: " + o);
|
||||
stack.push(toISBPL(o));
|
||||
});
|
||||
}
|
||||
|
@ -1097,7 +1100,7 @@ public class ISBPL {
|
|||
addFunction(type, field.getName(), stack -> {
|
||||
forceAccessible(field);
|
||||
if(debug)
|
||||
System.err.println("Java Get: " + field);
|
||||
ISBPL.gErrorStream.println("Java Get: " + field);
|
||||
try {
|
||||
stack.push(toISBPL(field.get(stack.pop().object)));
|
||||
}
|
||||
|
@ -1107,7 +1110,7 @@ public class ISBPL {
|
|||
addFunction(type, "=" + field.getName(), stack -> {
|
||||
forceAccessible(field);
|
||||
if(debug)
|
||||
System.err.println("Java Set: " + field);
|
||||
ISBPL.gErrorStream.println("Java Set: " + field);
|
||||
try {
|
||||
field.set(stack.pop().object, fromISBPL(stack.pop(), field.getType()));
|
||||
}
|
||||
|
@ -1138,7 +1141,7 @@ public class ISBPL {
|
|||
|
||||
forceAccessible(method);
|
||||
if(debug)
|
||||
System.err.println("Java Call: " + method + " - " + Arrays.toString(params));
|
||||
ISBPL.gErrorStream.println("Java Call: " + method + " - " + Arrays.toString(params));
|
||||
try {
|
||||
Object r = method.invoke(o, params);
|
||||
if(method.getReturnType() != void.class)
|
||||
|
@ -1174,7 +1177,7 @@ public class ISBPL {
|
|||
|
||||
forceAccessible(constructor);
|
||||
if(debug)
|
||||
System.err.println("Java Call: " + constructor + " - " + Arrays.toString(params));
|
||||
ISBPL.gErrorStream.println("Java Call: " + constructor + " - " + Arrays.toString(params));
|
||||
try {
|
||||
Object r = constructor.newInstance(params);
|
||||
stack.push(toISBPL(r));
|
||||
|
@ -1198,7 +1201,7 @@ public class ISBPL {
|
|||
int[] methodIDs = new int[paramCount];
|
||||
Arrays.fill(methodIDs, 0);
|
||||
if(debug)
|
||||
System.err.println("Consideration of " + paramTypes.length + " methods...");
|
||||
ISBPL.gErrorStream.println("Consideration of " + paramTypes.length + " methods...");
|
||||
for (int i = paramCount - 1 ; i >= 0 ; i--) {
|
||||
o[i] = stack.pop();
|
||||
for (int j = 0 ; j < paramTypes.length ; j++) {
|
||||
|
@ -1207,15 +1210,15 @@ public class ISBPL {
|
|||
params[j][i] = fromISBPL(o[i], m[i]);
|
||||
methodIDs[i] += 1 << j;
|
||||
if(debug)
|
||||
System.err.println("Consideration: Pass " + i + " " + Arrays.toString(paramTypes[j]));
|
||||
ISBPL.gErrorStream.println("Consideration: Pass " + i + " " + Arrays.toString(paramTypes[j]));
|
||||
}
|
||||
catch (ISBPLError ignored) {
|
||||
if(debug)
|
||||
System.err.println("Consideration: Fail " + i + " " + Arrays.toString(paramTypes[j]));
|
||||
ISBPL.gErrorStream.println("Consideration: Fail " + i + " " + Arrays.toString(paramTypes[j]));
|
||||
}
|
||||
}
|
||||
if(debug)
|
||||
System.err.println("Considerartion: " + i + " " + Integer.toBinaryString(methodIDs[i] + (1 << 31)).substring(32 - paramTypes.length));
|
||||
ISBPL.gErrorStream.println("Considerartion: " + i + " " + Integer.toBinaryString(methodIDs[i] + (1 << 31)).substring(32 - paramTypes.length));
|
||||
}
|
||||
int msize = paramTypes.length;
|
||||
for (int i = 0 ; i < msize; i++) {
|
||||
|
@ -1229,11 +1232,11 @@ public class ISBPL {
|
|||
if(works) {
|
||||
mid.set(i);
|
||||
if(debug)
|
||||
System.err.println("Considering: " + Arrays.toString(paramTypes[i]));
|
||||
ISBPL.gErrorStream.println("Considering: " + Arrays.toString(paramTypes[i]));
|
||||
}
|
||||
}
|
||||
if(debug)
|
||||
System.err.println("Considered " + paramTypes.length + " methods. Result: " + Arrays.toString(paramTypes[mid.get()]));
|
||||
ISBPL.gErrorStream.println("Considered " + paramTypes.length + " methods. Result: " + Arrays.toString(paramTypes[mid.get()]));
|
||||
return params[mid.get()];
|
||||
}
|
||||
|
||||
|
@ -1472,7 +1475,7 @@ public class ISBPL {
|
|||
for (int x = 0 ; x < frameStack.get().size() ; x++) {
|
||||
s.append("\t");
|
||||
}
|
||||
System.err.println(s + word + "\t\t" + (debug ? stack : ""));
|
||||
ISBPL.gErrorStream.println(s + word + "\t\t" + (debug ? stack : ""));
|
||||
}
|
||||
while (debuggerIPC.run.getOrDefault(Thread.currentThread().getId(), -1) == 0) Thread.sleep(1);
|
||||
int rid = debuggerIPC.run.getOrDefault(Thread.currentThread().getId(), -1);
|
||||
|
@ -1502,11 +1505,11 @@ public class ISBPL {
|
|||
// Doing this nonrecursively because it's much better despite the slight readability disadvantage.
|
||||
if(stack.peek() == null) {
|
||||
// We need to dump things immediately.
|
||||
System.err.println("!!! ISBPL WORD PARSER ERROR !!!");
|
||||
System.err.println("This is most likely due to a garbage collector malfunction.");
|
||||
System.err.println("Stack: " + stack);
|
||||
System.err.println("LastWords: " + lastWords);
|
||||
System.err.println("FileStack: " + fileStack);
|
||||
ISBPL.gErrorStream.println("!!! ISBPL WORD PARSER ERROR !!!");
|
||||
ISBPL.gErrorStream.println("This is most likely due to a garbage collector malfunction.");
|
||||
ISBPL.gErrorStream.println("Stack: " + stack);
|
||||
ISBPL.gErrorStream.println("LastWords: " + lastWords);
|
||||
ISBPL.gErrorStream.println("FileStack: " + fileStack);
|
||||
}
|
||||
ISBPLType type = stack.peek().type;
|
||||
Queue<ISBPLType> types = new LinkedList<>();
|
||||
|
@ -1556,11 +1559,11 @@ public class ISBPL {
|
|||
e.printStackTrace();
|
||||
}
|
||||
catch (Throwable t) {
|
||||
if(debug) System.out.println("Passing exception " + t + " to caller.");
|
||||
if(debug) ISBPL.gOutputStream.println("Passing exception " + t + " to caller.");
|
||||
if(stopExceptions) {
|
||||
t.printStackTrace();
|
||||
System.out.println("Current Words: ");
|
||||
System.out.println(Arrays.toString(words));
|
||||
ISBPL.gOutputStream.println("Current Words: ");
|
||||
ISBPL.gOutputStream.println(Arrays.toString(words));
|
||||
dump(stack);
|
||||
}
|
||||
throw t;
|
||||
|
@ -1643,36 +1646,36 @@ public class ISBPL {
|
|||
|
||||
public void dump(Stack<ISBPLObject> stack) {
|
||||
try {
|
||||
System.err.println("VAR DUMP\n----------------");
|
||||
ISBPL.gErrorStream.println("VAR DUMP\n----------------");
|
||||
for (ISBPLFrame map : frameStack.get()) {
|
||||
HashMap<String, ISBPLCallable> all = map.all();
|
||||
for (String key : all.keySet()) {
|
||||
if (key.startsWith("=")) {
|
||||
all.get(key.substring(1)).call(stack);
|
||||
System.err.println("\t" + key.substring(1) + ": \t" + stack.pop());
|
||||
ISBPL.gErrorStream.println("\t" + key.substring(1) + ": \t" + stack.pop());
|
||||
}
|
||||
}
|
||||
System.err.println("----------------");
|
||||
ISBPL.gErrorStream.println("----------------");
|
||||
}
|
||||
}
|
||||
catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
System.err.println("!!! VARS CORRUPTED! CANNOT FIX AUTOMATICALLY.");
|
||||
ISBPL.gErrorStream.println("!!! VARS CORRUPTED! CANNOT FIX AUTOMATICALLY.");
|
||||
}
|
||||
boolean fixed = false;
|
||||
while (!fixed) {
|
||||
try {
|
||||
System.err.println("STACK DUMP");
|
||||
ISBPL.gErrorStream.println("STACK DUMP");
|
||||
for (ISBPLObject object : stack) {
|
||||
System.err.println("\t" + object);
|
||||
ISBPL.gErrorStream.println("\t" + object);
|
||||
}
|
||||
fixed = true;
|
||||
}
|
||||
catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
System.err.println("!!! STACK CORRUPTED!");
|
||||
ISBPL.gErrorStream.println("!!! STACK CORRUPTED!");
|
||||
stack.pop();
|
||||
System.err.println("Popped. Trying again.");
|
||||
ISBPL.gErrorStream.println("Popped. Trying again.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1700,23 +1703,23 @@ public class ISBPL {
|
|||
isbpl.level0.add("dump", isbpl::dump);
|
||||
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
|
||||
String line;
|
||||
System.out.print("> ");
|
||||
ISBPL.gOutputStream.print("> ");
|
||||
while ((line = reader.readLine()) != null) {
|
||||
try {
|
||||
isbpl.interpret(new File("_shell"), line, stack);
|
||||
} catch(ISBPLError e) {
|
||||
System.out.println("Error: " + e.type + ": " + e.message);
|
||||
ISBPL.gOutputStream.println("Error: " + e.type + ": " + e.message);
|
||||
} catch(Throwable e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
System.out.print("\n> ");
|
||||
ISBPL.gOutputStream.print("\n> ");
|
||||
}
|
||||
}
|
||||
} catch (ISBPLStop stop) {
|
||||
System.exit(isbpl.exitCode);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
System.out.println(stack);
|
||||
ISBPL.gOutputStream.println(stack);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1749,7 +1752,7 @@ public class ISBPL {
|
|||
theSafe.putBoolean(thing, theSafe.objectFieldOffset(FakeAccessibleObject.class.getDeclaredField("override")), true);
|
||||
} catch(Exception e) { //we are doomed
|
||||
e.printStackTrace();
|
||||
System.err.println("Failed to set accessible property. We are doomed.");
|
||||
ISBPL.gErrorStream.println("Failed to set accessible property. We are doomed.");
|
||||
System.exit(1);
|
||||
}
|
||||
}
|
||||
|
@ -1994,7 +1997,7 @@ class ISBPLDebugger extends Thread {
|
|||
//noinspection resource
|
||||
socket = new ServerSocket(Integer.parseInt(System.getenv().getOrDefault("DEBUG", "9736")));
|
||||
port = socket.getLocalPort();
|
||||
System.err.println("Debugger listening on :" + socket.getLocalPort());
|
||||
ISBPL.gErrorStream.println("Debugger listening on :" + socket.getLocalPort());
|
||||
}
|
||||
catch (BindException e) {
|
||||
while (socket == null) {
|
||||
|
@ -2002,7 +2005,7 @@ class ISBPLDebugger extends Thread {
|
|||
//noinspection resource
|
||||
socket = new ServerSocket((int) (Math.random() * 5000 + 5000));
|
||||
port = socket.getLocalPort();
|
||||
System.err.println("Debugger listening on :" + socket.getLocalPort());
|
||||
ISBPL.gErrorStream.println("Debugger listening on :" + socket.getLocalPort());
|
||||
}
|
||||
catch (BindException ignored) { }
|
||||
}
|
||||
|
@ -2059,51 +2062,51 @@ class ISBPLDebugger extends Thread {
|
|||
boolean fixed = false;
|
||||
while (!fixed) {
|
||||
try {
|
||||
System.err.println("Stack recovered: " + isbpl.debuggerIPC.stack.get(tid));
|
||||
ISBPL.gErrorStream.println("Stack recovered: " + isbpl.debuggerIPC.stack.get(tid));
|
||||
fixed = true;
|
||||
}
|
||||
catch (Exception e1) {
|
||||
e.printStackTrace();
|
||||
System.err.println("!!! STACK CORRUPTED!");
|
||||
ISBPL.gErrorStream.println("!!! STACK CORRUPTED!");
|
||||
isbpl.debuggerIPC.stack.get(tid).pop();
|
||||
System.err.println("Popped. Trying again.");
|
||||
ISBPL.gErrorStream.println("Popped. Trying again.");
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
case "dump":
|
||||
try {
|
||||
System.err.println("VAR DUMP\n----------------");
|
||||
ISBPL.gErrorStream.println("VAR DUMP\n----------------");
|
||||
for (ISBPLFrame map : isbpl.frameStack.map.get(tid)) {
|
||||
HashMap<String, ISBPLCallable> all = map.all();
|
||||
for (String key : all.keySet()) {
|
||||
if (key.startsWith("=")) {
|
||||
all.get(key.substring(1)).call(isbpl.debuggerIPC.stack.get(tid));
|
||||
System.err.println("\t" + key.substring(1) + ": \t" + isbpl.debuggerIPC.stack.get(tid).pop());
|
||||
ISBPL.gErrorStream.println("\t" + key.substring(1) + ": \t" + isbpl.debuggerIPC.stack.get(tid).pop());
|
||||
}
|
||||
}
|
||||
System.err.println("----------------");
|
||||
ISBPL.gErrorStream.println("----------------");
|
||||
}
|
||||
}
|
||||
catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
System.err.println("!!! VARS CORRUPTED! CANNOT FIX AUTOMATICALLY.");
|
||||
ISBPL.gErrorStream.println("!!! VARS CORRUPTED! CANNOT FIX AUTOMATICALLY.");
|
||||
}
|
||||
case "stack":
|
||||
boolean fixed = false;
|
||||
while (!fixed) {
|
||||
try {
|
||||
System.err.println("STACK DUMP");
|
||||
ISBPL.gErrorStream.println("STACK DUMP");
|
||||
for (ISBPLObject object : isbpl.debuggerIPC.stack.get(tid)) {
|
||||
System.err.println("\t" + object);
|
||||
ISBPL.gErrorStream.println("\t" + object);
|
||||
}
|
||||
fixed = true;
|
||||
}
|
||||
catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
System.err.println("!!! STACK CORRUPTED!");
|
||||
ISBPL.gErrorStream.println("!!! STACK CORRUPTED!");
|
||||
isbpl.debuggerIPC.stack.get(tid).pop();
|
||||
System.err.println("Popped. Trying again.");
|
||||
ISBPL.gErrorStream.println("Popped. Trying again.");
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
@ -2123,10 +2126,10 @@ class ISBPLDebugger extends Thread {
|
|||
System.exit(255);
|
||||
break;
|
||||
case "threads":
|
||||
System.err.println("THREAD DUMP");
|
||||
ISBPL.gErrorStream.println("THREAD DUMP");
|
||||
for (Thread thread : Thread.getAllStackTraces().keySet()) {
|
||||
if (isbpl.debuggerIPC.stack.containsKey(thread.getId()))
|
||||
System.err.println(thread.getId() + "\t" + thread.getName());
|
||||
ISBPL.gErrorStream.println(thread.getId() + "\t" + thread.getName());
|
||||
}
|
||||
break;
|
||||
case "setthread":
|
||||
|
@ -2134,10 +2137,10 @@ class ISBPLDebugger extends Thread {
|
|||
long l = Long.parseLong(line.split(" ")[1]);
|
||||
if (isbpl.debuggerIPC.stack.containsKey(l)) {
|
||||
tid = l;
|
||||
System.err.println("Set TID=" + l);
|
||||
ISBPL.gErrorStream.println("Set TID=" + l);
|
||||
}
|
||||
else
|
||||
System.err.println("Thread not valid");
|
||||
ISBPL.gErrorStream.println("Thread not valid");
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
|
|
|
@ -35,4 +35,4 @@ def Context construct Context {
|
|||
"multi.isbpl:_eval" File new1 run stack jContext interpret3
|
||||
stack
|
||||
}
|
||||
}
|
||||
} =Context
|
||||
|
|
Loading…
Add table
Reference in a new issue