com.oracle.truffle.api.frame.FrameSlot Java Examples

The following examples show how to use com.oracle.truffle.api.frame.FrameSlot. 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: Namespace.java    From mumbler with GNU General Public License v3.0 6 votes vote down vote up
public Pair<Integer, FrameSlot> getIdentifier(String id) {
    int depth = 0;
    Namespace current = this;
    FrameSlot slot = current.frameDescriptor.findFrameSlot(id);
    while (slot == null) {
        depth++;
        current = current.parent;
        if (current == null) {
            return new Pair<>(LEVEL_UNDEFINED, null);
        }
        slot = current.frameDescriptor.findFrameSlot(id);
    }
    if (current.parent == null) {
        return new Pair<>(LEVEL_GLOBAL, slot);
    }
    return new Pair<>(depth, slot);
}
 
Example #2
Source File: HashemNodeFactory.java    From mr-hashemi with Universal Permissive License v1.0 6 votes vote down vote up
/**
 * Returns an {@link HashemWriteLocalVariableNode} for the given parameters.
 *
 * @param nameNode The name of the variable being assigned
 * @param valueNode The value to be assigned
 * @param argumentIndex null or index of the argument the assignment is assigning
 * @return An SLExpressionNode for the given parameters. null if nameNode or valueNode is null.
 */
public HashemExpressionNode createAssignment(HashemExpressionNode nameNode, HashemExpressionNode valueNode, Integer argumentIndex) {
    if (nameNode == null || valueNode == null) {
        return null;
    }

    String name = ((HashemStringLiteralNode) nameNode).executeGeneric(null);
    FrameSlot frameSlot = frameDescriptor.findOrAddFrameSlot(
                    name,
                    argumentIndex,
                    FrameSlotKind.Illegal);
    lexicalScope.locals.put(name, frameSlot);
    final HashemExpressionNode result = HashemWriteLocalVariableNodeGen.create(valueNode, frameSlot);

    if (valueNode.hasSource()) {
        final int start = nameNode.getSourceCharIndex();
        final int length = valueNode.getSourceEndIndex() - start;
        result.setSourceSection(start, length);
    }
    result.addExpressionTag();

    return result;
}
 
Example #3
Source File: HashemLexicalScope.java    From mr-hashemi with Universal Permissive License v1.0 6 votes vote down vote up
@ExportMessage
@TruffleBoundary
void writeMember(String member, Object value) throws UnsupportedMessageException, UnknownIdentifierException {
    if (frame == null) {
        throw UnsupportedMessageException.create();
    }
    FrameSlot slot = slots.get(member);
    if (slot == null) {
        throw UnknownIdentifierException.create(member);
    } else {
        Object info = slot.getInfo();
        if (args != null && info != null) {
            args[(Integer) info] = value;
        } else {
            frame.setObject(slot, value);
        }
    }
}
 
Example #4
Source File: HashemLexicalScope.java    From mr-hashemi with Universal Permissive License v1.0 6 votes vote down vote up
@ExportMessage
@TruffleBoundary
Object readMember(String member) throws UnknownIdentifierException {
    if (frame == null) {
        return HashemPooch.SINGLETON;
    }
    FrameSlot slot = slots.get(member);
    if (slot == null) {
        throw UnknownIdentifierException.create(member);
    } else {
        Object value;
        Object info = slot.getInfo();
        if (args != null && info != null) {
            value = args[(Integer) info];
        } else {
            value = frame.getValue(slot);
        }
        return value;
    }
}
 
Example #5
Source File: CompiledCodeObject.java    From trufflesqueak with MIT License 6 votes vote down vote up
protected void ensureCorrectNumberOfStackSlots() {
    final int requiredNumberOfStackSlots = getNumStackSlots();
    if (stackSlots == null) {
        CompilerDirectives.transferToInterpreterAndInvalidate();
        stackSlots = new FrameSlot[requiredNumberOfStackSlots];
        return;
    }
    final int currentNumberOfStackSlots = stackSlots.length;
    if (currentNumberOfStackSlots < requiredNumberOfStackSlots) {
        // Grow number of stack slots.
        CompilerDirectives.transferToInterpreterAndInvalidate();
        stackSlots = Arrays.copyOf(stackSlots, requiredNumberOfStackSlots);
    } else if (currentNumberOfStackSlots > requiredNumberOfStackSlots) {
        // Shrink number of stack slots.
        CompilerDirectives.transferToInterpreterAndInvalidate();
        for (int i = requiredNumberOfStackSlots; i < currentNumberOfStackSlots; i++) {
            frameDescriptor.removeFrameSlot(i);
        }
        stackSlots = Arrays.copyOf(stackSlots, requiredNumberOfStackSlots);
    }
}
 
