Skip to content
Snippets Groups Projects
Commit 09e791ea authored by Julien Lopez's avatar Julien Lopez
Browse files

Fix SQL translation of TruffleNode application (with one parameter only)

parent 46e3ee62
No related branches found
No related tags found
No related merge requests found
...@@ -115,19 +115,23 @@ public final class QIRSQLVisitor implements IQIRVisitor<String> { ...@@ -115,19 +115,23 @@ public final class QIRSQLVisitor implements IQIRVisitor<String> {
@Override @Override
public final String visit(final QIRApply qirApply) { public final String visit(final QIRApply qirApply) {
final Deque<String> args = new ArrayDeque<>(); final Deque<QIRNode> args = new ArrayDeque<>();
QIRNode curr = qirApply; QIRNode curr = qirApply;
if (qirApply.getRight() != null) if (qirApply.getRight() != null)
for (; curr instanceof QIRApply; curr = ((QIRApply) curr).getLeft()) for (; curr instanceof QIRApply; curr = ((QIRApply) curr).getLeft())
args.push(((QIRApply) curr).getRight().accept(this)); args.push(((QIRApply) curr).getRight());
else else
curr = qirApply.getLeft(); curr = qirApply.getLeft();
if (curr instanceof QIRTruffleNode) { if (curr instanceof QIRTruffleNode) {
// TODO: Handle more than one argument
final QIRNode arg = args.getFirst();
if (arg instanceof QIRVariable || arg instanceof QIRTdestr)
return "truffle.executeapply(" + curr.accept(this) + ", array[" + "truffle.translate(" + arg.accept(this) + ")" + "])";
final String id = genFreshId(); final String id = genFreshId();
return "(select truffle.executeapply(" + curr.accept(this) + ", array[" + "truffle.translate(" + id + ")" + "]) from (" + args.getFirst() + ") as " + id + ")"; return "(select truffle.executeapply(" + curr.accept(this) + ", array[" + "truffle.translate(" + id + ")" + "]) from (" + arg + ") as " + id + ")";
} }
return curr.accept(this) + "(" + args.stream().collect(Collectors.joining(", ")) + ")"; return curr.accept(this) + "(" + args.stream().map(arg -> arg.accept(this)).collect(Collectors.joining(", ")) + ")";
} }
@Override @Override
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment