chicken-users
[Top][All Lists]
Advanced

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

[Chicken-users] patch for chicken-bind!


From: Kristian Lein-Mathisen
Subject: [Chicken-users] patch for chicken-bind!
Date: Sat, 20 Oct 2012 20:21:17 +0200



Hi guys!

Some of you may have heard me whining about struct-by-value over the summer. I finally made a patch for chicken-bind that makes this possible a while back, which made it into chicken-bind 1.0. So that's good, but were two problems:

1. The code was a little bit tricky
2. It was not extensible

So, I've written a new patch which rewrites the struct-by-value support and introduces a concept of a 'bind-adapter'. This implementation should be much more readable.

It is also extensible. You can write your own adapters, which can handle conversions of different types automatically. This is useful if you have a lot of function declarations in your include-files and don't want to manually compose new foreign-lambda* for each function. I have 392 such declarations in my Chickmunk project, there's my motivation!

If you want to have a peek, check out chicken-adapters.scm. And yey, there are comments! There were a lot of problems that kept re-appearing, which I hope to have solved with the introduction of what I called "cexp". These is a lispy C, and gives semantical meaning to foreign-lambda* C-bodies:

(foreign-lambda* void (((struct "foo") var1)
                       ((c-pointer (struct "foo")) var2))
                 (= "float x"
                    ("bar" var1 var2)))

var1's type is invalid because structure arguments are not supported by Chicken. However, pointer to structures are. We can change the argument of var1 to a pointer and dereference in C:

(foreign-lambda* void (((c-pointer (struct "foo")) var1)
                       ((c-pointer (struct "foo")) var2))
                 (= "float x"
                    ("bar" (deref var1) var2)))

When we 'compile' the cexp, we get "float x = bar(*var1 , var2)" which looks ok to me. This way, we get automatic conversion of argument types like this, return types of structures and nested structures. Implemtation-wise, each adapter solves its own task individually. One adapter can take advantage of another adapter's transformations (as opposed to a lot of duplicated code in my previous implementation). However, I hope I haven't reinvented the wheel with this cexp thing!

It would be great if this were reviewed and made part of the official chicken-bind.

Thanks!
K.

reply via email to

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