* When/how during compilation are bindings attached?
@ 2020-11-15 0:57 Arvydas Silanskas
2020-11-15 2:42 ` Per Bothner
0 siblings, 1 reply; 3+ messages in thread
From: Arvydas Silanskas @ 2020-11-15 0:57 UTC (permalink / raw)
To: kawa mailing list
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<Void> {
@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
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: When/how during compilation are bindings attached?
2020-11-15 0:57 When/how during compilation are bindings attached? Arvydas Silanskas
@ 2020-11-15 2:42 ` Per Bothner
2020-11-15 8:59 ` Arvydas Silanskas
0 siblings, 1 reply; 3+ messages in thread
From: Per Bothner @ 2020-11-15 2:42 UTC (permalink / raw)
To: Arvydas Silanskas, kawa mailing list
On 11/14/20 4:57 PM, Arvydas Silanskas via Kawa wrote:
> 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)
You needs to add this (after getting the language):
Language.setDefaults(language);
Language.setDefaults is automatically called by Scheme.registerEnvironment.
(I had to do a little experimentation and searching through the code ...)
--
--Per Bothner
per@bothner.com http://per.bothner.com/
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: When/how during compilation are bindings attached?
2020-11-15 2:42 ` Per Bothner
@ 2020-11-15 8:59 ` Arvydas Silanskas
0 siblings, 0 replies; 3+ messages in thread
From: Arvydas Silanskas @ 2020-11-15 8:59 UTC (permalink / raw)
To: Per Bothner; +Cc: kawa mailing list
That works, thank you!
2020-11-15, sk, 04:42 Per Bothner <per@bothner.com> rašė:
> On 11/14/20 4:57 PM, Arvydas Silanskas via Kawa wrote:
> > 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)
>
> You needs to add this (after getting the language):
>
> Language.setDefaults(language);
>
> Language.setDefaults is automatically called by Scheme.registerEnvironment.
>
> (I had to do a little experimentation and searching through the code ...)
> --
> --Per Bothner
> per@bothner.com http://per.bothner.com/
>
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2020-11-15 9:00 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-11-15 0:57 When/how during compilation are bindings attached? Arvydas Silanskas
2020-11-15 2:42 ` Per Bothner
2020-11-15 8:59 ` Arvydas Silanskas
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).