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 * ------------------------------------------------------------------------
18 * Abstract: The Virtual Machine on which is based the whole
27 /* "ip" is the Instruction Pointer of the Virtual Machine. "ip" points to
28 * an array of "pfp", which stands for "primitive function pointer",
29 * in other words an array of pointers to primitive functions.
30 * Roughly speaking, primitive functions are the valid instructions of
31 * the Virtual Machine.
34 pfp *ip; /* Instruction Pointer */
36 Cell *sp, *sp_top, *sp_base; /* various stack pointers... */
37 Cell *rp, *rp_top, *rp_base;
38 Real *fp, *fp_top, *fp_base;
42 static union double_cell dcell; /* Used for double-cell transfer */
45 /* stacks_recovery: called when an exception occurs, it sets all stack
46 * ptrs to their original value.
49 stacks_recovery (void)
56 /* If double-cell transfer is realized with memory-copying, the following
57 * auxiliary procedures are needed
61 get_dcell (Cell * ptr)
64 dcell.d2.low = *(ptr + 1);
69 put_dcell (Cell * ptr, DCell d)
73 *(ptr + 1) = dcell.d2.low;
77 /* sig_fpe_handler: signal handler for math exceptions */
79 sig_fpe_handler (int sig)
81 signal (SIGFPE, sig_fpe_handler);
84 longjmp(warm_start_jump, 1);
87 /* sig_segv_handler: signal handler for segmentation violation */
89 sig_segv_handler (int sig)
91 signal (SIGSEGV, sig_segv_handler);
94 longjmp(warm_start_jump, 1);
97 /* init_signal: initialize signal handlers */
101 signal (SIGFPE, sig_fpe_handler);
102 signal (SIGSEGV, sig_segv_handler);