diff --git a/src/de.hpi.swa.graal.squeak/src/de/hpi/swa/graal/squeak/nodes/plugins/NullPlugin.java b/src/de.hpi.swa.graal.squeak/src/de/hpi/swa/graal/squeak/nodes/plugins/NullPlugin.java new file mode 100644 index 000000000..9a58e17ff --- /dev/null +++ b/src/de.hpi.swa.graal.squeak/src/de/hpi/swa/graal/squeak/nodes/plugins/NullPlugin.java @@ -0,0 +1,36 @@ +package de.hpi.swa.graal.squeak.nodes.plugins; + +import java.util.List; + +import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary; +import com.oracle.truffle.api.dsl.GenerateNodeFactory; +import com.oracle.truffle.api.dsl.NodeFactory; +import com.oracle.truffle.api.dsl.Specialization; + +import de.hpi.swa.graal.squeak.model.ClassObject; +import de.hpi.swa.graal.squeak.model.CompiledMethodObject; +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.UnaryPrimitive; +import de.hpi.swa.graal.squeak.nodes.primitives.SqueakPrimitive; + +public final class NullPlugin extends AbstractPrimitiveFactoryHolder { + @GenerateNodeFactory + @SqueakPrimitive(names = "primitiveUtcWithOffset") + protected abstract static class PrimUtcWithOffsetNode extends AbstractPrimitiveNode implements UnaryPrimitive { + protected PrimUtcWithOffsetNode(final CompiledMethodObject method) { + super(method); + } + + @Specialization + @TruffleBoundary + protected final Object doUTC(@SuppressWarnings("unused") final ClassObject receiver) { + return method.image.newList(new long[]{System.currentTimeMillis() * 1000L, java.time.ZonedDateTime.now().getOffset().getTotalSeconds()}); + } + } + + @Override + public List> getFactories() { + return NullPluginFactory.getFactories(); + } +} diff --git a/src/de.hpi.swa.graal.squeak/src/de/hpi/swa/graal/squeak/nodes/primitives/PrimitiveNodeFactory.java b/src/de.hpi.swa.graal.squeak/src/de/hpi/swa/graal/squeak/nodes/primitives/PrimitiveNodeFactory.java index f2870e041..e54b360fe 100644 --- a/src/de.hpi.swa.graal.squeak/src/de/hpi/swa/graal/squeak/nodes/primitives/PrimitiveNodeFactory.java +++ b/src/de.hpi.swa.graal.squeak/src/de/hpi/swa/graal/squeak/nodes/primitives/PrimitiveNodeFactory.java @@ -27,6 +27,7 @@ import de.hpi.swa.graal.squeak.nodes.plugins.LocalePlugin; import de.hpi.swa.graal.squeak.nodes.plugins.Matrix2x3Plugin; import de.hpi.swa.graal.squeak.nodes.plugins.MiscPrimitivePlugin; +import de.hpi.swa.graal.squeak.nodes.plugins.NullPlugin; import de.hpi.swa.graal.squeak.nodes.plugins.PolyglotPlugin; import de.hpi.swa.graal.squeak.nodes.plugins.SoundCodecPrims; import de.hpi.swa.graal.squeak.nodes.plugins.SqueakFFIPrims; @@ -49,6 +50,8 @@ public final class PrimitiveNodeFactory { private static final int MAX_PRIMITIVE_INDEX = 575; + private static final byte[] NULL_MODULE_NAME = NullPlugin.class.getSimpleName().getBytes(); + @CompilationFinal(dimensions = 1) private final AbstractPrimitiveFactoryHolder[] indexPrimitives = new AbstractPrimitiveFactoryHolder[]{ new ArithmeticPrimitives(), new ArrayStreamPrimitives(), @@ -74,6 +77,7 @@ public final class PrimitiveNodeFactory { new LocalePlugin(), new Matrix2x3Plugin(), new MiscPrimitivePlugin(), + new NullPlugin(), new PolyglotPlugin(), new SocketPlugin(), new SqueakFFIPrims(), @@ -105,8 +109,11 @@ public AbstractPrimitiveNode forIndex(final CompiledMethodObject method, final i public AbstractPrimitiveNode namedFor(final CompiledMethodObject method) { final Object[] values = ((ArrayObject) method.getLiteral(0)).getObjectStorage(); - if (values[0] == method.image.nil || values[1] == method.image.nil) { + if (values[1] == method.image.nil) { return PrimitiveFailedNode.create(method); + } else if (values[0] == method.image.nil) { + final NativeObject functionName = (NativeObject) values[1]; + return forName(method, NULL_MODULE_NAME, functionName.getByteStorage()); } else { final NativeObject moduleName = (NativeObject) values[0]; final NativeObject functionName = (NativeObject) values[1];