On 16/08/2012, at 6:54 AM, dobesv wrote:
> Currently to map C++ methods to felix you cannot rely on the default template.
>
> The default template for C function bindings is something like "$0($a)"
> (where $0 is the name of the function).
>
> For methods it should be "$1->$0($a)" or "$1.$0($a)".
>
> Perhaps an adjective "method" on the function definition would cause it to
> use the latter form when no explicit template is provided.
There's a somewhat related set of issues here.
(1) At present you can make function like:
fun f: int -> int -> int -> int = "f($1,$2,$3)";
but it won't work as expected, f 1 will fail by generating
f(1,$2, $3)
or else give an error (not sure). And f 1 2 3 will fail
the same way, trying to apply
f(1,$2,$3) 2 3
I could hack this so it works. Making f 1 2 3 work
isn't so hard. Making f 1 work is a bit harder.
however Felix already automagically wraps
macros like
f: int->int = "$1";
into functions by
fun f_closure (x:int) => f x;
if you happen to try to use f as a closure, you actually
get f_closure.
note that
fun f: int * int -> int;
is a cheat. The f macro will NOT accept a tuple argument,
it accepts two arguments, but Felix maps a tuple into these
two arguments. If you actually wanted a single tuple argument
you have to write
fun f: int * int -> int = "f($t)";
(2) There is another problem for C++ bindings:
fun f: int -> int;
binds to "whatever f is in scope". If you want to bind to
::myspace::f
you have to write
fun f:int->int = "::myspace::f($a)";
This is not much of a problem for function but for types,
there's no way to do it:
cstruct X { x ; int; };
binds Felix X to whatever X is in scope. It isn't possible
to bind X to ::myspace::X other than by
type X = "::myspace::X";
and if you do that you lose the members.
(3) For class methods something like:
cclass X {
fun f: int -> int;
}
might make sense, this produces:
fun f: X * int -> int = "$1.f($2)";
fun f: &X * int -> int = "$1->f($2)";
however that's a bit sick, better would be:
fun f: X -> int -> int
which would also allow an object closure, as well has
handling both variables of type X and pointers &X.
The only problem is that
f object
would be ambiguous if there's more than one method named f.
If you do this in C++ or any other OO language .. you deserve what you get!
note you can already write:
struct X {
x : int;
fun add (y:int) => self.x+y;
}
in Felix, and
anX . add
is perfectly legitimate and forms an object closure. The actual signature
of add is:
fun add: X -> int -> int;
and the definition is:
fun f(self:X) (y:int) => self.x + y;
The transformation is done in the parser so there is no semantic impact.
--
john skaller
[email protected]
http://felix-lang.org
------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and
threat landscape has changed and how IT managers can respond. Discussions
will include endpoint security, mobile security and the latest in malware
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
Felix-language mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/felix-language