xref: /freebsd/stand/ficl/softwords/prefix.fr (revision 02e9120893770924227138ba49df1edb3896112a)
1\ **
2\ ** Prefix words for ficl
3\ ** submitted by Larry Hastings, larry@hastings.org
4\ **
5\ (jws) To make a prefix, simply create a new definition in the <prefixes>
6\ wordlist. start-prefixes and end-prefixes handle the bookkeeping
7\
8
9variable save-current
10
11: start-prefixes   get-current save-current ! <prefixes> set-current ;
12: end-prefixes     save-current @ set-current ;
13: show-prefixes    <prefixes> >search  words  search> drop ;
14
15\ #if (FICL_EXTENDED_PREFIX)
16
17start-prefixes
18
19\ define " (double-quote) as an alias for s", and make it a prefix
20: " postpone s" ; immediate
21
22
23\ make .( a prefix (we just create an alias for it in the prefixes list)
24: .( postpone .( ; immediate
25
26
27\ make \ a prefix, and add // (same thing) as a prefix too
28\ (jws) "//" is precompiled to save aggravation with Perl
29\ : // postpone \ ; immediate
30
31
32\ ** add 0b, 0o, 0d, and 0x as prefixes
33\ ** these temporarily shift the base to 2, 8, 10, and 16 respectively
34\ ** and consume the next number in the input stream, pushing/compiling
35\ ** as normal
36
37\ (jws) __tempbase is precompiled, as are 0x and 0d - see prefix.c
38\
39\ : __tempbase  { newbase | oldbase -- }
40\   base @ to oldbase
41\   newbase base !
42\   0 0 parse-word >number 2drop drop
43\   oldbase base !
44\   ;
45
46: 0b  2 __tempbase ; immediate
47
48: 0o  8 __tempbase ; immediate
49
50\ : 0d 10 __tempbase ; immediate
51\ "0d" add-prefix
52
53\ : 0x 16 __tempbase ; immediate
54\ "0x" add-prefix
55
56end-prefixes
57
58\ #endif
59