chiark / gitweb /
An actual running implementation, which makes code that compiles.
[sod] / src / codegen-proto.lisp
index 4b3852115e04a38b572b73e18bedbaf8a65c4408..b8206fa489ba202d32b8ef92e5bf12b9a5903b65 100644 (file)
@@ -62,10 +62,10 @@ (defparameter *temporary-index* 0
 
    This is automatically reset to zero before the output functions are
    invoked to write a file.  This way, we can ensure that the same output
-   file is always produced from the same input."
-  ;; FIXME: this is currently a lie.  Need some protocol to ensure that this
-  ;; happens.
-)
+   file is always produced from the same input.")
+
+(define-clear-the-decks reset-codegen-index
+  (setf *temporary-index* 0))
 
 ;; Important temporary names.
 
@@ -86,9 +86,9 @@ (defclass inst () ()
    "A base class for instructions.
 
    An `instruction' is anything which might be useful to string into a code
-   generator.  Both statements and expressions map can be represented by
-   trees of instructions.  The `definst' macro is a convenient way of
-   defining new instructions.
+   generator.  Both statements and expressions can be represented by trees of
+   instructions.  The `definst' macro is a convenient way of defining new
+   instructions.
 
    The only important protocol for instructions is output, which is achieved
    by calling `print-object' with `*print-escape*' nil.
@@ -108,9 +108,14 @@ (defgeneric inst-metric (inst)
    This isn't intended to be a particularly rigorous definition.  Its purpose
    is to allow code generators to make decisions about inlining or calling
    code fairly simply.")
-  (:method (inst)
+  (:method ((inst t))
+    (declare (ignore inst))
+    1)
+  (:method ((inst null))
     (declare (ignore inst))
-    1))
+    1)
+  (:method ((inst list))
+    (reduce #'+ inst :key #'inst-metric)))
 
 ;; Instruction definition.
 
@@ -316,7 +321,7 @@ (defmacro with-temporary-var ((codegen var type) &body body)
   "Evaluate BODY with VAR bound to a temporary variable name.
 
    During BODY, VAR will be marked in-use; when BODY ends, VAR will be marked
-  available for re-use."
+   available for re-use."
   `(let ((,var (temporary-var ,codegen ,type)))
      (unwind-protect
          (progn ,@body)