From ab59390567b87fb6ca6ec82b67b803feab506f1c Mon Sep 17 00:00:00 2001
From: Julien Lopez <julien.lopez@lri.fr>
Date: Tue, 7 Feb 2017 15:58:08 +0100
Subject: [PATCH] Update to new QIR version

---
 .../r/nodes/qirinterface/QIRInterface.java    | 21 ++++----
 .../qirinterface/QIRTranslateVisitor.java     | 48 ++++++++-----------
 2 files changed, 32 insertions(+), 37 deletions(-)

diff --git a/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/qirinterface/QIRInterface.java b/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/qirinterface/QIRInterface.java
index bddc97c681..df43310c74 100644
--- a/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/qirinterface/QIRInterface.java
+++ b/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/qirinterface/QIRInterface.java
@@ -33,6 +33,7 @@ import java.util.Map;
 import java.util.Properties;
 
 import com.oracle.truffle.api.frame.Frame;
+import com.oracle.truffle.api.frame.FrameDescriptor;
 import com.oracle.truffle.api.frame.FrameSlot;
 import com.oracle.truffle.api.source.Source;
 import com.oracle.truffle.api.source.SourceSection;
@@ -45,7 +46,7 @@ import com.oracle.truffle.r.runtime.env.REnvironment;
 
 import qir.ast.*;
 import qir.ast.data.*;
-import qir.ast.value.*;
+import qir.ast.expression.*;
 import qir.driver.sql.OracleDriver;
 import qir.driver.sql.PostgreSQLDriver;
 import qir.driver.ConnectionData;
