Commits

Anonymous committed b6edb6f

Introduction de primitives C pour {Array,String}.{get,set}

git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@30f963ae5c-01c2-4b8c-9fe0-0dff7051ff02

Comments (0)

Files changed (2)

 #include "misc.h"
 #include "mlvalues.h"
 
+value array_get(array, index)   /* ML */
+     value array, index;
+{
+  long idx = Long_val(index);
+  if (idx < 0 || idx >= Wosize_val(array)) invalid_argument("Array.get");
+  return Field(array, idx);
+}
+
+value array_set(array, index, newval)   /* ML */
+     value array, index, newval;
+{
+  long idx = Long_val(index);
+  if (idx < 0 || idx >= Wosize_val(array)) invalid_argument("Array.set");
+  Modify(&Field(array, idx), newval);
+  return Val_unit;
+}
+
 value make_vect(len, init)      /* ML */
      value len, init;
 {
   return alloc_string(size);
 }
 
+value string_get(str, index)    /* ML */
+     value str, index;
+{
+  long idx = Long_val(index);
+  if (idx < 0 || idx >= string_length(str)) invalid_argument("String.get");
+  return Val_int(Byte_u(str, idx));
+}
+
+value string_set(str, index, newval)    /* ML */
+     value str, index, newval;
+{
+  long idx = Long_val(index);
+  if (idx < 0 || idx >= string_length(str)) invalid_argument("String.set");
+  Byte_u(str, idx) = Int_val(newval);
+  return Val_unit;
+}
+
 value blit_string(argv, argc)   /* ML */
      value * argv;
      int argc;