1 /********************************************************************/
2 /*                                                                  */
3 /*  data_rtl.h    Basic type definitions and settings.              */
4 /*  Copyright (C) 1989 - 2005  Thomas Mertes                        */
5 /*                                                                  */
6 /*  This file is part of the Seed7 Runtime Library.                 */
7 /*                                                                  */
8 /*  The Seed7 Runtime Library is free software; you can             */
9 /*  redistribute it and/or modify it under the terms of the GNU     */
10 /*  Lesser General Public License as published by the Free Software */
11 /*  Foundation; either version 2.1 of the License, or (at your      */
12 /*  option) any later version.                                      */
13 /*                                                                  */
14 /*  The Seed7 Runtime Library is distributed in the hope that it    */
15 /*  will be useful, but WITHOUT ANY WARRANTY; without even the      */
16 /*  implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR */
17 /*  PURPOSE.  See the GNU Lesser General Public License for more    */
18 /*  details.                                                        */
19 /*                                                                  */
20 /*  You should have received a copy of the GNU Lesser General       */
21 /*  Public License along with this program; if not, write to the    */
22 /*  Free Software Foundation, Inc., 51 Franklin Street,             */
23 /*  Fifth Floor, Boston, MA  02110-1301, USA.                       */
24 /*                                                                  */
25 /*  Module: Seed7 Runtime Library                                   */
26 /*  File: seed7/src/data_rtl.h                                      */
27 /*  Changes: 1990 - 1994, 2000, 2005  Thomas Mertes                 */
28 /*  Content: Type definitions for general data structures.          */
29 /*                                                                  */
30 /********************************************************************/
31 
32 /* In classic C a function cannot return structs by value and */
33 /* cannot have struct value parameters. Because of this the   */
34 /* unsigned integer type genericType is used, instead of      */
35 /* rtlObjectType. To work reliably it must be assured that    */
36 /* sizeof(genericType) == sizeof(rtlObjectType)               */
37 
38 #if INTTYPE_SIZE >= POINTER_SIZE
39 #if INTTYPE_SIZE >= FLOATTYPE_SIZE
40 #define GENERIC_SIZE INTTYPE_SIZE
41 #else
42 #define GENERIC_SIZE FLOATTYPE_SIZE
43 #endif
44 #elif POINTER_SIZE >= FLOATTYPE_SIZE
45 #define GENERIC_SIZE POINTER_SIZE
46 #else
47 #define GENERIC_SIZE FLOATTYPE_SIZE
48 #endif
49 
50 #if   GENERIC_SIZE == 64
51 typedef uint64Type genericType;
52 #define GENERIC_SUFFIX(num) UINT64_SUFFIX(num)
53 #define FMT_D_GEN  FMT_D64
54 #define FMT_U_GEN  FMT_U64
55 #define FMT_X_GEN  FMT_X64
56 #elif GENERIC_SIZE == 32
57 typedef uint32Type genericType;
58 #define GENERIC_SUFFIX(num) UINT32_SUFFIX(num)
59 #define FMT_D_GEN  FMT_D32
60 #define FMT_U_GEN  FMT_U32
61 #define FMT_X_GEN  FMT_X32
62 #endif
63 
64 #if GENERIC_SIZE != POINTER_SIZE
65 #define INIT_GENERIC_PTR(gen) (gen) = GENERIC_SUFFIX(0)
66 #else
67 /* Initialization is not necessary because it will be overwritten. */
68 #define INIT_GENERIC_PTR(gen)
69 #endif
70 
71 #if GENERIC_SIZE != INTTYPE_SIZE
72 #define INIT_GENERIC_INT(gen) (gen) = GENERIC_SUFFIX(0)
73 #else
74 /* Initialization is not necessary because it will be overwritten. */
75 #define INIT_GENERIC_INT(gen)
76 #endif
77 
78 typedef struct rtlTypeStruct     *rtlTypeType;
79 typedef struct rtlListStruct     *rtlListType;
80 typedef struct rtlArrayStruct    *rtlArrayType;
81 typedef struct rtlStructStruct   *rtlStructType;
82 typedef struct rtlStructStruct   *rtlInterfaceType;
83 typedef struct rtlHashElemStruct *rtlHashElemType;
84 typedef struct rtlHashStruct     *rtlHashType;
85 typedef void *rtlPtrType;
86 
87 typedef const struct rtlTypeStruct     *const_rtlTypeType;
88 typedef const struct rtlListStruct     *const_rtlListType;
89 typedef const struct rtlArrayStruct    *const_rtlArrayType;
90 typedef const struct rtlStructStruct   *const_rtlStructType;
91 typedef const struct rtlStructStruct   *const_rtlInterfaceType;
92 typedef const struct rtlHashElemStruct *const_rtlHashElemType;
93 typedef const struct rtlHashStruct     *const_rtlHashType;
94 typedef const void *const_rtlPtrType;
95 
96 typedef union {
97   /* Genericvalue must be the first element in the union. */
98   /* This allows initialisations of rtlValueUnion values. */
99     genericType      genericValue;
100 /*    posType          pos;            ** SYMBOLOBJECT */
101     boolType         boolValue;
102     rtlTypeType      typeValue;      /* TYPEOBJECT */
103     intType          intValue;       /* INTOBJECT */
104     bigIntType       bigIntValue;    /* BIGINTOBJECT */
105     charType         charValue;      /* CHAROBJECT */
106     striType         striValue;      /* STRIOBJECT */
107     bstriType        bstriValue;     /* BSTRIOBJECT */
108     rtlArrayType     arrayValue;     /* ARRAYOBJECT */
109     rtlHashType      hashValue;      /* HASHOBJECT */
110     setType          setValue;       /* SETOBJECT */
111     rtlStructType    structValue;    /* STRUCTOBJECT */
112     uintType         binaryValue;    /* INTOBJECT */
113     rtlInterfaceType interfaceValue; /* INTERFACEOBJECT */
114     fileType         fileValue;      /* FILEOBJECT */
115     fileDesType      fileDesValue;   /* FILEDESOBJECT */
116     socketType       socketValue;    /* SOCKETOBJECT */
117     rtlListType      listValue;      /* LISTOBJECT, EXPROBJECT */
118     winType          winValue;       /* WINOBJECT */
119     processType      processValue;   /* PROCESSOBJECT */
120     databaseType     databaseValue;  /* DATABASEOBJECT */
121     sqlStmtType      sqlStmtValue;   /* SQLSTMTOBJECT */
122     rtlPtrType       ptrValue;
123 /*    enumType         enumValue;      */
124 /*    pollType         pollValue;      */
125 /*    objRefType       objRefValue;    */
126 /*    rtlObjectType    objValue;       ** ENUMLITERALOBJECT, CONSTENUMOBJECT */
127                                      /* VARENUMOBJECT, VALUEPARAMOBJECT */
128                                      /* REFPARAMOBJECT, RESULTOBJECT */
129                                      /* LOCALVOBJECT, FORMPARAMOBJECT */
130 /*    blockType        blockValue;     ** BLOCKOBJECT */
131 /*    actType          actValue;       ** ACTOBJECT */
132 /*    progType         progValue;      ** PROGOBJECT */
133 #if WITH_FLOAT
134     floatType      floatValue;   /* FLOATOBJECT */
135 #endif
136   } rtlValueUnion;
137 
138 typedef struct rtlObjectStruct {
139     rtlValueUnion value;
140   } rtlObjectType;
141 
142 typedef const struct rtlObjectStruct const_rtlObjectType;
143 
144 typedef struct rtlTypeStruct {
145     int dummy;
146   } rtlTypeRecord;
147 
148 typedef struct rtlListStruct {
149     rtlListType next;
150     rtlObjectType obj;
151   } rtlListRecord;
152 
153 typedef struct rtlArrayStruct {
154     intType min_position;
155     intType max_position;
156     rtlObjectType arr[1];
157   } rtlArrayRecord;
158 
159 typedef struct rtlStructStruct {
160     memSizeType usage_count;
161     uint32Type type_num;
162     rtlObjectType stru[1];
163   } rtlStructRecord;
164 
165 typedef struct rtlHashElemStruct {
166     rtlHashElemType next_less;
167     rtlHashElemType next_greater;
168     rtlObjectType key;
169     rtlObjectType data;
170   } rtlHashElemRecord;
171 
172 typedef struct rtlHashStruct {
173     unsigned int bits;
174     unsigned int mask;
175     unsigned int table_size;
176     memSizeType size;
177     rtlHashElemType table[1];
178   } rtlHashRecord;
179 
180 typedef struct rtlTimeStruct {
181     rtlObjectType year;
182     rtlObjectType month;
183     rtlObjectType day;
184     rtlObjectType hour;
185     rtlObjectType minute;
186     rtlObjectType second;
187     rtlObjectType micro_second;
188     rtlObjectType timeZone;
189     rtlObjectType daylightSavingTime;
190   } rtlTimeRecord;
191 
192 typedef intType (*compareType) (genericType, genericType);
193 typedef genericType (*createFuncType) (genericType);
194 typedef void (*destrFuncType) (genericType);
195 typedef void (*copyFuncType) (genericType *, genericType);
196 
197 
198 intType genericCmp (const genericType value1, const genericType value2);
199 void genericCpy (genericType *const dest, const genericType source);
200 genericType genericCreate (genericType source);
201 void genericDestr (genericType old_value);
202