chiark / gitweb /
src/codegen-proto.lisp: Fix printing of `if`/`else if' ladders.
authorMark Wooding <mdw@distorted.org.uk>
Sat, 9 Jan 2016 20:41:01 +0000 (20:41 +0000)
committerMark Wooding <mdw@distorted.org.uk>
Sun, 29 May 2016 13:40:41 +0000 (14:40 +0100)
Should be in a nice column, rather than marching across to the right
margin like a mad thing.

src/codegen-proto.lisp

index c1156716fefff6c01f1228cd92b903eacab669f4..7a6be338cc20662292c2d8341ee82102bf5c1641 100644 (file)
@@ -255,11 +255,18 @@ (definst block (stream :export t) (decls body)
          decls body))
 
 (definst if (stream :export t) (#1=#:cond conseq &optional alt)
-  (format-compound-statement (stream conseq alt)
-    (format stream "if (~A)" #1#))
-  (when alt
-    (format-compound-statement (stream alt)
-      (write-string "else" stream))))
+  (let ((stmt "if"))
+    (loop (format-compound-statement (stream conseq (if alt t nil))
+           (format stream "~A (~A)" stmt #1#))
+         (typecase alt
+           (null (return))
+           (if-inst (setf stmt "else if"
+                          #1# (inst-cond alt)
+                          conseq (inst-conseq alt)
+                          alt (inst-alt alt)))
+           (t (format-compound-statement (stream alt)
+                (format stream "else"))
+              (return))))))
 
 (definst while (stream :export t) (#1=#:cond body)
   (format-compound-statement (stream body)