[uim-commit] r2152 - branches/r5rs/sigscheme

kzk at freedesktop.org kzk at freedesktop.org
Fri Nov 18 14:30:00 PST 2005


Author: kzk
Date: 2005-11-18 14:29:56 -0800 (Fri, 18 Nov 2005)
New Revision: 2152

Modified:
   branches/r5rs/sigscheme/TODO
   branches/r5rs/sigscheme/eval.c
   branches/r5rs/sigscheme/operations.c
   branches/r5rs/sigscheme/sigschemetype.h
Log:
* invalid storage model assumption of ScmOp_append() and qquote_internal()

* sigscheme/sigschemetype.h
  - (SCM_REF, SCM_REF_NULL): new macro
  - (SCM_REF_CAR, SCM_REF_CDR): use SCM_REF

* sigscheme/operations.c
  - remove comment
  - (ScmOp_append): use SCM_REF* macro and ScmRef

* sigscheme/eval.c
  - (qquote_internal): use SCM_REF* macro and ScmRef

* sigscheme/TODO
  - update


Modified: branches/r5rs/sigscheme/TODO
===================================================================
--- branches/r5rs/sigscheme/TODO	2005-11-17 09:05:27 UTC (rev 2151)
+++ branches/r5rs/sigscheme/TODO	2005-11-18 22:29:56 UTC (rev 2152)
@@ -21,9 +21,6 @@
 * Inhibit a mutation on string constants as described in "3.4 Storage model" of
   R5RS
 
-* Fix invalid storage model assumption of ScmOp_append() and qquote_internal()
-  with ScmRef
-
 * [uim] link libsscm into libuim statically
 
 * Dynamic encoding switching for a conversion between string and char list,

Modified: branches/r5rs/sigscheme/eval.c
===================================================================
--- branches/r5rs/sigscheme/eval.c	2005-11-17 09:05:27 UTC (rev 2151)
+++ branches/r5rs/sigscheme/eval.c	2005-11-18 22:29:56 UTC (rev 2152)
@@ -622,21 +622,21 @@
     ScmObj args      = SCM_NULL;
     ScmObj result    = SCM_NULL;
     ScmObj ret_lst   = SCM_NULL;
-    ScmObj *ret_tail = NULL;
+    ScmRef ret_tail  = SCM_REF_NULL;
     int splice_flag  = 0;
     DECLARE_INTERNAL_FUNCTION("qquote_internal");
 
     /* local "functions" */
 #define qquote_copy_delayed()   (QQUOTE_IS_VERBATIM(ret_lst))
-#define qquote_force_copy_upto(end) \
-    do { \
-        ScmObj src = qexpr; \
-        ret_tail = &ret_lst; \
-        while (!EQ(src, end)) { \
-            *ret_tail = CONS(CAR(src), SCM_NULL); \
-            ret_tail = &CDR(*ret_tail); \
-            src = CDR(src); \
-        } \
+#define qquote_force_copy_upto(end)                             \
+    do {                                                        \
+        ScmObj src = qexpr;                                     \
+        ret_tail = SCM_REF(ret_lst);                            \
+        while (!EQ(src, end)) {                                 \
+            SCM_SET(ret_tail, CONS(CAR(src), SCM_NULL));        \
+            ret_tail = SCM_REF_CDR(SCM_DEREF(ret_tail));        \
+            src = CDR(src);                                     \
+        }                                                       \
     } while (0)
 
 
@@ -687,24 +687,24 @@
 
         if (QQUOTE_IS_VERBATIM(result)) {
             if (!qquote_copy_delayed()) {
-                *ret_tail = CONS(obj, SCM_NULL);
-                ret_tail = &CDR(*ret_tail);
+                SCM_SET(ret_tail, CONS(obj, SCM_NULL));
+                ret_tail = SCM_REF_CDR(SCM_DEREF(ret_tail));
             }
         } else {
             if (qquote_copy_delayed())
                 qquote_force_copy_upto(ls);
 
             if (splice_flag) {
-                *ret_tail = result;
+                SCM_SET(ret_tail, result);
                 /* find the new tail (which may be the current pos) */
-                while (CONSP(*ret_tail))
-                    ret_tail = &CDR(*ret_tail);
-                if (!NULLP(*ret_tail))
+                while (CONSP(SCM_DEREF(ret_tail)))
+                    ret_tail = SCM_REF_CDR(SCM_DEREF(ret_tail));
+                if (!NULLP(SCM_DEREF(ret_tail)))
                     ERR_OBJ("unquote-splicing: bad list",
                                     result);
             } else {
-                *ret_tail = CONS(result, SCM_NULL);
-                ret_tail = &CDR(*ret_tail);
+                SCM_SET(ret_tail, CONS(result, SCM_NULL));
+                ret_tail = SCM_REF_CDR(SCM_DEREF(ret_tail));
             }
         }
     } /* foreach ls in qexpr */