Example #6
Source File: ContextObject.java    From trufflesqueak with MIT License 6 votes vote down vote up
private ContextObject(final ContextObject original) {
    super(original);
    final CompiledCodeObject code = FrameAccess.getBlockOrMethod(original.truffleFrame);
    hasModifiedSender = original.hasModifiedSender();
    escaped = original.escaped;
    size = original.size;
    // Create shallow copy of Truffle frame
    truffleFrame = Truffle.getRuntime().createMaterializedFrame(original.truffleFrame.getArguments().clone(), code.getFrameDescriptor());
    // Copy frame slot values
    FrameAccess.initializeMarker(truffleFrame, code);
    FrameAccess.setContext(truffleFrame, code, this);
    FrameAccess.setInstructionPointer(truffleFrame, code, FrameAccess.getInstructionPointer(original.truffleFrame, code));
    FrameAccess.setStackPointer(truffleFrame, code, FrameAccess.getStackPointer(original.truffleFrame, code));
    // Copy stack
    final int numStackSlots = code.getNumStackSlots();
    for (int i = 0; i < numStackSlots; i++) {
        final FrameSlot slot = code.getStackSlot(i);
        final Object value = original.truffleFrame.getValue(slot);
        if (value != null) {
            FrameAccess.setStackSlot(truffleFrame, slot, value);
        } else {
            break; // This and all following slots are not in use.
        }
    }
}
 
Example #7
Source File: ContextObjectInfo.java    From trufflesqueak with MIT License 6 votes vote down vote up
@ExportMessage
@TruffleBoundary
public boolean isMemberReadable(final String member) {
    for (final String field : ALL_FIELDS) {
        if (field.equals(member)) {
            return true;
        }
    }
    final FrameSlot slot = slots.get(member);
    if (slot == null) {
        return false;
    }
    final CompiledCodeObject blockOrMethod = FrameAccess.getBlockOrMethod(frame);
    int i = 0;
    for (final FrameSlot currentSlot : blockOrMethod.getStackSlotsUnsafe()) {
        if (currentSlot == slot) {
            return i < FrameAccess.getStackPointer(frame, blockOrMethod);
        }
        i++;
    }
    throw SqueakException.create("Unable to find slot");
}
 
Example #8
Source File: GetContextOrMarkerNode.java    From trufflesqueak with MIT License 6 votes vote down vote up
public static Object getNotProfiled(final VirtualFrame frame) {
    CompilerAsserts.neverPartOfCompilation();
    final ContextObject context = FrameAccess.getContext(frame);
    if (context != null) {
        return context;
    } else {
        final FrameSlot markerSlot = FrameAccess.getMarkerSlot(frame);
        final FrameMarker marker = FrameAccess.getMarker(frame, markerSlot);
        if (marker != null) {
            return marker;
        } else {
            final FrameMarker newMarker = new FrameMarker();
            FrameAccess.setMarker(frame, markerSlot, newMarker);
            return newMarker;
        }
    }
}
 
Example #9
Source File: HashemNodeFactory.java    From mr-hashemi with Universal Permissive License v1.0 6 votes vote down vote up
/**
 * Returns a {@link HashemReadLocalVariableNode} if this read is a local variable or a
 * {@link HashemBebinLiteralNode} if this read is global. In SL, the only global names are
 * functions.
 *
 * @param nameNode The name of the variable/function being read
 * @return either:
 *         <ul>
 *         <li>A SLReadLocalVariableNode representing the local variable being read.</li>
 *         <li>A SLFunctionLiteralNode representing the function definition.</li>
 *         <li>null if nameNode is null.</li>
 *         </ul>
 */
public HashemExpressionNode createRead(HashemExpressionNode nameNode) {
    if (nameNode == null) {
        return null;
    }

    String name = ((HashemStringLiteralNode) nameNode).executeGeneric(null);
    final HashemExpressionNode result;
    final FrameSlot frameSlot = lexicalScope.locals.get(name);
    if (frameSlot != null) {
        /* Read of a local variable. */
        result = HashemReadLocalVariableNodeGen.create(frameSlot);
    } else {
        /* Read of a global name. In our language, the only global names are functions. */
        result = new HashemBebinLiteralNode(name);
    }
    result.setSourceSection(nameNode.getSourceCharIndex(), nameNode.getSourceLength());
    result.addExpressionTag();
    return result;
}
 
