From a470a6705f13b1d57cdcc865e77e11e7aa413e34 Mon Sep 17 00:00:00 2001
From: Kaz Kylheku <kaz@kylheku.com>
Date: Wed, 13 Mar 2019 23:27:50 -0700
Subject: oop: make struct symbol supertype of all structs.

* lib.c (subtypep): If the supertype is struct, then return t
if the subtype is the name of a struct type.

* txr.1: Update the type graph to show the struct root, adding
a note about it.
---
 lib.c |  2 ++
 txr.1 | 14 ++++++++++++--
 2 files changed, 14 insertions(+), 2 deletions(-)

diff --git a/lib.c b/lib.c
index 06cd37c1..da8e0bf7 100644
--- a/lib.c
+++ b/lib.c
@@ -257,6 +257,8 @@ val subtypep(val sub, val sup)
     return tnil(sub == str_s || sub == lit_s || sub == lstr_s);
   } else if (sup == stream_s) {
     return tnil(sub == stdio_stream_s);
+  } else if (sup == struct_s) {
+    return tnil(find_struct_type(sub));
   } else {
     val sub_struct = find_struct_type(sub);
     val sup_struct = find_struct_type(sup);
diff --git a/txr.1 b/txr.1
index f8da8350..beafc62c 100644
--- a/txr.1
+++ b/txr.1
@@ -17115,7 +17115,7 @@ brackets indicate a plurality of types which are not listed by name:
         |                    |
         |                    +--- struct-type
         |                    |
-        |                    +--- <structures>
+        |                    +--- <all structures>
         |                    |
         |                    +--- ... others
         |
@@ -17161,6 +17161,8 @@ In addition to the above hierarchy, the following relationships also exist:
                     +--- nil
 
   sym --- null
+
+  struct ---- <all structures>
 .cble
 
 That is to say, the types are exhaustively partitioned into atoms and conses;
@@ -17194,7 +17196,7 @@ which is the type of the
 .code nil
 symbol.
 
-Lastly, because the type of
+Because the type of
 .code nil
 is the type
 .code null
@@ -17205,6 +17207,10 @@ is also a symbol, the
 type is a subtype of
 .codn sym .
 
+Lastly, the symbol
+.code struct
+serves as the supertype of all structures.
+
 .coNP Function @ typeof
 .synb
 .mets (typeof << value )
@@ -17308,6 +17314,10 @@ both name structure types, then
 yields true if the types are the same struct type, or if the right
 type is a direct or indirect supertype of the left.
 
+The type symbol
+.code struct
+is a supertype of all structure types.
+
 .coNP Function @ typep
 .synb
 .mets (typep < object << type-symbol )
-- 
cgit v1.2.3