@@ -719,11 +719,11 @@
   append_last_item:
     if (QQUOTE_IS_VERBATIM(result)) {
         if (!qquote_copy_delayed())
-            *ret_tail = ls;
+            SCM_SET(ret_tail, ls);
     } else {
         if (qquote_copy_delayed())
             qquote_force_copy_upto(ls);
-        *ret_tail = result;
+        SCM_SET(ret_tail, result);
     }
 
     return ret_lst;

Modified: branches/r5rs/sigscheme/operations.c
===================================================================
--- branches/r5rs/sigscheme/operations.c	2005-11-17 09:05:27 UTC (rev 2151)
+++ branches/r5rs/sigscheme/operations.c	2005-11-18 22:29:56 UTC (rev 2152)
@@ -747,16 +747,10 @@
     return Scm_NewInt(len);
 }
 
-/*
- * FIXME: Invalid direct cdr part referencing as lvalue. Don't assume such
- * specific storage model. It breaks the abstract storage API. For example,
- * base pointer + offset representation will not work under the lvalue
- * assumption. Use SET_CDR properly.  -- YamaKen 2005-09-23
- */
 ScmObj ScmOp_append(ScmObj args)
 {
-    ScmObj ret_lst = SCM_NULL;
-    ScmObj *ret_tail = &ret_lst;
+    ScmObj ret_lst  = SCM_NULL;
+    ScmRef ret_tail = SCM_REF(ret_lst);
     ScmObj ls;
     ScmObj obj = SCM_NULL;
     DECLARE_FUNCTION("append", ProcedureVariadic0);
@@ -768,15 +762,15 @@
     for (; !NULLP(CDR(args)); args = CDR(args)) {
         for (ls = CAR(args); CONSP(ls); ls = CDR(ls)) {
             obj = CAR(ls);
-            *ret_tail = CONS(obj, SCM_NULL);
-            ret_tail = &CDR(*ret_tail);
+            SCM_SET(ret_tail, CONS(obj, SCM_NULL));
+            ret_tail = SCM_REF_CDR(SCM_DEREF(ret_tail));
         }
         if (!NULLP(ls))
             ERR_OBJ("proper list required but got", CAR(args));
     }
 
     /* append the last argument */
-    *ret_tail = CAR(args);
+    SCM_SET(ret_tail, CAR(args));
 
     return ret_lst;
 }

Modified: branches/r5rs/sigscheme/sigschemetype.h
===================================================================
--- branches/r5rs/sigscheme/sigschemetype.h	2005-11-17 09:05:27 UTC (rev 2151)
+++ branches/r5rs/sigscheme/sigschemetype.h	2005-11-18 22:29:56 UTC (rev 2152)
@@ -396,8 +396,11 @@
   Abstract ScmObj Reference For Storage-Representation Independent Efficient
   List Operations
 ============================================================================*/
-#define SCM_REF_CAR(cons) (&SCM_CAR(cons))
-#define SCM_REF_CDR(cons) (&SCM_CDR(cons))
+#define SCM_REF_NULL      NULL
+
+#define SCM_REF(obj)      (&obj)
+#define SCM_REF_CAR(cons) (SCM_REF(SCM_CAR(cons)))
+#define SCM_REF_CDR(cons) (SCM_REF(SCM_CDR(cons)))
 #define SCM_DEREF(ref)    (*(ref))
 /* RFC: Is there a better name? */
 #define SCM_SET(ref, obj) (*(ref) = (obj))



More information about the uim-commit mailing list