Annotation of gforth/engine/forth.h, revision 1.5

1.1       anton       1: /* 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: */
                     21: 
                     22: #include "config.h"
                     23: 
                     24: #if defined(DOUBLY_INDIRECT)
                     25: #  undef DIRECT_THREADED
                     26: #  undef INDIRECT_THREADED
                     27: #  define INDIRECT_THREADED
                     28: #endif
                     29: 
                     30: #include <limits.h>
                     31: 
                     32: #if defined(NeXT)
                     33: #  include <libc.h>
                     34: #endif /* NeXT */
                     35: 
                     36: #if defined(DOUBLY_INDIRECT)
                     37: typedef void **Label;
                     38: #else /* !defined(DOUBLY_INDIRECT) */
                     39: typedef void *Label;
                     40: #endif /* !defined(DOUBLY_INDIRECT) */
                     41: 
                     42: /* symbol indexed constants */
                     43: 
                     44: #define DOCOL  0
                     45: #define DOCON  1
                     46: #define DOVAR  2
                     47: #define DOUSER 3
                     48: #define DODEFER        4
                     49: #define DOFIELD        5
                     50: #define DODOES 6
                     51: #define DOESJUMP       7
                     52: 
                     53: /* the size of the DOESJUMP, which resides between DOES> and the does-code */
                     54: #define DOES_HANDLER_SIZE      (2*sizeof(Cell))
                     55: 
                     56: #include "../machine/machine.h"
                     57: 
                     58: /* Forth data types */
                     59: /* Cell and UCell must be the same size as a pointer */
                     60: typedef CELL_TYPE Cell;
                     61: typedef unsigned CELL_TYPE UCell;
                     62: #define CELL_BITS      (sizeof(Cell) * CHAR_BIT)
                     63: typedef Cell Bool;
                     64: #define FLAG(b) (-(b))
                     65: #define FILEIO(error)  (FLAG(error) & -37)
                     66: #define FILEEXIST(error)       (FLAG(error) & -38)
                     67: 
                     68: #define F_TRUE (FLAG(0==0))
                     69: #define F_FALSE (FLAG(0!=0))
                     70: 
                     71: typedef unsigned char Char;
                     72: typedef double Float;
                     73: typedef char *Address;
                     74: 
                     75: #ifdef BUGGY_LONG_LONG
                     76: typedef struct {
                     77:   Cell hi;
                     78:   UCell lo;
                     79: } DCell;
                     80: 
                     81: typedef struct {
                     82:   UCell hi;
                     83:   UCell lo;
                     84: } UDCell;
                     85: 
                     86: #define FETCH_DCELL(d,lo,hi)   ((d)=(typeof(d)){(hi),(lo)})
                     87: #define STORE_DCELL(d,low,high)        ({ \
                     88:                                     typeof(d) _d = (d); \
                     89:                                     (low) = _d.lo; \
                     90:                                     (high)= _d.hi; \
                     91:                                 })
                     92: 
                     93: #define LONG2UD(l)     ({UDCell _ud; _ud.hi=0; _ud.lo=(Cell)(l); _ud;})
                     94: #define UD2LONG(ud)    ((long)(ud.lo))
                     95: #define DZERO          ((DCell){0,0})
                     96: 
                     97: #else /* ! defined(BUGGY_LONG_LONG) */
                     98: 
                     99: /* DCell and UDCell must be twice as large as Cell */
                    100: typedef DOUBLE_CELL_TYPE DCell;
                    101: typedef unsigned DOUBLE_CELL_TYPE UDCell;
                    102: 
                    103: typedef union {
                    104:   struct {
                    105: #ifdef WORDS_BIGENDIAN
                    106:     Cell high;
                    107:     UCell low;
                    108: #else
                    109:     UCell low;
                    110:     Cell high;
                    111: #endif;
                    112:   } cells;
                    113:   DCell dcell;
                    114: } Double_Store;
                    115: 
                    116: #define FETCH_DCELL(d,lo,hi)   ({ \
                    117:                                     Double_Store _d; \
                    118:                                     _d.cells.low = (lo); \
                    119:                                     _d.cells.high = (hi); \
                    120:                                     (d) = _d.dcell; \
                    121:                                 })
                    122: 
                    123: #define STORE_DCELL(d,lo,hi)   ({ \
                    124:                                     Double_Store _d; \
                    125:                                     _d.dcell = (d); \
                    126:                                     (lo) = _d.cells.low; \
                    127:                                     (hi) = _d.cells.high; \
                    128:                                 })
                    129: 
                    130: #define LONG2UD(l)     ((UDCell)(l))
                    131: #define UD2LONG(ud)    ((long)(ud))
                    132: #define DZERO          ((DCell)0)
                    133: 
                    134: #endif /* ! defined(BUGGY_LONG_LONG) */
                    135: 
                    136: #ifdef DIRECT_THREADED
                    137: typedef Label Xt;
                    138: #else
                    139: typedef Label *Xt;
                    140: #endif
                    141: 
                    142: 
                    143: #if !defined(DIRECT_THREADED)
                    144: /* i.e. indirect threaded our doubly indirect threaded */
                    145: /* the direct threaded version is machine dependent and resides in machine.h */
                    146: 
                    147: /* PFA gives the parameter field address corresponding to a cfa */
                    148: #define PFA(cfa)       (((Cell *)cfa)+2)
                    149: /* PFA1 is a special version for use just after a NEXT1 */
                    150: #define PFA1(cfa)      PFA(cfa)
                    151: /* CODE_ADDRESS is the address of the code jumped to through the code field */
                    152: #define CODE_ADDRESS(cfa)      (*(Xt)(cfa))
                    153: 
                    154: /* DOES_CODE is the Forth code does jumps to */
                    155: #if !defined(DOUBLY_INDIRECT)
                    156: #  define DOES_CA (symbols[DODOES])
                    157: #else /* defined(DOUBLY_INDIRECT) */
                    158: #  define DOES_CA ((Label)&symbols[DODOES])
                    159: #endif /* defined(DOUBLY_INDIRECT) */
                    160: 
                    161: 
                    162: 
                    163: #define DOES_CODE(cfa) ({Xt _cfa=(Xt)(cfa); \
                    164:                          (Xt *)(_cfa[0]==DOES_CA ? _cfa[1] : NULL);})
                    165: #define DOES_CODE1(cfa)        ((Xt *)(cfa[1]))
                    166: /* MAKE_CF creates an appropriate code field at the cfa;
                    167:    ca is the code address */
                    168: #define MAKE_CF(cfa,ca) ((*(Label *)(cfa)) = ((Label)ca))
                    169: /* make a code field for a defining-word-defined word */
                    170: #define MAKE_DOES_CF(cfa,does_code)  ({MAKE_CF(cfa,DOES_CA);   \
                    171:                                       ((Cell *)cfa)[1] = (Cell)(does_code);})
                    172: /* the does handler resides between DOES> and the following Forth code */
                    173: /* not needed in indirect threaded code */
                    174: #if defined(DOUBLY_INDIRECT)
                    175: #define MAKE_DOES_HANDLER(addr)        MAKE_CF(addr, ((Label)&symbols[DOESJUMP]))
                    176: #else /* !defined(DOUBLY_INDIRECT) */
                    177: #define MAKE_DOES_HANDLER(addr)        0
                    178: #endif /* !defined(DOUBLY_INDIRECT) */
                    179: #endif /* !defined(DIRECT_THREADED) */
                    180: 
                    181: #ifdef DEBUG
                    182: #      define  NAME(string)    fprintf(stderr,"%08lx: "string"\n",(Cell)ip);
                    183: #else
                    184: #      define  NAME(string)
                    185: #endif
                    186: 
                    187: #define CF(const)      (-const-2)
                    188: 
                    189: #define CF_NIL -1
                    190: 
                    191: #ifndef FLUSH_ICACHE
                    192: #warning flush-icache probably will not work (see manual)
                    193: #      define FLUSH_ICACHE(addr,size)
                    194: #endif
                    195: 
                    196: #if defined(DIRECT_THREADED)
                    197: #define CACHE_FLUSH(addr,size) FLUSH_ICACHE(addr,size)
                    198: #else
                    199: #define CACHE_FLUSH(addr,size)
                    200: #endif
                    201: 
                    202: #ifdef USE_TOS
                    203: #define IF_TOS(x) x
                    204: #else
                    205: #define IF_TOS(x)
                    206: #define TOS (sp[0])
                    207: #endif
                    208: 
                    209: #ifdef USE_FTOS
                    210: #define IF_FTOS(x) x
                    211: #else
                    212: #define IF_FTOS(x)
                    213: #define FTOS (fp[0])
                    214: #endif
                    215: 
                    216: Label *engine(Xt *ip, Cell *sp, Cell *rp, Float *fp, Address lp);
                    217: Address my_alloc(Cell size);
                    218: 
                    219: /* dblsub routines */
                    220: DCell dnegate(DCell d1);
                    221: UDCell ummul (UCell a, UCell b);
                    222: DCell mmul (Cell a, Cell b);
                    223: UDCell umdiv (UDCell u, UCell v);
                    224: DCell smdiv (DCell num, Cell denom);
                    225: DCell fmdiv (DCell num, Cell denom);
                    226: 
                    227: int memcasecmp(const char *s1, const char *s2, long n);
                    228: 
                    229: extern int offset_image;
1.5     ! anton     230: extern int die_on_signal;
1.2       pazsan    231: 
                    232: /* declare all the functions that are missing */
                    233: #ifndef HAVE_ATANH
                    234: extern double atanh(double r1);
                    235: extern double asinh(double r1);
                    236: extern double acosh(double r1);
                    237: #endif
                    238: #ifndef HAVE_ECVT
1.4       anton     239: /* extern char* ecvt(double x, int len, int* exp, int* sign);*/
1.2       pazsan    240: #endif
                    241: #ifndef HAVE_MEMMOVE
1.3       anton     242: /* extern char *memmove(char *dest, const char *src, long n); */
1.2       pazsan    243: #endif
                    244: #ifndef HAVE_POW10
                    245: extern double pow10(double x);
                    246: #endif
                    247: #ifndef HAVE_STRERROR
                    248: extern char *strerror(int err);
                    249: #endif
                    250: #ifndef HAVE_STRSIGNAL
                    251: extern char *strsignal(int sig);
                    252: #endif
                    253: #ifndef HAVE_STRTOUL
1.3       anton     254: extern unsigned long int strtoul(const char *nptr, char **endptr, int base);
1.2       pazsan    255: #endif
                    256: 
                    257: 

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>