@@ -29,6 +29,8 @@ public class PrologArchitecture implements Architecture {
2929 private FutureTask <Object > vmQueryResponseFutureTask ;
3030 private int vmQuerySleepTicks ;
3131
32+ private ExecutionResult forceExecutionResult ;
33+
3234 enum VMResponse {
3335 RunSynchronous ,
3436 Wait ,
@@ -65,6 +67,9 @@ public void runSynchronized() {
6567
6668 @ Override
6769 public ExecutionResult runThreaded (boolean isSynchronizedReturn ) {
70+ if (forceExecutionResult != null )
71+ return forceExecutionResult ;
72+
6873 //Called for: synchronized return, init, or signal
6974 vmQueryResponse = VMResponse .None ;
7075 vmQueryResponseFutureTask = new FutureTask <>(() -> "" );
@@ -109,13 +114,19 @@ public ExecutionResult runThreaded(boolean isSynchronizedReturn) {
109114 }
110115 // (magical time where prolog engine resolves part of the query)
111116 try {
117+ if (vm .exitException != null ) {
118+ return new ExecutionResult .Error (vm .exitException .getMessage ());
119+ }
120+ if (vm .getState () == Thread .State .TERMINATED ) {
121+ return new ExecutionResult .Error ("Terminated early" );
122+ }
112123 vmQueryResponseFutureTask .get (30 , TimeUnit .SECONDS );
113124// vmQueryResponseFutureTask.get(3, TimeUnit.SECONDS);
114125 } catch (InterruptedException | ExecutionException | TimeoutException e ) {
115126 if (vm .exitException != null ) {
116127 return new ExecutionResult .Error (vm .exitException .getMessage ());
117128 }
118- return new ExecutionResult .Error ("Some problem eh?" );
129+ return new ExecutionResult .Error ("Some problem eh? (1) " );
119130 }
120131
121132 // a query has sent us something (or the thread exited)
@@ -137,7 +148,7 @@ public ExecutionResult runThreaded(boolean isSynchronizedReturn) {
137148 if (vm .exitException != null ) {
138149 return new ExecutionResult .Error (vm .exitException .getMessage ());
139150 }
140- return new ExecutionResult .Error ("Some problem eh?" );
151+ return new ExecutionResult .Error ("Some problem eh? (2) " );
141152 }
142153
143154 // a query calls this
@@ -179,6 +190,18 @@ public void waitingCall(int ticks) {
179190 }
180191 }
181192
193+ public void crash (String e ) {
194+ forceExecutionResult = new ExecutionResult .Error (e );
195+
196+ if (!vmQueryResponseFutureTask .isDone ()) {
197+ vmQueryResponseFutureTask .cancel (true );
198+ }
199+ if (!synchronizedFutureTask .isDone ()) {
200+ synchronizedFutureTask .cancel (true );
201+ }
202+ // machine.crash(e);
203+ }
204+
182205 @ Override
183206 public boolean isInitialized () {
184207 return vm != null && vm .getState () != Thread .State .NEW ;
0 commit comments