Access Control is now enabled for Gitlab Pages so you can now restrict Pages to authorized users only. If needed, make your website publicly available : Navigate to your project's Settings > General > Visibility and select Everyone in pages section.

Commit a168fb7e authored by Tony Licata's avatar Tony Licata

Fixed bug where variable stocked into isBuiltinHeadNode wasn't the same as...

Fixed bug where variable stocked into isBuiltinHeadNode wasn't the same as clause variable, can now unify correctly variables with isBuiltinHeadNode.
Added ProloGraalIsOpTermNode to prepare is operators handling as Truffle Nodes.
parent bb4ea2be
......@@ -38,7 +38,6 @@ public abstract class ProloGraalBuiltinClause extends ProloGraalClause implement
}
public static ProloGraalBuiltinStructure initializeIs(ProloGraalTerm isTerm){
System.out.println(isTerm);
if( !(isTerm.isStructure() && isTerm.asStructure().getArity() == 2) )
return null;
List<ProloGraalTerm<?>> isArgs = isTerm.asStructure().getArguments();
......
......@@ -21,7 +21,6 @@ import java.util.function.Function;
@NodeInfo(shortName = "ProloGraalIsBuiltinNode")
public abstract class ProloGraalIsBuiltin extends ProloGraalBuiltinClause {
private final ProloGraalContext context; // we keep the context for the copy method
ProloGraalVariable arg; // the variable A in is(A,B). We keep it to use it in the execute method
ProloGraalVariable arg2; // the variable B in is(A,B). We keep it to use it in the execute method
......@@ -29,9 +28,8 @@ public abstract class ProloGraalIsBuiltin extends ProloGraalBuiltinClause {
// we fill the operations map to check the operator used by the user later in the execute method
private static final Map<ProloGraalAtom, Function<List<ProloGraalNumber>,ProloGraalNumber>> operations = ProloGraalIsOperators.getOperationsMap();
public ProloGraalIsBuiltin(ProloGraalContext context) {
super(new HashMap<>());
this.context = context;
public ProloGraalIsBuiltin(Map<ProloGraalVariable,ProloGraalVariable> variables) {
super(variables);
// create the head of this clause
// since we do not need custom unification, a simple structure is enough
......@@ -58,9 +56,6 @@ public abstract class ProloGraalIsBuiltin extends ProloGraalBuiltinClause {
@Specialization
public ProloGraalBoolean returnHead(VirtualFrame frame, ProloGraalBoolean head){
return head;
/*
List<ProloGraalTerm<?>> headArgs = ((ProloGraalStructure) head).getArguments();
return headArgs.get(0).unify(headArgs.get(1))?new ProloGraalSuccess(getVariables()):new ProloGraalFailure();*/
}
/**
......@@ -131,9 +126,10 @@ public abstract class ProloGraalIsBuiltin extends ProloGraalBuiltinClause {
public ProloGraalClause copy() {
List<Node> childrens = NodeUtil.findNodeChildren(this);
ProloGraalTerm head = ((ProloGraalBuiltinHeadNode)childrens.get(0)).getValue();
ProloGraalTerm copiedHead = head.copy(new HashMap<>());
Map<ProloGraalVariable, ProloGraalVariable> newVars = new HashMap<>();
ProloGraalTerm copiedHead = head.copy(newVars);
List<ProloGraalTerm<?>> headArgs = copiedHead.asStructure().getArguments();
return ProloGraalIsBuiltinNodeGen.create(context, ProloGraalIsHeadNodeGen.create(copiedHead,new ProloGraalSimpleTermNode(headArgs.get(0)),new ProloGraalSimpleTermNode(headArgs.get(1))));
return ProloGraalIsBuiltinNodeGen.create(newVars, ProloGraalIsHeadNodeGen.create(copiedHead,new ProloGraalSimpleTermNode(headArgs.get(0)),new ProloGraalSimpleTermNode(headArgs.get(1))));
}
// override getHead method to handle AST node head
......
......@@ -8,8 +8,8 @@ import com.oracle.truffle.api.instrumentation.GenerateWrapper;
import com.oracle.truffle.api.instrumentation.InstrumentableNode;
import com.oracle.truffle.api.instrumentation.ProbeNode;
import com.oracle.truffle.api.nodes.NodeInfo;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@TypeSystemReference(ProloGraalTypes.class)
@NodeInfo(shortName = "ProloGraalBuiltinHeadNode")
......@@ -35,7 +35,7 @@ public abstract class ProloGraalBuiltinHeadNode extends ProloGraalGenericNode im
public abstract ProloGraalBoolean executeBuiltin(VirtualFrame frame);
//public abstract ProloGraalObject executeGeneric(VirtualFrame frame);
public abstract ProloGraalBuiltinHeadNode copyBuiltin(Map<ProloGraalVariable, ProloGraalVariable> variables);
public boolean isInstrumentable() {
return true;
......
......@@ -70,10 +70,6 @@ public final class ProloGraalEvalRootNode extends RootNode {
for(ProloGraalQuery request : queries){
Deque<Integer> currentBranches = new ArrayDeque<>();
ProloGraalAtom head = new ProloGraalAtom(request.getVariables(),"goals");
ProloGraalTermNode[] goalsArray = new ProloGraalTermNode[request.getGoals().size()];
for (int i = 0; i < request.getGoals().size(); i++) {
goalsArray[i] = new ProloGraalSimpleTermNode(request.getGoals().get(i));
}
ProloGraalClause goal;
goal = new ProloGraalClause(request.getVariables());//ProloGraalClauseNodeGen.create(request.getVariables(), new ProloGraalSimpleTermNode(head),goalsArray);
goal.setHead(head);
......
......@@ -5,9 +5,12 @@ import ch.heiafr.prolograal.builtins.predicates.ProloGraalIsBuiltin;
import ch.heiafr.prolograal.runtime.*;
import com.oracle.truffle.api.dsl.Specialization;
import com.oracle.truffle.api.frame.VirtualFrame;
import com.oracle.truffle.api.nodes.Node;
import com.oracle.truffle.api.nodes.NodeInfo;
import com.oracle.truffle.api.nodes.NodeUtil;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
@NodeInfo(shortName = "ProloGraalIsHeadNode")
......@@ -23,16 +26,33 @@ public abstract class ProloGraalIsHeadNode extends ProloGraalBinaryHeadNode {
return new ProloGraalSuccess();
}*/
@Specialization(guards = "right.isStructure()")
public ProloGraalBoolean returnValue(VirtualFrame frame, ProloGraalVariable left, ProloGraalIntegerNumber right) {
@Specialization
public ProloGraalBoolean returnValue(VirtualFrame frame, ProloGraalVariable left, ProloGraalStructure right) {
System.out.println("@Specialization: returnValue");
ProloGraalNumber res = ProloGraalIsBuiltin.getOperations().get(right.asStructure().getFunctor()).apply(right.asStructure().getArguments().stream().map(x -> x.asNumber()).collect(Collectors.toList()));
return left.unify(res)?new ProloGraalSuccess():new ProloGraalFailure();
return value.asStructure().getArguments().get(0).unify(res)?new ProloGraalSuccess(value.getVariables()):new ProloGraalFailure();
//return left.unify(res)?new ProloGraalSuccess(left.getVariables()):new ProloGraalFailure();
}
/*
@Specialization
public ProloGraalBoolean returnWithInteger(VirtualFrame frame, ProloGraalVariable left, ProloGraalIntegerNumber right) {
System.out.println("@Specialization: returnValue");
ProloGraalNumber res = ProloGraalIsBuiltin.getOperations().get(right.asStructure().getFunctor()).apply(right.asStructure().getArguments().stream().map(x -> x.asNumber()).collect(Collectors.toList()));
return left.unify(res)?new ProloGraalSuccess():new ProloGraalFailure();
}*/
@Specialization
public ProloGraalBoolean testVariable(VirtualFrame frame, ProloGraalTerm left, ProloGraalTerm right) {
System.out.println("@Specialization: testVariable");
return left.unify(right)||right.unify(left)?new ProloGraalSuccess():new ProloGraalFailure();
return left.unify(right)||right.unify(left)?new ProloGraalSuccess(left.getVariables()):new ProloGraalFailure();
}
@Override
public ProloGraalBuiltinHeadNode copyBuiltin(Map<ProloGraalVariable, ProloGraalVariable> variables){
List<Node> childrens = NodeUtil.findNodeChildren(this);
ProloGraalTermNode left = (ProloGraalTermNode) childrens.get(0);
ProloGraalTermNode right = (ProloGraalTermNode) childrens.get(1);
return ProloGraalIsHeadNodeGen.create(value.copy(variables), new ProloGraalSimpleTermNode(left.value.copy(variables)), new ProloGraalSimpleTermNode(right.value.copy(variables)));
}
}
package ch.heiafr.prolograal.nodes;
import ch.heiafr.prolograal.builtins.predicates.ProloGraalIsBuiltin;
import ch.heiafr.prolograal.runtime.ProloGraalNumber;
import ch.heiafr.prolograal.runtime.ProloGraalTerm;
import com.oracle.truffle.api.dsl.NodeChild;
import com.oracle.truffle.api.dsl.Specialization;
import com.oracle.truffle.api.frame.VirtualFrame;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.function.Function;
@NodeChild(value = "left", type = ProloGraalTermNode.class)
@NodeChild(value = "right", type = ProloGraalTermNode.class)
public abstract class ProloGraalIsOpTermNode extends ProloGraalTermNode {
private final Function<List<ProloGraalNumber>,ProloGraalNumber> operation;
public ProloGraalIsOpTermNode(ProloGraalTerm<?> value) {
super(value);
operation = ProloGraalIsBuiltin.getOperations().get(value.asStructure().getFunctor());
}
/*
@Override
public ProloGraalNumber executeTerm(VirtualFrame frame) {
return null;
}*/
@Specialization(guards = {"left == null","right == null"})
public ProloGraalNumber computeNoArgs(VirtualFrame frame, ProloGraalNumber left, ProloGraalNumber right){
return operation.apply(new ArrayList<>());
}
@Specialization(guards = "right == null")
public ProloGraalNumber computeUnary(VirtualFrame frame, ProloGraalNumber left, ProloGraalNumber right){
return operation.apply(Arrays.asList(left));
}
@Specialization
public ProloGraalNumber computeBinary(VirtualFrame frame, ProloGraalNumber left, ProloGraalNumber right){
return operation.apply(Arrays.asList(left,right));
}
}
......@@ -107,7 +107,6 @@ public class ProloGraalProofTreeNode extends Node {
}
if(currentGoal instanceof ProloGraalBuiltinStructure){
System.out.println("resolving builtin term");
returnedValue = ((ProloGraalBuiltinStructure)currentGoal).getBuiltin().executeBuiltin(frame);
executeState = ExecuteState.RETURN;
break;
......
......@@ -25,7 +25,7 @@ public class ProloGraalBuiltinStructure extends ProloGraalStructure{
@Override
public ProloGraalBuiltinStructure copy(Map<ProloGraalVariable, ProloGraalVariable> variables) {
ProloGraalBuiltinStructure struct = new ProloGraalBuiltinStructure(builtin);
ProloGraalBuiltinStructure struct = new ProloGraalBuiltinStructure(builtin.copyBuiltin(variables));
struct.setFunctor(this.functor.copy(variables));
this.subterms.forEach(x -> struct.addSubterm(x.copy(variables)));
return struct;
......
......@@ -65,7 +65,7 @@ public final class ProloGraalRuntime {
ProloGraalIsHeadNode isHeadNode = ProloGraalIsHeadNodeGen.create(isHead, new ProloGraalSimpleTermNode(arg), new ProloGraalSimpleTermNode(arg2));
ProloGraalClause isBuiltin = ProloGraalIsBuiltinNodeGen.create(context, isHeadNode);
ProloGraalClause isBuiltin = ProloGraalIsBuiltinNodeGen.create(new HashMap<>(), isHeadNode);
clauses.put(isBuiltin.getHead(), Collections.singletonList(isBuiltin));
ProloGraalClause useinterpreterBuiltin = new ProloGraalUseInterpreterBuiltin(context);
......
Markdown is supported
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