From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from majordomo@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id XAA21554; Tue, 6 Mar 2001 23:56:34 +0100 (MET) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id XAA21518 for ; Tue, 6 Mar 2001 23:56:33 +0100 (MET) Received: from smtp4-cm.mail.eni.net (smtp4-cm.mail.eni.net [216.133.226.137]) by nez-perce.inria.fr (8.11.1/8.10.0) with ESMTP id f26MuWD27357 for ; Tue, 6 Mar 2001 23:56:32 +0100 (MET) Received: from checkerlap.d6.com (node-d8e9cca2.powerinter.net [216.233.204.162]) by smtp4-cm.mail.eni.net (8.9.3/8.9.3) with ESMTP id OAA00781; Tue, 6 Mar 2001 14:56:09 -0800 Message-Id: <4.3.2.7.2.20010306140915.03782b00@shell16.ba.best.com> X-Sender: def6@shell16.ba.best.com X-Mailer: QUALCOMM Windows Eudora Version 4.3.2 Date: Tue, 06 Mar 2001 14:56:51 -0800 To: qrczak@knm.org.pl (Marcin 'Qrczak' Kowalczyk), caml-list@inria.fr From: Chris Hecker Subject: Re: [Caml-list] create a closure in external C function? In-Reply-To: References: <4.3.2.7.2.20010306011427.03669de0@shell16.ba.best.com> <20010306180128.B12522@pauillac.inria.fr> <4.3.2.7.2.20010306111106.0372b7d0@shell16.ba.best.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk >> You can pass a closure to a C function and apply it to arguments >> with the callback.h library pretty easily. >It's not enough to convert a closure to a C function pointer. >For example to wrap C's qsort() in this interface: > ('a -> 'a -> int) -> 'a array -> unit Right, but it's part of the solution. The plan is to make it so you can do that automatically. On the C side, we'll use the ffcall trampoline/vacall interface to pass qsort the pointer to a function that calls back the caml function with the right parms. It's gonna be beautiful (or go down in flames, one of the two :). There are only a couple loose ends to tie up and I'm confident we'll be able to get it working in its full insane generality. You'll still want to use an interface generator for any permanent functions you want to hook because this is going to generate a bunch of code to loop over arguments at runtime and whatnot, but for dynalinking to dlls (or doing stuff like OpenGL extensions) it'll rule. Hopefully it'll only be 20% or so slower than a direct external function call. It's not going to handle records or polymorphism at first, of course (or even passing or returning closures when I first write it). I've got a plan for handling records, but I need to understand polymorphism more before I can think about that (in fact, I can't do any real work on this for a couple weeks, but I'm trying to lay the groundwork). I'm also a little terrified of making this play nice with the GC, but we'll blow up that bridge when we come to it. Chris ------------------- To unsubscribe, mail caml-list-request@inria.fr. Archives: http://caml.inria.fr