KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > gnu > kawa > functions > AppendValues


1 // Copyright (c) 2001, 2002 Per M.A. Bothner and Brainfood Inc.
2
// This is free software; for terms and warranty disclaimer see ./COPYING.
3

4 package gnu.kawa.functions;
5 import gnu.lists.*;
6 import gnu.mapping.*;
7 import gnu.bytecode.*;
8 import gnu.expr.*;
9
10 public class AppendValues extends MethodProc implements CanInline, Inlineable
11 {
12   public static final AppendValues appendValues = new AppendValues();
13
14   public void apply (CallContext ctx)
15   {
16     Object JavaDoc endMarker = Special.dfault;
17     for (;;)
18       {
19     Object JavaDoc arg = ctx.getNextArg(endMarker);
20     if (arg == endMarker)
21       break;
22     if (arg instanceof Consumable)
23       ((Consumable) arg).consume(ctx.consumer);
24     else
25       ctx.writeValue(arg);
26       }
27   }
28
29   public Expression inline (ApplyExp exp, ExpWalker walker)
30   {
31     Expression[] args = exp.getArgs();
32     if (args.length == 1)
33       return args[0];
34     if (args.length == 0)
35       return QuoteExp.voidExp;
36     Expression folded = exp.inlineIfConstant(this, walker);
37     if (folded != exp)
38       return folded;
39     return exp;
40   }
41
42   public void compile (ApplyExp exp, Compilation comp, Target target)
43   {
44     Expression[] args = exp.getArgs();
45     int nargs = args.length;
46     if (target instanceof ConsumerTarget || target instanceof IgnoreTarget)
47       {
48     for (int i = 0; i < nargs; i++)
49       args[i].compileWithPosition(comp, target);
50       }
51     else if (target instanceof SeriesTarget && nargs > 0)
52       {
53     CodeAttr code = comp.getCode();
54     SeriesTarget serTarget = (SeriesTarget) target;
55     Label done = serTarget.done;
56         serTarget.done = null;
57     for (int i = 0; i < nargs; i++)
58       {
59         if (i + 1 == nargs) // Last one
60
serTarget.done = done;
61         args[i].compileWithPosition(comp, serTarget);
62       }
63       }
64     else
65       {
66     ConsumerTarget.compileUsingConsumer(exp, comp, target);
67     /*
68     CodeAttr code = comp.getCode();
69     Scope scope = code.pushScope();
70     Variable values = scope.addVariable(code, comp.typeValues, null);
71     ConsumerTarget ctarget = new ConsumerTarget(values);
72     code.emitInvokeStatic(comp.typeValues.getDeclaredMethod("make", 0));
73     code.emitStore(values);
74     for (int i = 0; i < nargs; i++)
75       args[i].compile(comp, ctarget);
76     code.emitLoad(values);
77     code.popScope();
78     target.compileFromStack(comp, Compilation.typeValues);
79     */

80       }
81   }
82
83   public Type getReturnType (Expression[] args)
84   {
85     return Compilation.typeObject;
86   }
87 }
88
Popular Tags