use of com.oracle.truffle.api.nodes.RootNode in project graal by oracle.
the class EngineTest method testLanguageAccess.
@Test
public void testLanguageAccess() {
final PolyglotEngine.Builder builder = createBuilderInternal();
ForkingLanguageChannel channel = new ForkingLanguageChannel(builder::build);
PolyglotEngine vm = builder.config(ForkingLanguage.MIME_TYPE, "channel", channel).build();
vm.eval(Source.newBuilder("").name("").mimeType(ForkingLanguage.MIME_TYPE).build()).get();
RootNode root = new RootNode(channel.language) {
@Override
public Object execute(VirtualFrame frame) {
return null;
}
};
try {
// no access using a TruffleLanguage hack
root.getLanguage(TruffleLanguage.class);
fail();
} catch (ClassCastException e) {
}
Class<?> oClass = Object.class;
Class<? extends TruffleLanguage> lang = (Class<? extends TruffleLanguage>) oClass;
try {
// no access using a TruffleLanguage class cast
root.getLanguage(lang);
fail();
} catch (ClassCastException e) {
}
oClass = SecretInterfaceType.class;
Class<? extends TruffleLanguage> secretInterface = (Class<? extends TruffleLanguage>) oClass;
try {
// no access using secret interface
root.getLanguage(secretInterface);
fail();
} catch (ClassCastException e) {
}
// this should work as expected
assertNotNull(root.getLanguage(ForkingLanguage.class));
}
use of com.oracle.truffle.api.nodes.RootNode in project graal by oracle.
the class DefaultScope method lexicalScope.
static Iterable<Scope> lexicalScope(Node node, Frame frame) {
RootNode root = node.getRootNode();
String name = root.getName();
if (name == null) {
name = "local";
}
return Collections.singletonList(Scope.newBuilder(name, getVariables(root, frame)).node(root).arguments(getArguments(frame)).build());
}
use of com.oracle.truffle.api.nodes.RootNode in project graal by oracle.
the class JSONHelper method dumpNewNode.
/**
* @since 0.8 or earlier
*/
public static void dumpNewNode(Node newNode) {
if (AstJsonDumpBuilder != null) {
String language = "";
RootNode root = newNode.getRootNode();
if (root != null) {
TruffleLanguage<?> clazz = root.getLanguage(TruffleLanguage.class);
if (clazz != null) {
language = clazz.getClass().getName();
}
}
AstJsonDumpBuilder.append("{ \"action\": \"createNode\", \"newId\": \"" + getID(newNode) + "\", \"type\": \"" + getType(newNode) + "\", \"description\": \"" + newNode.getDescription() + "\", \"language\": \"" + language + "\"" + " },\n");
}
}
use of com.oracle.truffle.api.nodes.RootNode in project graal by oracle.
the class Scope method findScopes.
/**
* Find a list of scopes enclosing the given {@link Node node}. There is at least one scope
* provided, that corresponds to the enclosing function. The iteration order corresponds with
* the scope nesting, from the inner-most to the outer-most. The scopes contain variables valid
* at the provided node.
* <p>
* In general, there can be a different list of scopes with different variables and arguments
* returned for different {@link Frame} instances, as scopes may depend on runtime information.
* Known lexical scopes are returned when <code>frame</code> argument is <code>null</code>.
*
* @param instrumentEnv the instrument environment that is used to
* {@link com.oracle.truffle.api.instrumentation.TruffleInstrument.Env#lookup(com.oracle.truffle.api.nodes.LanguageInfo, java.lang.Class)
* look-up} the {@link ScopeProvider} service.
* @param node a node to get the enclosing scopes for. The node needs to be inside a
* {@link RootNode} associated with a language.
* @param frame The current frame the node is in, or <code>null</code> for lexical access when
* the program is not running, or is not suspended at the node's location.
* @return an {@link Iterable} providing list of scopes from the inner-most to the outer-most.
* @see ScopeProvider#findScope(java.lang.Object, com.oracle.truffle.api.nodes.Node,
* com.oracle.truffle.api.frame.Frame)
* @since 0.26
* @deprecated Use
* {@link TruffleInstrument.Env#findLocalScopes(com.oracle.truffle.api.nodes.Node, com.oracle.truffle.api.frame.Frame)}
* instead.
*/
@Deprecated
@SuppressWarnings({ "rawtypes", "unchecked" })
public static Iterable<Scope> findScopes(Env instrumentEnv, Node node, Frame frame) {
RootNode rootNode = node.getRootNode();
if (rootNode == null) {
throw new IllegalArgumentException("The node " + node + " does not have a RootNode.");
}
LanguageInfo languageInfo = rootNode.getLanguageInfo();
if (languageInfo == null) {
throw new IllegalArgumentException("The root node " + rootNode + " does not have a language associated.");
}
ScopeProvider scopeProvider = instrumentEnv.lookup(languageInfo, ScopeProvider.class);
com.oracle.truffle.api.metadata.ScopeProvider.AbstractScope ascope;
if (scopeProvider != null) {
TruffleLanguage.Env env = ScopeAccessor.engine().getEnvForInstrument(languageInfo);
Object context = ScopeAccessor.langs().getContext(env);
ascope = scopeProvider.findScope(context, node, frame);
} else {
ascope = new DefaultScopeVariables(node);
}
return ascope.toIterable();
}
use of com.oracle.truffle.api.nodes.RootNode in project graal by oracle.
the class SLInstrumentTest method checkBlock.
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);
}
Aggregations