182940Sdfr/*******************************************************************
282940Sdfr                    s y s d e p . h
382940Sdfr** Forth Inspired Command Language
482940Sdfr** Author: John Sadler (john_sadler@alum.mit.edu)
582940Sdfr** Created: 16 Oct 1997
682940Sdfr** Ficl system dependent types and prototypes...
782940Sdfr**
882940Sdfr** Note: Ficl also depends on the use of "assert" when
982940Sdfr** FICL_ROBUST is enabled. This may require some consideration
1082940Sdfr** in firmware systems since assert often
1182940Sdfr** assumes stderr/stdout.
1294290Sdcs** $Id: sysdep.h,v 1.11 2001/12/05 07:21:34 jsadler Exp $
1382940Sdfr*******************************************************************/
1482940Sdfr/*
1582940Sdfr** Copyright (c) 1997-2001 John Sadler (john_sadler@alum.mit.edu)
1682940Sdfr** All rights reserved.
1782940Sdfr**
1882940Sdfr** Get the latest Ficl release at http://ficl.sourceforge.net
1982940Sdfr**
2094290Sdcs** I am interested in hearing from anyone who uses ficl. If you have
2194290Sdcs** a problem, a success story, a defect, an enhancement request, or
2294290Sdcs** if you would like to contribute to the ficl release, please
2394290Sdcs** contact me by email at the address above.
2494290Sdcs**
2582940Sdfr** L I C E N S E  and  D I S C L A I M E R
2682940Sdfr**
2782940Sdfr** Redistribution and use in source and binary forms, with or without
2882940Sdfr** modification, are permitted provided that the following conditions
2982940Sdfr** are met:
3082940Sdfr** 1. Redistributions of source code must retain the above copyright
3182940Sdfr**    notice, this list of conditions and the following disclaimer.
3282940Sdfr** 2. Redistributions in binary form must reproduce the above copyright
3382940Sdfr**    notice, this list of conditions and the following disclaimer in the
3482940Sdfr**    documentation and/or other materials provided with the distribution.
3582940Sdfr**
3682940Sdfr** THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
3782940Sdfr** ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
3882940Sdfr** IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
3982940Sdfr** ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
4082940Sdfr** FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
4182940Sdfr** DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
4282940Sdfr** OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
4382940Sdfr** HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
4482940Sdfr** LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
4582940Sdfr** OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
4682940Sdfr** SUCH DAMAGE.
4782940Sdfr**
4882940Sdfr** $Id: sysdep.h,v 1.6 2001-04-26 21:41:55-07 jsadler Exp jsadler $
4982940Sdfr*/
5082940Sdfr
5182940Sdfr/* $FreeBSD$ */
5282940Sdfr
5382940Sdfr#if !defined (__SYSDEP_H__)
5482940Sdfr#define __SYSDEP_H__
5582940Sdfr
5682940Sdfr#include <sys/types.h>
5782940Sdfr
5882940Sdfr#include <stddef.h> /* size_t, NULL */
5982940Sdfr#include <setjmp.h>
6082940Sdfr#include <assert.h>
6182940Sdfr
6282940Sdfr#if !defined IGNORE		/* Macro to silence unused param warnings */
6382940Sdfr#define IGNORE(x) &x
6482940Sdfr#endif
6582940Sdfr
6682940Sdfr/*
6782940Sdfr** TRUE and FALSE for C boolean operations, and
6882940Sdfr** portable 32 bit types for CELLs
6982940Sdfr**
7082940Sdfr*/
7182940Sdfr#if !defined TRUE
7282940Sdfr#define TRUE 1
7382940Sdfr#endif
7482940Sdfr#if !defined FALSE
7582940Sdfr#define FALSE 0
7682940Sdfr#endif
7782940Sdfr
7882940Sdfr/*
7982940Sdfr** System dependent data type declarations...
8082940Sdfr*/
8182940Sdfr#if !defined INT32
8282940Sdfr#define INT32 int
8382940Sdfr#endif
8482940Sdfr
8582940Sdfr#if !defined UNS32
8682940Sdfr#define UNS32 unsigned int
8782940Sdfr#endif
8882940Sdfr
8982940Sdfr#if !defined UNS16
9082940Sdfr#define UNS16 unsigned short
9182940Sdfr#endif
9282940Sdfr
9382940Sdfr#if !defined UNS8
9482940Sdfr#define UNS8 unsigned char
9582940Sdfr#endif
9682940Sdfr
9782940Sdfr#if !defined NULL
9882940Sdfr#define NULL ((void *)0)
9982940Sdfr#endif
10082940Sdfr
10182940Sdfr/*
10282940Sdfr** FICL_UNS and FICL_INT must have the same size as a void* on
10382940Sdfr** the target system. A CELL is a union of void*, FICL_UNS, and
10482940Sdfr** FICL_INT.
10582940Sdfr** (11/2000: same for FICL_FLOAT)
10682940Sdfr*/
10782940Sdfr#if !defined FICL_INT
10882940Sdfr#define FICL_INT long
10982940Sdfr#endif
11082940Sdfr
11182940Sdfr#if !defined FICL_UNS
11282940Sdfr#define FICL_UNS unsigned long
11382940Sdfr#endif
11482940Sdfr
11582940Sdfr#if !defined FICL_FLOAT
11682940Sdfr#define FICL_FLOAT float
11782940Sdfr#endif
11882940Sdfr
11982940Sdfr/*
12082940Sdfr** Ficl presently supports values of 32 and 64 for BITS_PER_CELL
12182940Sdfr*/
12282940Sdfr#if !defined BITS_PER_CELL
12382940Sdfr#define BITS_PER_CELL 64
12482940Sdfr#endif
12582940Sdfr
12682940Sdfr#if ((BITS_PER_CELL != 32) && (BITS_PER_CELL != 64))
12782940Sdfr    Error!
12882940Sdfr#endif
12982940Sdfr
13082940Sdfrtypedef struct
13182940Sdfr{
13282940Sdfr    FICL_UNS hi;
13382940Sdfr    FICL_UNS lo;
13482940Sdfr} DPUNS;
13582940Sdfr
13682940Sdfrtypedef struct
13782940Sdfr{
13882940Sdfr    FICL_UNS quot;
13982940Sdfr    FICL_UNS rem;
14082940Sdfr} UNSQR;
14182940Sdfr
14282940Sdfrtypedef struct
14382940Sdfr{
14482940Sdfr    FICL_INT hi;
14582940Sdfr    FICL_INT lo;
14682940Sdfr} DPINT;
14782940Sdfr
14882940Sdfrtypedef struct
14982940Sdfr{
15082940Sdfr    FICL_INT quot;
15182940Sdfr    FICL_INT rem;
15282940Sdfr} INTQR;
15382940Sdfr
15482940Sdfr
15582940Sdfr/*
15682940Sdfr** B U I L D   C O N T R O L S
15782940Sdfr*/
15882940Sdfr
15982940Sdfr#if !defined (FICL_MINIMAL)
16082940Sdfr#define FICL_MINIMAL 0
16182940Sdfr#endif
16282940Sdfr#if (FICL_MINIMAL)
16382940Sdfr#define FICL_WANT_SOFTWORDS  0
16494290Sdcs#define FICL_WANT_FILE       0
16582940Sdfr#define FICL_WANT_FLOAT      0
16682940Sdfr#define FICL_WANT_USER       0
16782940Sdfr#define FICL_WANT_LOCALS     0
16882940Sdfr#define FICL_WANT_DEBUGGER   0
16982940Sdfr#define FICL_WANT_OOP        0
17082940Sdfr#define FICL_PLATFORM_EXTEND 0
17182940Sdfr#define FICL_MULTITHREAD     0
17282940Sdfr#define FICL_ROBUST          0
17382940Sdfr#define FICL_EXTENDED_PREFIX 0
17482940Sdfr#endif
17582940Sdfr
17682940Sdfr/*
17782940Sdfr** FICL_PLATFORM_EXTEND
17882940Sdfr** Includes words defined in ficlCompilePlatform
17982940Sdfr*/
18082940Sdfr#if !defined (FICL_PLATFORM_EXTEND)
18182940Sdfr#define FICL_PLATFORM_EXTEND 1
18282940Sdfr#endif
18382940Sdfr
18494290Sdcs
18582940Sdfr/*
18694290Sdcs** FICL_WANT_FILE
18794290Sdcs** Includes the FILE and FILE-EXT wordset and associated code. Turn this off if you do not
18896755Strhodes** have a filesystem!
18994290Sdcs** Contributed by Larry Hastings
19094290Sdcs*/
19194290Sdcs#if !defined (FICL_WANT_FILE)
19294290Sdcs#define FICL_WANT_FILE 0
19394290Sdcs#endif
19494290Sdcs
19594290Sdcs/*
19682940Sdfr** FICL_WANT_FLOAT
19782940Sdfr** Includes a floating point stack for the VM, and words to do float operations.
19882940Sdfr** Contributed by Guy Carver
19982940Sdfr*/
20082940Sdfr#if !defined (FICL_WANT_FLOAT)
20182940Sdfr#define FICL_WANT_FLOAT 0
20282940Sdfr#endif
20382940Sdfr
20482940Sdfr/*
20582940Sdfr** FICL_WANT_DEBUGGER
20682940Sdfr** Inludes a simple source level debugger
20782940Sdfr*/
20882940Sdfr#if !defined (FICL_WANT_DEBUGGER)
20982940Sdfr#define FICL_WANT_DEBUGGER 1
21082940Sdfr#endif
21182940Sdfr
21282940Sdfr/*
21394290Sdcs** FICL_EXTENDED_PREFIX enables a bunch of extra prefixes in prefix.c and prefix.fr (if
21494290Sdcs** included as part of softcore.c)
21594290Sdcs*/
21694290Sdcs#if !defined FICL_EXTENDED_PREFIX
21794290Sdcs#define FICL_EXTENDED_PREFIX 0
21894290Sdcs#endif
21994290Sdcs
22094290Sdcs/*
22182940Sdfr** User variables: per-instance variables bound to the VM.
22282940Sdfr** Kinda like thread-local storage. Could be implemented in a
22382940Sdfr** VM private dictionary, but I've chosen the lower overhead
22482940Sdfr** approach of an array of CELLs instead.
22582940Sdfr*/
22682940Sdfr#if !defined FICL_WANT_USER
22782940Sdfr#define FICL_WANT_USER 1
22882940Sdfr#endif
22982940Sdfr
23082940Sdfr#if !defined FICL_USER_CELLS
23182940Sdfr#define FICL_USER_CELLS 16
23282940Sdfr#endif
23382940Sdfr
23482940Sdfr/*
23582940Sdfr** FICL_WANT_LOCALS controls the creation of the LOCALS wordset and
23682940Sdfr** a private dictionary for local variable compilation.
23782940Sdfr*/
23882940Sdfr#if !defined FICL_WANT_LOCALS
23982940Sdfr#define FICL_WANT_LOCALS 1
24082940Sdfr#endif
24182940Sdfr
24282940Sdfr/* Max number of local variables per definition */
24382940Sdfr#if !defined FICL_MAX_LOCALS
24482940Sdfr#define FICL_MAX_LOCALS 16
24582940Sdfr#endif
24682940Sdfr
24782940Sdfr/*
24882940Sdfr** FICL_WANT_OOP
24982940Sdfr** Inludes object oriented programming support (in softwords)
25082940Sdfr** OOP support requires locals and user variables!
25182940Sdfr*/
25282940Sdfr#if !(FICL_WANT_LOCALS) || !(FICL_WANT_USER)
25382940Sdfr#if !defined (FICL_WANT_OOP)
25482940Sdfr#define FICL_WANT_OOP 0
25582940Sdfr#endif
25682940Sdfr#endif
25782940Sdfr
25882940Sdfr#if !defined (FICL_WANT_OOP)
25982940Sdfr#define FICL_WANT_OOP 1
26082940Sdfr#endif
26182940Sdfr
26282940Sdfr/*
26382940Sdfr** FICL_WANT_SOFTWORDS
26482940Sdfr** Controls inclusion of all softwords in softcore.c
26582940Sdfr*/
26682940Sdfr#if !defined (FICL_WANT_SOFTWORDS)
26782940Sdfr#define FICL_WANT_SOFTWORDS 1
26882940Sdfr#endif
26982940Sdfr
27082940Sdfr/*
27182940Sdfr** FICL_MULTITHREAD enables dictionary mutual exclusion
27282940Sdfr** wia the ficlLockDictionary system dependent function.
27382940Sdfr** Note: this implementation is experimental and poorly
27482940Sdfr** tested. Further, it's unnecessary unless you really
27582940Sdfr** intend to have multiple SESSIONS (poor choice of name
27682940Sdfr** on my part) - that is, threads that modify the dictionary
27782940Sdfr** at the same time.
27882940Sdfr*/
27982940Sdfr#if !defined FICL_MULTITHREAD
28082940Sdfr#define FICL_MULTITHREAD 0
28182940Sdfr#endif
28282940Sdfr
28382940Sdfr/*
28482940Sdfr** PORTABLE_LONGMULDIV causes ficlLongMul and ficlLongDiv to be
28582940Sdfr** defined in C in sysdep.c. Use this if you cannot easily
28682940Sdfr** generate an inline asm definition
28782940Sdfr*/
28882940Sdfr#if !defined (PORTABLE_LONGMULDIV)
28982940Sdfr#define PORTABLE_LONGMULDIV 0
29082940Sdfr#endif
29182940Sdfr
29282940Sdfr/*
29382940Sdfr** INLINE_INNER_LOOP causes the inner interpreter to be inline code
29482940Sdfr** instead of a function call. This is mainly because MS VC++ 5
29582940Sdfr** chokes with an internal compiler error on the function version.
29682940Sdfr** in release mode. Sheesh.
29782940Sdfr*/
29882940Sdfr#if !defined INLINE_INNER_LOOP
29982940Sdfr#if defined _DEBUG
30082940Sdfr#define INLINE_INNER_LOOP 0
30182940Sdfr#else
30282940Sdfr#define INLINE_INNER_LOOP 1
30382940Sdfr#endif
30482940Sdfr#endif
30582940Sdfr
30682940Sdfr/*
30782940Sdfr** FICL_ROBUST enables bounds checking of stacks and the dictionary.
30882940Sdfr** This will detect stack over and underflows and dictionary overflows.
30982940Sdfr** Any exceptional condition will result in an assertion failure.
31082940Sdfr** (As generated by the ANSI assert macro)
31182940Sdfr** FICL_ROBUST == 1 --> stack checking in the outer interpreter
31282940Sdfr** FICL_ROBUST == 2 also enables checking in many primitives
31382940Sdfr*/
31482940Sdfr
31582940Sdfr#if !defined FICL_ROBUST
31682940Sdfr#define FICL_ROBUST 2
31782940Sdfr#endif
31882940Sdfr
31982940Sdfr/*
32082940Sdfr** FICL_DEFAULT_STACK Specifies the default size (in CELLs) of
32182940Sdfr** a new virtual machine's stacks, unless overridden at
32282940Sdfr** create time.
32382940Sdfr*/
32482940Sdfr#if !defined FICL_DEFAULT_STACK
32582940Sdfr#define FICL_DEFAULT_STACK 128
32682940Sdfr#endif
32782940Sdfr
32882940Sdfr/*
32982940Sdfr** FICL_DEFAULT_DICT specifies the number of CELLs to allocate
33082940Sdfr** for the system dictionary by default. The value
33182940Sdfr** can be overridden at startup time as well.
33282940Sdfr** FICL_DEFAULT_ENV specifies the number of cells to allot
33382940Sdfr** for the environment-query dictionary.
33482940Sdfr*/
33582940Sdfr#if !defined FICL_DEFAULT_DICT
33682940Sdfr#define FICL_DEFAULT_DICT 12288
33782940Sdfr#endif
33882940Sdfr
33982940Sdfr#if !defined FICL_DEFAULT_ENV
34082940Sdfr#define FICL_DEFAULT_ENV 260
34182940Sdfr#endif
34282940Sdfr
34382940Sdfr/*
34482940Sdfr** FICL_DEFAULT_VOCS specifies the maximum number of wordlists in
34582940Sdfr** the dictionary search order. See Forth DPANS sec 16.3.3
34682940Sdfr** (file://dpans16.htm#16.3.3)
34782940Sdfr*/
34882940Sdfr#if !defined FICL_DEFAULT_VOCS
34982940Sdfr#define FICL_DEFAULT_VOCS 16
35082940Sdfr#endif
35182940Sdfr
35282940Sdfr/*
35382940Sdfr** FICL_MAX_PARSE_STEPS controls the size of an array in the FICL_SYSTEM structure
35482940Sdfr** that stores pointers to parser extension functions. I would never expect to have
35582940Sdfr** more than 8 of these, so that's the default limit. Too many of these functions
35682940Sdfr** will probably exact a nasty performance penalty.
35782940Sdfr*/
35882940Sdfr#if !defined FICL_MAX_PARSE_STEPS
35982940Sdfr#define FICL_MAX_PARSE_STEPS 8
36082940Sdfr#endif
36182940Sdfr
36282940Sdfr/*
36382940Sdfr** FICL_ALIGN is the power of two to which the dictionary
36482940Sdfr** pointer address must be aligned. This value is usually
36582940Sdfr** either 1 or 2, depending on the memory architecture
36682940Sdfr** of the target system; 2 is safe on any 16 or 32 bit
36782940Sdfr** machine. 3 would be appropriate for a 64 bit machine.
36882940Sdfr*/
36982940Sdfr#if !defined FICL_ALIGN
37082940Sdfr#define FICL_ALIGN 3
37182940Sdfr#define FICL_ALIGN_ADD ((1 << FICL_ALIGN) - 1)
37282940Sdfr#endif
37382940Sdfr
37482940Sdfr/*
37582940Sdfr** System dependent routines --
37682940Sdfr** edit the implementations in sysdep.c to be compatible
37782940Sdfr** with your runtime environment...
37882940Sdfr** ficlTextOut sends a NULL terminated string to the
37982940Sdfr**   default output device - used for system error messages
38082940Sdfr** ficlMalloc and ficlFree have the same semantics as malloc and free
38182940Sdfr**   in standard C
38282940Sdfr** ficlLongMul multiplies two UNS32s and returns a 64 bit unsigned
38382940Sdfr**   product
38482940Sdfr** ficlLongDiv divides an UNS64 by an UNS32 and returns UNS32 quotient
38582940Sdfr**   and remainder
38682940Sdfr*/
38782940Sdfrstruct vm;
38882940Sdfrvoid  ficlTextOut(struct vm *pVM, char *msg, int fNewline);
38982940Sdfrvoid *ficlMalloc (size_t size);
39082940Sdfrvoid  ficlFree   (void *p);
39182940Sdfrvoid *ficlRealloc(void *p, size_t size);
39282940Sdfr/*
39382940Sdfr** Stub function for dictionary access control - does nothing
39482940Sdfr** by default, user can redefine to guarantee exclusive dict
39582940Sdfr** access to a single thread for updates. All dict update code
39682940Sdfr** must be bracketed as follows:
39782940Sdfr** ficlLockDictionary(TRUE);
39882940Sdfr** <code that updates dictionary>
39982940Sdfr** ficlLockDictionary(FALSE);
40082940Sdfr**
40182940Sdfr** Returns zero if successful, nonzero if unable to acquire lock
40282940Sdfr** before timeout (optional - could also block forever)
40382940Sdfr**
40482940Sdfr** NOTE: this function must be implemented with lock counting
40582940Sdfr** semantics: nested calls must behave properly.
40682940Sdfr*/
40782940Sdfr#if FICL_MULTITHREAD
40882940Sdfrint ficlLockDictionary(short fLock);
40982940Sdfr#else
41082940Sdfr#define ficlLockDictionary(x) 0 /* ignore */
41182940Sdfr#endif
41282940Sdfr
41382940Sdfr/*
41482940Sdfr** 64 bit integer math support routines: multiply two UNS32s
41582940Sdfr** to get a 64 bit product, & divide the product by an UNS32
41682940Sdfr** to get an UNS32 quotient and remainder. Much easier in asm
41782940Sdfr** on a 32 bit CPU than in C, which usually doesn't support
41882940Sdfr** the double length result (but it should).
41982940Sdfr*/
42082940SdfrDPUNS ficlLongMul(FICL_UNS x, FICL_UNS y);
42182940SdfrUNSQR ficlLongDiv(DPUNS    q, FICL_UNS y);
42282940Sdfr
42394290Sdcs
42494290Sdcs/*
42594290Sdcs** FICL_HAVE_FTRUNCATE indicates whether the current OS supports
42694290Sdcs** the ftruncate() function (available on most UNIXes).  This
42794290Sdcs** function is necessary to provide the complete File-Access wordset.
42894290Sdcs*/
42994290Sdcs#if !defined (FICL_HAVE_FTRUNCATE)
43094290Sdcs#define FICL_HAVE_FTRUNCATE 0
43194290Sdcs#endif
43294290Sdcs
43394290Sdcs
43482940Sdfr#endif /*__SYSDEP_H__*/
435