diff options
Diffstat (limited to 'labels.e')
| -rw-r--r-- | labels.e | 20 |
1 files changed, 16 insertions, 4 deletions
diff --git a/labels.e b/labels.e index c437003..4e315f7 100644 --- a/labels.e +++ b/labels.e @@ -106,9 +106,20 @@ labels oldest-entry-in { dup } { dup label-heading labels next-newer-entry-in } while drop ; +~ This looks up a label by name if it exists, or returns 0 if it doesn't. +~ The return value if it's found is an entry pointer. +~ +~ Keep in mind that this is a pointer to the entry in the label dictionary, +~ not the label's value. It's common for a label's value to itself be a +~ pointer to a dictionary entry, in the program being compiled, so it's easy +~ to confuse that. +~ +~ (name string pointer -- label entry pointer) +: find-label labels swap find-in ; + ~ This creates a new label given a name for it, initializing its value and -~ status to zero and adding it to the dictionary. This is responsible for the -~ initial guess of zero on the first pass. +~ status to zero and adding it to the label dictionary. This is responsible +~ for the initial guess of zero on the first pass. ~ ~ (name string pointer -- ) : new-label labels create-in 0 , 0 , ; @@ -122,9 +133,9 @@ ~ Either way, it returns an entry pointer. It's named after the function ~ "intern" that many Lisp dialects have. ~ -~ (name string pointer -- entry pointer) +~ (name string pointer -- label entry pointer) : intern-label - dup labels swap find-in + dup find-label dup { swap drop } { drop dup new-label labels swap find-in } if-else ; @@ -279,6 +290,7 @@ ~ (iteration count, execution token, output start, output point) { 3 pick 100 > } { 2 pick execute 4 roll 1+ 4 unroll + check-labels-converged { 4 roll drop 3 roll drop |