[Nice-commit] Nice/src/bossa/syntax PrimitiveType.java,1.3,1.4 Pattern.java,1.36,1.37
Brought to you by:
bonniot
From: <bo...@us...> - 2003-02-18 14:21:24
|
Update of /cvsroot/nice/Nice/src/bossa/syntax In directory sc8-pr-cvs1:/tmp/cvs-serv7825/src/bossa/syntax Modified Files: PrimitiveType.java Pattern.java Log Message: Dispatch on boolean values: @true and @false (by Arjan). Index: PrimitiveType.java =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/syntax/PrimitiveType.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** PrimitiveType.java 7 Oct 2002 13:58:25 -0000 1.3 --- PrimitiveType.java 18 Feb 2003 14:21:20 -0000 1.4 *************** *** 94,97 **** --- 94,99 ---- { boolTC = tc; + trueBoolTC = new TypeConstructor("true"); + falseBoolTC = new TypeConstructor("false"); boolType = Monotype.sure(new MonotypeConstructor(tc, null)); boolPolytype = new mlsub.typing.Polytype(boolType); *************** *** 161,164 **** --- 163,169 ---- public static TypeConstructor byteTC, charTC, intTC, longTC, boolTC, shortTC, doubleTC, floatTC, arrayTC; + //these two only for dispatch testing booleans + public static TypeConstructor trueBoolTC, falseBoolTC; + public static mlsub.typing.Monotype byteType, charType, intType, longType, boolType, shortType, doubleType, floatType, voidType; static mlsub.typing.Polytype voidPolytype, boolPolytype, bytePolytype, shortPolytype, intPolytype, longPolytype; Index: Pattern.java =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/syntax/Pattern.java,v retrieving revision 1.36 retrieving revision 1.37 diff -C2 -d -r1.36 -r1.37 *** Pattern.java 14 Oct 2002 15:03:30 -0000 1.36 --- Pattern.java 18 Feb 2003 14:21:20 -0000 1.37 *************** *** 67,70 **** --- 67,86 ---- this.exactlyAt = exactlyAt; this.location = location; + if (tc != null) + { + String ident = tc.getName().toString(); + if (ident.equals("true")) + { + this.atValue = new IdentExp(tc.getName()); + this.typeConstructor = + new TypeIdent(new LocatedString("boolean",location)); + } + else if (ident.equals("false")) + { + this.atValue = new IdentExp(tc.getName()); + this.typeConstructor = + new TypeIdent(new LocatedString("boolean",location)); + } + } } *************** *** 229,233 **** Order on pattern that is compatible with the specificity of patterns. ! If that mathes all values that this matches, the result is true. Additionally, if this matches values that are more specific than the values that matches, the result is also true. --- 245,249 ---- Order on pattern that is compatible with the specificity of patterns. ! If that matches all values that this matches, the result is true. Additionally, if this matches values that are more specific than the values that matches, the result is also true. *************** *** 256,259 **** --- 272,281 ---- return false; + if (that.atBool()) + return this.atBool() && (this.atTrue() == that.atTrue()); + + if (this.atBool()) + return that.tc == PrimitiveType.boolTC; + if (this.tc == that.tc) return this.exactlyAt || ! that.exactlyAt; *************** *** 274,277 **** --- 296,313 ---- return false; + if (tag == PrimitiveType.trueBoolTC) + { + if (atBool()) + return atTrue(); + return tc == PrimitiveType.boolTC; + } + + if (tag == PrimitiveType.falseBoolTC) + { + if (atBool()) + return atFalse(); + return tc == PrimitiveType.boolTC; + } + if (exactlyAt) return Typing.testRigidLeq(tag, tc) && Typing.testRigidLeq(tc, tag); *************** *** 290,294 **** if (atAny()) return "@_"; ! StringBuffer res = new StringBuffer(); if (name != null) --- 326,331 ---- if (atAny()) return "@_"; ! if (atBool()) ! return "@" + atValue.toString(); StringBuffer res = new StringBuffer(); if (name != null) *************** *** 323,327 **** if (atAny()) return "@_"; ! return (exactlyAt ? "#" : "@") --- 360,367 ---- if (atAny()) return "@_"; ! ! if (atBool()) ! return "@" + atValue.toString(); ! return (exactlyAt ? "#" : "@") *************** *** 365,368 **** --- 405,413 ---- else if (name.equals("NULL")) atValue = NullExp.instance; + else if (name.equals("true") || name.equals("false") ) + { + atValue = new IdentExp(new LocatedString(name, Location.nowhere())); + tc = PrimitiveType.boolTC; + } else { *************** *** 393,396 **** --- 438,448 ---- if (atAny()) return QuoteExp.trueExp; + + if (atBool()) + { + if (atFalse()) + return Inline.inline(nice.lang.inline.BoolNotOp.instance, parameter); + return parameter; + } gnu.bytecode.Type ct = nice.tools.code.Types.javaType(tc); *************** *** 427,431 **** private boolean exactlyAt; ! private Expression atValue; private Location location; --- 479,483 ---- private boolean exactlyAt; ! public Expression atValue; private Location location; *************** *** 433,435 **** --- 485,496 ---- public boolean atNull() { return atValue == NullExp.instance; } public boolean atAny() { return atValue == null && tc == null; } + public boolean atBool() { + return atValue != null && tc == PrimitiveType.boolTC; + } + public boolean atTrue() { + return atBool() && atValue.toString().equals("true"); + } + public boolean atFalse() { + return atBool() && atValue.toString().equals("false"); + } } |