chiark / gitweb /
src/codegen-{proto,impl}.lisp: Gather `definst' forms together.
authorMark Wooding <mdw@distorted.org.uk>
Wed, 16 Dec 2015 03:35:50 +0000 (03:35 +0000)
committerMark Wooding <mdw@distorted.org.uk>
Sun, 29 May 2016 13:40:40 +0000 (14:40 +0100)
Having some of the definitions in the `proto' file and some in the
`impl' file doesn't make a great deal of sense.  I think that the ones
in the `impl' file were meant to be the ones which depend on the
`format-compound-statement' macro, but that's a terrible reason.

Hoist this macro above the `definst' forms, gather them all together as
part of the protocol, and sort them out a bit better.

Nothing observable has actually changed.

src/codegen-impl.lisp
src/codegen-proto.lisp

index bc6f11d56b72c629d6284c934b27d701614a47a0..0dba2c17fac7824a877f8f3d56da3c7f03f6a9e0 100644 (file)
@@ -70,40 +70,6 @@ (defmethod print-object ((var temporary-name) stream)
        (prin1 (temp-tag var) stream))
       (format-temporary-name var stream)))
 
-;;;--------------------------------------------------------------------------
-;;; Instruction types.
-
-;; Compound statements.
-
-;; HACK: use gensyms for the `condition' slots to avoid leaking the slot
-;; names, since the symbol `condition' actually comes from the `common-lisp'
-;; package.  The `definst' machinery will symbolicate the various associated
-;; methods correctly despite this subterfuge.
-
-(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))))
-
-(definst while (stream :export t) (#1=#:cond body)
-  (format-compound-statement (stream body)
-    (format stream "while (~A)" #1#)))
-
-(definst do-while (stream :export t) (body #1=#:cond)
-  (format-compound-statement (stream body :space)
-    (write-string "do" stream))
-  (format stream "while (~A);" #1#))
-
-
-;; Expressions.
-
-;; HACK: use a gensym for the `func' slot to avoid leaking the slot name,
-;; since the symbol `func' is exported from our package.
-(definst call (stream :export t) (#1=#:func args)
-  (format stream "~A(~@<~{~A~^, ~_~}~:>)" #1# args))
-
 ;;;--------------------------------------------------------------------------
 ;;; Code generator objects.
 
index 5364f72b4ef33ce55bc7d6ac3784bb4a9b294f08..264fd03cb930084c0b632dab505ab69111ab820a 100644 (file)
@@ -163,38 +163,6 @@        (defmethod print-object ((,inst-var ,class-name) ,streamvar)
                                           args)))))
        ',code)))
 
-;; Important instruction classes.
-
-;; HACK: use a gensym for the `expr' and `type' slots to avoid leaking the
-;; slot names, since the symbol `expr' is exported from our package and
-;; `type' belongs to the `common-lisp' package.
-
-(definst var (stream :export t) (name #1=#:type init)
-  (pprint-c-type #1# stream name)
-  (when init
-    (format stream " = ~A" init))
-  (write-char #\; stream))
-(definst set (stream :export t) (var #1=#:expr)
-  (format stream "~@<~A = ~@_~2I~A;~:>" var #1#))
-(definst update (stream :export t) (var op #1=#:expr)
-  (format stream "~@<~A ~A= ~@_~2I~A;~:>" var op #1#))
-(definst return (stream :export t) (#1=#:expr)
-  (format stream "return~@[ (~A)~];" #1#))
-(definst break (stream :export t) ()
-  (format stream "break;"))
-(definst continue (stream :export t) ()
-  (format stream "continue;"))
-(definst expr (stream :export t) (#1=#:expr)
-  (format stream "~A;" #1#))
-(definst block (stream :export t) (decls body)
-  (format stream "{~:@_~@<  ~2I~@[~{~A~:@_~}~:@_~]~{~A~^~:@_~}~:>~:@_}"
-         decls body))
-(definst function (stream :export t) (name #1=#:type body)
-  (pprint-logical-block (stream nil)
-    (princ "static " stream)
-    (pprint-c-type #1# stream name)
-    (format stream "~:@_~A~:@_~:@_" body)))
-
 ;; Formatting utilities.
 
 (defun format-compound-statement* (stream child morep thunk)
@@ -230,6 +198,66 @@ (defmacro format-compound-statement
   `(format-compound-statement* ,stream ,child ,morep
                               (lambda (,stream) ,@body)))
 
+;; Important instruction classes.
+
+;; HACK: Some of the slot names we'd like to use are external symbols in our
+;; package or the `common-lisp' package.  Use gensyms for these slot names to
+;; prevent them from leaking.
+
+(definst var (stream :export t) (name #1=#:type init)
+  (pprint-c-type #1# stream name)
+  (when init
+    (format stream " = ~A" init))
+  (write-char #\; stream))
+
+(definst function (stream :export t) (name #1=#:type body)
+  (pprint-logical-block (stream nil)
+    (princ "static " stream)
+    (pprint-c-type #1# stream name)
+    (format stream "~:@_~A~:@_~:@_" body)))
+
+;; Expression statements.
+(definst expr (stream :export t) (#1=#:expr)
+  (format stream "~A;" #1#))
+(definst set (stream :export t) (var #1=#:expr)
+  (format stream "~@<~A = ~@_~2I~A;~:>" var #1#))
+(definst update (stream :export t) (var op #1=#:expr)
+  (format stream "~@<~A ~A= ~@_~2I~A;~:>" var op #1#))
+
+;; Special kinds of expressions.
+(definst call (stream :export t) (#1=#:func args)
+  (format stream "~A(~@<~{~A~^, ~_~}~:>)" #1# args))
+
+;; Simple statements.
+(definst return (stream :export t) (#1=#:expr)
+  (format stream "return~@[ (~A)~];" #1#))
+(definst break (stream :export t) ()
+  (format stream "break;"))
+(definst continue (stream :export t) ()
+  (format stream "continue;"))
+
+;; Compound statements.
+
+(definst block (stream :export t) (decls body)
+  (format stream "{~:@_~@<  ~2I~@[~{~A~:@_~}~:@_~]~{~A~^~:@_~}~:>~:@_}"
+         decls body))
+
+(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))))
+
+(definst while (stream :export t) (#1=#:cond body)
+  (format-compound-statement (stream body)
+    (format stream "while (~A)" #1#)))
+
+(definst do-while (stream :export t) (body #1=#:cond)
+  (format-compound-statement (stream body :space)
+    (write-string "do" stream))
+  (format stream "while (~A);" #1#))
+
 ;;;--------------------------------------------------------------------------
 ;;; Code generation.