1 /*******************************************************************
3 ** Forth Inspired Command Language
4 ** Author: John Sadler (john_sadler@alum.mit.edu)
5 ** Created: 16 Oct 1997
6 ** Ficl system dependent types and prototypes...
8 ** Note: Ficl also depends on the use of "assert" when
9 ** FICL_ROBUST is enabled. This may require some consideration
10 ** in firmware systems since assert often
11 ** assumes stderr/stdout.
13 *******************************************************************/
15 ** N O T I C E -- DISCLAIMER OF WARRANTY
17 ** Ficl is freeware. Use it in any way that you like, with
18 ** the understanding that the code is not supported.
20 ** Any third party may reproduce, distribute, or modify the ficl
21 ** software code or any derivative works thereof without any
22 ** compensation or license, provided that the author information
23 ** and this disclaimer text are retained in the source code files.
24 ** The ficl software code is provided on an "as is" basis without
25 ** warranty of any kind, including, without limitation, the implied
26 ** warranties of merchantability and fitness for a particular purpose
27 ** and their equivalents under the laws of any jurisdiction.
29 ** I am interested in hearing from anyone who uses ficl. If you have
30 ** a problem, a success story, a defect, an enhancement request, or
31 ** if you would like to contribute to the ficl release (yay!), please
32 ** send me email at the address above.
37 #if !defined (__SYSDEP_H__)
40 #include <sys/types.h>
42 #include <stddef.h> /* size_t, NULL */
47 #if !defined IGNORE /* Macro to silence unused param warnings */
53 ** TRUE and FALSE for C boolean operations, and
54 ** portable 32 bit types for CELLs
66 ** System dependent data type declarations...
73 #define UNS32 unsigned long
77 #define UNS16 unsigned short
81 #define UNS8 unsigned char
85 #define NULL ((void *)0)
89 ** FICL_UNS and FICL_INT must have the same size as a void* on
90 ** the target system. A CELL is a union of void*, FICL_UNS, and
94 #define FICL_INT INT32
98 #define FICL_UNS UNS32
102 ** Ficl presently supports values of 32 and 64 for BITS_PER_CELL
104 #if !defined BITS_PER_CELL
105 #define BITS_PER_CELL 32
108 #if ((BITS_PER_CELL != 32) && (BITS_PER_CELL != 64))
139 ** FICL_MULTITHREAD enables dictionary mutual exclusion
140 ** wia the ficlLockDictionary system dependent function.
142 #if !defined FICL_MULTITHREAD
143 #define FICL_MULTITHREAD 0
147 ** PORTABLE_LONGMULDIV causes ficlLongMul and ficlLongDiv to be
148 ** defined in C in sysdep.c. Use this if you cannot easily
149 ** generate an inline asm definition
151 #if !defined (PORTABLE_LONGMULDIV)
152 #define PORTABLE_LONGMULDIV 0
157 ** INLINE_INNER_LOOP causes the inner interpreter to be inline code
158 ** instead of a function call. This is mainly because MS VC++ 5
159 ** chokes with an internal compiler error on the function version.
160 ** in release mode. Sheesh.
162 #if !defined INLINE_INNER_LOOP
164 #define INLINE_INNER_LOOP 0
166 #define INLINE_INNER_LOOP 1
171 ** FICL_ROBUST enables bounds checking of stacks and the dictionary.
172 ** This will detect stack over and underflows and dictionary overflows.
173 ** Any exceptional condition will result in an assertion failure.
174 ** (As generated by the ANSI assert macro)
175 ** FICL_ROBUST == 1 --> stack checking in the outer interpreter
176 ** FICL_ROBUST == 2 also enables checking in many primitives
179 #if !defined FICL_ROBUST
180 #define FICL_ROBUST 2
184 ** FICL_DEFAULT_STACK Specifies the default size (in CELLs) of
185 ** a new virtual machine's stacks, unless overridden at
188 #if !defined FICL_DEFAULT_STACK
189 #define FICL_DEFAULT_STACK 128
193 ** FICL_DEFAULT_DICT specifies the number of CELLs to allocate
194 ** for the system dictionary by default. The value
195 ** can be overridden at startup time as well.
196 ** FICL_DEFAULT_ENV specifies the number of cells to allot
197 ** for the environment-query dictionary.
199 #if !defined FICL_DEFAULT_DICT
200 #define FICL_DEFAULT_DICT 12288
203 #if !defined FICL_DEFAULT_ENV
204 #define FICL_DEFAULT_ENV 260
208 ** FICL_DEFAULT_VOCS specifies the maximum number of wordlists in
209 ** the dictionary search order. See Forth DPANS sec 16.3.3
210 ** (file://dpans16.htm#16.3.3)
212 #if !defined FICL_DEFAULT_VOCS
213 #define FICL_DEFAULT_VOCS 16
217 ** User variables: per-instance variables bound to the VM.
218 ** Kinda like thread-local storage. Could be implemented in a
219 ** VM private dictionary, but I've chosen the lower overhead
220 ** approach of an array of CELLs instead.
222 #if !defined FICL_WANT_USER
223 #define FICL_WANT_USER 1
226 #if !defined FICL_USER_CELLS
227 #define FICL_USER_CELLS 16
231 ** FICL_WANT_LOCALS controls the creation of the LOCALS wordset and
232 ** a private dictionary for local variable compilation.
234 #if !defined FICL_WANT_LOCALS
235 #define FICL_WANT_LOCALS 1
238 /* Max number of local variables per definition */
239 #if !defined FICL_MAX_LOCALS
240 #define FICL_MAX_LOCALS 16
244 ** FICL_ALIGN is the power of two to which the dictionary
245 ** pointer address must be aligned. This value is usually
246 ** either 1 or 2, depending on the memory architecture
247 ** of the target system; 2 is safe on any 16 or 32 bit
248 ** machine. 3 would be appropriate for a 64 bit machine.
250 #if !defined FICL_ALIGN
252 #define FICL_ALIGN_ADD ((1 << FICL_ALIGN) - 1)
256 ** System dependent routines --
257 ** edit the implementations in sysdep.c to be compatible
258 ** with your runtime environment...
259 ** ficlTextOut sends a NULL terminated string to the
260 ** default output device - used for system error messages
261 ** ficlMalloc and ficlFree have the same semantics as malloc and free
263 ** ficlLongMul multiplies two UNS32s and returns a 64 bit unsigned
265 ** ficlLongDiv divides an UNS64 by an UNS32 and returns UNS32 quotient
269 void ficlTextOut(struct vm *pVM, char *msg, int fNewline);
270 void *ficlMalloc (size_t size);
271 void ficlFree (void *p);
272 void *ficlRealloc(void *p, size_t size);
274 ** Stub function for dictionary access control - does nothing
275 ** by default, user can redefine to guarantee exclusive dict
276 ** access to a single thread for updates. All dict update code
277 ** must be bracketed as follows:
278 ** ficlLockDictionary(TRUE);
279 ** <code that updates dictionary>
280 ** ficlLockDictionary(FALSE);
282 ** Returns zero if successful, nonzero if unable to acquire lock
283 ** before timeout (optional - could also block forever)
285 ** NOTE: this function must be implemented with lock counting
286 ** semantics: nested calls must behave properly.
289 int ficlLockDictionary(short fLock);
291 #define ficlLockDictionary(x) 0 /* ignore */
295 ** 64 bit integer math support routines: multiply two UNS32s
296 ** to get a 64 bit product, & divide the product by an UNS32
297 ** to get an UNS32 quotient and remainder. Much easier in asm
298 ** on a 32 bit CPU than in C, which usually doesn't support
299 ** the double length result (but it should).
301 DPUNS ficlLongMul(FICL_UNS x, FICL_UNS y);
302 UNSQR ficlLongDiv(DPUNS q, FICL_UNS y);
304 #endif /*__SYSDEP_H__*/