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-05-04 03:15:53 -07:00
|
|
|
/* Operations on arrays */
|
|
|
|
|
|
|
|
#include "alloc.h"
|
|
|
|
#include "fail.h"
|
|
|
|
#include "memory.h"
|
|
|
|
#include "misc.h"
|
|
|
|
#include "mlvalues.h"
|
|
|
|
|
1997-09-02 05:55:01 -07:00
|
|
|
value array_get(value array, value index) /* ML */
|
1995-06-15 01:09:30 -07:00
|
|
|
{
|
|
|
|
long idx = Long_val(index);
|
|
|
|
if (idx < 0 || idx >= Wosize_val(array)) invalid_argument("Array.get");
|
|
|
|
return Field(array, idx);
|
|
|
|
}
|
|
|
|
|
1997-09-02 05:55:01 -07:00
|
|
|
value array_set(value array, value index, value newval) /* ML */
|
1995-06-15 01:09:30 -07:00
|
|
|
{
|
|
|
|
long idx = Long_val(index);
|
|
|
|
if (idx < 0 || idx >= Wosize_val(array)) invalid_argument("Array.set");
|
|
|
|
Modify(&Field(array, idx), newval);
|
|
|
|
return Val_unit;
|
|
|
|
}
|
|
|
|
|
1997-09-02 05:55:01 -07:00
|
|
|
value make_vect(value len, value init) /* ML */
|
1995-05-04 03:15:53 -07:00
|
|
|
{
|
|
|
|
value res;
|
|
|
|
mlsize_t size, i;
|
|
|
|
|
|
|
|
size = Long_val(len);
|
1997-05-26 10:16:31 -07:00
|
|
|
if (size > Max_wosize) invalid_argument("Array.new");
|
|
|
|
|
|
|
|
Begin_root(init);
|
|
|
|
if (size == 0) {
|
|
|
|
res = Atom(0);
|
|
|
|
}
|
|
|
|
else if (size < Max_young_wosize) {
|
|
|
|
res = alloc(size, 0);
|
|
|
|
for (i = 0; i < size; i++) Field(res, i) = init;
|
|
|
|
}
|
|
|
|
else if (Is_block(init) && Is_young(init)) {
|
|
|
|
minor_collection();
|
|
|
|
res = alloc_shr(size, 0);
|
|
|
|
for (i = 0; i < size; i++) Field(res, i) = init;
|
|
|
|
res = check_urgent_gc (res);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
res = alloc_shr(size, 0);
|
|
|
|
for (i = 0; i < size; i++) initialize(&Field(res, i), init);
|
|
|
|
res = check_urgent_gc (res);
|
|
|
|
}
|
|
|
|
End_roots();
|
1995-05-04 03:15:53 -07:00
|
|
|
return res;
|
|
|
|
}
|