/** * Created by Lucas Allan Amorim on 2014-09-14. */ @NodeInfo(shortName = "osclock") public abstract class LuaOSClockBuiltin extends LuaNode { @Specialization public double osclock() { return System.nanoTime() / 1e9; } }
/** * Returns a rough estimate for the cost of this {@link Node}. This estimate can be used by * runtime systems or guest languages to implement heuristics based on Truffle ASTs. This method * is intended to be overridden by subclasses. The default implementation returns the value of * {@link NodeInfo#cost()} of the {@link NodeInfo} annotation declared at the subclass. If no * {@link NodeInfo} annotation is declared the method returns {@link NodeCost#MONOMORPHIC} as a * default value. */ public NodeCost getCost() { NodeInfo info = getClass().getAnnotation(NodeInfo.class); if (info != null) { return info.cost(); } return NodeCost.MONOMORPHIC; }
/** * Returns a user-readable description of the purpose of the Node, or "" if no description is * available. */ public String getDescription() { NodeInfo info = getClass().getAnnotation(NodeInfo.class); if (info != null) { return info.description(); } return ""; }
protected void createElementForNode(Object node) { boolean exists = nodeMap.containsKey(node); if (!exists || NodeUtil.findAnnotation(node.getClass(), GraphDuplicate.class) != null) { Element nodeElem = dom.createElement("node"); nodeElem.setAttribute("id", !exists ? oldOrNextId(node) : nextId()); nodeMap.put(node, nodeElem); Element properties = dom.createElement("properties"); nodeElem.appendChild(properties); nodesElement.appendChild(nodeElem); setNodeProperty(node, "name", node.getClass().getSimpleName().replaceFirst("Node$", "")); NodeInfo nodeInfo = node.getClass().getAnnotation(NodeInfo.class); if (nodeInfo != null) { setNodeProperty(node, "cost", nodeInfo.cost()); if (!nodeInfo.shortName().isEmpty()) { setNodeProperty(node, "shortName", nodeInfo.shortName()); } } setNodeProperty(node, "class", node.getClass().getSimpleName()); if (node instanceof Node) { readNodeProperties((Node) node); copyDebugProperties((Node) node); } } }
private static void setBasicProperties(Map<String, ? super Object> properties, Node source) { String className = className(source.getClass()); properties.put("label", dropNodeSuffix(className)); properties.put("cost", source.getCost()); NodeInfo nodeInfo = source.getClass().getAnnotation(NodeInfo.class); if (nodeInfo != null) { if (!nodeInfo.shortName().isEmpty()) { properties.put("shortName", nodeInfo.shortName()); } } if (Introspection.isIntrospectable(source)) { final List<Introspection.SpecializationInfo> specializations = Introspection.getSpecializations(source); for (Introspection.SpecializationInfo specialization : specializations) { final String methodName = specialization.getMethodName(); properties.put(methodName + ".isActive", specialization.isActive()); properties.put(methodName + ".isExcluded", specialization.isExcluded()); properties.put(methodName + ".instances", specialization.getInstances()); for (int i = 0; i < specialization.getInstances(); i++) { final List<Object> cachedData = specialization.getCachedData(i); for (Object o : cachedData) { properties.put(methodName + "-cachedData[" + i + "]", o); } } } } }
/** * Returns a string representing the language this node has been implemented for. If the * language is unknown, returns "". */ public String getLanguage() { NodeInfo info = getClass().getAnnotation(NodeInfo.class); if (info != null && info.language() != null && info.language().length() > 0) { return info.language(); } if (parent != null) { return parent.getLanguage(); } return ""; }
final void createElementForNode(Object node) { boolean exists = nodeMap.containsKey(node); if (!exists) { int nodeId = !exists ? oldOrNextId(node) : nextId(); nodeMap.put(node, new NodeElement(nodeId)); String className = NodeUtil.className(node.getClass()); setNodeProperty(node, "name", dropNodeSuffix(className)); NodeInfo nodeInfo = node.getClass().getAnnotation(NodeInfo.class); if (nodeInfo != null) { setNodeProperty(node, "cost", nodeInfo.cost()); if (!nodeInfo.shortName().isEmpty()) { setNodeProperty(node, "shortName", nodeInfo.shortName()); } } setNodeProperty(node, "class", className); if (node instanceof Node) { readNodeProperties((Node) node); copyDebugProperties((Node) node); } } }
public void installBuiltin(NodeFactory<? extends LuaNode> factory) { int argumentCount = factory.getExecutionSignature().size(); Object[] argumentNodes = new Object[argumentCount]; for (int i = 0; i < argumentCount; i++) { argumentNodes[i] = new LuaReadArgumentNode(i); } for (int i = 0; i < argumentCount; i++) { argumentNodes[i] = new LuaReadArgumentNode(i); } LuaNode builtinBodyNode = factory.createNode(argumentNodes); String name = builtinBodyNode.getClass().getAnnotation(NodeInfo.class).shortName(); LuaRootNode rootNode = new LuaRootNode(builtinBodyNode, null); luaFunctionRegistry.register(name, rootNode); }
/** * Returns a string representing the language this node has been implemented for. If the * language is unknown, returns "". * * @since 0.8 or earlier * @deprecated in 0.25 use {@link #getRootNode() getRootNode()}. * {@link RootNode#getLanguageInfo() getLanguageInfo()}. * {@link LanguageInfo#getName() getName()} instead */ @Deprecated public String getLanguage() { NodeInfo info = getClass().getAnnotation(NodeInfo.class); if (info != null && info.language() != null && info.language().length() > 0) { return info.language(); } if (parent != null) { return parent.getLanguage(); } return ""; }
@NodeInfo(shortName = "loop", description = "Repeats the function call forever") public class LoopNode extends MumblerNode { @Child private com.oracle.truffle.api.nodes.LoopNode loopNode; private final String callString; public LoopNode(InvokeNode callNode) { this.callString = callNode.toString(); this.loopNode = Truffle.getRuntime().createLoopNode( new LoopReapeatingNode(callNode)); } @Override public Object execute(VirtualFrame virtualFrame) { this.loopNode.executeLoop(virtualFrame); return null; } @Override public String toString() { return '\u331e' + this.callString; } }
final void createElementForNode(Object node) { boolean exists = nodeMap.containsKey(node); if (!exists) { int nodeId = !exists ? oldOrNextId(node) : nextId(); nodeMap.put(node, new NodeElement(nodeId)); String className = NodeUtil.className(node.getClass()); setNodeProperty(node, "name", dropNodeSuffix(className)); NodeInfo nodeInfo = node.getClass().getAnnotation(NodeInfo.class); if (nodeInfo != null) { setNodeProperty(node, "cost", nodeInfo.cost()); if (!nodeInfo.shortName().isEmpty()) { setNodeProperty(node, "shortName", nodeInfo.shortName()); } } setNodeProperty(node, "class", className); if (node instanceof Node) { readNodeProperties((Node) node); copyDebugProperties((Node) node); } } }
/** * Returns a rough estimate for the cost of this {@link Node}. This estimate can be used by * runtime systems or guest languages to implement heuristics based on Truffle ASTs. This method * is intended to be overridden by subclasses. The default implementation returns the value of * {@link NodeInfo#cost()} of the {@link NodeInfo} annotation declared at the subclass. If no * {@link NodeInfo} annotation is declared the method returns {@link NodeCost#MONOMORPHIC} as a * default value. * * @since 0.8 or earlier */ public NodeCost getCost() { NodeInfo info = getClass().getAnnotation(NodeInfo.class); if (info != null) { return info.cost(); } return NodeCost.MONOMORPHIC; }
/** * Returns a user-readable description of the purpose of the Node, or "" if no description is * available. Can be called on any thread and without a language context. * * @since 0.8 or earlier */ public String getDescription() { NodeInfo info = getClass().getAnnotation(NodeInfo.class); if (info != null) { return info.description(); } return ""; }
/** * Returns a string representing the language this node has been implemented for. If the * language is unknown, returns "". * * @since 0.8 or earlier * @deprecated in 0.25 use {@link #getRootNode() getRootNode()}. * {@link RootNode#getLanguageInfo() getLanguageInfo()}. * {@link LanguageInfo#getName() getName()} instead */ @Deprecated public String getLanguage() { NodeInfo info = getClass().getAnnotation(NodeInfo.class); if (info != null && info.language() != null && info.language().length() > 0) { return info.language(); } if (parent != null) { return parent.getLanguage(); } return ""; }
@NodeInfo(cost = NodeCost.NONE) private final class SimpleInstrumentNode extends AbstractInstrumentNode {
/** * Returns a rough estimate for the cost of this {@link Node}. This estimate can be used by * runtime systems or guest languages to implement heuristics based on Truffle ASTs. This method * is intended to be overridden by subclasses. The default implementation returns the value of * {@link NodeInfo#cost()} of the {@link NodeInfo} annotation declared at the subclass. If no * {@link NodeInfo} annotation is declared the method returns {@link NodeCost#MONOMORPHIC} as a * default value. * * @since 0.8 or earlier */ public NodeCost getCost() { NodeInfo info = getClass().getAnnotation(NodeInfo.class); if (info != null) { return info.cost(); } return NodeCost.MONOMORPHIC; }
/** * Returns a user-readable description of the purpose of the Node, or "" if no description is * available. Can be called on any thread and without a language context. * * @since 0.8 or earlier */ public String getDescription() { NodeInfo info = getClass().getAnnotation(NodeInfo.class); if (info != null) { return info.description(); } return ""; }
@NodeInfo(cost = NodeCost.NONE) private final class StandardInstrumentNode extends AbstractInstrumentNode {
if (nodeInfo == null || nodeInfo.cost() == NodeCost.MONOMORPHIC /* the default */) { clazz.add(createGetCostMethod());
@NodeInfo(cost = NodeCost.NONE) private final class TruffleOptInstrumentNode extends AbstractInstrumentNode {