continue adding commentary to RetroForth source
FossilOrigin-Name: 74121e8f5c8e3d53a59dc4658d12081892494a3ec9a863b876585b1bb5d265d2
This commit is contained in:
parent
e62ae42e7e
commit
3becf4d899
1 changed files with 22 additions and 1 deletions
|
@ -125,17 +125,33 @@ With this I can then define `immediate` (for state-smart words) and
|
|||
:data (-) &class:data reclass ;
|
||||
~~~
|
||||
|
||||
`depth` returns the number of items on the data stack. This is
|
||||
provided by the VM upon reading from address *-1*.
|
||||
|
||||
~~~
|
||||
:depth (-n) #-1 fetch ;
|
||||
~~~
|
||||
|
||||
The next two are additional prefixes to make working with variables
|
||||
a bit less painful. By default you have to do things like:
|
||||
|
||||
&Name fetch #10 * &Name store
|
||||
|
||||
Or use combinators:
|
||||
|
||||
&Name [ fetch #10 * ] sip store
|
||||
|
||||
With the @ and ! prefixes this can become:
|
||||
|
||||
@Name #10 * !Name
|
||||
|
||||
~~~
|
||||
:prefix:@ (s-n) d:lookup d:xt fetch class:data &fetch class:word ; immediate
|
||||
:prefix:! (s-n) d:lookup d:xt fetch class:data &store class:word ; immediate
|
||||
~~~
|
||||
|
||||
I have a `compile` namespace for some low level words that compile
|
||||
Nga bytecode.
|
||||
specific Nga bytecode.
|
||||
|
||||
~~~
|
||||
:compile:lit (a-) #1 , , ;
|
||||
|
@ -651,6 +667,11 @@ from fixed ends of the string.
|
|||
|
||||
Hash (using DJB2)
|
||||
|
||||
I use the djb2 hash algorithm for computing hashes from strings.
|
||||
There are certainly better hashes out there, but this is pretty
|
||||
simple and works well for my limited hash needs. The implementation
|
||||
was adapted from the C example at http://www.cse.yorku.ca/~oz/hash.html
|
||||
|
||||
~~~
|
||||
:s:hash (s-n) #5381 swap [ swap #33 * + ] s:for-each ;
|
||||
~~~
|
||||
|
|
Loading…
Reference in a new issue