Imported Upstream version 0.1beta
[debian/yforth] / search.c
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  * ------------------------------------------------------------------------
7  * Module name: 
8  * Abstract:
9  */
10
11 #include <stdlib.h>
12 #include "core.h"
13 #include "search.h"
14
15 /**************************************************************************/
16 /* VARIABLES **************************************************************/
17 /**************************************************************************/
18
19 struct vocabulary *list[WORD_LISTS];
20 Cell top;               /* indice primo vocabolario sulla pila */
21 struct vocabulary *voc; /* ptr al vocabolario usato per le definzioni */
22 struct vocabulary *forth_wid;
23
24 /**************************************************************************/
25 /* WORDS ******************************************************************/
26 /**************************************************************************/
27
28 void _definitions() {
29         voc = list[top];
30 }
31
32 void _forth_wordlist() {
33         *--sp = (Cell) forth_wid;
34 }
35
36 void _get_current() {
37         *--sp = (Cell) voc;
38 }
39
40 void _get_order() {
41         register Cell i;
42         for (i = 0; i <= top; i++) *--sp = (Cell) list[i];
43         *--sp = top;
44 }
45
46 void _search_wordlist() {
47         register struct vocabulary *wid = (struct vocabulary *) *sp++;
48         register Cell len = *sp++;
49         register Char *addr = (Char *) *sp;
50         register struct word_def *xt = search_wordlist(addr, len, wid);
51         set_find_stack(addr, xt);
52         if (!*sp) *++sp = 0;
53 }
54
55 void _set_current() {
56         voc = (struct vocabulary *) *sp++;
57 }
58
59 void _set_order() {
60         register Cell n = *sp++;
61         register int i;
62         for (i = 0; i < n; i++)
63                 if (i < WORD_LISTS) list[i] = (struct vocabulary *) *sp++;
64                 else sp++;
65         top = n - 1;
66 }
67
68 void _wordlist() {
69         register struct vocabulary *v;
70         register int i;
71         _align();
72         v = (struct vocabulary *) _dp;
73         _dp += sizeof(struct vocabulary);
74         for (i = 0; i < VOC_HASH; i++) v->voc[i] = NULL;
75         *--sp = (Cell) v;
76 }
77
78
79 /**************************************************************************/
80 /* AUXILIARY FUNCTIONS ****************************************************/
81 /**************************************************************************/
82
83 void save_vocabulary(struct voc_marker *vm) {
84         register int i;
85         for (i = 0; i < WORD_LISTS; i++) {
86                 vm->list[i] = list[i];
87                 if (list[i]) vm->v_list[i] = *list[i];
88         }
89         vm->top = top;
90         vm->voc = voc;
91         vm->_dp = _dp;
92         vm->last = _last;
93 }
94
95 void load_vocabulary(struct voc_marker *vm) {
96         register int i;
97         for (i = 0; i < WORD_LISTS; i++) {
98                 list[i] = vm->list[i];
99                 if (list[i]) *list[i] = vm->v_list[i];
100         }
101         top = vm->top;
102         voc = vm->voc;
103         _dp = vm->_dp;
104         _last = vm->last;
105 }