1 /* yForth? - Written by Luca Padovani (C) 1996/97
2 * ------------------------------------------------------------------------
3 * This software is FreeWare as long as it comes with this header in each
4 * source file, anyway you can use it or any part of it whatever
5 * you want. It comes without any warranty, so use it at your own risk.
6 * ------------------------------------------------------------------------
7 * Module name: yforth.h
8 * Abstract: definition of constants, data types, prototypes, and so on.
20 /* Following definitions may be tuned for a particular system. Note however
21 * that their minimal value is defined by the standard.
24 #define TMP_BUFFER_SIZE 80
25 #define FILE_BUFFER_SIZE 128
26 #define FILE_NAME_SIZE 128
33 /* data structures definitions */
35 typedef void (*pfp)(void);
39 struct word_def *link;
45 struct word_def *voc[VOC_HASH];
48 struct voc_marker { /* MARKER structure */
49 struct vocabulary *list[WORD_LISTS]; /* vocabulary stack */
50 Cell top; /* top of stack */
51 struct vocabulary *voc; /* definition vocabulary */
52 struct vocabulary v_list[WORD_LISTS]; /* content of vocabularies in stack */
53 struct vocabulary v_voc;
54 Char *_dp; /* dictionary pointer */
55 struct word_def *last; /* ptr to last defined word */
64 struct image_header { /* header for image file */
85 DCell get_dcell(Cell *ptr);
86 void put_dcell(Cell *ptr, DCell d);
89 /* Some constant definitions. This should not be changed. */
94 #define BLOCK_SIZE 1024
97 #define COMP_ONLY 0x0100
98 #define IMMEDIATE 0x0200
99 #define CLASS_MASK (~(COMP_ONLY | IMMEDIATE))
101 #define A_PRIMITIVE 0
106 #define A_FCONSTANT 5
107 #define A_FVARIABLE 6
110 #define A_2CONSTANT 9
111 #define A_2VARIABLE 10
118 #define ALIGN_PTR(n) (((((Cell) (n)) - 1) | CellLog) + 1)
119 #define FALIGN_PTR(n) (((((Cell) (n)) - 1) | RealLog) + 1)
120 #define WORD_PTR(ptr) (ALIGN_PTR((ptr) + *(ptr) + sizeof(Char)))
121 #define compile_cell(x) *((Cell *) _dp) = x, _dp += sizeof(Cell)
122 #define compile_real(x) *((Real *) _dp) = x, _dp += sizeof(Real)
123 #define hash_func(name,len) ((len) & (VOC_HASH - 1))
125 # ifdef LITTLE_ENDIAN
126 # define GET_DCELL(ptr) get_dcell((Cell *) ptr)
127 # define PUT_DCELL(ptr, d) put_dcell((Cell *) ptr, (DCell) d)
129 # define GET_DCELL(ptr) *((DCell *) ptr)
130 # define PUT_DCELL(ptr, d) *((DCell *) ptr) = d
133 # ifdef LITTLE_ENDIAN
134 # define GET_DCELL(ptr) ((DCell) (*(((Cell *) ptr) + 1)) + \
135 (((DCell) (*((Cell *) ptr))) << CellBits))
136 # define PUT_DCELL(ptr, d) *(((Cell *) ptr) + 1) = (Cell) d, \
137 *((Cell *) ptr) = (Cell) (d >> CellBits)
139 # define GET_DCELL(ptr) ((DCell) (*((Cell *) ptr)) + \
140 (((DCell) (*(((Cell *) ptr) + 1))) << CellBits))
141 # define PUT_DCELL(ptr, d) *((Cell *) ptr) = (Cell) d, \
142 *(((Cell *) ptr) + 1) = (Cell) (d >> CellBits)
146 #define GET_UDCELL(ptr) ((UDCell) GET_DCELL(ptr))
147 #define PUT_UDCELL(ptr, ud) PUT_DCELL(ptr, ud)
149 /* Global variables */
151 extern jmp_buf warm_start_jump;
153 extern Cell dspace_size;
154 extern Cell dstack_size, rstack_size, fstack_size;
155 extern Cell tib_size;
156 extern Cell in_pnos, pnos_size;
157 extern Char * pnos, * p_pnos;
158 extern Cell pad_size;
160 extern struct vocabulary *list[WORD_LISTS];
161 extern Cell top; /* indice primo vocabolario sulla pila */
162 extern struct vocabulary *voc; /* ptr al vocabolario usato per le definzioni */
163 extern struct vocabulary *forth_wid;
165 /* Global functions prototypes */
167 void init_vocabulary(Char **dp);
168 void init_stacks(int dstack_size, int rstack_size, int fstack_size);
169 void init_data_space(int dspace_size);
170 void init_tib(int size);
171 void init_pad(int size);
172 void init_pnos(void);
173 void init_forth_environment(int reload);
174 void init_signals(void);
175 void print_version(void);
177 /* Virtual Machine registers definition */
181 extern Cell *sp, *sp_top, *sp_base;
182 extern Cell *rp, *rp_top, *rp_base;
183 extern Real *fp, *fp_top, *fp_base;
186 /* Some definitions that may be missing under certain systems or compilers */
201 # define max(a, b) ((a) > (b) ? (a) : (b))