chicken-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Chicken-users] Macros and loading compiled code


From: Daniel Leslie
Subject: Re: [Chicken-users] Macros and loading compiled code
Date: Wed, 10 Sep 2014 07:05:43 -0700

I think you need to define the import library when building both test.scm and test.import.scm. If I do so, your test works:

address@hidden:~$ csc -s test.scm -j test
address@hidden:~$ csc -s test.import.scm -j test
address@hidden:~$ csi

CHICKEN
(c) 2008-2014, The Chicken Team
(c) 2000-2007, Felix L. Winkelmann
Version 4.9.0 (rev 3f195ba)
linux-unix-gnu-x86-64 [ 64bit manyargs dload ptables ]
compiled 2014-06-02 on yves (Linux)

#;1> (import test)
; loading ./test.import.so ...
; loading /var/lib//chicken/7/chicken.import.so ...
#;2> (a-macro 1 2)
3
#;3>

-Dan

On Wed, Sep 10, 2014 at 3:26 AM, Richard <address@hidden> wrote:
On Wed, 10 Sep 2014 00:01:54 -0700
alex <address@hidden> wrote:

> Hi,
>
> I defined a macro. I compiled it separately and built it into my main
> program. When my main program calls the load procedure on normal
> Scheme source files, the procedures in these files use the macro
> without complaint.
>
> However, when it loads the dynamic object code created from compiling
> those same source files, I get an error about an "unbound value" in a
> subexpression of a macro _expression_. This seems to be because the
> macro expressions are being evaluated as normal procedure
> applications. If I insert the macro definition verbatim into each
> source file before I compile it, the errors do not occur.
>
> I tried passing both the source file and the macro definition file as
> input to the compiler. The errors remain.
> What else can I do to ensure that the dynamic object code knows about
> the macro definition?
>
> --Alex
>
> _______________________________________________
> Chicken-users mailing list
> address@hidden
> https://lists.nongnu.org/mailman/listinfo/chicken-users

Try wrapping a module around the code to be compiled separately.
Compile it using the '-j <module-name>' flag then compile the generated
scheme file: <module-name>.import.scm

$ cat test.scm

(module test
*
(import chicken scheme)

(define-syntax a-macro
  (syntax-rules ()
    ((_ l r) (+ l r))))

(define (a-function l r)
  (+ l r))

)

compile like so:
$ csc -s test.scm -j test
$ csc -s test.import.scm

use it like so:
$ csi
#;1> (load "test.so")
#;2> (import test)
#;3> (a-function 1 2)
3
#;4> (a-macro 1 2)
3

I hope this is useful to you,
greetings,
Richard



_______________________________________________
Chicken-users mailing list
address@hidden
https://lists.nongnu.org/mailman/listinfo/chicken-users


reply via email to

[Prev in Thread] Current Thread [Next in Thread]