[CRUNCH] c-declare in non top-level

Diogo via Chicken-users <[email protected]>
Newsgroups gmane.lisp.scheme.chicken
Message-ID <[email protected]>
Hi,

I'm trying to write a macro that will do the following translation:

crunch:
    (set-bits! PORTD 1 2 XBIT)

C:
    PORTD |= (1 << 1) | (1 << 2) | (1 << XBIT);

chicken-crunch works if I use the following macro in the top-level of my file:

(define-syntax set-bits!
    (er-macro-transformer
     (lambda (x r c)
         (let* ((reg (symbol->string (cadr x)))
                (val (apply shift-bit (cddr x))))
         `(##core#c-declare ,(list (string-append reg " |= " val ";")))))))

But chicken-crunch fails if I use the macro inside a function, eg,

(define (main)
   (set-bits! PORTD 6))

The error is as follows:

% chicken-crunch led.scm -o led.c
Error: during expansion of (clr-bits! ...) - unbound variable: ##core#c-declare

        Call history:
        ...
        <eval>    [combine-or] (string-join lst " | ")
        <eval>    (##core#c-declare (list (string-append reg " &= ~(" val ");")))       <--
*** Error code 70

It also does not work if I replace ##core#c-declare with
    c-declare or ,(r 'c-declare)

This is probably something silly that I am not yet aware of.

Any hints?

Thanks.

Best
-- 
Diogo
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.