[gforth] / gforth / engine / forth.h  

gforth: gforth/engine/forth.h


1 : anton 1.1 /* common header file
2 :    
3 : anton 1.12 Copyright (C) 1995,1996,1997,1998,2000 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 :     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 : anton 1.13 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
20 : anton 1.1 */
21 :    
22 :     #include "config.h"
23 : anton 1.18 #include <stdio.h>
24 : anton 1.35 #include <sys/time.h>
25 :     #include <unistd.h>
26 : anton 1.1
27 : anton 1.32 #if defined(DOUBLY_INDIRECT)||defined(INDIRECT_THREADED)||defined(VM_PROFILING)
28 :     #define NO_DYNAMIC
29 :     #endif
30 :    
31 : anton 1.1 #if defined(DOUBLY_INDIRECT)
32 :     # undef DIRECT_THREADED
33 :     # undef INDIRECT_THREADED
34 :     # define INDIRECT_THREADED
35 :     #endif
36 :    
37 : anton 1.23 #if defined(GFORTH_DEBUGGING)
38 :     # undef USE_TOS
39 :     # undef USE_FTOS
40 :     # define USE_NO_TOS
41 :     # define USE_NO_FTOS
42 :     #endif
43 :    
44 : anton 1.1 #include <limits.h>
45 :    
46 :     #if defined(NeXT)
47 :     # include <libc.h>
48 :     #endif /* NeXT */
49 :    
50 :     /* symbol indexed constants */
51 :    
52 :     #define DOCOL 0
53 :     #define DOCON 1
54 :     #define DOVAR 2
55 :     #define DOUSER 3
56 :     #define DODEFER 4
57 :     #define DOFIELD 5
58 :     #define DODOES 6
59 :     #define DOESJUMP 7
60 :    
61 :     /* the size of the DOESJUMP, which resides between DOES> and the does-code */
62 :     #define DOES_HANDLER_SIZE (2*sizeof(Cell))
63 :    
64 : jwilke 1.6 #include "machine.h"
65 : anton 1.1
66 :     /* Forth data types */
67 :     /* Cell and UCell must be the same size as a pointer */
68 :     #define CELL_BITS (sizeof(Cell) * CHAR_BIT)
69 :     #define FLAG(b) (-(b))
70 :     #define FILEIO(error) (FLAG(error) & -37)
71 :     #define FILEEXIST(error) (FLAG(error) & -38)
72 :    
73 :     #define F_TRUE (FLAG(0==0))
74 :     #define F_FALSE (FLAG(0!=0))
75 :    
76 :     #ifdef BUGGY_LONG_LONG
77 :     typedef struct {
78 :     Cell hi;
79 :     UCell lo;
80 :     } DCell;
81 :    
82 :     typedef struct {
83 :     UCell hi;
84 :     UCell lo;
85 :     } UDCell;
86 :    
87 : anton 1.39 #if SMALL_OFF_T
88 :     #define OFF2UD(o) ({UDCell _ud; _ud.hi=0; _ud.lo=(Cell)(o); _ud;})
89 :     #define UD2OFF(ud) ((ud).lo)
90 :     #else /* !SMALL_OFF_T */
91 :     #define OFF2UD(o) ({UDCell _ud; off_t _o=(o); _ud.hi=_o>>CELL_BITS; _ud.lo=(Cell)_o; _ud;})
92 : anton 1.36 #define UD2OFF(ud) ({UDCell _ud=(ud); (((off_t)_ud.hi)<<CELL_BITS)+_ud.lo;})
93 : anton 1.39 #endif /* !SMALL_OFF_T */
94 : anton 1.1 #define DZERO ((DCell){0,0})
95 :    
96 :     #else /* ! defined(BUGGY_LONG_LONG) */
97 :    
98 :     /* DCell and UDCell must be twice as large as Cell */
99 :     typedef DOUBLE_CELL_TYPE DCell;
100 :     typedef unsigned DOUBLE_CELL_TYPE UDCell;
101 :    
102 : anton 1.36 #define OFF2UD(o) ((UDCell)(o))
103 :     #define UD2OFF(ud) ((off_t)(ud))
104 : anton 1.16 #define DZERO ((DCell)0)
105 :    
106 :     #endif /* ! defined(BUGGY_LONG_LONG) */
107 :    
108 : anton 1.1 typedef union {
109 :     struct {
110 : anton 1.16 #if defined(WORDS_BIGENDIAN)||defined(BUGGY_LONG_LONG)
111 : anton 1.1 Cell high;
112 :     UCell low;
113 :     #else
114 :     UCell low;
115 :     Cell high;
116 : crook 1.20 #endif
117 : anton 1.1 } cells;
118 : anton 1.16 DCell d;
119 :     UDCell ud;
120 : anton 1.1 } Double_Store;
121 :    
122 : anton 1.16 #define FETCH_DCELL_T(d_,lo,hi,t_) ({ \
123 : anton 1.1 Double_Store _d; \
124 :     _d.cells.low = (lo); \
125 :     _d.cells.high = (hi); \
126 : anton 1.16 (d_) = _d.t_; \
127 : anton 1.1 })
128 :    
129 : anton 1.16 #define STORE_DCELL_T(d_,lo,hi,t_) ({ \
130 : anton 1.1 Double_Store _d; \
131 : anton 1.16 _d.t_ = (d_); \
132 : anton 1.1 (lo) = _d.cells.low; \
133 :     (hi) = _d.cells.high; \
134 :     })
135 :    
136 : anton 1.28 #define vm_twoCell2d(lo,hi,d_) FETCH_DCELL_T(d_,lo,hi,d);
137 :     #define vm_twoCell2ud(lo,hi,d_) FETCH_DCELL_T(d_,lo,hi,ud);
138 : anton 1.1
139 : anton 1.28 #define vm_d2twoCell(d_,lo,hi) STORE_DCELL_T(d_,lo,hi,d);
140 :     #define vm_ud2twoCell(d_,lo,hi) STORE_DCELL_T(d_,lo,hi,ud);
141 : anton 1.1
142 :     typedef Label *Xt;
143 :    
144 :     /* PFA gives the parameter field address corresponding to a cfa */
145 :     #define PFA(cfa) (((Cell *)cfa)+2)
146 :     /* PFA1 is a special version for use just after a NEXT1 */
147 :     #define PFA1(cfa) PFA(cfa)
148 :     /* CODE_ADDRESS is the address of the code jumped to through the code field */
149 :     #define CODE_ADDRESS(cfa) (*(Xt)(cfa))
150 :    
151 :     /* DOES_CODE is the Forth code does jumps to */
152 :     #if !defined(DOUBLY_INDIRECT)
153 :     # define DOES_CA (symbols[DODOES])
154 :     #else /* defined(DOUBLY_INDIRECT) */
155 : anton 1.24 # define DOES_CA ((Label)&xts[DODOES])
156 : anton 1.1 #endif /* defined(DOUBLY_INDIRECT) */
157 :    
158 :    
159 :    
160 :     #define DOES_CODE1(cfa) ((Xt *)(cfa[1]))
161 :     /* MAKE_CF creates an appropriate code field at the cfa;
162 :     ca is the code address */
163 :     #define MAKE_CF(cfa,ca) ((*(Label *)(cfa)) = ((Label)ca))
164 :     /* make a code field for a defining-word-defined word */
165 :     #define MAKE_DOES_CF(cfa,does_code) ({MAKE_CF(cfa,DOES_CA); \
166 :     ((Cell *)cfa)[1] = (Cell)(does_code);})
167 :     /* the does handler resides between DOES> and the following Forth code */
168 :     /* not needed in indirect threaded code */
169 :     #if defined(DOUBLY_INDIRECT)
170 :     #define MAKE_DOES_HANDLER(addr) MAKE_CF(addr, ((Label)&symbols[DOESJUMP]))
171 :     #else /* !defined(DOUBLY_INDIRECT) */
172 : anton 1.42 #define MAKE_DOES_HANDLER(addr) ((void)0)
173 : anton 1.1 #endif /* !defined(DOUBLY_INDIRECT) */
174 :    
175 : anton 1.29 #ifdef GFORTH_DEBUGGING
176 : anton 1.30 #define NAME(string) { saved_ip=ip; asm(""); }
177 :     /* the asm here is to avoid reordering of following stuff above the
178 :     assignment; this is an old-style asm (no operands), and therefore
179 :     is treated like "asm volatile ..."; i.e., it prevents most
180 :     reorderings across itself. We want the assignment above first,
181 :     because the stack loads may already cause a stack underflow. */
182 : anton 1.29 #elif DEBUG
183 : anton 1.1 # define NAME(string) fprintf(stderr,"%08lx: "string"\n",(Cell)ip);
184 :     #else
185 :     # define NAME(string)
186 :     #endif
187 :    
188 :     #define CF(const) (-const-2)
189 :    
190 :     #define CF_NIL -1
191 :    
192 :     #ifndef FLUSH_ICACHE
193 :     #warning flush-icache probably will not work (see manual)
194 :     # define FLUSH_ICACHE(addr,size)
195 :     #endif
196 :    
197 :     #ifdef USE_TOS
198 : anton 1.14 #define IF_spTOS(x) x
199 : anton 1.1 #else
200 : anton 1.14 #define IF_spTOS(x)
201 :     #define spTOS (sp[0])
202 : anton 1.1 #endif
203 :    
204 :     #ifdef USE_FTOS
205 : anton 1.14 #define IF_fpTOS(x) x
206 : anton 1.1 #else
207 : anton 1.14 #define IF_fpTOS(x)
208 :     #define fpTOS (fp[0])
209 : anton 1.1 #endif
210 :    
211 : anton 1.15 #define IF_rpTOS(x)
212 :     #define rpTOS (rp[0])
213 :    
214 : anton 1.10 typedef struct {
215 :     Address base; /* base address of image (0 if relocatable) */
216 :     UCell checksum; /* checksum of ca's to protect against some
217 :     incompatible binary/executable combinations
218 :     (0 if relocatable) */
219 :     UCell image_size; /* all sizes in bytes */
220 :     UCell dict_size;
221 :     UCell data_stack_size;
222 :     UCell fp_stack_size;
223 :     UCell return_stack_size;
224 :     UCell locals_stack_size;
225 :     Xt *boot_entry; /* initial ip for booting (in BOOT) */
226 :     Xt *throw_entry; /* ip after signal (in THROW) */
227 :     Cell unused1; /* possibly tib stack size */
228 : anton 1.24 Label *xt_base; /* base of DOUBLE_INDIRECT xts[], for comp-i.fs */
229 : anton 1.10 Address data_stack_base; /* this and the following fields are initialized by the loader */
230 :     Address fp_stack_base;
231 :     Address return_stack_base;
232 :     Address locals_stack_base;
233 :     } ImageHeader;
234 :     /* the image-header is created in main.fs */
235 :    
236 : anton 1.1 Label *engine(Xt *ip, Cell *sp, Cell *rp, Float *fp, Address lp);
237 : anton 1.42 Label *engine2(Xt *ip, Cell *sp, Cell *rp, Float *fp, Address lp);
238 :     Label *engine3(Xt *ip, Cell *sp, Cell *rp, Float *fp, Address lp);
239 : anton 1.1 Address my_alloc(Cell size);
240 : anton 1.35 char *cstr(Char *from, UCell size, int clear);
241 : anton 1.11 char *tilde_cstr(Char *from, UCell size, int clear);
242 : anton 1.35 DCell timeval2us(struct timeval *tvp);
243 : anton 1.1
244 :     /* dblsub routines */
245 :     DCell dnegate(DCell d1);
246 :     UDCell ummul (UCell a, UCell b);
247 :     DCell mmul (Cell a, Cell b);
248 :     UDCell umdiv (UDCell u, UCell v);
249 :     DCell smdiv (DCell num, Cell denom);
250 :     DCell fmdiv (DCell num, Cell denom);
251 :    
252 : pazsan 1.7 Cell memcasecmp(const Char *s1, const Char *s2, Cell n);
253 : anton 1.1
254 : anton 1.17 /* peephole routines */
255 :    
256 :     Xt *primtable(Label symbols[], Cell size);
257 :     Cell prepare_peephole_table(Xt xts[]);
258 :     Xt peephole_opt(Xt xt1, Xt xt2, Cell peeptable);
259 : anton 1.18 void vm_print_profile(FILE *file);
260 :     void vm_count_block(Xt *ip);
261 : anton 1.17
262 : anton 1.22 /* dynamic superinstruction stuff */
263 :     Label compile_prim(Label prim);
264 : anton 1.33 void compile_prim1(Cell *start);
265 :     void finish_code(void);
266 : anton 1.34 int forget_dyncode(Address code);
267 :     Label decompile_code(Label prim);
268 : anton 1.17
269 : anton 1.1 extern int offset_image;
270 : anton 1.5 extern int die_on_signal;
271 : anton 1.10 extern UCell pagesize;
272 :     extern ImageHeader *gforth_header;
273 : anton 1.19 extern Label *vm_prims;
274 : anton 1.24 extern Label *xts;
275 : anton 1.25 extern Cell npriminfos;
276 : pazsan 1.2
277 : anton 1.31 #ifdef HAS_DEBUG
278 :     extern int debug;
279 :     #else
280 :     # define debug 0
281 :     #endif
282 :    
283 : anton 1.35 extern Cell *SP;
284 :     extern Float *FP;
285 :     extern Address UP;
286 :    
287 : anton 1.9 #ifdef GFORTH_DEBUGGING
288 : anton 1.29 extern Xt *saved_ip;
289 : anton 1.9 extern Cell *rp;
290 : anton 1.35 #endif
291 :    
292 :     #ifdef NO_IP
293 :     extern Label next_code;
294 :     #endif
295 :    
296 :     #ifdef HAS_FILE
297 :     extern char* fileattr[6];
298 :     extern char* pfileattr[6];
299 :     extern int ufileattr[6];
300 : anton 1.9 #endif
301 :    
302 : anton 1.27 #ifdef PRINT_SUPER_LENGTHS
303 :     Cell prim_length(Cell prim);
304 :     void print_super_lengths();
305 :     #endif
306 : anton 1.9
307 : pazsan 1.2 /* declare all the functions that are missing */
308 :     #ifndef HAVE_ATANH
309 :     extern double atanh(double r1);
310 :     extern double asinh(double r1);
311 :     extern double acosh(double r1);
312 :     #endif
313 :     #ifndef HAVE_ECVT
314 : anton 1.4 /* extern char* ecvt(double x, int len, int* exp, int* sign);*/
315 : pazsan 1.2 #endif
316 :     #ifndef HAVE_MEMMOVE
317 : anton 1.3 /* extern char *memmove(char *dest, const char *src, long n); */
318 : pazsan 1.2 #endif
319 :     #ifndef HAVE_POW10
320 :     extern double pow10(double x);
321 :     #endif
322 :     #ifndef HAVE_STRERROR
323 :     extern char *strerror(int err);
324 :     #endif
325 :     #ifndef HAVE_STRSIGNAL
326 :     extern char *strsignal(int sig);
327 :     #endif
328 :     #ifndef HAVE_STRTOUL
329 : anton 1.3 extern unsigned long int strtoul(const char *nptr, char **endptr, int base);
330 : pazsan 1.2 #endif
331 :    
332 :    
333 : pazsan 1.37 #define GROUP(x, n)

CVS Admin

Powered by ViewCVS 1.0-dev
(Powered by ViewCVS)

ViewCVS and CVS Help