public inbox for kawa@sourceware.org
 help / color / mirror / Atom feed
* How to get the return type kawa would infer for an expression?
@ 2019-08-13 20:48 spellcard199
  0 siblings, 0 replies; only message in thread
From: spellcard199 @ 2019-08-13 20:48 UTC (permalink / raw)
  To: kawa

Hello. I'm a beginner trying to make an emacs library called "geiser" to work with kawa and having access to the kawa's type inference could be useful for java completion and method arglist.

Is there a simple way to get the return type the compiler would infer for an expression? In the end I would like to obtain something like `(which-return-type-would-you-tell-for-this '(....))`.

I read in a past thread in the mailing list archive that the kind of type inference the kawa compiler does is based on "optimistic", not static type checking, but I think that's ok if the user is aware of it.

The reason I'm trying to avoid plain reflection on the sexp, like =(*:getMethods (*:getClass '(...)))=, is that the (...) form could have side effects the programmer may not want to trigger just to get completions.

P.S.

While I was trying to find this by myself I wrote the following copy/pasting from kawa source code and noticed that after `(gnu.expr.ModuleExp:evalToClass comp #!null)`
type warnings appear in the sourceMessages, so the compiler has to know something about types at that point. Maybe the answer to my question is near there?

#+BEGIN_SRC scheme
(let* ((code-str "(define (foobar x) (x:concat \"foobar\"))")
       (inp       (gnu.kawa.io.CharArrayInPort code-str))
       (messages  (gnu.text.SourceMessages))
       (s         (kawa.standard.Scheme))
       (env       (s:getEnvironment))
       (lexer     (s:getLexer inp messages))
       (ctx       (gnu.mapping.CallContext:getInstance))
       (out       (gnu.kawa.io.CharArrayOutPort))
       (opts      gnu.expr.Language:PARSE_IMMEDIATE)
       (comp      (s:parse lexer opts #!null)))

  ;; type warnings are not yet produced
  (display "msg-dbg-1:\n")
  (messages:printAll out 999)
  (out:flush)
  (display (java.lang.String (out:toCharArray)))
  (newline)

  (gnu.expr.ModuleExp:evalToClass comp #!null)

  ;; type warnings present
  (display "msg-dbg-2:\n")
  (messages:printAll out 999)
  (out:flush)
  (display (java.lang.String (out:toCharArray)))
  (newline))
#+END_SRC

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2019-08-13 20:48 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-08-13 20:48 How to get the return type kawa would infer for an expression? spellcard199

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).