From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-lj1-x231.google.com (mail-lj1-x231.google.com [IPv6:2a00:1450:4864:20::231]) by sourceware.org (Postfix) with ESMTPS id AD42A3857809 for ; Sun, 15 Nov 2020 00:57:43 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org AD42A3857809 Received: by mail-lj1-x231.google.com with SMTP id h23so15458314ljg.13 for ; Sat, 14 Nov 2020 16:57:43 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:from:date:message-id:subject:to; bh=Rsrw8J7BT/EPzYh+AFTpaq4ViTLv9C309H+TmZf5wVE=; b=i1Uj3rlDdcDCiKrmwYQyeeDKZpBtWP6x18ugf8kO68L4+aHxqb5Q8MD/MAYdf1AQkF 7BUiU5vVC8UJTOiQTk1Eu1e38z73+y/Ye6nksWK/R8BmS1owjgWCoFAnKeTzl1iHdJ+j b9wr8CuZ/C3uI+qzuKL/oe+3QNruYQzO3R7kL+WOdTYuUbfRxRHjBtiuuKFVRy63b+E7 Y0LrqQ+LR2aCjK17q3DR1RpNYWvymOSSuMj2JnElRxGsEp7EqOdMR3PYc8SVlHepdmBB V4nv0ar+MlShnzGtxsL7Oijh2dnDkx+lZrTATB/5PHoTlRqoYOW0SBDbf8IbFvI0mCSP flBw== X-Gm-Message-State: AOAM532mlPsu6jyTOWEtiSrRlmY1ZmN257akBaZ8Y0GvYMFhKlLtY9xa KPhe1o6KAkKJACZQmYQkeA8Q/k37417Xk4ucI/ntSiZZSlCqPQ== X-Google-Smtp-Source: ABdhPJzmESxeKaF+hpinHWI9OC/+A8I2EaGVoG2daX4P+GIMFPBwc6ZSUTee3nvSOV5ETN9ddBgbGWOP6poxj+wS79w= X-Received: by 2002:a05:651c:134f:: with SMTP id j15mr3709266ljb.469.1605401861961; Sat, 14 Nov 2020 16:57:41 -0800 (PST) MIME-Version: 1.0 From: Arvydas Silanskas Date: Sun, 15 Nov 2020 02:57:31 +0200 Message-ID: Subject: When/how during compilation are bindings attached? To: kawa mailing list X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, HTML_MESSAGE, RCVD_IN_DNSWL_NONE, 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 Content-Type: text/plain; charset="UTF-8" X-Content-Filtered-By: Mailman/MimeDel 2.1.29 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: Sun, 15 Nov 2020 00:57:45 -0000 I'm working with tracking of definition place for identifiers. For some reason, found identifiers don't have binding information attached, do you have insight why that could be? Here is standalone snippet (mostly based on LSP in kawa source tree) import gnu.expr.Compilation; import gnu.expr.ExpExpVisitor; import gnu.expr.Expression; import gnu.expr.ReferenceExp; import gnu.kawa.io.CharArrayInPort; import gnu.text.SourceMessages; import kawa.standard.Scheme; import java.io.IOException; import java.util.Arrays; import java.util.stream.Collectors; public class TestModuleBinding { public static void main(String[] args) throws IOException { var source = new String[]{ "(define (a) 1)", "(a)" }; var sourceCode = Arrays.stream(source).collect(Collectors.joining("\n")); int line = 2; int col = 2; var language = Scheme.getR7rsInstance(); var inPort = CharArrayInPort.make(sourceCode); var sourceMessages = new SourceMessages(); Compilation compilation = language.parse(inPort, sourceMessages, Scheme.PARSE_FOR_EVAL); language.resolve(compilation); class FindDecl extends ExpExpVisitor { @Override protected Expression visitReferenceExp(ReferenceExp exp, Void ignored) { var expLine = exp.getLineNumber(); var expCol = exp.getColumnNumber(); if (line == expLine && col == expCol) { if (!exp.getName().equals("a")) throw new RuntimeException("Expected 'a'"); if (exp.getBinding() == null) throw new RuntimeException("Expected non-null binding"); } return super.visitReferenceExp(exp, ignored); } } FindDecl fd = new FindDecl(); var module = compilation.getModule(); fd.visit(module, null); } } Arvydas