Removed unnecessary ['] primitive.
[forth.jl.git] / src / lib_1_basic.4th
1 \ Basic definitions
2
3 : / /MOD SWAP DROP ;
4 : MOD /MOD DROP ;
5 : */ -ROT * SWAP / ;
6
7 : NEGATE \ ( x -- -x )
8     0 SWAP - ;
9
10 : NIP \ ( x y -- y )
11     SWAP DROP ;
12
13 : TUCK \ ( x y -- y x y )
14     DUP -ROT ;
15
16 : PICK \ ( x_u ... x_1 x_0 u -- x_u ... x_1 x_0 x_u )
17         1+ PSP@ SWAP - @ ;
18
19 : TRUE -1 ;
20 : FALSE 0 ;
21 : NOT 0= ;
22
23 \ Standard words for manipulating BASE.
24 : DECIMAL   10 BASE ! ;
25 : HEX       16 BASE ! ;
26
27
28 \ Translate a number of cells into memory units
29 \ (in our case 1 cell = 1 memory unit)
30 : CELLS ;
31
32 \ Since the smallest unit of memory in our system is 64 bits and since strings
33 \ are stored as arrays of 64 bit integers, the character store/fetch words are
34 \ just aliases of the standard store/fetch words.
35 : C! ! ;
36 : C@ @ ;
37 : C, , ;
38
39 : DEPTH PSP@ PSP0 - ;
40
41 : '\n' 10 ;
42 : BL 32 ;
43 : CR '\n' emit ;
44 : SPACE BL emit ;
45
46 : ' BL WORD FIND DROP ;
47 : [COMPILE] IMMEDIATE ' , ;
48 : ['] IMMEDIATE
49      LIT LIT , ' , ;
50
51 : LITERAL IMMEDIATE ['] LIT , , ;
52
53 : CHAR BL WORD 1+ @ ;
54 : [CHAR] IMMEDIATE
55     CHAR
56     ['] LIT , ,
57 ;
58
59 : RECURSE IMMEDIATE
60         LATEST @        \ LATEST points to the word being compiled at the moment
61         >CFA            \ get the codeword
62         ,               \ compile it
63 ;
64