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 * ------------------------------------------------------------------------
8 * Abstract: The Virtual Machine on which is based the whole
17 /* "ip" is the Instruction Pointer of the Virtual Machine. "ip" points to
18 * an array of "pfp", which stands for "primitive function pointer",
19 * in other words an array of pointers to primitive functions.
20 * Roughly speaking, primitive functions are the valid instructions of
21 * the Virtual Machine.
24 pfp *ip; /* Instruction Pointer */
26 Cell *sp, *sp_top, *sp_base; /* various stack pointers... */
27 Cell *rp, *rp_top, *rp_base;
28 Real *fp, *fp_top, *fp_base;
32 static union double_cell dcell; /* Used for double-cell transfer */
35 /* stacks_recovery: called when an exception occurs, it sets all stack
36 * ptrs to their original value.
39 stacks_recovery (void)
46 /* If double-cell transfer is realized with memory-copying, the following
47 * auxiliary procedures are needed
51 get_dcell (Cell * ptr)
54 dcell.d2.low = *(ptr + 1);
59 put_dcell (Cell * ptr, DCell d)
63 *(ptr + 1) = dcell.d2.low;
67 /* sig_fpe_handler: signal handler for math exceptions */
69 sig_fpe_handler (int sig)
71 signal (SIGFPE, sig_fpe_handler);
74 longjmp(warm_start_jump, 1);
77 /* sig_segv_handler: signal handler for segmentation violation */
79 sig_segv_handler (int sig)
81 signal (SIGSEGV, sig_segv_handler);
84 longjmp(warm_start_jump, 1);
87 /* init_signal: initialize signal handlers */
91 signal (SIGFPE, sig_fpe_handler);
92 signal (SIGSEGV, sig_segv_handler);