From 6a36091426a7815a62cc877e999901a850b149a4 Mon Sep 17 00:00:00 2001 From: Dustin Boyd <59116123+memreflect@users.noreply.github.com> Date: Thu, 1 Aug 2024 16:04:32 -0500 Subject: [PATCH] Abridge closure strings by default A new 'ABRIDGE_CLOSURES' configuration parameter has been added to esconfig.h. It defaults to 0 so a closure string is abridged to %closure(a;b;...)@ * {...} When 'ABRIDGE_CLOSURES' is enabled, some old code that was previously commented out has been uncommented, so even closures with cyclical references can be printed: ; whatis <={@ x y { (x y) = @ cmd { $cmd $y } 1 ; result $x }} %closure(x='0 $&nestedbinding';y=1)@ cmd{$cmd $y} # 0 $&nestedbinding # the code tree associated with the closure, i.e. # '@ cmd{$cmd $y}' in this case # {n} $&nestedbinding # the code tree bound to another closure # # NOTE: $&nestedbinding doesn't actually exist. # It's purely an indicator of a cyclical reference, like # how '#1=(a b . #1#)' is used in some Lisps to avoid # printing an endless stream of 'a b'. --- conv.c | 10 +++++++--- esconfig.h | 11 +++++++++++ 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/conv.c b/conv.c index c3ebb03a..e7c0bfcf 100644 --- a/conv.c +++ b/conv.c @@ -179,11 +179,15 @@ static void enclose(Format *f, Binding *binding, const char *sep) { if (binding != NULL) { Binding *next = binding->next; enclose(f, next, ";"); +#if !ABRIDGE_CLOSURES + fmtprint(f, "%S%s", binding->name, sep); +#else fmtprint(f, "%S=%#L%s", binding->name, binding->defn, " ", sep); +#endif } } -#if 0 +#if ABRIDGE_CLOSURES typedef struct Chain Chain; struct Chain { Closure *closure; @@ -199,7 +203,7 @@ static Boolean Cconv(Format *f) { Binding *binding = closure->binding; Boolean altform = (f->flags & FMT_altform) != 0; -#if 0 +#if ABRIDGE_CLOSURES int i; Chain me, *cp; assert(tree->kind == nThunk || tree->kind == nLambda || tree->kind == nPrim); @@ -226,7 +230,7 @@ static Boolean Cconv(Format *f) { fmtprint(f, "%T", tree); } -#if 0 +#if ABRIDGE_CLOSURES chain = chain->next; /* TODO: exception unwinding? */ #endif return FALSE; diff --git a/esconfig.h b/esconfig.h index 9b4c054f..4788523e 100644 --- a/esconfig.h +++ b/esconfig.h @@ -15,6 +15,13 @@ * line definitions. (That is, remember to do the #ifndef dance.) * * + * ABRIDGE_CLOSURES + * if on, produce closure strings without the values bound in a closure: + * %closure(x;y;x)@ * {...} + * else: + * %closure(x=1;y=4;x=9)@ * {...} + * this is particularly useful when dealing with "nested bindings". + * * ASSERTIONS * if this is on, asserts will be checked, raising errors on * actual assertion failure. @@ -276,6 +283,10 @@ * default defaults -- don't change this section */ +#ifndef ABRIDGE_CLOSURES +#define ABRIDGE_CLOSURES 1 +#endif + #ifndef ASSERTIONS #define ASSERTIONS 1 #endif