@harmoniclabs/plu-ts-onchain
Version:
An embedded DSL for Cardano smart contracts creation coupled with a library for Cardano transactions, all in Typescript
88 lines (87 loc) • 5.67 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.peqBool = exports.por = exports.pstrictOr = exports.pand = exports.pstrictAnd = exports.pnot = exports.pif = exports.pstrictIf = void 0;
var obj_utils_1 = require("@harmoniclabs/obj-utils");
var IRNative_1 = require("../../../../IR/IRNodes/IRNative/index.js");
var Term_1 = require("../../../Term/index.js");
var type_system_1 = require("../../../type_system/index.js");
var papp_1 = require("../../papp.js");
var pappArg_1 = require("../../pappArg.js");
var pdelay_1 = require("../../pdelay.js");
var pforce_1 = require("../../pforce/index.js");
var phoist_1 = require("../../phoist.js");
var plam_1 = require("../../plam.js");
var pBool_1 = require("../../std/bool/pBool.js");
var addApplications_1 = require("../addApplications.js");
function pstrictIf(returnType) {
var returnT = returnType;
return (0, addApplications_1.addApplications)(new Term_1.Term((0, type_system_1.fn)([type_system_1.bool, returnT, returnT], returnT), function (_dbn) { return IRNative_1.IRNative.strictIfThenElse; }));
}
exports.pstrictIf = pstrictIf;
function pif(returnType) {
if (returnType === void 0) { returnType = undefined; }
var returnT = returnType !== null && returnType !== void 0 ? returnType : (0, type_system_1.tyVar)("pif_returnType");
// new term identical to the strict one in order to define new (different) "$" properties
var _lambdaIf = new Term_1.Term(
// type is different from the one specified by the generic because
// ```papp``` throws if types don't match;
// but the perceived type form the user perspective is the one of the generic
(0, type_system_1.fn)([type_system_1.bool, (0, type_system_1.delayed)(returnT), (0, type_system_1.delayed)(returnT)], (0, type_system_1.delayed)(returnT)), function (_dbn) { return IRNative_1.IRNative.strictIfThenElse; });
return (0, obj_utils_1.defineReadOnlyProperty)(_lambdaIf, "$", function (condition) { return (function () {
/*
[ (builtin ifThenElse) condition ]
*/
var _lambdaIfThen = (0, papp_1.papp)(_lambdaIf, condition);
var _lambdaIfThenApp = (0, obj_utils_1.defineReadOnlyProperty)(_lambdaIfThen, "$",
//@ts-ignore
function (caseTrue) { return (function () {
/*
[
[ (builtin ifThenElse) condition ]
(delay case true)
]
*/
var _lambdaIfThenElse = (0, papp_1.papp)(_lambdaIfThen, (0, pdelay_1.pdelay)((0, pappArg_1.pappArgToTerm)(caseTrue, returnT)));
var _lambdaIfThenElseApp = (0, obj_utils_1.defineReadOnlyProperty)(_lambdaIfThenElse, "$", function (caseFalse) {
/*
(force [
[
[ (builtin ifThenElse) condition ]
(delay caseTrue)
]
(delay caseFalse)
])
*/
return ((0, pforce_1.pforce)((0, papp_1.papp)(_lambdaIfThenElse, (0, pdelay_1.pdelay)((0, pappArg_1.pappArgToTerm)(caseFalse, returnT)))));
});
// @ts-ingore Type instantiation is excessively deep and possibly infinite.
return (0, obj_utils_1.defineReadOnlyProperty)(_lambdaIfThenElseApp, "else", _lambdaIfThenElseApp.$);
})(); });
return (0, obj_utils_1.defineReadOnlyProperty)(_lambdaIfThenApp, "then", _lambdaIfThenApp.$);
})(); });
}
exports.pif = pif;
exports.pnot = (0, phoist_1.phoist)((0, plam_1.plam)(type_system_1.bool, type_system_1.bool)(function (b) {
return pstrictIf(type_system_1.bool).$(b)
.$((0, pBool_1.pBool)(false))
.$((0, pBool_1.pBool)(true));
}));
exports.pstrictAnd = (0, phoist_1.phoist)((0, plam_1.plam)(type_system_1.bool, (0, type_system_1.lam)(type_system_1.bool, type_system_1.bool))(function (a) { return (0, plam_1.plam)(type_system_1.bool, type_system_1.bool)(function (b) { return pstrictIf(type_system_1.bool).$(a)
.$(b)
.$((0, pBool_1.pBool)(false)); }); }));
exports.pand = (0, phoist_1.phoist)((0, plam_1.plam)(type_system_1.bool, (0, type_system_1.lam)((0, type_system_1.delayed)(type_system_1.bool), type_system_1.bool))(function (a) { return (0, plam_1.plam)((0, type_system_1.delayed)(type_system_1.bool), type_system_1.bool)(function (b) {
return (0, pforce_1.pforce)(pstrictIf((0, type_system_1.delayed)(type_system_1.bool)).$(a)
.$(b)
.$((0, pdelay_1.pdelay)((0, pBool_1.pBool)(false))));
}, "pand"); }, "pand"));
exports.pstrictOr = (0, phoist_1.phoist)((0, plam_1.plam)(type_system_1.bool, (0, type_system_1.lam)(type_system_1.bool, type_system_1.bool))(function (a) { return (0, plam_1.plam)(type_system_1.bool, type_system_1.bool)(function (b) { return pstrictIf(type_system_1.bool).$(a)
.$((0, pBool_1.pBool)(true))
.$(b); }); }));
exports.por = (0, phoist_1.phoist)((0, plam_1.plam)(type_system_1.bool, (0, type_system_1.lam)((0, type_system_1.delayed)(type_system_1.bool), type_system_1.bool))(function (a) { return (0, plam_1.plam)((0, type_system_1.delayed)(type_system_1.bool), type_system_1.bool)(function (b) {
return (0, pforce_1.pforce)(pstrictIf((0, type_system_1.delayed)(type_system_1.bool)).$(a)
.$((0, pdelay_1.pdelay)((0, pBool_1.pBool)(true)))
.$(b));
}); }));
exports.peqBool = (0, phoist_1.phoist)((0, plam_1.plam)(type_system_1.bool, (0, type_system_1.lam)(type_system_1.bool, type_system_1.bool))(function (a) { return (0, plam_1.plam)(type_system_1.bool, type_system_1.bool)(function (b) { return pstrictIf(type_system_1.bool).$(a)
.$(b)
.$(exports.pnot.$(b)); }); }));