1523
1523
<p>Note: although other ACL2-style directives are not yet supported, we may
1524
1524
eventually extend the printer to allow them.</p>")
1526
(define vl-ppr-escape-slashes
1527
:parents (vl-basic-fmt)
1528
:short "This is basically like acl2::prin1-with-slashes, but we put the
1529
characters into the accumulator in reverse order instead of printing them."
1532
(xl (eql xl (length x)))
1533
(slash-char characterp)
1537
:returns (mv (col-prime natp :rule-classes :type-prescription)
1538
(acc-prime character-listp :hyp (character-listp acc)))
1539
:measure (nfix (- (nfix xl) (nfix n)))
1543
((when (mbe :logic (zp (- (nfix xl) (nfix n)))
1546
((the character char)
1547
(mbe :logic (char-fix (char x n))
1549
((the character slash-char)
1550
(mbe :logic (char-fix slash-char)
1552
(vl-ppr-escape-slashes x
1553
(the unsigned-byte (+ 1 n))
1556
(if (eql char #\Newline)
1558
(the unsigned-byte (+ 1 col)))
1559
(if (or (eql char #\\)
1560
(eql char slash-char))
1561
(list* char #\\ acc)
1563
:hooks ((:fix :hints(("Goal"
1564
;; The expansion heuristics stupidly don't want to open
1565
;; up calls that have fixes in them.
1566
:expand ((:free (x n xl slash-char col)
1567
(vl-ppr-escape-slashes x n xl slash-char col acc)))))))
1569
(defthm vl-printedlist-p-of-vl-ppr-escape-slashes
1570
(implies (vl-printedlist-p acc)
1572
(mv-nth 1 (vl-ppr-escape-slashes x n xl slash-char col acc))))))
1574
(define vl-ppr-explode-symbol-aux
1575
:parents (vl-ppr-explode-symbol)
1576
:short "Write the characters for a symbol name, adding bars if necessary."
1577
((name stringp "Name of a symbol or package.")
1580
:returns (mv (new-col natp :rule-classes :type-prescription)
1581
(acc character-listp :hyp (character-listp acc)))
1582
(b* ((name (string-fix name))
1585
((when (acl2::may-need-slashes-fn name 10))
1587
(vl-ppr-escape-slashes name 0 len #\| (+ 1 col) (cons #\| acc))))
1588
(mv (+ 1 col) (cons #\| acc)))))
1589
(mv (+ (lnfix col) len)
1590
(str::revappend-chars name acc)))
1593
((local (in-theory (disable acl2::may-need-slashes-fn))))
1595
(defthm vl-printedlist-p-of-vl-ppr-explode-symbol-aux
1596
(implies (vl-printedlist-p acc)
1597
(vl-printedlist-p (mv-nth 1 (vl-ppr-explode-symbol-aux name col acc))))))
1600
(define vl-ppr-explode-symbol
1601
:parents (vl-basic-fmt)
1602
:short "Print a symbol."
1603
((x symbolp "The symbol we want to explode.")
1604
(pkg symbolp "A symbol in the current package we are printing from.")
1605
(col natp "Current column we're at.")
1607
:returns (mv (new-col natp :rule-classes :type-prescription)
1608
(acc character-listp :hyp (character-listp acc)))
1609
(b* ((x (mbe :logic (acl2::symbol-fix x) :exec x))
1610
(pkg (mbe :logic (acl2::symbol-fix pkg) :exec pkg))
1612
(xname (symbol-name x))
1613
(xpkg (symbol-package-name x))
1614
((when (or (equal xpkg xname)
1615
(equal (intern-in-package-of-symbol xname pkg) x)))
1616
(vl-ppr-explode-symbol-aux xname col acc))
1617
((when (equal xpkg "KEYWORD"))
1618
(vl-ppr-explode-symbol-aux xname (+ 1 col) (cons #\: acc)))
1619
((mv col acc) (vl-ppr-explode-symbol-aux xpkg col acc))
1621
(acc (list* #\: #\: acc)))
1622
(vl-ppr-explode-symbol-aux xname col acc))
1624
(defthm vl-printedlist-p-of-vl-ppr-explode-symbol
1625
(implies (vl-printedlist-p acc)
1626
(vl-printedlist-p (mv-nth 1 (vl-ppr-explode-symbol x pkg col acc))))))
1628
(define vl-ppr-explode-string
1629
:parents (vl-basic-fmt)
1630
:short "Print a string."
1634
:returns (mv (new-col natp :rule-classes :type-prescription)
1635
(acc character-listp :hyp (character-listp acc)))
1636
(b* ((x (string-fix x))
1639
(vl-ppr-escape-slashes x 0 (length x) #\" (+ 1 col) (cons #\" acc))))
1640
(mv (+ 1 col) (cons #\" acc)))
1642
(defthm vl-printedlist-p-of-vl-ppr-explode-string
1643
(implies (vl-printedlist-p acc)
1644
(vl-printedlist-p (mv-nth 1 (vl-ppr-explode-string x col acc))))))
1646
(define vl-ppr-explode-atom
1647
:parents (vl-basic-fmt)
1653
:hooks ((:fix :args ((pkg symbolp) (col natp))))
1654
:returns (mv (new-col natp :rule-classes :type-prescription)
1655
(acc character-listp :hyp (character-listp acc)))
1656
(b* ((col (lnfix col))
1658
(vl-ppr-explode-symbol x pkg col acc))
1660
(vl-ppr-explode-string x col acc))
1661
((when (acl2-numberp x))
1662
(let* ((explode (explode-atom x base))
1663
(len (len explode)))
1664
(mv (+ col len) (revappend explode acc))))
1665
((when (characterp x))
1667
(#\Space (mv (+ col 7) (str::revappend-chars "#\\Space" acc)))
1668
(#\Newline (mv (+ col 9) (str::revappend-chars "#\\Newline" acc)))
1669
(#\Tab (mv (+ col 5) (str::revappend-chars "#\\Tab" acc)))
1670
(#\Rubout (mv (+ col 8) (str::revappend-chars "#\\Rubout" acc)))
1671
(#\Page (mv (+ col 6) (str::revappend-chars "#\\Page" acc)))
1672
(otherwise (mv (+ col 3) (list* x #\\ #\# acc))))))
1673
(raise "Bad atom: ~x0." x)
1674
(mv (+ col 10) (str::revappend-chars "<bad atom>" acc)))
1676
(defthm vl-printedlist-p-of-vl-ppr-explode-atom
1677
(implies (vl-printedlist-p acc)
1678
(vl-printedlist-p (mv-nth 1 (vl-ppr-explode-atom x pkg base col acc))))))
1681
(define vl-stupid-ppr1
1682
:parents (vl-basic-fmt)
1683
:short "Barbaric pretty-printer."
1684
((x "Any ACL2 object.")
1685
(pkg symbolp "Home package we're printing from.")
1686
(base print-base-p "Numeric base for printing numbers.")
1687
(rmargin natp "Right margin for line wrapping.")
1688
(in-listp booleanp "Are we currently in a list?")
1689
(col natp "Current column number.")
1691
:hooks ((:fix :args ((pkg symbolp)
1695
:returns (mv (new-col natp :rule-classes :type-prescription)
1696
(new-acc character-listp :hyp (character-listp acc)))
1698
(b* ((col (lnfix col))
1699
(rmargin (lnfix rmargin))
1701
(vl-ppr-explode-atom x pkg base col acc))
1704
(vl-stupid-ppr1 (car x) pkg base rmargin nil col acc)
1705
(vl-stupid-ppr1 (car x) pkg base rmargin nil (+ 1 col) (cons #\( acc))))
1706
((when (not (cdr x)))
1707
(mv (+ 1 (lnfix col)) (if in-listp acc (cons #\) acc))))
1709
((mv col acc) (if (< col rmargin)
1711
(mv 0 (cons #\Newline acc))))
1712
((when (consp (cdr x)))
1713
;; Successive elements of a list, no dots.
1715
(vl-stupid-ppr1 (cdr x) pkg base rmargin t (+ 1 col) (cons #\Space acc))))
1716
(mv (+ 1 (lnfix col))
1717
(if in-listp acc (cons #\) acc)))))
1719
;; End element, need a dot.
1721
(acc (list* #\Space #\. #\Space acc))
1724
((mv col acc) (if (< col rmargin)
1726
(mv 0 (cons #\Newline acc))))
1729
(vl-stupid-ppr1 (cdr x) pkg base rmargin t col acc)))
1731
(mv (+ 1 (lnfix col))
1732
(if in-listp acc (cons #\) acc))))
1734
(defthm vl-printedlist-p-of-vl-stupid-ppr1
1735
(implies (vl-printedlist-p acc)
1736
(vl-printedlist-p (mv-nth 1 (vl-stupid-ppr1 x pkg base rmargin in-listp col acc)))))
1738
(verify-guards vl-stupid-ppr1))
1530
;; (define vl-ppr-escape-slashes
1531
;; :parents (vl-basic-fmt)
1532
;; :short "This is basically like acl2::prin1-with-slashes, but we put the
1533
;; characters into the accumulator in reverse order instead of printing them."
1536
;; (xl (eql xl (length x)))
1537
;; (slash-char characterp)
1541
;; :returns (mv (col-prime natp :rule-classes :type-prescription)
1542
;; (acc-prime character-listp :hyp (character-listp acc)))
1543
;; :measure (nfix (- (nfix xl) (nfix n)))
1545
;; (b* ((n (lnfix n))
1546
;; (col (lnfix col))
1547
;; ((when (mbe :logic (zp (- (nfix xl) (nfix n)))
1548
;; :exec (eql n xl)))
1550
;; ((the character char)
1551
;; (mbe :logic (char-fix (char x n))
1552
;; :exec (char x n)))
1553
;; ((the character slash-char)
1554
;; (mbe :logic (char-fix slash-char)
1555
;; :exec slash-char)))
1556
;; (vl-ppr-escape-slashes x
1557
;; (the unsigned-byte (+ 1 n))
1560
;; (if (eql char #\Newline)
1562
;; (the unsigned-byte (+ 1 col)))
1563
;; (if (or (eql char #\\)
1564
;; (eql char slash-char))
1565
;; (list* char #\\ acc)
1566
;; (cons char acc))))
1567
;; :hooks ((:fix :hints(("Goal"
1568
;; ;; The expansion heuristics stupidly don't want to open
1569
;; ;; up calls that have fixes in them.
1570
;; :expand ((:free (x n xl slash-char col)
1571
;; (vl-ppr-escape-slashes x n xl slash-char col acc)))))))
1573
;; (defthm vl-printedlist-p-of-vl-ppr-escape-slashes
1574
;; (implies (vl-printedlist-p acc)
1575
;; (vl-printedlist-p
1576
;; (mv-nth 1 (vl-ppr-escape-slashes x n xl slash-char col acc))))))
1578
;; (define vl-ppr-explode-symbol-aux
1579
;; :parents (vl-ppr-explode-symbol)
1580
;; :short "Write the characters for a symbol name, adding bars if necessary."
1581
;; ((name stringp "Name of a symbol or package.")
1584
;; :returns (mv (new-col natp :rule-classes :type-prescription)
1585
;; (acc character-listp :hyp (character-listp acc)))
1586
;; (b* ((name (string-fix name))
1587
;; (col (lnfix col))
1588
;; (len (length name))
1589
;; ((when (acl2::may-need-slashes-fn name 10))
1590
;; (b* (((mv col acc)
1591
;; (vl-ppr-escape-slashes name 0 len #\| (+ 1 col) (cons #\| acc))))
1592
;; (mv (+ 1 col) (cons #\| acc)))))
1593
;; (mv (+ (lnfix col) len)
1594
;; (str::revappend-chars name acc)))
1597
;; ((local (in-theory (disable acl2::may-need-slashes-fn))))
1599
;; (defthm vl-printedlist-p-of-vl-ppr-explode-symbol-aux
1600
;; (implies (vl-printedlist-p acc)
1601
;; (vl-printedlist-p (mv-nth 1 (vl-ppr-explode-symbol-aux name col acc))))))
1604
;; (define vl-ppr-explode-symbol
1605
;; :parents (vl-basic-fmt)
1606
;; :short "Print a symbol."
1607
;; ((x symbolp "The symbol we want to explode.")
1608
;; (pkg symbolp "A symbol in the current package we are printing from.")
1609
;; (col natp "Current column we're at.")
1611
;; :returns (mv (new-col natp :rule-classes :type-prescription)
1612
;; (acc character-listp :hyp (character-listp acc)))
1613
;; (b* ((x (mbe :logic (acl2::symbol-fix x) :exec x))
1614
;; (pkg (mbe :logic (acl2::symbol-fix pkg) :exec pkg))
1615
;; (col (lnfix col))
1616
;; (xname (symbol-name x))
1617
;; (xpkg (symbol-package-name x))
1618
;; ((when (or (equal xpkg xname)
1619
;; (equal (intern-in-package-of-symbol xname pkg) x)))
1620
;; (vl-ppr-explode-symbol-aux xname col acc))
1621
;; ((when (equal xpkg "KEYWORD"))
1622
;; (vl-ppr-explode-symbol-aux xname (+ 1 col) (cons #\: acc)))
1623
;; ((mv col acc) (vl-ppr-explode-symbol-aux xpkg col acc))
1625
;; (acc (list* #\: #\: acc)))
1626
;; (vl-ppr-explode-symbol-aux xname col acc))
1628
;; (defthm vl-printedlist-p-of-vl-ppr-explode-symbol
1629
;; (implies (vl-printedlist-p acc)
1630
;; (vl-printedlist-p (mv-nth 1 (vl-ppr-explode-symbol x pkg col acc))))))
1632
;; (define vl-ppr-explode-string
1633
;; :parents (vl-basic-fmt)
1634
;; :short "Print a string."
1638
;; :returns (mv (new-col natp :rule-classes :type-prescription)
1639
;; (acc character-listp :hyp (character-listp acc)))
1640
;; (b* ((x (string-fix x))
1641
;; (col (lnfix col))
1643
;; (vl-ppr-escape-slashes x 0 (length x) #\" (+ 1 col) (cons #\" acc))))
1644
;; (mv (+ 1 col) (cons #\" acc)))
1646
;; (defthm vl-printedlist-p-of-vl-ppr-explode-string
1647
;; (implies (vl-printedlist-p acc)
1648
;; (vl-printedlist-p (mv-nth 1 (vl-ppr-explode-string x col acc))))))
1650
;; (define vl-ppr-explode-atom
1651
;; :parents (vl-basic-fmt)
1654
;; (base print-base-p)
1657
;; :hooks ((:fix :args ((pkg symbolp) (col natp))))
1658
;; :returns (mv (new-col natp :rule-classes :type-prescription)
1659
;; (acc character-listp :hyp (character-listp acc)))
1660
;; (b* ((col (lnfix col))
1661
;; ((when (symbolp x))
1662
;; (vl-ppr-explode-symbol x pkg col acc))
1663
;; ((when (stringp x))
1664
;; (vl-ppr-explode-string x col acc))
1665
;; ((when (acl2-numberp x))
1666
;; (let* ((explode (explode-atom x base))
1667
;; (len (len explode)))
1668
;; (mv (+ col len) (revappend explode acc))))
1669
;; ((when (characterp x))
1671
;; (#\Space (mv (+ col 7) (str::revappend-chars "#\\Space" acc)))
1672
;; (#\Newline (mv (+ col 9) (str::revappend-chars "#\\Newline" acc)))
1673
;; (#\Tab (mv (+ col 5) (str::revappend-chars "#\\Tab" acc)))
1674
;; (#\Rubout (mv (+ col 8) (str::revappend-chars "#\\Rubout" acc)))
1675
;; (#\Page (mv (+ col 6) (str::revappend-chars "#\\Page" acc)))
1676
;; (otherwise (mv (+ col 3) (list* x #\\ #\# acc))))))
1677
;; (raise "Bad atom: ~x0." x)
1678
;; (mv (+ col 10) (str::revappend-chars "<bad atom>" acc)))
1680
;; (defthm vl-printedlist-p-of-vl-ppr-explode-atom
1681
;; (implies (vl-printedlist-p acc)
1682
;; (vl-printedlist-p (mv-nth 1 (vl-ppr-explode-atom x pkg base col acc))))))
1685
;; (define vl-stupid-ppr1
1686
;; :parents (vl-basic-fmt)
1687
;; :short "Barbaric pretty-printer."
1688
;; ((x "Any ACL2 object.")
1689
;; (pkg symbolp "Home package we're printing from.")
1690
;; (base print-base-p "Numeric base for printing numbers.")
1691
;; (rmargin natp "Right margin for line wrapping.")
1692
;; (in-listp booleanp "Are we currently in a list?")
1693
;; (col natp "Current column number.")
1695
;; :hooks ((:fix :args ((pkg symbolp)
1697
;; (in-listp booleanp)
1699
;; :returns (mv (new-col natp :rule-classes :type-prescription)
1700
;; (new-acc character-listp :hyp (character-listp acc)))
1701
;; :verify-guards nil
1702
;; (b* ((col (lnfix col))
1703
;; (rmargin (lnfix rmargin))
1705
;; (vl-ppr-explode-atom x pkg base col acc))
1708
;; (vl-stupid-ppr1 (car x) pkg base rmargin nil col acc)
1709
;; (vl-stupid-ppr1 (car x) pkg base rmargin nil (+ 1 col) (cons #\( acc))))
1710
;; ((when (not (cdr x)))
1711
;; (mv (+ 1 (lnfix col)) (if in-listp acc (cons #\) acc))))
1713
;; ((mv col acc) (if (< col rmargin)
1715
;; (mv 0 (cons #\Newline acc))))
1716
;; ((when (consp (cdr x)))
1717
;; ;; Successive elements of a list, no dots.
1718
;; (b* (((mv col acc)
1719
;; (vl-stupid-ppr1 (cdr x) pkg base rmargin t (+ 1 col) (cons #\Space acc))))
1720
;; (mv (+ 1 (lnfix col))
1721
;; (if in-listp acc (cons #\) acc)))))
1723
;; ;; End element, need a dot.
1725
;; (acc (list* #\Space #\. #\Space acc))
1728
;; ((mv col acc) (if (< col rmargin)
1730
;; (mv 0 (cons #\Newline acc))))
1733
;; (vl-stupid-ppr1 (cdr x) pkg base rmargin t col acc)))
1735
;; (mv (+ 1 (lnfix col))
1736
;; (if in-listp acc (cons #\) acc))))
1738
;; (defthm vl-printedlist-p-of-vl-stupid-ppr1
1739
;; (implies (vl-printedlist-p acc)
1740
;; (vl-printedlist-p (mv-nth 1 (vl-stupid-ppr1 x pkg base rmargin in-listp col acc)))))
1742
;; (verify-guards vl-stupid-ppr1))
1741
1744
(define vl-skip-ws
1742
1745
:parents (vl-basic-fmt)