public inbox for kawa@sourceware.org
 help / color / mirror / Atom feed
* Reflection on function argument types
@ 2016-12-28  5:38 Duncan Mak
  2017-01-01 18:19 ` Per Bothner
  0 siblings, 1 reply; 2+ messages in thread
From: Duncan Mak @ 2016-12-28  5:38 UTC (permalink / raw)
  To: kawa mailing list

Hello all,

Happy holidays!

I'm playing around with Kawa over Christmas break to learn more how
functions are represented in the system.

I wrote the following code:

(import (srfi 1))
(define (foo (a :: integer)) (+ a a))
(define (hello-number (n :: number) (i :: number)) (list "number" n))
(define (hello-string (s :: string)) (list "string" s))
(define (print-types (func :: gnu.mapping.MethodProc))
  (display (procedure-property func 'name)) (newline)
  (for-each (lambda (t) (display t) (newline))
            (map (lambda (i) (func:getParameterType i)) (iota
(func:numParameters))))
  (newline))
(print-types foo)
(print-types hello-number)
(print-types hello-string)

I'm surprise to see that the output differs between foo and hello-*:

foo
Type integer

hello-number
ClassType java.lang.Object
ClassType java.lang.Object

hello-string
ClassType java.lang.Object

Why is it that I only see java.lang.Object for the hello-* functions?
Shouldn't number and string show up, like it did for foo?

Thanks!


-- 
Duncan.

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: Reflection on function argument types
  2016-12-28  5:38 Reflection on function argument types Duncan Mak
@ 2017-01-01 18:19 ` Per Bothner
  0 siblings, 0 replies; 2+ messages in thread
From: Per Bothner @ 2017-01-01 18:19 UTC (permalink / raw)
  To: Duncan Mak, kawa mailing list



On 12/27/2016 09:34 PM, Duncan Mak wrote:

> I wrote the following code:
>
> (import (srfi 1))
> (define (foo (a :: integer)) (+ a a))
> (define (hello-number (n :: number) (i :: number)) (list "number" n))
> (define (hello-string (s :: string)) (list "string" s))
> (define (print-types (func :: gnu.mapping.MethodProc))
>   (display (procedure-property func 'name)) (newline)
>   (for-each (lambda (t) (display t) (newline))
>             (map (lambda (i) (func:getParameterType i)) (iota
> (func:numParameters))))
>   (newline))
> (print-types foo)
> (print-types hello-number)
> (print-types hello-string)
>
> I'm surprise to see that the output differs between foo and hello-*:
>
> foo
> Type integer
>
> hello-number
> ClassType java.lang.Object
> ClassType java.lang.Object
>
> hello-string
> ClassType java.lang.Object
>
> Why is it that I only see java.lang.Object for the hello-* functions?
> Shouldn't number and string show up, like it did for foo?

This turns out to be a problem with demangling.  'foo' works because
it doesn't have any special characters.

In ModuleMethod.java in resolveParameterTypes it says:
             String mangledName = Mangling.mangleNameIfNeeded(name);
but it should be:
             String mangledName = Mangling.mangleName(name);
  
Unfortunately, fixing this improves the accuracy of type-checking
enough to cause some problems.  For example this code
(simplified from r7rs-tests.scm):

(let ((val 'abc))
   (cond ((and (complex? val)
               (not (nan? val)))
          (display val))))

Kawa complains that the call to nan? is invalid because the argument val
is a symbol.  This is bogus, since the previous test to complex? ensures
nan? is never called.

I created this issue:
https://gitlab.com/kashell/Kawa/issues/1
-- 
	--Per Bothner
per@bothner.com   http://per.bothner.com/

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2017-01-01 18:19 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-12-28  5:38 Reflection on function argument types Duncan Mak
2017-01-01 18:19 ` Per Bothner

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