[Nice-commit] Nice/stdlib/nice/lang/inline Instanceof.java,1.4,1.5
Brought to you by:
bonniot
From: Daniel B. <bo...@us...> - 2004-08-11 09:06:14
|
Update of /cvsroot/nice/Nice/stdlib/nice/lang/inline In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv13107/stdlib/nice/lang/inline Modified Files: Instanceof.java Log Message: Make instanceof work with non-literal type expressions. Index: Instanceof.java =================================================================== RCS file: /cvsroot/nice/Nice/stdlib/nice/lang/inline/Instanceof.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** Instanceof.java 19 Dec 2003 02:12:34 -0000 1.4 --- Instanceof.java 11 Aug 2004 09:06:04 -0000 1.5 *************** *** 38,53 **** public void compile (ApplyExp exp, Compilation comp, Target target) { - gnu.bytecode.CodeAttr code = comp.getCode(); Expression[] args = exp.getArgs(); Expression value = args[0]; ! Type type = (Type) ((QuoteExp) args[1]).getValue(); // instanceof on boolean can make sense if (type == Type.boolean_type) type = Type.boolean_ctype; ! if (type instanceof PrimType) throw new bossa.util.UserError ! (exp, "instanceof cannot be used with primitive types"); value.compile(comp, Target.pushObject); --- 38,66 ---- public void compile (ApplyExp exp, Compilation comp, Target target) { Expression[] args = exp.getArgs(); Expression value = args[0]; ! Expression typeExp = args[1]; ! ! if (typeExp instanceof QuoteExp && ! ((QuoteExp) typeExp).getValue() instanceof Type) ! compile(value, (Type) ((QuoteExp) typeExp).getValue(), comp, exp); ! else ! compile(value, typeExp, comp); ! ! target.compileFromStack(comp, Type.boolean_type); ! } ! ! private void compile(Expression value, Type type, Compilation comp, ! Expression applyExp) ! { ! gnu.bytecode.CodeAttr code = comp.getCode(); // instanceof on boolean can make sense if (type == Type.boolean_type) type = Type.boolean_ctype; ! if (type instanceof PrimType) throw new bossa.util.UserError ! (applyExp, "instanceof cannot be used with primitive types"); value.compile(comp, Target.pushObject); *************** *** 68,72 **** else code.emitInstanceof(type); ! target.compileFromStack(comp, Type.boolean_type); } --- 81,94 ---- else code.emitInstanceof(type); ! } ! ! private void compile(Expression value, Expression type, Compilation comp) ! { ! gnu.bytecode.CodeAttr code = comp.getCode(); ! ! type.compile(comp, Target.pushObject); ! value.compile(comp, Target.pushObject); ! code.emitInvoke ! (ClassType.make("java.lang.Class").getDeclaredMethod("isInstance", 1)); } |