1 package gnu.kawa.functions; 2 import gnu.mapping.*; 3 import gnu.expr.*; 4 5 public class MakeProcedure extends ProcedureN implements CanInline 6 { 7 public static final MakeProcedure makeProcedure = new MakeProcedure(); 8 static { makeProcedure.setName("make-procedure"); } 9 10 public static GenericProc makeProcedure$V (Object [] args) 11 { 12 return GenericProc.make(args); 13 } 14 15 public Object applyN(Object [] args) 16 { 17 return GenericProc.make(args); 18 } 19 20 public Expression inline (ApplyExp exp, ExpWalker walker) 21 { 22 Expression[] args = exp.getArgs(); 23 int alen = args.length; 24 Expression method = null; 25 int countMethods = 0; 26 String name = null; 27 for (int i = 0; i < alen; i++) 28 { 29 Expression arg = args[i]; 30 Object key; 31 if (arg instanceof QuoteExp 32 && (key = ((QuoteExp) arg).getValue()) instanceof Keyword) 33 { 34 String keyword = ((Keyword) key).getName(); 35 Expression next = args[++i]; 36 if (keyword == "name") 37 { 38 if (next instanceof QuoteExp) 39 name = ((QuoteExp) next).getValue().toString(); 40 } 41 else if (keyword == "method") 42 { 43 countMethods++; 44 method = next; 45 } 46 else 47 ; } 49 else 50 { 51 countMethods++; 52 method = arg; 53 } 54 } 55 if (countMethods == 1 && method instanceof LambdaExp) 56 { 57 LambdaExp proc = (LambdaExp) method; 58 for (int i = 0; i < alen; i++) 59 { 60 Expression arg = args[i]; 61 Object key; 62 if (arg instanceof QuoteExp 63 && (key = ((QuoteExp) arg).getValue()) instanceof Keyword) 64 { 65 String keyword = ((Keyword) key).getName(); 66 Expression next = args[++i]; 67 if (keyword == "name") 68 proc.setName(name); 69 else if (keyword == "method") 70 ; 71 else 72 proc.setProperty(keyword, next); 73 } 74 } 75 return method; 76 } 77 return exp; 78 } 79 } 80 | Popular Tags |