1 /* yForth? - A Forth interpreter written in ANSI C
2 * Copyright (C) 2012 Luca Padovani
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 * ------------------------------------------------------------------------
17 * Module name: yforth.h
18 * Abstract: definition of constants, data types, prototypes, and so on.
30 /* Following definitions may be tuned for a particular system. Note however
31 * that their minimal value is defined by the standard.
34 #define TMP_BUFFER_SIZE 80
35 #define FILE_BUFFER_SIZE 128
36 #define FILE_NAME_SIZE 128
43 /* data structures definitions */
45 typedef void (*pfp)(void);
49 struct word_def *link;
55 struct word_def *voc[VOC_HASH];
58 struct voc_marker { /* MARKER structure */
59 struct vocabulary *list[WORD_LISTS]; /* vocabulary stack */
60 Cell top; /* top of stack */
61 struct vocabulary *voc; /* definition vocabulary */
62 struct vocabulary v_list[WORD_LISTS]; /* content of vocabularies in stack */
63 struct vocabulary v_voc;
64 Char *_dp; /* dictionary pointer */
65 struct word_def *last; /* ptr to last defined word */
74 struct image_header { /* header for image file */
95 DCell get_dcell(Cell *ptr);
96 void put_dcell(Cell *ptr, DCell d);
99 /* Some constant definitions. This should not be changed. */
104 #define BLOCK_SIZE 1024
107 #define COMP_ONLY 0x0100
108 #define IMMEDIATE 0x0200
109 #define CLASS_MASK (~(COMP_ONLY | IMMEDIATE))
111 #define A_PRIMITIVE 0
116 #define A_FCONSTANT 5
117 #define A_FVARIABLE 6
120 #define A_2CONSTANT 9
121 #define A_2VARIABLE 10
128 #define ALIGN_PTR(n) (((((Cell) (n)) - 1) | CellLog) + 1)
129 #define FALIGN_PTR(n) (((((Cell) (n)) - 1) | RealLog) + 1)
130 #define WORD_PTR(ptr) (ALIGN_PTR((ptr) + *(ptr) + sizeof(Char)))
131 #define compile_cell(x) *((Cell *) _dp) = x, _dp += sizeof(Cell)
132 #define compile_real(x) *((Real *) _dp) = x, _dp += sizeof(Real)
133 #define hash_func(name,len) ((len) & (VOC_HASH - 1))
135 # ifdef LITTLE_ENDIAN
136 # define GET_DCELL(ptr) get_dcell((Cell *) ptr)
137 # define PUT_DCELL(ptr, d) put_dcell((Cell *) ptr, (DCell) d)
139 # define GET_DCELL(ptr) *((DCell *) (ptr))
140 # define PUT_DCELL(ptr, d) *((DCell *) (ptr)) = d
143 # ifdef LITTLE_ENDIAN
144 # define GET_DCELL(ptr) ((DCell) (*(((Cell *) ptr) + 1)) + \
145 (((DCell) (*((Cell *) ptr))) << CellBits))
146 # define PUT_DCELL(ptr, d) *(((Cell *) ptr) + 1) = (Cell) d, \
147 *((Cell *) ptr) = (Cell) (d >> CellBits)
149 # define GET_DCELL(ptr) ((DCell) (*((Cell *) ptr)) + \
150 (((DCell) (*(((Cell *) ptr) + 1))) << CellBits))
151 # define PUT_DCELL(ptr, d) *((Cell *) ptr) = (Cell) d, \
152 *(((Cell *) ptr) + 1) = (Cell) (d >> CellBits)
156 #define GET_UDCELL(ptr) ((UDCell) GET_DCELL(ptr))
157 #define PUT_UDCELL(ptr, ud) PUT_DCELL(ptr, ud)
159 /* Global variables */
161 extern jmp_buf warm_start_jump;
163 extern Cell dspace_size;
164 extern Cell dstack_size, rstack_size, fstack_size;
165 extern Cell tib_size;
166 extern Cell in_pnos, pnos_size;
167 extern Char * pnos, * p_pnos;
168 extern Cell pad_size;
170 extern struct vocabulary *list[WORD_LISTS];
171 extern Cell top; /* indice primo vocabolario sulla pila */
172 extern struct vocabulary *voc; /* ptr al vocabolario usato per le definzioni */
173 extern struct vocabulary *forth_wid;
175 /* Global functions prototypes */
177 void init_vocabulary(Char **dp);
178 void init_stacks(int dstack_size, int rstack_size, int fstack_size);
179 void init_data_space(int dspace_size);
180 void init_tib(int size);
181 void init_pad(int size);
182 void init_pnos(void);
183 void init_forth_environment(int reload);
184 void init_signals(void);
185 void print_version(void);
187 /* Virtual Machine registers definition */
191 extern Cell *sp, *sp_top, *sp_base;
192 extern Cell *rp, *rp_top, *rp_base;
193 extern Real *fp, *fp_top, *fp_base;
196 /* Some definitions that may be missing under certain systems or compilers */
211 # define max(a, b) ((a) > (b) ? (a) : (b))