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 TAA16119; Tue, 6 Mar 2001 19:20:25 +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 TAA15694 for ; Tue, 6 Mar 2001 19:20:24 +0100 (MET) Received: from mta5.snfc21.pbi.net (mta5.snfc21.pbi.net [206.13.28.241]) by nez-perce.inria.fr (8.11.1/8.10.0) with ESMTP id f26IKND24943; Tue, 6 Mar 2001 19:20:23 +0100 (MET) Received: from checkerlap.d6.com ([64.160.54.42]) by mta5.snfc21.pbi.net (Sun Internet Mail Server sims.3.5.2000.01.05.12.18.p9) with ESMTP id <0G9S005J6G8IGW@mta5.snfc21.pbi.net>; Tue, 6 Mar 2001 10:19:30 -0800 (PST) Date: Tue, 06 Mar 2001 10:19:23 -0800 From: Chris Hecker Subject: Re: [Caml-list] create a closure in external C function? In-reply-to: <20010306180128.B12522@pauillac.inria.fr> X-Sender: def6@shell16.ba.best.com To: Xavier Leroy Cc: caml-list@inria.fr Message-id: <4.3.2.7.2.20010306100442.00e18a60@shell16.ba.best.com> MIME-version: 1.0 X-Mailer: QUALCOMM Windows Eudora Version 4.3.2 Content-type: text/plain; charset="us-ascii" References: <4.3.2.7.2.20010306011427.03669de0@shell16.ba.best.com> <4.3.2.7.2.20010306011427.03669de0@shell16.ba.best.com> Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk At 06:01 PM 3/6/01 +0100, Xavier Leroy wrote: >Not directly, at least. Building closures from C isn't impossible, >just very delicate and highly processor-dependent (in the case of the >native-code compiler). >Right. caml_c_call does part of the job, but is indeed very >platform-specific. It seems like most of the platform specific parts are already there in pieces in the native compiler itself. I'm not familiar enough with calling conventions on the other platforms, but is it true that one could stitch together a bunch of the asmrun functions to give us a simple c-callable function that can be passed as a closure? Or, are the caml calling conventions such that you need to do special stuff depending on how many arguments there are? > As Fabrice noted, the hard part is >to deal with arbitrary many C function types, determined dynamically. >There, you'd need some kind of dynamic invocation interface for C >functions, and I don't know of any C library that provides this in a >portable or semi-portable fashion. > ... At 11:50 AM 3/6/01 +0100, Fabrice Le Fessant wrote: >My problem is: how to call the function f_v, using the types in >types_v (either integer, char, string or double) to build the call, >and using arg1_v (translated using its type) as argument. >Of course, I can implement this easily on my PC, but I don't know any >way to implement such a function in an architecture-independant way... I think I can do this part with the ffcall library. It has functions for building c-callable functions, both in the stdargs way but with return values as well, and the opposite (where you incrementally tell it what paramters the function takes, and then it gives you back a pointer you can call as a full c function call). It's highly portable (I think it supports more platforms than ocaml, even, so it's overkill). I was hoping to avoid the "list of parms" solution and just get both ends hooked up directly, which would be really cool. >PS: I can give you the code I have already written for building the >closure, and so on if you are interested... but I'm stuck on this >function ! Yes, that'd be great. Please email me the code. Chris ------------------- To unsubscribe, mail caml-list-request@inria.fr. Archives: http://caml.inria.fr