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