Ejemplo n.º 1
0
 private static int effectiveIndex(Array array, Procedure proc, Object[] args, int[] work)
     throws Throwable {
   Object mapval = proc.applyN(args);
   if (mapval instanceof Values) {
     Values mapvals = (Values) mapval;
     for (int i = 0, j = 0; (i = mapvals.nextPos(i)) != 0; j++) {
       work[j] = ((Number) mapvals.getPosPrevious(i)).intValue();
     }
   } else work[0] = ((Number) mapval).intValue();
   if (array instanceof GeneralArray) return ((GeneralArray) array).resolve(work);
   else return work[0];
 }
Ejemplo n.º 2
0
 /**
  * Inline this ApplyExp if parameters are constant.
  *
  * @param proc the procedure bound to this.func.
  * @return the constant result (as a QuoteExp) if inlining was possible; otherwise this ApplyExp.
  *     If applying proc throws an exception, print a warning on walker.messages.
  */
 public final Expression inlineIfConstant(Procedure proc, SourceMessages messages) {
   int len = args.length;
   Object[] vals = new Object[len];
   for (int i = len; --i >= 0; ) {
     Expression arg = args[i];
     if (arg instanceof ReferenceExp) {
       Declaration decl = ((ReferenceExp) arg).getBinding();
       if (decl != null) {
         arg = decl.getValue();
         if (arg == QuoteExp.undefined_exp) return this;
       }
     }
     if (!(arg instanceof QuoteExp)) return this;
     vals[i] = ((QuoteExp) arg).getValue();
   }
   try {
     return new QuoteExp(proc.applyN(vals), type);
   } catch (Throwable ex) {
     if (messages != null) messages.error('w', "call to " + proc + " throws " + ex);
     return this;
   }
 }