"Answer whether VAR is currently being used. See `with-temporary-var'.")
(:method (var)
"Non-temporary variables are always in use."
+ (declare (ignore var))
t))
(defgeneric (setf var-in-use-p) (value var)
(:documentation
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.
"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.
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) 1))
+ (:method ((inst t))
+ (declare (ignore inst))
+ 1)
+ (:method ((inst null))
+ (declare (ignore inst))
+ 1)
+ (:method ((inst list))
+ (reduce #'+ inst :key #'inst-metric)))
;; Instruction definition.
"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)