The following macro works fine under Ypsilon and does
exactly what I want. But under Ikarus it gives me the
following error:
Unhandled exception:
Condition components:
1. &who: make-c-function
2. &message: "raw symbol encountered in output of macro"
3. &syntax:
form: (make-c-function void __gmpf_abs (mpf_ptr mpf_srcptr))
subform: quote
4. &trace: #<syntax (make-c-function void __gmpf_abs (mpf_ptr mpf_srcptr))>
5. &trace: #<syntax (define-c-function mpf_abs (void __gmpf_abs (mpf_ptr
mpf_srcptr))) [char 2122 of ../libraries/mp/mpf.sls]>
(define-syntax make-c-function
(lambda (use-stx)
(define list-of-types
'(void
char schar signed-char uchar unsigned-char
int signed-int ssize_t uint unsigned unsigned-int size_t
long ulong unsigned-long float double
pointer void* char* FILE* callback))
(define (quote-if-predefined-type arg)
(if (memq arg list-of-types)
`(quote ,arg)
arg))
(syntax-case use-stx ()
((_ ?ret-type ?funcname (?arg-type0 ?arg-type ...))
(with-syntax
((ret
(quote-if-predefined-type
(syntax->datum (syntax ?ret-type))))
(args
(cons 'list
(map quote-if-predefined-type
(syntax->datum
(syntax (?arg-type0 ?arg-type ...)))))))
(syntax
(primitive-make-c-function ret '?funcname args)))))))
I understand that the value of the two additional pattern
variables "ret" and "args", is a symbol that does not have
the requird properties, according to Ikarus. I guess that
is because I should convert these symbols into syntaxes, so
I try this:
(define-syntax make-c-function
(lambda (use-stx)
(define list-of-types
'(void
char schar signed-char uchar unsigned-char
int signed-int ssize_t uint unsigned unsigned-int size_t
long ulong unsigned-long float double
pointer void* char* FILE* callback))
(define (quote-if-predefined-type arg)
(if (memq arg list-of-types)
`(quote ,arg)
arg))
(syntax-case use-stx ()
((use ?ret-type ?funcname (?arg-type0 ?arg-type ...))
(with-syntax
((ret
(datum->syntax (syntax use)
(quote-if-predefined-type
(syntax->datum (syntax ?ret-type)))))
(args
(datum->syntax (syntax use)
(cons 'list
(map quote-if-predefined-type
(syntax->datum
(syntax (?arg-type0 ?arg-type ...))))))))
(syntax
(primitive-make-c-function ret '?funcname args)))))))
and again Ypsilon works, but Ikarus gives me a different
error:
Unhandled exception:
Condition components:
1. &who: mpf_ptr
2. &message: "unbound identifier"
3. &undefined
4. &trace: #<syntax mpf_ptr>
5. &trace: #<syntax (define-c-function mpf_abs (void __gmpf_abs (mpf_ptr
mpf_srcptr))) [char 2122 of ../libraries/mp/mpf.sls]>
but I am sure that "mpf_ptr" is bound because Ypsilon
executes a program that requires the library in which that
binding is used.
Suggestions? Is the macro 1st or 2nd correct?
I can provide the whole code, but it is a bit complex.
--
Marco Maggi