public inbox for kawa@sourceware.org
 help / color / mirror / Atom feed
From: Per Bothner <per@bothner.com>
To: kawa@sourceware.org
Subject: Re: Analyzing Scheme source code
Date: Tue, 8 Dec 2020 19:19:31 -0800	[thread overview]
Message-ID: <794018ef-503f-111d-f5a7-36e1823c255a@bothner.com> (raw)
In-Reply-To: <CABgWrqqVRmv9Wq4FNDo6aUareX0-M_wLFPPJYNyazWYjRWMmxQ@mail.gmail.com>

On 12/8/20 6:32 PM, Duncan Mak via Kawa wrote:
> I started writing my own analyzer with the match macro, and it looks
> something like this:
> 
> (define (process-form form)
>    (match form
>      (['define [name @args] @body]
>       (cons name (map process-form body)))
>   ... etc ...

That would not handle macros or imports, without a lot of effort.

> Thinking a bit more, rather than doing it myself, I thought maybe I could
> reuse the existing machinery that's in Kawa already,

I think that is a better way to go, though it would need internal undocumented APIs.

There is a non-documented kawa.expressions library (kawa/lib/kawa/expressions.scm),
though it is current mostly used for optimizing map and some other procedures.
See compile_map.scm and compile_misc.scm for uses.

To scan for uses, define a sub-class of ExpVisitor or ExpExpVisitor
looking for ReferenceExp.

For a more ambitious approach, one could beef up KawaLanguageServer,
and use existing clients/IDEs.

> For example, it'd be useful to see (define-record-type ...) forms too,
> right now, I don't know how to get at them.

Compiling a sample program with --debug-print-expr lets you see the
Expression tree generated for the program.

> Also, I can't quite figure out how to open up the inside of a Declaration
> either -- I'm looking for a getBody() method that might give me an
> Expression[], but I haven't been able to find any methods of that sort.

A Declaration is the "symbol" being defined.  The form in the source code
that does the defining is usually a SetExp (if at top-level).
It is possible to map from Declaration to defining expressions, but it
includes assignments (since it is used for optimization), and is rather
complicated.
-- 
	--Per Bothner
per@bothner.com   http://per.bothner.com/

      parent reply	other threads:[~2020-12-09  3:19 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-12-08 23:49 Duncan Mak
2020-12-09  2:32 ` Duncan Mak
2020-12-09  3:00   ` Duncan Mak
2020-12-09  3:19   ` Per Bothner [this message]

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=794018ef-503f-111d-f5a7-36e1823c255a@bothner.com \
    --to=per@bothner.com \
    --cc=kawa@sourceware.org \
    /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).