private static Object evalInContext(SuspendedEvent ev, Node node, MaterializedFrame frame, String code) { RootNode rootNode = node.getRootNode(); if (rootNode == null) { throw new IllegalArgumentException("Cannot evaluate in context using a node that is not yet adopated using a RootNode."); } LanguageInfo info = rootNode.getLanguageInfo(); if (info == null) { throw new IllegalArgumentException("Cannot evaluate in context using a without an associated TruffleLanguage."); } if (!info.isInteractive()) { throw new IllegalStateException("Can not evaluate in a non-interactive language."); } final Source source = Source.newBuilder(info.getId(), code, "eval in context").build(); ExecutableNode fragment = ev.getSession().getDebugger().getEnv().parseInline(source, node, frame); if (fragment != null) { ev.getInsertableNode().setParentOf(fragment); return fragment.execute(frame); } else { return Debugger.ACCESSOR.evalInContext(source, node, frame); } }
@CompilerDirectives.TruffleBoundary @Override public SourceSection getSourceSection() { if (sourceSection == null) { String patternSrc = "/" + source.getPattern() + "/" + source.getFlags(); Source src = Source.newBuilder(RegexLanguage.ID, patternSrc, source.getPattern()).mimeType("application/js-regex").build(); sourceSection = src.createSection(0, patternSrc.length()); } return sourceSection; }
/** * Evaluate the given code in this context. * * @param code the code to evaluate * @param languageId the language to evaluate the code in * @return result of the evaluation * @since 0.30 */ public DebugValue evaluate(String code, String languageId) { assert code != null; Object prevContext = context.enter(); try { Debugger debugger = executionLifecycle.getDebugger(); CallTarget target = debugger.getEnv().parse(Source.newBuilder(languageId, code, "eval").build()); Object result = target.call(); LanguageInfo languageInfo = debugger.getEnv().getLanguages().get(languageId); return new DebugValue.HeapValue(executionLifecycle.getSession(), languageInfo, null, result); } catch (IOException ex) { throw new RuntimeException(ex); } finally { context.leave(prevContext); } }
private void initializeConditional(MaterializedFrame frame) { Node instrumentedNode = context.getInstrumentedNode(); final RootNode rootNode = instrumentedNode.getRootNode(); if (rootNode == null) { throw new IllegalStateException("Probe was disconnected from the AST."); } Source instrumentedSource = context.getInstrumentedSourceSection().getSource(); Source conditionSource; synchronized (breakpoint) { conditionSource = Source.newBuilder(instrumentedSource.getLanguage(), breakpoint.condition, "breakpoint condition").mimeType(instrumentedSource.getMimeType()).build(); if (conditionSource == null) { throw new IllegalStateException("Condition is not resolved " + rootNode); } conditionUnchanged = breakpoint.getConditionUnchanged(); } ExecutableNode snippet = breakpoint.debugger.getEnv().parseInline(conditionSource, instrumentedNode, frame); if (snippet != null) { conditionSnippet = insert(snippet); notifyInserted(snippet); } else { CallTarget callTarget = Debugger.ACCESSOR.parse(conditionSource, instrumentedNode, new String[0]); conditionCallNode = insert(Truffle.getRuntime().createDirectCallNode(callTarget)); } } }
public Source getSource() { if (source == null) { String text = toString(); source = Source.newBuilder(RegexLanguage.ID, text, text).name(text).mimeType(RegexLanguage.MIME_TYPE).build(); } return source; }