Question: extending CodeGeneration[C] and array arguments

Does anyone know how to extend CodeGeneration[C], using AddFunction, so that the new function's signature matches a specific type of Matrix/Vector/Array?

By specific type I mean a match for a specific combination of indexing function, hardware datatype, order, and storage.

I haven't even had success using the 'anything' type in the signature, for (C) array arguments, for examples with the new function used within a proc and not just as an inlined example.

First the new function's "definition",

> with(CodeGeneration):
> with(LanguageDefinition):
>
> LanguageDefinition:-Define("NewC", extend="C",
>   AddFunction("foo", [anything]::anything,
>               proc(X)
>                  Printer:-Print("FOO(", X, ")")
>               end proc,
>               numeric=double));

And now a single inlined statement example, which is successful in its own limited way,

> Translate('`foo`(x)', language="NewC");
cg = FOO(x);

And now trying it within a procedure,

> p := proc(x::Array) foo(x); NULL: end proc:
>
> Translate(p, language="NewC");
Warning, type signature
[CodeGeneration:-Names:-ArrayType(CodeGeneration:-Names:-untyped,
CodeGeneration:-Names:-ArrayRanges(1..CodeGeneration:-Names:-unknown),
CodeGeneration:-Names:-ArrayOptions())]
for function foo is not recognized

void p (double *x)
{
  foo(x);
  ;
}

As you can see, that did not work, and the signature was not successfully matched and so the custum printing scheme was not used. I would like to be able to put something like,

Matrix(storage=rectangular,datatype=float[8],order=Fortran_order)

in the list portion of the second argument to AddFunction. Or some equivalent would do.

The goal is to be able to sign particular handling schemes by specific variants of the function signature.

It's clear that CodeGeneration[C] understands the array nature of the general "prototyped" Array argument x of procedure p. And so it generates its own form of intermediate code to represent it. But now, how can I specify the signature to  allow any kind of match?

acer

Please Wait...