01: package gnu.kawa.functions;
02:
03: import gnu.mapping.*;
04: import gnu.expr.*;
05:
06: public class MakeProcedure extends ProcedureN implements CanInline {
07: public static final MakeProcedure makeProcedure = new MakeProcedure();
08: static {
09: makeProcedure.setName("make-procedure");
10: }
11:
12: public static GenericProc makeProcedure$V(Object[] args) {
13: return GenericProc.make(args);
14: }
15:
16: public Object applyN(Object[] args) {
17: return GenericProc.make(args);
18: }
19:
20: public Expression inline(ApplyExp exp, ExpWalker walker) {
21: Expression[] args = exp.getArgs();
22: int alen = args.length;
23: Expression method = null;
24: int countMethods = 0;
25: String name = null;
26: for (int i = 0; i < alen; i++) {
27: Expression arg = args[i];
28: Object key;
29: if (arg instanceof QuoteExp
30: && (key = ((QuoteExp) arg).getValue()) instanceof Keyword) {
31: String keyword = ((Keyword) key).getName();
32: Expression next = args[++i];
33: if (keyword == "name") {
34: if (next instanceof QuoteExp)
35: name = ((QuoteExp) next).getValue().toString();
36: } else if (keyword == "method") {
37: countMethods++;
38: method = next;
39: } else
40: ; // result.setProperty(keyword, value);
41: } else {
42: countMethods++;
43: method = arg;
44: }
45: }
46: if (countMethods == 1 && method instanceof LambdaExp) {
47: LambdaExp proc = (LambdaExp) method;
48: for (int i = 0; i < alen; i++) {
49: Expression arg = args[i];
50: Object key;
51: if (arg instanceof QuoteExp
52: && (key = ((QuoteExp) arg).getValue()) instanceof Keyword) {
53: String keyword = ((Keyword) key).getName();
54: Expression next = args[++i];
55: if (keyword == "name")
56: proc.setName(name);
57: else if (keyword == "method")
58: ;
59: else
60: proc.setProperty(keyword, next);
61: }
62: }
63: return method;
64: }
65: return exp;
66: }
67: }
|