This is the mail archive of the
kawa@sourceware.org
mailing list for the Kawa project.
Problem using MyType[] in macros
- From: Bill Robinson <airbaggins at gmail dot com>
- To: kawa <kawa at sourceware dot org>
- Date: Sun, 22 Jan 2012 17:42:58 +0000
- Subject: Problem using MyType[] in macros
Hi.
Hi again,
I'm trying to make some macros that generate classes. I have come
unstuck trying to expand a java array type with a [] after an expanded
type name to make it an array.
I've made a simplified test case to demonstrate this:
File test.macros.scm:
(define (my-type-helper in)
(syntax-case in (array)
(my-integer
(syntax int))
((array element-type)
(with-syntax ((final-element-type (my-type-helper (syntax element-type))))
(syntax final-element-type[])))))
(define-syntax my-macro
(lambda (in)
(syntax-case in ()
((_ class-name type)
(with-syntax ((final-type (my-type-helper (syntax type))))
;; Just output for debugging
(display (format "final-type ~A~%" (syntax-object->datum (syntax
final-type))))
;; Obviously, this doesn't do much. I have other code (omitted for
this test) that generate methods based on "type"
(syntax (define-simple-class class-name ()
(theField :: final-type))))))))
File test.scm:
(my-macro MyClass (array my-integer))
And I am trying to compile like this:
$ kawa -f test.macros.scm -C test.scm && javap MyClass
(compiling test.scm to test)
final-type int
Compiled from "test.scm"
public class MyClass extends java.lang.Object{
public int theField;
public MyClass();
}
So theField ends up being just int instead of int[]. Any ideas how I
can make the (syntax final-element-type[]) expand to the correct
syntax for a java array type?
Thanks!
-Bill