File:  [gforth] / gforth / engine / forth.h
Revision 1.8: download - view: text, annotated - select for diffs
Tue Dec 8 22:03:03 1998 UTC (23 years, 9 months ago) by anton
Branches: MAIN
CVS tags: v0-4-0, HEAD
updated dates in copyright messages
inserted copyright messages in most files that did not have them
removed outdated files engine/32bit.h engine/strsig.c

    1: /* common header file
    2: 
    3:   Copyright (C) 1995,1996,1997,1998 Free Software Foundation, Inc.
    4: 
    5:   This file is part of Gforth.
    6: 
    7:   Gforth is free software; you can redistribute it and/or
    8:   modify it under the terms of the GNU General Public License
    9:   as published by the Free Software Foundation; either version 2
   10:   of the License, or (at your option) any later version.
   11: 
   12:   This program is distributed in the hope that it will be useful,
   13:   but WITHOUT ANY WARRANTY; without even the implied warranty of
   14:   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   15:   GNU General Public License for more details.
   16: 
   17:   You should have received a copy of the GNU General Public License
   18:   along with this program; if not, write to the Free Software
   19:   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
   20: */
   21: 
   22: #include "config.h"
   23: 
   24: #if defined(DOUBLY_INDIRECT)
   25: #  undef DIRECT_THREADED
   26: #  undef INDIRECT_THREADED
   27: #  define INDIRECT_THREADED
   28: #endif
   29: 
   30: #include <limits.h>
   31: 
   32: #if defined(NeXT)
   33: #  include <libc.h>
   34: #endif /* NeXT */
   35: 
   36: /* symbol indexed constants */
   37: 
   38: #define DOCOL	0
   39: #define DOCON	1
   40: #define DOVAR	2
   41: #define DOUSER	3
   42: #define DODEFER	4
   43: #define DOFIELD	5
   44: #define DODOES	6
   45: #define DOESJUMP	7
   46: 
   47: /* the size of the DOESJUMP, which resides between DOES> and the does-code */
   48: #define DOES_HANDLER_SIZE	(2*sizeof(Cell))
   49: 
   50: #include "machine.h"
   51: 
   52: /* Forth data types */
   53: /* Cell and UCell must be the same size as a pointer */
   54: #define CELL_BITS	(sizeof(Cell) * CHAR_BIT)
   55: #define FLAG(b) (-(b))
   56: #define FILEIO(error)	(FLAG(error) & -37)
   57: #define FILEEXIST(error)	(FLAG(error) & -38)
   58: 
   59: #define F_TRUE (FLAG(0==0))
   60: #define F_FALSE (FLAG(0!=0))
   61: 
   62: #ifdef BUGGY_LONG_LONG
   63: typedef struct {
   64:   Cell hi;
   65:   UCell lo;
   66: } DCell;
   67: 
   68: typedef struct {
   69:   UCell hi;
   70:   UCell lo;
   71: } UDCell;
   72: 
   73: #define FETCH_DCELL(d,lo,hi)	((d)=(typeof(d)){(hi),(lo)})
   74: #define STORE_DCELL(d,low,high)	({ \
   75: 				     typeof(d) _d = (d); \
   76: 				     (low) = _d.lo; \
   77: 				     (high)= _d.hi; \
   78: 				 })
   79: 
   80: #define LONG2UD(l)	({UDCell _ud; _ud.hi=0; _ud.lo=(Cell)(l); _ud;})
   81: #define UD2LONG(ud)	((long)(ud.lo))
   82: #define DZERO		((DCell){0,0})
   83: 
   84: #else /* ! defined(BUGGY_LONG_LONG) */
   85: 
   86: /* DCell and UDCell must be twice as large as Cell */
   87: typedef DOUBLE_CELL_TYPE DCell;
   88: typedef unsigned DOUBLE_CELL_TYPE UDCell;
   89: 
   90: typedef union {
   91:   struct {
   92: #ifdef WORDS_BIGENDIAN
   93:     Cell high;
   94:     UCell low;
   95: #else
   96:     UCell low;
   97:     Cell high;
   98: #endif;
   99:   } cells;
  100:   DCell dcell;
  101: } Double_Store;
  102: 
  103: #define FETCH_DCELL(d,lo,hi)	({ \
  104: 				     Double_Store _d; \
  105: 				     _d.cells.low = (lo); \
  106: 				     _d.cells.high = (hi); \
  107: 				     (d) = _d.dcell; \
  108: 				 })
  109: 
  110: #define STORE_DCELL(d,lo,hi)	({ \
  111: 				     Double_Store _d; \
  112: 				     _d.dcell = (d); \
  113: 				     (lo) = _d.cells.low; \
  114: 				     (hi) = _d.cells.high; \
  115: 				 })
  116: 
  117: #define LONG2UD(l)	((UDCell)(l))
  118: #define UD2LONG(ud)	((long)(ud))
  119: #define DZERO		((DCell)0)
  120: 
  121: #endif /* ! defined(BUGGY_LONG_LONG) */
  122: 
  123: #ifdef DIRECT_THREADED
  124: typedef Label Xt;
  125: #else
  126: typedef Label *Xt;
  127: #endif
  128: 
  129: 
  130: #if !defined(DIRECT_THREADED)
  131: /* i.e. indirect threaded our doubly indirect threaded */
  132: /* the direct threaded version is machine dependent and resides in machine.h */
  133: 
  134: /* PFA gives the parameter field address corresponding to a cfa */
  135: #define PFA(cfa)	(((Cell *)cfa)+2)
  136: /* PFA1 is a special version for use just after a NEXT1 */
  137: #define PFA1(cfa)	PFA(cfa)
  138: /* CODE_ADDRESS is the address of the code jumped to through the code field */
  139: #define CODE_ADDRESS(cfa)	(*(Xt)(cfa))
  140: 
  141: /* DOES_CODE is the Forth code does jumps to */
  142: #if !defined(DOUBLY_INDIRECT)
  143: #  define DOES_CA (symbols[DODOES])
  144: #else /* defined(DOUBLY_INDIRECT) */
  145: #  define DOES_CA ((Label)&symbols[DODOES])
  146: #endif /* defined(DOUBLY_INDIRECT) */
  147: 
  148: 
  149: 
  150: #define DOES_CODE(cfa)	({Xt _cfa=(Xt)(cfa); \
  151: 			  (Xt *)(_cfa[0]==DOES_CA ? _cfa[1] : NULL);})
  152: #define DOES_CODE1(cfa)	((Xt *)(cfa[1]))
  153: /* MAKE_CF creates an appropriate code field at the cfa;
  154:    ca is the code address */
  155: #define MAKE_CF(cfa,ca) ((*(Label *)(cfa)) = ((Label)ca))
  156: /* make a code field for a defining-word-defined word */
  157: #define MAKE_DOES_CF(cfa,does_code)  ({MAKE_CF(cfa,DOES_CA);	\
  158: 				       ((Cell *)cfa)[1] = (Cell)(does_code);})
  159: /* the does handler resides between DOES> and the following Forth code */
  160: /* not needed in indirect threaded code */
  161: #if defined(DOUBLY_INDIRECT)
  162: #define MAKE_DOES_HANDLER(addr)	MAKE_CF(addr, ((Label)&symbols[DOESJUMP]))
  163: #else /* !defined(DOUBLY_INDIRECT) */
  164: #define MAKE_DOES_HANDLER(addr)	0
  165: #endif /* !defined(DOUBLY_INDIRECT) */
  166: #endif /* !defined(DIRECT_THREADED) */
  167: 
  168: #ifdef DEBUG
  169: #	define	NAME(string)	fprintf(stderr,"%08lx: "string"\n",(Cell)ip);
  170: #else
  171: #	define	NAME(string)
  172: #endif
  173: 
  174: #define CF(const)	(-const-2)
  175: 
  176: #define CF_NIL	-1
  177: 
  178: #ifndef FLUSH_ICACHE
  179: #warning flush-icache probably will not work (see manual)
  180: #	define FLUSH_ICACHE(addr,size)
  181: #endif
  182: 
  183: #if defined(DIRECT_THREADED)
  184: #define CACHE_FLUSH(addr,size) FLUSH_ICACHE(addr,size)
  185: #else
  186: #define CACHE_FLUSH(addr,size)
  187: #endif
  188: 
  189: #ifdef USE_TOS
  190: #define IF_TOS(x) x
  191: #else
  192: #define IF_TOS(x)
  193: #define TOS (sp[0])
  194: #endif
  195: 
  196: #ifdef USE_FTOS
  197: #define IF_FTOS(x) x
  198: #else
  199: #define IF_FTOS(x)
  200: #define FTOS (fp[0])
  201: #endif
  202: 
  203: Label *engine(Xt *ip, Cell *sp, Cell *rp, Float *fp, Address lp);
  204: Address my_alloc(Cell size);
  205: 
  206: /* dblsub routines */
  207: DCell dnegate(DCell d1);
  208: UDCell ummul (UCell a, UCell b);
  209: DCell mmul (Cell a, Cell b);
  210: UDCell umdiv (UDCell u, UCell v);
  211: DCell smdiv (DCell num, Cell denom);
  212: DCell fmdiv (DCell num, Cell denom);
  213: 
  214: Cell memcasecmp(const Char *s1, const Char *s2, Cell n);
  215: 
  216: extern int offset_image;
  217: extern int die_on_signal;
  218: 
  219: /* declare all the functions that are missing */
  220: #ifndef HAVE_ATANH
  221: extern double atanh(double r1);
  222: extern double asinh(double r1);
  223: extern double acosh(double r1);
  224: #endif
  225: #ifndef HAVE_ECVT
  226: /* extern char* ecvt(double x, int len, int* exp, int* sign);*/
  227: #endif
  228: #ifndef HAVE_MEMMOVE
  229: /* extern char *memmove(char *dest, const char *src, long n); */
  230: #endif
  231: #ifndef HAVE_POW10
  232: extern double pow10(double x);
  233: #endif
  234: #ifndef HAVE_STRERROR
  235: extern char *strerror(int err);
  236: #endif
  237: #ifndef HAVE_STRSIGNAL
  238: extern char *strsignal(int sig);
  239: #endif
  240: #ifndef HAVE_STRTOUL
  241: extern unsigned long int strtoul(const char *nptr, char **endptr, int base);
  242: #endif
  243: 
  244: 

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>