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.
35 #if !defined (__SYSDEP_H__)
38 #include <sys/types.h>
40 #include <stddef.h> /* size_t, NULL */
45 #if !defined IGNORE /* Macro to silence unused param warnings */
51 ** TRUE and FALSE for C boolean operations, and
52 ** portable 32 bit types for CELLs
68 #define UNS32 u_int32_t
72 #define UNS16 u_int16_t
80 #define NULL ((void *)0)
110 ** FICL_MULTITHREAD enables dictionary mutual exclusion
111 ** wia the ficlLockDictionary system dependent function.
113 #if !defined FICL_MULTITHREAD
114 #define FICL_MULTITHREAD 0
118 ** FICL_ROBUST enables bounds checking of stacks and the dictionary.
119 ** This will detect stack over and underflows and dictionary overflows.
120 ** Any exceptional condition will result in an assertion failure.
121 ** (As generated by the ANSI assert macro)
122 ** FICL_ROBUST == 1 --> stack checking in the outer interpreter
123 ** FICL_ROBUST == 2 also enables checking in many primitives
126 #if !defined FICL_ROBUST
127 #define FICL_ROBUST 2
131 ** FICL_DEFAULT_STACK Specifies the default size (in CELLs) of
132 ** a new virtual machine's stacks, unless overridden at
135 #if !defined FICL_DEFAULT_STACK
136 #define FICL_DEFAULT_STACK 128
140 ** FICL_DEFAULT_DICT specifies the number of CELLs to allocate
141 ** for the system dictionary by default. The value
142 ** can be overridden at startup time as well.
143 ** FICL_DEFAULT_ENV specifies the number of cells to allot
144 ** for the environment-query dictionary.
146 #if !defined FICL_DEFAULT_DICT
147 #define FICL_DEFAULT_DICT 12288
150 #if !defined FICL_DEFAULT_ENV
151 #define FICL_DEFAULT_ENV 260
155 ** FICL_DEFAULT_VOCS specifies the maximum number of wordlists in
156 ** the dictionary search order. See Forth DPANS sec 16.3.3
157 ** (file://dpans16.htm#16.3.3)
159 #if !defined FICL_DEFAULT_VOCS
160 #define FICL_DEFAULT_VOCS 16
164 ** User variables: per-instance variables bound to the VM.
165 ** Kinda like thread-local storage. Could be implemented in a
166 ** VM private dictionary, but I've chosen the lower overhead
167 ** approach of an array of CELLs instead.
169 #if !defined FICL_WANT_USER
170 #define FICL_WANT_USER 1
173 #if !defined FICL_USER_CELLS
174 #define FICL_USER_CELLS 16
178 ** FICL_WANT_LOCALS controls the creation of the LOCALS wordset and
179 ** a private dictionary for local variable compilation.
181 #if !defined FICL_WANT_LOCALS
182 #define FICL_WANT_LOCALS 1
185 /* Max number of local variables per definition */
186 #if !defined FICL_MAX_LOCALS
187 #define FICL_MAX_LOCALS 16
191 ** FICL_ALIGN is the power of two to which the dictionary
192 ** pointer address must be aligned. This value is usually
193 ** either 1 or 2, depending on the memory architecture
194 ** of the target system; 2 is safe on any 16 or 32 bit
197 #if !defined FICL_ALIGN
199 #define FICL_ALIGN_ADD ((1 << FICL_ALIGN) - 1)
203 ** System dependent routines --
204 ** edit the implementations in sysdep.c to be compatible
205 ** with your runtime environment...
206 ** ficlTextOut sends a NULL terminated string to the
207 ** default output device - used for system error messages
208 ** ficlMalloc and ficlFree have the same semantics as malloc and free
210 ** ficlLongMul multiplies two UNS32s and returns a 64 bit unsigned
212 ** ficlLongDiv divides an UNS64 by an UNS32 and returns UNS32 quotient
216 void ficlTextOut(struct vm *pVM, char *msg, int fNewline);
217 void *ficlMalloc (size_t size);
218 void *ficlRealloc (void *p, size_t size);
219 void ficlFree (void *p);
222 ** Stub function for dictionary access control - does nothing
223 ** by default, user can redefine to guarantee exclusive dict
224 ** access to a single thread for updates. All dict update code
225 ** must be bracketed as follows:
226 ** ficlLockDictionary(TRUE);
227 ** <code that updates dictionary>
228 ** ficlLockDictionary(FALSE);
230 ** Returns zero if successful, nonzero if unable to acquire lock
231 ** before timeout (optional - could also block forever)
233 ** NOTE: this function must be implemented with lock counting
234 ** semantics: nested calls must behave properly.
237 int ficlLockDictionary(short fLock);
239 #define ficlLockDictionary(x) 0 /* ignore */
243 ** 64 bit integer math support routines: multiply two UNS32s
244 ** to get a 64 bit prodict, & divide the product by an UNS32
245 ** to get an UNS32 quotient and remainder. Much easier in asm
246 ** on a 32 bit CPU than in C, which usually doesn't support
247 ** the double length result (but it should).
249 UNS64 ficlLongMul(UNS32 x, UNS32 y);
250 UNSQR ficlLongDiv(UNS64 q, UNS32 y);
252 #endif /*__SYSDEP_H__*/