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

Reply via email to