You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: riscish.md
+22-15
Original file line number
Diff line number
Diff line change
@@ -52,7 +52,7 @@ Values are preferred to VARIABLES, as they are much safer to use, and simpler to
52
52
199 VALUE myvalue
53
53
```
54
54
55
-
A value is read
55
+
A value is read and printed with dot.
56
56
```FORTH
57
57
myvalue .
58
58
```
@@ -66,7 +66,7 @@ An array of values is created with the VALUES plural word.
66
66
```FORTH
67
67
128 VALUES myvalues
68
68
```
69
-
The VALUES are allotted from memory that is zero filled, so all values will initially read as 0.
69
+
The VALUES are allotted from s pool of memory that is zero filled, so all values will initially read as 0.
70
70
71
71
To change every value.
72
72
```FORTH
@@ -189,17 +189,18 @@ A string is created with an initial text value like this.
189
189
' This is my initial value ' STRING myString
190
190
```
191
191
A string returns the address of its data.
192
+
192
193
```FORTH
193
194
myString $.
194
195
```
195
-
Will print the string.
196
+
Given the address $. will print the string.
196
197
197
-
A string should not be mutated, each unique string exists only once in the string pool,
198
+
A string should neot normally be mutated, each unique string exists only once in the string pool,
198
199
changing one would impact all usages everywhere in a program.
199
200
200
201
Strings can be compared with $= and $== which check if they are same and $COMPARE wich checks if one is equal, greater, or less than the other.
201
202
202
-
In terms of storage the strings content is stored in the string pool with all the rest, the word just points it and gives it a name.
203
+
In terms of storage the strings content is stored in the string pool with all the rest, the STRING word just points to the storage and gives it a name.
203
204
204
205
Just as you can create a STRING you can also create a number of strings.
205
206
@@ -219,11 +220,13 @@ Ok
219
220
string zero
220
221
```
221
222
223
+
0 myStrings returns the address of the 0th string.
224
+
222
225
$. is a word that prints a string.
223
226
224
-
The storage for the string text lives in the string pool a STRING just points a name at it.
227
+
The storage for the string text lives in the string pool a STRING word just points a name at it.
225
228
226
-
The string pool can be accessed using the VALUE $$
229
+
The string pool can be accessed using the special VALUE $$
227
230
228
231
e.g.
229
232
@@ -233,18 +236,22 @@ e.g.
233
236
234
237
```
235
238
239
+
Looks up the first 0th string in the storage and $. types it to the terminal.
240
+
241
+
236
242
### Little defining words
237
243
238
-
As this is an interpeter it is almost always slower to use two words when one will do.
244
+
As this is an interpeter it is almost always slower to use two words if one word will do.
245
+
246
+
It is also faster if each word *does more*, the overhead of the interpreter is calling each word in the first place.
239
247
240
-
It is also faster if a word does more, the overhead of the interpreter is calling the word in the first place.
241
-
The compiler also does not optimize, so it is often up to the programmer to choose to use a faster word not up to the compiler to invent them on the fly.
248
+
The compiler also does not optimize, so it is often up to the programmer to choose to use a faster optimal word not up to the compiler to invent them on the fly.
242
249
243
-
A good example is that 1 + is slower than 1+ and if you do 1 + millions of times, this will have a performance impact.
250
+
A good example is that `1 + `is slower than `1+` and if you do 1 + millions of times, this will have a performance impact.
244
251
245
252
For this reason FORTH interpreters often come with dozens of little optimized words.
246
253
247
-
The approach I am taking is to provide a few words for defining those little words, so you can define the words your specific program actually benefits from.
254
+
The approach in this implementation is to provide a few words for defining those little words, so you can define the words your specific program actually benefits from.
248
255
249
256
Shifting left and right
250
257
@@ -253,16 +260,16 @@ You can define words that perform left and right shifts for faster multiplicatio
253
260
```FORTH
254
261
3 SHIFTSL 8*
255
262
```
256
-
Defines the word 8* that SHIFTS the top of stack left 3 times, multiplying by 8. SHIFTSR is the opposite word that does division.
263
+
Defines the new word 8* that SHIFTS the top of stack left 3 times, effectively multiplying by 8. SHIFTSR is the opposite word that does division.
257
264
258
265
259
266
```FORTH
260
267
1 ADDS 1+
261
268
```
262
269
263
-
Defines a fast word for adding 1 to the top of the stack, the opposite word is SUBS.
270
+
Defines a fast little word for adding 1 to the top of the stack, the opposite word is SUBS.
264
271
265
-
Take a look though your app and if you find some common patterns define some of these to speed it up.
272
+
Take a look though your app and if you find some common patterns, define some of these to speed it up.
0 commit comments