Merge tag 'upstream/0.2.1'
[debian/yforth] / toolse.c
1 /* yForth? - A Forth interpreter written in ANSI C
2  * Copyright (C) 2012 Luca Padovani
3  *
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.
8  *
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.
13  *
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: toolse.c
18  * Abstract:    Programming Tools extension word set
19  */
20
21 #include <stdio.h>
22 #include <stdlib.h>
23 #include "yforth.h"
24 #include "toolse.h"
25 #include "core.h"
26 #include "coree.h"
27 #include "block.h"
28
29 /**************************************************************************/
30 /* WORDS ******************************************************************/
31 /**************************************************************************/
32
33 void _bye() {
34 #if BLOCK_DEF
35         close_block_file();
36 #endif
37     exit(0);
38 }
39
40 void _ahead() {
41         compile_cell((Cell) _branch);
42         *--sp = (Cell) _dp;
43         compile_cell(0);
44 }
45
46 void _bracket_if() {
47         register Cell flag = *sp++;
48         register Cell nest = 1;
49         register Cell ok = FFLAG(1);
50         if (!flag) {
51                 do {
52                         _b_l();
53                         _word();
54                         sp++;
55                         if (!*_dp) {
56                                 _refill();
57                                 ok = *sp++;
58                         } else {
59                                 if (!strmatch("[IF]", _dp, 4)) nest++;
60                                 else if (!strmatch("[THEN]", _dp, 6) ||
61                                                  (!strmatch("[ELSE]", _dp, 6) && nest == 1)) nest--;
62                         }
63                 } while (nest && ok);
64         }
65 }
66
67 void _bracket_else() {
68         register Cell nest = 1;
69         register Cell ok = FFLAG(1);
70         do {
71                 _b_l();
72                 _word();
73                 sp++;
74                 if (!*_dp) {
75                         _refill();
76                         ok = *sp++;
77                 } else {
78                         if (!strmatch("[IF]", _dp, 4)) nest++;
79                         else if (!strmatch("[THEN]", _dp, 6)) nest--;
80                 }
81         } while (nest && ok);
82 }
83
84 void _bracket_then() {
85 }
86