Пример #1
0
 public PythonWrapperNode(PythonContext context, PNode child) {
   /**
    * Don't insert the child here, because child node will be replaced with the wrapper node. If
    * child node is inserted here, it's parent (which will be wrapper's parent after replacement)
    * will be lost. Instead, wrapper is created, and the child is replaced with its wrapper, and
    * then wrapper's child is adopted by calling adoptChildren() in {@link ProfilerTranslator}.
    */
   this.child = child;
   /**
    * context.getProbe will either generate a probe for this source section, or return the existing
    * probe for this section. There can be only one probe for the same source section.
    */
   this.probe = context.createProbe(child.getSourceSection());
 }
Пример #2
0
public final class PGenerator extends PythonBuiltinObject implements PIterator {

  public static final PythonBuiltinClass __class__ =
      PythonContext.getBuiltinTypeFor(PGenerator.class);

  protected final String name;
  protected final RootCallTarget callTarget;
  protected final FrameDescriptor frameDescriptor;
  protected final Object[] arguments;

  public static PGenerator create(
      String name,
      RootCallTarget callTarget,
      FrameDescriptor frameDescriptor,
      MaterializedFrame declarationFrame,
      Object[] arguments,
      int numOfActiveFlags,
      int numOfGeneratorBlockNode,
      int numOfGeneratorForNode) {
    /** Setting up the persistent frame in {@link #arguments}. */
    GeneratorControlData generatorArgs =
        new GeneratorControlData(numOfActiveFlags, numOfGeneratorBlockNode, numOfGeneratorForNode);
    MaterializedFrame generatorFrame =
        Truffle.getRuntime().createMaterializedFrame(PArguments.create(), frameDescriptor);
    PArguments.setDeclarationFrame(arguments, declarationFrame);
    PArguments.setGeneratorFrame(arguments, generatorFrame);
    PArguments.setControlData(arguments, generatorArgs);
    return new PGenerator(name, callTarget, frameDescriptor, arguments);
  }

  public PGenerator(
      String name, RootCallTarget callTarget, FrameDescriptor frameDescriptor, Object[] arguments) {
    this.name = name;
    this.callTarget = callTarget;
    this.frameDescriptor = frameDescriptor;
    this.arguments = arguments;
  }

  @Override
  public PythonBuiltinClass __class__() {
    return __class__;
  }

  public FrameDescriptor getFrameDescriptor() {
    return frameDescriptor;
  }

  public RootCallTarget getCallTarget() {
    return callTarget;
  }

  public Object[] getArguments() {
    return arguments;
  }

  @Override
  public Object __next__() throws StopIterationException {
    return callTarget.call(arguments);
  }

  public Object send(Object value) throws StopIterationException {
    PArguments.setSpecialArgument(arguments, value);
    return callTarget.call(arguments);
  }

  @Override
  public String toString() {
    return "<generator object '" + name + "' at " + hashCode() + ">";
  }
}