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 MAA11841; Sat, 22 May 2004 12:09:16 +0200 (MET DST) 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 MAA11855 for ; Sat, 22 May 2004 12:09:15 +0200 (MET DST) Received: from qrnik.knm.org.pl (paf87.warszawa.sdi.tpnet.pl [217.96.225.87]) by nez-perce.inria.fr (8.12.10/8.12.10) with ESMTP id i4MA9DEV016839 for ; Sat, 22 May 2004 12:09:14 +0200 Received: from qrnik ([192.168.0.1] ident=qrczak) by qrnik.knm.org.pl with esmtp (Exim 3.36 #1) id 1BRTRJ-0000Wd-00 for caml-list@inria.fr; Sat, 22 May 2004 12:09:13 +0200 Subject: Re: [Caml-list] Automatic wrapper generator From: "Marcin 'Qrczak' Kowalczyk" To: caml-list In-Reply-To: <1084869517.19838.409.camel@pelican.wigram> References: <1084869517.19838.409.camel@pelican.wigram> Content-Type: text/plain; charset=ISO-8859-2 Message-Id: <1085220553.32267.49.camel@qrnik> Mime-Version: 1.0 X-Mailer: Ximian Evolution 1.5.7 Date: Sat, 22 May 2004 12:09:13 +0200 Content-Transfer-Encoding: quoted-printable X-Miltered: at nez-perce with ID 40AF26C9.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Loop: caml-list@inria.fr X-Spam: no; 0.00; caml-list:01 marcin:01 'qrczak':01 kowalczyk:01 qrczak:01 wto:99 hackery:01 usr:01 include':01 zlib:01 ncurses:01 python:01 api:01 instructive:01 qsort:01 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk W li=B6cie z wto, 18-05-2004, godz. 18:38 +1000, skaller napisa=B3: > With some platform specific hackery, I am now able to=20 > wrap 90% of all headers in '/usr/include' and execute > a single Felix test case: It's impressive, but I'm afraid a high quality binding to an average library is impossible to obtain automatically. I'm currently wrapping some libraries for my own language. I have working bindings to zlib, ncurses, Python interpreter, some Unix API, and as a rather impractical but instructive example - qsort(). It's a tedious task because I set up high requirements for myself. Big ints are transparently converted even in case the C library uses 64-bit numbers, memory management is integrated with GC, various error codes are converted to exceptions, exceptions are propagated through C callbacks, C enumerations and ints which encode enumerations are translated in a typesafe manner (my language is dynamically typed, so it looks differently than in OCaml, but the issue is there too). More importantly, C libraries which can be made instances of generic APIs of my language are wrapped appropriately: you can use zlib as a layer on I/O streams, or treat gzip files with the same API as native files, use Python collections and numbers together with collections and numbers of my language, mixed in either environment, and use values hashed by one language as keys in dictionaries in the other language. All this seems impossible to be done automatically, and I feel it's important. I wonder how much the amount of work depends on the source and target languages. For example although interfacing to the Python interpreter, written in C, was a big task, interfacing to particular Python libraries themselves need zero additional code! And they even look quite usable, modulo lack of matching of additional generic interfaces. I have a working Gtk+ binding for free because Python people once wrapped it for Python. OCaml doesn't seem to use generic APIs with substitutable interfaces too much, because it's expressed either as modules, which are somewhat second-class, or as objects, which are quite heavy. For example there is no place to offer your semantics of arithmetic, to provide a layer of translation for I/O functions, or a type of a sequence. This is both a good and a bad thing: - Poor reuse of code, you can't use standard function on non-standard objects, e.g. character I/O works only on raw files. + No runtime dispatch, so it's fast. + Less work for interface generator :-) I will try to make a binding between my language and OCaml, but I'm not sure how should I approach it because OCaml is statically typed. Perhaps this time I should consider OCaml the "master" side where most glue code is put in. Objects of a dynamically typed language are easier to be operated on from other languages. It will be fun to use Python libraries from OCaml through my language. I've seen some Python binding for OCaml but it was very poor. --=20 __("< Marcin Kowalczyk \__/ qrczak@knm.org.pl ^^ http://qrnik.knm.org.pl/~qrczak/ ------------------- To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/ Beginner's list: http://groups.yahoo.com/group/ocaml_beginners