Example #10
Source File: Converter.java    From mumbler with GNU General Public License v3.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
private LambdaNode convertLambda(ListSyntax syntax, Namespace ns) {
	MumblerList<? extends Syntax<?>> list = syntax.getValue();
    Namespace lambdaNs = this.analyzer.getNamespace(syntax);
    List<FrameSlot> formalParameters = new ArrayList<>();
    ListSyntax argsSyntax = (ListSyntax) list.cdr().car();
    for (SymbolSyntax arg : (MumblerList<SymbolSyntax>) argsSyntax.getValue()) {
        formalParameters.add(convert(arg, lambdaNs).getSlot());
    }
    List<MumblerNode> bodyNodes = new ArrayList<>();
    for (Syntax<?> body : list.cdr().cdr()) {
        bodyNodes.add(convert(body, lambdaNs));
    }

    bodyNodes.get(bodyNodes.size() - 1).setIsTail();

    MumblerFunction function = MumblerFunction.create(
            lang,
            formalParameters.toArray(new FrameSlot[] {}),
            bodyNodes.toArray(new MumblerNode[] {}),
            lambdaNs.getFrameDescriptor());
    LambdaNode node = LambdaNodeGen.create(function);
    node.setSourceSection(syntax.getSourceSection());
    return node;
}
 
Example #11
Source File: Converter.java    From mumbler with GNU General Public License v3.0 6 votes vote down vote up
public SymbolNode convert(SymbolSyntax syntax, Namespace ns) {
	SymbolNode node;
	MumblerSymbol sym = syntax.getValue();
    Pair<Integer, FrameSlot> pair = ns.getIdentifier(sym.name);
    if (pair.a == Namespace.LEVEL_UNDEFINED) {
        throwReaderException(sym.name + " undefined", syntax, ns);
        return null;
    } else if (pair.a == 0) {
        node = LocalSymbolNodeGen.create(pair.b);
    } else if (pair.a == Namespace.LEVEL_GLOBAL) {
        node = GlobalSymbolNodeGen.create(pair.b, this.context.getGlobalFrame());
    } else {
        node = ClosureSymbolNodeGen.create(pair.b, pair.a);
    }
    node.setSourceSection(syntax.getSourceSection());
    return node;
}
 
Example #12
Source File: FrameAccess.java    From trufflesqueak with MIT License 6 votes vote down vote up
/** Write to a frame slot (slow operation), prefer {@link FrameStackPushNode}. */
public static void setStackSlot(final Frame frame, final FrameSlot frameSlot, final Object value) {
    final FrameDescriptor frameDescriptor = frame.getFrameDescriptor();
    assert frame.getFrameDescriptor().getSlots().contains(frameSlot);
    final FrameSlotKind frameSlotKind = frameDescriptor.getFrameSlotKind(frameSlot);
    final boolean isIllegal = frameSlotKind == FrameSlotKind.Illegal;
    if (value instanceof Boolean && (isIllegal || frameSlotKind == FrameSlotKind.Boolean)) {
        frameDescriptor.setFrameSlotKind(frameSlot, FrameSlotKind.Boolean);
        frame.setBoolean(frameSlot, (boolean) value);
    } else if (value instanceof Long && (isIllegal || frameSlotKind == FrameSlotKind.Long)) {
        frameDescriptor.setFrameSlotKind(frameSlot, FrameSlotKind.Long);
        frame.setLong(frameSlot, (long) value);
    } else if (value instanceof Double && (isIllegal || frameSlotKind == FrameSlotKind.Double)) {
        frameDescriptor.setFrameSlotKind(frameSlot, FrameSlotKind.Double);
        frame.setDouble(frameSlot, (double) value);
    } else {
        frameDescriptor.setFrameSlotKind(frameSlot, FrameSlotKind.Object);
        frame.setObject(frameSlot, value);
    }
}
 
