public inbox for cgen@sourceware.org
 help / color / mirror / Atom feed
From: Jim Blandy <jimb@redhat.com>
To: cgen@sources.redhat.com
Subject: New printing code
Date: Fri, 06 May 2005 21:57:00 -0000	[thread overview]
Message-ID: <vt2br7oc96b.fsf@zenia.home> (raw)


I've just committed the following: 

2005-05-06  Jim Blandy  <jimb@redhat.com>

	* pprint.scm, cos-pprint.scm: New files.

pprint.scm defines a new function, pprint, that prints cyclic and
shared structures using the Common Lisp notation: #0=(1 . #0)

It also defines a hook for "elision": printing certain kinds of values
in an abbreviated way.  Elided values are numbered in the output, and
there is a way to get them by number and use them in later
expressions.  The value passed directly to pprint is never elided, so
you can look inside elided values just by calling pprint on them
directly.

cos-pprint.scm defines those hooks so that COS objects and classes are
elided.  So, for example:

;;; Print a simple cyclic structure.
guile> (pprint (let ((p (cons 1 2)))
		 (set-cdr! p p)
		 p))
#0=(1 . #0#)

;;; Print the <insn> class.
guile> (pprint <insn>)

#0=#("class" <insn> (<ident>) ((syntax #:unbound #f . 0) (iflds #:unbound #f . 1) (iflds-values #f #f . 2) (ifield-assertion #f #f . 3) (fmt-desc #:unbound #f . 4) (ifmt #:unbound #f . 5) (sfmt #:unbound #f . 6) (tmp #:unbound #f . 7) (semantics #f #f . 8) (compiled-semantics #f #f . 9) (host-semantics #:unbound #f . 10) (timing #:unbound #f . 11)) ((gen-profile-code #f . #<procedure #f (self model when cycles-var-name)>) (gen-profile-locals #f . #<procedure #f (self model)>) (make! #f . #<procedure #f (self name comment attrs syntax iflds ifield-assertion semantics timing)>) (make! #f . #<procedure #f args>)) (#:unbound #:unbound #:unbound #:unbound #:unbound #f #f #:unbound #:unbound #:unbound #:unbound #f #f #:unbound #:unbound) #f #1=(#0# #f (2 . 3) #f (($ 2499 (class <ident>)) #f (2 . 0) #1#)))

;;; The superclass of <insn>, <ident>, was elided above as:
;;;   ($ 2499 (class <ident>))
;;; We can refer to it by ($ 2499), and see it unelided by passing
;;; it directly to pprint.
guile> (pprint ($ 2499))
#0=#("class" <ident> () ((name #:unbound #f . 0) (comment #:unbound #f . 1) (attrs #:unbound #f . 2)) ((set-atlist! #f . #<procedure #f (self newval)>) (set-comment! #f . #<procedure #f (self newval)>) (set-name! #f . #<procedure #f (self newval)>) (get-atlist #f . #<procedure #f (self)>) (get-comment #f . #<procedure #f (self)>) (get-name #f . #<procedure #f (self)>) (make! #f . #<procedure #f args>)) (#:unbound #:unbound #:unbound) #f (#0# #f (2 . 0) #f))
guile> 

One can even print CURRENT-ARCH this way; each instruction gets
elided, so you can pick it out with a ($) expression and mess with it.

It would be nice to fix Guile's own pretty-printer to handle cyclic
structure; then we'd get indentation, too.  But the elision hooks are
pretty important.  So I thought it would be best to at least make this
available as it is, since it makes CGEN a lot easier to debug.

                 reply	other threads:[~2005-05-06 21:57 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=vt2br7oc96b.fsf@zenia.home \
    --to=jimb@redhat.com \
    --cc=cgen@sources.redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).