123 lines
1.9 KiB
JavaScript
123 lines
1.9 KiB
JavaScript
|
|
|
|
|
|
function sub(x, offset, len) {
|
|
var result = new Array(len);
|
|
var j = 0;
|
|
var i = offset;
|
|
while(j < len) {
|
|
result[j] = x[i];
|
|
j = j + 1 | 0;
|
|
i = i + 1 | 0;
|
|
};
|
|
return result;
|
|
}
|
|
|
|
function len(_acc, _l) {
|
|
while(true) {
|
|
var l = _l;
|
|
var acc = _acc;
|
|
if (!l) {
|
|
return acc;
|
|
}
|
|
_l = l.tl;
|
|
_acc = l.hd.length + acc | 0;
|
|
continue ;
|
|
};
|
|
}
|
|
|
|
function fill(arr, _i, _l) {
|
|
while(true) {
|
|
var l = _l;
|
|
var i = _i;
|
|
if (!l) {
|
|
return ;
|
|
}
|
|
var x = l.hd;
|
|
var l$1 = x.length;
|
|
var k = i;
|
|
var j = 0;
|
|
while(j < l$1) {
|
|
arr[k] = x[j];
|
|
k = k + 1 | 0;
|
|
j = j + 1 | 0;
|
|
};
|
|
_l = l.tl;
|
|
_i = k;
|
|
continue ;
|
|
};
|
|
}
|
|
|
|
function concat(l) {
|
|
var v = len(0, l);
|
|
var result = new Array(v);
|
|
fill(result, 0, l);
|
|
return result;
|
|
}
|
|
|
|
function set(xs, index, newval) {
|
|
if (index < 0 || index >= xs.length) {
|
|
throw {
|
|
RE_EXN_ID: "Invalid_argument",
|
|
_1: "index out of bounds",
|
|
Error: new Error()
|
|
};
|
|
}
|
|
xs[index] = newval;
|
|
}
|
|
|
|
function get(xs, index) {
|
|
if (index < 0 || index >= xs.length) {
|
|
throw {
|
|
RE_EXN_ID: "Invalid_argument",
|
|
_1: "index out of bounds",
|
|
Error: new Error()
|
|
};
|
|
}
|
|
return xs[index];
|
|
}
|
|
|
|
function make(len, init) {
|
|
var b = new Array(len);
|
|
for(var i = 0; i < len; ++i){
|
|
b[i] = init;
|
|
}
|
|
return b;
|
|
}
|
|
|
|
function make_float(len) {
|
|
var b = new Array(len);
|
|
for(var i = 0; i < len; ++i){
|
|
b[i] = 0;
|
|
}
|
|
return b;
|
|
}
|
|
|
|
function blit(a1, i1, a2, i2, len) {
|
|
if (i2 <= i1) {
|
|
for(var j = 0; j < len; ++j){
|
|
a2[j + i2 | 0] = a1[j + i1 | 0];
|
|
}
|
|
return ;
|
|
}
|
|
for(var j$1 = len - 1 | 0; j$1 >= 0; --j$1){
|
|
a2[j$1 + i2 | 0] = a1[j$1 + i1 | 0];
|
|
}
|
|
}
|
|
|
|
function dup(prim) {
|
|
return prim.slice(0);
|
|
}
|
|
|
|
export {
|
|
dup ,
|
|
sub ,
|
|
concat ,
|
|
make ,
|
|
make_float ,
|
|
blit ,
|
|
get ,
|
|
set ,
|
|
}
|
|
/* No side effect */
|