File:  [gforth] / gforth / Attic / forth.h
Revision 1.28: download - view: text, annotated - select for diffs
Tue Mar 4 17:49:48 1997 UTC (22 years, 4 months ago) by anton
Branches: MAIN
CVS tags: v0-3-0, HEAD
added double indirect threaded version and making of fully relocatable images.
added gforth-makeimage script for making fully relocatable images.
removed locals bug in if else endif constructs.
added mmap support for machines without MAP_ANON
removed command-line options -c and -o
moved definition of DOES_HANDLER_SIZE from machine.h to forth.h.
added hpux FLUSH_ICACHE in m68k.h
made source words print decimal

    1: /* common header file
    2: 
    3:   Copyright (C) 1995 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: #  define INDIRECT_THREADED
   27: #endif
   28: 
   29: #include <limits.h>
   30: 
   31: #if defined(NeXT)
   32: #  include <libc.h>
   33: #endif /* NeXT */
   34: 
   35: #if defined(DOUBLY_INDIRECT)
   36: typedef void **Label;
   37: #else /* !defined(DOUBLY_INDIRECT) */
   38: typedef void *Label;
   39: #endif /* !defined(DOUBLY_INDIRECT) */
   40: 
   41: /* symbol indexed constants */
   42: 
   43: #define DOCOL	0
   44: #define DOCON	1
   45: #define DOVAR	2
   46: #define DOUSER	3
   47: #define DODEFER	4
   48: #define DOFIELD	5
   49: #define DODOES	6
   50: #define DOESJUMP	7
   51: 
   52: /* the size of the DOESJUMP, which resides between DOES> and the does-code */
   53: #define DOES_HANDLER_SIZE	(2*sizeof(Cell))
   54: 
   55: #include "machine.h"
   56: 
   57: /* Forth data types */
   58: /* Cell and UCell must be the same size as a pointer */
   59: typedef CELL_TYPE Cell;
   60: typedef unsigned CELL_TYPE UCell;
   61: #define CELL_BITS	(sizeof(Cell) * CHAR_BIT)
   62: typedef Cell Bool;
   63: #define FLAG(b) (-(b))
   64: #define FILEIO(error)	(FLAG(error) & -37)
   65: #define FILEEXIST(error)	(FLAG(error) & -38)
   66: 
   67: #define F_TRUE (FLAG(0==0))
   68: #define F_FALSE (FLAG(0!=0))
   69: 
   70: typedef unsigned char Char;
   71: typedef double Float;
   72: typedef char *Address;
   73: 
   74: #ifdef BUGGY_LONG_LONG
   75: typedef struct {
   76:   Cell hi;
   77:   UCell lo;
   78: } DCell;
   79: 
   80: typedef struct {
   81:   UCell hi;
   82:   UCell lo;
   83: } UDCell;
   84: 
   85: #define FETCH_DCELL(d,lo,hi)	((d)=(typeof(d)){(hi),(lo)})
   86: #define STORE_DCELL(d,low,high)	({ \
   87: 				     typeof(d) _d = (d); \
   88: 				     (low) = _d.lo; \
   89: 				     (high)= _d.hi; \
   90: 				 })
   91: 
   92: #define LONG2UD(l)	({UDCell _ud; _ud.hi=0; _ud.lo=(Cell)(l); _ud;})
   93: #define UD2LONG(ud)	((long)(ud.lo))
   94: #define DZERO		((DCell){0,0})
   95: 
   96: #else /* ! defined(BUGGY_LONG_LONG) */
   97: 
   98: /* DCell and UDCell must be twice as large as Cell */
   99: typedef DOUBLE_CELL_TYPE DCell;
  100: typedef unsigned DOUBLE_CELL_TYPE UDCell;
  101: 
  102: typedef union {
  103:   struct {
  104: #ifdef WORDS_BIGENDIAN
  105:     Cell high;
  106:     UCell low;
  107: #else
  108:     UCell low;
  109:     Cell high;
  110: #endif;
  111:   } cells;
  112:   DCell dcell;
  113: } Double_Store;
  114: 
  115: #define FETCH_DCELL(d,lo,hi)	({ \
  116: 				     Double_Store _d; \
  117: 				     _d.cells.low = (lo); \
  118: 				     _d.cells.high = (hi); \
  119: 				     (d) = _d.dcell; \
  120: 				 })
  121: 
  122: #define STORE_DCELL(d,lo,hi)	({ \
  123: 				     Double_Store _d; \
  124: 				     _d.dcell = (d); \
  125: 				     (lo) = _d.cells.low; \
  126: 				     (hi) = _d.cells.high; \
  127: 				 })
  128: 
  129: #define LONG2UD(l)	((UDCell)(l))
  130: #define UD2LONG(ud)	((long)(ud))
  131: #define DZERO		((DCell)0)
  132: 
  133: #endif /* ! defined(BUGGY_LONG_LONG) */
  134: 
  135: #ifdef DIRECT_THREADED
  136: typedef Label Xt;
  137: #else
  138: typedef Label *Xt;
  139: #endif
  140: 
  141: 
  142: #if !defined(DIRECT_THREADED)
  143: /* i.e. indirect threaded our doubly indirect threaded */
  144: /* the direct threaded version is machine dependent and resides in machine.h */
  145: 
  146: /* PFA gives the parameter field address corresponding to a cfa */
  147: #define PFA(cfa)	(((Cell *)cfa)+2)
  148: /* PFA1 is a special version for use just after a NEXT1 */
  149: #define PFA1(cfa)	PFA(cfa)
  150: /* CODE_ADDRESS is the address of the code jumped to through the code field */
  151: #define CODE_ADDRESS(cfa)	(*(Xt)(cfa))
  152: 
  153: /* DOES_CODE is the Forth code does jumps to */
  154: #if !defined(DOUBLY_INDIRECT)
  155: #  define DOES_CA (symbols[DODOES])
  156: #else /* defined(DOUBLY_INDIRECT) */
  157: #  define DOES_CA ((Label)&symbols[DODOES])
  158: #endif /* defined(DOUBLY_INDIRECT) */
  159: 
  160: 
  161: 
  162: #define DOES_CODE(cfa)	({Xt _cfa=(Xt)(cfa); \
  163: 			  (Xt *)(_cfa[0]==DOES_CA ? _cfa[1] : NULL);})
  164: #define DOES_CODE1(cfa)	((Xt *)(cfa[1]))
  165: /* MAKE_CF creates an appropriate code field at the cfa;
  166:    ca is the code address */
  167: #define MAKE_CF(cfa,ca) ((*(Label *)(cfa)) = ((Label)ca))
  168: /* make a code field for a defining-word-defined word */
  169: #define MAKE_DOES_CF(cfa,does_code)  ({MAKE_CF(cfa,DOES_CA);	\
  170: 				       ((Cell *)cfa)[1] = (Cell)(does_code);})
  171: /* the does handler resides between DOES> and the following Forth code */
  172: /* not needed in indirect threaded code */
  173: #if defined(DOUBLY_INDIRECT)
  174: #define MAKE_DOES_HANDLER(addr)	MAKE_CF(addr, ((Label)&symbols[DOESJUMP]))
  175: #else /* !defined(DOUBLY_INDIRECT) */
  176: #define MAKE_DOES_HANDLER(addr)	0
  177: #endif /* !defined(DOUBLY_INDIRECT) */
  178: #endif /* !defined(DIRECT_THREADED) */
  179: 
  180: #ifdef DEBUG
  181: #	define	NAME(string)	fprintf(stderr,"%08lx: "string"\n",(Cell)ip);
  182: #else
  183: #	define	NAME(string)
  184: #endif
  185: 
  186: #define CF(const)	(-const-2)
  187: 
  188: #define CF_NIL	-1
  189: 
  190: #ifndef FLUSH_ICACHE
  191: #warning flush-icache probably will not work (see manual)
  192: #	define FLUSH_ICACHE(addr,size)
  193: #endif
  194: 
  195: #if defined(DIRECT_THREADED)
  196: #define CACHE_FLUSH(addr,size) FLUSH_ICACHE(addr,size)
  197: #else
  198: #define CACHE_FLUSH(addr,size)
  199: #endif
  200: 
  201: #ifdef USE_TOS
  202: #define IF_TOS(x) x
  203: #else
  204: #define IF_TOS(x)
  205: #define TOS (sp[0])
  206: #endif
  207: 
  208: #ifdef USE_FTOS
  209: #define IF_FTOS(x) x
  210: #else
  211: #define IF_FTOS(x)
  212: #define FTOS (fp[0])
  213: #endif
  214: 
  215: Label *engine(Xt *ip, Cell *sp, Cell *rp, Float *fp, Address lp);
  216: Address my_alloc(Cell size);
  217: 
  218: /* dblsub routines */
  219: DCell dnegate(DCell d1);
  220: UDCell ummul (UCell a, UCell b);
  221: DCell mmul (Cell a, Cell b);
  222: UDCell umdiv (UDCell u, UCell v);
  223: DCell smdiv (DCell num, Cell denom);
  224: DCell fmdiv (DCell num, Cell denom);
  225: 
  226: int memcasecmp(const char *s1, const char *s2, long n);
  227: 
  228: extern int offset_image;

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