Skip to content

Commit

Permalink
Add some UnixOSProcessPlugin primitives (#3)
Browse files Browse the repository at this point in the history
  • Loading branch information
fniephaus committed Feb 8, 2019
1 parent d837c20 commit 1979a9d
Showing 1 changed file with 64 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import java.util.List;

import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
import com.oracle.truffle.api.dsl.Fallback;
import com.oracle.truffle.api.dsl.GenerateNodeFactory;
import com.oracle.truffle.api.dsl.NodeFactory;
import com.oracle.truffle.api.dsl.Specialization;
Expand All @@ -13,8 +14,10 @@
import de.hpi.swa.graal.squeak.model.AbstractSqueakObject;
import de.hpi.swa.graal.squeak.model.CompiledMethodObject;
import de.hpi.swa.graal.squeak.model.NativeObject;
import de.hpi.swa.graal.squeak.model.NilObject;
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.BinaryPrimitiveWithoutFallback;
import de.hpi.swa.graal.squeak.nodes.primitives.PrimitiveInterfaces.TernaryPrimitive;
import de.hpi.swa.graal.squeak.nodes.primitives.PrimitiveInterfaces.UnaryPrimitive;
import de.hpi.swa.graal.squeak.nodes.primitives.SqueakPrimitive;
Expand All @@ -39,6 +42,25 @@ public List<? extends NodeFactory<? extends AbstractPrimitiveNode>> getFactories
return factories;
}

@GenerateNodeFactory
@SqueakPrimitive(names = "primitiveArgumentAt")
protected abstract static class PrimArgumentAtNode extends AbstractPrimitiveNode implements BinaryPrimitiveWithoutFallback {
protected PrimArgumentAtNode(final CompiledMethodObject method) {
super(method);
}

@Specialization(guards = "inBounds1(index, method.image.getImageArguments().length)")
protected final Object doAt(@SuppressWarnings("unused") final Object receiver, final long index) {
return method.image.wrap(method.image.getImageArguments()[(int) index]);
}

@SuppressWarnings("unused")
@Fallback
protected final NilObject doNil(final Object receiver, final Object index) {
return method.image.nil;
}
}

@GenerateNodeFactory
@SqueakPrimitive(names = "primitiveEnvironmentAt")
protected abstract static class PrimEnvironmentAtNode extends AbstractPrimitiveNode implements BinaryPrimitive {
Expand Down Expand Up @@ -104,6 +126,48 @@ protected final Object doAt(@SuppressWarnings("unused") final AbstractSqueakObje
}
}

@GenerateNodeFactory
@SqueakPrimitive(names = "primitiveGetStdErrHandle")
protected abstract static class PrimGetStdErrHandleNode extends AbstractPrimitiveNode implements UnaryPrimitive {

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

@Specialization
protected static final long doGet(@SuppressWarnings("unused") final AbstractSqueakObject receiver) {
return FilePlugin.STDIO_HANDLES.ERROR;
}
}

@GenerateNodeFactory
@SqueakPrimitive(names = "primitiveGetStdInHandle")
protected abstract static class PrimGetStdInHandleNode extends AbstractPrimitiveNode implements UnaryPrimitive {

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

@Specialization
protected static final long doGet(@SuppressWarnings("unused") final AbstractSqueakObject receiver) {
return FilePlugin.STDIO_HANDLES.IN;
}
}

@GenerateNodeFactory
@SqueakPrimitive(names = "primitiveGetStdOutHandle")
protected abstract static class PrimGetStdOutHandleNode extends AbstractPrimitiveNode implements UnaryPrimitive {

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

@Specialization
protected static final long doGet(@SuppressWarnings("unused") final AbstractSqueakObject receiver) {
return FilePlugin.STDIO_HANDLES.OUT;
}
}

@GenerateNodeFactory
@SqueakPrimitive(names = "primitiveSigChldNumber")
protected abstract static class PrimSigChldNumberNode extends AbstractPrimitiveNode implements UnaryPrimitive {
Expand Down

0 comments on commit 1979a9d

Please sign in to comment.