diff --git a/src/de.hpi.swa.trufflesqueak/src/de/hpi/swa/trufflesqueak/interop/JavaObjectWrapper.java b/src/de.hpi.swa.trufflesqueak/src/de/hpi/swa/trufflesqueak/interop/JavaObjectWrapper.java index aa47154dd..1feb33207 100644 --- a/src/de.hpi.swa.trufflesqueak/src/de/hpi/swa/trufflesqueak/interop/JavaObjectWrapper.java +++ b/src/de.hpi.swa.trufflesqueak/src/de/hpi/swa/trufflesqueak/interop/JavaObjectWrapper.java @@ -413,30 +413,30 @@ protected boolean fitsInLong(@Shared("lib") @CachedLibrary(limit = "LIMIT") fina } @ExportMessage - protected boolean fitsInFloat(@Shared("lib") @CachedLibrary(limit = "LIMIT") final InteropLibrary lib) { + protected boolean fitsInBigInteger(@Shared("lib") @CachedLibrary(limit = "LIMIT") final InteropLibrary lib) { + if (wrappedObject instanceof BigInteger) { + return true; + } if (isNumber()) { - return lib.fitsInFloat(wrappedObject); + return lib.fitsInBigInteger(wrappedObject); } else { return false; } } @ExportMessage - protected boolean fitsInDouble(@Shared("lib") @CachedLibrary(limit = "LIMIT") final InteropLibrary lib) { + protected boolean fitsInFloat(@Shared("lib") @CachedLibrary(limit = "LIMIT") final InteropLibrary lib) { if (isNumber()) { - return lib.fitsInDouble(wrappedObject); + return lib.fitsInFloat(wrappedObject); } else { return false; } } @ExportMessage - protected boolean fitsInBigInteger(@Shared("lib") @CachedLibrary(limit = "LIMIT") final InteropLibrary lib) { - if (wrappedObject instanceof BigInteger) { - return true; - } + protected boolean fitsInDouble(@Shared("lib") @CachedLibrary(limit = "LIMIT") final InteropLibrary lib) { if (isNumber()) { - return lib.fitsInBigInteger(wrappedObject); + return lib.fitsInDouble(wrappedObject); } else { return false; } @@ -479,29 +479,29 @@ protected long asLong(@Shared("lib") @CachedLibrary(limit = "LIMIT") final Inter } @ExportMessage - protected float asFloat(@Shared("lib") @CachedLibrary(limit = "LIMIT") final InteropLibrary lib) throws UnsupportedMessageException { - if (isNumber()) { - return lib.asFloat(wrappedObject); + protected BigInteger asBigInteger(@Shared("lib") @CachedLibrary(limit = "LIMIT") final InteropLibrary lib) throws UnsupportedMessageException { + if (wrappedObject instanceof final BigInteger w) { + return w; + } else if (isNumber()) { + return lib.asBigInteger(wrappedObject); } else { throw UnsupportedMessageException.create(); } } @ExportMessage - protected double asDouble(@Shared("lib") @CachedLibrary(limit = "LIMIT") final InteropLibrary lib) throws UnsupportedMessageException { + protected float asFloat(@Shared("lib") @CachedLibrary(limit = "LIMIT") final InteropLibrary lib) throws UnsupportedMessageException { if (isNumber()) { - return lib.asDouble(wrappedObject); + return lib.asFloat(wrappedObject); } else { throw UnsupportedMessageException.create(); } } @ExportMessage - protected BigInteger asBigInteger(@Shared("lib") @CachedLibrary(limit = "LIMIT") final InteropLibrary lib) throws UnsupportedMessageException { - if (wrappedObject instanceof final BigInteger w) { - return w; - } else if (isNumber()) { - return lib.asBigInteger(wrappedObject); + protected double asDouble(@Shared("lib") @CachedLibrary(limit = "LIMIT") final InteropLibrary lib) throws UnsupportedMessageException { + if (isNumber()) { + return lib.asDouble(wrappedObject); } else { throw UnsupportedMessageException.create(); } @@ -864,6 +864,20 @@ protected boolean isMetaInstance(final Object other) throws UnsupportedMessageEx } } + @ExportMessage + public boolean hasMetaParents() { + return isMetaObject(); + } + + @ExportMessage + public Object getMetaParents(@Shared("lib") @CachedLibrary(limit = "LIMIT") final InteropLibrary lib) throws UnsupportedMessageException { + if (isClass()) { + return wrap(new Object[]{asClass().getSuperclass()}); + } else { + throw UnsupportedMessageException.create(); + } + } + @ExportMessage protected boolean hasLanguage() { return true; @@ -915,6 +929,8 @@ private static Object toJavaArgument(final Object argument) { return lib.asInt(argument); } else if (lib.fitsInLong(argument)) { return lib.asLong(argument); + } else if (lib.fitsInBigInteger(argument)) { + return lib.asBigInteger(argument); } else if (lib.fitsInFloat(argument)) { return lib.asFloat(argument); } else if (lib.fitsInDouble(argument)) { diff --git a/src/de.hpi.swa.trufflesqueak/src/de/hpi/swa/trufflesqueak/nodes/plugins/PolyglotPlugin.java b/src/de.hpi.swa.trufflesqueak/src/de/hpi/swa/trufflesqueak/nodes/plugins/PolyglotPlugin.java index 713acfd74..e64d7bac4 100644 --- a/src/de.hpi.swa.trufflesqueak/src/de/hpi/swa/trufflesqueak/nodes/plugins/PolyglotPlugin.java +++ b/src/de.hpi.swa.trufflesqueak/src/de/hpi/swa/trufflesqueak/nodes/plugins/PolyglotPlugin.java @@ -9,6 +9,7 @@ import java.io.IOException; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; +import java.math.BigInteger; import java.nio.ByteOrder; import java.util.List; import java.util.Map; @@ -55,6 +56,7 @@ import de.hpi.swa.trufflesqueak.model.ArrayObject; import de.hpi.swa.trufflesqueak.model.BooleanObject; import de.hpi.swa.trufflesqueak.model.ClassObject; +import de.hpi.swa.trufflesqueak.model.LargeIntegerObject; import de.hpi.swa.trufflesqueak.model.NativeObject; import de.hpi.swa.trufflesqueak.model.NilObject; import de.hpi.swa.trufflesqueak.model.PointersObject; @@ -65,6 +67,7 @@ import de.hpi.swa.trufflesqueak.nodes.primitives.PrimitiveFallbacks.BinaryPrimitiveFallback; import de.hpi.swa.trufflesqueak.nodes.primitives.PrimitiveFallbacks.QuaternaryPrimitiveFallback; import de.hpi.swa.trufflesqueak.nodes.primitives.PrimitiveFallbacks.QuinaryPrimitiveFallback; +import de.hpi.swa.trufflesqueak.nodes.primitives.PrimitiveFallbacks.SenaryPrimitiveFallback; 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; @@ -539,6 +542,33 @@ protected static final double doAsDouble(@SuppressWarnings("unused") final Objec } } + @GenerateNodeFactory + @SqueakPrimitive(names = "primitiveFitsInBigInteger") + protected abstract static class PrimFitsInBigIntegerNode extends AbstractPrimitiveNode { + + @Specialization + protected static final boolean doFitsInBigInteger(@SuppressWarnings("unused") final Object receiver, final Object object, + @CachedLibrary(limit = "2") final InteropLibrary lib) { + return BooleanObject.wrap(lib.fitsInBigInteger(object)); + } + } + + @GenerateNodeFactory + @SqueakPrimitive(names = "primitiveAsBigInteger") + protected abstract static class PrimAsBigIntegerNode extends AbstractPrimitiveNode implements BinaryPrimitiveFallback { + + @TruffleBoundary + @Specialization(guards = {"lib.fitsInBigInteger(object)"}, limit = "2") + protected final Object doAsDouble(@SuppressWarnings("unused") final Object receiver, final Object object, + @CachedLibrary("object") final InteropLibrary lib) { + try { + return new LargeIntegerObject(getContext(), lib.asBigInteger(object)); + } catch (final UnsupportedMessageException e) { + throw primitiveFailedInInterpreterCapturing(e); + } + } + } + @GenerateNodeFactory @SqueakPrimitive(names = "primitiveIsExecutable") protected abstract static class PrimIsExecutableNode extends AbstractPrimitiveNode { @@ -1213,6 +1243,21 @@ protected static final long doReadBufferByte(@SuppressWarnings("unused") final O } } + @GenerateNodeFactory + @SqueakPrimitive(names = "primitiveReadBuffer") + protected abstract static class PrimReadBufferNode extends AbstractPrimitiveNode implements SenaryPrimitiveFallback { + @Specialization(guards = {"lib.hasBufferElements(object)", "destination.isByteType()"}) + protected static final Object doReadBuffer(final Object receiver, final Object object, final long byteOffset, final NativeObject destination, final long destinationOffset, final long length, + @CachedLibrary(limit = "2") final InteropLibrary lib) { + try { + lib.readBuffer(object, byteOffset, destination.getByteStorage(), MiscUtils.toIntExact(destinationOffset), MiscUtils.toIntExact(length)); + return receiver; + } catch (final UnsupportedMessageException | InvalidBufferOffsetException e) { + throw primitiveFailedInInterpreterCapturing(e); + } + } + } + @GenerateNodeFactory @SqueakPrimitive(names = "primitiveWriteBufferByte") protected abstract static class PrimWriteBufferByteNode extends AbstractPrimitiveNode implements QuaternaryPrimitiveFallback { @@ -1657,6 +1702,29 @@ protected static final Object getMetaSimpleName(@SuppressWarnings("unused") fina } } + @GenerateNodeFactory + @SqueakPrimitive(names = "primitiveHasMetaParents") + protected abstract static class PrimHasMetaParentsNode extends AbstractPrimitiveNode implements BinaryPrimitiveFallback { + @Specialization(guards = "lib.isMetaObject(object)") + protected static final boolean hasMetaParents(@SuppressWarnings("unused") final Object receiver, final Object object, @CachedLibrary(limit = "2") final InteropLibrary lib) { + return lib.hasMetaParents(object); + } + } + + @GenerateNodeFactory + @SqueakPrimitive(names = "primitiveGetMetaParents") + protected abstract static class PrimGetMetaParentsNode extends AbstractPrimitiveNode implements BinaryPrimitiveFallback { + @Specialization(guards = "lib.isMetaObject(object)") + protected static final Object getMetaParents(@SuppressWarnings("unused") final Object receiver, final Object object, + @CachedLibrary(limit = "2") final InteropLibrary lib) { + try { + return lib.getMetaParents(object); + } catch (final UnsupportedMessageException e) { + throw primitiveFailedInInterpreterCapturing(e); + } + } + } + @GenerateNodeFactory @SqueakPrimitive(names = "primitiveHasSourceLocation") protected abstract static class PrimHasSourceLocationNode extends AbstractPrimitiveNode { @@ -2172,6 +2240,15 @@ protected static final int toJavaInteger(@SuppressWarnings("unused") final Objec } } + @GenerateNodeFactory + @SqueakPrimitive(names = "primitiveToJavaBigInteger") + protected abstract static class PrimToJavaBigIntegerNode extends AbstractPrimitiveNode implements BinaryPrimitiveFallback { + @Specialization + protected static final BigInteger toJavaInteger(@SuppressWarnings("unused") final Object receiver, final LargeIntegerObject value) { + return value.getBigInteger(); + } + } + @GenerateNodeFactory @SqueakPrimitive(names = "primitiveToJavaString") protected abstract static class PrimToJavaStringNode extends AbstractPrimitiveNode implements BinaryPrimitiveFallback { diff --git a/src/image b/src/image index 2747e4e32..5ae9534e8 160000 --- a/src/image +++ b/src/image @@ -1 +1 @@ -Subproject commit 2747e4e32acdaec1dc0316179727434b2982f73c +Subproject commit 5ae9534e81d495e30f82438de988f3508a660d3f