com.oracle.truffle.api.dsl.Cached Java Examples

The following examples show how to use com.oracle.truffle.api.dsl.Cached. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: IOPrimitives.java    From trufflesqueak with MIT License 6 votes vote down vote up
@Specialization
protected static final void doWeakPointers(final WeakVariablePointersObject rcvr, final long start, final long stop, final WeakVariablePointersObject repl, final long replStart,
                @Cached final AbstractPointersObjectInstSizeNode rcvrInstSizeNode,
                @Cached final AbstractPointersObjectInstSizeNode replInstSizeNode,
                @Cached final WeakVariablePointersObjectReadNode readNode,
                @Cached final WeakVariablePointersObjectWriteNode writeNode,
                @Shared("errorProfile") @Cached final BranchProfile errorProfile) {
    final int rcvrInstSize = rcvrInstSizeNode.execute(rcvr);
    final int replInstSize = replInstSizeNode.execute(repl);
    if (!inBounds(rcvrInstSize, rcvrInstSize + rcvr.getVariablePartSize(), start, stop, replInstSize, replInstSize + repl.getVariablePartSize(), replStart)) {
        errorProfile.enter();
        throw PrimitiveFailed.BAD_INDEX;
    }
    final int repOff = (int) (replStart - start);
    for (int i = (int) (start - 1); i < stop; i++) {
        writeNode.execute(rcvr, i, readNode.execute(repl, repOff + i));
    }
}
 
Example #2
Source File: DispatchEagerlyNode.java    From trufflesqueak with MIT License 6 votes vote down vote up
@Specialization(guards = {"cachedMethod.hasPrimitive()", "method == cachedMethod", "primitiveNode != null"}, //
                limit = "INLINE_CACHE_SIZE", assumptions = {"cachedMethod.getCallTargetStable()"}, rewriteOn = PrimitiveFailed.class)
protected static final Object doPrimitiveEagerly(final VirtualFrame frame, @SuppressWarnings("unused") final CompiledMethodObject method, final Object[] receiverAndArguments,
                @SuppressWarnings("unused") @Cached("method") final CompiledMethodObject cachedMethod,
                @Cached("forIndex(cachedMethod, false, cachedMethod.primitiveIndex())") final AbstractPrimitiveNode primitiveNode,
                @Cached final CreateEagerArgumentsNode createEagerArgumentsNode,
                @Cached final PrimitiveFailedCounter failureCounter) {
    try {
        return primitiveNode.executeWithArguments(frame, createEagerArgumentsNode.executeCreate(primitiveNode.getNumArguments(), receiverAndArguments));
    } catch (final PrimitiveFailed pf) {
        CompilerDirectives.transferToInterpreterAndInvalidate();
        if (failureCounter.shouldNoLongerSendEagerly()) {
            throw pf; // Rewrite specialization.
        } else {
            // Slow path send to fallback code.
            return IndirectCallNode.getUncached().call(cachedMethod.getCallTarget(),
                            FrameAccess.newWith(cachedMethod, FrameAccess.getContextOrMarkerSlow(frame), null, receiverAndArguments));
        }
    }
}
 
Example #3
Source File: ReturnBytecodes.java    From trufflesqueak with MIT License 6 votes vote down vote up
@Specialization(guards = {"hasModifiedSender(frame)"})
protected final Object doNonLocalReturnClosure(final VirtualFrame frame,
                @Cached final GetActiveProcessNode getActiveProcessNode) {
    // Target is sender of closure's home context.
    final ContextObject homeContext = FrameAccess.getClosure(frame).getHomeContext();
    assert homeContext.getProcess() != null;
    final boolean homeContextNotOnTheStack = homeContext.getProcess() != getActiveProcessNode.execute();
    final Object caller = homeContext.getFrameSender();
    if (caller == NilObject.SINGLETON || homeContextNotOnTheStack) {
        CompilerDirectives.transferToInterpreter();
        final ContextObject contextObject = GetOrCreateContextNode.getOrCreateFromActiveProcessUncached(frame);
        lookupContext().cannotReturn.executeAsSymbolSlow(frame, contextObject, getReturnValue(frame));
        throw SqueakException.create("Should not reach");
    }
    throw new NonLocalReturn(getReturnValue(frame), caller);
}
 
