caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Chris Hecker <checker@d6.com>
To: fabrice.le_fessant@inria.fr
Cc: caml-list@inria.fr
Subject: Re: [Caml-list] dynamically loading C functions
Date: Thu, 08 Mar 2001 01:34:34 -0800	[thread overview]
Message-ID: <4.3.2.7.2.20010308010305.00cd4140@shell16.ba.best.com> (raw)
In-Reply-To: <15015.16731.108064.51473@cremant.inria.fr>


>I've written a Dlopen module for x86 and alpha available at
>http://pauillac.inria.fr/~lefessan/src/dlopen.tar.gz

Neat!  This is a very nice type hack to get the return value parameterizable with format:

val dlsym : dll -> string -> ('c -> 'a,unit, 'c) format -> 'a

When I was thinking of using the printf format strings, I couldn't figure out how to get the implicit 'c return value out of there on the result, but putting it in the first type argument as well is ingenious!

Does this library ever build closures around C functions and pass them back to caml (like you mentioned in a previous mail)?  I don't see the code that does that anywhere.

 From looking at the cmmgen.ml source, it looks like closures are a pretty simple layout (there's a header before these):

if physical arity 1:
word: pointer to function
word: 3 (arity (as caml int 1 lsl 1 + 1))

if physical arity > 1:
word: pointer to a curry function generated at link time
word: arity
word: pointer to function

But I've only looked at x86 so far.  The compiler actually is pretty smart (as if we didn't know that already :).  From what I can tell, if a module has been compiled, the cmx file (and maybe the cmi file) has extra information in it about the physical arity of its functions, so when they're called from another module, the compiler can just directly call the function rather than grovel around in its closure datastructure to find its physical arity (or call a subroutine to do this, which is what happens if you haven't compiled a module and you call a function in it, or just have an mli file but no ml file backing it).  I guess this is one of the currying optimizations people have been talking about.  I wonder how compilation-unit-order-dependent this is...

Chris


-------------------
To unsubscribe, mail caml-list-request@inria.fr.  Archives: http://caml.inria.fr


  reply	other threads:[~2001-03-08  9:34 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2001-03-05 20:28 Chris Hecker
2001-03-05 21:24 ` Marcin 'Qrczak' Kowalczyk
2001-03-06  0:10   ` Chris Hecker
2001-03-06  0:55     ` Chris Hecker
2001-03-06 16:48       ` Marcin 'Qrczak' Kowalczyk
2001-03-06 18:02         ` Chris Hecker
2001-03-08  8:22           ` Fabrice Le Fessant
2001-03-08  9:34             ` Chris Hecker [this message]
2001-03-09 10:54               ` Fabrice Le Fessant

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4.3.2.7.2.20010308010305.00cd4140@shell16.ba.best.com \
    --to=checker@d6.com \
    --cc=caml-list@inria.fr \
    --cc=fabrice.le_fessant@inria.fr \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).