Skip to content

Commit

Permalink
Simplify two fallback guards
Browse files Browse the repository at this point in the history
  • Loading branch information
fniephaus committed Oct 20, 2024
1 parent 0d9d15d commit 4aaa41d
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@
import de.hpi.swa.trufflesqueak.model.NativeObject;
import de.hpi.swa.trufflesqueak.model.NilObject;
import de.hpi.swa.trufflesqueak.model.PointersObject;
import de.hpi.swa.trufflesqueak.nodes.SqueakGuards;
import de.hpi.swa.trufflesqueak.nodes.accessing.AbstractPointersObjectNodes;
import de.hpi.swa.trufflesqueak.nodes.primitives.AbstractPrimitiveFactoryHolder;
import de.hpi.swa.trufflesqueak.nodes.primitives.AbstractPrimitiveNode;
import de.hpi.swa.trufflesqueak.nodes.primitives.PrimitiveFallbacks.BinaryPrimitiveFallback;
import de.hpi.swa.trufflesqueak.nodes.primitives.PrimitiveFallbacks.TernaryPrimitiveFallback;
import de.hpi.swa.trufflesqueak.nodes.primitives.PrimitiveFallbacks.UnaryPrimitiveFallback;
import de.hpi.swa.trufflesqueak.nodes.primitives.SqueakPrimitive;

Expand Down Expand Up @@ -80,7 +80,7 @@ protected static final double doAt(final NativeObject receiver, final long index

@GenerateNodeFactory
@SqueakPrimitive(names = "primitiveAtPut")
public abstract static class PrimFloat64ArrayAtPutNode extends AbstractPrimitiveNode implements TernaryPrimitiveFallback {
public abstract static class PrimFloat64ArrayAtPutNode extends AbstractPrimitiveNode {

@Specialization(guards = {"receiver.isLongType()", "index <= receiver.getLongLength()"})
protected static final double doDouble(final NativeObject receiver, final long index, final double value) {
Expand All @@ -104,6 +104,18 @@ protected static final double doFraction(final NativeObject receiver, final long
@Cached final AbstractPointersObjectNodes.AbstractPointersObjectReadNode readNode) {
return doDouble(receiver, index, getContext(node).fromFraction(value, readNode, node));
}

@SuppressWarnings("unused")
@Specialization(guards = "isFallback(node, receiver, index, value)")
protected static final Object doFail(final NativeObject receiver, final long index, final Object value,
@Bind("this") final Node node) {
throw PrimitiveFailed.GENERIC_ERROR;
}

protected static final boolean isFallback(final Node node, final NativeObject receiver, final long index, final Object value) {
return !(receiver.isIntType() && index <= receiver.getIntLength() && (value instanceof Double || value instanceof FloatObject || value instanceof Long ||
(value instanceof PointersObject pointersObject && SqueakGuards.isFraction(pointersObject, node))));
}
}

@GenerateNodeFactory
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@
import de.hpi.swa.trufflesqueak.model.NativeObject;
import de.hpi.swa.trufflesqueak.model.NilObject;
import de.hpi.swa.trufflesqueak.model.PointersObject;
import de.hpi.swa.trufflesqueak.nodes.SqueakGuards;
import de.hpi.swa.trufflesqueak.nodes.accessing.AbstractPointersObjectNodes;
import de.hpi.swa.trufflesqueak.nodes.primitives.AbstractPrimitiveFactoryHolder;
import de.hpi.swa.trufflesqueak.nodes.primitives.AbstractPrimitiveNode;
import de.hpi.swa.trufflesqueak.nodes.primitives.PrimitiveFallbacks.BinaryPrimitiveFallback;
import de.hpi.swa.trufflesqueak.nodes.primitives.PrimitiveFallbacks.TernaryPrimitiveFallback;
import de.hpi.swa.trufflesqueak.nodes.primitives.PrimitiveFallbacks.UnaryPrimitiveFallback;
import de.hpi.swa.trufflesqueak.nodes.primitives.SqueakPrimitive;

Expand Down Expand Up @@ -81,7 +81,7 @@ protected static final double doAt(final NativeObject receiver, final long index

@GenerateNodeFactory
@SqueakPrimitive(names = "primitiveAtPut")
public abstract static class PrimFloatArrayAtPutNode extends AbstractPrimitiveNode implements TernaryPrimitiveFallback {
public abstract static class PrimFloatArrayAtPutNode extends AbstractPrimitiveNode {

@Specialization(guards = {"receiver.isIntType()", "index <= receiver.getIntLength()"})
protected static final double doDouble(final NativeObject receiver, final long index, final double value) {
Expand All @@ -105,6 +105,18 @@ protected static final double doFraction(final NativeObject receiver, final long
@Cached final AbstractPointersObjectNodes.AbstractPointersObjectReadNode readNode) {
return doDouble(receiver, index, getContext(node).fromFraction(value, readNode, node));
}

@SuppressWarnings("unused")
@Specialization(guards = "isFallback(node, receiver, index, value)")
protected static final Object doFail(final NativeObject receiver, final long index, final Object value,
@Bind("this") final Node node) {
throw PrimitiveFailed.GENERIC_ERROR;
}

protected static final boolean isFallback(final Node node, final NativeObject receiver, final long index, final Object value) {
return !(receiver.isIntType() && index <= receiver.getIntLength() && (value instanceof Double || value instanceof FloatObject || value instanceof Long ||
(value instanceof PointersObject pointersObject && SqueakGuards.isFraction(pointersObject, node))));
}
}

@GenerateNodeFactory
Expand Down

0 comments on commit 4aaa41d

Please sign in to comment.