Skip to content

Commit 1644316

Browse files
committedDec 23, 2021
Update docs
1 parent 60373e4 commit 1644316

File tree

3 files changed

+34
-19
lines changed

3 files changed

+34
-19
lines changed
 

‎forth.fs

+11-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,17 @@
1-
// forth.fs is loaded when FORTH starts.
2-
1+
// forth.fs - this file is loaded when FORTH starts.
32

43
TICKS VALUE start_ticks
54

5+
3.14159265359 CONSTANT PI
6+
7+
// common fast add and subtract
8+
1 ADDS 1+ 1 SUBS 1-
9+
10+
// common fast shifts
11+
1 SHIFTSL 2* 2 SHIFTSL 4* 3 SHIFTSL 8*
12+
1 SHIFTSR 2/ 2 SHIFTSR 4/ 3 SHIFTSR 8/
13+
14+
615
// : SQUARE DUP * ;
716

817
// : QUADRATIC ( a b c x -- n ) >R SWAP ROT R@ * + R> * + ;

‎riscish.md

+22-15
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ Values are preferred to VARIABLES, as they are much safer to use, and simpler to
5252
199 VALUE myvalue
5353
```
5454

55-
A value is read
55+
A value is read and printed with dot.
5656
```FORTH
5757
myvalue .
5858
```
@@ -66,7 +66,7 @@ An array of values is created with the VALUES plural word.
6666
```FORTH
6767
128 VALUES myvalues
6868
```
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.
7070

7171
To change every value.
7272
```FORTH
@@ -189,17 +189,18 @@ A string is created with an initial text value like this.
189189
' This is my initial value ' STRING myString
190190
```
191191
A string returns the address of its data.
192+
192193
```FORTH
193194
myString $.
194195
```
195-
Will print the string.
196+
Given the address $. will print the string.
196197

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,
198199
changing one would impact all usages everywhere in a program.
199200

200201
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.
201202

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.
203204

204205
Just as you can create a STRING you can also create a number of strings.
205206

@@ -219,11 +220,13 @@ Ok
219220
string zero
220221
```
221222

223+
0 myStrings returns the address of the 0th string.
224+
222225
$. is a word that prints a string.
223226

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.
225228

226-
The string pool can be accessed using the VALUE $$
229+
The string pool can be accessed using the special VALUE $$
227230

228231
e.g.
229232

@@ -233,18 +236,22 @@ e.g.
233236
234237
```
235238

239+
Looks up the first 0th string in the storage and $. types it to the terminal.
240+
241+
236242
### Little defining words
237243

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.
239247

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.
242249

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.
244251

245252
For this reason FORTH interpreters often come with dozens of little optimized words.
246253

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.
248255

249256
Shifting left and right
250257

@@ -253,16 +260,16 @@ You can define words that perform left and right shifts for faster multiplicatio
253260
```FORTH
254261
3 SHIFTSL 8*
255262
```
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.
257264

258265

259266
```FORTH
260267
1 ADDS 1+
261268
```
262269

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.
264271

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.
266273

267274

268275

‎time.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@ def F(n):
1111
start_time = time.time()
1212

1313
for x in range(25):
14-
F(34)BYE
15-
14+
F(34)
1615

1716
finish_time=time.time()
1817

0 commit comments

Comments
 (0)
Please sign in to comment.