Annotation of gforth/forth.h, revision 1.28

1.19      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.
1.1       anton      20: */
                     21: 
1.21      anton      22: #include "config.h"
1.28    ! anton      23: 
        !            24: #if defined(DOUBLY_INDIRECT)
        !            25: #  undef DIRECT_THREADED
        !            26: #  define INDIRECT_THREADED
        !            27: #endif
        !            28: 
1.21      anton      29: #include <limits.h>
1.28    ! anton      30: 
1.26      pazsan     31: #if defined(NeXT)
                     32: #  include <libc.h>
                     33: #endif /* NeXT */
1.21      anton      34: 
1.28    ! anton      35: #if defined(DOUBLY_INDIRECT)
        !            36: typedef void **Label;
        !            37: #else /* !defined(DOUBLY_INDIRECT) */
1.1       anton      38: typedef void *Label;
1.28    ! anton      39: #endif /* !defined(DOUBLY_INDIRECT) */
1.1       anton      40: 
1.2       pazsan     41: /* symbol indexed constants */
                     42: 
                     43: #define DOCOL  0
                     44: #define DOCON  1
                     45: #define DOVAR  2
                     46: #define DOUSER 3
1.8       anton      47: #define DODEFER        4
1.16      anton      48: #define DOFIELD        5
1.14      pazsan     49: #define DODOES 6
                     50: #define DOESJUMP       7
1.6       benschop   51: 
1.28    ! anton      52: /* the size of the DOESJUMP, which resides between DOES> and the does-code */
        !            53: #define DOES_HANDLER_SIZE      (2*sizeof(Cell))
        !            54: 
1.1       anton      55: #include "machine.h"
                     56: 
                     57: /* Forth data types */
1.21      anton      58: /* Cell and UCell must be the same size as a pointer */
                     59: typedef CELL_TYPE Cell;
                     60: typedef unsigned CELL_TYPE UCell;
                     61: #define CELL_BITS      (sizeof(Cell) * CHAR_BIT)
1.20      pazsan     62: typedef Cell Bool;
1.1       anton      63: #define FLAG(b) (-(b))
1.5       pazsan     64: #define FILEIO(error)  (FLAG(error) & -37)
                     65: #define FILEEXIST(error)       (FLAG(error) & -38)
1.1       anton      66: 
                     67: #define F_TRUE (FLAG(0==0))
                     68: #define F_FALSE (FLAG(0!=0))
                     69: 
                     70: typedef unsigned char Char;
                     71: typedef double Float;
                     72: typedef char *Address;
                     73: 
1.21      anton      74: #ifdef BUGGY_LONG_LONG
                     75: typedef struct {
                     76:   Cell hi;
                     77:   UCell lo;
                     78: } DCell;
                     79: 
                     80: typedef struct {
                     81:   UCell hi;
                     82:   UCell lo;
                     83: } UDCell;
                     84: 
                     85: #define FETCH_DCELL(d,lo,hi)   ((d)=(typeof(d)){(hi),(lo)})
                     86: #define STORE_DCELL(d,low,high)        ({ \
                     87:                                     typeof(d) _d = (d); \
                     88:                                     (low) = _d.lo; \
                     89:                                     (high)= _d.hi; \
                     90:                                 })
                     91: 
                     92: #define LONG2UD(l)     ({UDCell _ud; _ud.hi=0; _ud.lo=(Cell)(l); _ud;})
                     93: #define UD2LONG(ud)    ((long)(ud.lo))
                     94: #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: typedef union {
                    103:   struct {
                    104: #ifdef WORDS_BIGENDIAN
                    105:     Cell high;
                    106:     UCell low;
                    107: #else
                    108:     UCell low;
                    109:     Cell high;
                    110: #endif;
                    111:   } cells;
                    112:   DCell dcell;
                    113: } Double_Store;
                    114: 
                    115: #define FETCH_DCELL(d,lo,hi)   ({ \
                    116:                                     Double_Store _d; \
                    117:                                     _d.cells.low = (lo); \
                    118:                                     _d.cells.high = (hi); \
                    119:                                     (d) = _d.dcell; \
                    120:                                 })
                    121: 
                    122: #define STORE_DCELL(d,lo,hi)   ({ \
                    123:                                     Double_Store _d; \
                    124:                                     _d.dcell = (d); \
                    125:                                     (lo) = _d.cells.low; \
                    126:                                     (hi) = _d.cells.high; \
                    127:                                 })
                    128: 
                    129: #define LONG2UD(l)     ((UDCell)(l))
                    130: #define UD2LONG(ud)    ((long)(ud))
                    131: #define DZERO          ((DCell)0)
                    132: 
                    133: #endif /* ! defined(BUGGY_LONG_LONG) */
                    134: 
