summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorXavier Leroy <xavier.leroy@inria.fr>2000-04-07 14:43:31 +0000
committerXavier Leroy <xavier.leroy@inria.fr>2000-04-07 14:43:31 +0000
commitd3c45d93f083cf7d30b54f682f0fcf6141d9ae58 (patch)
treed830b44a08364ca87e267484760082c131260da3
parentd2d789e8a8ed6f8a7d2816f7fc70c1d53bd4553a (diff)
Ajout de hash_variant (pour manipuler des variantes depuis C)
git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@3048 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
-rw-r--r--byterun/hash.c15
-rw-r--r--byterun/mlvalues.h3
2 files changed, 18 insertions, 0 deletions
diff --git a/byterun/hash.c b/byterun/hash.c
index af756eaf2..114d9d69c 100644
--- a/byterun/hash.c
+++ b/byterun/hash.c
@@ -131,3 +131,18 @@ static void hash_aux(value obj)
a priori unknown structure. Use its physical address as hash key. */
Combine((long) obj);
}
+
+/* Hashing variant tags */
+
+value hash_variant(char * tag)
+{
+ value accu;
+ /* Same hashing algorithm as in ../typing/btype.ml, function hash_variant */
+ for (accu = Val_int(0); *tag != 0; tag++)
+ accu = Val_int(223 * Int_val(accu) + *((unsigned char *) tag));
+ accu = accu & Val_int((1 << 31) - 1);
+ /* Force sign extension of bit 31 for compatibility between 32 and 64-bit
+ platforms */
+ return (int32) accu;
+}
+
diff --git a/byterun/mlvalues.h b/byterun/mlvalues.h
index cfa06d26d..434adba94 100644
--- a/byterun/mlvalues.h
+++ b/byterun/mlvalues.h
@@ -176,6 +176,9 @@ typedef opcode_t * code_t;
#define Class_val(val) Field(val, 0)
#define Oid_val(val) Long_val(Field(val, 1))
+/* Another special case: variants */
+extern value hash_variant(char * tag);
+
/* 2- If tag >= No_scan_tag : a sequence of bytes. */
/* Pointer to the first byte */