time-to-botec/squiggle/node_modules/@rescript/std/lib/js/caml_obj.js
NunoSempere b6addc7f05 feat: add the node modules
Necessary in order to clearly see the squiggle hotwiring.
2022-12-03 12:44:49 +00:00

412 lines
8.6 KiB
JavaScript

'use strict';
var Caml = require("./caml.js");
var for_in = (function(o,foo){
for (var x in o) { foo(x) }});
var obj_dup = (function(x){
if(Array.isArray(x)){
var len = x.length
var v = new Array(len)
for(var i = 0 ; i < len ; ++i){
v[i] = x[i]
}
if(x.TAG !== undefined){
v.TAG = x.TAG // TODO this can be removed eventually
}
return v
}
return Object.assign({},x)
});
var update_dummy = (function(x,y){
var k
if(Array.isArray(y)){
for(k = 0; k < y.length ; ++k){
x[k] = y[k]
}
if(y.TAG !== undefined){
x.TAG = y.TAG
}
} else {
for (var k in y){
x[k] = y[k]
}
}
});
function compare(a, b) {
if (a === b) {
return 0;
}
var a_type = typeof a;
var b_type = typeof b;
switch (a_type) {
case "boolean" :
if (b_type === "boolean") {
return Caml.bool_compare(a, b);
}
break;
case "function" :
if (b_type === "function") {
throw {
RE_EXN_ID: "Invalid_argument",
_1: "compare: functional value",
Error: new Error()
};
}
break;
case "number" :
if (b_type === "number") {
return Caml.int_compare(a, b);
}
break;
case "string" :
if (b_type === "string") {
return Caml.string_compare(a, b);
} else {
return 1;
}
case "undefined" :
return -1;
default:
}
switch (b_type) {
case "string" :
return -1;
case "undefined" :
return 1;
default:
if (a_type === "boolean") {
return 1;
}
if (b_type === "boolean") {
return -1;
}
if (a_type === "function") {
return 1;
}
if (b_type === "function") {
return -1;
}
if (a_type === "number") {
if (b === null || b.BS_PRIVATE_NESTED_SOME_NONE !== undefined) {
return 1;
} else {
return -1;
}
}
if (b_type === "number") {
if (a === null || a.BS_PRIVATE_NESTED_SOME_NONE !== undefined) {
return -1;
} else {
return 1;
}
}
if (a === null) {
if (b.BS_PRIVATE_NESTED_SOME_NONE !== undefined) {
return 1;
} else {
return -1;
}
}
if (b === null) {
if (a.BS_PRIVATE_NESTED_SOME_NONE !== undefined) {
return -1;
} else {
return 1;
}
}
if (a.BS_PRIVATE_NESTED_SOME_NONE !== undefined) {
if (b.BS_PRIVATE_NESTED_SOME_NONE !== undefined) {
return aux_obj_compare(a, b);
} else {
return -1;
}
}
var tag_a = a.TAG | 0;
var tag_b = b.TAG | 0;
if (tag_a === 248) {
return Caml.int_compare(a[1], b[1]);
}
if (tag_a === 251) {
throw {
RE_EXN_ID: "Invalid_argument",
_1: "equal: abstract value",
Error: new Error()
};
}
if (tag_a !== tag_b) {
if (tag_a < tag_b) {
return -1;
} else {
return 1;
}
}
var len_a = a.length | 0;
var len_b = b.length | 0;
if (len_a === len_b) {
if (Array.isArray(a)) {
var _i = 0;
while(true) {
var i = _i;
if (i === len_a) {
return 0;
}
var res = compare(a[i], b[i]);
if (res !== 0) {
return res;
}
_i = i + 1 | 0;
continue ;
};
} else if ((a instanceof Date && b instanceof Date)) {
return (a - b);
} else {
return aux_obj_compare(a, b);
}
} else if (len_a < len_b) {
var _i$1 = 0;
while(true) {
var i$1 = _i$1;
if (i$1 === len_a) {
return -1;
}
var res$1 = compare(a[i$1], b[i$1]);
if (res$1 !== 0) {
return res$1;
}
_i$1 = i$1 + 1 | 0;
continue ;
};
} else {
var _i$2 = 0;
while(true) {
var i$2 = _i$2;
if (i$2 === len_b) {
return 1;
}
var res$2 = compare(a[i$2], b[i$2]);
if (res$2 !== 0) {
return res$2;
}
_i$2 = i$2 + 1 | 0;
continue ;
};
}
}
}
function aux_obj_compare(a, b) {
var min_key_lhs = {
contents: undefined
};
var min_key_rhs = {
contents: undefined
};
var do_key = function (param, key) {
var min_key = param[2];
var b = param[1];
if (!(!Object.prototype.hasOwnProperty.call(b, key) || compare(param[0][key], b[key]) > 0)) {
return ;
}
var mk = min_key.contents;
if (mk !== undefined && key >= mk) {
return ;
} else {
min_key.contents = key;
return ;
}
};
var partial_arg = [
a,
b,
min_key_rhs
];
var do_key_a = function (param) {
return do_key(partial_arg, param);
};
var partial_arg$1 = [
b,
a,
min_key_lhs
];
var do_key_b = function (param) {
return do_key(partial_arg$1, param);
};
for_in(a, do_key_a);
for_in(b, do_key_b);
var match = min_key_lhs.contents;
var match$1 = min_key_rhs.contents;
if (match !== undefined) {
if (match$1 !== undefined) {
return Caml.string_compare(match, match$1);
} else {
return -1;
}
} else if (match$1 !== undefined) {
return 1;
} else {
return 0;
}
}
function equal(a, b) {
if (a === b) {
return true;
}
var a_type = typeof a;
if (a_type === "string" || a_type === "number" || a_type === "boolean" || a_type === "undefined" || a === null) {
return false;
}
var b_type = typeof b;
if (a_type === "function" || b_type === "function") {
throw {
RE_EXN_ID: "Invalid_argument",
_1: "equal: functional value",
Error: new Error()
};
}
if (b_type === "number" || b_type === "undefined" || b === null) {
return false;
}
var tag_a = a.TAG | 0;
var tag_b = b.TAG | 0;
if (tag_a === 248) {
return a[1] === b[1];
}
if (tag_a === 251) {
throw {
RE_EXN_ID: "Invalid_argument",
_1: "equal: abstract value",
Error: new Error()
};
}
if (tag_a !== tag_b) {
return false;
}
var len_a = a.length | 0;
var len_b = b.length | 0;
if (len_a === len_b) {
if (Array.isArray(a)) {
var _i = 0;
while(true) {
var i = _i;
if (i === len_a) {
return true;
}
if (!equal(a[i], b[i])) {
return false;
}
_i = i + 1 | 0;
continue ;
};
} else if ((a instanceof Date && b instanceof Date)) {
return !(a > b || a < b);
} else {
var result = {
contents: true
};
var do_key_a = function (key) {
if (!Object.prototype.hasOwnProperty.call(b, key)) {
result.contents = false;
return ;
}
};
var do_key_b = function (key) {
if (!Object.prototype.hasOwnProperty.call(a, key) || !equal(b[key], a[key])) {
result.contents = false;
return ;
}
};
for_in(a, do_key_a);
if (result.contents) {
for_in(b, do_key_b);
}
return result.contents;
}
} else {
return false;
}
}
function equal_null(x, y) {
if (y !== null) {
return equal(x, y);
} else {
return x === y;
}
}
function equal_undefined(x, y) {
if (y !== undefined) {
return equal(x, y);
} else {
return x === y;
}
}
function equal_nullable(x, y) {
if (y == null) {
return x === y;
} else {
return equal(x, y);
}
}
function notequal(a, b) {
return !equal(a, b);
}
function greaterequal(a, b) {
return compare(a, b) >= 0;
}
function greaterthan(a, b) {
return compare(a, b) > 0;
}
function lessequal(a, b) {
return compare(a, b) <= 0;
}
function lessthan(a, b) {
return compare(a, b) < 0;
}
function min(x, y) {
if (compare(x, y) <= 0) {
return x;
} else {
return y;
}
}
function max(x, y) {
if (compare(x, y) >= 0) {
return x;
} else {
return y;
}
}
exports.obj_dup = obj_dup;
exports.update_dummy = update_dummy;
exports.compare = compare;
exports.equal = equal;
exports.equal_null = equal_null;
exports.equal_undefined = equal_undefined;
exports.equal_nullable = equal_nullable;
exports.notequal = notequal;
exports.greaterequal = greaterequal;
exports.greaterthan = greaterthan;
exports.lessthan = lessthan;
exports.lessequal = lessequal;
exports.min = min;
exports.max = max;
/* No side effect */