| 1 : |
anton
|
1.19
|
/* 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 : |
anton
|
1.1
|
*/ |
| 21 : |
|
|
|
| 22 : |
anton
|
1.21
|
#include "config.h" |
| 23 : |
|
|
#include <limits.h> |
| 24 : |
|
|
|
| 25 : |
anton
|
1.1
|
typedef void *Label; |
| 26 : |
|
|
|
| 27 : |
pazsan
|
1.2
|
/* symbol indexed constants */ |
| 28 : |
|
|
|
| 29 : |
|
|
#define DOCOL 0 |
| 30 : |
|
|
#define DOCON 1 |
| 31 : |
|
|
#define DOVAR 2 |
| 32 : |
|
|
#define DOUSER 3 |
| 33 : |
anton
|
1.8
|
#define DODEFER 4 |
| 34 : |
anton
|
1.16
|
#define DOFIELD 5 |
| 35 : |
pazsan
|
1.14
|
#define DODOES 6 |
| 36 : |
|
|
#define DOESJUMP 7 |
| 37 : |
benschop
|
1.6
|
|
| 38 : |
anton
|
1.1
|
#include "machine.h" |
| 39 : |
|
|
|
| 40 : |
|
|
/* Forth data types */ |
| 41 : |
anton
|
1.21
|
/* 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 : |
pazsan
|
1.20
|
typedef Cell Bool; |
| 46 : |
anton
|
1.1
|
#define FLAG(b) (-(b)) |
| 47 : |
pazsan
|
1.5
|
#define FILEIO(error) (FLAG(error) & -37) |
| 48 : |
|
|
#define FILEEXIST(error) (FLAG(error) & -38) |
| 49 : |
anton
|
1.1
|
|
| 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 : |
anton
|
1.21
|
#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 : |
anton
|
1.1
|
#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 */ |
| 141 : |
pazsan
|
1.2
|
#define MAKE_DOES_CF(cfa,does_code) ({MAKE_CF(cfa,symbols[DODOES]); \ |
| 142 : |
anton
|
1.1
|
((Cell *)cfa)[1] = (Cell)does_code;}) |
| 143 : |
|
|
/* the does handler resides between DOES> and the following Forth code */ |
| 144 : |
pazsan
|
1.13
|
#define DOES_HANDLER_SIZE (2*sizeof(Cell)) |
| 145 : |
anton
|
1.1
|
#define MAKE_DOES_HANDLER(addr) 0 /* do nothing */ |
| 146 : |
anton
|
1.21
|
#endif /* !defined(DIRECT_THREADED) */ |
| 147 : |
anton
|
1.1
|
|
| 148 : |
|
|
#ifdef DEBUG |
| 149 : |
pazsan
|
1.18
|
# define NAME(string) fprintf(stderr,"%08lx: "string"\n",(Cell)ip); |
| 150 : |
anton
|
1.1
|
#else |
| 151 : |
|
|
# define NAME(string) |
| 152 : |
|
|
#endif |
| 153 : |
pazsan
|
1.2
|
|
| 154 : |
|
|
#define CF(const) (-const-2) |
| 155 : |
|
|
|
| 156 : |
|
|
#define CF_NIL -1 |
| 157 : |
pazsan
|
1.3
|
|
| 158 : |
anton
|
1.15
|
#ifndef FLUSH_ICACHE |
| 159 : |
anton
|
1.16
|
#warning flush-icache probably will not work (see manual) |
| 160 : |
pazsan
|
1.17
|
# define FLUSH_ICACHE(addr,size) |
| 161 : |
anton
|
1.15
|
#endif |
| 162 : |
|
|
|
| 163 : |
|
|
#ifdef DIRECT_THREADED |
| 164 : |
|
|
#define CACHE_FLUSH(addr,size) FLUSH_ICACHE(addr,size) |
| 165 : |
|
|
#else |
| 166 : |
pazsan
|
1.17
|
#define CACHE_FLUSH(addr,size) |
| 167 : |
pazsan
|
1.3
|
#endif |
| 168 : |
anton
|
1.21
|
|
| 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 : |
|
|
|