Changeset 14017


Ignore:
Timestamp:
07/28/12 20:44:37 (8 years ago)
Author:
ehuelsmann
Message:

Fix #191: Compiling SHARPSIGN SHARPSIGN form causes stack overflow.

We weren't correctly detecting recursive structures when traversing
the to-be-compiled tree of sexps.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/abcl/src/org/armedbear/lisp/jvm.lisp

    r13800 r14017  
    578578      (return block))))
    579579
    580 (defun %find-enclosed-blocks (form)
     580(defun %find-enclosed-blocks (form traversed-blocks)
    581581  "Helper function for `find-enclosed-blocks`, implementing the actual
    582 algorithm specified there."
     582algorithm specified there.
     583`traversed-blocks' prevents traversal of recursive structures."
    583584  (cond
    584585   ((node-p form) (list form))
     
    587588    ;; We can't use MAPCAN or DOLIST here: they'll choke on dotted lists
    588589    (do* ((tail form (cdr tail))
     590          (current-block (if (consp tail)
     591                             (car tail) tail)
     592                         (if (consp tail)
     593                             (car tail) tail))
    589594          blocks)
    590595         ((null tail) blocks)
    591       (setf blocks
    592             (nconc (%find-enclosed-blocks (if (consp tail)
    593                                               (car tail) tail))
    594                    blocks))
     596      (unless (gethash current-block traversed-blocks)
     597        (setf (gethash current-block traversed-blocks) t)
     598        (setf blocks
     599              (nconc (%find-enclosed-blocks current-block
     600                                            traversed-blocks)
     601                     blocks)))
    595602      (when (not (listp tail))
    596603        (return blocks))))))
     
    610617        (return-from find-enclosed-blocks))))
    611618
    612   (%find-enclosed-blocks form))
     619  (%find-enclosed-blocks form (make-hash-table :test 'eq)))
    613620
    614621
Note: See TracChangeset for help on using the changeset viewer.