[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: ffi helper
From: |
Matt Wette |
Subject: |
Re: ffi helper |
Date: |
Sun, 19 Mar 2017 10:23:14 -0700 |
> On Mar 13, 2017, at 5:53 PM, Matt Wette <address@hidden> wrote:
>
>
>> On Mar 8, 2017, at 6:06 PM, Matt Wette <address@hidden> wrote:
>>
>> I’m now working on a FFI helper based on the nyacc C99 parser.
>
I am making some progress with some ragged prototype code.
Here is a top-level program, just pulling out three declarations to start:
(let* ((file "/opt/local/include/cairo/cairo-svg.h")
(defs '())
(incs '("/opt/local/include" "/opt/local/include/cairo" "/usr/include"))
(tree (my-parse defs incs file))
(file-decls (reverse (c99-trans-unit->udict tree #:filter cairo-filter)))
(udecl-dict (c99-trans-unit->udict/deep tree)))
(fold
(lambda (pair type-list)
(udecl->ffi-decl (cdr pair) type-list))
fixed-width-int-names
(filter
(lambda (e)
(member (car e)
'("cairo_matrix_t" "cairo_surface_t" "cairo_svg_surface_create")))
file-decls)))
And here is the autogenerated output for the declarations:
(define-std-pointer-wrapper cairo_surface_t*)
(define cairo_matrix_t
(bs:struct
`(,(string->symbol "xx") ,double)
`(,(string->symbol "yx") ,double)
`(,(string->symbol "xy") ,double)
`(,(string->symbol "yy") ,double)
`(,(string->symbol "x0") ,double)
`(,(string->symbol "y0") ,double)))
(define cairo_svg_surface_create
(let ((f (pointer->procedure
'*
(libcairo-func "cairo_svg_surface_create")
(list '* double double))))
(lambda (filename width_in_points height_in_points)
(let ((~filename (string->pointer filename))
(~width_in_points width_in_points)
(~height_in_points height_in_points)
(~result
(f ~filename ~width_in_points ~height_in_points)))
(wrap-cairo_surface_t* ~result)))))
I was not able to come up with a procedure that would take arguments “xx” and
“double” and generate the bs:struct pattern `(xx ,double). Help is welcome.