-
Notifications
You must be signed in to change notification settings - Fork 465
/
Copy pathtest_array_primitive.js
48 lines (42 loc) · 1.28 KB
/
test_array_primitive.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
'use strict';
var Caml_array = require("../../lib/js/caml_array.js");
var Caml_builtin_exceptions = require("../../lib/js/caml_builtin_exceptions.js");
function caml_array_sub(x, offset, len) {
var result = new Array(len);
for(var j = 0 ,j_finish = len - 1 | 0; j <= j_finish; ++j){
Caml_array.caml_array_set(result, j, Caml_array.caml_array_get(x, offset + j | 0));
}
return result;
}
function caml_array_set(xs, index, newval) {
if (index < 0 || index >= xs.length) {
throw [
Caml_builtin_exceptions.invalid_argument,
"index out of bounds"
];
} else {
return Caml_array.caml_array_set(xs, index, newval);
}
}
function caml_array_get(xs, index) {
if (index < 0 || index >= xs.length) {
throw [
Caml_builtin_exceptions.invalid_argument,
"index out of bounds"
];
} else {
return Caml_array.caml_array_get(xs, index);
}
}
function caml_make_vect(len, init) {
var b = new Array(len);
for(var i = 0 ,i_finish = len - 1 | 0; i <= i_finish; ++i){
Caml_array.caml_array_set(b, i, init);
}
return b;
}
exports.caml_array_sub = caml_array_sub;
exports.caml_array_set = caml_array_set;
exports.caml_array_get = caml_array_get;
exports.caml_make_vect = caml_make_vect;
/* No side effect */