On 17/05/2008, at 4:05 PM, Erick Tryzelaar wrote:
> On Fri, May 16, 2008 at 5:36 PM, Erick Tryzelaar
> <[EMAIL PROTECTED]> wrote:
>> Yay! Almost got it to work! The only thing left is to figure out how
>> to handle external functions.
>
> This seems like it's going to be a little more complicated.
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)";
>
> Hmm. Maybe this would work:
>
> body foo = 'declare i32 @foo(i32, i32)';
> fun foo: int * int -> int = "call i32 @foo(i32 %$1, i32 %$2)"
> requires foo;
>
> It's terribly ugly, but it might work for the first pass.
yes, that's how it would be done, only you can give the "requires"
part literally.
But this hides the real problem, which is that the call is not
an expression but a procedure, presumably with an implicit return
in a result register. So actually, you'd have to have
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).
This is all tricky.. the compiler would have to unravel expressions
and translate then to procedure calls, which would mean setting
up a correspondence between primitive functions and
their matching procedures.
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
--
john skaller
[EMAIL PROTECTED]
-------------------------------------------------------------------------
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
[email protected]
https://lists.sourceforge.net/lists/listinfo/felix-language