bind 0.992: typo fix by Kristian Lein-Mathisen

git-svn-id: https://code.call-cc.org/svn/chicken-eggs/release/4/bind/trunk@26848 fca3e652-9b03-0410-8d7b-ac86a6ce46c4
added support for nested structs: make-struct takes pointer and struct-getter returns locative

struct types in arguments in make-struct are converted to pointers
which are dereferenced in C.
cleanup: placed c-codeblock in separate function
added locative-wrappers to getters of nested structs:

(struct_point-x my-point)  ==> #<locative>

you can still get the raw blob contents using the % variant:

(%struct_point-x my-point) ==> ${.....} blob contents of struct
improved wrap-in-pointer helper-util

(wrap-in-pointer '(struct "foo")) --> (c-pointer (struct "foo"))
(wrap-in-pointer '((struct "foo") argname)) --> ((c-pointer (struct "foo")) argname)
added automatic wrapping of struct-by-value in argument type

the argument-type on the scheme-side is converted to

 (c-pointer (struct ...

and foreign-lambda is converted to foreign-lambda* where
struct-pointer arg is dereferenced on the c-side, which calls
to the original foreign function.
added conversion for struct return types

function returns void,
adds destination argument to start of arglist

;; this fixes generated code which won't compile:
;; (not supported by foreign)

(define get_position
     (foreign-lambda*
       (struct "point")
       (((c-pointer (struct "line")) a0))
       "C_return(get_position(a0));"))))

;; the new version should work, but requires
;; a new desination in its first argument:

---->
(define %get_position
     (foreign-lambda*
       void
       (((c-pointer (struct "point")) dest) ((c-pointer (struct "line")) a0))
       "dest=(get_position(a0));"))
added wrapper for struct as return-type (returns #<locative>)

last commit produces %-versions of functions that return structs,
where the first argument is the destination of the result of the
original function.

this commit adds a convenience non-% version which makes a blob and
passes it as the destination of the %-version. the #<locative> of this
blob is then returned. this should mimic struct return-types in a
relatively seamless manner.
bugfix: struct-by-value with prefix did not work

and prefix was included twice in generated function names
(used fix-num instead of ->symbol)
added tests for struct passing (struct by values in args and return types)
cleanup: in nested structs, using make-blob instead of stack allocation with foreign-primitive

like this:
[klm@kth tests]$ echo "struct line { struct point a, b; } " | chicken-bind -  -o -

;;; GENERATED BY CHICKEN-BIND FROM -
(begin
  (begin
    (define %line-a
      (foreign-primitive
        scheme-object
        (((c-pointer (struct "line")) s))
        "\nC_word ab [C_bytestowords(sizeof(C_header) + sizeof(struct point))];\n*((struct point*)C_data_pointer(ab)) = s->a;\nab [0] = C_BYTEVECTOR_TYPE | sizeof(struct point);\nC_return(ab);"))
    (define (line-a s) (location (%line-a s))))

The new version now produces hopefully cleaner code:

(begin
  (define line-a
    (lambda (s)
      (let ((blob (location
                    (make-blob (foreign-value "sizeof(struct point)" int))))
            (copy-struct!
              (foreign-lambda*
                void
                (((c-pointer (struct "point")) _dest)
                 ((c-pointer (struct "line")) s))
                "*_dest = s->a;")))
        (copy-struct! blob s)
        blob)))

Note that the %-version has disappeared