This is the mail archive of the kawa@sourceware.org mailing list for the Kawa project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: CL implementation questions


On Apr 4, 2012, at 2:37 PM, Charles Turner wrote:

I've attached some code showing
what I've done so far. It's not ready for serious consideration, but
I'd like to know if I'm on the right track. I have the following
behaviour with it:

#|kawa:1|# (defun test (x) (declare (integer x)) (+ x 10))
#|kawa:2|# (test 20)
30
#|kawa:3|# (test 50.4)
/dev/stdin:3:7: warning - type gnu.math.DFloNum is incompatible with
required type gnu.math.IntNum
Argument #1 '50.4' to 'test' has wrong type (gnu.math.DFloNum)
(expected: gnu.math.IntNum)
...

Looks good. That compiles to something like (modulo line numbers)


Method name:"test" public static Signature: (gnu.math.IntNum)gnu.math.IntNum
Attribute "Code", length:53, max_stack:2, max_locals:1, code_length:7
0: aload_0
1: bipush 10
3: invokestatic <Method gnu.math.IntNum.add (gnu.math.IntNum,int)gnu.math.IntNum>
6: areturn
Attribute "LineNumberTable", length:10, count: 2
line: 6 at pc: 0
line: 8 at pc: 0
Attribute "LocalVariableTable", length:12, count: 1
slot#0: name: x, type: gnu.math.IntNum (pc: 0 length: 7)


so it's definitely doing the right thing, even if it's incomplete and
needs some polishing. Good start!

#|kawa:4|# (defun test (x) (declare (gnu.lists.Sequence x)) (car x))
#|kawa:5|# (test '(1 2 3))
/dev/stdin:5:1: warning - type gnu.lists.PairWithPosition is
incompatible with required type gnu.math.IntNum
1
#|kawa:6|# (test 10)
Argument #1 '10' to 'test' has wrong type (gnu.math.IntNum) (expected:
gnu.math.IntNum)

Note the strange error message in the last line there, to my surprise,
that happens in Scheme too, which looks like a bug.

Yup, I see it too with (define (test x::integer) (+ x 10)) and then a subsequent (define (test x::gnu.lists.Sequence) (car x)). But only if I've called the original test function first before the redefinition:

$ kawa
#|kawa:1|# (define (test x::integer) (+ x 10))
#|kawa:2|# (define (test x::gnu.lists.Sequence) (car x))
#|kawa:3|# (test '(1 2 3))
1
#|kawa:4|# ^D
$ kawa
#|kawa:1|# (define (test x::integer) (+ x 10))
#|kawa:2|# (test 10)
20
#|kawa:3|# (define (test x::gnu.lists.Sequence) (car x))
#|kawa:4|# (test '(1 2 3))
/dev/stdin:4:1: warning - type pair-with-position is incompatible with required type integer
1
#|kawa:5|# ^D


So this is an issue with the REPL (some kind of method signature caching?),
not your declare tinkering.


I had to override Translator#checkDefaultBinding to get type lookups
working. As with the rest of this patch, it's not nice, just
exploration.

I have a feeling we'll find that some functionality currently found in kawa.standard.Scheme (such as getNamedType) ought to be pulled out into something more readily usable by other languages.

So far so good, and thanks for submitting your GSoC proposal. I hope to
have time to go over it later tonight or tomorrow morning.

-Jamie

--
Jamison Hope
The PTR Group
www.theptrgroup.com




Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]