1 package gnu.kawa.functions; 2 import gnu.bytecode.*; 3 import gnu.mapping.*; 4 import gnu.expr.*; 5 6 8 9 public class IsEq extends Procedure2 implements Inlineable 10 { 11 Language language; 12 13 public IsEq(Language language, String name) 14 { 15 this.language = language; 16 setName(name); 17 } 18 19 public boolean apply(Object arg1, Object arg2) 20 { 21 return arg1 == arg2; 22 } 23 24 public Object apply2(Object arg1, Object arg2) 25 { 26 return language.booleanObject(arg1==arg2); 27 } 28 29 public void compile (ApplyExp exp, Compilation comp, Target target) 30 { 31 compile(exp.getArgs(), comp, target, language); 32 } 33 34 public static void compile (Expression[] args, Compilation comp, 35 Target target, Language language) 36 { 37 CodeAttr code = comp.getCode(); 38 args[0].compile(comp, Target.pushObject); 39 args[1].compile(comp, Target.pushObject); 40 if (target instanceof ConditionalTarget) 41 { 42 ConditionalTarget ctarget = (ConditionalTarget) target; 43 if (ctarget.trueBranchComesFirst) 44 code.emitGotoIfNE(ctarget.ifFalse); 45 else 46 code.emitGotoIfEq(ctarget.ifTrue); 47 ctarget.emitGotoFirstBranch(code); 48 } 49 else 50 { 51 Type type; 52 code.emitIfEq(); 53 if (target.getType() instanceof ClassType) 54 { 55 Object trueValue = language.booleanObject(true); 56 Object falseValue = language.booleanObject(false); 57 comp.compileConstant(trueValue, Target.pushObject); 58 code.emitElse(); 59 comp.compileConstant(falseValue, Target.pushObject); 60 if (trueValue instanceof Boolean && falseValue instanceof Boolean ) 61 type = Compilation.scmBooleanType; 62 else 63 type = Type.pointer_type; 64 } 65 else 66 { 67 code.emitPushInt(1); 68 code.emitElse(); 69 code.emitPushInt(0); 70 type = language.getTypeFor(Boolean.TYPE); 71 } 72 code.emitFi(); 73 target.compileFromStack(comp, type); 74 } 75 } 76 77 public Type getReturnType (Expression[] args) 78 { 79 return language.getTypeFor(Boolean.TYPE); 80 } 81 } 82 | Popular Tags |