Example #13
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 #14
Source File: ObjectGraphUtils.java    From trufflesqueak with MIT License 6 votes vote down vote up
private void addObjectsFromTruffleFrames() {
    CompilerAsserts.neverPartOfCompilation();
    Truffle.getRuntime().iterateFrames(frameInstance -> {
        final Frame current = frameInstance.getFrame(FrameInstance.FrameAccess.READ_ONLY);
        if (!FrameAccess.isTruffleSqueakFrame(current)) {
            return null;
        }
        for (final Object argument : current.getArguments()) {
            addIfUnmarked(argument);
        }
        final CompiledCodeObject blockOrMethod = FrameAccess.getBlockOrMethod(current);
        addIfUnmarked(FrameAccess.getContext(current, blockOrMethod));
        for (final FrameSlot slot : blockOrMethod.getStackSlotsUnsafe()) {
            if (slot == null) {
                return null; // Stop here, slot has not (yet) been created.
            }
            if (current.isObject(slot)) {
                addIfUnmarked(FrameUtil.getObjectSafe(current, slot));
            }
        }
        return null;
    });
}
 
Example #15
Source File: DispatchEagerlyFromStackNode.java    From trufflesqueak with MIT License 5 votes vote down vote up
@Specialization(guards = {"cachedMethod.hasPrimitive()", "method == cachedMethod", "primitiveNode != null"}, //
                limit = "INLINE_CACHE_SIZE", assumptions = {"cachedMethod.getCallTargetStable()"}, rewriteOn = PrimitiveFailed.class)
protected final Object doPrimitiveEagerly(final VirtualFrame frame, @SuppressWarnings("unused") final CompiledMethodObject method,
                @SuppressWarnings("unused") @Cached("method") final CompiledMethodObject cachedMethod,
                @Cached("forIndex(cachedMethod, true, cachedMethod.primitiveIndex())") final AbstractPrimitiveNode primitiveNode,
                @Cached("getStackPointerSlot(frame)") final FrameSlot stackPointerSlot,
                @Cached("getStackPointer(frame, stackPointerSlot)") final int stackPointer,
                @Cached final PrimitiveFailedCounter failureCounter) {
    /**
     * Pretend that values are popped off the stack. Primitive nodes will read them using
     * ArgumentOnStackNodes.
     */
    FrameAccess.setStackPointer(frame, stackPointerSlot, stackPointer - 1 - argumentCount);
    try {
        return primitiveNode.executePrimitive(frame);
    } catch (final PrimitiveFailed pf) {
        CompilerDirectives.transferToInterpreterAndInvalidate();
        // Restore stackPointer.
        FrameAccess.setStackPointer(frame, stackPointerSlot, stackPointer);
        if (failureCounter.shouldNoLongerSendEagerly()) {
            throw pf; // Rewrite specialization.
        } else {
            // Slow path send to fallback code.
            final Object[] receiverAndArguments = FrameStackPopNNode.create(1 + argumentCount).execute(frame);
            return IndirectCallNode.getUncached().call(method.getCallTarget(),
                            FrameAccess.newWith(cachedMethod, FrameAccess.getContextOrMarkerSlow(frame), null, receiverAndArguments));
        }
    }
}
 
Example #16
Source File: TruffleAST.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public Object[] getRawSlots() {
    Frame frame = frameInstance.getFrame(FrameInstance.FrameAccess.MATERIALIZE);
    List<? extends FrameSlot> slots = frame.getFrameDescriptor().getSlots();
    int n = slots.size();
    Object[] slotInfo = new Object[2*n];
    for (int i = 0; i < n; i++) {
        FrameSlot slot = slots.get(i);
        slotInfo[2*i] = slot.getIdentifier();
        slotInfo[2*i + 1] = frame.getValue(slot);
    }
    return slotInfo;
}
 
Example #17
Source File: MumblerRootNode.java    From mumbler with GNU General Public License v3.0 5 votes vote down vote up
public static MumblerRootNode create(MumblerLanguage lang, FrameSlot[] argumentNames,
        MumblerNode[] bodyNodes, FrameDescriptor frameDescriptor) {
    MumblerNode[] allNodes = new MumblerNode[argumentNames.length
                                             + bodyNodes.length];
    for (int i=0; i<argumentNames.length; i++) {
        allNodes[i] = DefineNodeGen.create(
                new ReadArgumentNode(i), argumentNames[i]);
    }
    System.arraycopy(bodyNodes, 0, allNodes,
            argumentNames.length, bodyNodes.length);
    return new MumblerRootNode(lang, allNodes, frameDescriptor);
}
 
