Annotation of gforth/forth.h, revision 1.21
1.19 anton 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.
1.1 anton 20: */
21:
1.21 ! anton 22: #include "config.h"
! 23: #include <limits.h>
! 24:
1.1 anton 25: typedef void *Label;
26:
1.2 pazsan 27: /* symbol indexed constants */
28:
29: #define DOCOL 0
30: #define DOCON 1
31: #define DOVAR 2
32: #define DOUSER 3
1.8 anton 33: #define DODEFER 4
1.16 anton 34: #define DOFIELD 5
1.14 pazsan 35: #define DODOES 6
36: #define DOESJUMP 7
1.6 benschop 37:
1.1 anton 38: #include "machine.h"
39:
40: /* Forth data types */
1.21 ! anton 41: /* Cell and UCell must be the same size as a pointer */
! 42: typedef CELL_TYPE Cell;
! 43: typedef unsigned CELL_TYPE UCell;
! 44: #define CELL_BITS (sizeof(Cell) * CHAR_BIT)
1.20 pazsan 45: typedef Cell Bool;
1.1 anton 46: #define FLAG(b) (-(b))
1.5 pazsan 47: #define FILEIO(error) (FLAG(error) & -37)
48: #define FILEEXIST(error) (FLAG(error) & -38)
1.1 anton 49:
50: #define F_TRUE (FLAG(0==0))
51: #define F_FALSE (FLAG(0!=0))
52:
53: typedef unsigned char Char;
54: typedef double Float;
55: typedef char *Address;
56:
1.21 ! anton 57: #ifdef BUGGY_LONG_LONG
! 58: typedef struct {
! 59: Cell hi;
! 60: UCell lo;
! 61: } DCell;
! 62:
! 63: typedef struct {
! 64: UCell hi;
! 65: UCell lo;
! 66: } UDCell;
! 67:
! 68: #define FETCH_DCELL(d,lo,hi) ((d)=(typeof(d)){(hi),(lo)})
! 69: #define STORE_DCELL(d,low,high) ({ \
! 70: typeof(d) _d = (d); \
! 71: (low) = _d.lo; \
! 72: (high)= _d.hi; \
! 73: })
! 74:
! 75: #define LONG2UD(l) ({UDCell _ud; _ud.hi=0; _ud.lo=(Cell)(l); _ud;})
! 76: #define UD2LONG(ud) ((long)(ud.lo))
! 77: #define DZERO ((DCell){0,0})
! 78:
! 79: #else /* ! defined(BUGGY_LONG_LONG) */
! 80:
! 81: /* DCell and UDCell must be twice as large as Cell */
! 82: typedef DOUBLE_CELL_TYPE DCell;
! 83: typedef unsigned DOUBLE_CELL_TYPE UDCell;
! 84:
! 85: typedef union {
! 86: struct {
! 87: #ifdef WORDS_BIGENDIAN
! 88: Cell high;
! 89: UCell low;
! 90: #else
! 91: UCell low;
! 92: Cell high;
! 93: #endif;
! 94: } cells;
! 95: DCell dcell;
! 96: } Double_Store;
! 97:
! 98: #define FETCH_DCELL(d,lo,hi) ({ \
! 99: Double_Store _d; \
! 100: _d.cells.low = (lo); \
! 101: _d.cells.high = (hi); \
! 102: (d) = _d.dcell; \
! 103: })
! 104:
! 105: #define STORE_DCELL(d,lo,hi) ({ \
! 106: Double_Store _d; \
! 107: _d.dcell = (d); \
! 108: (lo) = _d.cells.low; \
! 109: (hi) = _d.cells.high; \
! 110: })
! 111:
! 112: #define LONG2UD(l) ((UDCell)(l))
! 113: #define UD2LONG(ud) ((long)(ud))
! 114: #define DZERO ((DCell)0)
! 115:
! 116: #endif /* ! defined(BUGGY_LONG_LONG) */
! 117:
1.1 anton 118: #ifdef DIRECT_THREADED
119: typedef Label Xt;
120: #else
121: typedef Label *Xt;
122: #endif
123:
124: #ifndef DIRECT_THREADED
125: /* i.e. indirect threaded */
126: /* the direct threaded version is machine dependent and resides in machine.h */
127:
128: /* PFA gives the parameter field address corresponding to a cfa */
129: #define PFA(cfa) (((Cell *)cfa)+2)
130: /* PFA1 is a special version for use just after a NEXT1 */
131: #define PFA1(cfa) PFA(cfa)
132: /* CODE_ADDRESS is the address of the code jumped to through the code field */
133: #define CODE_ADDRESS(cfa) (*(Label *)(cfa))
134: /* DOES_CODE is the Forth code does jumps to */
135: #define DOES_CODE(cfa) (cfa[1])
136: #define DOES_CODE1(cfa) DOES_CODE(cfa)
137: /* MAKE_CF creates an appropriate code field at the cfa;
138: ca is the code address */
139: #define MAKE_CF(cfa,ca) ((*(Label *)(cfa)) = ((Label)ca))
140: /* make a code field for a defining-word-defined word */
1.2 pazsan 141: #define MAKE_DOES_CF(cfa,does_code) ({MAKE_CF(cfa,symbols[DODOES]); \
1.1 anton 142: ((Cell *)cfa)[1] = (Cell)does_code;})
143: /* the does handler resides between DOES> and the following Forth code */
1.13 pazsan 144: #define DOES_HANDLER_SIZE (2*sizeof(Cell))
1.1 anton 145: #define MAKE_DOES_HANDLER(addr) 0 /* do nothing */
1.21 ! anton 146: #endif /* !defined(DIRECT_THREADED) */
1.1 anton 147:
148: #ifdef DEBUG
1.18 pazsan 149: # define NAME(string) fprintf(stderr,"%08lx: "string"\n",(Cell)ip);
1.1 anton 150: #else
151: # define NAME(string)
152: #endif
1.2 pazsan 153:
154: #define CF(const) (-const-2)
155:
156: #define CF_NIL -1
1.3 pazsan 157:
1.15 anton 158: #ifndef FLUSH_ICACHE
1.16 anton 159: #warning flush-icache probably will not work (see manual)
1.17 pazsan 160: # define FLUSH_ICACHE(addr,size)
1.15 anton 161: #endif
162:
163: #ifdef DIRECT_THREADED
164: #define CACHE_FLUSH(addr,size) FLUSH_ICACHE(addr,size)
165: #else
1.17 pazsan 166: #define CACHE_FLUSH(addr,size)
1.3 pazsan 167: #endif
1.21 ! anton 168:
! 169: Label *engine(Xt *ip, Cell *sp, Cell *rp, Float *fp, Address lp);
! 170:
! 171: /* dblsub routines */
! 172: DCell dnegate(DCell d1);
! 173: UDCell ummul (UCell a, UCell b);
! 174: DCell mmul (Cell a, Cell b);
! 175: UDCell umdiv (UDCell u, UCell v);
! 176: DCell smdiv (DCell num, Cell denom);
! 177: DCell fmdiv (DCell num, Cell denom);
! 178:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>