From 3becf4d899829856f681effcdc5f3ace5ef545fa Mon Sep 17 00:00:00 2001 From: crc Date: Mon, 23 Oct 2017 18:56:56 +0000 Subject: [PATCH] continue adding commentary to RetroForth source FossilOrigin-Name: 74121e8f5c8e3d53a59dc4658d12081892494a3ec9a863b876585b1bb5d265d2 --- literate/RetroForth.md | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/literate/RetroForth.md b/literate/RetroForth.md index abf7709..8254686 100644 --- a/literate/RetroForth.md +++ b/literate/RetroForth.md @@ -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 ; ~~~