1 /******************************** -*- C -*- ****************************
2  *
3  *	GNU Smalltalk generic inclusions.
4  *
5  *
6  ***********************************************************************/
7 
8 /***********************************************************************
9  *
10  * Copyright 1988,89,90,91,92,94,95,99,2000,2001,2002,2006,2008
11  * Free Software Foundation, Inc.
12  * Written by Steve Byrne.
13  *
14  * This file is part of GNU Smalltalk.
15  *
16  * GNU Smalltalk is free software; you can redistribute it and/or modify it
17  * under the terms of the GNU General Public License as published by the Free
18  * Software Foundation; either version 2, or (at your option) any later
19  * version.
20  *
21  * Linking GNU Smalltalk statically or dynamically with other modules is
22  * making a combined work based on GNU Smalltalk.  Thus, the terms and
23  * conditions of the GNU General Public License cover the whole
24  * combination.
25  *
26  * In addition, as a special exception, the Free Software Foundation
27  * give you permission to combine GNU Smalltalk with free software
28  * programs or libraries that are released under the GNU LGPL and with
29  * independent programs running under the GNU Smalltalk virtual machine.
30  *
31  * You may copy and distribute such a system following the terms of the
32  * GNU GPL for GNU Smalltalk and the licenses of the other code
33  * concerned, provided that you include the source code of that other
34  * code when and as the GNU GPL requires distribution of source code.
35  *
36  * Note that people who make modified versions of GNU Smalltalk are not
37  * obligated to grant this special exception for their modified
38  * versions; it is their choice whether to do so.  The GNU General
39  * Public License gives permission to release a modified version without
40  * this exception; this exception also makes it possible to release a
41  * modified version which carries forward this exception.
42  *
43  * GNU Smalltalk is distributed in the hope that it will be useful, but WITHOUT
44  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
45  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
46  * more details.
47  *
48  * You should have received a copy of the GNU General Public License along with
49  * GNU Smalltalk; see the file COPYING.  If not, write to the Free Software
50  * Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
51  *
52  ***********************************************************************/
53 
54 #ifndef GST_GST_H
55 #define GST_GST_H
56 
57 /* AIX is so broken that requires this to be the first thing in the file.  */
58 #if defined(_AIX)
59 #pragma alloca
60 #else
61 # if !defined(alloca)		/* predefined by HP cc +Olibcalls */
62 #  ifdef __GNUC__
63 #   define alloca(size) __builtin_alloca(size)
64 #  else
65 #   if HAVE_ALLOCA_H
66 #    include <alloca.h>
67 #   else
68 #    if defined(__hpux)
69 void *alloca ();
70 #    else
71 #     if !defined(__OS2__) && !defined(WIN32)
72 char *alloca ();
73 #     else
74 #      include <malloc.h>	/* OS/2 defines alloca in here */
75 #     endif
76 #    endif
77 #   endif
78 #  endif
79 # endif
80 #endif
81 
82 /* Some compilers use different win32 definitions. Define WIN32 so we
83    have only to check for one symbol.  */
84 #if defined(_WIN32) || defined(__CYGWIN32__) || defined(__CYGWIN__) || defined(Win32) || defined(__WIN32)
85 #ifndef WIN32
86 #define WIN32 1
87 #endif
88 #endif
89 
90 #ifdef _MSC_VER
91 /* Visual C++ does not define STDC */
92 #define __STDC__ 1
93 #endif
94 
95 /* Defined as char * in traditional compilers, void * in
96    standard-compliant compilers.  */
97 #ifndef PTR
98 #if !defined(__STDC__)
99 #define PTR char *
100 #else
101 #define PTR void *
102 #endif
103 #endif
104 
105 /* A boolean type */
106 #ifdef __cplusplus
107 typedef bool mst_Boolean;
108 #else
109 typedef enum {
110   false,
111   true
112 } mst_Boolean;
113 #endif
114 
115 /* An indirect pointer to object data.  */
116 typedef struct oop_s *OOP;
117 
118 /* A direct pointer to the object data.  */
119 typedef struct object_s *gst_object, *mst_Object;
120 
121 /* The contents of an indirect pointer to object data.  */
122 struct oop_s
123 {
124   gst_object object;
125   unsigned long flags;		/* FIXME, use uintptr_t */
126 };
127 
128 /* The header of all objects in the system.
129    Note how structural inheritance is achieved without adding extra levels of
130    nested structures.  */
131 #define OBJ_HEADER \
132   OOP		objSize; \
133   OOP		objClass
134 
135 
136 /* Just for symbolic use in sizeof's */
137 typedef struct gst_object_header
138 {
139   OBJ_HEADER;
140 }
141 gst_object_header;
142 
143 #define OBJ_HEADER_SIZE_WORDS	(sizeof(gst_object_header) / sizeof(PTR))
144 
145 /* A bare-knuckles accessor for real objects */
146 struct object_s
147 {
148   OBJ_HEADER;
149   OOP data[1];			/* variable length, may not be objects,
150 				   but will always be at least this
151 				   big.  */
152 };
153 
154 /* Convert an OOP (indirect pointer to an object) to the real object
155    data.  */
156 #define OOP_TO_OBJ(oop) \
157   ((oop)->object)
158 
159 /* Retrieve the class for the object pointed to by OOP.  OOP must be
160    a real pointer, not a SmallInteger.  */
161 #define OOP_CLASS(oop) \
162   (OOP_TO_OBJ(oop)->objClass)
163 
164 
165 /* Answer whether OOP is a SmallInteger or a `real' object pointer.  */
166 #define IS_INT(oop) \
167   ((intptr_t)(oop) & 1)
168 
169 /* Answer whether both OOP1 and OOP2 are SmallIntegers, or rather at
170    least one of them a `real' object pointer.  */
171 #define ARE_INTS(oop1, oop2) \
172   ((intptr_t)(oop1) & (intptr_t)(oop2) & 1)
173 
174 /* Answer whether OOP is a `real' object pointer or rather a
175    SmallInteger.  */
176 #define IS_OOP(oop) \
177   (! IS_INT(oop) )
178 
179 /* Keep these in sync with _gst_sizes, in dict.c.
180    FIXME: these should be exported in a pool dictionary.  */
181 enum gst_indexed_kind {
182   GST_ISP_FIXED = 0,
183   GST_ISP_SCHAR = 32,
184   GST_ISP_UCHAR = 34,
185   GST_ISP_CHARACTER = 36,
186   GST_ISP_SHORT = 38,
187   GST_ISP_USHORT = 40,
188   GST_ISP_INT = 42,
189   GST_ISP_UINT = 44,
190   GST_ISP_FLOAT = 46,
191   GST_ISP_INT64 = 48,
192   GST_ISP_UINT64 = 50,
193   GST_ISP_DOUBLE = 52,
194   GST_ISP_UTF32 = 54,
195   GST_ISP_LAST_SCALAR = 54,
196   GST_ISP_POINTER = 62,
197 
198 #if SIZEOF_OOP == 8
199   GST_ISP_LONG = GST_ISP_INT64,
200   GST_ISP_ULONG = GST_ISP_UINT64,
201   GST_ISP_LAST_UNALIGNED = GST_ISP_FLOAT,
202 #else
203   GST_ISP_LONG = GST_ISP_INT,
204   GST_ISP_ULONG = GST_ISP_UINT,
205   GST_ISP_LAST_UNALIGNED = GST_ISP_USHORT,
206 #endif
207 };
208 
209 
210 /* enum types used by the public APIs.  */
211 enum gst_file_dir {
212   GST_DIR_ABS,
213   GST_DIR_KERNEL_SYSTEM,
214   GST_DIR_KERNEL,
215   GST_DIR_BASE
216 };
217 
218 enum gst_var_index {
219   GST_DECLARE_TRACING,
220   GST_EXECUTION_TRACING,
221   GST_EXECUTION_TRACING_VERBOSE,
222   GST_GC_MESSAGE,
223   GST_VERBOSITY,
224   GST_MAKE_CORE_FILE,
225   GST_REGRESSION_TESTING
226 };
227 
228 enum gst_init_flags {
229   GST_REBUILD_IMAGE = 1,
230   GST_MAYBE_REBUILD_IMAGE = 2,
231   GST_IGNORE_USER_FILES = 4,
232   GST_IGNORE_BAD_IMAGE_PATH = 8,
233   GST_IGNORE_BAD_KERNEL_PATH = 16,
234   GST_NO_TTY = 32,
235 };
236 
237 enum gst_vm_hook {
238   GST_BEFORE_EVAL,
239   GST_AFTER_EVAL,
240   GST_RETURN_FROM_SNAPSHOT,
241   GST_ABOUT_TO_QUIT,
242   GST_ABOUT_TO_SNAPSHOT,
243   GST_FINISHED_SNAPSHOT
244 };
245 
246 #define INDEXED_WORD(obj, n)   ( ((long *) ((obj) + 1))		    [(n)-1] )
247 #define INDEXED_BYTE(obj, n)   ( ((char *) ((obj) + 1))		    [(n)-1] )
248 #define INDEXED_OOP(obj, n)    ( ((OOP  *) ((obj) + 1))		    [(n)-1] )
249 #define ARRAY_OOP_AT(obj, n)   ( ((OOP  *) ((gst_object) obj)->data) [(n)-1] )
250 #define STRING_OOP_AT(obj, n)  ( ((char *) ((gst_object) obj)->data) [(n)-1] )
251 
252 #endif /* GST_GST_H */
253