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