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: #include <limits.h>
24:
25: typedef void *Label;
26:
27: /* symbol indexed constants */
28:
29: #define DOCOL 0
30: #define DOCON 1
31: #define DOVAR 2
32: #define DOUSER 3
33: #define DODEFER 4
34: #define DOFIELD 5
35: #define DODOES 6
36: #define DOESJUMP 7
37:
38: #include "machine.h"
39:
40: /* Forth data types */
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)
45: typedef Cell Bool;
46: #define FLAG(b) (-(b))
47: #define FILEIO(error) (FLAG(error) & -37)
48: #define FILEEXIST(error) (FLAG(error) & -38)
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:
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:
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) ({Xt _cfa=(Xt)(cfa); \
136: _cfa[0] == symbols[DODOES] ? _cfa[1] : NULL;})
137: #define DOES_CODE1(cfa) (cfa[1])
138: /* MAKE_CF creates an appropriate code field at the cfa;
139: ca is the code address */
140: #define MAKE_CF(cfa,ca) ((*(Label *)(cfa)) = ((Label)ca))
141: /* make a code field for a defining-word-defined word */
142: #define MAKE_DOES_CF(cfa,does_code) ({MAKE_CF(cfa,symbols[DODOES]); \
143: ((Cell *)cfa)[1] = (Cell)does_code;})
144: /* the does handler resides between DOES> and the following Forth code */
145: #define DOES_HANDLER_SIZE (2*sizeof(Cell))
146: #define MAKE_DOES_HANDLER(addr) 0 /* do nothing */
147: #endif /* !defined(DIRECT_THREADED) */
148:
149: #ifdef DEBUG
150: # define NAME(string) fprintf(stderr,"%08lx: "string"\n",(Cell)ip);
151: #else
152: # define NAME(string)
153: #endif
154:
155: #define CF(const) (-const-2)
156:
157: #define CF_NIL -1
158:
159: #ifndef FLUSH_ICACHE
160: #warning flush-icache probably will not work (see manual)
161: # define FLUSH_ICACHE(addr,size)
162: #endif
163:
164: #ifdef DIRECT_THREADED
165: #define CACHE_FLUSH(addr,size) FLUSH_ICACHE(addr,size)
166: #else
167: #define CACHE_FLUSH(addr,size)
168: #endif
169:
170: Label *engine(Xt *ip, Cell *sp, Cell *rp, Float *fp, Address lp);
171:
172: /* dblsub routines */
173: DCell dnegate(DCell d1);
174: UDCell ummul (UCell a, UCell b);
175: DCell mmul (Cell a, Cell b);
176: UDCell umdiv (UDCell u, UCell v);
177: DCell smdiv (DCell num, Cell denom);
178: DCell fmdiv (DCell num, Cell denom);
179:
180: int memcasecmp(const char *s1, const char *s2, long n);
181:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>