[Top][All Lists]

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

[Chicken-users] Chicken Workflow for Editing C Code

From: F. Rafael Leon
Subject: [Chicken-users] Chicken Workflow for Editing C Code
Date: Tue, 7 Apr 2015 11:21:32 -0400

On Tue, Apr 7, 2015 at 9:48 AM, Peter Bex <address@hidden> wrote:
>> Even when editing the C code, I wrap it in chicken and dynamically
>> load it over and over again as I refine the inner loop.
> Hey, that sounds interesting!  How do you do that?

This is a whole different topic from the performance debate.

I do the following and "It Works For Me":

I work from a chicken REPL.  I run the chicken interpreter with the
linenoise egg:

An alternative is to use rlwrap, but the result is that I end up with
a csi prompt with readline support:


In theory, it would be even better to run csi in an emacs buffer, but
I never adapted to that habit.

>From the prompt, I load a set of data into memory, and I put it in
srfi-4 vectors in the interpreter:

(define big-vector-a ... )
(define big-vector-b ... )

That is my starting state: a scheme prompt which represents a window
into a context holding some utility functions and lots of packed
binary data.

There are three more pieces to the puzzle:

Makefile - compiles and links things
innerloop.c - the file with the inner loop function with a "for" loop inside
example.scm - the wrapper for example.c

*** Makefile looks something like: example.o
        ld -shared -o example.o $(LIBDIR) -lchicken

%.o: %.c
        gcc -c -fPIC $^ $(INCDIR)

example.c: innerloop.c
        chicken example.scm

*** innerloop.c looks like:

int innerfunc(unsigned char *dat){
              for( ... ){
                        ... }

*** and example.scm:

(declare (unit example))

(foreign-declare "#include \"innerloop.c\" ")
(define innerwrap
    (lambda (mybigvector)
             innerfunc u8vector)


and then from my prompt, I run:

#;1> (load-library 'example "")
#;2> (innerwrap big-vector-a)

Then, edit innerloop.c and type "make" again and then hit the up arrow
and the enter key:

#;3> (load-library 'example "")
#;4> (innerwrap big-vector-a)

I do this over and over again until the C code is fast.


reply via email to

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