@harmoniclabs/plu-ts-onchain
Version:
An embedded DSL for Cardano smart contracts creation coupled with a library for Cardano transactions, all in Typescript
92 lines (91 loc) • 3.96 kB
JavaScript
;
var __read = (this && this.__read) || function (o, n) {
var m = typeof Symbol === "function" && o[Symbol.iterator];
if (!m) return o;
var i = m.call(o), r, ar = [], e;
try {
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
}
catch (error) { e = { error: error }; }
finally {
try {
if (r && !r.done && (m = i["return"])) m.call(i);
}
finally { if (e) throw e.error; }
}
return ar;
};
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
if (ar || !(i in from)) {
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
ar[i] = from[i];
}
}
return to.concat(ar || Array.prototype.slice.call(from));
};
Object.defineProperty(exports, "__esModule", { value: true });
exports._addDepths = void 0;
var IRNodes_1 = require("../../IRNodes/index.js");
var IRApp_1 = require("../../IRNodes/IRApp.js");
var IRDelayed_1 = require("../../IRNodes/IRDelayed.js");
var IRForced_1 = require("../../IRNodes/IRForced.js");
var IRFunc_1 = require("../../IRNodes/IRFunc.js");
var IRHoisted_1 = require("../../IRNodes/IRHoisted.js");
var IRLetted_1 = require("../../IRNodes/IRLetted.js");
var IRRecursive_1 = require("../../IRNodes/IRRecursive.js");
var mapArrayLike_1 = require("../../IRNodes/utils/mapArrayLike.js");
var depth_1 = require("./depth.js");
function _addDepths(_term, initialDepth) {
if (initialDepth === void 0) { initialDepth = 0; }
var stack = [(0, depth_1.defineDepth)(_term, initialDepth)];
var _loop_1 = function () {
var t = stack.pop();
if (t instanceof IRApp_1.IRApp) {
stack.push((0, depth_1.defineDepth)(t.fn, t.depth + 1), (0, depth_1.defineDepth)(t.arg, t.depth + 1));
return "continue";
}
if (t instanceof IRNodes_1.IRCase) {
var nextDepth_1 = t.depth + 1;
stack.push.apply(stack, __spreadArray([(0, depth_1.defineDepth)(t.constrTerm, nextDepth_1)], __read((0, mapArrayLike_1.mapArrayLike)(t.continuations, function (continuation) { return (0, depth_1.defineDepth)(continuation, nextDepth_1); })), false));
return "continue";
}
if (t instanceof IRNodes_1.IRConstr) {
stack.push.apply(stack, __spreadArray([], __read((0, mapArrayLike_1.mapArrayLike)(t.fields, function (field) { return (0, depth_1.defineDepth)(field, t.depth + 1); })), false));
return "continue";
}
if (t instanceof IRDelayed_1.IRDelayed) {
stack.push((0, depth_1.defineDepth)(t.delayed, t.depth + 1));
return "continue";
}
if (t instanceof IRForced_1.IRForced) {
stack.push((0, depth_1.defineDepth)(t.forced, t.depth + 1));
return "continue";
}
if (t instanceof IRFunc_1.IRFunc) {
stack.push((0, depth_1.defineDepth)(t.body, t.depth + 1));
return "continue";
}
if (t instanceof IRRecursive_1.IRRecursive) {
stack.push((0, depth_1.defineDepth)(t.body, t.depth + 1));
return "continue";
}
if (t instanceof IRHoisted_1.IRHoisted) {
// 0 because hoisted are closed
// for hoisted we keep track of the depth inside the term
stack.push((0, depth_1.defineDepth)(t.hoisted, 0));
return "continue";
}
if (t instanceof IRLetted_1.IRLetted) {
// same stuff as the hoisted terms
// the only difference is that depth is then incremented
// once the letted term reaches its final position
stack.push((0, depth_1.defineDepth)(t.value, 0));
return "continue";
}
};
while (stack.length > 0) {
_loop_1();
}
}
exports._addDepths = _addDepths;