How to get the return type kawa would infer for an expression?

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

How to get the return type kawa would infer for an expression?

spellcard199
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