caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: skaller <skaller@users.sourceforge.net>
To: David Teller <David.Teller@ens-lyon.org>
Cc: Nathan Mishra Linger <nathan.mishralinger@gmail.com>,
	caml-list@yquem.inria.fr
Subject: Re: [Caml-list] OCaml/C interface
Date: Mon, 29 Oct 2007 00:34:33 +1100	[thread overview]
Message-ID: <1193578473.19122.33.camel@rosella.wigram> (raw)
In-Reply-To: <1193575003.6383.19.camel@Blefuscu>


On Sun, 2007-10-28 at 13:36 +0100, David Teller wrote:

> external "C" my_native_function = "char* stuff(char* a, char* b)" 
> 
> That was just a random thought, I have no particular interest in
> implementing this, but what do you think about it ?

This is the basis of how Felix binds to C/C++.

You need to provide ways to bind *types* as well.

With experience, you'll find various property annotations
are useful.

Felix says stuff like:

	type mytype = "mytype";
	fun f: int * mytype-> int = "f($1,$2)";

and emits appropriate code. Camlp4 can do the same thing
probably, and emit C glue.

Note your form of specification isn't as good as mine.
With coding like my 'f' you specify the name and Ocaml
calling convention, then the way to wrap an Ocaml call
to a C call. In particular you could write:

	fun f: int * mytype-> int = "g($1,100,$2)+1";

The problem with your notation is that it is a bit naive:
it assumes a simple correspondence between Ocaml and C calls
that doesn't exist in general: you need to use a richer
binding language.

The actual C code would make a function which is called
which does conversions based on type stuff for the
arguments $1 $2 etc, and then actually emit the C
code with replacements of the converted values.

You need to allow for more than one kind of conversion.
Concrete copying, as in integers, is not the same as a pointer
based representation (abstract type). It's important not
to fix one or the other but allow choices.

Felix also does this:

	fun f: ... = " .. " requires '#include "mine.h"';

so that you can put the header file etc in with the 
specification.

Once you use automated wrapping, it HAS to do everything
because you can no longer intervene -- the only alternative
is write your C glue by hand in a separate file, which is
precisely what the facility here is trying to avoid.

A good design goal here is .. GET RID OF int64 etc type
from Ocaml. Work on the binding feature until it can
be done by the user with no external C code.


-- 
John Skaller <skaller at users dot sf dot net>
Felix, successor to C++: http://felix.sf.net


  reply	other threads:[~2007-10-28 13:34 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-10-25 22:17 Nathan Mishra Linger
2007-10-26  9:18 ` [Caml-list] " Julien Moutinho
2007-10-26 18:13   ` Nathan Mishra Linger
2007-10-28 12:36     ` David Teller
2007-10-28 13:34       ` skaller [this message]
2007-10-28 13:48       ` Christopher L Conway
2007-10-28 15:39         ` David Teller

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=1193578473.19122.33.camel@rosella.wigram \
    --to=skaller@users.sourceforge.net \
    --cc=David.Teller@ens-lyon.org \
    --cc=caml-list@yquem.inria.fr \
    --cc=nathan.mishralinger@gmail.com \
    /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).