Re: [ooc-compiler] Interfacing OOC to Gnu Scientific Library
Brought to you by:
mva
|
From: Stewart G. <sgr...@ip...> - 2002-02-04 13:50:05
|
Michael van Acken wrote:
>
> Stewart Greenhill <sgr...@ip...> writes:
>
> > [...]
> > 2) GSL makes quite frequent use of C's ability to pass / return structures
> > by value. I did a rough calculation and it appears that of 3500 functions,
> > approximately 500 are affected in this way. This includes all complex math
> > functions, some BLAS functions (eg. passing complex constants by value), and
> > various fuctions related to the use of views of vectors and matrices.
> >
> > In the translated interface the affected functions are annotated "Function
> > returns RECORD", or "Function has RECORD parameter" (or both) so searching
> > for "Function" will show you which ones are involved.
> >
> > It would be useful to be able to pass C records by value to and from C
> > functions. I suspect that this is probably not too hard to acheive, although
> > I have not looked at the details. Michael, how easy is this to do? I'm not
> > suggesting that the feature be used within Oberon-2, just as a way of
> > interfacing to C. It would only need to work with records declared in
> > interface modules.
>
> There are two issues here: Handling of "struct" values that are passed
> to parameters, and structured return values (returning a "struct" from
> a function).
>
> The former needs a flag for interface module (probably a module global
> flag for INTERFACE), changes to the code that emits procedure headers
> (interpreting the flag), and the code that produces values that are
> passed to these arguments. All in all, this seems to be pretty
> straightforward.
>
> The second issue is more of a problem. With OOC1, returning a
> structured value from a function is not anticipated. Changing this
> could be a major piece of work.
>
> All in all: these two changes required lots of work ;-)
OK, well perhaps we can flag this as a possible feature for OOC2.
In the mean time, I guess the only work-around is to generate some kind of
wrapper functions. These would map each struct value C parameter to a VAR
RECORD parameter in the Oberon-2 wrapper. The result would be returned via
an extra VAR result parameter. For example, if
str F (str a, str b)
has the following wrapper:
F_wrapper(str * a, str * b, str * c) {
*c = F(*a, *b);
}
which has the Oberon-2 declaration:
F_wrapper(VAR a, b, c : str);
It would of course be slower, but should work fine.
Cheers,
Stewart
|