/*******************************************************************1s y s d e p . h2** Forth Inspired Command Language3** Author: John Sadler ([email protected])4** Created: 16 Oct 19975** Ficl system dependent types and prototypes...6**7** Note: Ficl also depends on the use of "assert" when8** FICL_ROBUST is enabled. This may require some consideration9** in firmware systems since assert often10** assumes stderr/stdout.11** $Id: sysdep.h,v 1.11 2001/12/05 07:21:34 jsadler Exp $12*******************************************************************/13/*14** Copyright (c) 1997-2001 John Sadler ([email protected])15** All rights reserved.16**17** Get the latest Ficl release at http://ficl.sourceforge.net18**19** I am interested in hearing from anyone who uses ficl. If you have20** a problem, a success story, a defect, an enhancement request, or21** if you would like to contribute to the ficl release, please22** contact me by email at the address above.23**24** L I C E N S E and D I S C L A I M E R25**26** Redistribution and use in source and binary forms, with or without27** modification, are permitted provided that the following conditions28** are met:29** 1. Redistributions of source code must retain the above copyright30** notice, this list of conditions and the following disclaimer.31** 2. Redistributions in binary form must reproduce the above copyright32** notice, this list of conditions and the following disclaimer in the33** documentation and/or other materials provided with the distribution.34**35** THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND36** ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE37** IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE38** ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE39** FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL40** DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS41** OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)42** HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT43** LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY44** OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF45** SUCH DAMAGE.46*/474849#if !defined (__SYSDEP_H__)50#define __SYSDEP_H__5152#include <sys/types.h>5354#include <stddef.h> /* size_t, NULL */55#include <setjmp.h>56#include <assert.h>5758#if !defined IGNORE /* Macro to silence unused param warnings */59#define IGNORE(x) (void)x60#endif6162/*63** TRUE and FALSE for C boolean operations, and64** portable 32 bit types for CELLs65**66*/67#if !defined TRUE68#define TRUE 169#endif70#if !defined FALSE71#define FALSE 072#endif7374/*75** System dependent data type declarations...76*/77#if !defined INT3278#define INT32 long79#endif8081#if !defined UNS3282#define UNS32 unsigned long83#endif8485#if !defined UNS1686#define UNS16 unsigned short87#endif8889#if !defined UNS890#define UNS8 unsigned char91#endif9293#if !defined NULL94#define NULL ((void *)0)95#endif9697/*98** FICL_UNS and FICL_INT must have the same size as a void* on99** the target system. A CELL is a union of void*, FICL_UNS, and100** FICL_INT.101** (11/2000: same for FICL_FLOAT)102*/103#if !defined FICL_INT104#define FICL_INT INT32105#endif106107#if !defined FICL_UNS108#define FICL_UNS UNS32109#endif110111#if !defined FICL_FLOAT112#define FICL_FLOAT float113#endif114115/*116** Ficl presently supports values of 32 and 64 for BITS_PER_CELL117*/118#if !defined BITS_PER_CELL119#define BITS_PER_CELL 32120#endif121122#if ((BITS_PER_CELL != 32) && (BITS_PER_CELL != 64))123Error!124#endif125126typedef struct127{128FICL_UNS hi;129FICL_UNS lo;130} DPUNS;131132typedef struct133{134FICL_UNS quot;135FICL_UNS rem;136} UNSQR;137138typedef struct139{140FICL_INT hi;141FICL_INT lo;142} DPINT;143144typedef struct145{146FICL_INT quot;147FICL_INT rem;148} INTQR;149150151/*152** B U I L D C O N T R O L S153*/154155#if !defined (FICL_MINIMAL)156#define FICL_MINIMAL 0157#endif158#if (FICL_MINIMAL)159#define FICL_WANT_SOFTWORDS 0160#define FICL_WANT_FILE 0161#define FICL_WANT_FLOAT 0162#define FICL_WANT_USER 0163#define FICL_WANT_LOCALS 0164#define FICL_WANT_DEBUGGER 0165#define FICL_WANT_OOP 0166#define FICL_PLATFORM_EXTEND 0167#define FICL_MULTITHREAD 0168#define FICL_ROBUST 0169#define FICL_EXTENDED_PREFIX 0170#endif171172/*173** FICL_PLATFORM_EXTEND174** Includes words defined in ficlCompilePlatform175*/176#if !defined (FICL_PLATFORM_EXTEND)177#define FICL_PLATFORM_EXTEND 1178#endif179180181/*182** FICL_WANT_FILE183** Includes the FILE and FILE-EXT wordset and associated code. Turn this off if you do not184** have a filesystem!185** Contributed by Larry Hastings186*/187#if !defined (FICL_WANT_FILE)188#define FICL_WANT_FILE 0189#endif190191/*192** FICL_WANT_FLOAT193** Includes a floating point stack for the VM, and words to do float operations.194** Contributed by Guy Carver195*/196#if !defined (FICL_WANT_FLOAT)197#define FICL_WANT_FLOAT 0198#endif199200/*201** FICL_WANT_DEBUGGER202** Inludes a simple source level debugger203*/204#if !defined (FICL_WANT_DEBUGGER)205#define FICL_WANT_DEBUGGER 1206#endif207208/*209** FICL_EXTENDED_PREFIX enables a bunch of extra prefixes in prefix.c and prefix.fr (if210** included as part of softcore.c)211*/212#if !defined FICL_EXTENDED_PREFIX213#define FICL_EXTENDED_PREFIX 0214#endif215216/*217** User variables: per-instance variables bound to the VM.218** Kinda like thread-local storage. Could be implemented in a219** VM private dictionary, but I've chosen the lower overhead220** approach of an array of CELLs instead.221*/222#if !defined FICL_WANT_USER223#define FICL_WANT_USER 1224#endif225226#if !defined FICL_USER_CELLS227#define FICL_USER_CELLS 16228#endif229230/*231** FICL_WANT_LOCALS controls the creation of the LOCALS wordset and232** a private dictionary for local variable compilation.233*/234#if !defined FICL_WANT_LOCALS235#define FICL_WANT_LOCALS 1236#endif237238/* Max number of local variables per definition */239#if !defined FICL_MAX_LOCALS240#define FICL_MAX_LOCALS 16241#endif242243/*244** FICL_WANT_OOP245** Inludes object oriented programming support (in softwords)246** OOP support requires locals and user variables!247*/248#if !(FICL_WANT_LOCALS) || !(FICL_WANT_USER)249#if !defined (FICL_WANT_OOP)250#define FICL_WANT_OOP 0251#endif252#endif253254#if !defined (FICL_WANT_OOP)255#define FICL_WANT_OOP 1256#endif257258/*259** FICL_WANT_SOFTWORDS260** Controls inclusion of all softwords in softcore.c261*/262#if !defined (FICL_WANT_SOFTWORDS)263#define FICL_WANT_SOFTWORDS 1264#endif265266/*267** FICL_MULTITHREAD enables dictionary mutual exclusion268** wia the ficlLockDictionary system dependent function.269** Note: this implementation is experimental and poorly270** tested. Further, it's unnecessary unless you really271** intend to have multiple SESSIONS (poor choice of name272** on my part) - that is, threads that modify the dictionary273** at the same time.274*/275#if !defined FICL_MULTITHREAD276#define FICL_MULTITHREAD 0277#endif278279/*280** PORTABLE_LONGMULDIV causes ficlLongMul and ficlLongDiv to be281** defined in C in sysdep.c. Use this if you cannot easily282** generate an inline asm definition283*/284#if !defined (PORTABLE_LONGMULDIV)285#define PORTABLE_LONGMULDIV 0286#endif287288/*289** INLINE_INNER_LOOP causes the inner interpreter to be inline code290** instead of a function call. This is mainly because MS VC++ 5291** chokes with an internal compiler error on the function version.292** in release mode. Sheesh.293*/294#if !defined INLINE_INNER_LOOP295#if defined _DEBUG296#define INLINE_INNER_LOOP 0297#else298#define INLINE_INNER_LOOP 1299#endif300#endif301302/*303** FICL_ROBUST enables bounds checking of stacks and the dictionary.304** This will detect stack over and underflows and dictionary overflows.305** Any exceptional condition will result in an assertion failure.306** (As generated by the ANSI assert macro)307** FICL_ROBUST == 1 --> stack checking in the outer interpreter308** FICL_ROBUST == 2 also enables checking in many primitives309*/310311#if !defined FICL_ROBUST312#define FICL_ROBUST 2313#endif314315/*316** FICL_DEFAULT_STACK Specifies the default size (in CELLs) of317** a new virtual machine's stacks, unless overridden at318** create time.319*/320#if !defined FICL_DEFAULT_STACK321#define FICL_DEFAULT_STACK 128322#endif323324/*325** FICL_DEFAULT_DICT specifies the number of CELLs to allocate326** for the system dictionary by default. The value327** can be overridden at startup time as well.328** FICL_DEFAULT_ENV specifies the number of cells to allot329** for the environment-query dictionary.330*/331#if !defined FICL_DEFAULT_DICT332#define FICL_DEFAULT_DICT 12288333#endif334335#if !defined FICL_DEFAULT_ENV336#define FICL_DEFAULT_ENV 260337#endif338339/*340** FICL_DEFAULT_VOCS specifies the maximum number of wordlists in341** the dictionary search order. See Forth DPANS sec 16.3.3342** (file://dpans16.htm#16.3.3)343*/344#if !defined FICL_DEFAULT_VOCS345#define FICL_DEFAULT_VOCS 16346#endif347348/*349** FICL_MAX_PARSE_STEPS controls the size of an array in the FICL_SYSTEM structure350** that stores pointers to parser extension functions. I would never expect to have351** more than 8 of these, so that's the default limit. Too many of these functions352** will probably exact a nasty performance penalty.353*/354#if !defined FICL_MAX_PARSE_STEPS355#define FICL_MAX_PARSE_STEPS 8356#endif357358/*359** FICL_ALIGN is the power of two to which the dictionary360** pointer address must be aligned. This value is usually361** either 1 or 2, depending on the memory architecture362** of the target system; 2 is safe on any 16 or 32 bit363** machine. 3 would be appropriate for a 64 bit machine.364*/365#if !defined FICL_ALIGN366#define FICL_ALIGN 2367#define FICL_ALIGN_ADD ((1 << FICL_ALIGN) - 1)368#endif369370/*371** System dependent routines --372** edit the implementations in sysdep.c to be compatible373** with your runtime environment...374** ficlTextOut sends a NULL terminated string to the375** default output device - used for system error messages376** ficlMalloc and ficlFree have the same semantics as malloc and free377** in standard C378** ficlLongMul multiplies two UNS32s and returns a 64 bit unsigned379** product380** ficlLongDiv divides an UNS64 by an UNS32 and returns UNS32 quotient381** and remainder382*/383struct vm;384void ficlTextOut(struct vm *pVM, char *msg, int fNewline);385void *ficlMalloc (size_t size);386void ficlFree (void *p);387void *ficlRealloc(void *p, size_t size);388/*389** Stub function for dictionary access control - does nothing390** by default, user can redefine to guarantee exclusive dict391** access to a single thread for updates. All dict update code392** must be bracketed as follows:393** ficlLockDictionary(TRUE);394** <code that updates dictionary>395** ficlLockDictionary(FALSE);396**397** Returns zero if successful, nonzero if unable to acquire lock398** before timeout (optional - could also block forever)399**400** NOTE: this function must be implemented with lock counting401** semantics: nested calls must behave properly.402*/403#if FICL_MULTITHREAD404int ficlLockDictionary(short fLock);405#else406#define ficlLockDictionary(x) /* ignore */407#endif408409/*410** 64 bit integer math support routines: multiply two UNS32s411** to get a 64 bit product, & divide the product by an UNS32412** to get an UNS32 quotient and remainder. Much easier in asm413** on a 32 bit CPU than in C, which usually doesn't support414** the double length result (but it should).415*/416DPUNS ficlLongMul(FICL_UNS x, FICL_UNS y);417UNSQR ficlLongDiv(DPUNS q, FICL_UNS y);418419420/*421** FICL_HAVE_FTRUNCATE indicates whether the current OS supports422** the ftruncate() function (available on most UNIXes). This423** function is necessary to provide the complete File-Access wordset.424*/425#if !defined (FICL_HAVE_FTRUNCATE)426#define FICL_HAVE_FTRUNCATE 0427#endif428429430#endif /*__SYSDEP_H__*/431432433