UNPKG

@harmoniclabs/plu-ts-onchain

Version:

An embedded DSL for Cardano smart contracts creation coupled with a library for Cardano transactions, all in Typescript

90 lines (89 loc) 3.6 kB
"use strict"; 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.getDiffDbn = void 0; var IRCase_1 = require("../../IRNodes/IRCase.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 mapArrayLike_1 = require("../../IRNodes/utils/mapArrayLike.js"); var IRNodes_1 = require("../../IRNodes/index.js"); var IRRecursive_1 = require("../../IRNodes/IRRecursive.js"); function getDiffDbn(parentNode, childNode) { var stack = [{ term: parentNode, dbn: 0 }]; var _loop_1 = function () { var _a = stack.pop(), t = _a.term, dbn = _a.dbn; if (t === childNode) return { value: dbn }; if (t instanceof IRLetted_1.IRLetted) { stack.push({ term: t.value, dbn: dbn }); return "continue"; } if (t instanceof IRApp_1.IRApp) { stack.push({ term: t.fn, dbn: dbn }, { term: t.arg, dbn: dbn }); return "continue"; } if (t instanceof IRCase_1.IRCase) { stack.push.apply(stack, __spreadArray([{ term: t.constrTerm, dbn: dbn }], __read((0, mapArrayLike_1.mapArrayLike)(t.continuations, function (continuation) { return ({ term: continuation, dbn: dbn }); })), false)); return "continue"; } if (t instanceof IRNodes_1.IRConstr) { stack.push.apply(stack, __spreadArray([], __read((0, mapArrayLike_1.mapArrayLike)(t.fields, function (field) { return ({ term: field, dbn: dbn }); })), false)); return "continue"; } if (t instanceof IRDelayed_1.IRDelayed) { stack.push({ term: t.delayed, dbn: dbn }); return "continue"; } if (t instanceof IRForced_1.IRForced) { stack.push({ term: t.forced, dbn: dbn }); return "continue"; } if (t instanceof IRFunc_1.IRFunc) { stack.push({ term: t.body, dbn: dbn + t.arity }); return "continue"; } if (t instanceof IRRecursive_1.IRRecursive) { stack.push({ term: t.body, dbn: dbn + t.arity }); return "continue"; } if (t instanceof IRHoisted_1.IRHoisted) { stack.push({ term: t.hoisted, dbn: dbn }); return "continue"; } }; while (stack.length > 0) { var state_1 = _loop_1(); if (typeof state_1 === "object") return state_1.value; } return undefined; } exports.getDiffDbn = getDiffDbn;