[gforth] / gforth / engine / forth.h  

gforth: gforth/engine/forth.h


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

CVS Admin

Powered by ViewCVS 1.0-dev
(Powered by ViewCVS)

ViewCVS and CVS Help