On Sat, May 17, 2008 at 3:36 AM, john skaller
<[EMAIL PROTECTED]> wrote:
> No, we do just this for C. You do it like this:
>
> fun sin: float -> float = "sin($1)"
> requires header "extern float sin(float);";
>
> or for llvm I guess:
>
> fun sin: double -> double:
> "call double @sin(double $1)"
> requires header "declare double @sin(double)";

Thats a little bit simpler. We could also just hide everything, and do
something like this:

fun add: double -* double > double: "add"
fun sin: double -> double: "@sin"

And do the declare if the string starts with @. That loses the ability
to write arbitrary text. On the other hand, this would allow the
compiler to do things like choose between a "call", a "tail call", or
an "invoke" (which supports stack unwinding).

> proc sin: lvalue[double] * double =
> """
> ld %x, $2  # load %x with argument 2
> call double @sin(double %x)
> st %r,$1  # store result to argument 1
> """
>
> (using ld and st for load an store, and assuming result
> is returned in register %r).

True, but in many cases llvm can hide this away. LLvm uses load and
store only when interacting explicitly with the stack or heap. For
something like sin, you can just read and return the value directly.
They've even got support now for returning multiple values. In the
next release, I believe they're adding support for returning complex
data like structures and arrays.

> The best trick I can think of is:
>
> gen sin...
>
> i.e. use a generator to force calls to be unravelled to
>
>        tmp = sin(v);
>
> and then mangle it to
>
>        sin(tmp,v)
>
> and thence
>
>        ld %x,v
>        call double @sin(%x)
>        st %r, tmp

Hmm, interesting. I forgot that gen did that automatically.

Finally, I'll be uploading my patches shortly, once I finish this one last bug.

-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft 
Defy all challenges. Microsoft(R) Visual Studio 2008. 
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
Felix-language mailing list
Felix-language@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/felix-language

Reply via email to