summaryrefslogtreecommitdiffstats
path: root/byterun/custom.c
diff options
context:
space:
mode:
authorXavier Leroy <xavier.leroy@inria.fr>2000-02-10 14:04:59 +0000
committerXavier Leroy <xavier.leroy@inria.fr>2000-02-10 14:04:59 +0000
commit9e206909f48d5d2579b6ec17764d3273df23ff08 (patch)
tree3319a3e0c3383ed812f781859aadffd7f1462fdf /byterun/custom.c
parent7175ab048dcaaa39649ebc386ae37750baaf27e1 (diff)
Introduction des blocs de type Custom.
Remplacement des blocs de type Final par des blocs de type Custom. git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@2804 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
Diffstat (limited to 'byterun/custom.c')
-rw-r--r--byterun/custom.c79
1 files changed, 79 insertions, 0 deletions
diff --git a/byterun/custom.c b/byterun/custom.c
new file mode 100644
index 000000000..1c013ceab
--- /dev/null
+++ b/byterun/custom.c
@@ -0,0 +1,79 @@
+/***********************************************************************/
+/* */
+/* Objective Caml */
+/* */
+/* Manuel Serrano and Xavier Leroy, INRIA Rocquencourt */
+/* */
+/* Copyright 2000 Institut National de Recherche en Informatique et */
+/* en Automatique. All rights reserved. This file is distributed */
+/* under the terms of the GNU Library General Public License. */
+/* */
+/***********************************************************************/
+
+/* $Id$ */
+
+#include "alloc.h"
+#include "custom.h"
+#include "fail.h"
+#include "memory.h"
+#include "mlvalues.h"
+
+int custom_compare_default(value v1, value v2)
+{
+ failwith("equal: abstract value");
+ return 0;
+}
+
+void custom_serialize_default(value v, unsigned long * wsize_32,
+ unsigned long * wsize_64)
+{
+ failwith("output_value: abstract value");
+}
+
+struct custom_operations_list {
+ struct custom_operations * ops;
+ struct custom_operations_list * next;
+};
+
+static struct custom_operations_list * custom_ops_table = NULL;
+
+void register_custom_operations(struct custom_operations * ops)
+{
+ struct custom_operations_list * l =
+ stat_alloc(sizeof(struct custom_operations_list));
+ Assert(ops->identifier != NULL);
+ Assert(ops->deserialize != NULL);
+ l->ops = ops;
+ l->next = custom_ops_table;
+ custom_ops_table = l;
+}
+
+struct custom_operations * find_custom_operations(char * ident)
+{
+ struct custom_operations_list * l;
+ for (l = custom_ops_table; l != NULL; l = l->next)
+ if (strcmp(l->ops->identifier, ident) == 0) return l->ops;
+ return NULL;
+}
+
+static struct custom_operations_list * custom_ops_final_table = NULL;
+
+struct custom_operations * final_custom_operations(final_fun fn)
+{
+ struct custom_operations_list * l;
+ struct custom_operations * ops;
+ for (l = custom_ops_final_table; l != NULL; l = l->next)
+ if (l->ops->finalize == fn) return l->ops;
+ ops = stat_alloc(sizeof(struct custom_operations));
+ ops->identifier = "_final";
+ ops->finalize = fn;
+ ops->compare = custom_compare_default;
+ ops->hash = custom_hash_default;
+ ops->serialize = custom_serialize_default;
+ ops->deserialize = custom_deserialize_default;
+ l = stat_alloc(sizeof(struct custom_operations_list));
+ l->ops = ops;
+ l->next = custom_ops_final_table;
+ custom_ops_table = l;
+ return ops;
+}