| 1 : |
anton
|
1.1
|
/* common header file |
| 2 : |
|
|
|
| 3 : |
anton
|
1.107
|
Copyright (C) 1995,1996,1997,1998,2000,2003,2004,2005,2006,2007,2008,2009 Free Software Foundation, Inc. |
| 4 : |
anton
|
1.1
|
|
| 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 : |
anton
|
1.89
|
as published by the Free Software Foundation, either version 3 |
| 10 : |
anton
|
1.1
|
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 : |
anton
|
1.89
|
along with this program; if not, see http://www.gnu.org/licenses/. |
| 19 : |
anton
|
1.1
|
*/ |
| 20 : |
|
|
|
| 21 : |
|
|
#include "config.h" |
| 22 : |
anton
|
1.90
|
#include "128bit.h" |
| 23 : |
anton
|
1.18
|
#include <stdio.h> |
| 24 : |
anton
|
1.35
|
#include <sys/time.h> |
| 25 : |
|
|
#include <unistd.h> |
| 26 : |
pazsan
|
1.95
|
#ifndef STANDALONE |
| 27 : |
anton
|
1.103
|
#if defined(HAVE_LIBLTDL) |
| 28 : |
anton
|
1.87
|
#include <ltdl.h> |
| 29 : |
pazsan
|
1.95
|
#endif |
| 30 : |
anton
|
1.103
|
#endif |
| 31 : |
anton
|
1.1
|
|
| 32 : |
anton
|
1.93
|
#if !defined(FORCE_LL) && !defined(BUGGY_LONG_LONG) |
| 33 : |
|
|
#define BUGGY_LONG_LONG |
| 34 : |
|
|
#endif |
| 35 : |
|
|
|
| 36 : |
anton
|
1.32
|
#if defined(DOUBLY_INDIRECT)||defined(INDIRECT_THREADED)||defined(VM_PROFILING) |
| 37 : |
|
|
#define NO_DYNAMIC |
| 38 : |
|
|
#endif |
| 39 : |
|
|
|
| 40 : |
anton
|
1.1
|
#if defined(DOUBLY_INDIRECT) |
| 41 : |
|
|
# undef DIRECT_THREADED |
| 42 : |
|
|
# undef INDIRECT_THREADED |
| 43 : |
|
|
# define INDIRECT_THREADED |
| 44 : |
|
|
#endif |
| 45 : |
|
|
|
| 46 : |
anton
|
1.57
|
#if defined(GFORTH_DEBUGGING) || defined(INDIRECT_THREADED) || defined(DOUBLY_INDIRECT) || defined(VM_PROFILING) |
| 47 : |
anton
|
1.23
|
# undef USE_TOS |
| 48 : |
|
|
# undef USE_FTOS |
| 49 : |
anton
|
1.56
|
# undef USE_NO_TOS |
| 50 : |
|
|
# undef USE_NO_FTOS |
| 51 : |
anton
|
1.23
|
# define USE_NO_TOS |
| 52 : |
|
|
# define USE_NO_FTOS |
| 53 : |
anton
|
1.57
|
|
| 54 : |
|
|
#define PRIM_I "prim.i" |
| 55 : |
|
|
#define PRIM_LAB_I "prim_lab.i" |
| 56 : |
|
|
#define PRIM_NAMES_I "prim_names.i" |
| 57 : |
|
|
#define PRIM_SUPEREND_I "prim_superend.i" |
| 58 : |
|
|
#define PRIM_NUM_I "prim_num.i" |
| 59 : |
|
|
#define PRIM_GRP_I "prim_grp.i" |
| 60 : |
|
|
#define COSTS_I "costs.i" |
| 61 : |
|
|
#define SUPER2_I "super2.i" |
| 62 : |
anton
|
1.58
|
/* #define PROFILE_I "profile.i" */ |
| 63 : |
anton
|
1.57
|
|
| 64 : |
|
|
#else |
| 65 : |
|
|
/* gforth-fast or gforth-native */ |
| 66 : |
anton
|
1.59
|
# undef USE_TOS |
| 67 : |
|
|
# undef USE_FTOS |
| 68 : |
|
|
# undef USE_NO_TOS |
| 69 : |
|
|
# undef USE_NO_FTOS |
| 70 : |
|
|
# define USE_TOS |
| 71 : |
anton
|
1.57
|
|
| 72 : |
|
|
#define PRIM_I "prim-fast.i" |
| 73 : |
|
|
#define PRIM_LAB_I "prim_lab-fast.i" |
| 74 : |
|
|
#define PRIM_NAMES_I "prim_names-fast.i" |
| 75 : |
|
|
#define PRIM_SUPEREND_I "prim_superend-fast.i" |
| 76 : |
|
|
#define PRIM_NUM_I "prim_num-fast.i" |
| 77 : |
|
|
#define PRIM_GRP_I "prim_grp-fast.i" |
| 78 : |
|
|
#define COSTS_I "costs-fast.i" |
| 79 : |
|
|
#define SUPER2_I "super2-fast.i" |
| 80 : |
anton
|
1.58
|
/* profile.c uses profile.i but does not define VM_PROFILING */ |
| 81 : |
|
|
/* #define PROFILE_I "profile-fast.i" */ |
| 82 : |
anton
|
1.57
|
|
| 83 : |
anton
|
1.23
|
#endif |
| 84 : |
anton
|
1.57
|
|
| 85 : |
|
|
|
| 86 : |
anton
|
1.23
|
|
| 87 : |
anton
|
1.1
|
#include <limits.h> |
| 88 : |
|
|
|
| 89 : |
|
|
#if defined(NeXT) |
| 90 : |
|
|
# include <libc.h> |
| 91 : |
|
|
#endif /* NeXT */ |
| 92 : |
|
|
|
| 93 : |
|
|
/* symbol indexed constants */ |
| 94 : |
|
|
|
| 95 : |
|
|
#define DOCOL 0 |
| 96 : |
|
|
#define DOCON 1 |
| 97 : |
|
|
#define DOVAR 2 |
| 98 : |
|
|
#define DOUSER 3 |
| 99 : |
|
|
#define DODEFER 4 |
| 100 : |
|
|
#define DOFIELD 5 |
| 101 : |
pazsan
|
1.86
|
#define DOVAL 6 |
| 102 : |
|
|
#define DODOES 7 |
| 103 : |
|
|
#define DOESJUMP 8 |
| 104 : |
dvdkhlng
|
1.108
|
#define DOABICODE 9 |
| 105 : |
|
|
#define DOER_MAX 9 |
| 106 : |
anton
|
1.1
|
|
| 107 : |
|
|
/* the size of the DOESJUMP, which resides between DOES> and the does-code */ |
| 108 : |
|
|
#define DOES_HANDLER_SIZE (2*sizeof(Cell)) |
| 109 : |
|
|
|
| 110 : |
jwilke
|
1.6
|
#include "machine.h" |
| 111 : |
anton
|
1.1
|
|
| 112 : |
pazsan
|
1.68
|
/* C interface data types */ |
| 113 : |
|
|
|
| 114 : |
|
|
typedef WYDE_TYPE Wyde; |
| 115 : |
|
|
typedef TETRABYTE_TYPE Tetrabyte; |
| 116 : |
|
|
typedef unsigned WYDE_TYPE UWyde; |
| 117 : |
|
|
typedef unsigned TETRABYTE_TYPE UTetrabyte; |
| 118 : |
|
|
|
| 119 : |
anton
|
1.1
|
/* Forth data types */ |
| 120 : |
|
|
/* Cell and UCell must be the same size as a pointer */ |
| 121 : |
|
|
#define CELL_BITS (sizeof(Cell) * CHAR_BIT) |
| 122 : |
anton
|
1.77
|
#define CELL_MIN (((Cell)1)<<(sizeof(Cell)*CHAR_BIT-1)) |
| 123 : |
anton
|
1.78
|
|
| 124 : |
|
|
#define HALFCELL_BITS (CELL_BITS/2) |
| 125 : |
|
|
#define HALFCELL_MASK ((~(UCell)0)>>HALFCELL_BITS) |
| 126 : |
|
|
#define UH(x) (((UCell)(x))>>HALFCELL_BITS) |
| 127 : |
|
|
#define LH(x) ((x)&HALFCELL_MASK) |
| 128 : |
|
|
#define L2U(x) (((UCell)(x))<<HALFCELL_BITS) |
| 129 : |
|
|
#define HIGHBIT(x) (((UCell)(x))>>(CELL_BITS-1)) |
| 130 : |
|
|
|
| 131 : |
anton
|
1.1
|
#define FLAG(b) (-(b)) |
| 132 : |
|
|
#define FILEIO(error) (FLAG(error) & -37) |
| 133 : |
|
|
#define FILEEXIST(error) (FLAG(error) & -38) |
| 134 : |
|
|
|
| 135 : |
|
|
#define F_TRUE (FLAG(0==0)) |
| 136 : |
|
|
#define F_FALSE (FLAG(0!=0)) |
| 137 : |
|
|
|
| 138 : |
pazsan
|
1.65
|
/* define this false if you want native division */ |
| 139 : |
pazsan
|
1.66
|
#ifdef FORCE_CDIV |
| 140 : |
|
|
#define FLOORED_DIV 0 |
| 141 : |
|
|
#else |
| 142 : |
pazsan
|
1.65
|
#define FLOORED_DIV ((1%-3)>0) |
| 143 : |
pazsan
|
1.66
|
#endif |
| 144 : |
pazsan
|
1.65
|
|
| 145 : |
anton
|
1.93
|
#if defined(BUGGY_LONG_LONG) |
| 146 : |
pazsan
|
1.64
|
|
| 147 : |
|
|
#define BUGGY_LL_CMP /* compares not possible */ |
| 148 : |
|
|
#define BUGGY_LL_MUL /* multiplication not possible */ |
| 149 : |
|
|
#define BUGGY_LL_DIV /* division not possible */ |
| 150 : |
|
|
#define BUGGY_LL_ADD /* addition not possible */ |
| 151 : |
|
|
#define BUGGY_LL_SHIFT /* shift not possible */ |
| 152 : |
|
|
#define BUGGY_LL_D2F /* to float not possible */ |
| 153 : |
|
|
#define BUGGY_LL_F2D /* from float not possible */ |
| 154 : |
|
|
#define BUGGY_LL_SIZE /* long long "too short", so we use something else */ |
| 155 : |
|
|
|
| 156 : |
anton
|
1.1
|
typedef struct { |
| 157 : |
|
|
Cell hi; |
| 158 : |
|
|
UCell lo; |
| 159 : |
|
|
} DCell; |
| 160 : |
|
|
|
| 161 : |
|
|
typedef struct { |
| 162 : |
|
|
UCell hi; |
| 163 : |
|
|
UCell lo; |
| 164 : |
|
|
} UDCell; |
| 165 : |
|
|
|
| 166 : |
pazsan
|
1.64
|
#define DHI(x) (x).hi |
| 167 : |
|
|
#define DLO(x) (x).lo |
| 168 : |
|
|
#define DHI_IS(x,y) (x).hi=(y) |
| 169 : |
|
|
#define DLO_IS(x,y) (x).lo=(y) |
| 170 : |
|
|
|
| 171 : |
anton
|
1.78
|
#define UD2D(ud) ({UDCell _ud=(ud); (DCell){_ud.hi,_ud.lo};}) |
| 172 : |
anton
|
1.80
|
#define D2UD(d) ({DCell _d1=(d); (UDCell){_d1.hi,_d1.lo};}) |
| 173 : |
|
|
|
| 174 : |
|
|
/* shifts by less than CELL_BITS */ |
| 175 : |
anton
|
1.104
|
#define DLSHIFT(d,u) ({DCell _d=(d); UCell _u=(u); \ |
| 176 : |
|
|
((_u==0) ? \ |
| 177 : |
|
|
_d : \ |
| 178 : |
|
|
(DCell){(_d.hi<<_u)|(_d.lo>>(CELL_BITS-_u)), \ |
| 179 : |
|
|
_d.lo<<_u});}) |
| 180 : |
|
|
|
| 181 : |
anton
|
1.80
|
#define UDLSHIFT(ud,u) D2UD(DLSHIFT(UD2D(ud),u)) |
| 182 : |
anton
|
1.78
|
|
| 183 : |
anton
|
1.39
|
#if SMALL_OFF_T |
| 184 : |
|
|
#define OFF2UD(o) ({UDCell _ud; _ud.hi=0; _ud.lo=(Cell)(o); _ud;}) |
| 185 : |
|
|
#define UD2OFF(ud) ((ud).lo) |
| 186 : |
|
|
#else /* !SMALL_OFF_T */ |
| 187 : |
|
|
#define OFF2UD(o) ({UDCell _ud; off_t _o=(o); _ud.hi=_o>>CELL_BITS; _ud.lo=(Cell)_o; _ud;}) |
| 188 : |
anton
|
1.36
|
#define UD2OFF(ud) ({UDCell _ud=(ud); (((off_t)_ud.hi)<<CELL_BITS)+_ud.lo;}) |
| 189 : |
anton
|
1.39
|
#endif /* !SMALL_OFF_T */ |
| 190 : |
anton
|
1.1
|
#define DZERO ((DCell){0,0}) |
| 191 : |
|
|
|
| 192 : |
anton
|
1.93
|
#else /* !defined(BUGGY_LONG_LONG) */ |
| 193 : |
anton
|
1.1
|
|
| 194 : |
|
|
/* DCell and UDCell must be twice as large as Cell */ |
| 195 : |
|
|
typedef DOUBLE_CELL_TYPE DCell; |
| 196 : |
pazsan
|
1.63
|
typedef DOUBLE_UCELL_TYPE UDCell; |
| 197 : |
anton
|
1.1
|
|
| 198 : |
anton
|
1.93
|
#define DHI(x) ({ Double_Store _d; _d.d=(x); _d.cells.high; }) |
| 199 : |
|
|
#define DLO(x) ({ Double_Store _d; _d.d=(x); _d.cells.low; }) |
| 200 : |
|
|
|
| 201 : |
|
|
/* beware with the assignment: x is referenced twice! */ |
| 202 : |
|
|
#define DHI_IS(x,y) ({ Double_Store _d; _d.d=(x); _d.cells.high=(y); (x)=_d.d; }) |
| 203 : |
|
|
#define DLO_IS(x,y) ({ Double_Store _d; _d.d=(x); _d.cells.low =(y); (x)=_d.d; }) |
| 204 : |
|
|
|
| 205 : |
|
|
#define UD2D(ud) ((DCell)(ud)) |
| 206 : |
|
|
#define D2UD(d) ((UDCell)(d)) |
| 207 : |
anton
|
1.36
|
#define OFF2UD(o) ((UDCell)(o)) |
| 208 : |
|
|
#define UD2OFF(ud) ((off_t)(ud)) |
| 209 : |
anton
|
1.16
|
#define DZERO ((DCell)0) |
| 210 : |
anton
|
1.80
|
/* shifts by less than CELL_BITS */ |
| 211 : |
|
|
#define DLSHIFT(d,u) ((d)<<(u)) |
| 212 : |
|
|
#define UDLSHIFT(d,u) ((d)<<(u)) |
| 213 : |
anton
|
1.16
|
|
| 214 : |
anton
|
1.93
|
#endif /* !defined(BUGGY_LONG_LONG) */ |
| 215 : |
anton
|
1.16
|
|
| 216 : |
anton
|
1.1
|
typedef union { |
| 217 : |
|
|
struct { |
| 218 : |
anton
|
1.16
|
#if defined(WORDS_BIGENDIAN)||defined(BUGGY_LONG_LONG) |
| 219 : |
anton
|
1.1
|
Cell high; |
| 220 : |
|
|
UCell low; |
| 221 : |
|
|
#else |
| 222 : |
|
|
UCell low; |
| 223 : |
|
|
Cell high; |
| 224 : |
crook
|
1.20
|
#endif |
| 225 : |
anton
|
1.1
|
} cells; |
| 226 : |
anton
|
1.16
|
DCell d; |
| 227 : |
|
|
UDCell ud; |
| 228 : |
anton
|
1.1
|
} Double_Store; |
| 229 : |
pazsan
|
1.64
|
|
| 230 : |
anton
|
1.16
|
#define FETCH_DCELL_T(d_,lo,hi,t_) ({ \ |
| 231 : |
anton
|
1.1
|
Double_Store _d; \ |
| 232 : |
|
|
_d.cells.low = (lo); \ |
| 233 : |
|
|
_d.cells.high = (hi); \ |
| 234 : |
anton
|
1.16
|
(d_) = _d.t_; \ |
| 235 : |
anton
|
1.1
|
}) |
| 236 : |
|
|
|
| 237 : |
anton
|
1.16
|
#define STORE_DCELL_T(d_,lo,hi,t_) ({ \ |
| 238 : |
anton
|
1.1
|
Double_Store _d; \ |
| 239 : |
anton
|
1.16
|
_d.t_ = (d_); \ |
| 240 : |
anton
|
1.1
|
(lo) = _d.cells.low; \ |
| 241 : |
|
|
(hi) = _d.cells.high; \ |
| 242 : |
|
|
}) |
| 243 : |
|
|
|
| 244 : |
anton
|
1.28
|
#define vm_twoCell2d(lo,hi,d_) FETCH_DCELL_T(d_,lo,hi,d); |
| 245 : |
|
|
#define vm_twoCell2ud(lo,hi,d_) FETCH_DCELL_T(d_,lo,hi,ud); |
| 246 : |
anton
|
1.1
|
|
| 247 : |
anton
|
1.28
|
#define vm_d2twoCell(d_,lo,hi) STORE_DCELL_T(d_,lo,hi,d); |
| 248 : |
|
|
#define vm_ud2twoCell(d_,lo,hi) STORE_DCELL_T(d_,lo,hi,ud); |
| 249 : |
anton
|
1.1
|
|
| 250 : |
|
|
typedef Label *Xt; |
| 251 : |
|
|
|
| 252 : |
|
|
/* PFA gives the parameter field address corresponding to a cfa */ |
| 253 : |
|
|
#define PFA(cfa) (((Cell *)cfa)+2) |
| 254 : |
|
|
/* PFA1 is a special version for use just after a NEXT1 */ |
| 255 : |
|
|
#define PFA1(cfa) PFA(cfa) |
| 256 : |
|
|
/* CODE_ADDRESS is the address of the code jumped to through the code field */ |
| 257 : |
|
|
#define CODE_ADDRESS(cfa) (*(Xt)(cfa)) |
| 258 : |
|
|
|
| 259 : |
|
|
/* DOES_CODE is the Forth code does jumps to */ |
| 260 : |
|
|
#if !defined(DOUBLY_INDIRECT) |
| 261 : |
|
|
# define DOES_CA (symbols[DODOES]) |
| 262 : |
|
|
#else /* defined(DOUBLY_INDIRECT) */ |
| 263 : |
anton
|
1.24
|
# define DOES_CA ((Label)&xts[DODOES]) |
| 264 : |
anton
|
1.1
|
#endif /* defined(DOUBLY_INDIRECT) */ |
| 265 : |
|
|
|
| 266 : |
|
|
|
| 267 : |
|
|
|
| 268 : |
|
|
#define DOES_CODE1(cfa) ((Xt *)(cfa[1])) |
| 269 : |
|
|
/* MAKE_CF creates an appropriate code field at the cfa; |
| 270 : |
|
|
ca is the code address */ |
| 271 : |
|
|
#define MAKE_CF(cfa,ca) ((*(Label *)(cfa)) = ((Label)ca)) |
| 272 : |
|
|
/* make a code field for a defining-word-defined word */ |
| 273 : |
|
|
#define MAKE_DOES_CF(cfa,does_code) ({MAKE_CF(cfa,DOES_CA); \ |
| 274 : |
|
|
((Cell *)cfa)[1] = (Cell)(does_code);}) |
| 275 : |
|
|
|
| 276 : |
|
|
#define CF(const) (-const-2) |
| 277 : |
|
|
|
| 278 : |
|
|
#define CF_NIL -1 |
| 279 : |
|
|
|
| 280 : |
|
|
#ifndef FLUSH_ICACHE |
| 281 : |
|
|
#warning flush-icache probably will not work (see manual) |
| 282 : |
|
|
# define FLUSH_ICACHE(addr,size) |
| 283 : |
anton
|
1.45
|
#warning no FLUSH_ICACHE, turning off dynamic native code by default |
| 284 : |
|
|
#undef NO_DYNAMIC_DEFAULT |
| 285 : |
|
|
#define NO_DYNAMIC_DEFAULT 1 |
| 286 : |
anton
|
1.1
|
#endif |
| 287 : |
|
|
|
| 288 : |
anton
|
1.67
|
#if defined(GFORTH_DEBUGGING) || defined(INDIRECT_THREADED) || defined(DOUBLY_INDIRECT) || defined(VM_PROFILING) |
| 289 : |
|
|
#define STACK_CACHE_DEFAULT 0 |
| 290 : |
anton
|
1.1
|
#else |
| 291 : |
anton
|
1.67
|
#define STACK_CACHE_DEFAULT STACK_CACHE_DEFAULT_FAST |
| 292 : |
anton
|
1.1
|
#endif |
| 293 : |
|
|
|
| 294 : |
|
|
#ifdef USE_FTOS |
| 295 : |
anton
|
1.14
|
#define IF_fpTOS(x) x |
| 296 : |
anton
|
1.1
|
#else |
| 297 : |
anton
|
1.14
|
#define IF_fpTOS(x) |
| 298 : |
|
|
#define fpTOS (fp[0]) |
| 299 : |
anton
|
1.1
|
#endif |
| 300 : |
|
|
|
| 301 : |
anton
|
1.15
|
#define IF_rpTOS(x) |
| 302 : |
|
|
#define rpTOS (rp[0]) |
| 303 : |
|
|
|
| 304 : |
anton
|
1.10
|
typedef struct { |
| 305 : |
|
|
Address base; /* base address of image (0 if relocatable) */ |
| 306 : |
|
|
UCell checksum; /* checksum of ca's to protect against some |
| 307 : |
|
|
incompatible binary/executable combinations |
| 308 : |
|
|
(0 if relocatable) */ |
| 309 : |
|
|
UCell image_size; /* all sizes in bytes */ |
| 310 : |
|
|
UCell dict_size; |
| 311 : |
|
|
UCell data_stack_size; |
| 312 : |
|
|
UCell fp_stack_size; |
| 313 : |
|
|
UCell return_stack_size; |
| 314 : |
|
|
UCell locals_stack_size; |
| 315 : |
|
|
Xt *boot_entry; /* initial ip for booting (in BOOT) */ |
| 316 : |
|
|
Xt *throw_entry; /* ip after signal (in THROW) */ |
| 317 : |
|
|
Cell unused1; /* possibly tib stack size */ |
| 318 : |
anton
|
1.24
|
Label *xt_base; /* base of DOUBLE_INDIRECT xts[], for comp-i.fs */ |
| 319 : |
anton
|
1.10
|
Address data_stack_base; /* this and the following fields are initialized by the loader */ |
| 320 : |
|
|
Address fp_stack_base; |
| 321 : |
|
|
Address return_stack_base; |
| 322 : |
|
|
Address locals_stack_base; |
| 323 : |
|
|
} ImageHeader; |
| 324 : |
|
|
/* the image-header is created in main.fs */ |
| 325 : |
|
|
|
| 326 : |
pazsan
|
1.82
|
#ifdef HAS_F83HEADERSTRING |
| 327 : |
|
|
struct F83Name { |
| 328 : |
|
|
struct F83Name *next; /* the link field for old hands */ |
| 329 : |
|
|
char countetc; |
| 330 : |
|
|
char name[0]; |
| 331 : |
|
|
}; |
| 332 : |
|
|
|
| 333 : |
|
|
#define F83NAME_COUNT(np) ((np)->countetc & 0x1f) |
| 334 : |
|
|
#endif |
| 335 : |
anton
|
1.48
|
struct Longname { |
| 336 : |
|
|
struct Longname *next; /* the link field for old hands */ |
| 337 : |
|
|
Cell countetc; |
| 338 : |
|
|
char name[0]; |
| 339 : |
|
|
}; |
| 340 : |
|
|
|
| 341 : |
anton
|
1.106
|
#define LONGNAME_COUNT(np) ((np)->countetc & (((~((UCell)0))<<4)>>4)) |
| 342 : |
anton
|
1.48
|
|
| 343 : |
|
|
struct Cellpair { |
| 344 : |
|
|
Cell n1; |
| 345 : |
|
|
Cell n2; |
| 346 : |
|
|
}; |
| 347 : |
|
|
|
| 348 : |
|
|
struct Cellquad { |
| 349 : |
|
|
Cell n1; |
| 350 : |
|
|
Cell n2; |
| 351 : |
|
|
Cell n3; |
| 352 : |
|
|
Cell n4; |
| 353 : |
|
|
}; |
| 354 : |
anton
|
1.49
|
|
| 355 : |
|
|
#define IOR(flag) ((flag)? -512-errno : 0) |
| 356 : |
anton
|
1.48
|
|
| 357 : |
anton
|
1.91
|
#ifdef GFORTH_DEBUGGING |
| 358 : |
|
|
#if defined(GLOBALS_NONRELOC) |
| 359 : |
|
|
/* if globals cause non-relocatable primitives, keep saved_ip and rp |
| 360 : |
|
|
in a structure and access it through locals */ |
| 361 : |
|
|
typedef struct saved_regs { |
| 362 : |
|
|
Xt *sr_saved_ip; |
| 363 : |
|
|
Cell *sr_rp; |
| 364 : |
|
|
} saved_regs; |
| 365 : |
|
|
extern saved_regs saved_regs_v, *saved_regs_p; |
| 366 : |
|
|
#define saved_ip (saved_regs_p->sr_saved_ip) |
| 367 : |
|
|
#define rp (saved_regs_p->sr_rp) |
| 368 : |
|
|
/* for use in gforth_engine header */ |
| 369 : |
anton
|
1.94
|
#error sr_proto not passed in fflib.fs callbacks (solution: disable GLOBALS_NONRELOC) |
| 370 : |
anton
|
1.92
|
#define sr_proto , struct saved_regs *saved_regs_p0 |
| 371 : |
anton
|
1.91
|
#define sr_call , saved_regs_p |
| 372 : |
|
|
#else /* !defined(GLOBALS_NONRELOC) */ |
| 373 : |
|
|
extern Xt *saved_ip; |
| 374 : |
|
|
extern Cell *rp; |
| 375 : |
|
|
#define sr_proto |
| 376 : |
|
|
#define sr_call |
| 377 : |
|
|
#endif /* !defined(GLOBALS_NONRELOC) */ |
| 378 : |
|
|
#else /* !defined(GFORTH_DEBUGGING) */ |
| 379 : |
|
|
#define sr_proto |
| 380 : |
|
|
#define sr_call |
| 381 : |
|
|
#endif /* !defined(GFORTH_DEBUGGING) */ |
| 382 : |
|
|
|
| 383 : |
|
|
Label *gforth_engine(Xt *ip, Cell *sp, Cell *rp0, Float *fp, Address lp sr_proto); |
| 384 : |
|
|
Label *gforth_engine2(Xt *ip, Cell *sp, Cell *rp0, Float *fp, Address lp sr_proto); |
| 385 : |
|
|
Label *gforth_engine3(Xt *ip, Cell *sp, Cell *rp0, Float *fp, Address lp sr_proto); |
| 386 : |
anton
|
1.48
|
|
| 387 : |
|
|
/* engine/prim support routines */ |
| 388 : |
pazsan
|
1.71
|
Address gforth_alloc(Cell size); |
| 389 : |
anton
|
1.35
|
char *cstr(Char *from, UCell size, int clear); |
| 390 : |
anton
|
1.11
|
char *tilde_cstr(Char *from, UCell size, int clear); |
| 391 : |
anton
|
1.85
|
Cell opencreate_file(char *s, Cell wfam, int flags, Cell *wiorp); |
| 392 : |
anton
|
1.35
|
DCell timeval2us(struct timeval *tvp); |
| 393 : |
anton
|
1.48
|
void cmove(Char *c_from, Char *c_to, UCell u); |
| 394 : |
|
|
void cmove_up(Char *c_from, Char *c_to, UCell u); |
| 395 : |
|
|
Cell compare(Char *c_addr1, UCell u1, Char *c_addr2, UCell u2); |
| 396 : |
|
|
struct Longname *listlfind(Char *c_addr, UCell u, struct Longname *longname1); |
| 397 : |
|
|
struct Longname *hashlfind(Char *c_addr, UCell u, Cell *a_addr); |
| 398 : |
|
|
struct Longname *tablelfind(Char *c_addr, UCell u, Cell *a_addr); |
| 399 : |
|
|
UCell hashkey1(Char *c_addr, UCell u, UCell ubits); |
| 400 : |
|
|
struct Cellpair parse_white(Char *c_addr1, UCell u1); |
| 401 : |
|
|
Cell rename_file(Char *c_addr1, UCell u1, Char *c_addr2, UCell u2); |
| 402 : |
anton
|
1.105
|
struct Cellquad read_line(Char *c_addr, UCell u1, FILE *wfileid); |
| 403 : |
anton
|
1.48
|
struct Cellpair file_status(Char *c_addr, UCell u); |
| 404 : |
anton
|
1.91
|
Cell to_float(Char *c_addr, UCell u, Float *r_p); |
| 405 : |
anton
|
1.48
|
Float v_star(Float *f_addr1, Cell nstride1, Float *f_addr2, Cell nstride2, UCell ucount); |
| 406 : |
|
|
void faxpy(Float ra, Float *f_x, Cell nstridex, Float *f_y, Cell nstridey, UCell ucount); |
| 407 : |
pazsan
|
1.60
|
UCell lshift(UCell u1, UCell n); |
| 408 : |
|
|
UCell rshift(UCell u1, UCell n); |
| 409 : |
anton
|
1.61
|
int gforth_system(Char *c_addr, UCell u); |
| 410 : |
anton
|
1.83
|
void gforth_ms(UCell u); |
| 411 : |
pazsan
|
1.102
|
UCell gforth_dlopen(Char *c_addr, UCell u); |
| 412 : |
pazsan
|
1.72
|
Cell capscompare(Char *c_addr1, UCell u1, Char *c_addr2, UCell u2); |
| 413 : |
anton
|
1.105
|
int gf_ungetc(int c, FILE *stream); |
| 414 : |
|
|
void gf_regetc(FILE *stream); |
| 415 : |
|
|
int gf_ungottenc(FILE *stream); |
| 416 : |
anton
|
1.1
|
|
| 417 : |
anton
|
1.50
|
/* signal handler stuff */ |
| 418 : |
|
|
void install_signal_handlers(void); |
| 419 : |
anton
|
1.75
|
void throw(int code); |
| 420 : |
anton
|
1.76
|
/* throw codes */ |
| 421 : |
|
|
#define BALL_DIVZERO -10 |
| 422 : |
|
|
#define BALL_RESULTRANGE -11 |
| 423 : |
|
|
|
| 424 : |
anton
|
1.50
|
typedef void Sigfunc(int); |
| 425 : |
|
|
Sigfunc *bsd_signal(int signo, Sigfunc *func); |
| 426 : |
|
|
|
| 427 : |
anton
|
1.1
|
/* dblsub routines */ |
| 428 : |
|
|
DCell dnegate(DCell d1); |
| 429 : |
|
|
UDCell ummul (UCell a, UCell b); |
| 430 : |
|
|
DCell mmul (Cell a, Cell b); |
| 431 : |
|
|
UDCell umdiv (UDCell u, UCell v); |
| 432 : |
|
|
DCell smdiv (DCell num, Cell denom); |
| 433 : |
|
|
DCell fmdiv (DCell num, Cell denom); |
| 434 : |
|
|
|
| 435 : |
pazsan
|
1.7
|
Cell memcasecmp(const Char *s1, const Char *s2, Cell n); |
| 436 : |
anton
|
1.1
|
|
| 437 : |
anton
|
1.18
|
void vm_print_profile(FILE *file); |
| 438 : |
|
|
void vm_count_block(Xt *ip); |
| 439 : |
anton
|
1.17
|
|
| 440 : |
anton
|
1.22
|
/* dynamic superinstruction stuff */ |
| 441 : |
anton
|
1.33
|
void compile_prim1(Cell *start); |
| 442 : |
|
|
void finish_code(void); |
| 443 : |
anton
|
1.34
|
int forget_dyncode(Address code); |
| 444 : |
|
|
Label decompile_code(Label prim); |
| 445 : |
anton
|
1.17
|
|
| 446 : |
anton
|
1.1
|
extern int offset_image; |
| 447 : |
anton
|
1.5
|
extern int die_on_signal; |
| 448 : |
anton
|
1.74
|
extern int ignore_async_signals; |
| 449 : |
anton
|
1.10
|
extern UCell pagesize; |
| 450 : |
|
|
extern ImageHeader *gforth_header; |
| 451 : |
anton
|
1.19
|
extern Label *vm_prims; |
| 452 : |
anton
|
1.24
|
extern Label *xts; |
| 453 : |
anton
|
1.25
|
extern Cell npriminfos; |
| 454 : |
pazsan
|
1.2
|
|
| 455 : |
anton
|
1.31
|
#ifdef HAS_DEBUG |
| 456 : |
|
|
extern int debug; |
| 457 : |
|
|
#else |
| 458 : |
|
|
# define debug 0 |
| 459 : |
|
|
#endif |
| 460 : |
|
|
|
| 461 : |
pazsan
|
1.71
|
extern Cell *gforth_SP; |
| 462 : |
pazsan
|
1.100
|
extern Cell *gforth_RP; |
| 463 : |
|
|
extern Address gforth_LP; |
| 464 : |
pazsan
|
1.71
|
extern Float *gforth_FP; |
| 465 : |
|
|
extern Address gforth_UP; |
| 466 : |
pazsan
|
1.101
|
#ifndef HAS_LINKBACK |
| 467 : |
|
|
extern void * gforth_pointers[]; |
| 468 : |
|
|
#endif |
| 469 : |
anton
|
1.35
|
|
| 470 : |
pazsan
|
1.53
|
#ifdef HAS_FFCALL |
| 471 : |
pazsan
|
1.71
|
extern Cell *gforth_RP; |
| 472 : |
|
|
extern Address gforth_LP; |
| 473 : |
|
|
extern void gforth_callback(Xt* fcall, void * alist); |
| 474 : |
pazsan
|
1.53
|
#endif |
| 475 : |
|
|
|
| 476 : |
anton
|
1.35
|
#ifdef NO_IP |
| 477 : |
|
|
extern Label next_code; |
| 478 : |
|
|
#endif |
| 479 : |
|
|
|
| 480 : |
|
|
#ifdef HAS_FILE |
| 481 : |
|
|
extern char* fileattr[6]; |
| 482 : |
|
|
extern char* pfileattr[6]; |
| 483 : |
|
|
extern int ufileattr[6]; |
| 484 : |
anton
|
1.9
|
#endif |
| 485 : |
|
|
|
| 486 : |
anton
|
1.27
|
#ifdef PRINT_SUPER_LENGTHS |
| 487 : |
|
|
Cell prim_length(Cell prim); |
| 488 : |
|
|
void print_super_lengths(); |
| 489 : |
|
|
#endif |
| 490 : |
anton
|
1.9
|
|
| 491 : |
pazsan
|
1.2
|
/* declare all the functions that are missing */ |
| 492 : |
|
|
#ifndef HAVE_ATANH |
| 493 : |
|
|
extern double atanh(double r1); |
| 494 : |
|
|
extern double asinh(double r1); |
| 495 : |
|
|
extern double acosh(double r1); |
| 496 : |
|
|
#endif |
| 497 : |
|
|
#ifndef HAVE_ECVT |
| 498 : |
anton
|
1.4
|
/* extern char* ecvt(double x, int len, int* exp, int* sign);*/ |
| 499 : |
pazsan
|
1.2
|
#endif |
| 500 : |
|
|
#ifndef HAVE_MEMMOVE |
| 501 : |
anton
|
1.3
|
/* extern char *memmove(char *dest, const char *src, long n); */ |
| 502 : |
pazsan
|
1.2
|
#endif |
| 503 : |
|
|
#ifndef HAVE_POW10 |
| 504 : |
|
|
extern double pow10(double x); |
| 505 : |
|
|
#endif |
| 506 : |
|
|
#ifndef HAVE_STRERROR |
| 507 : |
|
|
extern char *strerror(int err); |
| 508 : |
|
|
#endif |
| 509 : |
|
|
#ifndef HAVE_STRSIGNAL |
| 510 : |
|
|
extern char *strsignal(int sig); |
| 511 : |
|
|
#endif |
| 512 : |
|
|
#ifndef HAVE_STRTOUL |
| 513 : |
anton
|
1.3
|
extern unsigned long int strtoul(const char *nptr, char **endptr, int base); |
| 514 : |
pazsan
|
1.2
|
#endif |
| 515 : |
|
|
|
| 516 : |
pazsan
|
1.37
|
#define GROUP(x, n) |
| 517 : |
pazsan
|
1.53
|
#define GROUPADD(n) |