-(definst if (stream :export t) (#1=#:cond conseq alt)
- (format-compound-statement (stream conseq alt)
- (format stream "if (~A)" #1#))
- (when alt
- (format-compound-statement (stream alt)
- (write-string "else" stream))))
+(export 'emit-banner)
+(defun emit-banner (codegen control &rest args)
+ (emit-inst codegen (apply #'make-banner-inst control args)))
+
+(definst block (stream :export t) (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)))
+ (let ((*first-statement-p* t))
+ (dolist (inst body)
+ (newline)
+ (write inst :stream stream)
+ (setf *first-statement-p* nil))))))
+ (pprint-newline :mandatory stream)
+ (write-char #\} stream))
+
+(definst if (stream :export t) (#1=#:cond conseq &optional alt)
+ (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))))))