Skip to content

Commit

Permalink
format
Browse files Browse the repository at this point in the history
  • Loading branch information
alexzerntev committed Jan 26, 2024
1 parent 7cd7dc6 commit 78dddcd
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
import raw.runtime.truffle.ast.expressions.binary.MultNodeGen;
import raw.runtime.truffle.ast.expressions.binary.SubNodeGen;
import raw.runtime.truffle.ast.expressions.function.ClosureNode;
import raw.runtime.truffle.ast.expressions.function.InvokeWithNamesNode;
import raw.runtime.truffle.ast.expressions.function.InvokeNode;
import raw.runtime.truffle.ast.expressions.function.LambdaNode;
import raw.runtime.truffle.ast.expressions.function.MethodNode;
import raw.runtime.truffle.ast.expressions.literals.*;
Expand Down Expand Up @@ -394,7 +394,7 @@ case FunApp fa when tipe(fa.f()) instanceof PackageEntryType -> {
case FunApp fa -> {
String[] argNames = JavaConverters.asJavaCollection(fa.args()).stream().map(a -> a.idn().isDefined() ? a.idn().get() : null).toArray(String[]::new);
ExpressionNode[] exps = JavaConverters.asJavaCollection(fa.args()).stream().map(a -> recurseExp(a.e())).toArray(ExpressionNode[]::new);
yield new InvokeWithNamesNode(recurseExp(fa.f()), argNames, exps);
yield new InvokeNode(recurseExp(fa.f()), argNames, exps);
}
default -> throw new RawTruffleInternalErrorException("Unknown expression type");
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,38 +19,21 @@
import com.oracle.truffle.api.nodes.ExplodeLoop;
import com.oracle.truffle.api.nodes.NodeInfo;
import raw.runtime.truffle.ExpressionNode;
import raw.runtime.truffle.runtime.function.FunctionExecuteNodes;
import raw.runtime.truffle.runtime.function.FunctionExecuteNodesFactory;
import raw.runtime.truffle.runtime.function.Lambda;

@NodeInfo(shortName = "InvokeWithNames")
public final class InvokeWithNamesNode extends ExpressionNode {
public final class InvokeNode extends ExpressionNode {

@Child private ExpressionNode functionNode;

@Child
private FunctionExecuteNodes.FunctionExecuteWithNames functionExecWithNames =
FunctionExecuteNodesFactory.FunctionExecuteWithNamesNodeGen.create();

@Child
private FunctionExecuteNodes.FunctionExecuteZero functionExecZero =
FunctionExecuteNodesFactory.FunctionExecuteZeroNodeGen.create();

@Child
private FunctionExecuteNodes.FunctionExecuteOne functionExecOne =
FunctionExecuteNodesFactory.FunctionExecuteOneNodeGen.create();

@Child
private FunctionExecuteNodes.FunctionExecuteTwo functionExecTwo =
FunctionExecuteNodesFactory.FunctionExecuteTwoNodeGen.create();
@Child private InvokeNodes.Invoke invoke = InvokeNodesFactory.InvokeNodeGen.create();

@Children private final ExpressionNode[] argumentNodes;

private final Object[] argumentValues;

private final String[] argNames;

public InvokeWithNamesNode(
public InvokeNode(
ExpressionNode functionNode, String[] argNames, ExpressionNode[] argumentNodes) {
this.functionNode = functionNode;
assert (argNames.length == argumentNodes.length);
Expand All @@ -64,23 +47,10 @@ public InvokeWithNamesNode(
public Object executeGeneric(VirtualFrame frame) {
CompilerAsserts.compilationConstant(argumentNodes.length);
Object function = functionNode.executeGeneric(frame);
if (function instanceof Lambda) {
if (argNames.length == 0) {
return functionExecZero.execute(this, function);
} else if (argNames.length == 1) {
return functionExecOne.execute(this, function, argumentNodes[0].executeGeneric(frame));
} else if (argNames.length == 2) {
return functionExecTwo.execute(
this,
function,
argumentNodes[0].executeGeneric(frame),
argumentNodes[1].executeGeneric(frame));
}
}
for (int i = 0; i < argumentNodes.length; i++) {
argumentValues[i] = argumentNodes[i].executeGeneric(frame);
}
return functionExecWithNames.execute(this, function, argNames, argumentValues);
return invoke.execute(this, function, argNames, argumentValues);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package raw.runtime.truffle.ast.expressions.function;

import com.oracle.truffle.api.dsl.*;
import com.oracle.truffle.api.nodes.Node;
import com.oracle.truffle.api.nodes.NodeInfo;
import raw.runtime.truffle.runtime.function.FunctionExecuteNodes;
import raw.runtime.truffle.runtime.function.Lambda;

public class InvokeNodes {
@NodeInfo(shortName = "Invoke")
@GenerateUncached
@GenerateInline
public abstract static class Invoke extends Node {

public abstract Object execute(
Node node, Object function, String[] argNames, Object[] argumentValues);

@Specialization(guards = "argumentValues.length == 0")
static Object execZero(
Node node,
Lambda function,
String[] argNames,
Object[] argumentValues,
@Bind("$node") Node thisNode,
@Cached Lambda.LambdaExecuteZeroNode functionExecZero) {
return functionExecZero.execute(thisNode, function);
}

@Specialization(guards = "argumentValues.length == 1")
static Object execOne(
Node node,
Lambda function,
String[] argNames,
Object[] argumentValues,
@Bind("$node") Node thisNode,
@Cached Lambda.LambdaExecuteOneNode functionExecOne) {
return functionExecOne.execute(thisNode, function, argumentValues[0]);
}

@Specialization(guards = "argumentValues.length == 1")
static Object execTwo(
Node node,
Lambda function,
String[] argNames,
Object[] argumentValues,
@Bind("$node") Node thisNode,
@Cached Lambda.LambdaExecuteTwoNode functionExecOne) {
return functionExecOne.execute(thisNode, function, argumentValues[0], argumentValues[1]);
}

@Specialization
static Object execTwo(
Node node,
Object function,
String[] argNames,
Object[] argumentValues,
@Bind("$node") Node thisNode,
@Cached FunctionExecuteNodes.FunctionExecuteWithNames functionExecOne) {
return functionExecOne.execute(thisNode, function, argNames, argumentValues);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
import raw.runtime.truffle.runtime.function.Lambda;

public class LambdaNode extends ExpressionNode {

@CompilerDirectives.CompilationFinal private final RootCallTarget callTarget;
private final RootCallTarget callTarget;
@CompilerDirectives.CompilationFinal private Lambda lambda;

public LambdaNode(Function f) {
callTarget = f.getCallTarget();
Expand All @@ -19,6 +19,9 @@ public LambdaNode(Function f) {
@Override
@ExplodeLoop
public Object executeGeneric(VirtualFrame virtualFrame) {
return new Lambda(callTarget, virtualFrame);
if (lambda == null) {
lambda = new Lambda(callTarget, virtualFrame);
}
return lambda;
}
}

0 comments on commit 78dddcd

Please sign in to comment.