com.oracle.truffle.api.nodes.RootNode Java Examples
The following examples show how to use
com.oracle.truffle.api.nodes.RootNode.
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: HashemParseInContextTest.java From mr-hashemi with Universal Permissive License v1.0 | 6 votes |
@Override protected CallTarget parse(ParsingRequest request) throws Exception { return Truffle.getRuntime().createCallTarget(new RootNode(this) { @CompilationFinal private ContextReference<Env> reference; @Override public Object execute(VirtualFrame frame) { return parseAndEval(); } @TruffleBoundary private Object parseAndEval() { if (reference == null) { CompilerDirectives.transferToInterpreterAndInvalidate(); this.reference = lookupContextReference(EvalLang.class); } Source aPlusB = Source.newBuilder("hashemi", "a + b", "plus.hashem").build(); return reference.get().parsePublic(aPlusB, "a", "b").call(30, 12); } }); }
Example #2
Source File: HashemStatementNode.java From mr-hashemi with Universal Permissive License v1.0 | 5 votes |
@Override @TruffleBoundary public final SourceSection getSourceSection() { if (sourceCharIndex == NO_SOURCE) { // AST node without source return null; } RootNode rootNode = getRootNode(); if (rootNode == null) { // not yet adopted yet return null; } SourceSection rootSourceSection = rootNode.getSourceSection(); if (rootSourceSection == null) { return null; } Source source = rootSourceSection.getSource(); if (sourceCharIndex == UNAVAILABLE_SOURCE) { if (hasRootTag && !rootSourceSection.isAvailable()) { return rootSourceSection; } else { return source.createUnavailableSection(); } } else { return source.createSection(sourceCharIndex, sourceLength); } }
Example #3
Source File: HashemStackTraceBuiltin.java From mr-hashemi with Universal Permissive License v1.0 | 5 votes |
@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(); }
Example #4
Source File: HashemInstrumentTest.java From mr-hashemi with Universal Permissive License v1.0 | 5 votes |
private static void checkRootNode(Scope ls, String name, MaterializedFrame frame) { assertEquals(name, ls.getName()); Node node = ls.getNode(); assertTrue(node.getClass().getName(), node instanceof RootNode); assertEquals(name, ((RootNode) node).getName()); assertEquals(frame.getFrameDescriptor(), ((RootNode) node).getFrameDescriptor()); }
Example #5
Source File: HashemInstrumentTest.java From mr-hashemi with Universal Permissive License v1.0 | 5 votes |
private static void checkBlock(Scope ls) { assertEquals("block", ls.getName()); // Test that ls.getNode() does not return the current root node, it ought to be a block node Node node = ls.getNode(); assertNotNull(node); assertFalse(node.getClass().getName(), node instanceof RootNode); }
Example #6
Source File: DebuggerVisualizer.java From netbeans with Apache License 2.0 | 5 votes |
static String getDisplayName(CallTarget ct) { if (ct instanceof RootCallTarget) { RootNode rn = ((RootCallTarget) ct).getRootNode(); return getMethodName(rn); } else { //System.err.println("Unexpected CallTarget: "+ct.getClass()); return ct.toString(); } }
Example #7
Source File: MumblerException.java From mumbler with GNU General Public License v3.0 | 5 votes |
public static Throwable fillInMumblerStackTrace(Throwable t) { final List<StackTraceElement> stackTrace = new ArrayList<>(); Truffle.getRuntime().iterateFrames((FrameInstanceVisitor<Void>) frame -> { Node callNode = frame.getCallNode(); if (callNode == null) { return null; } RootNode root = callNode.getRootNode(); /* * There should be no RootNodes other than SLRootNodes on the stack. Just for the * case if this would change. */ String methodName = "$unknownFunction"; if (root instanceof MumblerRootNode) { methodName = ((MumblerRootNode) root).name; } SourceSection sourceSection = callNode.getEncapsulatingSourceSection(); Source source = sourceSection != null ? sourceSection.getSource() : null; String sourceName = source != null ? source.getName() : null; int lineNumber; try { lineNumber = sourceSection != null ? sourceSection.getStartLine() : -1; } catch (UnsupportedOperationException e) { /* * SourceSection#getLineLocation() may throw an UnsupportedOperationException. */ lineNumber = -1; } stackTrace.add(new StackTraceElement("mumbler", methodName, sourceName, lineNumber)); return null; }); t.setStackTrace(stackTrace.toArray(new StackTraceElement[stackTrace.size()])); return t; }
Example #8
Source File: HashemLanguage.java From mr-hashemi with Universal Permissive License v1.0 | 4 votes |
@Override protected CallTarget parse(ParsingRequest request) throws Exception { Source source = request.getSource(); Map<String, RootCallTarget> functions; /* * Parse the provided source. At this point, we do not have a SLContext yet. Registration of * the functions with the SLContext happens lazily in SLEvalRootNode. */ if (request.getArgumentNames().isEmpty()) { functions = HashemLanguageParser.parseHashemiLang(this, source); } else { Source requestedSource = request.getSource(); StringBuilder sb = new StringBuilder(); sb.append("bebin azinja("); String sep = ""; for (String argumentName : request.getArgumentNames()) { sb.append(sep); sb.append(argumentName); sep = ","; } sb.append(") { return "); sb.append(request.getSource().getCharacters()); sb.append(";}"); String language = requestedSource.getLanguage() == null ? ID : requestedSource.getLanguage(); Source decoratedSource = Source.newBuilder(language, sb.toString(), request.getSource().getName()).build(); functions = HashemLanguageParser.parseHashemiLang(this, decoratedSource); } RootCallTarget main = functions.get("azinja"); RootNode evalMain; if (main != null) { /* * We have a main function, so "evaluating" the parsed source means invoking that main * function. However, we need to lazily register functions into the SLContext first, so * we cannot use the original SLRootNode for the main function. Instead, we create a new * SLEvalRootNode that does everything we need. */ evalMain = new HashemEvalRootNode(this, main, functions); } else { /* * Even without a main function, "evaluating" the parsed source needs to register the * functions into the SLContext. */ evalMain = new HashemEvalRootNode(this, null, functions); } return Truffle.getRuntime().createCallTarget(evalMain); }
Example #9
Source File: DebuggerVisualizer.java From netbeans with Apache License 2.0 | 4 votes |
static String getMethodName(RootNode rn) { return rn.getName(); }
Example #10
Source File: ContextPrimitives.java From trufflesqueak with MIT License | 4 votes |
@TruffleBoundary @Specialization(guards = {"!receiver.hasMaterializedSender()"}) protected final AbstractSqueakObject findNextAvoidingMaterialization(final ContextObject receiver) { final boolean[] foundMyself = new boolean[1]; final Object[] lastSender = new Object[1]; final ContextObject result = Truffle.getRuntime().iterateFrames(frameInstance -> { final Frame current = frameInstance.getFrame(FrameInstance.FrameAccess.READ_ONLY); if (!FrameAccess.isTruffleSqueakFrame(current)) { final RootNode rootNode = ((RootCallTarget) frameInstance.getCallTarget()).getRootNode(); if (rootNode.isInternal() || rootNode.getLanguageInfo().getId().equals(SqueakLanguageConfig.ID)) { /* Skip internal and all other nodes that belong to TruffleSqueak. */ return null; } else { /* * Found a frame of another language. Stop here by returning the receiver * context. This special case will be handled later on. */ return receiver; } } final ContextObject context = FrameAccess.getContext(current); if (!foundMyself[0]) { if (context == receiver) { foundMyself[0] = true; } } else { if (FrameAccess.getMethod(current).isExceptionHandlerMarked()) { if (context != null) { return context; } else { return ContextObject.create(frameInstance); } } else { lastSender[0] = FrameAccess.getSender(current); } } return null; }); if (result == receiver) { /* * Foreign frame found during frame iteration. Inject a fake context which will * throw the Smalltalk exception as polyglot exception. */ return getInteropExceptionThrowingContext(); } else if (result == null) { if (!foundMyself[0]) { return findNext(receiver); // Fallback to other version. } if (lastSender[0] instanceof ContextObject) { return findNext((ContextObject) lastSender[0]); } else { return NilObject.SINGLETON; } } else { return result; } }
Example #11
Source File: HashemLexicalScope.java From mr-hashemi with Universal Permissive License v1.0 | 3 votes |
/** * Create a new functionalHashemilexical scope. * * @param current the current node, or <code>null</code> when it would be above the block * @param block a nearest block enclosing the current node * @param root a functional root node for top-most block */ private HashemLexicalScope(Node current, HashemBlockNode block, RootNode root) { this.current = current; this.block = block; this.parentBlock = null; this.root = root; }
Example #12
Source File: TruffleAST.java From netbeans with Apache License 2.0 | 3 votes |
/** * Get the nodes hierarchy. Every node is described by: * <ul> * <li>node class</li> * <li>node description</li> * <li>node source section - either an empty line, or following items:</li> * <ul> * <li>URI</li> * <li><start line>:<start column>-<end line>:<end column></li> * </ul> * <li>number of children</li> * <li><child nodes follow...></li> * </ul> * @return a newline-separated list of elements describing the nodes hierarchy. */ public String getNodes() { StringBuilder nodes = new StringBuilder(); RootCallTarget rct = (RootCallTarget) frameInstance.getCallTarget(); RootNode rootNode = rct.getRootNode(); fillNode(rootNode, nodes); return nodes.toString(); }