[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elk] Patch: new thing->string primitives



When you do (backtrace), you see primitives, compounds, and control points.
Possibly promises and macros could also appear.  Unfortunately you can't
use (symbol->string) with those objects because they are not symbols.

This patch adds new primitives:

in Scheme		in C

primitive->string	P_Primitive_To_String
compound->string	P_Compound_To_String
macro->string		P_Macro_To_String

to convert those objects' names to Scheme strings.  Each primitive takes
one argument.  I adapted the implementation of symbol->string.  It checks
its argument for the correct type, and the new primitives do too.

The patch does not add control-point->string or promise->string, since those
objects never have names according to the print routines in print.c.

The code compiles but I haven't tested it yet!  Note that compounds and
macros may not have names, and I don't know how the code will deal with that
situation.

I intend to use these primitives to rewrite the backtrace code, to suppress
the #<> syntax where possible.  But if I do, I'll send a separate patch.

-- Derek


--- include/extern.h.orig	Mon Aug  9 13:05:05 2004
+++ include/extern.h	Tue Jan 13 20:04:18 2009
@@ -366,8 +366,11 @@
 extern Object P_Macro_Body (Object);
 extern Object P_Macro_Expand (Object);
 extern Object P_Primitivep (Object);
+extern Object P_Primitive_To_String (Object);
 extern Object P_Compoundp (Object);
+extern Object P_Compound_To_String (Object);
 extern Object P_Macrop (Object);
+extern Object P_Macro_To_String (Object);
 extern void Check_Procedure (Object);
 
 /* Delay and force
--- src/prim.c.orig	Thu Mar  2 13:14:38 2006
+++ src/prim.c	Tue Jan 13 19:56:43 2009
@@ -301,13 +301,18 @@
      */
     { P_Procedurep,        "procedure?",                     1, 1,    EVAL },
     { P_Primitivep,        "primitive?",                     1, 1,    EVAL },
+    { P_Primitive_To_String,
+                           "primitive->string",              1, 1,    EVAL },
     { P_Compoundp,         "compound?",                      1, 1,    EVAL },
+    { P_Compound_To_String,
+                           "compound->string",               1, 1,    EVAL },
     { P_Macrop,            "macro?",                         1, 1,    EVAL },
+    { P_Macro_To_String,   "macro->string",                  1, 1,    EVAL },
     { P_Eval,              "eval",                           1, 2,    VARARGS },
     { P_Apply,             "apply",                          2, MANY, VARARGS },
     { P_Lambda,            "lambda",                         2, MANY, NOEVAL },
     { P_Procedure_Environment,
-                         "procedure-environment",          1, 1,    EVAL },
+                           "procedure-environment",          1, 1,    EVAL },
     { P_Procedure_Lambda,  "procedure-lambda",               1, 1,    EVAL },
     { P_Map,               "map",                            2, MANY, VARARGS },
     { P_For_Each,          "for-each",                       2, MANY, VARARGS },
--- src/proc.c.orig	Thu Mar  2 13:05:36 2006
+++ src/proc.c	Tue Jan 13 20:51:42 2009
@@ -100,12 +100,27 @@
     return TYPE(x) == T_Primitive ? True : False;
 }
 
+Object P_Primitive_To_String (Object x) {
+    Check_Type (x, T_Primitive);
+    return Make_String (PRIM(x)->name, strlen(PRIM(x)->name));
+}
+
 Object P_Compoundp (Object x) {
     return TYPE(x) == T_Compound ? True : False;
 }
 
+Object P_Compound_To_String (Object x) {
+    Check_Type (x, T_Compound);
+    return COMPOUND(x)->name;
+}
+
 Object P_Macrop (Object x) {
     return TYPE(x) == T_Macro ? True : False;
+}
+
+Object P_Macro_To_String (Object x) {
+    Check_Type (x, T_Macro);
+    return MACRO(x)->name;
 }
 
 Object Make_Compound () {
-- 
This is the elk mailing-list, see http://sam.zoy.org/elk/
Trouble unsubscribing? Please contact <sam@zoy.org>
List archives are at http://sam.zoy.org/elk/threads.html