From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from aibo.runbox.com (aibo.runbox.com [91.220.196.211]) by sourceware.org (Postfix) with ESMTPS id 454AA3835091 for ; Wed, 9 Dec 2020 03:19:53 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 454AA3835091 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=bothner.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=per@bothner.com Received: from [10.9.9.72] (helo=submission01.runbox) by mailtransmit02.runbox with esmtp (Exim 4.86_2) (envelope-from ) id 1kmq19-0002NA-Ca for kawa@sourceware.org; Wed, 09 Dec 2020 04:19:51 +0100 Received: by submission01.runbox with esmtpsa [Authenticated alias (524175)] (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) id 1kmq0t-0003ke-7c for kawa@sourceware.org; Wed, 09 Dec 2020 04:19:35 +0100 Subject: Re: Analyzing Scheme source code To: kawa@sourceware.org References: From: Per Bothner Message-ID: <794018ef-503f-111d-f5a7-36e1823c255a@bothner.com> Date: Tue, 8 Dec 2020 19:19:31 -0800 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.5.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00, KAM_DMARC_STATUS, NICE_REPLY_A, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: kawa@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Kawa mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 09 Dec 2020 03:19:54 -0000 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/