From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from weis@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id LAA00669 for caml-red; Tue, 31 Oct 2000 11:39:25 +0100 (MET) 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 TAA23288 for ; Mon, 30 Oct 2000 19:40:38 +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 e9UIebr15413 for ; Mon, 30 Oct 2000 19:40:37 +0100 (MET) Received: from checkerlap.d6.com ([64.160.52.206]) by mta5.snfc21.pbi.net (Sun Internet Mail Server sims.3.5.2000.01.05.12.18.p9) with ESMTP id <0G39002L3AH3RG@mta5.snfc21.pbi.net> for caml-list@inria.fr; Mon, 30 Oct 2000 10:39:04 -0800 (PST) Date: Sun, 29 Oct 2000 19:13:08 -0800 From: Chris Hecker Subject: ocaml to c variant hashes X-Sender: def6@shell16.ba.best.com To: caml-list@inria.fr Message-id: <4.3.2.7.2.20001029184954.00a8e3b0@shell16.ba.best.com> MIME-version: 1.0 X-Mailer: QUALCOMM Windows Eudora Version 4.3.2 Content-type: text/plain; charset="us-ascii" Sender: weis@pauillac.inria.fr Hi, I'm looking at the lablGL stuff, and came across a utility that computes the ocaml hash value for a given variant name. The var2def.ml file in the package preprocesses a variables file and outputs a C header with the appropriate hash values. The ml file contains a function, hash_variant that does this hash, but that function is copied from the source code to the compiler. This doesn't seem like a very robust way to do this, since the internal hash function could change at any time (in fact, the comment in the code says hash_variant is from ctype.ml, but it's now in btype.ml). What's the right way to do this? I can think of 3 ways: 1. Like var2def.ml, and just hope the internal hash function doesn't change. 2. Do it at runtime, by calling a function on the C side with a string and the variant. That's slow and lame. 3. Do it with camlp4. This seems like the right way to do it because it's synced to the compiler version (I assume). Is that true? Are there better ways? It seems like this is important if we're going to mix ocaml and C a lot. Hmm...I just looked around a bit more, and the c interface docs talk about mlvalues.h's hash_variant, but I look in the source and hash.c's hash_variant is yet another copy of the same function. Is there some way to make it call the btypes.ml hash_variant to avoid potential versioning bugs? Given mlvalues.h's hash_variant, I suppose the correct way to do this is to call hash_variant at runtime? Unfortunately, that means you can't have a switch statement with the values predefined when you compile your C version... Also, the documentation for the hash_variant function in the html says that VConstr is hash_value("VConstr") and `VConstr is also hash_value("VConstr"), not hash_value("`VConstr") as you'd expect. Is that true? Chris