KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > kawa > standard > not


1 package kawa.standard;
2 import gnu.bytecode.Type;
3 import gnu.bytecode.CodeAttr;
4 import gnu.mapping.*;
5 import gnu.expr.*;
6
7 /** Implement the standard Scheme procedure "not". */
8
9 public class not extends Procedure1 implements Inlineable
10 {
11   Language language;
12   public QuoteExp trueExp;
13   public QuoteExp falseExp;
14
15   public not(Language language)
16   {
17     this.language = language;
18     trueExp = new QuoteExp(language.booleanObject(true));
19     falseExp = new QuoteExp(language.booleanObject(false));
20   }
21
22   public not(Language language, String JavaDoc name)
23   {
24     this(language);
25     setName(name);
26   }
27
28   public Object JavaDoc apply1 (Object JavaDoc arg1)
29    {
30      return language.booleanObject(! language.isTrue(arg1));
31    }
32
33   public void compile (ApplyExp exp, Compilation comp, Target target)
34   {
35     Expression arg = exp.getArgs()[0];
36     if (target instanceof ConditionalTarget)
37       {
38     ConditionalTarget ctarget = (ConditionalTarget) target;
39     ConditionalTarget sub_target
40       = new ConditionalTarget(ctarget.ifFalse, ctarget.ifTrue, language);
41     sub_target.trueBranchComesFirst = ! ctarget.trueBranchComesFirst;
42     arg.compile(comp, sub_target);
43     return;
44       }
45     CodeAttr code = comp.getCode();
46     Type type = target.getType();
47     if (target instanceof StackTarget && type.getSignature().charAt(0) == 'Z')
48       {
49     arg.compile(comp, target);
50     code.emitNot(target.getType());
51       }
52     else
53       {
54     IfExp.compile(arg, falseExp, trueExp, comp, target);
55       }
56   }
57
58   public Type getReturnType (Expression[] args)
59   {
60     return language.getTypeFor(Boolean.TYPE);
61   }
62 }
63
Popular Tags