Le support aux utilisateurs et les demandes de création de comptes externes doivent être faites depuis les issues du projet GitLab HEFR (https://gitlab.forge.hefr.ch/forge-hefr/gitlab-hefr)

Commit 533c942c authored by Tony Licata's avatar Tony Licata
Browse files

added PV06, cleaned is/2 class (adding isOperators class)

parent 3c7df11c
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="RemoteRepositoriesConfiguration">
<remote-repository>
<option name="id" value="central" />
<option name="name" value="Central Repository" />
<option name="url" value="https://repo.maven.apache.org/maven2" />
</remote-repository>
<remote-repository>
<option name="id" value="central" />
<option name="name" value="Maven Central repository" />
<option name="url" value="https://repo1.maven.org/maven2" />
</remote-repository>
<remote-repository>
<option name="id" value="jboss.community" />
<option name="name" value="JBoss Community repository" />
<option name="url" value="https://repository.jboss.org/nexus/content/repositories/public/" />
</remote-repository>
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Perl5LocalSettings">
<option name="DISABLE_ASSOCIATIONS_CHECKING" value="true" />
</component>
</project>
\ No newline at end of file
package ch.heiafr.prolograal.builtins;
import ch.heiafr.prolograal.runtime.ProloGraalAtom;
/**
* Class containing the different built-in atoms.
* Unlike built-in predicates, these are meant for internal use.
* @author Martin Spoto
* @see ProloGraalAtom
*/
public final class ProloGraalBuiltinAtoms {
public static final ProloGraalAtom EMPTY_LIST = new ProloGraalAtom(null, "[]");
public static final ProloGraalAtom DOT_OPERATOR = new ProloGraalAtom(null, ".");
}
\ No newline at end of file
package ch.heiafr.prolograal.builtins.predicates;
import ch.heiafr.prolograal.builtins.ProloGraalIsOperators;
import ch.heiafr.prolograal.runtime.*;
import com.oracle.truffle.api.CompilerDirectives;
import com.oracle.truffle.api.dsl.NodeChild;
import com.oracle.truffle.api.dsl.Specialization;
import com.oracle.truffle.api.frame.VirtualFrame;
import java.io.PrintWriter;
import java.util.*;
......@@ -13,16 +17,16 @@ import java.util.function.Function;
* @author Licata Tony
* @see ProloGraalBuiltinClause
*/
public final class ProloGraalIsBuiltin extends ProloGraalBuiltinClause {
public class ProloGraalIsBuiltin extends ProloGraalBuiltinClause {
private final PrintWriter writer; // used for outputting
private final ProloGraalContext context; // we keep the context for the copy method
private ProloGraalVariable arg; // the variable A in is(A,B). We keep it to use it in the execute method
private ProloGraalVariable arg2; // the variable B in is(A,B). We keep it to use it in the execute 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
// 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 = fillOperations();
private static final Map<ProloGraalAtom, Function<List<ProloGraalNumber>,ProloGraalNumber>> operations = ProloGraalIsOperators.getOperationsMap();
public ProloGraalIsBuiltin(ProloGraalContext context) {
super();
......@@ -44,6 +48,13 @@ public final class ProloGraalIsBuiltin extends ProloGraalBuiltinClause {
setHead(head);
}
public ProloGraalBoolean executeFastPath() {
if(arg.unify(arg2))
return new ProloGraalSuccess(getVariables());
return new ProloGraalFailure();
}
/**
* Execute the is/2 predicate, unifying the left variable with the result
*/
......@@ -107,183 +118,4 @@ public final class ProloGraalIsBuiltin extends ProloGraalBuiltinClause {
public ProloGraalClause copy() {
return new ProloGraalIsBuiltin(context);
}
/* is/2 operators */
private static ProloGraalNumber pi(List<ProloGraalNumber> args) {
if (!args.isEmpty()) return null;
return new ProloGraalDoubleNumber(new HashMap<>(), Math.PI);
}
private static ProloGraalNumber e(List<ProloGraalNumber> args) {
if (!args.isEmpty()) return null;
return new ProloGraalDoubleNumber(new HashMap<>(), Math.E);
}
private static ProloGraalNumber tau(List<ProloGraalNumber> args) {
if (!args.isEmpty()) return null;
return new ProloGraalDoubleNumber(new HashMap<>(), Math.PI * 2);
}
private static ProloGraalNumber add(List<ProloGraalNumber> args) {
if (args.size() != 2) return null;
ProloGraalNumber arg0 = args.get(0), arg1 = args.get(1);
if (areAllIntegers(arg0, arg1))
return new ProloGraalIntegerNumber(new HashMap<>(), arg0.asInteger() + arg1.asInteger());
return new ProloGraalDoubleNumber(new HashMap<>(), arg0.asDouble() + arg1.asDouble());
}
private static ProloGraalNumber substract(List<ProloGraalNumber> args) {
if (args.size() != 2) return null;
ProloGraalNumber arg0 = args.get(0), arg1 = args.get(1);
if (areAllIntegers(arg0, arg1))
return new ProloGraalIntegerNumber(new HashMap<>(), arg0.asInteger() - arg1.asInteger());
return new ProloGraalDoubleNumber(new HashMap<>(), arg0.asDouble() - arg1.asDouble());
}
private static ProloGraalNumber multiply(List<ProloGraalNumber> args) {
if (args.size() != 2) return null;
ProloGraalNumber arg0 = args.get(0), arg1 = args.get(1);
if (areAllIntegers(arg0, arg1))
return new ProloGraalIntegerNumber(new HashMap<>(), arg0.asInteger() * arg1.asInteger());
return new ProloGraalDoubleNumber(new HashMap<>(), arg0.asDouble() * arg1.asDouble());
}
private static ProloGraalNumber divide(List<ProloGraalNumber> args) {
if (args.size() != 2) return null;
return new ProloGraalDoubleNumber(new HashMap<>(), args.get(0).asDouble() / args.get(1).asDouble());
}
private static ProloGraalNumber pow(List<ProloGraalNumber> args) {
if (args.size() != 2) return null;
ProloGraalNumber arg0 = args.get(0), arg1 = args.get(1);
if (areAllIntegers(arg0, arg1) && Math.abs(Math.pow(arg0.asInteger(), arg1.asInteger())) < Integer.MAX_VALUE)
return new ProloGraalIntegerNumber(new HashMap<>(), (int) Math.pow(arg0.asInteger(), arg1.asInteger()));
return new ProloGraalDoubleNumber(new HashMap<>(), Math.pow(arg0.asDouble(), arg1.asDouble()));
}
private static ProloGraalNumber sqrt(List<ProloGraalNumber> args) {
if (args.size() != 1) return null;
return new ProloGraalDoubleNumber(new HashMap<>(), Math.sqrt(args.get(0).asDouble()));
}
private static ProloGraalNumber rem(List<ProloGraalNumber> args) {
if (args.size() != 2) return null;
ProloGraalNumber arg0 = args.get(0), arg1 = args.get(1);
if (areAllIntegers(arg0, arg1))
return new ProloGraalIntegerNumber(new HashMap<>(), arg0.asInteger() % arg1.asInteger());
return new ProloGraalDoubleNumber(new HashMap<>(), arg0.asDouble() % arg1.asDouble());
}
private static ProloGraalNumber mod(List<ProloGraalNumber> args) {
if (args.size() != 2) return null;
ProloGraalNumber arg0 = args.get(0), arg1 = args.get(1);
double ad = arg0.asDouble();
double bd = arg1.asDouble();
double res = ((ad % bd + bd) % bd);
if (areAllIntegers(arg0, arg1))
return new ProloGraalIntegerNumber(new HashMap<>(), (int) res);
return new ProloGraalDoubleNumber(new HashMap<>(), res);
}
private static ProloGraalNumber sign(List<ProloGraalNumber> args) {
if (args.size() != 1) return null;
double val = args.get(0).asDouble();
int res = 0;
if (val > 0) res = 1;
if (val < 0) res = -1;
return new ProloGraalIntegerNumber(new HashMap<>(), res);
}
private static ProloGraalNumber exp(List<ProloGraalNumber> args) {
if (args.size() != 1) return null;
return new ProloGraalDoubleNumber(new HashMap<>(), Math.exp(args.get(0).asDouble()));
}
private static ProloGraalNumber log(List<ProloGraalNumber> args) {
if (args.size() != 1) return null;
return new ProloGraalDoubleNumber(new HashMap<>(), Math.log(args.get(0).asDouble()));
}
private static ProloGraalNumber sin(List<ProloGraalNumber> args) {
if (args.size() != 1) return null;
return new ProloGraalDoubleNumber(new HashMap<>(), Math.sin(args.get(0).asDouble()));
}
private static ProloGraalNumber cos(List<ProloGraalNumber> args) {
if (args.size() != 1) return null;
return new ProloGraalDoubleNumber(new HashMap<>(), Math.cos(args.get(0).asDouble()));
}
private static ProloGraalNumber tan(List<ProloGraalNumber> args) {
if (args.size() != 1) return null;
return new ProloGraalDoubleNumber(new HashMap<>(), Math.tan(args.get(0).asDouble()));
}
private static ProloGraalNumber asin(List<ProloGraalNumber> args) {
if (args.size() != 1) return null;
return new ProloGraalDoubleNumber(new HashMap<>(), Math.asin(args.get(0).asDouble()));
}
private static ProloGraalNumber acos(List<ProloGraalNumber> args) {
if (args.size() != 1) return null;
return new ProloGraalDoubleNumber(new HashMap<>(), Math.acos(args.get(0).asDouble()));
}
private static ProloGraalNumber atan(List<ProloGraalNumber> args) {
if (args.size() != 1) return null;
return new ProloGraalDoubleNumber(new HashMap<>(), Math.atan(args.get(0).asDouble()));
}
private static ProloGraalNumber atan2(List<ProloGraalNumber> args) {
if (args.size() != 2) return null;
return new ProloGraalDoubleNumber(new HashMap<>(), Math.atan2(args.get(0).asDouble(), args.get(1).asDouble()));
}
private static ProloGraalNumber abs(List<ProloGraalNumber> args) {
if (args.size() != 1) return null;
ProloGraalNumber arg0 = args.get(0);
if (areAllIntegers(arg0))
return new ProloGraalIntegerNumber(new HashMap<>(), Math.abs(arg0.asInteger()));
return new ProloGraalDoubleNumber(new HashMap<>(), Math.abs(arg0.asDouble()));
}
private static Map<ProloGraalAtom, Function<List<ProloGraalNumber>,ProloGraalNumber>> fillOperations(){
Map<ProloGraalAtom, Function<List<ProloGraalNumber>,ProloGraalNumber>> operationsMap = new HashMap<>();
addOpperation(operationsMap,"pi",ProloGraalIsBuiltin::pi);
addOpperation(operationsMap,"e",ProloGraalIsBuiltin::e);
addOpperation(operationsMap,"tau",ProloGraalIsBuiltin::tau);
addOpperation(operationsMap,"+",ProloGraalIsBuiltin::add);
addOpperation(operationsMap,"-",ProloGraalIsBuiltin::substract);
addOpperation(operationsMap,"*",ProloGraalIsBuiltin::multiply);
addOpperation(operationsMap,"/",ProloGraalIsBuiltin::divide);
addOpperation(operationsMap,"**",ProloGraalIsBuiltin::pow);
addOpperation(operationsMap,"^",ProloGraalIsBuiltin::pow);
addOpperation(operationsMap,"sqrt",ProloGraalIsBuiltin::sqrt);
addOpperation(operationsMap,"rem",ProloGraalIsBuiltin::rem);
addOpperation(operationsMap,"mod",ProloGraalIsBuiltin::mod);
addOpperation(operationsMap,"sign",ProloGraalIsBuiltin::sign);
addOpperation(operationsMap,"exp",ProloGraalIsBuiltin::exp);
addOpperation(operationsMap,"log",ProloGraalIsBuiltin::log);
addOpperation(operationsMap,"sin",ProloGraalIsBuiltin::sin);
addOpperation(operationsMap,"cos",ProloGraalIsBuiltin::cos);
addOpperation(operationsMap,"tan",ProloGraalIsBuiltin::tan);
addOpperation(operationsMap,"asin",ProloGraalIsBuiltin::asin);
addOpperation(operationsMap,"acos",ProloGraalIsBuiltin::acos);
addOpperation(operationsMap,"atan",ProloGraalIsBuiltin::atan);
addOpperation(operationsMap,"atan2",ProloGraalIsBuiltin::atan2);
addOpperation(operationsMap,"abs",ProloGraalIsBuiltin::abs);
return operationsMap;
}
private static void addOpperation(Map<ProloGraalAtom, Function<List<ProloGraalNumber>,ProloGraalNumber>> operations,
String atomName,
Function<List<ProloGraalNumber>,ProloGraalNumber> function){
operations.put(new ProloGraalAtom(new HashMap<>(),atomName), function);
}
private static boolean areAllIntegers(ProloGraalNumber<?>... args){
for (ProloGraalNumber number : args)
if(!number.isInteger())return false;
return true;
}
}
![Logo HEIAFR](logo.png)
# PV de séance du 17.06, 08h30
Membres : Frédéric Bapst, Tony Licata
Lieu : domicile
## Ordre du jour
- validation du précédant PV
- point sur les tests unitaires
- point sur le profiling
- point sur les optimisations actuelles
- avancements avec l'annotation de spécialisation
## Validation du précédant PV
le précédant PV a été validé
## Objectifs du projet
- l'alternative trouvée pour les tests unitaires est acceptée, garder une trace de ce problème
- il est bien dommage de ne pas pouvoir profiler ProloGraal, mais au vue des priorités, il a été décidé de ne pas continuer les investigations pour le moment
- bien identifier dans ProloGraal les noeuds Truffle actuel, quels éléments de ProloGraal devraient être des noeuds Truffle?
## Tâches à réaliser
- transformer en noeuds Truffle les composants de ProloGraal qui y sont propices
- ajouter des @Specialization Truffle aux composants ProloGraal récemment transformés en noeuds Truffle
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