Now that I've organized the compiler a bit, it's starting to get a little 
easier to see how we could do an [LLVM](http://llvm.org) backend for felix. One 
of the many challenges we'll have to deal with for that is what do we do for a 
foreign function interface. For those who don't know, one of the neat things 
felix does is compile into C++ code. This lets us easily define adds like this:

{{{
:::felix
fun add: int * int -> int = "$1 + $2";
fun sin: float -> float = "std::sin($1)";
}}}

Where we will just pass the string through the program, translating the 
`$`-prefixed values into the proper variable names in the output source. We can 
even do complex functions like this:

{{{
:::felix
fun foo: int * int * int -> int = "$1 + $2 - $3";
}}}

And still have it work.

For [LLVM](http://llvm.org), though, we'd be directly compiling against their 
API, since that would be more efficient. So, what can we do? One possibility 
would be to use [Ocs Scheme](http://will.iki.fi/software/ocs/) and our 
S-Expression Library, sex:

{{{
:::felix
fun add: int * int -> int = "`(add ,_1 ,_2)";
fun sin: float -> float = "`(ccall std::sin ,_1)";
fun foo: int * int * int -> int = "`(add ,_1 `(sub ,_2 ,_3))";
}}}

Then just implement in the backends how to translate these simple calls into 
the target format. The nice thing about this is that it stays reasonably 
generic. I was worried that we'd have to sprinkle `#IFDEF`s throughout our 
source, but this seems to avoid that in most situations.

-------------------------------------------------------------------------
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