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)); } } }
/** * 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 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); } }
/** * Creates a new file based source builder from a given file. A file based source is either * interpreted as {@link Source#hasBytes() binary} or {@link Source#hasCharacters() character} * source depending on the {@link LanguageInfo#getDefaultMimeType() default MIME type} of the * language, the {@link SourceBuilder#content(ByteSequence) contents} or the specified * {@link SourceBuilder#mimeType(String) MIME type}. A language may be detected from an existing * file using {@link #findLanguage(TruffleFile)}. * <p> * Example usage: {@link SourceSnippets#fromFile} * * @param language the language id, must not be <code>null</code> * @param file the file to use and load, must not be <code>null</code> * @since 1.0 */ public static SourceBuilder newBuilder(String language, TruffleFile file) { return EMPTY.new LiteralBuilder(language, file); }
/** * Creates a new URL based source builder from a given URL. A URL based source is either * interpreted as {@link Source#hasBytes() binary} or {@link Source#hasCharacters() character} * source depending on the {@link LanguageInfo#getDefaultMimeType() default MIME type} of the * language, the {@link SourceBuilder#content(ByteSequence) contents} or the specified * {@link SourceBuilder#mimeType(String) MIME type}. A language may be detected from an existing * file using {@link #findLanguage(URL)}. * <p> * Example usage: {@link SourceSnippets#fromURL} * * @param language the language id, must not be <code>null</code> * @param url the URL to use and load, must not be <code>null</code> * @since 1.0 */ public static SourceBuilder newBuilder(String language, URL url) { return EMPTY.new LiteralBuilder(language, url); }
/** * Creates a new character based source from a character sequence. The given characters must not * mutate after they were accessed for the first time. * <p> * Example usage: {@link SourceSnippets#fromAString} * * @param language the language id, must not be <code>null</code> * @param characters the character sequence or string, must not be <code>null</code> * @param name the name of the source, if <code>null</code> then <code>"Unnamed"</code> will be * used as name. * @since 1.0 */ public static LiteralBuilder newBuilder(String language, CharSequence characters, String name) { return EMPTY.new LiteralBuilder(language, characters).name(name); }
static SourceBuilder newBuilder(String language, File source) { return EMPTY.new LiteralBuilder(language, source); }
/** * Creates a new byte based source from a byte sequence. The given bytes must not mutate after * they were accessed for the first time. * <p> * Example usage: {@link SourceSnippets#fromBytes} * * @param language the language id, must not be <code>null</code> * @param bytes the byte sequence or string, must not be <code>null</code> * @param name the name of the source, if <code>null</code> then <code>"Unnamed"</code> will be * used as name. * @since 1.0 */ public static LiteralBuilder newBuilder(String language, ByteSequence bytes, String name) { return EMPTY.new LiteralBuilder(language, bytes).name(name); }
@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; }
/** * Creates new character based source from a reader. * * <p> * Example usage: {@link SourceSnippets#fromReader} * * @since 1.0 */ public static SourceBuilder newBuilder(String language, Reader source, String name) { return EMPTY.new LiteralBuilder(language, source).name(name); }