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]

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


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