@@ -106,9 +107,9 @@ public final class QIRInterface {
 
         for (Map<String, QIRVariable> fvs = QIRDriver.getFreeVars(query); !fvs.isEmpty(); fvs = QIRDriver.getFreeVars(query))
             for (final QIRVariable fv : fvs.values()) {
-                final String varName = fv.getId();
+                final String varName = fv.id;
                 final FrameSlot varSlot = frame.getFrameDescriptor().findFrameSlot(varName);
-                query = new QIRApply(dummy, new QIRLambda(dummy, null, new QIRVariable(dummy, varName, varSlot), query),
+                query = new QIRApply(dummy, new QIRLambda(dummy, null, new QIRVariable(dummy, varName, varSlot), query, new FrameDescriptor()),
                                 RToQIRType(fv.sourceSection, varSlot != null ? frame.getValue(varSlot) : RContext.lookupBuiltin(varName)));
             }
         return query;
@@ -205,7 +206,7 @@ public final class QIRInterface {
         if (value instanceof Double)
             return new QIRDouble(src, (Double) value);
         if (value instanceof Boolean)
-            return (Boolean) value ? QIRBoolean.qirTrue : QIRBoolean.qirFalse;
+            return QIRBoolean.create((Boolean) value);
         if (value instanceof String)
             return new QIRString(src, (String) value);
         if (value instanceof REnvironment) {
@@ -236,16 +237,16 @@ public final class QIRInterface {
             if (fun.isBuiltin())
                 switch (fun.getName()) {
                     case "new.env":
-                        return new QIRLambda(src, "new.env", new QIRVariable(null, "_", null), QIRTnil.instance);
+                        return new QIRLambda(src, "new.env", new QIRVariable(null, "_", null), QIRTnil.instance, new FrameDescriptor());
                     case "return":
                     case "(": {
                         final QIRVariable x = new QIRVariable(null, "x", null);
-                        return new QIRLambda(src, "identity", x, x);
+                        return new QIRLambda(src, "identity", x, x, new FrameDescriptor());
                     }
                     case "c": {
                         // TODO: This works only for lists with one element
                         final QIRVariable x = new QIRVariable(null, "x", null);
-                        return new QIRLambda(src, "lcons", x, new QIRLcons(null, x, QIRLnil.instance));
+                        return new QIRLambda(src, "lcons", x, new QIRLcons(null, x, QIRLnil.instance), new FrameDescriptor());
                     }
                     case "sum":
                         return new QIRBuiltin(src, "sum");
@@ -257,15 +258,15 @@ public final class QIRInterface {
         throw new RuntimeException("Unsupported value: " + value);
     }
 
-    private static final <T> QIRNode RFunctionToQIRType(final SourceSection src, final String funName, final FunctionDefinitionNode fun) {
+    private static final QIRNode RFunctionToQIRType(final SourceSection src, final String funName, final FunctionDefinitionNode fun) {
         try {
             QIRNode res = ((FunctionDefinitionNode) fun.getCallTarget().getRootNode()).getBody().accept(QIRTranslateVisitor.instance);
             final String[] args = ((FunctionDefinitionNode) fun.getCallTarget().getRootNode()).getSignature().getNames();
 
             if (args.length == 0)
-                return new QIRLambda(src, funName, null, res);
+                return new QIRLambda(src, funName, null, res, new FrameDescriptor());
             for (int i = 0; i < args.length; i++)
-                res = new QIRLambda(src, funName, new QIRVariable(null, args[i], null), res);
+                res = new QIRLambda(src, funName, new QIRVariable(null, args[i], null), res, new FrameDescriptor());
             return res;
         } catch (UnsupportedOperationException e) {
             final SourceSection funSrc = fun.getCallTarget().getRootNode().getSourceSection();
diff --git a/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/qirinterface/QIRTranslateVisitor.java b/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/qirinterface/QIRTranslateVisitor.java
index 1a53f3547b..3f65ed370b 100644
--- a/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/qirinterface/QIRTranslateVisitor.java
+++ b/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/qirinterface/QIRTranslateVisitor.java
@@ -4,6 +4,7 @@ import java.util.Arrays;
 import java.util.List;
 import java.util.stream.Collectors;
 
+import com.oracle.truffle.api.frame.FrameDescriptor;
 import com.oracle.truffle.api.source.Source;
 import com.oracle.truffle.api.source.SourceSection;
 import com.oracle.truffle.r.nodes.RSyntaxNodeVisitor;
@@ -23,18 +24,11 @@ import com.oracle.truffle.r.runtime.nodes.RNode;
 import com.oracle.truffle.r.runtime.nodes.RSyntaxNode;
 
 import qir.ast.*;
-import qir.ast.data.QIRTcons;
-import qir.ast.data.QIRTdestr;
-import qir.ast.expression.arithmetic.QIRDiv;
-import qir.ast.expression.arithmetic.QIRMinus;
-import qir.ast.expression.arithmetic.QIRPlus;
-import qir.ast.expression.arithmetic.QIRStar;
-import qir.ast.expression.logic.QIRAnd;
-import qir.ast.expression.logic.QIRNot;
-import qir.ast.expression.logic.QIROr;
-import qir.ast.expression.relational.QIREqual;
-import qir.ast.expression.relational.QIRLowerOrEqual;
-import qir.ast.expression.relational.QIRLowerThan;
+import qir.ast.data.*;
+import qir.ast.expression.QIRNull;
+import qir.ast.expression.arithmetic.*;
+import qir.ast.expression.logic.*;
+import qir.ast.expression.relational.*;
 import qir.ast.operator.*;
 
 /**
@@ -88,7 +82,7 @@ public final class QIRTranslateVisitor implements RSyntaxNodeVisitor<QIRNode> {
                 final RNode value = ((WriteLocalFrameVariableNode) child).getRhs();
 
                 // If the assignment value reads an argument, then we translate to a lambda.
-                result = new QIRLambda(dummy, null, new QIRVariable(dummy, (String) ((WriteLocalFrameVariableNode) child).getName(), null), result);
+                result = new QIRLambda(dummy, null, new QIRVariable(dummy, (String) ((WriteLocalFrameVariableNode) child).getName(), null), result, new FrameDescriptor());
                 // Else we apply STRAD-ASSIGN-ID normally
                 if (!(value instanceof AccessArgumentNode))
                     result = new QIRApply(dummy, result, value.asRSyntaxNode().accept(this));
@@ -96,7 +90,7 @@ public final class QIRTranslateVisitor implements RSyntaxNodeVisitor<QIRNode> {
                 final RNode value = ((ReplacementDispatchNode) child).rhs;
 
                 // If the assignment value reads an argument, then we translate to a lambda.
-                result = new QIRLambda(dummy, null, new QIRVariable(dummy, ((ReadVariableNode) ((ReplacementDispatchNode) child).lhs).getIdentifier(), null), result);
+                result = new QIRLambda(dummy, null, new QIRVariable(dummy, ((ReadVariableNode) ((ReplacementDispatchNode) child).lhs).getIdentifier(), null), result, new FrameDescriptor());
                 // Else we apply STRAD-ASSIGN-ID normally
                 if (!(value instanceof AccessArgumentNode))
                     result = new QIRApply(dummy, result, value.asRSyntaxNode().accept(this));
@@ -109,7 +103,7 @@ public final class QIRTranslateVisitor implements RSyntaxNodeVisitor<QIRNode> {
                 final ReadVariableNode receiver = (ReadVariableNode) lhs.getSyntaxArguments()[0];
                 final ConstantNode eid = (ConstantNode) lhs.getSyntaxArguments()[1];
                 final RNode value = repl.rhs;
-                result = new QIRApply(dummy, new QIRLambda(dummy, null, new QIRVariable(dummy, receiver.getIdentifier(), null), result),
+                result = new QIRApply(dummy, new QIRLambda(dummy, null, new QIRVariable(dummy, receiver.getIdentifier(), null), result, new FrameDescriptor()),
                                 new QIRTcons(dummy, (String) eid.getValue(), value.asRSyntaxNode().accept(this), receiver.accept(this)));
             } else
                 throw new UnsupportedOperationException("Cannot translate \"" + block.getSourceSection() + "\" to QIR: untranslatable sequence.");
@@ -160,31 +154,31 @@ public final class QIRTranslateVisitor implements RSyntaxNodeVisitor<QIRNode> {
             case "$":
                 return new QIRTdestr(dot.getSourceSection(), nodes.get(0), (String) ((ConstantNode) dot.getSyntaxArguments()[1]).getValue());
             case "+":
-                return new QIRPlus(dot.getSourceSection(), nodes.get(0), nodes.get(1));
+                return QIRPlusNodeGen.create(dot.getSourceSection(), nodes.get(0), nodes.get(1));
             case "-":
-                return new QIRMinus(dot.getSourceSection(), nodes.get(0), nodes.get(1));
+                return QIRMinusNodeGen.create(dot.getSourceSection(), nodes.get(0), nodes.get(1));
             case "*":
-                return new QIRStar(dot.getSourceSection(), nodes.get(0), nodes.get(1));
+                return QIRStarNodeGen.create(dot.getSourceSection(), nodes.get(0), nodes.get(1));
             case "/":
-                return new QIRDiv(dot.getSourceSection(), nodes.get(0), nodes.get(1));
+                return QIRDivNodeGen.create(dot.getSourceSection(), nodes.get(0), nodes.get(1));
             case "==":
-                return new QIREqual(dot.getSourceSection(), nodes.get(0), nodes.get(1));
+                return QIREqualNodeGen.create(dot.getSourceSection(), nodes.get(0), nodes.get(1));
             case "&":
             case "&&":
-                return new QIRAnd(dot.getSourceSection(), nodes.get(0), nodes.get(1));
+                return QIRAndNodeGen.create(dot.getSourceSection(), nodes.get(0), nodes.get(1));
             case "|":
             case "||":
-                return new QIROr(dot.getSourceSection(), nodes.get(0), nodes.get(1));
+                return QIROrNodeGen.create(dot.getSourceSection(), nodes.get(0), nodes.get(1));
             case "<=":
-                return new QIRLowerOrEqual(dot.getSourceSection(), nodes.get(0), nodes.get(1));
+                return QIRLowerOrEqualNodeGen.create(dot.getSourceSection(), nodes.get(0), nodes.get(1));
             case "<":
-                return new QIRLowerThan(dot.getSourceSection(), nodes.get(0), nodes.get(1));
+                return QIRLowerThanNodeGen.create(dot.getSourceSection(), nodes.get(0), nodes.get(1));
             case ">=":
-                return new QIRNot(dot.getSourceSection(), new QIRLowerThan(dot.getSourceSection(), nodes.get(0), nodes.get(1)));
+                return QIRNotNodeGen.create(dot.getSourceSection(), QIRLowerThanNodeGen.create(dot.getSourceSection(), nodes.get(0), nodes.get(1)));
             case ">":
-                return new QIRNot(dot.getSourceSection(), new QIRLowerOrEqual(dot.getSourceSection(), nodes.get(0), nodes.get(1)));
+                return QIRNotNodeGen.create(dot.getSourceSection(), QIRLowerOrEqualNodeGen.create(dot.getSourceSection(), nodes.get(0), nodes.get(1)));
             case "!":
-                return new QIRNot(dot.getSourceSection(), nodes.get(0));
+                return QIRNotNodeGen.create(dot.getSourceSection(), nodes.get(0));
             default:
                 throw new RuntimeException("Unknown call special node: " + name);
         }
-- 
GitLab