Example #4
Source File: HandleNonLocalReturnNode.java    From trufflesqueak with MIT License 6 votes vote down vote up
@Specialization
protected final Object doHandle(final VirtualFrame frame, final NonLocalReturn nlr,
                @Cached("getInstructionPointerSlot(frame)") final FrameSlot instructionPointerSlot,
                @Cached final GetContextNode getContextNode,
                @Cached("createBinaryProfile()") final ConditionProfile hasModifiedSenderProfile) {
    if (hasModifiedSenderProfile.profile(getContextNode.hasModifiedSender(frame))) {
        aboutToReturnNode.executeAboutToReturn(frame, nlr); // handle ensure: or ifCurtailed:
        // Sender has changed.
        final ContextObject newSender = FrameAccess.getSenderContext(frame);
        final ContextObject target = (ContextObject) nlr.getTargetContextOrMarker();
        FrameAccess.terminate(frame, instructionPointerSlot);
        throw new NonVirtualReturn(nlr.getReturnValue(), target, newSender);
    } else {
        aboutToReturnNode.executeAboutToReturn(frame, nlr); // handle ensure: or ifCurtailed:
        FrameAccess.terminate(frame, instructionPointerSlot);
        throw nlr;
    }
}
 
Example #5
Source File: MapDeviceArrayFunction.java    From grcuda with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Specialization(limit = "3")
Object doMap(Object source, Type elementType, CUDARuntime runtime,
                @CachedLibrary("source") InteropLibrary interop,
                @CachedContext(GrCUDALanguage.class) @SuppressWarnings("unused") GrCUDAContext context,
                @Cached(value = "createLoop(source)", uncached = "createUncachedLoop(source, context)") CallTarget loop) {

    if (source instanceof DeviceArray && ((DeviceArray) source).getElementType() == elementType) {
        return source;
    }

    if (!interop.hasArrayElements(source)) {
        CompilerDirectives.transferToInterpreter();
        throw new GrCUDAException("cannot map from non-array to DeviceArray");
    }

    long size;
    try {
        size = interop.getArraySize(source);
    } catch (UnsupportedMessageException e) {
        CompilerDirectives.transferToInterpreter();
        throw new GrCUDAException("cannot read array size");
    }
    DeviceArray result = new DeviceArray(runtime, size, elementType);
    loop.call(size, source, result);
    return result;
}
 
Example #6
Source File: DispatchSendNode.java    From trufflesqueak with MIT License 6 votes vote down vote up
@Specialization(guards = {"!isCompiledMethodObject(targetObject)"})
protected final Object doObjectAsMethod(final VirtualFrame frame, final NativeObject selector, final Object targetObject, @SuppressWarnings("unused") final ClassObject rcvrClass,
                final Object[] rcvrAndArgs,
                @Cached final SqueakObjectClassNode classNode,
                @Shared("writeNode") @Cached final AbstractPointersObjectWriteNode writeNode,
                @Cached final LookupMethodNode lookupNode,
                @Cached("createBinaryProfile()") final ConditionProfile isDoesNotUnderstandProfile,
                @CachedContext(SqueakLanguage.class) final SqueakImageContext image) {
    final Object[] arguments = ArrayUtils.allButFirst(rcvrAndArgs);
    final ClassObject targetClass = classNode.executeLookup(targetObject);
    final Object newLookupResult = lookupNode.executeLookup(targetClass, image.runWithInSelector);
    if (isDoesNotUnderstandProfile.profile(newLookupResult == null)) {
        final Object doesNotUnderstandMethod = lookupNode.executeLookup(targetClass, image.doesNotUnderstand);
        return dispatchNode.executeDispatch(frame, (CompiledMethodObject) doesNotUnderstandMethod,
                        new Object[]{targetObject, image.newMessage(writeNode, selector, targetClass, arguments)});
    } else {
        return dispatchNode.executeDispatch(frame, (CompiledMethodObject) newLookupResult, new Object[]{targetObject, selector, image.asArrayOfObjects(arguments), rcvrAndArgs[0]});
    }
}
 
Example #7
Source File: ControlPrimitives.java    From trufflesqueak with MIT License 6 votes vote down vote up
@Specialization(guards = {"receiver.getSqueakClass().isSemaphoreClass()", "!hasExcessSignals(receiver)"})
protected final Object doWait(final VirtualFrame frame, final PointersObject receiver,
                @Cached final LinkProcessToListNode linkProcessToListNode,
                @Cached final WakeHighestPriorityNode wakeHighestPriorityNode,
                @Cached final GetActiveProcessNode getActiveProcessNode) {
    linkProcessToListNode.executeLink(getActiveProcessNode.execute(), receiver);
    try {
        wakeHighestPriorityNode.executeWake(frame);
    } catch (final ProcessSwitch ps) {
        /*
         * Leave receiver on stack. It has not been removed from the stack yet, so it is
         * enough to increment the stack pointer.
         */
        getFrameStackPointerIncrementNode().execute(frame);
        throw ps;
    }
    return receiver;
}
 
Example #8
Source File: IOPrimitives.java    From trufflesqueak with MIT License 6 votes vote down vote up
@Specialization
protected static final void doPointers(final PointersObject rcvr, final long start, final long stop, final VariablePointersObject repl, final long replStart,
                @Cached final AbstractPointersObjectInstSizeNode rcvrSizeNode,
                @Cached final AbstractPointersObjectInstSizeNode replSizeNode,
                @Cached final AbstractPointersObjectReadNode readNode,
                @Cached final AbstractPointersObjectWriteNode writeNode,
                @Shared("errorProfile") @Cached final BranchProfile errorProfile) {
    final int rcvrSize = rcvrSizeNode.execute(rcvr);
    final int replSize = replSizeNode.execute(repl);
    if (inBounds(rcvrSize, rcvrSize, start, stop, replSize, replSize, replStart)) {
        final int repOff = (int) (replStart - start);
        for (int i = (int) (start - 1); i < stop; i++) {
            writeNode.execute(rcvr, i, readNode.execute(repl, repOff + i));
        }
    } else {
        errorProfile.enter();
        throw PrimitiveFailed.BAD_INDEX;
    }
}
 
Example #9
Source File: SqueakSSL.java    From trufflesqueak with MIT License 6 votes vote down vote up
/**
 * Sets an integer property in a SSL session.
 *
 * @param receiver the receiver
 * @param sslHandle the handle of the target SSL instance
 * @param propertyId the property ID; see {@link IntProperty}
 * @param anInteger the property value
 * @return despite the return code convention, non-zero if successful
 */
@Specialization
protected static final long doSet(@SuppressWarnings("unused") final Object receiver,
                final PointersObject sslHandle,
                final long propertyId,
                final long anInteger,
                @Cached final BranchProfile errorProfile) {
    final SqSSL ssl = getSSLOrNull(sslHandle);
    final IntProperty property = propertyWithId(IntProperty.class, propertyId);
    if (ssl == null || property == null) {
        errorProfile.enter();
        return 0L;
    }

    if (property == IntProperty.LOG_LEVEL) {
        ssl.logLevel = anInteger;
    }

    return 1L;
}
 
Example #10
Source File: IOPrimitives.java    From trufflesqueak with MIT License 5 votes vote down vote up
@Specialization(guards = {"rcvr.isByteType()", "repl.isByteType()"})
protected static final void doNativeBytes(final NativeObject rcvr, final long start, final long stop, final NativeObject repl, final long replStart,
                @Shared("errorProfile") @Cached final BranchProfile errorProfile) {
    try {
        System.arraycopy(repl.getByteStorage(), (int) replStart - 1, rcvr.getByteStorage(), (int) start - 1, (int) (1 + stop - start));
    } catch (final IndexOutOfBoundsException e) {
        errorProfile.enter();
        throw PrimitiveFailed.BAD_INDEX;
    }
}
 
Example #11
Source File: PolyglotPlugin.java    From trufflesqueak with MIT License 5 votes vote down vote up
@Specialization(guards = "languageID.isByteType()")
@TruffleBoundary
protected static final ArrayObject doGet(@SuppressWarnings("unused") final Object receiver, final NativeObject languageID,
                @Cached final WrapToSqueakNode wrapNode,
                @CachedContext(SqueakLanguage.class) final SqueakImageContext image) {
    final Collection<LanguageInfo> languages = image.env.getPublicLanguages().values();
    return wrapNode.executeList(languages.stream().//
                    filter(l -> l.getId().equals(languageID.asStringUnsafe())).//
                    map(l -> new Object[]{l.getId(), l.getName(), l.getVersion(), l.getDefaultMimeType(), l.getMimeTypes().toArray()}).//
                    findFirst().orElseThrow(() -> PrimitiveFailed.GENERIC_ERROR));
}
 
Example #12
Source File: ControlPrimitives.java    From trufflesqueak with MIT License 5 votes vote down vote up
@Specialization(replaces = "performContextCached")
protected final Object performContext(final VirtualFrame frame, @SuppressWarnings("unused") final Object receiver, final Object target, final NativeObject selector,
                final ArrayObject arguments, final ClassObject superClass,
                @Cached final LookupMethodNode lookupMethodNode,
                @Cached final DispatchSendSelectorNode dispatchNode) {
    if (inheritsFromNode.execute(target, superClass)) {
        final Object lookupResult = lookupMethodNode.executeLookup(superClass, selector);
        return dispatchNode.executeSend(frame, selector, lookupResult, superClass, getObjectArrayNode.execute(target, arguments));
    } else {
        CompilerDirectives.transferToInterpreter();
        throw PrimitiveFailed.BAD_RECEIVER;
    }
}
 
Example #13
Source File: JumpBytecodes.java    From trufflesqueak with MIT License 5 votes vote down vote up
@Specialization(guards = "!isBoolean(result)")
protected final boolean doMustBeBooleanSend(final VirtualFrame frame, @SuppressWarnings("unused") final boolean expected, final Object result,
                @Cached("getInstructionPointerSlot(frame)") final FrameSlot instructionPointerSlot) {
    CompilerDirectives.transferToInterpreter();
    FrameAccess.setInstructionPointer(frame, instructionPointerSlot, successorIndex);
    lookupContext().mustBeBooleanSelector.executeAsSymbolSlow(frame, result);
    throw SqueakException.create("Should not be reached");
}
 
Example #14
Source File: IOPrimitives.java    From trufflesqueak with MIT License 5 votes vote down vote up
@Specialization(guards = {"!rcvr.hasSameStorageType(repl)"})
protected final void doArraysWithDifferenStorageTypes(final ArrayObject rcvr, final long start, final long stop, final ArrayObject repl, final long replStart,
                @Cached final ArrayObjectReadNode readNode,
                @Shared("arrayWriteNode") @Cached final ArrayObjectWriteNode writeNode,
                @Shared("errorProfile") @Cached final BranchProfile errorProfile) {
    if (!inBounds(getSizeNode().execute(rcvr), start, stop, getSizeNode().execute(repl), replStart)) {
        errorProfile.enter();
        throw PrimitiveFailed.BAD_INDEX;
    }
    final long repOff = replStart - start;
    for (int i = (int) (start - 1); i < stop; i++) {
        writeNode.execute(rcvr, i, readNode.execute(repl, repOff + i));
    }
}
 
Example #15
Source File: AbstractPointersObjectNodes.java    From trufflesqueak with MIT License 5 votes vote down vote up
@Specialization(guards = {"cachedIndex == index", "object.getLayout() == cachedLayout", "cachedIndex >= cachedLayout.getInstSize()"}, limit = "VARIABLE_PART_INDEX_CACHE_LIMIT")
protected static final void doWriteIntoVariablePartCachedIndex(final WeakVariablePointersObject object, @SuppressWarnings("unused") final int index, final Object value,
                @Cached("index") final int cachedIndex,
                @Cached("object.getLayout()") final ObjectLayout cachedLayout,
                @Cached final BranchProfile nilProfile,
                @Cached("createBinaryProfile()") final ConditionProfile primitiveProfile) {
    object.putIntoVariablePart(cachedIndex - cachedLayout.getInstSize(), value, nilProfile, primitiveProfile);
}
 
Example #16
Source File: LargeIntegers.java    From trufflesqueak with MIT License 5 votes vote down vote up
@Specialization(rewriteOn = ArithmeticException.class)
protected static final long doLong(final long lhs, final long rhs,
                @Cached("createBinaryProfile()") final ConditionProfile differentSignProfile) {
    if (differentSignProfile.profile(differentSign(lhs, rhs))) {
        return Math.subtractExact(lhs, rhs);
    } else {
        return Math.addExact(lhs, rhs);
    }
}
 
Example #17
Source File: LargeIntegers.java    From trufflesqueak with MIT License 5 votes vote down vote up
@Specialization
protected static final Object doLongLargeInteger(final long lhs, final LargeIntegerObject rhs,
                @Cached("createBinaryProfile()") final ConditionProfile differentSignProfile) {
    if (differentSignProfile.profile(rhs.differentSign(lhs))) {
        return rhs.add(lhs);
    } else {
        return LargeIntegerObject.subtract(lhs, rhs);
    }
}
 
Example #18
Source File: ClassObject.java    From trufflesqueak with MIT License 5 votes vote down vote up
@Specialization(guards = "arguments.length == 0")
protected static final Object doNoArguments(final ClassObject receiver, final Object[] arguments,
                @Shared("newObjectNode") @Cached final SqueakObjectNewNode newObjectNode,
                @CachedLibrary(limit = "2") final InteropLibrary initializer,
                @CachedContext(SqueakLanguage.class) final SqueakImageContext theImage) throws UnsupportedTypeException {
    final AbstractSqueakObjectWithHash newObject = newObjectNode.execute(theImage, receiver);
    initializeObject(arguments, initializer, newObject);
    return newObject;
}
 
Example #19
Source File: IOPrimitives.java    From trufflesqueak with MIT License 5 votes vote down vote up
@Specialization(guards = {"rcvr.isIntType()", "repl.isIntType()"})
protected static final void doNativeInts(final NativeObject rcvr, final long start, final long stop, final NativeObject repl, final long replStart,
                @Shared("errorProfile") @Cached final BranchProfile errorProfile) {
    try {
        System.arraycopy(repl.getIntStorage(), (int) replStart - 1, rcvr.getIntStorage(), (int) start - 1, (int) (1 + stop - start));
    } catch (final IndexOutOfBoundsException e) {
        errorProfile.enter();
        throw PrimitiveFailed.BAD_INDEX;
    }
}
 
Example #20
Source File: DispatchClosureNode.java    From trufflesqueak with MIT License 5 votes vote down vote up
@SuppressWarnings("unused")
@Specialization(guards = {"closure.getCompiledBlock() == cachedBlock"}, assumptions = {"cachedBlock.getCallTargetStable()"}, limit = "INLINE_CACHE_SIZE")
protected static final Object doDirect(final BlockClosureObject closure, final Object[] arguments,
                @Cached("closure.getCompiledBlock()") final CompiledBlockObject cachedBlock,
                @Cached("create(cachedBlock.getCallTarget())") final DirectCallNode directCallNode) {
    return directCallNode.call(arguments);
}
 
Example #21
Source File: SqueakObjectNewNode.java    From trufflesqueak with MIT License 5 votes vote down vote up
@Specialization(guards = {"classObject.isNonIndexableWithInstVars()", "!classObject.isMetaClass()", "!classObject.instancesAreClasses()",
                "classObject.getLayout() == cachedLayout"}, limit = "NEW_CACHE_SIZE")
protected static final PointersObject doPointers(final SqueakImageContext image, final ClassObject classObject, final int extraSize,
                @Cached(value = "classObject.getLayout()", allowUncached = true) final ObjectLayout cachedLayout) {
    assert extraSize == 0;
    return new PointersObject(image, classObject, cachedLayout);
}
 
Example #22
Source File: ControlPrimitives.java    From trufflesqueak with MIT License 5 votes vote down vote up
@SuppressWarnings("unused")
@Specialization(guards = {"!isNotProvided(object1)", "!isNotProvided(object2)"}, replaces = "perform2Cached")
protected static final Object perform2(final VirtualFrame frame, final Object receiver, final NativeObject selector, final Object object1, final Object object2,
                final NotProvided object3, final NotProvided object4, final NotProvided object5,
                @Cached final SqueakObjectClassNode lookupClassNode,
                @Cached final LookupMethodNode lookupMethodNode,
                @Cached final DispatchSendSelectorNode dispatchNode) {
    return dispatchUncached(frame, selector, new Object[]{receiver, object1, object2}, lookupClassNode, lookupMethodNode, dispatchNode);
}
 
Example #23
Source File: DispatchUneagerlyNode.java    From trufflesqueak with MIT License 5 votes vote down vote up
@Specialization(guards = {"method == cachedMethod"}, //
                limit = "INLINE_CACHE_SIZE", assumptions = "cachedMethod.getCallTargetStable()")
protected static final Object doDirect(@SuppressWarnings("unused") final CompiledMethodObject method, final Object[] receiverAndArguments, final Object contextOrMarker,
                @SuppressWarnings("unused") @Cached("method") final CompiledMethodObject cachedMethod,
                @Cached("create(cachedMethod.getCallTarget())") final DirectCallNode callNode) {
    return callNode.call(FrameAccess.newWith(cachedMethod, contextOrMarker, null, receiverAndArguments));
}
 
Example #24
Source File: DispatchSendNode.java    From trufflesqueak with MIT License 5 votes vote down vote up
@Specialization(guards = {"lookupResult == null"})
protected final Object doDoesNotUnderstand(final VirtualFrame frame, final NativeObject selector, @SuppressWarnings("unused") final Object lookupResult, final ClassObject rcvrClass,
                final Object[] rcvrAndArgs,
                @Shared("writeNode") @Cached final AbstractPointersObjectWriteNode writeNode,
                @Cached final LookupMethodNode lookupNode,
                @CachedContext(SqueakLanguage.class) final SqueakImageContext image) {
    final CompiledMethodObject doesNotUnderstandMethod = (CompiledMethodObject) lookupNode.executeLookup(rcvrClass, image.doesNotUnderstand);
    final PointersObject message = image.newMessage(writeNode, selector, rcvrClass, ArrayUtils.allButFirst(rcvrAndArgs));
    return dispatchNode.executeDispatch(frame, doesNotUnderstandMethod, new Object[]{rcvrAndArgs[0], message});
}
 