1.1       anton     135: #ifdef DIRECT_THREADED
                    136: typedef Label Xt;
                    137: #else
                    138: typedef Label *Xt;
                    139: #endif
                    140: 
1.28    ! anton     141: 
        !           142: #if !defined(DIRECT_THREADED)
        !           143: /* i.e. indirect threaded our doubly indirect threaded */
1.1       anton     144: /* the direct threaded version is machine dependent and resides in machine.h */
                    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 */
1.28    ! anton     151: #define CODE_ADDRESS(cfa)      (*(Xt)(cfa))
        !           152: 
1.25      anton     153: /* DOES_CODE is the Forth code does jumps to */
1.28    ! anton     154: #if !defined(DOUBLY_INDIRECT)
        !           155: #  define DOES_CA (symbols[DODOES])
        !           156: #else /* defined(DOUBLY_INDIRECT) */
        !           157: #  define DOES_CA ((Label)&symbols[DODOES])
        !           158: #endif /* defined(DOUBLY_INDIRECT) */
        !           159: 
        !           160: 
        !           161: 
1.24      anton     162: #define DOES_CODE(cfa) ({Xt _cfa=(Xt)(cfa); \
1.28    ! anton     163:                          (Xt *)(_cfa[0]==DOES_CA ? _cfa[1] : NULL);})
        !           164: #define DOES_CODE1(cfa)        ((Xt *)(cfa[1]))
1.1       anton     165: /* MAKE_CF creates an appropriate code field at the cfa;
                    166:    ca is the code address */
                    167: #define MAKE_CF(cfa,ca) ((*(Label *)(cfa)) = ((Label)ca))
                    168: /* make a code field for a defining-word-defined word */
1.28    ! anton     169: #define MAKE_DOES_CF(cfa,does_code)  ({MAKE_CF(cfa,DOES_CA);   \
        !           170:                                       ((Cell *)cfa)[1] = (Cell)(does_code);})
1.1       anton     171: /* the does handler resides between DOES> and the following Forth code */
1.28    ! anton     172: /* not needed in indirect threaded code */
        !           173: #if defined(DOUBLY_INDIRECT)
        !           174: #define MAKE_DOES_HANDLER(addr)        MAKE_CF(addr, ((Label)&symbols[DOESJUMP]))
        !           175: #else /* !defined(DOUBLY_INDIRECT) */
        !           176: #define MAKE_DOES_HANDLER(addr)        0
        !           177: #endif /* !defined(DOUBLY_INDIRECT) */
1.21      anton     178: #endif /* !defined(DIRECT_THREADED) */
1.1       anton     179: 
                    180: #ifdef DEBUG
1.18      pazsan    181: #      define  NAME(string)    fprintf(stderr,"%08lx: "string"\n",(Cell)ip);
1.1       anton     182: #else
                    183: #      define  NAME(string)
                    184: #endif
1.2       pazsan    185: 
                    186: #define CF(const)      (-const-2)
                    187: 
                    188: #define CF_NIL -1
1.3       pazsan    189: 
1.15      anton     190: #ifndef FLUSH_ICACHE
1.16      anton     191: #warning flush-icache probably will not work (see manual)
1.17      pazsan    192: #      define FLUSH_ICACHE(addr,size)
1.15      anton     193: #endif
                    194: 
1.28    ! anton     195: #if defined(DIRECT_THREADED)
1.15      anton     196: #define CACHE_FLUSH(addr,size) FLUSH_ICACHE(addr,size)
                    197: #else
1.17      pazsan    198: #define CACHE_FLUSH(addr,size)
1.3       pazsan    199: #endif
1.21      anton     200: 
1.27      anton     201: #ifdef USE_TOS
                    202: #define IF_TOS(x) x
                    203: #else
                    204: #define IF_TOS(x)
                    205: #define TOS (sp[0])
                    206: #endif
                    207: 
                    208: #ifdef USE_FTOS
                    209: #define IF_FTOS(x) x
                    210: #else
                    211: #define IF_FTOS(x)
                    212: #define FTOS (fp[0])
                    213: #endif
                    214: 
1.21      anton     215: Label *engine(Xt *ip, Cell *sp, Cell *rp, Float *fp, Address lp);
1.28    ! anton     216: Address my_alloc(Cell size);
1.21      anton     217: 
                    218: /* dblsub routines */
                    219: DCell dnegate(DCell d1);
                    220: UDCell ummul (UCell a, UCell b);
                    221: DCell mmul (Cell a, Cell b);
                    222: UDCell umdiv (UDCell u, UCell v);
                    223: DCell smdiv (DCell num, Cell denom);
                    224: DCell fmdiv (DCell num, Cell denom);
                    225: 
1.22      anton     226: int memcasecmp(const char *s1, const char *s2, long n);
                    227: 
1.28    ! anton     228: extern int offset_image;

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