Skip to content

Commit

Permalink
Refactor closure prims into PrimClosureValueNode
Browse files Browse the repository at this point in the history
  • Loading branch information
fniephaus committed Jun 24, 2019
1 parent 4f34e9d commit 61a795c
Showing 1 changed file with 29 additions and 56 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,14 @@
import de.hpi.swa.graal.squeak.model.ArrayObject;
import de.hpi.swa.graal.squeak.model.BlockClosureObject;
import de.hpi.swa.graal.squeak.model.CompiledMethodObject;
import de.hpi.swa.graal.squeak.model.NotProvided;
import de.hpi.swa.graal.squeak.nodes.BlockActivationNode;
import de.hpi.swa.graal.squeak.nodes.accessing.ArrayObjectNodes.ArrayObjectToObjectArrayCopyNode;
import de.hpi.swa.graal.squeak.nodes.accessing.SqueakObjectSizeNode;
import de.hpi.swa.graal.squeak.nodes.primitives.AbstractPrimitiveFactoryHolder;
import de.hpi.swa.graal.squeak.nodes.primitives.AbstractPrimitiveNode;
import de.hpi.swa.graal.squeak.nodes.primitives.PrimitiveInterfaces.BinaryPrimitive;
import de.hpi.swa.graal.squeak.nodes.primitives.PrimitiveInterfaces.QuaternaryPrimitive;
import de.hpi.swa.graal.squeak.nodes.primitives.PrimitiveInterfaces.QuinaryPrimitive;
import de.hpi.swa.graal.squeak.nodes.primitives.PrimitiveInterfaces.TernaryPrimitive;
import de.hpi.swa.graal.squeak.nodes.primitives.PrimitiveInterfaces.SenaryPrimitive;
import de.hpi.swa.graal.squeak.nodes.primitives.PrimitiveInterfaces.UnaryPrimitive;
import de.hpi.swa.graal.squeak.nodes.primitives.SqueakPrimitive;
import de.hpi.swa.graal.squeak.util.ArrayUtils;
Expand All @@ -30,77 +29,51 @@
public final class BlockClosurePrimitives extends AbstractPrimitiveFactoryHolder {

@GenerateNodeFactory
@SqueakPrimitive(indices = 201)
public abstract static class PrimClosureValue0Node extends AbstractPrimitiveNode implements UnaryPrimitive {
@SqueakPrimitive(indices = {201, 202, 203, 204, 205})
protected abstract static class PrimClosureValueNode extends AbstractPrimitiveNode implements SenaryPrimitive {
@Child private BlockActivationNode activationNode = BlockActivationNode.create();

protected PrimClosureValue0Node(final CompiledMethodObject method) {
protected PrimClosureValueNode(final CompiledMethodObject method) {
super(method);
}

@SuppressWarnings("unused")
@Specialization(guards = {"block.getCompiledBlock().getNumArgs() == 0"})
protected final Object doClosure(final VirtualFrame frame, final BlockClosureObject block,
@Cached final BlockActivationNode activationNode) {
protected final Object doClosure(final VirtualFrame frame, final BlockClosureObject block, final NotProvided arg1, final NotProvided arg2, final NotProvided arg3, final NotProvided arg4,
final NotProvided arg5) {
return activationNode.executeBlock(block, FrameAccess.newClosureArguments(block, getContextOrMarker(frame), ArrayUtils.EMPTY_ARRAY));
}
}

@GenerateNodeFactory
@SqueakPrimitive(indices = 202)
protected abstract static class PrimClosureValue1Node extends AbstractPrimitiveNode implements BinaryPrimitive {

protected PrimClosureValue1Node(final CompiledMethodObject method) {
super(method);
@SuppressWarnings("unused")
@Specialization(guards = {"block.getCompiledBlock().getNumArgs() == 1", "!isNotProvided(arg1)"})
protected final Object doValue(final VirtualFrame frame, final BlockClosureObject block, final Object arg1, final NotProvided arg2, final NotProvided arg3, final NotProvided arg4,
final NotProvided arg5) {
return activationNode.executeBlock(block, FrameAccess.newClosureArguments(block, getContextOrMarker(frame), new Object[]{arg1}));
}

@Specialization(guards = {"block.getCompiledBlock().getNumArgs() == 1"})
protected final Object doValue(final VirtualFrame frame, final BlockClosureObject block, final Object arg,
@Cached final BlockActivationNode activationNode) {
return activationNode.executeBlock(block, FrameAccess.newClosureArguments(block, getContextOrMarker(frame), new Object[]{arg}));
}
}

@GenerateNodeFactory
@SqueakPrimitive(indices = 203)
protected abstract static class PrimClosureValue2Node extends AbstractPrimitiveNode implements TernaryPrimitive {

protected PrimClosureValue2Node(final CompiledMethodObject method) {
super(method);
}

@Specialization(guards = {"block.getCompiledBlock().getNumArgs() == 2"})
protected final Object doValue(final VirtualFrame frame, final BlockClosureObject block, final Object arg1, final Object arg2,
@Cached final BlockActivationNode activationNode) {
@SuppressWarnings("unused")
@Specialization(guards = {"block.getCompiledBlock().getNumArgs() == 2", "!isNotProvided(arg1)", "!isNotProvided(arg2)"})
protected final Object doValue(final VirtualFrame frame, final BlockClosureObject block, final Object arg1, final Object arg2, final NotProvided arg3, final NotProvided arg4,
final NotProvided arg5) {
return activationNode.executeBlock(block, FrameAccess.newClosureArguments(block, getContextOrMarker(frame), new Object[]{arg1, arg2}));
}
}

@GenerateNodeFactory
@SqueakPrimitive(indices = 204)
protected abstract static class PrimClosureValue3Node extends AbstractPrimitiveNode implements QuaternaryPrimitive {

protected PrimClosureValue3Node(final CompiledMethodObject method) {
super(method);
}

@Specialization(guards = {"block.getCompiledBlock().getNumArgs() == 3"})
protected final Object doValue(final VirtualFrame frame, final BlockClosureObject block, final Object arg1, final Object arg2, final Object arg3,
@Cached final BlockActivationNode activationNode) {
@SuppressWarnings("unused")
@Specialization(guards = {"block.getCompiledBlock().getNumArgs() == 3", "!isNotProvided(arg1)", "!isNotProvided(arg2)", "!isNotProvided(arg3)"})
protected final Object doValue(final VirtualFrame frame, final BlockClosureObject block, final Object arg1, final Object arg2, final Object arg3, final NotProvided arg4,
final NotProvided arg5) {
return activationNode.executeBlock(block, FrameAccess.newClosureArguments(block, getContextOrMarker(frame), new Object[]{arg1, arg2, arg3}));
}
}

@GenerateNodeFactory
@SqueakPrimitive(indices = 205)
protected abstract static class PrimClosureValue4Node extends AbstractPrimitiveNode implements QuinaryPrimitive {

protected PrimClosureValue4Node(final CompiledMethodObject method) {
super(method);
@SuppressWarnings("unused")
@Specialization(guards = {"block.getCompiledBlock().getNumArgs() == 4", "!isNotProvided(arg1)", "!isNotProvided(arg2)", "!isNotProvided(arg3)", "!isNotProvided(arg4)"})
protected final Object doValue(final VirtualFrame frame, final BlockClosureObject block, final Object arg1, final Object arg2, final Object arg3, final Object arg4, final NotProvided arg5) {
return activationNode.executeBlock(block, FrameAccess.newClosureArguments(block, getContextOrMarker(frame), new Object[]{arg1, arg2, arg3, arg4}));
}

@Specialization(guards = {"block.getCompiledBlock().getNumArgs() == 4"})
protected final Object doValue(final VirtualFrame frame, final BlockClosureObject block, final Object arg1, final Object arg2, final Object arg3, final Object arg4,
@Cached final BlockActivationNode activationNode) {
return activationNode.executeBlock(block, FrameAccess.newClosureArguments(block, getContextOrMarker(frame), new Object[]{arg1, arg2, arg3, arg4}));
@Specialization(guards = {"block.getCompiledBlock().getNumArgs() == 5", "!isNotProvided(arg1)", "!isNotProvided(arg2)", "!isNotProvided(arg3)", "!isNotProvided(arg4)", "!isNotProvided(arg5)"})
protected final Object doValue(final VirtualFrame frame, final BlockClosureObject block, final Object arg1, final Object arg2, final Object arg3, final Object arg4, final Object arg5) {
return activationNode.executeBlock(block, FrameAccess.newClosureArguments(block, getContextOrMarker(frame), new Object[]{arg1, arg2, arg3, arg4, arg5}));
}
}

Expand Down

0 comments on commit 61a795c

Please sign in to comment.