X-Git-Url: https://git.distorted.org.uk/~mdw/sod/blobdiff_plain/167524b5890cdbf4a832b1766a328f6d8a1f8f04..ae0f15ee8427fa91cfd1945bfded847032cb8a25:/src/codegen-proto.lisp diff --git a/src/codegen-proto.lisp b/src/codegen-proto.lisp index 4bfaeca..7a6be33 100644 --- a/src/codegen-proto.lisp +++ b/src/codegen-proto.lisp @@ -67,6 +67,9 @@ (defparameter *sod-tmp-val* (make-instance 'temporary-name :tag "sod__t")) +(export '*null-pointer*) +(defparameter *null-pointer* "NULL") + ;;;-------------------------------------------------------------------------- ;;; Instructions. @@ -252,11 +255,18 @@ 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)