Example #18
Source File: ContextObjectInfo.java    From trufflesqueak with MIT License 5 votes vote down vote up
public ContextObjectInfo(final Frame frame) {
    this.frame = frame;
    final CompiledCodeObject code = FrameAccess.getBlockOrMethod(frame);
    for (final FrameSlot slot : code.getStackSlotsUnsafe()) {
        if (slot == null) {
            break;
        }
        slots.put(Objects.toString(slot.getIdentifier()), slot);
    }
}
 
Example #19
Source File: DefineNode.java    From mumbler with GNU General Public License v3.0 5 votes vote down vote up
private boolean isKind(FrameSlot slot, FrameSlotKind kind) {
	if (slot.getKind() == kind) {
		return true;
	}
	if (slot.getKind() == FrameSlotKind.Illegal) {
		CompilerDirectives.transferToInterpreterAndInvalidate();
		slot.setKind(kind);
		return true;
	}
	return false;
}
 
Example #20
Source File: DefineNode.java    From mumbler with GNU General Public License v3.0 5 votes vote down vote up
@Specialization(replaces = {"writeLong", "writeBoolean"})
protected Object write(VirtualFrame virtualFrame, Object value) {
	FrameSlot slot = this.getSlot();
	if (slot.getKind() != FrameSlotKind.Object) {
		CompilerDirectives.transferToInterpreterAndInvalidate();
		slot.setKind(FrameSlotKind.Object);
	}
	virtualFrame.setObject(slot, value);
	return value;
}
 
Example #21
Source File: ContextObjectInfo.java    From trufflesqueak with MIT License 5 votes vote down vote up
@ExportMessage
@TruffleBoundary
public Object readMember(final String member) throws UnknownIdentifierException {
    if (frame == null) {
        return NilObject.SINGLETON;
    }
    if (SENDER.equals(member)) {
        return FrameAccess.getSender(frame);
    }
    if (PC.equals(member)) {
        return FrameAccess.getInstructionPointer(frame, FrameAccess.getBlockOrMethod(frame));
    }
    if (STACKP.equals(member)) {
        return FrameAccess.getStackPointer(frame, FrameAccess.getBlockOrMethod(frame));
    }
    if (METHOD.equals(member)) {
        return FrameAccess.getMethod(frame);
    }
    if (CLOSURE_OR_NIL.equals(member)) {
        return NilObject.nullToNil(FrameAccess.getClosure(frame));
    }
    if (RECEIVER.equals(member)) {
        return FrameAccess.getReceiver(frame);
    }
    final FrameSlot slot = slots.get(member);
    if (slot == null) {
        throw UnknownIdentifierException.create(member);
    } else {
        return Objects.requireNonNull(frame.getValue(slot));
    }
}
 
Example #22
Source File: HashemLexicalScope.java    From mr-hashemi with Universal Permissive License v1.0 5 votes vote down vote up
private Map<String, FrameSlot> collectVars(Node varsBlock, Node currentNode) {
    // Variables are slot-based.
    // To collect declared variables, traverse the block's AST and find slots associated
    // with SLWriteLocalVariableNode. The traversal stops when we hit the current node.
    Map<String, FrameSlot> slots = new LinkedHashMap<>(4);
    NodeUtil.forEachChild(varsBlock, new NodeVisitor() {
        @Override
        public boolean visit(Node node) {
            if (node == currentNode) {
                return false;
            }
            // Do not enter any nested blocks.
            if (!(node instanceof HashemBlockNode)) {
                boolean all = NodeUtil.forEachChild(node, this);
                if (!all) {
                    return false;
                }
            }
            // Write to a variable is a declaration unless it exists already in a parent scope.
            if (node instanceof HashemWriteLocalVariableNode) {
                HashemWriteLocalVariableNode wn = (HashemWriteLocalVariableNode) node;
                String name = Objects.toString(wn.getSlot().getIdentifier());
                if (!hasParentVar(name)) {
                    slots.put(name, wn.getSlot());
                }
            }
            return true;
        }
    });
    return slots;
}
 
Example #23
Source File: ContextObjectInfo.java    From trufflesqueak with MIT License 5 votes vote down vote up
@ExportMessage
@TruffleBoundary
public void writeMember(final String member, final Object value) throws UnknownIdentifierException, UnsupportedMessageException {
    if (frame == null) {
        throw UnsupportedMessageException.create();
    }
    final FrameSlot slot = slots.get(member);
    if (slot != null) {
        FrameAccess.setStackSlot(frame, slot, value);
    } else {
        throw UnknownIdentifierException.create(member);
    }
}
 
