1188824Simp/******************************************************************* 2188824Simp s y s d e p . h 3188824Simp** Forth Inspired Command Language 4188824Simp** Author: John Sadler (john_sadler@alum.mit.edu) 5188824Simp** Created: 16 Oct 1997 6188824Simp** Ficl system dependent types and prototypes... 7188824Simp** 8188824Simp** Note: Ficl also depends on the use of "assert" when 9188824Simp** FICL_ROBUST is enabled. This may require some consideration 10188824Simp** in firmware systems since assert often 11188824Simp** assumes stderr/stdout. 12188824Simp** $Id: sysdep.h,v 1.6 2001-04-26 21:41:55-07 jsadler Exp jsadler $ 13188824Simp*******************************************************************/ 14188824Simp/* 15188824Simp** Copyright (c) 1997-2001 John Sadler (john_sadler@alum.mit.edu) 16188824Simp** All rights reserved. 17188824Simp** 18188824Simp** Get the latest Ficl release at http://ficl.sourceforge.net 19188824Simp** 20188824Simp** L I C E N S E and D I S C L A I M E R 21188824Simp** 22188824Simp** Redistribution and use in source and binary forms, with or without 23188824Simp** modification, are permitted provided that the following conditions 24188824Simp** are met: 25188824Simp** 1. Redistributions of source code must retain the above copyright 26188824Simp** notice, this list of conditions and the following disclaimer. 27188824Simp** 2. Redistributions in binary form must reproduce the above copyright 28188824Simp** notice, this list of conditions and the following disclaimer in the 29188824Simp** documentation and/or other materials provided with the distribution. 30188824Simp** 31188824Simp** THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 32188824Simp** ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 33188824Simp** IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 34188824Simp** ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 35188824Simp** FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 36188824Simp** DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 37188824Simp** OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 38188824Simp** HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 39188824Simp** LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 40188824Simp** OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 41188824Simp** SUCH DAMAGE. 42188824Simp** 43188824Simp** I am interested in hearing from anyone who uses ficl. If you have 44188824Simp** a problem, a success story, a defect, an enhancement request, or 45188824Simp** if you would like to contribute to the ficl release, please send 46188824Simp** contact me by email at the address above. 47188824Simp** 48188824Simp** $Id: sysdep.h,v 1.6 2001-04-26 21:41:55-07 jsadler Exp jsadler $ 49188824Simp** $FreeBSD: stable/11/stand/ficl/mips64/sysdep.h 262402 2014-02-23 22:10:25Z rwatson $ 50188824Simp*/ 51188824Simp 52188824Simp#if !defined (__SYSDEP_H__) 53188824Simp#define __SYSDEP_H__ 54188824Simp 55188824Simp#include <sys/types.h> 56188824Simp 57188824Simp#include <stddef.h> /* size_t, NULL */ 58188824Simp#include <setjmp.h> 59188824Simp#include <assert.h> 60188824Simp 61188824Simp#if !defined IGNORE /* Macro to silence unused param warnings */ 62188824Simp#define IGNORE(x) &x 63188824Simp#endif 64188824Simp 65188824Simp/* 66188824Simp** TRUE and FALSE for C boolean operations, and 67188824Simp** portable 32 bit types for CELLs 68188824Simp** 69188824Simp*/ 70188824Simp#if !defined TRUE 71188824Simp#define TRUE 1 72188824Simp#endif 73188824Simp#if !defined FALSE 74188824Simp#define FALSE 0 75188824Simp#endif 76188824Simp 77188824Simp 78188824Simp/* 79188824Simp** System dependent data type declarations... 80188824Simp*/ 81188824Simp#if !defined INT32 82188824Simp#define INT32 int 83188824Simp#endif 84188824Simp 85188824Simp#if !defined UNS32 86188824Simp#define UNS32 unsigned int 87188824Simp#endif 88188824Simp 89188824Simp#if !defined UNS16 90188824Simp#define UNS16 unsigned short 91188824Simp#endif 92188824Simp 93188824Simp#if !defined UNS8 94188824Simp#define UNS8 unsigned char 95188824Simp#endif 96188824Simp 97188824Simp#if !defined NULL 98188824Simp#define NULL ((void *)0) 99188824Simp#endif 100188824Simp 101188824Simp/* 102188824Simp** FICL_UNS and FICL_INT must have the same size as a void* on 103188824Simp** the target system. A CELL is a union of void*, FICL_UNS, and 104188824Simp** FICL_INT. 105188824Simp** (11/2000: same for FICL_FLOAT) 106188824Simp*/ 107188824Simp#if !defined FICL_INT 108262402Srwatson#define FICL_INT long 109188824Simp#endif 110188824Simp 111188824Simp#if !defined FICL_UNS 112262402Srwatson#define FICL_UNS unsigned long 113188824Simp#endif 114188824Simp 115188824Simp#if !defined FICL_FLOAT 116188824Simp#define FICL_FLOAT float 117188824Simp#endif 118188824Simp 119188824Simp/* 120188824Simp** Ficl presently supports values of 32 and 64 for BITS_PER_CELL 121188824Simp*/ 122188824Simp#if !defined BITS_PER_CELL 123262402Srwatson#define BITS_PER_CELL 64 124188824Simp#endif 125188824Simp 126188824Simp#if ((BITS_PER_CELL != 32) && (BITS_PER_CELL != 64)) 127188824Simp Error! 128188824Simp#endif 129188824Simp 130188824Simptypedef struct 131188824Simp{ 132188824Simp FICL_UNS hi; 133188824Simp FICL_UNS lo; 134188824Simp} DPUNS; 135188824Simp 136188824Simptypedef struct 137188824Simp{ 138188824Simp FICL_UNS quot; 139188824Simp FICL_UNS rem; 140188824Simp} UNSQR; 141188824Simp 142188824Simptypedef struct 143188824Simp{ 144188824Simp FICL_INT hi; 145188824Simp FICL_INT lo; 146188824Simp} DPINT; 147188824Simp 148188824Simptypedef struct 149188824Simp{ 150188824Simp FICL_INT quot; 151188824Simp FICL_INT rem; 152188824Simp} INTQR; 153188824Simp 154188824Simp 155188824Simp/* 156188824Simp** B U I L D C O N T R O L S 157188824Simp*/ 158188824Simp 159188824Simp#if !defined (FICL_MINIMAL) 160188824Simp#define FICL_MINIMAL 0 161188824Simp#endif 162188824Simp#if (FICL_MINIMAL) 163188824Simp#define FICL_WANT_SOFTWORDS 0 164188824Simp#define FICL_WANT_FILE 0 165188824Simp#define FICL_WANT_FLOAT 0 166188824Simp#define FICL_WANT_USER 0 167188824Simp#define FICL_WANT_LOCALS 0 168188824Simp#define FICL_WANT_DEBUGGER 0 169188824Simp#define FICL_WANT_OOP 0 170188824Simp#define FICL_PLATFORM_EXTEND 0 171188824Simp#define FICL_MULTITHREAD 0 172188824Simp#define FICL_ROBUST 1 173188824Simp#define FICL_EXTENDED_PREFIX 0 174188824Simp#endif 175188824Simp 176188824Simp/* 177188824Simp** FICL_PLATFORM_EXTEND 178188824Simp** Includes words defined in ficlCompilePlatform 179188824Simp*/ 180188824Simp#if !defined (FICL_PLATFORM_EXTEND) 181188824Simp#define FICL_PLATFORM_EXTEND 1 182188824Simp#endif 183188824Simp 184188824Simp/* 185188824Simp** FICL_WANT_FILE 186188824Simp** Includes the FILE and FILE-EXT wordset and associated code. Turn this off if you do not 187188824Simp** have a filesystem! 188188824Simp** Contributed by Larry Hastings 189188824Simp*/ 190188824Simp#if !defined (FICL_WANT_FILE) 191188824Simp#define FICL_WANT_FILE 0 192188824Simp#endif 193188824Simp 194188824Simp/* 195188824Simp** FICL_WANT_FLOAT 196188824Simp** Includes a floating point stack for the VM, and words to do float operations. 197188824Simp** Contributed by Guy Carver 198188824Simp*/ 199188824Simp#if !defined (FICL_WANT_FLOAT) 200188824Simp#define FICL_WANT_FLOAT 0 201188824Simp#endif 202188824Simp 203188824Simp/* 204188824Simp** FICL_WANT_DEBUGGER 205188824Simp** Inludes a simple source level debugger 206188824Simp*/ 207188824Simp#if !defined (FICL_WANT_DEBUGGER) 208188824Simp#define FICL_WANT_DEBUGGER 1 209188824Simp#endif 210188824Simp 211188824Simp/* 212188824Simp** User variables: per-instance variables bound to the VM. 213188824Simp** Kinda like thread-local storage. Could be implemented in a 214188824Simp** VM private dictionary, but I've chosen the lower overhead 215188824Simp** approach of an array of CELLs instead. 216188824Simp*/ 217188824Simp#if !defined FICL_WANT_USER 218188824Simp#define FICL_WANT_USER 1 219188824Simp#endif 220188824Simp 221188824Simp#if !defined FICL_USER_CELLS 222188824Simp#define FICL_USER_CELLS 16 223188824Simp#endif 224188824Simp 225188824Simp/* 226188824Simp** FICL_WANT_LOCALS controls the creation of the LOCALS wordset and 227188824Simp** a private dictionary for local variable compilation. 228188824Simp*/ 229188824Simp#if !defined FICL_WANT_LOCALS 230188824Simp#define FICL_WANT_LOCALS 1 231188824Simp#endif 232188824Simp 233188824Simp/* Max number of local variables per definition */ 234188824Simp#if !defined FICL_MAX_LOCALS 235188824Simp#define FICL_MAX_LOCALS 16 236188824Simp#endif 237188824Simp 238188824Simp/* 239188824Simp** FICL_WANT_OOP 240188824Simp** Inludes object oriented programming support (in softwords) 241188824Simp** OOP support requires locals and user variables! 242188824Simp*/ 243188824Simp#if !(FICL_WANT_LOCALS) || !(FICL_WANT_USER) 244188824Simp#if !defined (FICL_WANT_OOP) 245188824Simp#define FICL_WANT_OOP 0 246188824Simp#endif 247188824Simp#endif 248188824Simp 249188824Simp#if !defined (FICL_WANT_OOP) 250188824Simp#define FICL_WANT_OOP 1 251188824Simp#endif 252188824Simp 253188824Simp/* 254188824Simp** FICL_WANT_SOFTWORDS 255188824Simp** Controls inclusion of all softwords in softcore.c 256188824Simp*/ 257188824Simp#if !defined (FICL_WANT_SOFTWORDS) 258188824Simp#define FICL_WANT_SOFTWORDS 1 259188824Simp#endif 260188824Simp 261188824Simp/* 262188824Simp** FICL_MULTITHREAD enables dictionary mutual exclusion 263188824Simp** wia the ficlLockDictionary system dependent function. 264188824Simp** Note: this implementation is experimental and poorly 265188824Simp** tested. Further, it's unnecessary unless you really 266188824Simp** intend to have multiple SESSIONS (poor choice of name 267188824Simp** on my part) - that is, threads that modify the dictionary 268188824Simp** at the same time. 269188824Simp*/ 270188824Simp#if !defined FICL_MULTITHREAD 271188824Simp#define FICL_MULTITHREAD 0 272188824Simp#endif 273188824Simp 274188824Simp/* 275188824Simp** PORTABLE_LONGMULDIV causes ficlLongMul and ficlLongDiv to be 276188824Simp** defined in C in sysdep.c. Use this if you cannot easily 277188824Simp** generate an inline asm definition 278188824Simp*/ 279188824Simp#if !defined (PORTABLE_LONGMULDIV) 280188824Simp#define PORTABLE_LONGMULDIV 0 281188824Simp#endif 282188824Simp 283188824Simp/* 284188824Simp** INLINE_INNER_LOOP causes the inner interpreter to be inline code 285188824Simp** instead of a function call. This is mainly because MS VC++ 5 286188824Simp** chokes with an internal compiler error on the function version. 287188824Simp** in release mode. Sheesh. 288188824Simp*/ 289188824Simp#if !defined INLINE_INNER_LOOP 290188824Simp#if defined _DEBUG 291188824Simp#define INLINE_INNER_LOOP 0 292188824Simp#else 293188824Simp#define INLINE_INNER_LOOP 1 294188824Simp#endif 295188824Simp#endif 296188824Simp 297188824Simp/* 298188824Simp** FICL_ROBUST enables bounds checking of stacks and the dictionary. 299188824Simp** This will detect stack over and underflows and dictionary overflows. 300188824Simp** Any exceptional condition will result in an assertion failure. 301188824Simp** (As generated by the ANSI assert macro) 302188824Simp** FICL_ROBUST == 1 --> stack checking in the outer interpreter 303188824Simp** FICL_ROBUST == 2 also enables checking in many primitives 304188824Simp*/ 305188824Simp 306188824Simp#if !defined FICL_ROBUST 307188824Simp#define FICL_ROBUST 2 308188824Simp#endif 309188824Simp 310188824Simp/* 311188824Simp** FICL_DEFAULT_STACK Specifies the default size (in CELLs) of 312188824Simp** a new virtual machine's stacks, unless overridden at 313188824Simp** create time. 314188824Simp*/ 315188824Simp#if !defined FICL_DEFAULT_STACK 316188824Simp#define FICL_DEFAULT_STACK 128 317188824Simp#endif 318188824Simp 319188824Simp/* 320188824Simp** FICL_DEFAULT_DICT specifies the number of CELLs to allocate 321188824Simp** for the system dictionary by default. The value 322188824Simp** can be overridden at startup time as well. 323188824Simp** FICL_DEFAULT_ENV specifies the number of cells to allot 324188824Simp** for the environment-query dictionary. 325188824Simp*/ 326188824Simp#if !defined FICL_DEFAULT_DICT 327188824Simp#define FICL_DEFAULT_DICT 12288 328188824Simp#endif 329188824Simp 330188824Simp#if !defined FICL_DEFAULT_ENV 331188824Simp#define FICL_DEFAULT_ENV 260 332188824Simp#endif 333188824Simp 334188824Simp/* 335188824Simp** FICL_DEFAULT_VOCS specifies the maximum number of wordlists in 336188824Simp** the dictionary search order. See Forth DPANS sec 16.3.3 337188824Simp** (file://dpans16.htm#16.3.3) 338188824Simp*/ 339188824Simp#if !defined FICL_DEFAULT_VOCS 340188824Simp#define FICL_DEFAULT_VOCS 16 341188824Simp#endif 342188824Simp 343188824Simp/* 344188824Simp** FICL_MAX_PARSE_STEPS controls the size of an array in the FICL_SYSTEM structure 345188824Simp** that stores pointers to parser extension functions. I would never expect to have 346188824Simp** more than 8 of these, so that's the default limit. Too many of these functions 347188824Simp** will probably exact a nasty performance penalty. 348188824Simp*/ 349188824Simp#if !defined FICL_MAX_PARSE_STEPS 350188824Simp#define FICL_MAX_PARSE_STEPS 8 351188824Simp#endif 352188824Simp 353188824Simp/* 354188824Simp** FICL_EXTENDED_PREFIX enables a bunch of extra prefixes in prefix.c and prefix.fr (if 355188824Simp** included as part of softcore.c) 356188824Simp*/ 357188824Simp#if !defined FICL_EXTENDED_PREFIX 358188824Simp#define FICL_EXTENDED_PREFIX 0 359188824Simp#endif 360188824Simp 361188824Simp/* 362188824Simp** FICL_ALIGN is the power of two to which the dictionary 363188824Simp** pointer address must be aligned. This value is usually 364188824Simp** either 1 or 2, depending on the memory architecture 365188824Simp** of the target system; 2 is safe on any 16 or 32 bit 366188824Simp** machine. 3 would be appropriate for a 64 bit machine. 367188824Simp*/ 368188824Simp#if !defined FICL_ALIGN 369262402Srwatson#define FICL_ALIGN 3 370188824Simp#define FICL_ALIGN_ADD ((1 << FICL_ALIGN) - 1) 371188824Simp#endif 372188824Simp 373188824Simp/* 374188824Simp** System dependent routines -- 375188824Simp** edit the implementations in sysdep.c to be compatible 376188824Simp** with your runtime environment... 377188824Simp** ficlTextOut sends a NULL terminated string to the 378188824Simp** default output device - used for system error messages 379188824Simp** ficlMalloc and ficlFree have the same semantics as malloc and free 380188824Simp** in standard C 381188824Simp** ficlLongMul multiplies two UNS32s and returns a 64 bit unsigned 382188824Simp** product 383188824Simp** ficlLongDiv divides an UNS64 by an UNS32 and returns UNS32 quotient 384188824Simp** and remainder 385188824Simp*/ 386188824Simpstruct vm; 387188824Simpvoid ficlTextOut(struct vm *pVM, char *msg, int fNewline); 388188824Simpvoid *ficlMalloc (size_t size); 389188824Simpvoid ficlFree (void *p); 390188824Simpvoid *ficlRealloc(void *p, size_t size); 391188824Simp/* 392188824Simp** Stub function for dictionary access control - does nothing 393188824Simp** by default, user can redefine to guarantee exclusive dict 394188824Simp** access to a single thread for updates. All dict update code 395188824Simp** must be bracketed as follows: 396188824Simp** ficlLockDictionary(TRUE); 397188824Simp** <code that updates dictionary> 398188824Simp** ficlLockDictionary(FALSE); 399188824Simp** 400188824Simp** Returns zero if successful, nonzero if unable to acquire lock 401188824Simp** before timeout (optional - could also block forever) 402188824Simp** 403188824Simp** NOTE: this function must be implemented with lock counting 404188824Simp** semantics: nested calls must behave properly. 405188824Simp*/ 406188824Simp#if FICL_MULTITHREAD 407188824Simpint ficlLockDictionary(short fLock); 408188824Simp#else 409188824Simp#define ficlLockDictionary(x) 0 /* ignore */ 410188824Simp#endif 411188824Simp 412188824Simp/* 413188824Simp** 64 bit integer math support routines: multiply two UNS32s 414188824Simp** to get a 64 bit product, & divide the product by an UNS32 415188824Simp** to get an UNS32 quotient and remainder. Much easier in asm 416188824Simp** on a 32 bit CPU than in C, which usually doesn't support 417188824Simp** the double length result (but it should). 418188824Simp*/ 419188824SimpDPUNS ficlLongMul(FICL_UNS x, FICL_UNS y); 420188824SimpUNSQR ficlLongDiv(DPUNS q, FICL_UNS y); 421188824Simp 422188824Simp/* 423188824Simp** FICL_HAVE_FTRUNCATE indicates whether the current OS supports 424188824Simp** the ftruncate() function (available on most UNIXes). This 425188824Simp** function is necessary to provide the complete File-Access wordset. 426188824Simp*/ 427188824Simp#if !defined (FICL_HAVE_FTRUNCATE) 428188824Simp#define FICL_HAVE_FTRUNCATE 0 429188824Simp#endif 430188824Simp 431188824Simp 432188824Simp#endif /*__SYSDEP_H__*/ 433