/*******************************************************************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**47** $Id: sysdep.h,v 1.6 2001-04-26 21:41:55-07 jsadler Exp jsadler $48*/495051#if !defined (__SYSDEP_H__)52#define __SYSDEP_H__5354#include <sys/types.h>5556#include <stddef.h> /* size_t, NULL */57#include <setjmp.h>58#include <assert.h>5960#if !defined IGNORE /* Macro to silence unused param warnings */61#define IGNORE(x) &x62#endif6364/*65** TRUE and FALSE for C boolean operations, and66** portable 32 bit types for CELLs67**68*/69#if !defined TRUE70#define TRUE 171#endif72#if !defined FALSE73#define FALSE 074#endif7576/*77** System dependent data type declarations...78*/79#if !defined INT3280#define INT32 int81#endif8283#if !defined UNS3284#define UNS32 unsigned int85#endif8687#if !defined UNS1688#define UNS16 unsigned short89#endif9091#if !defined UNS892#define UNS8 unsigned char93#endif9495#if !defined NULL96#define NULL ((void *)0)97#endif9899/*100** FICL_UNS and FICL_INT must have the same size as a void* on101** the target system. A CELL is a union of void*, FICL_UNS, and102** FICL_INT.103** (11/2000: same for FICL_FLOAT)104*/105#if !defined FICL_INT106#define FICL_INT long107#endif108109#if !defined FICL_UNS110#define FICL_UNS unsigned long111#endif112113#if !defined FICL_FLOAT114#define FICL_FLOAT float115#endif116117/*118** Ficl presently supports values of 32 and 64 for BITS_PER_CELL119*/120#if !defined BITS_PER_CELL121#define BITS_PER_CELL 64122#endif123124#if ((BITS_PER_CELL != 32) && (BITS_PER_CELL != 64))125Error!126#endif127128typedef struct129{130FICL_UNS hi;131FICL_UNS lo;132} DPUNS;133134typedef struct135{136FICL_UNS quot;137FICL_UNS rem;138} UNSQR;139140typedef struct141{142FICL_INT hi;143FICL_INT lo;144} DPINT;145146typedef struct147{148FICL_INT quot;149FICL_INT rem;150} INTQR;151152153/*154** B U I L D C O N T R O L S155*/156157#if !defined (FICL_MINIMAL)158#define FICL_MINIMAL 0159#endif160#if (FICL_MINIMAL)161#define FICL_WANT_SOFTWORDS 0162#define FICL_WANT_FILE 0163#define FICL_WANT_FLOAT 0164#define FICL_WANT_USER 0165#define FICL_WANT_LOCALS 0166#define FICL_WANT_DEBUGGER 0167#define FICL_WANT_OOP 0168#define FICL_PLATFORM_EXTEND 0169#define FICL_MULTITHREAD 0170#define FICL_ROBUST 0171#define FICL_EXTENDED_PREFIX 0172#endif173174/*175** FICL_PLATFORM_EXTEND176** Includes words defined in ficlCompilePlatform177*/178#if !defined (FICL_PLATFORM_EXTEND)179#define FICL_PLATFORM_EXTEND 1180#endif181182183/*184** FICL_WANT_FILE185** Includes the FILE and FILE-EXT wordset and associated code. Turn this off if you do not186** have a filesystem!187** Contributed by Larry Hastings188*/189#if !defined (FICL_WANT_FILE)190#define FICL_WANT_FILE 0191#endif192193/*194** FICL_WANT_FLOAT195** Includes a floating point stack for the VM, and words to do float operations.196** Contributed by Guy Carver197*/198#if !defined (FICL_WANT_FLOAT)199#define FICL_WANT_FLOAT 0200#endif201202/*203** FICL_WANT_DEBUGGER204** Inludes a simple source level debugger205*/206#if !defined (FICL_WANT_DEBUGGER)207#define FICL_WANT_DEBUGGER 1208#endif209210/*211** FICL_EXTENDED_PREFIX enables a bunch of extra prefixes in prefix.c and prefix.fr (if212** included as part of softcore.c)213*/214#if !defined FICL_EXTENDED_PREFIX215#define FICL_EXTENDED_PREFIX 0216#endif217218/*219** User variables: per-instance variables bound to the VM.220** Kinda like thread-local storage. Could be implemented in a221** VM private dictionary, but I've chosen the lower overhead222** approach of an array of CELLs instead.223*/224#if !defined FICL_WANT_USER225#define FICL_WANT_USER 1226#endif227228#if !defined FICL_USER_CELLS229#define FICL_USER_CELLS 16230#endif231232/*233** FICL_WANT_LOCALS controls the creation of the LOCALS wordset and234** a private dictionary for local variable compilation.235*/236#if !defined FICL_WANT_LOCALS237#define FICL_WANT_LOCALS 1238#endif239240/* Max number of local variables per definition */241#if !defined FICL_MAX_LOCALS242#define FICL_MAX_LOCALS 16243#endif244245/*246** FICL_WANT_OOP247** Inludes object oriented programming support (in softwords)248** OOP support requires locals and user variables!249*/250#if !(FICL_WANT_LOCALS) || !(FICL_WANT_USER)251#if !defined (FICL_WANT_OOP)252#define FICL_WANT_OOP 0253#endif254#endif255256#if !defined (FICL_WANT_OOP)257#define FICL_WANT_OOP 1258#endif259260/*261** FICL_WANT_SOFTWORDS262** Controls inclusion of all softwords in softcore.c263*/264#if !defined (FICL_WANT_SOFTWORDS)265#define FICL_WANT_SOFTWORDS 1266#endif267268/*269** FICL_MULTITHREAD enables dictionary mutual exclusion270** wia the ficlLockDictionary system dependent function.271** Note: this implementation is experimental and poorly272** tested. Further, it's unnecessary unless you really273** intend to have multiple SESSIONS (poor choice of name274** on my part) - that is, threads that modify the dictionary275** at the same time.276*/277#if !defined FICL_MULTITHREAD278#define FICL_MULTITHREAD 0279#endif280281/*282** PORTABLE_LONGMULDIV causes ficlLongMul and ficlLongDiv to be283** defined in C in sysdep.c. Use this if you cannot easily284** generate an inline asm definition285*/286#if !defined (PORTABLE_LONGMULDIV)287#define PORTABLE_LONGMULDIV 0288#endif289290/*291** INLINE_INNER_LOOP causes the inner interpreter to be inline code292** instead of a function call. This is mainly because MS VC++ 5293** chokes with an internal compiler error on the function version.294** in release mode. Sheesh.295*/296#if !defined INLINE_INNER_LOOP297#if defined _DEBUG298#define INLINE_INNER_LOOP 0299#else300#define INLINE_INNER_LOOP 1301#endif302#endif303304/*305** FICL_ROBUST enables bounds checking of stacks and the dictionary.306** This will detect stack over and underflows and dictionary overflows.307** Any exceptional condition will result in an assertion failure.308** (As generated by the ANSI assert macro)309** FICL_ROBUST == 1 --> stack checking in the outer interpreter310** FICL_ROBUST == 2 also enables checking in many primitives311*/312313#if !defined FICL_ROBUST314#define FICL_ROBUST 2315#endif316317/*318** FICL_DEFAULT_STACK Specifies the default size (in CELLs) of319** a new virtual machine's stacks, unless overridden at320** create time.321*/322#if !defined FICL_DEFAULT_STACK323#define FICL_DEFAULT_STACK 128324#endif325326/*327** FICL_DEFAULT_DICT specifies the number of CELLs to allocate328** for the system dictionary by default. The value329** can be overridden at startup time as well.330** FICL_DEFAULT_ENV specifies the number of cells to allot331** for the environment-query dictionary.332*/333#if !defined FICL_DEFAULT_DICT334#define FICL_DEFAULT_DICT 12288335#endif336337#if !defined FICL_DEFAULT_ENV338#define FICL_DEFAULT_ENV 260339#endif340341/*342** FICL_DEFAULT_VOCS specifies the maximum number of wordlists in343** the dictionary search order. See Forth DPANS sec 16.3.3344** (file://dpans16.htm#16.3.3)345*/346#if !defined FICL_DEFAULT_VOCS347#define FICL_DEFAULT_VOCS 16348#endif349350/*351** FICL_MAX_PARSE_STEPS controls the size of an array in the FICL_SYSTEM structure352** that stores pointers to parser extension functions. I would never expect to have353** more than 8 of these, so that's the default limit. Too many of these functions354** will probably exact a nasty performance penalty.355*/356#if !defined FICL_MAX_PARSE_STEPS357#define FICL_MAX_PARSE_STEPS 8358#endif359360/*361** FICL_ALIGN is the power of two to which the dictionary362** pointer address must be aligned. This value is usually363** either 1 or 2, depending on the memory architecture364** of the target system; 2 is safe on any 16 or 32 bit365** machine. 3 would be appropriate for a 64 bit machine.366*/367#if !defined FICL_ALIGN368#define FICL_ALIGN 3369#define FICL_ALIGN_ADD ((1 << FICL_ALIGN) - 1)370#endif371372/*373** System dependent routines --374** edit the implementations in sysdep.c to be compatible375** with your runtime environment...376** ficlTextOut sends a NULL terminated string to the377** default output device - used for system error messages378** ficlMalloc and ficlFree have the same semantics as malloc and free379** in standard C380** ficlLongMul multiplies two UNS32s and returns a 64 bit unsigned381** product382** ficlLongDiv divides an UNS64 by an UNS32 and returns UNS32 quotient383** and remainder384*/385struct vm;386void ficlTextOut(struct vm *pVM, char *msg, int fNewline);387void *ficlMalloc (size_t size);388void ficlFree (void *p);389void *ficlRealloc(void *p, size_t size);390/*391** Stub function for dictionary access control - does nothing392** by default, user can redefine to guarantee exclusive dict393** access to a single thread for updates. All dict update code394** must be bracketed as follows:395** ficlLockDictionary(TRUE);396** <code that updates dictionary>397** ficlLockDictionary(FALSE);398**399** Returns zero if successful, nonzero if unable to acquire lock400** before timeout (optional - could also block forever)401**402** NOTE: this function must be implemented with lock counting403** semantics: nested calls must behave properly.404*/405#if FICL_MULTITHREAD406int ficlLockDictionary(short fLock);407#else408#define ficlLockDictionary(x) 0 /* ignore */409#endif410411/*412** 64 bit integer math support routines: multiply two UNS32s413** to get a 64 bit product, & divide the product by an UNS32414** to get an UNS32 quotient and remainder. Much easier in asm415** on a 32 bit CPU than in C, which usually doesn't support416** the double length result (but it should).417*/418DPUNS ficlLongMul(FICL_UNS x, FICL_UNS y);419UNSQR ficlLongDiv(DPUNS q, FICL_UNS y);420421422/*423** FICL_HAVE_FTRUNCATE indicates whether the current OS supports424** the ftruncate() function (available on most UNIXes). This425** function is necessary to provide the complete File-Access wordset.426*/427#if !defined (FICL_HAVE_FTRUNCATE)428#define FICL_HAVE_FTRUNCATE 0429#endif430431432#endif /*__SYSDEP_H__*/433434435