Example #24
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 #25
Source File: HashemLexicalScope.java    From mr-hashemi with Universal Permissive License v1.0 5 votes vote down vote up
private Map<String, FrameSlot> getVars() {
    if (varSlots == null) {
        if (current != null) {
            varSlots = collectVars(block, current);
        } else if (block != null) {
            // Provide the arguments only when the current node is above the block
            varSlots = collectArgs(block);
        } else {
            varSlots = Collections.emptyMap();
        }
    }
    return varSlots;
}
 
Example #26
Source File: HashemLexicalScope.java    From mr-hashemi with Universal Permissive License v1.0 5 votes vote down vote up
public Object getArguments(Frame frame) {
    if (root == null) {
        // No arguments for block scope
        return null;
    }
    // The slots give us names of the arguments:
    Map<String, FrameSlot> argSlots = collectArgs(block);
    // The frame's arguments array give us the argument values:
    Object[] args = (frame != null) ? frame.getArguments() : null;
    // Create a TruffleObject having the arguments as properties:
    return new VariablesMapObject(argSlots, args, frame);
}
 
Example #27
Source File: HashemEvaluateLocalNode.java    From mr-hashemi with Universal Permissive License v1.0 5 votes vote down vote up
@Override
public Object execute(VirtualFrame currentFrame) {
    for (FrameSlot slot : inspectFrame.getFrameDescriptor().getSlots()) {
        if (variable.equals(slot.getIdentifier())) {
            return inspectFrame.getValue(slot);
        }
    }
    return null;
}
 
Example #28
Source File: Converter.java    From mumbler with GNU General Public License v3.0 5 votes vote down vote up
private DefineNode convertDefine(ListSyntax syntax, Namespace ns) {
    MumblerList<? extends Syntax<?>> list = syntax.getValue();
    SymbolSyntax symSyntax = (SymbolSyntax) list.cdr().car();
    FrameSlot nameSlot = ns.getIdentifier(symSyntax.getValue().name).b;
    MumblerNode valueNode = convert(list.cdr().cdr().car(), ns);
    DefineNode node = DefineNodeGen.create(valueNode, nameSlot);
    node.setSourceSection(syntax.getSourceSection());
    if (valueNode instanceof LambdaNode) {
        // TODO : not good enough. if there's an error in the lambda,
        // the name won't be used. Have to pass name
        LambdaNode lambda = (LambdaNode) valueNode;
        lambda.setName(nameSlot.toString());
    }
    return node;
}
 
Example #29
Source File: HashemLexicalScope.java    From mr-hashemi with Universal Permissive License v1.0 5 votes vote down vote up
public Object getVariables(Frame frame) {
    Map<String, FrameSlot> vars = getVars();
    Object[] args = null;
    // Use arguments when the current node is above the block
    if (current == null) {
        args = (frame != null) ? frame.getArguments() : null;
    }
    return new VariablesMapObject(vars, args, frame);
}
 
Example #30
Source File: HashemStackTraceBuiltin.java    From mr-hashemi with Universal Permissive License v1.0 5 votes vote down vote up
@TruffleBoundary
private static String createStackTrace() {
    final StringBuilder str = new StringBuilder();

    Truffle.getRuntime().iterateFrames(new FrameInstanceVisitor<Integer>() {
        private int skip = 1; // skip stack trace builtin

        @Override
        public Integer visitFrame(FrameInstance frameInstance) {
            if (skip > 0) {
                skip--;
                return null;
            }
            CallTarget callTarget = frameInstance.getCallTarget();
            Frame frame = frameInstance.getFrame(FrameAccess.READ_ONLY);
            RootNode rn = ((RootCallTarget) callTarget).getRootNode();
            // ignore internal or interop stack frames
            if (rn.isInternal() || rn.getLanguageInfo() == null) {
                return 1;
            }
            if (str.length() > 0) {
                str.append(System.getProperty("line.separator"));
            }
            str.append("Frame: ").append(rn.toString());
            FrameDescriptor frameDescriptor = frame.getFrameDescriptor();
            for (FrameSlot s : frameDescriptor.getSlots()) {
                str.append(", ").append(s.getIdentifier()).append("=").append(frame.getValue(s));
            }
            return null;
        }
    });
    return str.toString();
}