From 9922f43d213bb2f710f90cb5165a7580ef0326cd Mon Sep 17 00:00:00 2001 From: Irene Knapp Date: Sat, 16 May 2026 00:43:24 -0700 Subject: it's much closer, most of the labels work correctly now Force-Push: yes Change-Id: I45662e60c0035758a2cd57d971031eb0562eccb7 --- labels.e | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) (limited to 'labels.e') 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 -- cgit 1.4.1