Annotation of gforth/engine/forth.h, revision 1.56
1.1 anton 1: /* common header file
2:
1.51 anton 3: Copyright (C) 1995,1996,1997,1998,2000,2003 Free Software Foundation, Inc.
1.1 anton 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
1.13 anton 19: Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
1.1 anton 20: */
21:
22: #include "config.h"
1.18 anton 23: #include <stdio.h>
1.35 anton 24: #include <sys/time.h>
25: #include <unistd.h>
1.1 anton 26:
1.32 anton 27: #if defined(DOUBLY_INDIRECT)||defined(INDIRECT_THREADED)||defined(VM_PROFILING)
28: #define NO_DYNAMIC
29: #endif
30:
1.1 anton 31: #if defined(DOUBLY_INDIRECT)
32: # undef DIRECT_THREADED
33: # undef INDIRECT_THREADED
34: # define INDIRECT_THREADED
35: #endif
36:
1.23 anton 37: #if defined(GFORTH_DEBUGGING)
38: # undef USE_TOS
39: # undef USE_FTOS
1.56 ! anton 40: # undef USE_NO_TOS
! 41: # undef USE_NO_FTOS
1.23 anton 42: # define USE_NO_TOS
43: # define USE_NO_FTOS
44: #endif
45:
1.1 anton 46: #include <limits.h>
47:
48: #if defined(NeXT)
49: # include <libc.h>
50: #endif /* NeXT */
51:
52: /* symbol indexed constants */
53:
54: #define DOCOL 0
55: #define DOCON 1
56: #define DOVAR 2
57: #define DOUSER 3
58: #define DODEFER 4
59: #define DOFIELD 5
60: #define DODOES 6
61: #define DOESJUMP 7
62:
63: /* the size of the DOESJUMP, which resides between DOES> and the does-code */
64: #define DOES_HANDLER_SIZE (2*sizeof(Cell))
65:
1.6 jwilke 66: #include "machine.h"
1.1 anton 67:
68: /* Forth data types */
69: /* Cell and UCell must be the same size as a pointer */
70: #define CELL_BITS (sizeof(Cell) * CHAR_BIT)
71: #define FLAG(b) (-(b))
72: #define FILEIO(error) (FLAG(error) & -37)
73: #define FILEEXIST(error) (FLAG(error) & -38)
74:
75: #define F_TRUE (FLAG(0==0))
76: #define F_FALSE (FLAG(0!=0))
77:
78: #ifdef BUGGY_LONG_LONG
79: typedef struct {
80: Cell hi;
81: UCell lo;
82: } DCell;
83:
84: typedef struct {
85: UCell hi;
86: UCell lo;
87: } UDCell;
88:
1.39 anton 89: #if SMALL_OFF_T
90: #define OFF2UD(o) ({UDCell _ud; _ud.hi=0; _ud.lo=(Cell)(o); _ud;})
91: #define UD2OFF(ud) ((ud).lo)
92: #else /* !SMALL_OFF_T */
93: #define OFF2UD(o) ({UDCell _ud; off_t _o=(o); _ud.hi=_o>>CELL_BITS; _ud.lo=(Cell)_o; _ud;})
1.36 anton 94: #define UD2OFF(ud) ({UDCell _ud=(ud); (((off_t)_ud.hi)<<CELL_BITS)+_ud.lo;})
1.39 anton 95: #endif /* !SMALL_OFF_T */
1.1 anton 96: #define DZERO ((DCell){0,0})
97:
98: #else /* ! defined(BUGGY_LONG_LONG) */
99:
100: /* DCell and UDCell must be twice as large as Cell */
101: typedef DOUBLE_CELL_TYPE DCell;
102: typedef unsigned DOUBLE_CELL_TYPE UDCell;
103:
1.36 anton 104: #define OFF2UD(o) ((UDCell)(o))
105: #define UD2OFF(ud) ((off_t)(ud))
1.16 anton 106: #define DZERO ((DCell)0)
107:
108: #endif /* ! defined(BUGGY_LONG_LONG) */
109:
1.1 anton 110: typedef union {
111: struct {
1.16 anton 112: #if defined(WORDS_BIGENDIAN)||defined(BUGGY_LONG_LONG)
1.1 anton 113: Cell high;
114: UCell low;
115: #else
116: UCell low;
117: Cell high;
1.20 crook 118: #endif
1.1 anton 119: } cells;
1.16 anton 120: DCell d;
121: UDCell ud;
1.1 anton 122: } Double_Store;
123:
1.16 anton 124: #define FETCH_DCELL_T(d_,lo,hi,t_) ({ \
1.1 anton 125: Double_Store _d; \
126: _d.cells.low = (lo); \
127: _d.cells.high = (hi); \
1.16 anton 128: (d_) = _d.t_; \
1.1 anton 129: })
130:
1.16 anton 131: #define STORE_DCELL_T(d_,lo,hi,t_) ({ \
1.1 anton 132: Double_Store _d; \
1.16 anton 133: _d.t_ = (d_); \
1.1 anton 134: (lo) = _d.cells.low; \
135: (hi) = _d.cells.high; \
136: })
137:
1.28 anton 138: #define vm_twoCell2d(lo,hi,d_) FETCH_DCELL_T(d_,lo,hi,d);
139: #define vm_twoCell2ud(lo,hi,d_) FETCH_DCELL_T(d_,lo,hi,ud);
1.1 anton 140:
1.28 anton 141: #define vm_d2twoCell(d_,lo,hi) STORE_DCELL_T(d_,lo,hi,d);
142: #define vm_ud2twoCell(d_,lo,hi) STORE_DCELL_T(d_,lo,hi,ud);
1.1 anton 143:
144: typedef Label *Xt;
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) */
1.24 anton 157: # define DOES_CA ((Label)&xts[DODOES])
1.1 anton 158: #endif /* defined(DOUBLY_INDIRECT) */
159:
160:
161:
162: #define DOES_CODE1(cfa) ((Xt *)(cfa[1]))
163: /* MAKE_CF creates an appropriate code field at the cfa;
164: ca is the code address */
165: #define MAKE_CF(cfa,ca) ((*(Label *)(cfa)) = ((Label)ca))
166: /* make a code field for a defining-word-defined word */
167: #define MAKE_DOES_CF(cfa,does_code) ({MAKE_CF(cfa,DOES_CA); \
168: ((Cell *)cfa)[1] = (Cell)(does_code);})
169:
170: #define CF(const) (-const-2)
171:
172: #define CF_NIL -1
173:
174: #ifndef FLUSH_ICACHE
175: #warning flush-icache probably will not work (see manual)
176: # define FLUSH_ICACHE(addr,size)
1.45 anton 177: #warning no FLUSH_ICACHE, turning off dynamic native code by default
178: #undef NO_DYNAMIC_DEFAULT
179: #define NO_DYNAMIC_DEFAULT 1
1.1 anton 180: #endif
181:
182: #ifdef USE_TOS
1.14 anton 183: #define IF_spTOS(x) x
1.1 anton 184: #else
1.14 anton 185: #define IF_spTOS(x)
186: #define spTOS (sp[0])
1.1 anton 187: #endif
188:
189: #ifdef USE_FTOS
1.14 anton 190: #define IF_fpTOS(x) x
1.1 anton 191: #else
1.14 anton 192: #define IF_fpTOS(x)
193: #define fpTOS (fp[0])
1.1 anton 194: #endif
195:
1.15 anton 196: #define IF_rpTOS(x)
197: #define rpTOS (rp[0])
198:
1.10 anton 199: typedef struct {
200: Address base; /* base address of image (0 if relocatable) */
201: UCell checksum; /* checksum of ca's to protect against some
202: incompatible binary/executable combinations
203: (0 if relocatable) */
204: UCell image_size; /* all sizes in bytes */
205: UCell dict_size;
206: UCell data_stack_size;
207: UCell fp_stack_size;
208: UCell return_stack_size;
209: UCell locals_stack_size;
210: Xt *boot_entry; /* initial ip for booting (in BOOT) */
211: Xt *throw_entry; /* ip after signal (in THROW) */
212: Cell unused1; /* possibly tib stack size */
1.24 anton 213: Label *xt_base; /* base of DOUBLE_INDIRECT xts[], for comp-i.fs */
1.10 anton 214: Address data_stack_base; /* this and the following fields are initialized by the loader */
215: Address fp_stack_base;
216: Address return_stack_base;
217: Address locals_stack_base;
218: } ImageHeader;
219: /* the image-header is created in main.fs */
220:
1.48 anton 221: struct Longname {
222: struct Longname *next; /* the link field for old hands */
223: Cell countetc;
224: char name[0];
225: };
226:
227: #define LONGNAME_COUNT(np) ((np)->countetc & (((~((UCell)0))<<3)>>3))
228:
229: struct Cellpair {
230: Cell n1;
231: Cell n2;
232: };
233:
234: struct Cellquad {
235: Cell n1;
236: Cell n2;
237: Cell n3;
238: Cell n4;
239: };
1.49 anton 240:
241: #define IOR(flag) ((flag)? -512-errno : 0)
1.48 anton 242:
1.1 anton 243: Label *engine(Xt *ip, Cell *sp, Cell *rp, Float *fp, Address lp);
1.42 anton 244: Label *engine2(Xt *ip, Cell *sp, Cell *rp, Float *fp, Address lp);
245: Label *engine3(Xt *ip, Cell *sp, Cell *rp, Float *fp, Address lp);
1.48 anton 246:
247: /* engine/prim support routines */
1.1 anton 248: Address my_alloc(Cell size);
1.35 anton 249: char *cstr(Char *from, UCell size, int clear);
1.11 anton 250: char *tilde_cstr(Char *from, UCell size, int clear);
1.35 anton 251: DCell timeval2us(struct timeval *tvp);
1.48 anton 252: void cmove(Char *c_from, Char *c_to, UCell u);
253: void cmove_up(Char *c_from, Char *c_to, UCell u);
254: Cell compare(Char *c_addr1, UCell u1, Char *c_addr2, UCell u2);
255: struct Longname *listlfind(Char *c_addr, UCell u, struct Longname *longname1);
256: struct Longname *hashlfind(Char *c_addr, UCell u, Cell *a_addr);
257: struct Longname *tablelfind(Char *c_addr, UCell u, Cell *a_addr);
258: UCell hashkey1(Char *c_addr, UCell u, UCell ubits);
259: struct Cellpair parse_white(Char *c_addr1, UCell u1);
260: Cell rename_file(Char *c_addr1, UCell u1, Char *c_addr2, UCell u2);
261: struct Cellquad read_line(Char *c_addr, UCell u1, Cell wfileid);
262: struct Cellpair file_status(Char *c_addr, UCell u);
263: Cell to_float(Char *c_addr, UCell u, Float *rp);
264: Float v_star(Float *f_addr1, Cell nstride1, Float *f_addr2, Cell nstride2, UCell ucount);
265: void faxpy(Float ra, Float *f_x, Cell nstridex, Float *f_y, Cell nstridey, UCell ucount);
1.1 anton 266:
1.50 anton 267: /* signal handler stuff */
268: void install_signal_handlers(void);
269: typedef void Sigfunc(int);
270: Sigfunc *bsd_signal(int signo, Sigfunc *func);
271:
1.1 anton 272: /* dblsub routines */
273: DCell dnegate(DCell d1);
274: UDCell ummul (UCell a, UCell b);
275: DCell mmul (Cell a, Cell b);
276: UDCell umdiv (UDCell u, UCell v);
277: DCell smdiv (DCell num, Cell denom);
278: DCell fmdiv (DCell num, Cell denom);
279:
1.7 pazsan 280: Cell memcasecmp(const Char *s1, const Char *s2, Cell n);
1.1 anton 281:
1.18 anton 282: void vm_print_profile(FILE *file);
283: void vm_count_block(Xt *ip);
1.17 anton 284:
1.22 anton 285: /* dynamic superinstruction stuff */
1.33 anton 286: void compile_prim1(Cell *start);
287: void finish_code(void);
1.34 anton 288: int forget_dyncode(Address code);
289: Label decompile_code(Label prim);
1.17 anton 290:
1.1 anton 291: extern int offset_image;
1.5 anton 292: extern int die_on_signal;
1.10 anton 293: extern UCell pagesize;
294: extern ImageHeader *gforth_header;
1.19 anton 295: extern Label *vm_prims;
1.24 anton 296: extern Label *xts;
1.25 anton 297: extern Cell npriminfos;
1.2 pazsan 298:
1.31 anton 299: #ifdef HAS_DEBUG
300: extern int debug;
301: #else
302: # define debug 0
303: #endif
304:
1.35 anton 305: extern Cell *SP;
306: extern Float *FP;
307: extern Address UP;
308:
1.53 pazsan 309: #ifdef HAS_FFCALL
310: extern Cell *RP;
311: extern Address LP;
1.54 pazsan 312: extern void engine_callback(Xt* fcall, void * alist);
1.53 pazsan 313: #endif
314:
1.9 anton 315: #ifdef GFORTH_DEBUGGING
1.29 anton 316: extern Xt *saved_ip;
1.9 anton 317: extern Cell *rp;
1.35 anton 318: #endif
319:
320: #ifdef NO_IP
321: extern Label next_code;
322: #endif
323:
324: #ifdef HAS_FILE
325: extern char* fileattr[6];
326: extern char* pfileattr[6];
327: extern int ufileattr[6];
1.9 anton 328: #endif
329:
1.27 anton 330: #ifdef PRINT_SUPER_LENGTHS
331: Cell prim_length(Cell prim);
332: void print_super_lengths();
333: #endif
1.9 anton 334:
1.2 pazsan 335: /* declare all the functions that are missing */
336: #ifndef HAVE_ATANH
337: extern double atanh(double r1);
338: extern double asinh(double r1);
339: extern double acosh(double r1);
340: #endif
341: #ifndef HAVE_ECVT
1.4 anton 342: /* extern char* ecvt(double x, int len, int* exp, int* sign);*/
1.2 pazsan 343: #endif
344: #ifndef HAVE_MEMMOVE
1.3 anton 345: /* extern char *memmove(char *dest, const char *src, long n); */
1.2 pazsan 346: #endif
347: #ifndef HAVE_POW10
348: extern double pow10(double x);
349: #endif
350: #ifndef HAVE_STRERROR
351: extern char *strerror(int err);
352: #endif
353: #ifndef HAVE_STRSIGNAL
354: extern char *strsignal(int sig);
355: #endif
356: #ifndef HAVE_STRTOUL
1.3 anton 357: extern unsigned long int strtoul(const char *nptr, char **endptr, int base);
1.2 pazsan 358: #endif
359:
360:
1.37 pazsan 361: #define GROUP(x, n)
1.53 pazsan 362: #define GROUPADD(n)
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>