private static String langId(LanguageInfo languageInfo) { if (languageInfo == null) { return null; } else { return languageInfo.getId(); } }
private static String langId(LanguageInfo languageInfo) { if (languageInfo == null) { return null; } else { return languageInfo.getId(); } }
@Override public Object lookupSymbol(Object vmObject, Env env, LanguageInfo language, String symbolName) { PolyglotLanguageContext context = (PolyglotLanguageContext) vmObject; int index = context.context.engine.idToLanguage.get(language.getId()).index; return context.context.contexts[index].lookupGuest(symbolName); }
@SuppressWarnings({"unchecked", "rawtypes"}) static Map<String, Object>[] toMap(Map<LanguageInfo, Map<String, HeapSummary>> summaries) { List<Map<String, Object>> heapHisto = new ArrayList<>(summaries.size()); for (Entry<LanguageInfo, Map<String, HeapSummary>> objectsByLanguage : summaries.entrySet()) { LanguageInfo language = objectsByLanguage.getKey(); for (Entry<String, HeapSummary> objectsByMetaObject : objectsByLanguage.getValue().entrySet()) { HeapSummary mi = objectsByMetaObject.getValue(); Map<String, Object> metaObjMap = new HashMap<>(); metaObjMap.put("language", language.getId()); metaObjMap.put("name", objectsByMetaObject.getKey()); metaObjMap.put("totalInstances", mi.getTotalInstances()); metaObjMap.put("totalBytes", mi.getTotalBytes()); metaObjMap.put("aliveInstances", mi.getAliveInstances()); metaObjMap.put("aliveBytes", mi.getAliveBytes()); heapHisto.add(metaObjMap); } } return heapHisto.toArray(new Map[0]); }
void checkAccess(PolyglotLanguage accessingLanguage) { context.engine.checkState(); if (context.closed) { throw new PolyglotIllegalStateException("The Context is already closed."); } boolean accessPermitted = language.isHost() || language.cache.isInternal() || context.allowedPublicLanguages.contains(language.info.getId()) || (accessingLanguage != null && accessingLanguage.dependsOn(language)); if (!accessPermitted) { throw new PolyglotIllegalStateException(String.format("Access to language '%s' is not permitted. ", language.getId())); } RuntimeException initError = language.initError; if (initError != null) { throw new PolyglotIllegalStateException(String.format("Initialization error: %s", initError.getMessage()), initError); } }
void checkAccess(PolyglotLanguage accessingLanguage) { context.engine.checkState(); if (context.closed) { throw new PolyglotIllegalStateException("The Context is already closed."); } boolean accessPermitted = language.isHost() || language.cache.isInternal() || context.config.allowedPublicLanguages.contains(language.info.getId()) || (accessingLanguage != null && accessingLanguage.dependsOn(language)); if (!accessPermitted) { throw new PolyglotIllegalArgumentException(String.format("Access to language '%s' is not permitted. ", language.getId())); } RuntimeException initError = language.initError; if (initError != null) { throw new PolyglotIllegalStateException(String.format("Initialization error: %s", initError.getMessage()), initError); } }
static Iterable<Scope> findTopScopes(TruffleLanguage.Env env) { Iterable<Scope> langScopes = AccessorInstrumentHandler.langAccess().findTopScopes(env); assert langScopes != null : AccessorInstrumentHandler.langAccess().getLanguageInfo(env).getId(); return langScopes; }
static Iterable<Scope> findTopScopes(TruffleLanguage.Env env) { Iterable<Scope> langScopes = AccessorInstrumentHandler.langAccess().findTopScopes(env); assert langScopes != null : AccessorInstrumentHandler.langAccess().getLanguageInfo(env).getId(); return langScopes; }
StackTraceElement toTraceElement() { if (stackTrace == null) { LanguageInfo language = getLanguage(); String declaringClass = language != null ? "<" + language.getId() + ">" : "<unknown>"; String methodName = getName0(); if (methodName == null) { methodName = ""; } SourceSection sourceLocation = getSourceSection(); String fileName = sourceLocation != null ? sourceLocation.getSource().getName() : "Unknown"; int startLine = sourceLocation != null ? sourceLocation.getStartLine() : -1; stackTrace = new StackTraceElement(declaringClass, methodName, fileName, startLine); } return stackTrace; } }
assert langScopes != null : languageInfo.getId(); return langScopes;
assert langScopes != null : languageInfo.getId(); return langScopes;
String declaringClass; if (languageInfo != null) { declaringClass = languageInfo.getId(); } else { declaringClass = "";
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); } }
final Source source = Source.newBuilder(code).name("eval in context").language(info.getId()).mimeType("content/unknown").build(); ExecutableNode fragment = null; CallTarget target = null;
static PolyglotExceptionFrame createGuest(PolyglotExceptionImpl exception, TruffleStackTraceElement frame, boolean first) { if (frame == null) { return null; } RootNode targetRoot = frame.getTarget().getRootNode(); if (targetRoot.isInternal()) { return null; } LanguageInfo info = targetRoot.getLanguageInfo(); if (info == null) { return null; } PolyglotEngineImpl engine = exception.context.getEngine(); PolyglotLanguage language = engine.idToLanguage.get(info.getId()); String rootName = targetRoot.getName(); SourceSection location; Node callNode = frame.getLocation(); if (callNode != null) { com.oracle.truffle.api.source.SourceSection section = callNode.getEncapsulatingSourceSection(); if (section != null) { Source source = engine.getAPIAccess().newSource(language.getId(), section.getSource()); location = engine.getAPIAccess().newSourceSection(source, section); } else { location = null; } } else { location = first ? exception.getSourceLocation() : null; } return new PolyglotExceptionFrame(exception, language, location, rootName, false, null); }
static PolyglotExceptionFrame createGuest(PolyglotExceptionImpl exception, TruffleStackTraceElement frame, boolean first) { if (frame == null) { return null; } RootNode targetRoot = frame.getTarget().getRootNode(); if (targetRoot.isInternal()) { return null; } LanguageInfo info = targetRoot.getLanguageInfo(); if (info == null) { return null; } PolyglotEngineImpl engine = exception.getEngine(); PolyglotLanguage language = engine.idToLanguage.get(info.getId()); String rootName = targetRoot.getName(); SourceSection location; Node callNode = frame.getLocation(); if (callNode != null) { com.oracle.truffle.api.source.SourceSection section = callNode.getEncapsulatingSourceSection(); if (section != null) { Source source = engine.getAPIAccess().newSource(language.getId(), section.getSource()); location = engine.getAPIAccess().newSourceSection(source, section); } else { location = null; } } else { location = first ? exception.getSourceLocation() : null; } return new PolyglotExceptionFrame(exception, language, location, rootName, false, null); }