diff options
author | Damien Doligez <damien.doligez-inria.fr> | 1998-10-26 19:19:32 +0000 |
---|---|---|
committer | Damien Doligez <damien.doligez-inria.fr> | 1998-10-26 19:19:32 +0000 |
commit | 3be947947e3249a9b362fc790d377e43c4108a62 (patch) | |
tree | fa0c0fbdd5b3148f926e2f7f15090f7bd7d9a44d /byterun/memory.h | |
parent | 59cb8750d21154c767d7224cd0f726b5da62d59b (diff) |
nouvelles fonctions alloc/alloc_small
git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@2134 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
Diffstat (limited to 'byterun/memory.h')
-rw-r--r-- | byterun/memory.h | 179 |
1 files changed, 167 insertions, 12 deletions
diff --git a/byterun/memory.h b/byterun/memory.h index 08a82fb7b..4c4d271c9 100644 --- a/byterun/memory.h +++ b/byterun/memory.h @@ -5,7 +5,7 @@ /* Damien Doligez, projet Para, INRIA Rocquencourt */ /* */ /* Copyright 1996 Institut National de Recherche en Informatique et */ -/* Automatique. Distributed only by permission. */ +/* en Automatique. Distributed only by permission. */ /* */ /***********************************************************************/ @@ -78,7 +78,172 @@ color_t allocation_color (void *hp); } \ } \ + +struct caml__roots_block { + struct caml__roots_block *next; + long ntables; + long nitems; + value *tables [5]; +}; + +extern struct caml__roots_block *local_roots; /* defined in roots.c */ + +/* The following macros are used to declare C local variables and + function parameters of type [value]. + + The function body must start with one of the [CAMLparam] macros. + If the function has no parameter of type [value], use [CAMLparam0]. + If the function has 1 to 5 [value] parameters, use the corresponding + [CAMLparam] with the parameters as arguments. + If the function has more than 5 [value] parameters, use [CAMLparam5] + for the first 5 parameters, and one or more calls to the [CAMLxparam] + macros for the others. + + If you need local variables of type [value], declare them with one + or more calls to the [CAMLlocal] macros. + Use [CAMLlocalN] to declare an array of [value]s. + + Your function may raise and exception or return a [value] with the + [CAMLreturn] macro. Its argument is simply the [value] returned by + your function. Do NOT directly return a [value] with the [return] + keyword. + + All the identifiers beginning with "caml__" are reserved by Caml. + Do not use them for anything (local or global variables, struct or + union tags, macros, etc.) +*/ + +#define CAMLparam0() \ + caml__roots_block *caml__frame = local_roots + +#define CAMLparam1(x) \ + CAMLparam0 (); \ + CAMLxparam1 (x) + +#define CAMLparam2(x, y) \ + CAMLparam0 (); \ + CAMLxparam2 (x, y) + +#define CAMLparam3(x, y, z) \ + CAMLparam0 (); \ + CAMLxparam3 (x, y, z) + +#define CAMLparam4(x, y, z, t) \ + CAMLparam0 (); \ + CAMLxparam4 (x, y, z, t) + +#define CAMLparam5(x, y, z, t, u) \ + CAMLparam0 (); \ + CAMLxparam4 (x, y, z, t, u) + +#define CAMLxparam1(x) \ + caml__roots_block caml__roots_##x; \ + void *caml__dummy_##x = ( \ + caml__frame, \ + (caml__roots_##x.next = local_roots), \ + (local_roots = &caml__roots##x), \ + (caml__roots_##x.nitems = 1), \ + (caml__roots_##x.ntables = 1), \ + (caml__roots_##x.tables [0] = &x), \ + NULL) + +#define CAMLxparam2(x, y) \ + caml__roots_block caml__roots_##x; \ + void *caml__dummy_##x = ( \ + caml__frame, \ + (caml__roots_##x.next = local_roots), \ + (local_roots = &caml__roots##x), \ + (caml__roots_##x.nitems = 1), \ + (caml__roots_##x.ntables = 2), \ + (caml__roots_##x.tables [0] = &x), \ + (caml__roots_##x.tables [1] = &y), \ + NULL) + +#define CAMLxparam3(x, y, z) \ + caml__roots_block caml__roots_##x; \ + void *caml__dummy_##x = ( \ + caml__frame, \ + (caml__roots_##x.next = local_roots), \ + (local_roots = &caml__roots##x), \ + (caml__roots_##x.nitems = 1), \ + (caml__roots_##x.ntables = 3), \ + (caml__roots_##x.tables [0] = &x), \ + (caml__roots_##x.tables [1] = &y), \ + (caml__roots_##x.tables [2] = &z), \ + NULL) + +#define CAMLxparam4(x, y, z, t) \ + caml__roots_block caml__roots_##x; \ + void *caml__dummy_##x = ( \ + caml__frame, \ + (caml__roots_##x.next = local_roots), \ + (local_roots = &caml__roots##x), \ + (caml__roots_##x.nitems = 1), \ + (caml__roots_##x.ntables = 4), \ + (caml__roots_##x.tables [0] = &x), \ + (caml__roots_##x.tables [1] = &y), \ + (caml__roots_##x.tables [2] = &z), \ + (caml__roots_##x.tables [3] = &t), \ + NULL) + +#define CAMLxparam5(x, y, z, t, u) \ + caml__roots_block caml__roots_##x; \ + void *caml__dummy_##x = ( \ + caml__frame, \ + (caml__roots_##x.next = local_roots), \ + (local_roots = &caml__roots##x), \ + (caml__roots_##x.nitems = 1), \ + (caml__roots_##x.ntables = 5), \ + (caml__roots_##x.tables [0] = &x), \ + (caml__roots_##x.tables [1] = &y), \ + (caml__roots_##x.tables [2] = &z), \ + (caml__roots_##x.tables [3] = &t), \ + (caml__roots_##x.tables [4] = &u), \ + NULL) + +#define CAMLlocal1(x) \ + value x = Val_unit; \ + CAMLxparam1 (x) + +#define CAMLlocal2(x, y) \ + value x = Val_unit, y = Val_unit; \ + CAMLxparam1 (x, y) + +#define CAMLlocal3(x, y, z) \ + value x = Val_unit, y = Val_unit, z = Val_unit; \ + CAMLxparam1 (x, y, z) + +#define CAMLlocal4(x, y, z, t) \ + value x = Val_unit, y = Val_unit, z = Val_unit, t = Val_unit; \ + CAMLxparam1 (x, y, z, t) + +#define CAMLlocal5(x, y, z, t, u) \ + value x = Val_unit, y = Val_unit, z = Val_unit, t = Val_unit, u = Val_unit; \ + CAMLxparam1 (x, y, z, t, u) + +#define CAMLlocalN(x, size) \ + value x [(size)] = { NULL }; \ + caml__roots_block caml__roots_##x; \ + void *caml__dummy_##x = ( \ + caml_frame, \ + (caml_roots_##x.next = local_roots), \ + (local_roots = &caml__roots##x), \ + (caml__roots_##x.nitems = (size)), \ + (caml__roots_##x.ntables = 1), \ + (caml__roots_##x.tables [0] = &(x [0])), \ + NULL) + +#define CAMLreturn(x) \ + local_roots = caml__frame; \ + return (x) + +/* convenience macro */ +#define Store_field(block, offset, val) modify (&Field (block, offset), val) + /* + NOTE: [Begin_roots] and [End_roots] are superseded by [CAMLparam]*, + [CAMLxparam]*, [CAMLlocal]*, [CAMLreturn]. + [Begin_roots] and [End_roots] are used for C variables that are GC roots. It must contain all values in C local variables and function parameters at the time the minor GC is called. @@ -95,16 +260,6 @@ color_t allocation_color (void *hp); You can use [Val_unit] as a dummy initial value for your variables. */ - -struct caml__roots_block { - struct caml__roots_block *next; - long ntables; - long nitems; - value *tables [5]; -}; - -extern struct caml__roots_block *local_roots; /* defined in roots.c */ - #define Begin_root Begin_roots1 #define Begin_roots1(r0) { \ @@ -170,7 +325,7 @@ extern struct caml__roots_block *local_roots; /* defined in roots.c */ /* [Push_roots] and [Pop_roots] are obsolete. - Use [Begin_roots] and [End_roots] instead. + Use [CAMLparam], [CAMLxparam], [CAMLlocal], [CAMLreturn] instead. */ /* [Push_roots] and [Pop_roots] are used for C variables that are GC roots. |