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 64563b7c authored by Tony Licata's avatar Tony Licata

Can now call multiple time isHeadNode, node specialization is now working, we...

Can now call multiple time isHeadNode, node specialization is now working, we can now choose which method we will use to resolve the unification (see ProloGraalIsHeadNode.java)
Added ProloGraalTerm.isBoundVariable() method, permitting to know if a term is a bound variable (previously term.isVar() would be true only if term is an unbound var)
parent c7ae1d9a
package ch.heiafr.prolograal.builtins.predicates;
import ch.heiafr.prolograal.builtins.ProloGraalIsOperators;
import ch.heiafr.prolograal.nodes.ProloGraalBuiltinHeadNode;
import ch.heiafr.prolograal.nodes.ProloGraalIsHeadNode;
import ch.heiafr.prolograal.nodes.*;
import ch.heiafr.prolograal.runtime.*;
import com.oracle.truffle.api.dsl.Specialization;
import com.oracle.truffle.api.frame.VirtualFrame;
......@@ -37,7 +36,7 @@ public abstract class ProloGraalIsBuiltin extends ProloGraalBuiltinClause {
// create the head of this clause
// since we do not need custom unification, a simple structure is enough
ProloGraalStructure head = new ProloGraalStructure(getVariables());
head.setFunctor(new ProloGraalAtom(getVariables(), "is"));
head.setFunctor(new ProloGraalAtom(getVariables(), "testos"));
// we create and store the variables to access them more easily later in the execute method
arg = new ProloGraalVariable(getVariables(), "_");
......@@ -127,7 +126,10 @@ public abstract class ProloGraalIsBuiltin extends ProloGraalBuiltinClause {
@Override
public ProloGraalClause copy() {
List<Node> childrens = NodeUtil.findNodeChildren(this);
return ProloGraalIsBuiltinNodeGen.create(context, (ProloGraalBuiltinHeadNode)NodeUtil.cloneNode(childrens.get(0)));
ProloGraalTerm head = ((ProloGraalBuiltinHeadNode)childrens.get(0)).getValue();
ProloGraalTerm copiedHead = head.copy(new HashMap<>());
List<ProloGraalTerm<?>> headArgs = copiedHead.asStructure().getArguments();
return ProloGraalIsBuiltinNodeGen.create(context, ProloGraalIsHeadNodeGen.create(copiedHead,new ProloGraalSimpleTermNode(headArgs.get(0)),new ProloGraalSimpleTermNode(headArgs.get(1))));
}
// override getHead method to handle AST node head
......
......@@ -23,30 +23,21 @@ public abstract class ProloGraalIsHeadNode extends ProloGraalBinaryHeadNode {
}*/
@Specialization(guards = "left.isNumber()")
public ProloGraalBoolean returnValue(VirtualFrame frame, ProloGraalTerm left, ProloGraalTerm right) {
public ProloGraalBoolean returnValue(VirtualFrame frame, ProloGraalVariable left, ProloGraalVariable right) {
System.out.println("@Specialization: returnValue");
return left.unify(right)||right.unify(left)?new ProloGraalSuccess(buildVars(left, right)):new ProloGraalFailure();
return left.unify(right)||right.unify(left)?new ProloGraalSuccess():new ProloGraalFailure();
}
@Specialization
public ProloGraalBoolean testVariable(VirtualFrame frame, ProloGraalVariable left, ProloGraalVariable right) {
System.out.println("@Specialization: testVariable");
System.out.println(left);
System.out.println(right);
return left.unify(right)||right.unify(left)?new ProloGraalSuccess(buildVars(left, right)):new ProloGraalFailure();
}
private HashMap<ProloGraalVariable, ProloGraalVariable> buildVars(ProloGraalTerm left, ProloGraalTerm right){
HashMap<ProloGraalVariable,ProloGraalVariable> vars = new HashMap<>();
vars.putAll(left.getVariables());
vars.putAll(right.getVariables());
return vars;
@Specialization(guards = "left.isAtom()")
public ProloGraalBoolean executeIs(VirtualFrame frame, ProloGraalVariable left, ProloGraalVariable right) {
System.out.println("@Specialization: executeIs");
return left.unify(right)||right.unify(left)?new ProloGraalSuccess():new ProloGraalFailure();
}
/*
@Specialization
public ProloGraalBoolean executeIs(ProloGraalNumber left, ProloGraalNumber right) {
System.out.println("@Specialization: executeIs");
public ProloGraalBoolean testVariable(VirtualFrame frame, ProloGraalVariable left, ProloGraalVariable right) {
System.out.println("@Specialization: testVariable");
return left.unify(right)||right.unify(left)?new ProloGraalSuccess():new ProloGraalFailure();
}*/
}
}
......@@ -75,6 +75,11 @@ public final class ProloGraalAtom extends ProloGraalTerm<ProloGraalAtom> {
return false;
}
@Override
public boolean isBoundVariable() {
return false;
}
@Override
public boolean isStructure(){
return false;
......
......@@ -65,6 +65,11 @@ public abstract class ProloGraalNumber<T extends ProloGraalTerm<T>> extends Prol
return false;
}
@Override
public boolean isBoundVariable() {
return false;
}
@Override
public boolean equals(Object obj) {
return obj instanceof ProloGraalNumber && ((ProloGraalNumber<?>) obj).asDouble() == this.asDouble();
......
......@@ -57,10 +57,10 @@ public final class ProloGraalRuntime {
isHead.setFunctor(new ProloGraalAtom(isVars, "is"));
ProloGraalVariable arg = new ProloGraalVariable(isVars, "_");
ProloGraalVariable arg = new ProloGraalVariable(isVars, "Left");
isHead.addSubterm(arg);
ProloGraalVariable arg2 = new ProloGraalVariable(isVars, "op");
ProloGraalVariable arg2 = new ProloGraalVariable(isVars, "Right");
isHead.addSubterm(arg2);
ProloGraalIsHeadNode isHeadNode = ProloGraalIsHeadNodeGen.create(isHead, new ProloGraalSimpleTermNode(arg), new ProloGraalSimpleTermNode(arg2));
......
......@@ -196,6 +196,11 @@ public class ProloGraalStructure extends ProloGraalTerm<ProloGraalStructure> {
return false;
}
@Override
public boolean isBoundVariable() {
return false;
}
@Override
public boolean isAtom() {
return false;
......
......@@ -90,6 +90,8 @@ public abstract class ProloGraalTerm<T extends ProloGraalTerm<T>> extends ProloG
public abstract boolean isVariable();
public abstract boolean isBoundVariable();
public abstract boolean isStructure();
public ProloGraalAtom asAtom() throws ProloGraalTypeCastingError {
......
......@@ -236,7 +236,7 @@ public final class ProloGraalVariable extends ProloGraalTerm<ProloGraalVariable>
public void saveState() {
//System.out.println("Saving state " + this);
states.push(new ProloGraalVariable(this));
if (this.isBound && this.boundValue instanceof ProloGraalVariable) {
if (this.isBound && this.boundValue.isBoundVariable()) {
((ProloGraalVariable) this.boundValue).saveState();
}
}
......@@ -250,7 +250,7 @@ public final class ProloGraalVariable extends ProloGraalTerm<ProloGraalVariable>
this.isBound = previous.isBound;
this.boundValue = previous.boundValue;
//System.out.println("Restored state " + this);
if (this.isBound && this.boundValue instanceof ProloGraalVariable) {
if (this.isBound && this.boundValue.isBoundVariable()) {
((ProloGraalVariable) this.boundValue).revertState();
}
}
......@@ -260,6 +260,11 @@ public final class ProloGraalVariable extends ProloGraalTerm<ProloGraalVariable>
return !isBound;
}
@Override
public boolean isBoundVariable() {
return isBound;
}
@Override
public boolean isAtom() {
return isBound && boundValue instanceof ProloGraalAtom;
......
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