Example #25
Source File: ControlPrimitives.java    From trufflesqueak with MIT License 5 votes vote down vote up
@SuppressWarnings("unused")
@Specialization(guards = {"selector == cachedSelector", "!isNotProvided(object1)", "!isNotProvided(object2)", "!isNotProvided(object3)"}, limit = "CACHE_LIMIT")
protected static final Object perform3Cached(final VirtualFrame frame, final Object receiver, final NativeObject selector, final Object object1, final Object object2,
                final Object object3, final NotProvided object4, final NotProvided object5,
                @Cached("selector") final NativeObject cachedSelector,
                @Cached final SqueakObjectClassNode lookupClassNode,
                @Cached final LookupMethodNode lookupMethodNode,
                @Cached("create(cachedSelector, getBlockOrMethod(frame))") final DispatchSendNode dispatchNode) {
    return dispatchCached(frame, cachedSelector, new Object[]{receiver, object1, object2, object3}, lookupClassNode, lookupMethodNode, dispatchNode);
}
 
Example #26
Source File: ArrayObject.java    From trufflesqueak with MIT License 5 votes vote down vote up
@ExportMessage
protected void writeArrayElement(final long index, final Object value,
                @Exclusive @Cached final WrapToSqueakNode wrapNode,
                @Cached final ArrayObjectWriteNode writeNode) throws InvalidArrayIndexException {
    try {
        writeNode.execute(this, index, wrapNode.executeWrap(value));
    } catch (final ArrayIndexOutOfBoundsException e) {
        throw InvalidArrayIndexException.create(index);
    }
}
 
Example #27
Source File: ControlPrimitives.java    From trufflesqueak with MIT License 5 votes vote down vote up
@Specialization(replaces = "performCached")
protected final Object perform(final VirtualFrame frame, final Object receiver, final NativeObject selector, final ArrayObject arguments,
                @Cached final SqueakObjectClassNode lookupClassNode,
                @Cached final LookupMethodNode lookupMethodNode,
                @Cached final DispatchSendSelectorNode dispatchNode) {
    final ClassObject rcvrClass = lookupClassNode.executeLookup(receiver);
    final Object lookupResult = lookupMethodNode.executeLookup(rcvrClass, selector);
    return dispatchNode.executeSend(frame, selector, lookupResult, rcvrClass, getObjectArrayNode.execute(receiver, arguments));
}
 
Example #28
Source File: BlockClosureObject.java    From trufflesqueak with MIT License 5 votes vote down vote up
@ExportMessage
public Object execute(final Object[] arguments,
                @Exclusive @Cached final WrapToSqueakNode wrapNode) throws ArityException {
    if (getNumArgs() == arguments.length) {
        final Object[] frameArguments = FrameAccess.newClosureArgumentsTemplate(this, NilObject.SINGLETON, arguments.length);
        for (int i = 0; i < arguments.length; i++) {
            frameArguments[FrameAccess.getArgumentStartIndex() + i] = wrapNode.executeWrap(arguments[i]);
        }
        return getCompiledBlock().getCallTarget().call(frameArguments);
    } else {
        throw ArityException.create((int) getNumArgs(), arguments.length);
    }
}
 
Example #29
Source File: GetOrCreateContextNode.java    From trufflesqueak with MIT License 5 votes vote down vote up
@Specialization(guards = "getContext(frame, code) == null", limit = "1")
protected static final ContextObject doCreate(final VirtualFrame frame,
                @Cached("getBlockOrMethod(frame)") final CompiledCodeObject code,
                @Cached final GetActiveProcessNode getActiveProcessNode) {
    final ContextObject result = ContextObject.create(frame.materialize(), code);
    result.setProcess(getActiveProcessNode.execute());
    return result;
}
 
Example #30
Source File: GetOrCreateContextNode.java    From trufflesqueak with MIT License 5 votes vote down vote up
@Specialization
protected static final ContextObject doCreate(final VirtualFrame frame,
                @Cached("getBlockOrMethod(frame)") final CompiledCodeObject code,
                @Cached("createCountingProfile()") final ConditionProfile hasContextProfile) {
    final ContextObject context = FrameAccess.getContext(frame, code);
    if (hasContextProfile.profile(context != null)) {
        return context;
    } else {
        return ContextObject.create(frame.materialize(), code);
    }
}