home *** CD-ROM | disk | FTP | other *** search
/ Chip 1998 November / Chip_1998-11_cd.bin / tema / Cafe / main.bin / typecodes.h < prev    next >
C/C++ Source or Header  |  1997-11-24  |  5KB  |  153 lines

  1. /*
  2.  * @(#)typecodes.h    1.9 96/11/23
  3.  * 
  4.  * Copyright (c) 1995, 1996 Sun Microsystems, Inc. All Rights Reserved.
  5.  * 
  6.  * This software is the confidential and proprietary information of Sun
  7.  * Microsystems, Inc. ("Confidential Information").  You shall not
  8.  * disclose such Confidential Information and shall use it only in
  9.  * accordance with the terms of the license agreement you entered into
  10.  * with Sun.
  11.  * 
  12.  * SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF THE
  13.  * SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
  14.  * IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
  15.  * PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR ANY DAMAGES
  16.  * SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR DISTRIBUTING
  17.  * THIS SOFTWARE OR ITS DERIVATIVES.
  18.  * 
  19.  * CopyrightVersion 1.1_beta
  20.  * 
  21.  */
  22.  
  23. /*
  24.  * Type codes  6/12/91
  25.  
  26.     This typecode system allows us to represent the type
  27.     of scalars in a uniform way. For instance, all integer types
  28.     have some bits in common, and are distinguished by a built-in
  29.     size field. Types without multiple sizes don't have a size field.
  30.  
  31.     Scalars may only have sizes which are powers of 2. The size
  32.     field holds the log-based-2 of the object's size.
  33.  
  34.     All run-time types can be encoded in 4 bits. There are more
  35.     compile- time types. These fit in 5 bits.
  36.     Schematically, we have:
  37.         +----+----+----+----+----+
  38.         | c  |    t    |    s    |
  39.         +----+----+----+----+----+
  40.  
  41.         Encoding is:
  42.            c   t  s    type
  43.         -------------------------
  44.            0  00 00    unassigned
  45.            0  00 01    array
  46.            0  00 10    class
  47.            0  00 11    proxy    (OBSOLETE)
  48.            0  01 00    boolean (1 byte)
  49.            0  01 01    char    (2 bytes)
  50.            0  01 1s    float (single=1; double=2)
  51.            0  1u xx    integer (byte=0; short=1; int=2; long=3;
  52.                      u=1 => unsigned)
  53.  
  54.             For runtime types, the size of an object
  55.             is 1<<(t&3)
  56.  
  57.            1  00 00    typedef    (compiler only)
  58.            1  00 01    void    (compiler only)
  59.            1  00 10    func    (compiler only)
  60.            1  00 11    unknown (compiler only)
  61.            1  01 00     error   (compiler only)
  62.  
  63.     Char and Boolean are not int's because they need a different signature,
  64.     so have to be distinguishable, even at runtime. We allow arrays
  65.     of objects, arrays(?), booleans, char, integers, and floats.
  66.     Note that the low-order two bits of all these gives the log of
  67.     the size, except for arrays, of course.
  68.  
  69.     I would prefer not to have unsigned int in the language, but
  70.     don't want to make that decision at this level. We could come up
  71.     with a better encoding of boolean and char if there were no
  72.     unsigned.
  73.  
  74.     The compile-only type values that could be confused with the 
  75.     integer and float scalar types must not ever be used. Value 0 must
  76.     not be assigned a runtime type, as this is used for some sleazy
  77.     trickery in punning types and pointer. In fact, we even have a name
  78.     for it.
  79. */
  80.  
  81. /* If you change these typecodes, you'll have to fix the arrayinfo table
  82.    in gc.c and the {in,}direct_{load,store}_ops tables in
  83.    compiler/tree2code.c */
  84.  
  85. #ifndef _TYPECODES_H_
  86. #define _TYPECODES_H_
  87.  
  88. #define T_NORMAL_OBJECT    0
  89. #define T_XXUNUSEDXX1   1    /* Used to be T_ARRAY */
  90. #define T_CLASS        2
  91. #define T_BOOLEAN    4
  92. #define T_CHAR        5
  93.  
  94. #define T_FLOATING    4    /* add log2 size to get correct code:
  95.                     float has code 6,
  96.                     double has code 7 */
  97. #define T_INTEGER    010
  98. #define T_UINTEGER    014
  99.  
  100. #define    T_MAXNUMERIC    020
  101.  
  102. #define    T_XXUNUSEDXX2    020
  103. #define    T_VOID        021
  104. #define    T_FUNC        022
  105. #define    T_UNKNOWN    023
  106. #define    T_ERROR        024
  107.  
  108. /* for type construction */
  109. #define T_TMASK    034
  110. #define T_LMASK 003
  111. #define T_LSIZE 2
  112. #define T_MKTYPE( t, l )  ( ( (t)&T_TMASK ) | ( (l)&T_LMASK) )
  113.  
  114. /* for type deconstruction */
  115.     /*
  116.      * Because we promise always to let ints and compile-only types be 
  117.      * distinguished by the "t" and "s" bits above, we can simplify
  118.      * some of our predicates by masking out the "c" bit when testing
  119.      * for integers. Thus the T_TS_MASK...
  120.      */
  121. #define T_TS_MASK 034
  122. #define T_ISINTEGER(t)  ( ((t)&030) == T_INTEGER  )
  123. #define T_ISFLOATING(t) ( ((t)&036) == T_FLOAT )
  124. #define T_ISNUMERIC(t)  ( (t) >= T_CHAR && (t) < T_MAXNUMERIC )
  125. #define T_SIZEFIELD(t)    ((t)&T_LMASK)
  126. #define T_ELEMENT_SIZE(t) (1<<T_SIZEFIELD(t))    /* only for some!! */
  127.  
  128. #define T_IS_BIG_TYPE(t) ((t == T_DOUBLE) || (t == T_LONG))
  129. #define T_TYPE_WORDS(t) (T_IS_BIG_TYPE(t) ? 2 : 1)
  130.  
  131. /* nick-names for the usual scalar types */
  132. #define T_FLOAT  T_MKTYPE(T_FLOATING,2)
  133. #define T_DOUBLE T_MKTYPE(T_FLOATING,3)
  134. #define T_BYTE     T_MKTYPE(T_INTEGER,0)
  135. #define T_SHORT     T_MKTYPE(T_INTEGER,1)
  136. #define T_INT     T_MKTYPE(T_INTEGER,2)
  137. #define T_LONG     T_MKTYPE(T_INTEGER,3)
  138.  
  139. #ifdef NO_LONGER_USED
  140. /* We no longer support these types */
  141. #define T_UBYTE     T_MKTYPE(T_UINTEGER,0)
  142. #define T_USHORT T_MKTYPE(T_UINTEGER,1)
  143. #define T_UINT     T_MKTYPE(T_UINTEGER,2)
  144. #define T_ULONG     T_MKTYPE(T_UINTEGER,3)
  145.  
  146. #endif
  147.  
  148. /* only a slight exaggeration */
  149. #define N_TYPECODES    (1<<6)
  150. #define    N_TYPEMASK    (N_TYPECODES-1)
  151.  
  152. #endif /* !_TYPECODES_H_ */
  153.