unofficial mirror of guile-devel@gnu.org 
 help / color / mirror / Atom feed
* [PATCH] Fix serialization of #nil-terminated lists during compilation
@ 2012-01-14  8:49 Mark H Weaver
  2012-01-14  9:15 ` Cheap list? (was: [PATCH] Fix serialization of #nil-terminated lists during compilation) David Kastrup
  0 siblings, 1 reply; 3+ messages in thread
From: Mark H Weaver @ 2012-01-14  8:49 UTC (permalink / raw)
  To: guile-devel

[-- Attachment #1: Type: text/plain, Size: 335 bytes --]

FYI, bipt mentioned this bug on IRC:

<bipt>(compile '(cdr '(5 . #nil)) #:to 'value) => ()                                                                  
<bipt>(cdr '(5 . #nil)) => #nil                                                                                       

and I pushed the attached fix to stable-2.0.

     Mark



[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: [PATCH] Fix serialization of #nil-terminated lists during compilation --]
[-- Type: text/x-patch, Size: 2011 bytes --]

From 39eb0b7297a0e5baad5d3dc34068c854fa4c0c8b Mon Sep 17 00:00:00 2001
From: Mark H Weaver <mhw@netris.org>
Date: Sat, 14 Jan 2012 03:27:35 -0500
Subject: [PATCH] Fix serialization of #nil-terminated lists during
 compilation

* module/language/glil/compile-assembly.scm (scheme-list?): New
  predicate, like `list?' but requires that the last cdr must be '(),
  not #nil.

  (dump-object, dump-constants): Use `list' opcode to create a list only
  if it is terminated by '().  If it's terminated by #nil, we must use
  the more general `cons' opcode.
---
 module/language/glil/compile-assembly.scm |   11 +++++++++--
 1 files changed, 9 insertions(+), 2 deletions(-)

diff --git a/module/language/glil/compile-assembly.scm b/module/language/glil/compile-assembly.scm
index c76e412..997f7c7 100644
--- a/module/language/glil/compile-assembly.scm
+++ b/module/language/glil/compile-assembly.scm
@@ -103,6 +103,13 @@
 (define (immediate? x)
   (object->assembly x))
 
+;; This tests for a proper scheme list whose last cdr is '(), not #nil.
+;;
+(define (scheme-list? x)
+  (or (eq? x '())
+      (and (pair? x)
+           (scheme-list? (cdr x)))))
+
 ;; Note: in all of these procedures that build up constant tables, the
 ;; first (zeroth) index is reserved.  At runtime it is replaced with the
 ;; procedure's module.  Hence all of this 1+ length business.
@@ -733,7 +740,7 @@
    ((keyword? x)
     `(,@(dump-object (keyword->symbol x) addr)
       (make-keyword)))
-   ((list? x)
+   ((scheme-list? x)
     (let ((tail (let ((len (length x)))
                   (if (>= len 65536) (too-long "list"))
                   `((list ,(quotient len 256) ,(modulo len 256))))))
@@ -815,7 +822,7 @@
         (values code (addr+ addr code))))
      ((variable-cache-cell? x)
       (dump1 (variable-cache-cell-key x) i addr))
-     ((list? x)
+     ((scheme-list? x)
       (receive (codes addr)
           (fold2 (lambda (x codes addr)
                    (receive (subcode addr) (ref-or-dump x i addr)
-- 
1.7.5.4


^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2012-01-14 15:08 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-01-14  8:49 [PATCH] Fix serialization of #nil-terminated lists during compilation Mark H Weaver
2012-01-14  9:15 ` Cheap list? (was: [PATCH] Fix serialization of #nil-terminated lists during compilation) David Kastrup
2012-01-14 15:08   ` Cheap list? Andy Wingo

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).