Build the proper expression for successive indexing operations.
(vl-build-indexing-nest expr indices) → expr
Another operation which we want to left-associate is bit/part
selection, which might also be called array or memory indexing. The idea is
that for
(vl-index (vl-index (vl-index foo 1) 2)) 3)
This is easy because we are only dealing with one operation and no attributes, so we can just read the list of selects and then left-associate them.
Function:
(defun vl-build-indexing-nest (expr indices) (declare (xargs :guard (and (vl-expr-p expr) (vl-exprlist-p indices)))) (let ((__function__ 'vl-build-indexing-nest)) (declare (ignorable __function__)) (if (atom indices) expr (vl-build-indexing-nest (make-vl-nonatom :op :vl-index :args (list expr (car indices))) (cdr indices)))))
Theorem:
(defthm vl-expr-p-of-vl-build-indexing-nest (implies (and (force (vl-expr-p expr)) (force (vl-exprlist-p indices))) (b* ((expr (vl-build-indexing-nest expr indices))) (vl-expr-p expr))) :rule-classes :rewrite)