File: tools.c

package info (click to toggle)
yforth 0.2.1-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, jessie, jessie-kfreebsd, sid, stretch
  • size: 396 kB
  • ctags: 788
  • sloc: ansic: 4,426; makefile: 23
file content (86 lines) | stat: -rw-r--r-- 2,091 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
/* yForth? - A Forth interpreter written in ANSI C
 * Copyright (C) 2012 Luca Padovani
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 * ------------------------------------------------------------------------
 * Module name: tools.c
 * Abstract:	Programming Tools word set
 */

#include <stdio.h>
#include "yforth.h"
#include "tools.h"
#include "core.h"

/**************************************************************************/
/* WORDS ******************************************************************/
/**************************************************************************/

void _dot_s() {
	register Cell *p = sp;
	while (p < sp_top) {
		*--sp = *p;
		_dot();
		p++;
	}
}

void _question() {
	_fetch();
	_dot();
}

void _dump() {
	register UCell u = *sp++;
	register Char *addr = (Char *) *sp++;
	while (u) {
		register int i;
		printf("%08p: ", addr);
		for (i = 0; i < 16; i++)
			if ((int) (u - i) > 0) printf("%02x ", *(addr + i) & 0xff);
			else printf("   ");
		for (i = 0; i < 16 && (u - i) > 0; i++)
			printf("%c", *(addr + i) < 32 ? '.' : *(addr + i));
		putchar('\n');
		addr += i;
		u -= i;
	}
}

void _see() {
	_error = E_NOPRIM;
}

void _words() {
	register int i = 0;
	register struct word_def *p;
	register Cell col = 1;
	while (i < VOC_HASH) {
		p = voc->voc[i++];
		while (p) {
			*--sp = (Cell) p->name;
			_count();
			if (col + sp[0] > 79) {
				col = 1;
				_c_r();
			}
			col += sp[0] + 1;
			_type();
			_b_l();
			_emit();
			p = p->link;
		}
	}
}