Commit f1951ce3 authored by Martin Spoto's avatar Martin Spoto
Browse files

Handle multiple goals input

parent cce8d7ff
package ch.heiafr.prolograal.exceptions;
import ch.heiafr.prolograal.runtime.ProloGraalTerm;
import com.oracle.truffle.api.nodes.ControlFlowException;
public class ProloGraalExistenceError extends ControlFlowException {
// cannot use built-in because of inheritance from ControlFlowException
private String message;
public ProloGraalExistenceError(ProloGraalTerm<?> what) {
message = what.toString();
}
@Override
public String getMessage() {
return message;
}
private static final long serialVersionUID = 0xd4cc78cfb9ef9000L;
}
\ No newline at end of file
......@@ -56,6 +56,9 @@ public class ProloGraalInterpreterNode extends RootNode {
continue;
}
// count the line as a list of goals to resolve
line = "goals :- " + line;
Source source = Source.newBuilder("pl", line, null).build();
try {
ProloGraalRuntime runtime = ProloGraalParserImpl.parseProloGraal(language, source);
......@@ -80,7 +83,7 @@ public class ProloGraalInterpreterNode extends RootNode {
writer.println();
writer.println(callResult);
} catch(ProloGraalExistenceError existenceError) {
writer.println("Error : no clause for goal '" + runtime.getFirstClause() + "'");
writer.println("Error : no clause for goal '" + existenceError.getMessage() + "'");
}
} catch(ProloGraalParseError parseError) {
writer.println(parseError.getMessage());
......
......@@ -36,7 +36,7 @@ public class ProloGraalProofTreeNode extends Node {
ProloGraalTerm<?> currentGoal = goals.getFirst();
List<ProloGraalClause> possibleClauses = clauses.get(currentGoal);
if(possibleClauses == null || possibleClauses.isEmpty()) // if no match, throw an error
throw new ProloGraalExistenceError();
throw new ProloGraalExistenceError(currentGoal);
List<ProloGraalProofTreeNode> branches = new ArrayList<>();
......
......@@ -34,17 +34,15 @@ public final class ProloGraalResolverNode extends RootNode {
System.out.println("Executing : " + goalRuntime.getFirstClause());
}
ProloGraalTerm<?> head = goalRuntime.getFirstClause().getHead();
Deque<ProloGraalTerm<?>> goals = new ArrayDeque<>();
goals.push(head);
ProloGraalClause clause = goalRuntime.getFirstClause();
Deque<ProloGraalTerm<?>> goals = new ArrayDeque<>(clause.getGoals());
ProloGraalProofTreeNode proofTreeNode = new ProloGraalProofTreeNode(clauses, goals);
treeNode = this.insert(proofTreeNode); // FIXME handle multiples goals
ProloGraalBoolean r = treeNode.execute();
if(r.asBoolean()) {
r = new ProloGraalSuccess(head.getVariables());
r = new ProloGraalSuccess(clause.getVariables());
}
return r;
}
......
% fact.
yes
% fact2.
Error : no clause for goal 'fact2:-.'
Error : no clause for goal 'fact2'
% fact(X).
Error : no clause for goal 'fact/1(X):-.'
Error : no clause for goal 'fact/1(X)'
% hello(world).
yes
% hello(world2).
......@@ -23,7 +23,7 @@ no
% this(is(getting, a(bit(out, of, hand)))).
yes
% fact(world).
Error : no clause for goal 'fact/1(world):-.'
Error : no clause for goal 'fact/1(world)'
% EOF
yes
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment