コード例 #1
0
ファイル: Cons.java プロジェクト: rritoch/jrelisp-abcl
 @Override
 public LispObject execute(LispObject[] args) {
   if (car == Symbol.LAMBDA) {
     Closure closure = new Closure(this, new Environment());
     return closure.execute(args);
   }
   return signalExecutionError();
 }
コード例 #2
0
ファイル: Cons.java プロジェクト: rritoch/jrelisp-abcl
  @Override
  public LispObject execute(LispObject first, LispObject second, LispObject third) {

    if (car == Symbol.LAMBDA) {
      Closure closure = new Closure(this, new Environment());
      return closure.execute(first, second, third);
    }
    return signalExecutionError();
  }
コード例 #3
0
ファイル: Predicate.java プロジェクト: srnsw/xena
  /**
   * Translate a predicate expression. This translation pushes two references on the stack: a
   * reference to a newly created filter object and a reference to the predicate's closure.
   */
  public void translateFilter(ClassGenerator classGen, MethodGenerator methodGen) {
    final ConstantPoolGen cpg = classGen.getConstantPool();
    final InstructionList il = methodGen.getInstructionList();

    // Compile auxiliary class for filter
    compileFilter(classGen, methodGen);

    // Create new instance of filter
    il.append(new NEW(cpg.addClass(_className)));
    il.append(DUP);
    il.append(new INVOKESPECIAL(cpg.addMethodref(_className, "<init>", "()V")));

    // Initialize closure variables
    final int length = (_closureVars == null) ? 0 : _closureVars.size();

    for (int i = 0; i < length; i++) {
      VariableRefBase varRef = (VariableRefBase) _closureVars.get(i);
      VariableBase var = varRef.getVariable();
      Type varType = var.getType();

      il.append(DUP);

      // Find nearest closure implemented as an inner class
      Closure variableClosure = _parentClosure;
      while (variableClosure != null) {
        if (variableClosure.inInnerClass()) break;
        variableClosure = variableClosure.getParentClosure();
      }

      // Use getfield if in an inner class
      if (variableClosure != null) {
        il.append(ALOAD_0);
        il.append(
            new GETFIELD(
                cpg.addFieldref(
                    variableClosure.getInnerClassName(),
                    var.getEscapedName(),
                    varType.toSignature())));
      } else {
        // Use a load of instruction if in translet class
        il.append(var.loadInstruction());
      }

      // Store variable in new closure
      il.append(
          new PUTFIELD(cpg.addFieldref(_className, var.getEscapedName(), varType.toSignature())));
    }
  }
コード例 #4
0
ファイル: Predicate.java プロジェクト: srnsw/xena
  /** Add new variable to the closure. */
  public void addVariable(VariableRefBase variableRef) {
    if (_closureVars == null) {
      _closureVars = new ArrayList();
    }

    // Only one reference per variable
    if (!_closureVars.contains(variableRef)) {
      _closureVars.add(variableRef);

      // Add variable to parent closure as well
      Closure parentClosure = getParentClosure();
      if (parentClosure != null) {
        parentClosure.addVariable(variableRef);
      }
    }
  }
コード例 #5
0
 protected <T extends RuntimeException> T catches(Closure c, Class<T> rex) {
   T t = null;
   try {
     c.f();
   } catch (RuntimeException ex) {
     ex.printStackTrace();
     assertTrue(
         ex.getClass().getName() + " is not assignable to runtime exception " + rex.getName(),
         ex.getClass().isAssignableFrom(rex));
     t = rex.cast(ex);
   }
   assertNotNull("No exception was caught of class " + rex.getName(), t);
   return t;
 }
コード例 #6
0
ファイル: Context.java プロジェクト: fosterac/renjin
 public Context beginFunction(
     Environment rho, FunctionCall call, Closure closure, PairList arguments) {
   Context context = new Context();
   context.type = Type.FUNCTION;
   context.parent = this;
   context.evaluationDepth = evaluationDepth + 1;
   context.closure = closure;
   context.environment = Environment.createChildEnvironment(closure.getEnclosingEnvironment());
   context.session = session;
   context.arguments = arguments;
   context.call = call;
   context.callingEnvironment = rho;
   return context;
 }
コード例 #7
0
ファイル: Callee.java プロジェクト: jekay100/Java
 public static void main(String[] args) {
   Callee callee = new Callee();
   Closure closure = callee.getClosure();
   closure.increate();
 }
コード例 #8
0
ファイル: NodesAbstract.java プロジェクト: nnombela/graph
 public void forEach(Closure closure) {
   for (Iterator iterator = iterator(); iterator.hasNext(); ) {
     closure.execute(iterator.next());
   }
 }