chiark / gitweb /
src/codegen-proto.lisp: Rewrite `block' printing longhand.
authorMark Wooding <mdw@distorted.org.uk>
Tue, 5 Jan 2016 21:52:36 +0000 (21:52 +0000)
committerMark Wooding <mdw@distorted.org.uk>
Sun, 29 May 2016 14:09:03 +0000 (15:09 +0100)
There are going to be some changes made to it, so it has to be written
out suitably.  Nothing should be very different.  The way newlines are
handled is a little tricksy.

A shame, really, because the old `format' string was quite fun.

src/codegen-proto.lisp

index 7a6be338cc20662292c2d8341ee82102bf5c1641..767f35bdef503dd6a8cb4c2b3c30538b64839051 100644 (file)
@@ -251,8 +251,26 @@ (definst continue (stream :export t) ()
 ;; Compound statements.
 
 (definst block (stream :export t) (decls body)
-  (format stream "{~:@_~@<  ~2I~@[~{~A~:@_~}~:@_~]~{~A~^~:@_~}~:>~:@_}"
-         decls body))
+  (write-char #\{ stream)
+  (pprint-newline :mandatory stream)
+  (pprint-logical-block (stream nil)
+    (let ((newlinep nil))
+      (flet ((newline ()
+              (if newlinep
+                  (pprint-newline :mandatory stream)
+                  (setf newlinep t))))
+       (pprint-indent :block 2 stream)
+       (write-string "  " stream)
+       (when decls
+         (dolist (decl decls)
+           (newline)
+           (write decl :stream stream))
+         (when body (newline)))
+       (dolist (inst body)
+         (newline)
+         (write inst :stream stream)))))
+  (pprint-newline :mandatory stream)
+  (write-char #\} stream))
 
 (definst if (stream :export t) (#1=#:cond conseq &optional alt)
   (let ((stmt "if"))