KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > gnu > jemacs > lang > lambda


1 package gnu.jemacs.lang;
2 import gnu.mapping.*;
3 import gnu.expr.*;
4 import gnu.lists.*;
5 import kawa.lang.*;
6
7 /**
8  * The Syntax transformer that re-writes the lambda builtin.
9  * @author Per Bothner
10  */

11
12 public class lambda extends Lambda
13 {
14   /** True if parameters should be bound fluidly. */
15   boolean fluidBindings = true;
16
17   public void rewriteBody(LambdaExp lexp, Object JavaDoc body, Translator tr)
18   {
19     tr.push(lexp);
20     if (lexp.defaultArgs != null)
21       for (int i = 0, n = lexp.defaultArgs.length; i < n; i++)
22     lexp.defaultArgs[i] = tr.rewrite(lexp.defaultArgs[i]);
23
24     Pair pair;
25     int i = 0;
26     if (body instanceof Pair
27     && (pair = (Pair) body).car instanceof FString)
28       {
29     // Process documentation string. FIXME.
30
body = pair.cdr;
31       }
32     Object JavaDoc interactive = null;
33     if (body instanceof Pair
34     && (pair = (Pair) body).car instanceof Pair)
35       {
36     Pair first_application = (Pair) pair.car;
37     Object JavaDoc first_function = first_application.car;
38     if (first_function instanceof Symbol
39         && ((Symbol) first_function).getName() == "interactive")
40       {
41         interactive = first_application.cdr;
42         if (interactive != LList.Empty
43         && ! (interactive instanceof Pair
44               && ((Pair) interactive).cdr == LList.Empty))
45           {
46         tr.syntaxError ("missing 'interactive' specification");
47         interactive = null;
48           }
49         body = pair.cdr;
50       }
51       }
52     if (body instanceof PairWithPosition)
53       lexp.setFile(((PairWithPosition) body).getFileName());
54     FluidLetExp let = null;
55
56     int decl_count = lexp.min_args;
57     if (lexp.defaultArgs != null)
58       decl_count += lexp.defaultArgs.length;
59     if (lexp.max_args < 0)
60       decl_count++;
61
62     if (fluidBindings && decl_count > 0)
63       {
64     Expression[] inits = new Expression[decl_count];
65     let = new FluidLetExp (inits);
66     i = 0;
67     for (Declaration arg = lexp.firstDecl(); arg != null;
68          arg = arg.nextDecl(), i++)
69       {
70         Declaration decl = let.addDeclaration(arg.getSymbol());
71         decl.setFluid(true);
72         decl.setIndirectBinding(true);
73         inits[i] = new ReferenceExp(arg);
74         decl.noteValue(inits[i]);
75       }
76     tr.push(let);
77     let.body = tr.rewrite_body (body);
78     tr.pop(let);
79     lexp.body = let;
80       }
81     else
82       lexp.body = tr.rewrite_body (body);
83     tr.pop(lexp);
84
85     if (interactive != null)
86       {
87         if (interactive == LList.Empty)
88           interactive = QuoteExp.nullExp;
89         else
90           {
91             Object JavaDoc arg = ((Pair) interactive).car;
92             if (arg instanceof FString)
93               interactive = new QuoteExp(arg.toString());
94             else
95               {
96                 LambdaExp ilexp = new LambdaExp();
97                 rewrite(ilexp, LList.Empty, interactive, tr, null);
98                 ilexp.setCanRead(true);
99                 interactive = ilexp;
100               }
101           }
102         lexp.setProperty("emacs-interactive", interactive);
103       }
104   }
105 }
106
Popular Tags