Package com.oracle.truffle.api.frame

Examples of com.oracle.truffle.api.frame.Frame


    }

    public static void setCurrentVisibility(Visibility visibility) {
        RubyNode.notDesignedForCompilation();

        final Frame callerFrame = Truffle.getRuntime().getCallerFrame().getFrame(FrameInstance.FrameAccess.READ_WRITE, false);

        assert callerFrame != null;
        assert callerFrame.getFrameDescriptor() != null;

        final FrameSlot visibilitySlot = callerFrame.getFrameDescriptor().findFrameSlot(VISIBILITY_FRAME_SLOT_ID);
        assert visibilitySlot != null;

        callerFrame.setObject(visibilitySlot, visibility);
    }
View Full Code Here


    @CompilerDirectives.SlowPath
    public Object matchOperator(String string) {
        // TODO(CS) merge with match

        final Frame frame = Truffle.getRuntime().getCallerFrame().getFrame(FrameInstance.FrameAccess.READ_WRITE, false);

        final RubyContext context = getContext();

        final byte[] stringBytes = string.getBytes(StandardCharsets.UTF_8);
        final Matcher matcher = regex.matcher(stringBytes);
        final int match = matcher.search(0, stringBytes.length, Option.DEFAULT);

        if (match != -1) {
            final Region region = matcher.getEagerRegion();

            final Object[] values = new Object[region.numRegs];

            for (int n = 0; n < region.numRegs; n++) {
                final int start = region.beg[n];
                final int end = region.end[n];

                final Object groupString;

                if (start > -1 && end > -1) {
                    groupString = context.makeString(string.substring(start, end));
                } else {
                    groupString = getContext().getCoreLibrary().getNilObject();
                }

                values[n] = groupString;

                final FrameSlot slot = frame.getFrameDescriptor().findFrameSlot("$" + n);

                if (slot != null) {
                    frame.setObject(slot, groupString);
                }
            }

            if (values.length > 0) {
                final FrameSlot slot = frame.getFrameDescriptor().findFrameSlot("$+");

                int nonNil = values.length - 1;

                while (values[nonNil] == getContext().getCoreLibrary().getNilObject()) {
                    nonNil--;
                }

                if (slot != null) {
                    frame.setObject(slot, values[nonNil]);
                }
            }

            final RubyMatchData matchObject =  new RubyMatchData(context.getCoreLibrary().getMatchDataClass(), values);

            final FrameSlot slot = frame.getFrameDescriptor().findFrameSlot("$~");

            if (slot != null) {
                frame.setObject(slot, matchObject);
            }

            return matcher.getBegin();
        } else {
            final FrameSlot slot = frame.getFrameDescriptor().findFrameSlot("$~");

            if (slot != null) {
                frame.setObject(slot, getContext().getCoreLibrary().getNilObject());
            }

            return getContext().getCoreLibrary().getNilObject();
        }
    }
View Full Code Here

    @CompilerDirectives.SlowPath
    public Object match(RubyString string) {
        final RubyContext context = getContext();

        final Frame frame = Truffle.getRuntime().getCallerFrame().getFrame(FrameInstance.FrameAccess.READ_WRITE, false);

        final byte[] stringBytes = string.getBytes().bytes();
        final Matcher matcher = regex.matcher(stringBytes);
        final int match = matcher.search(0, stringBytes.length, Option.DEFAULT);

        if (match != -1) {
            final Region region = matcher.getEagerRegion();

            final Object[] values = new Object[region.numRegs];

            for (int n = 0; n < region.numRegs; n++) {
                final int start = region.beg[n];
                final int end = region.end[n];

                if (start == -1 || end == -1) {
                    values[n] = getContext().getCoreLibrary().getNilObject();
                } else {
                    final RubyString groupString = new RubyString(context.getCoreLibrary().getStringClass(), string.getBytes().makeShared(start, end - start).dup());
                    values[n] = groupString;
                }
            }

            final RubyMatchData matchObject =  new RubyMatchData(context.getCoreLibrary().getMatchDataClass(), values);

            final FrameSlot slot = frame.getFrameDescriptor().findFrameSlot("$~");

            if (slot != null) {
                frame.setObject(slot, matchObject);
            }

            return matchObject;
        } else {
            final FrameSlot slot = frame.getFrameDescriptor().findFrameSlot("$~");

            if (slot != null) {
                frame.setObject(slot, getContext().getCoreLibrary().getNilObject());
            }

            return getContext().getCoreLibrary().getNilObject();
        }
    }
View Full Code Here

        return RNull.instance;
    }

    private void removeFromCurrentFrame(VirtualFrame frame, String x) {
        // standard case for lookup in current frame
        Frame frm = frame;
        FrameSlot fs = frame.getFrameDescriptor().findFrameSlot(x);
        while (fs == null && frm != null) {
            frm = RArguments.getEnclosingFrame(frm);
            if (frm != null) {
                fs = frm.getFrameDescriptor().findFrameSlot(x);
            }
        }
        if (fs == null) {
            RError.warning(this.getEncapsulatingSourceSection(), RError.Message.UNKNOWN_OBJECT, x);
        } else {
            frm.setObject(fs, null); // use null (not an R value) to represent "undefined"
        }
    }
View Full Code Here

TOP

Related Classes of com.oracle.truffle.api.frame.Frame

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.