summaryrefslogtreecommitdiffstats
path: root/byterun/alloc.c
diff options
context:
space:
mode:
Diffstat (limited to 'byterun/alloc.c')
-rw-r--r--byterun/alloc.c28
1 files changed, 27 insertions, 1 deletions
diff --git a/byterun/alloc.c b/byterun/alloc.c
index 4ea4091b5..d16c39267 100644
--- a/byterun/alloc.c
+++ b/byterun/alloc.c
@@ -94,7 +94,8 @@ value alloc_array(value (*funct)(char *), char ** arr)
Begin_root(result);
for (n = 0; n < nbr; n++) {
/* The two statements below must be separate because of evaluation
- order. */
+ order (don't take the address &Field(result, n) before
+ calling funct, which may cause a GC and move result). */
v = funct(arr[n]);
modify(&Field(result, n), v);
}
@@ -118,3 +119,28 @@ int convert_flag_list(value list, int *flags)
}
return res;
}
+
+/* For compiling let rec over values */
+
+value alloc_dummy(value size) /* ML */
+{
+ mlsize_t wosize = Int_val(size);
+ value result;
+ mlsize_t i;
+
+ if (wosize == 0) return Atom(0);
+ result = alloc(wosize, 0);
+ for (i = 0; i < wosize; i++) Field(result, i) = Val_int(0);
+ return result;
+}
+
+value update_dummy(value dummy, value newval) /* ML */
+{
+ mlsize_t size, i;
+ size = Wosize_val(newval);
+ Assert (size == Wosize_val(dummy));
+ Tag_val(dummy) = Tag_val(newval);
+ for (i = 0; i < size; i++)
+ modify(&Field(dummy, i), Field(newval, i));
+ return Val_unit;
+}