001: /**************************************************************************/
002: /* N I C E */
003: /* A high-level object-oriented research language */
004: /* (c) Daniel Bonniot 2004 */
005: /* */
006: /* This program is free software; you can redistribute it and/or modify */
007: /* it under the terms of the GNU General Public License as published by */
008: /* the Free Software Foundation; either version 2 of the License, or */
009: /* (at your option) any later version. */
010: /* */
011: /**************************************************************************/package nice.tools.typing;
012:
013: import bossa.util.*;
014: import java.util.*;
015:
016: import mlsub.typing.*;
017:
018: import mlsub.typing.TypeConstructor;
019: import mlsub.typing.MonotypeConstructor;
020: import mlsub.typing.Polytype;
021: import mlsub.typing.Constraint;
022:
023: import nice.tools.code.SpecialTypes;
024:
025: /**
026:
027: */
028: public final class PrimitiveType {
029:
030: public static gnu.bytecode.Type register(String name,
031: TypeConstructor tc) {
032: if (name.equals("nice.lang.char")) {
033: charTC = tc;
034: charType = Types.sureMonotype(new MonotypeConstructor(tc,
035: null));
036: charPolytype = new Polytype(charType);
037: return SpecialTypes.charType;
038: }
039:
040: if (name.equals("nice.lang.byte")) {
041: byteTC = tc;
042: byteType = Types.sureMonotype(new MonotypeConstructor(tc,
043: null));
044: bytePolytype = new Polytype(byteType);
045: return SpecialTypes.byteType;
046: }
047:
048: if (name.equals("nice.lang.short")) {
049: shortTC = tc;
050: shortType = Types.sureMonotype(new MonotypeConstructor(tc,
051: null));
052: shortPolytype = new Polytype(shortType);
053: return SpecialTypes.shortType;
054: }
055:
056: if (name.equals("nice.lang.int")) {
057: intTC = tc;
058: intType = Types.sureMonotype(new MonotypeConstructor(tc,
059: null));
060: intPolytype = new Polytype(intType);
061: return SpecialTypes.intType;
062: }
063:
064: if (name.equals("nice.lang.long")) {
065: longTC = tc;
066: longType = Types.sureMonotype(new MonotypeConstructor(tc,
067: null));
068: longPolytype = new Polytype(longType);
069: return SpecialTypes.longType;
070: }
071:
072: if (name.equals("nice.lang.boolean")) {
073: boolTC = tc;
074: boolType = Types.sureMonotype(new MonotypeConstructor(tc,
075: null));
076: boolPolytype = new Polytype(boolType);
077: return SpecialTypes.booleanType;
078: }
079:
080: if (name.equals("nice.lang.double")) {
081: doubleTC = tc;
082: doubleType = Types.sureMonotype(new MonotypeConstructor(tc,
083: null));
084: doublePolytype = new Polytype(doubleType);
085: return SpecialTypes.doubleType;
086: }
087:
088: if (name.equals("nice.lang.float")) {
089: floatTC = tc;
090: floatType = Types.sureMonotype(new MonotypeConstructor(tc,
091: null));
092: floatPolytype = new Polytype(floatType);
093: return SpecialTypes.floatType;
094: }
095:
096: if (name.equals("nice.lang.void")) {
097: voidTC = tc;
098: mlsub.typing.lowlevel.Engine.setTop(tc);
099: voidType = Types.sureMonotype(new MonotypeConstructor(tc,
100: null));
101: voidPolytype = new Polytype(Constraint.True, voidType);
102: return SpecialTypes.voidType;
103: }
104:
105: if (name.equals("nice.lang.Array")) {
106: arrayTC = tc;
107: return nice.tools.code.SpecialArray.wrappedType();
108: }
109:
110: if (name.equals("nice.lang.Maybe")) {
111: maybeTC = tc;
112: mlsub.typing.NullnessKind.setMaybe(tc);
113: // to differ with the null result, which signals error
114: return gnu.bytecode.Type.pointer_type;
115: }
116:
117: if (name.equals("nice.lang.Sure")) {
118: sureTC = tc;
119: mlsub.typing.NullnessKind.setSure(tc);
120: // to differ with the null result, which signals error
121: return gnu.bytecode.Type.pointer_type;
122: }
123:
124: if (name.equals("nice.lang.Null")) {
125: nullTC = tc;
126: // to differ with the null result, which signals error
127: return gnu.bytecode.Type.pointer_type;
128: }
129:
130: return null;
131: }
132:
133: public static TypeConstructor byteTC, charTC, intTC, longTC,
134: boolTC, shortTC, doubleTC, floatTC, arrayTC, voidTC;
135:
136: public static mlsub.typing.Monotype byteType, charType, intType,
137: longType, boolType, shortType, doubleType, floatType,
138: voidType;
139: public static Polytype voidPolytype, boolPolytype, charPolytype,
140: bytePolytype, shortPolytype, intPolytype, longPolytype,
141: doublePolytype, floatPolytype;
142:
143: private static Polytype objectPolytype;
144:
145: public static Polytype objectPolytype() {
146: if (objectPolytype == null)
147: objectPolytype = new Polytype(mlsub.typing.Constraint.True,
148: Types.sureMonotype(TopMonotype.instance));
149:
150: return objectPolytype;
151: }
152:
153: public static void reset() {
154: objectPolytype = null;
155: }
156:
157: public static TypeConstructor maybeTC, sureTC, nullTC;
158:
159: public static TypeConstructor classTC;
160: public static TypeConstructor collectionTC;
161: public static TypeConstructor throwableTC;
162: }
|