1995-08-09 08:06:35 -07:00
|
|
|
/***********************************************************************/
|
|
|
|
/* */
|
1996-04-30 07:53:58 -07:00
|
|
|
/* Objective Caml */
|
1995-08-09 08:06:35 -07:00
|
|
|
/* */
|
|
|
|
/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */
|
|
|
|
/* */
|
1996-04-30 07:53:58 -07:00
|
|
|
/* Copyright 1996 Institut National de Recherche en Informatique et */
|
1995-08-09 08:06:35 -07:00
|
|
|
/* Automatique. Distributed only by permission. */
|
|
|
|
/* */
|
|
|
|
/***********************************************************************/
|
|
|
|
|
|
|
|
/* $Id$ */
|
|
|
|
|
1995-07-11 11:09:15 -07:00
|
|
|
/* Operations on objects */
|
|
|
|
|
|
|
|
#include "alloc.h"
|
|
|
|
#include "major_gc.h"
|
|
|
|
#include "memory.h"
|
|
|
|
#include "minor_gc.h"
|
|
|
|
#include "misc.h"
|
|
|
|
#include "mlvalues.h"
|
|
|
|
#include "prims.h"
|
|
|
|
|
1997-09-02 05:55:01 -07:00
|
|
|
value static_alloc(value size) /* ML */
|
1995-07-11 11:09:15 -07:00
|
|
|
{
|
|
|
|
return (value) stat_alloc((asize_t) Long_val(size));
|
|
|
|
}
|
|
|
|
|
1997-09-02 05:55:01 -07:00
|
|
|
value static_free(value blk) /* ML */
|
1995-07-11 11:09:15 -07:00
|
|
|
{
|
1997-11-20 07:30:43 -08:00
|
|
|
stat_free((void *) blk);
|
1995-07-11 11:09:15 -07:00
|
|
|
return Val_unit;
|
|
|
|
}
|
|
|
|
|
1997-09-02 05:55:01 -07:00
|
|
|
value static_resize(value blk, value new_size) /* ML */
|
1995-07-11 11:09:15 -07:00
|
|
|
{
|
|
|
|
return (value) stat_resize((char *) blk, (asize_t) Long_val(new_size));
|
|
|
|
}
|
|
|
|
|
1997-09-02 05:55:01 -07:00
|
|
|
value obj_is_block(value arg) /* ML */
|
1995-07-11 11:09:15 -07:00
|
|
|
{
|
|
|
|
return Val_bool(Is_block(arg));
|
|
|
|
}
|
|
|
|
|
1997-09-02 05:55:01 -07:00
|
|
|
value obj_tag(value arg) /* ML */
|
1995-07-11 11:09:15 -07:00
|
|
|
{
|
|
|
|
return Val_int(Tag_val(arg));
|
|
|
|
}
|
|
|
|
|
1997-09-02 05:55:01 -07:00
|
|
|
value obj_block(value tag, value size) /* ML */
|
1995-07-11 11:09:15 -07:00
|
|
|
{
|
|
|
|
value res;
|
|
|
|
mlsize_t sz, i;
|
|
|
|
tag_t tg;
|
|
|
|
|
|
|
|
sz = Long_val(size);
|
|
|
|
tg = Long_val(tag);
|
|
|
|
if (sz == 0) return Atom(tg);
|
|
|
|
res = alloc(sz, tg);
|
|
|
|
for (i = 0; i < sz; i++)
|
|
|
|
Field(res, i) = Val_long(0);
|
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
1998-06-24 12:22:26 -07:00
|
|
|
value obj_dup(value arg) /* ML */
|
|
|
|
{
|
|
|
|
value res;
|
|
|
|
mlsize_t sz, i;
|
|
|
|
tag_t tg;
|
|
|
|
|
|
|
|
sz = Wosize_val(arg);
|
|
|
|
if (sz == 0) return arg;
|
|
|
|
|
|
|
|
Begin_root(arg);
|
|
|
|
tg = Tag_val(arg);
|
|
|
|
res = alloc(sz, tg);
|
|
|
|
for (i = 0; i < sz; i++)
|
|
|
|
Field(res, i) = Field(arg, i);
|
|
|
|
End_roots();
|
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|