Dear list,

I'm again trying to understand how the mix CHICKEN+CRUNCH works.

My use case is (still)
- a program which should be written only in CRUNCH (and C)
- a bunch of test cases written in CHICKEN to test the CRUNCH modules.

Let's say we have this CRUNCH module:

    ;; foo.scm
    (module foo
        (foo)
        (import (scheme base)
                (crunch c))
        (define (foo)
            (c-value byte "0xAA"))
    )

And this silly test case:

    ;; foo-test.scm
    (import (scheme base)
            (scheme write)
            foo)
    (display (foo))
    (newline)

I know how to compile the CRUNCH module to use in a C program:

    chicken-crunch foo.scm -o foo.c
    gcc -I ... -c -o foo.o foo.c
    and so on

But now, I want to import this in a clean way in the test case. I see two flags
in chicken-crunch that seem to be for that, but I don't understand them.

    chicken-crunch -J -emit-wrappers wrap.scm foo.scm

The generated files (besides foo.c) are foo.import.scm:

    (begin
      (##sys#with-environment
        (lambda ()
          (##sys#register-compiled-module
            'foo
            '#f
            (scheme#list)
            '((foo . foo#foo))
            (scheme#list)
            (scheme#list)
            (scheme#list))))
      (if (memq #:crunched ##sys#features)
        (begin
          (crunch.compiler#declare-entity 'foo#foo '(procedure () integer) 
'foo))))

And wrap.scm:

    (module
      foo
      (foo)
      (import (scheme base) (chicken foreign))
      (define foo#foo (begin (foreign-lambda integer foo))))

// By the way, I had to do a small change in crunch-driver.scm again, to get the
// output in wrap.scm (see below)

Now, with these 3 files (foo.c, foo.import.scm, wrap.scm), what is the right way
to build foo-test.scm with csc?

Thanks for your help.

Best,
-Diogo

--
The following patch allows me to get some output with -emit-wrappers.

Index: crunch-driver.scm
===================================================================
--- crunch-driver.scm   (revision 45088)
+++ crunch-driver.scm   (working copy)
@@ -58,7 +58,7 @@
   (define (emit-wrappers out)
     (lambda (mod exps)
       (if mod
-          (emit-scheme-wrappers/module (##sys#module-name mod) exps out)
+          (emit-scheme-wrappers/module mod exps out)
           (emit-scheme-wrappers/exported exps out))))

   (define short-options (string->list "wxvdJ"))

Reply via email to