initial commit
[fifth.git] / doc / commands / cmp&misc.txt
1                         Compilation & misc\r
2                         ------------------\r
3 \r
4 \r
5 init    module  ( -- )\r
6                 First module, control is passed to on startup. Contains\r
7                 initialization routines. Also it is the last core module.\r
8                 All new modules on top of it comes as result of executing\r
9                 external source files.\r
10 \r
11 head <name>     ( -- )  compiles new dictionary entry without specifying\r
12                 new module type.\r
13                 ex: head myentry\r
14 \r
15 : <name>        ( -- )  creates new code module\r
16 ;               ( -- )  ends module (immideate)\r
17                 ex: : hello ." hi there" ;\r
18 \r
19 const <name>    ( n -- ) defines new constant.\r
20                 ex: 2147483647 const max\r
21 \r
22 :i <name>       ( -- ) same as ":" but this module will be executed\r
23                 immideately even in compile mode.\r
24                 ex: :i ( 41 scan ;\r
25 \r
26 create <name>   ( -- ) same as "head" , but specify module type as data.\r
27                 ex: create LotoResults 5 , 13 , 52 , 12 , 11 , 3 ,\r
28 \r
29 allot           ( n -- ) allocate n bytes in dictionary.\r
30                 ex: create MyArray 100 allot\r
31 \r
32 " <string>"     ( -- ) compile string and its size into core.\r
33                 ex: create Mystring " This is it's contects"\r
34 \r
35 str <name> <string>" ( -- ) just shorter way for defining strings.\r
36                 ex: str Mystring This is it's contenc"\r
37 \r
38 var <name>      ( -- ) define new 32 bit variable.\r
39                 ex: var result\r
40 \r
41 ' <module>      ( -- n ) return memory address of given entry.\r
42                 ex: ' init\r
43 \r
44 forget <name>   ( -- ) erases from RAM given entry and all entries what was\r
45                 defined after it.\r
46                 ex: forget myprog\r
47 \r
48 [               ( -- )  set interpret mode (immideate)\r
49 ]               ( n -- ) set compile mode and compile top stack element\r
50                 in as literal. Together [ .... ] cobination provides good\r
51                 way to compute some values only once, at compile time,\r
52                 rather than every time while program is running.\r
53                 ex: : calculate - [ 4 MyConst1 + MyConst2 * ] ;\r
54 \r
55 defer <name>    ( -- ) creates new module, with jump instruction.\r
56                 Later address where to jump can be modified by "is" command.\r
57                 This provides method of foward referencing. So you can use\r
58                 modules what not jet exist.\r
59 is              ( address1 address2 -- ) address1 - where to jump, address2 -\r
60                 address of module created by defer command.\r
61                 ex:     defer dispver\r
62                         : run dispver ." running ..." ;\r
63                                ... whatever ...\r
64                         : (dispver ." Version 9.99 " ;\r
65                         ' (dispver ' dispver is\r
66 \r
67                 Now if I type "run" on the screen appears:\r
68                         Version 9.99 running ...\r
69 \r
70 asc <char>      ( -- ) reads char ascii code and treats it as literal.\r
71                 (immideate)\r
72                 ex: : BreakLine 30 do asc - emit loop ;\r
73                                  same as:\r
74                     : BreakLine 30 do    45 emit loop ;\r
75 \r
76 dyninc          ( handle -- ) execute code in dynamic memory handle.\r
77                 automatically deallocates it when done.\r
78 \r
79 include         ( filenumber -- ) execute code in specified file.\r
80 \r
81 words           ( -- ) display existing blocks in core.\r
82 \r
83 bye             ( -- ) exit from Fifth\r
84 \r
85 fkey            ( -- c )\r
86                 Read one byte from input stream.\r
87 \r
88 sadd            ( c addr -- )\r
89                 Add one byte "c" to string located at "addr" and updates\r
90                 string length.\r
91 \r
92 scan            ( c -- )\r
93                 Read input stream and store it to  pad   until it finds  c  .\r
94                 It ignores all "c" bytes until it finds any non "c" byte.\r
95                 in other words:\r
96                                 c  is:  "\r
97                          input stream:  """"This is test !"aoeu idh\r
98                                result:  This is test !\r
99 \r
100                 Is useful for breaking text lines into words.\r
101 \r
102 skey            ( -- c )\r
103                 So called safe "fkey". Reads data from input stream\r
104                 but converts characters with ASCII codes: 9 13 10\r
105                 to spaces.\r
106 \r
107 str=str?        ( adr1 adr2 -- result )\r
108                 Compares string at "adr1" with string at "adr2", returns\r
109                 true flag if they are equal or false if they are not.\r
110                 true = -1\r
111                 false = 0\r
112 \r
113 find            ( -- addr )\r
114                 Searches whole dictionary for word in "pad". If found,\r
115                 returns it address, if not, returns 0.\r
116 \r
117 execute         ( -- )\r
118                 Execute word located in "pad". Depending on "mode".\r
119 \r
120 dta             ( addr -- DataAddr )\r
121                 Calculates address of dictionary entry data area, from\r
122                 entry point.\r
123 \r
124 2num            ( -- num result )\r
125                 Attempt to convert string located in "pad" into numeric\r
126                 value. If succeed returns number and true as result.\r
127                 If not, returns whatever and false as result.\r
128 \r
129 dadd            ( addr length -- )\r
130                 Add to dictionary data located at "addr", with specified\r
131                 length.\r
132 \r
133 lit             ( n -- )\r
134                 Act with number depending on "mode". When interpreting,\r
135                 leaves it in stack.\r
136 \r
137 \r
138 incmod          ( addr -- )\r
139                 Add to dictionary data located at "addr"+1 , length is taken\r
140                 from "addr".\r
141 \r
142 here            ( -- n )\r
143                 return "h" contents.\r
144 \r
145 mode    var     8 bit\r
146                 Holds input stream parser operation mode.\r
147                 0 = interpreting\r
148                 1 = compiling\r
149 \r
150 pad     var     128 bytes\r
151                 Holds temprorary strings.\r
152 \r
153 h       var     32 bit\r
154                 Pointer to free byte in memory, always at the end of the\r
155                 dictionary. Each time when something is stored\r
156                 by "c," command, pointer is incareased.\r
157 \r
158 lp      var     32 bit\r
159                 Pointer to last dictionary word. Each time when new word is\r
160                 compiled or erased by "forget", this pointer is updated.\r
161 \r
162 modulechk       ( Dstr<filename> -- ) check if module is loaded, if not\r
163                 immideately load it.\r
164 \r
165 ne              ( entrydata entrytype -- ) Compile new dictionary entry.\r
166                 It's name must be in "pad".\r