Skip to content

Commit

Permalink
Add NullPlugin and primitiveUtcWithOffset (#3)
Browse files Browse the repository at this point in the history
  • Loading branch information
fniephaus committed Feb 8, 2019
1 parent 883dba1 commit 257b1e8
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -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<? extends NodeFactory<? extends AbstractPrimitiveNode>> getFactories() {
return NullPluginFactory.getFactories();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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(),
Expand All @@ -74,6 +77,7 @@ public final class PrimitiveNodeFactory {
new LocalePlugin(),
new Matrix2x3Plugin(),
new MiscPrimitivePlugin(),
new NullPlugin(),
new PolyglotPlugin(),
new SocketPlugin(),
new SqueakFFIPrims(),
Expand Down Expand Up @@ -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];
Expand Down

0 comments on commit 257b1e8

Please sign in to comment.