factor copy-tree and cons-source out of eval.[ch]
[bpt/guile.git] / libguile / srcprop.c
index 8fa0393..b2e4ff3 100644 (file)
@@ -34,6 +34,7 @@
 #include "libguile/ports.h"
 #include "libguile/root.h"
 #include "libguile/weaks.h"
+#include "libguile/gc.h"
 
 #include "libguile/validate.h"
 #include "libguile/srcprop.h"
@@ -97,13 +98,6 @@ static SCM scm_srcprops_to_alist (SCM obj);
 
 scm_t_bits scm_tc16_srcprops;
 
-static SCM
-srcprops_mark (SCM obj)
-{
-  scm_gc_mark (SRCPROPCOPY (obj));
-  return SRCPROPALIST (obj);
-}
-
 static int
 srcprops_print (SCM obj, SCM port, scm_print_state *pstate)
 {
@@ -389,11 +383,28 @@ SCM_DEFINE (scm_set_source_property_x, "set-source-property!", 3, 0, 0,
 #undef FUNC_NAME
 
 
+SCM_DEFINE (scm_cons_source, "cons-source", 3, 0, 0, 
+            (SCM xorig, SCM x, SCM y),
+           "Create and return a new pair whose car and cdr are @var{x} and @var{y}.\n"
+           "Any source properties associated with @var{xorig} are also associated\n"
+           "with the new pair.")
+#define FUNC_NAME s_scm_cons_source
+{
+  SCM p, z;
+  z = scm_cons (x, y);
+  /* Copy source properties possibly associated with xorig. */
+  p = scm_whash_lookup (scm_source_whash, xorig);
+  if (scm_is_true (p))
+    scm_whash_insert (scm_source_whash, z, p);
+  return z;
+}
+#undef FUNC_NAME
+
+
 void
 scm_init_srcprop ()
 {
   scm_tc16_srcprops = scm_make_smob_type ("srcprops", 0);
-  scm_set_smob_mark (scm_tc16_srcprops, srcprops_mark);
   scm_set_smob_print (scm_tc16_srcprops, srcprops_print);
 
   scm_source_whash = scm_make_weak_key_hash_table (scm_from_int (2047));