[Mono-devel-list] New compiler--CIL/CTS questions
Michal Moskal
malekith at pld-linux.org
Sat Feb 14 04:48:49 EST 2004
On Fri, Feb 13, 2004 at 07:05:43PM -0600, Chris Capel wrote:
> Hello, all.
>
> I'm in the planning phases of writing a Lisp compiler for the CLI, and
> I'm stuck trying to figure out how to implement dynamic functions
> (lambdas and macros, basically) efficiently using CIL, and cooperating
> as much as possible with the CTS. The problem is, I don't see any way
> to generate a method at runtime and then call it without using lots and
> lots and lots of really slow, excruciatingly non-dynamic reflection.
You don't need to generate code for each lambda expression. That is you
need to generate it once, and then pass the code along with closure.
As I am not familiar with lisp, syntax but to give you an idea:
(def adder (x) (lambda (y) (x + y))
Now you compile this to something like:
interface Function {
object apply (object arg);
}
class adder_closure {
int x;
}
class lambda_1 : Function {
adder_closure clo;
lambda_1 (adder_closure c) { clo = c; }
object apply (object arg)
{
return clo.x + (int)arg;
}
}
class someclass {
Function adder (int _x) {
adder_closure clo = new adder_closure ();
clo.x = _x;
return new lambda_1 (clo);
}
}
Instead of using Function interface, you can also use delegates, but
beware that delegate invocation is about 5 times slower then method
invocation, and creation is about 10-20 times slower, then adder_closure
+ lambda_1 creation. This what I have just shown on the other hand works
quite nice (I have bootstraping compiler using this).
I'm sorry, if you already know all this -- but you asked for lambdas.
Have you looked at Hot Dog Scheme compiler? Maybe they come out with
something better.
BTW: your question (as well as my reply :-) can be considered off topic
here, as this list is devoted to discuss mono, not .NET in general.
--
: Michal Moskal :: http://www.kernel.pl/~malekith :: GCS !tv h e>+++ b++
: When in doubt, use brute force. -- Ken Thompson :: UL++++$ C++ E--- a?
More information about the Mono-devel-list
mailing list