guile-devel
[Top][All Lists]
Advanced

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

[PATCH 02/10] remove CONS macro in VM; use scm_cons instead


From: Andy Wingo
Subject: [PATCH 02/10] remove CONS macro in VM; use scm_cons instead
Date: Thu, 23 May 2013 15:30:55 +0200

* libguile/vm-engine.c (CONS): Remove.  Callers should use scm_cons
  instead, syncing registers beforehand.
  (POP_LIST): Adapt, only synchronizing once.
  (POP_LIST_MARK, POP_CONS_MARK): Remove unused macros.

* libguile/vm-i-scheme.c (cons):
* libguile/vm-i-system.c (push-rest, bind-rest): Adapt.
---
 libguile/vm-engine.c   |   41 ++---------------------------------------
 libguile/vm-i-scheme.c |    3 ++-
 libguile/vm-i-system.c |    6 ++++--
 3 files changed, 8 insertions(+), 42 deletions(-)

diff --git a/libguile/vm-engine.c b/libguile/vm-engine.c
index d950f12..cb92fc7 100644
--- a/libguile/vm-engine.c
+++ b/libguile/vm-engine.c
@@ -315,17 +315,6 @@
 #define POP2(x,y) do { PRE_CHECK_UNDERFLOW (2); x = *sp--; y = *sp--; 
NULLSTACK (2); } while (0)
 #define POP3(x,y,z) do { PRE_CHECK_UNDERFLOW (3); x = *sp--; y = *sp--; z = 
*sp--; NULLSTACK (3); } while (0)
 
-/* A fast CONS.  This has to be fast since its used, for instance, by
-   POP_LIST when fetching a function's argument list.  Note: `scm_cell' is an
-   inlined function in Guile 1.7.  Unfortunately, it calls
-   `scm_gc_for_newcell ()' which is _not_ inlined and allocated cells on the
-   heap.  XXX  */
-#define CONS(x,y,z)                                    \
-{                                                      \
-  SYNC_BEFORE_GC ();                                   \
-  x = scm_cell (SCM_UNPACK (y), SCM_UNPACK (z));       \
-}
-
 /* Pop the N objects on top of the stack and push a list that contains
    them.  */
 #define POP_LIST(n)                            \
@@ -333,10 +322,11 @@ do                                                \
 {                                              \
   int i;                                       \
   SCM l = SCM_EOL, x;                          \
+  SYNC_BEFORE_GC ();                            \
   for (i = n; i; i--)                           \
     {                                           \
       POP (x);                                  \
-      CONS (l, x, l);                           \
+      l = scm_cons (x, l);                      \
     }                                           \
   PUSH (l);                                    \
 } while (0)
@@ -351,33 +341,6 @@ do                                         \
 } while (0)
 
 
-#define POP_LIST_MARK()                                \
-do {                                           \
-  SCM o;                                       \
-  SCM l = SCM_EOL;                             \
-  POP (o);                                     \
-  while (!SCM_UNBNDP (o))                      \
-    {                                          \
-      CONS (l, o, l);                          \
-      POP (o);                                 \
-    }                                          \
-  PUSH (l);                                    \
-} while (0)
-
-#define POP_CONS_MARK()                                \
-do {                                           \
-  SCM o, l;                                    \
-  POP (l);                                      \
-  POP (o);                                     \
-  while (!SCM_UNBNDP (o))                      \
-    {                                          \
-      CONS (l, o, l);                          \
-      POP (o);                                 \
-    }                                          \
-  PUSH (l);                                    \
-} while (0)
-
-
 /*
  * Instruction operation
  */
diff --git a/libguile/vm-i-scheme.c b/libguile/vm-i-scheme.c
index dce90e3..c12c42b 100644
--- a/libguile/vm-i-scheme.c
+++ b/libguile/vm-i-scheme.c
@@ -131,7 +131,8 @@ VM_DEFINE_FUNCTION (141, vectorp, "vector?", 1)
 VM_DEFINE_FUNCTION (142, cons, "cons", 2)
 {
   ARGS2 (x, y);
-  CONS (x, x, y);
+  SYNC_BEFORE_GC ();
+  x = scm_cons (x, y);
   RETURN (x);
 }
 
diff --git a/libguile/vm-i-system.c b/libguile/vm-i-system.c
index ac1d4a6..4445d0c 100644
--- a/libguile/vm-i-system.c
+++ b/libguile/vm-i-system.c
@@ -715,9 +715,10 @@ VM_DEFINE_INSTRUCTION (51, push_rest, "push-rest", 2, -1, 
-1)
   SCM rest = SCM_EOL;
   n = FETCH () << 8;
   n += FETCH ();
+  SYNC_BEFORE_GC ();
   while (sp - (fp - 1) > n)
     /* No need to check for underflow. */
-    CONS (rest, *sp--, rest);
+    rest = scm_cons (*sp--, rest);
   PUSH (rest);
   NEXT;
 }
@@ -731,9 +732,10 @@ VM_DEFINE_INSTRUCTION (52, bind_rest, "bind-rest", 4, -1, 
-1)
   n += FETCH ();
   i = FETCH () << 8;
   i += FETCH ();
+  SYNC_BEFORE_GC ();
   while (sp - (fp - 1) > n)
     /* No need to check for underflow. */
-    CONS (rest, *sp--, rest);
+    rest = scm_cons (*sp--, rest);
   LOCAL_SET (i, rest);
   NEXT;
 }
-- 
1.7.10.4




reply via email to

[Prev in Thread] Current Thread [Next in Thread]