Scheme reader fully replaces C reader
authorAndy Wingo <wingo@pobox.com>
Wed, 3 Mar 2021 20:41:28 +0000 (21:41 +0100)
committerAndy Wingo <wingo@pobox.com>
Wed, 3 Mar 2021 20:43:33 +0000 (21:43 +0100)
* libguile/read.h:
* libguile/read.c (scm_primitive_read): New name for C reader.
(scm_read): Call current value of "read" variable.
(scm_init_read): Initialize "read" binding to "primitive-read".
Replaced later in boot-9.

libguile/read.c
libguile/read.h

index 51dffbf3a823c9b966da129041f8a9d76199ac43..1d7ca78a0f6a4db83355ed650d71bf7b0498e84f 100644 (file)
@@ -1,4 +1,4 @@
-/* Copyright 1995-1997,1999-2001,2003-2004,2006-2012,2014-2020
+/* Copyright 1995-1997,1999-2001,2003-2004,2006-2012,2014-2021
      Free Software Foundation, Inc.
 
    This file is part of Guile.
@@ -1943,12 +1943,12 @@ scm_read_expression (SCM port, scm_t_read_opts *opts)
 
 static void init_read_options (SCM port, scm_t_read_opts *opts);
 
-SCM_DEFINE (scm_read, "read", 0, 1, 0, 
+SCM_DEFINE (scm_primitive_read, "primitive-read", 0, 1, 0,
             (SCM port),
            "Read an s-expression from the input port @var{port}, or from\n"
            "the current input port if @var{port} is not specified.\n"
            "Any whitespace before the next token is discarded.")
-#define FUNC_NAME s_scm_read
+#define FUNC_NAME s_scm_primitive_read
 {
   scm_t_read_opts opts;
   int c;
@@ -1968,6 +1968,19 @@ SCM_DEFINE (scm_read, "read", 0, 1, 0,
 }
 #undef FUNC_NAME
 
+static SCM scm_read_var;
+
+SCM
+scm_read (SCM port)
+#define FUNC_NAME "read"
+{
+  if (SCM_UNBNDP (port))
+    return scm_call_0 (scm_variable_ref (scm_read_var));
+
+  return scm_call_1 (scm_variable_ref (scm_read_var), port);
+}
+#undef FUNC_NAME
+
 
 \f
 
@@ -2399,4 +2412,7 @@ scm_init_read ()
 
   scm_init_opts (scm_read_options, scm_read_opts);
 #include "read.x"
+
+  scm_read_var = scm_c_define
+    ("read", scm_variable_ref (scm_c_lookup (s_scm_primitive_read)));
 }
index 94d92db4a5a6234332f2f0c4a6862edee156e86a..c3d62cd159d62c39c1a0cfda89cb041d02e10fda 100644 (file)
@@ -1,7 +1,7 @@
 #ifndef SCM_READ_H
 #define SCM_READ_H
 
-/* Copyright 1995-1996,2000,2006,2008-2009,2018
+/* Copyright 1995-1996,2000,2006,2008-2009,2018,2021
      Free Software Foundation, Inc.
 
    This file is part of Guile.
@@ -49,6 +49,8 @@
 
 SCM_API SCM scm_sym_dot;
 
+SCM_INTERNAL SCM scm_primitive_read (SCM port);
+
 SCM_API SCM scm_read_options (SCM setting);
 SCM_API SCM scm_read (SCM port);
 SCM_API SCM scm_read_hash_extend (SCM chr, SCM proc);