-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinterpreter.min.js
1 lines (1 loc) · 299 KB
/
interpreter.min.js
1
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.Interpreter=t():e.Interpreter=t()}(this,(function(){return function(e){var t={};function n(r){if(t[r])return t[r].exports;var i=t[r]={i:r,l:!1,exports:{}};return e[r].call(i.exports,i,i.exports,n),i.l=!0,i.exports}return n.m=e,n.c=t,n.d=function(e,t,r){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:r})},n.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.t=function(e,t){if(1&t&&(e=n(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var r=Object.create(null);if(n.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var i in e)n.d(r,i,function(t){return e[t]}.bind(null,i));return r},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="",n(n.s=8)}([function(e,t,n){"use strict";var r,i=this&&this.__extends||(r=function(e,t){return(r=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)t.hasOwnProperty(n)&&(e[n]=t[n])})(e,t)},function(e,t){function n(){this.constructor=e}r(e,t),e.prototype=null===t?Object.create(t):(n.prototype=t.prototype,new n)});Object.defineProperty(t,"__esModule",{value:!0});var o=function(e){function t(n,r){var i=e.call(this,n)||this;return i.message=n,i.name=r,Object.setPrototypeOf(i,t.prototype),i}return i(t,e),t.prototype.toString=function(){return this.name+": "+this.message},t}(Error);t.InterpreterError=o;var a=function(e){function t(n){var r=e.call(this,n,"You triggered Third Impact")||this;return Object.setPrototypeOf(r,t.prototype),r}return i(t,e),t}(o);t.InternalInterpreterError=a;var s=function(e){function t(n){var r=e.call(this,n,"Have you ever tried doing something you were not supposed to? Basically that")||this;return Object.setPrototypeOf(r,t.prototype),r}return i(t,e),t}(o);t.FeatureDisabledError=s;var u=function(e){function t(n){var r=e.call(this,n,"Input Incomplete")||this;return Object.setPrototypeOf(r,t.prototype),r}return i(t,e),t}(o);t.IncompleteError=u;var p=function(e){function t(n){var r=e.call(this,n,"Lexing failed")||this;return Object.setPrototypeOf(r,t.prototype),r}return i(t,e),t}(o);t.LexerError=p;var c=function(e){function t(n){var r=e.call(this,n,"Parsing failed")||this;return Object.setPrototypeOf(r,t.prototype),r}return i(t,e),t}(o);t.ParserError=c;var h=function(e){function t(n){var r=e.call(this,n,"Elaboration failed")||this;return Object.setPrototypeOf(r,t.prototype),r}return i(t,e),t.getUnguarded=function(e){var n="";e.length>1&&(n+="s"),n+=" ";for(var r=0;r<e.length;++r)r>0&&(n+=", "),n+='"'+e[r]+'"';return new t("Unguarded type variable"+n+".")},t}(o);t.ElaborationError=h;var f=function(e){function t(n){var r=e.call(this,n,"Evaluation failed")||this;return Object.setPrototypeOf(r,t.prototype),r}return i(t,e),t}(o);t.EvaluationError=f;var l=function(e){function t(n){var r=e.call(this,n,"Checking Pattern failed")||this;return Object.setPrototypeOf(r,t.prototype),r}return i(t,e),t}(o);t.PatternMatchError=l;var d=function(e){function t(n,r){var i=e.call(this,r,"Warning")||this;return i.type=n,Object.setPrototypeOf(i,t.prototype),i}return i(t,e),t}(o);t.Warning=d},function(e,t,n){"use strict";var r,i=this&&this.__extends||(r=function(e,t){return(r=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)t.hasOwnProperty(n)&&(e[n]=t[n])})(e,t)},function(e,t){function n(){this.constructor=e}r(e,t),e.prototype=null===t?Object.create(t):(n.prototype=t.prototype,new n)});Object.defineProperty(t,"__esModule",{value:!0});var o=n(0),a=new Map([["'a","α"],["'b","β"],["'c","γ"],["'d","δ"],["'e","ε"],["'f","ζ"],["'g","η"],["'h","θ"],["'i","ι"],["'k","κ"],["'l","λ"],["'m","μ"],["'n","ν"],["'j","ξ"],["'o","ο"],["'p","π"],["'r","ρ"],["'s","σ"],["'t","τ"],["'u","υ"],["'v","φ"],["'x","χ"],["'q","ψ"],["'w","ω"]]),s=function(){function e(){}return e.prototype.instantiate=function(e,t,n){throw void 0===n&&(n=new Set),new o.ElaborationError("I mustn't run away. I mustn't run away. I mustn't run away.")},e.prototype.merge=function(e,t,n){throw new o.ElaborationError("I don't know anything. But you know everything.")},e.prototype.makeEqType=function(e,t){throw new o.ElaborationError("I don't know everything. I just know what I know.")},e.prototype.getTypeVariables=function(e){throw void 0===e&&(e=!1),new o.ElaborationError("This is wrong.\nI said with a posed look.")},e.prototype.getOrderedTypeVariables=function(){throw new o.ElaborationError("You seem well today.\nDid something nice happen?")},e.prototype.replaceTypeVariables=function(e,t){throw void 0===t&&(t=new Set),new o.ElaborationError("あんたバカ?")},e.prototype.qualify=function(e,t){return this},e.prototype.propagate=function(e){return void 0===e&&(e=new Map),this},e.prototype.makeFree=function(){return this},e.prototype.simplify=function(){return this},e.prototype.isOpaque=function(){return!1},e.prototype.getOpaqueName=function(){return"undefined"},e.prototype.isResolved=function(){return!1},e.prototype.admitsEquality=function(e){return!1},e.prototype.flatten=function(e){return void 0===e&&(e=new Map),this},e.prototype.replace=function(e,t){return e.equals(this)?t:this},e.prototype.normalize=function(e,t){void 0===e&&(e=0),void 0===t&&(t={});for(var n=this.getOrderedTypeVariables(),r=this.getTypeVariables(!0),i=new Map,o=0,a=0,s=n;a<s.length;a++){var u=s[a];if(!i.has(u)){var p="",c=++o;if(r.has(u)&&(c=++e),c<=26)p=String.fromCharCode("a".charCodeAt(0)+c-1);else for(;c>0;){var h=--c%26;p=String.fromCharCode("a".charCodeAt(0)+h)+p,c=Math.floor(c/26)}var f="'";u.length>2&&"'"===u.charAt(1)&&(f+="'"),r.has(u)&&(f+="~"),f+=p,r.has(u)&&(f=f.toUpperCase()),i.set(u,f)}}var l=this.replaceTypeVariables(i);return!1!==t.strictMode&&(l=l.flatten(new Map)),[l,e]},e}();t.Type=s;var u=function(e){function t(){return e.call(this)||this}return i(t,e),t.prototype.isResolved=function(){return!0},t.prototype.typeName=function(){return"AnyType"},t.prototype.toString=function(e){return void 0===e&&(e={}),"any"},t.prototype.equals=function(e){return!0},t.prototype.instantiate=function(e,t,n){return void 0===n&&(n=new Set),this},t.prototype.merge=function(e,t,n){return[n,t]},t.prototype.makeEqType=function(e,t){return[this,t]},t.prototype.getTypeVariables=function(e){return void 0===e&&(e=!1),new Map},t.prototype.getOrderedTypeVariables=function(){return[]},t.prototype.replaceTypeVariables=function(e,t){return void 0===t&&(t=new Set),this},t}(s);t.AnyType=u;var p=function(e){function t(t,n,r){void 0===r&&(r=[]);var i=e.call(this)||this;return i.name=t,i.type=n,i.domain=r,i.isFree=!1,i}return i(t,e),t.prototype.isResolved=function(){return this.type.isResolved()},t.prototype.simplify=function(){var e=new t(this.name,this.type.simplify(),this.domain);return e.isFree=this.isFree,e},t.prototype.makeFree=function(){var e=new t(this.name,this.type.makeFree(),this.domain);return e.isFree=!0,e},t.prototype.flatten=function(e){if(this.domain.length>0)return e=e.set(this.name,this.domain[0]),this.type.flatten(e);var n=new t(this.name,this.type.flatten(e),this.domain);return n.isFree=this.isFree,n},t.prototype.qualify=function(e,n){var r=new t(this.name,this.type.qualify(e,n),this.domain);return r.isFree=this.isFree,r},t.prototype.propagate=function(e){void 0===e&&(e=new Map),this.domain.length>0&&(e=e.set(this.name,this.domain));var n=new t(this.name,this.type.propagate(e),this.domain);return n.isFree=this.isFree,n},t.prototype.isOpaque=function(){return this.type.isOpaque()},t.prototype.getOpaqueName=function(){return this.type.getOpaqueName()},t.prototype.instantiate=function(e,n){var r=new t(this.name,this.type.instantiate(e,n),this.domain);return r.isFree=this.isFree,r},t.prototype.typeName=function(){return"TypeVariableBind"},t.prototype.toString=function(e){void 0===e&&(e={});for(var n=new Set,r=new Set,i=this;i instanceof t;)i.isFree?n=n.add([i.name,i.domain]):r=r.add([i.name,i.domain]),i=i.type;var o="";return r.size>0&&(o+="∀",r.forEach((function(t){if(!0===e.showTypeVariablesAsUnicode&&a.has(t[0])?o+=" "+a.get(t[0]):!0===e.showTypeVariablesAsUnicode&&a.has(t[0].substr(1))?o+=" '"+a.get(t[0].substr(1)):o+=" "+t[0],t[1].length>0){o+=" ∈ {";for(var n=0;n<t[1].length;++n)n>0&&(o+=", "),o+=t[1][n];o+="}"}})),o+=" . "),o+=i.toString(e),n.size>0&&(o+=",",n.forEach((function(t){if(!0===e.showTypeVariablesAsUnicode&&a.has(t[0])?o+=" "+a.get(t[0]):!0===e.showTypeVariablesAsUnicode&&a.has(t[0].substr(1))?o+=" '"+a.get(t[0].substr(1)):o+=" "+t[0],t[1].length>0){o+=" ∈ {";for(var n=0;n<t[1].length;++n)n>0&&(o+=", "),o+=t[1][n];o+="}"}})),o+=" free"),o},t.prototype.getTypeVariables=function(e){var t=this;void 0===e&&(e=!1);var n=this.type.getTypeVariables(e),r=new Map;return n.forEach((function(n,i){i===t.name&&e!==t.isFree||(r=r.has(i)?r.set(i,c.mergeDomain(n,r.get(i))):r.set(i,n))})),e&&this.isFree&&!r.has(this.name)&&(r=r.set(this.name,this.domain)),r},t.prototype.getOrderedTypeVariables=function(){return[this.name].concat(this.type.getOrderedTypeVariables())},t.prototype.replaceTypeVariables=function(e,n){if(void 0===n&&(n=new Set),e.has(this.name)){var r=new t(e.get(this.name),this.type.replaceTypeVariables(e,n),this.domain);return n.has(this.name)?r.isFree=!0:r.isFree=this.isFree,r}return(r=new t(this.name,this.type.replaceTypeVariables(e,n),this.domain)).isFree=this.isFree,r},t.prototype.equals=function(e){return e instanceof t&&e.name===this.name&&e.type.equals(this.type)},t}(s);t.TypeVariableBind=p;var c=function(e){function t(t,n){void 0===n&&(n=[]);var r=e.call(this)||this;return r.name=t,r.domain=n,r.isFree=!1,r}return i(t,e),t.mergeDomain=function(e,t){if(0===e.length)return t;if(0===t.length)return e;for(var n=[],r=0,i=e;r<i.length;r++)for(var o=i[r],a=0,s=t;a<s.length;a++){var u=s[a];o.equals(u)&&n.push(o)}return n},t.getUnusedTypeVariableName=function(e,t,n,r,i){void 0===t&&(t="'*t0"),void 0===n&&(n=new Set),void 0===r&&(r=new Map),void 0===i&&(i=new Set);for(var a=+t.substring(3)+1;;++a)if(t="'"+t[1]+t[2]+a,!i.has(t)&&!n.has(t)&&!r.has(t)&&void 0===e.getStaticValue(t))return t;throw new o.InternalInterpreterError("")},t.prototype.isResolved=function(){return!0},t.prototype.makeFree=function(){var e=new t(this.name,this.domain);return e.isFree=!0,e},t.prototype.flatten=function(e){return this.domain.length>0?(e=e.set(this.name,this.domain[0]),this.domain[0]):e.has(this.name)?e.get(this.name):this},t.prototype.propagate=function(e){void 0===e&&(e=new Map);var n=[];e.has(this.name)&&(n=e.get(this.name));var r=new t(this.name,n);return r.isFree=this.isFree,r},t.prototype.typeName=function(){return"TypeVariable"},t.prototype.toString=function(e){return void 0===e&&(e={}),!0===e.showTypeVariablesAsUnicode&&a.has(this.name)?a.get(this.name):!0===e.showTypeVariablesAsUnicode&&a.has(this.name.substr(1))?"'"+a.get(this.name.substr(1)):this.name},t.prototype.instantiate=function(e,t,n){if(void 0===n&&(n=new Set),!t.has(this.name))return this;if(n.has(this.name))throw new o.ElaborationError('Type clash. An expression of type "'+this.normalize()[0]+'" cannot have type "'+t.get(this.name)[0].normalize()[0]+'" because of circularity.');var r=new Set;n.forEach((function(e){r.add(e)})),r.add(this.name);var i=t.get(this.name)[0];return i instanceof h&&!i.complete&&void 0===i.sourceTyVar&&(i.sourceTyVar=this.name),i.instantiate(e,t,r)},t.prototype.merge=function(e,n,r){if(r instanceof u)return[this,n];var i=this.instantiate(e,n);if(i instanceof t){var a=r.instantiate(e,n);if(a instanceof t){if(i.name===a.name){var s=t.mergeDomain(i.domain,a.domain);if(0===s.length&&i.domain.length+a.domain.length>0)throw['Cannot merge domains of "'+i.normalize(0,{strictMode:!1})[0]+'" and "'+r.normalize(0,{strictMode:!1})[0]+'" ({'+i.domain+"} and {"+a.domain+"})"];var p=new t(i.name,s);return p.isFree=i.isFree&&a.isFree,[p,n]}var c=new Map,h=i;if(i.name<a.name?(i.domain=t.mergeDomain(i.domain,a.domain),c.set(a.name,i.name)):(a.domain=t.mergeDomain(i.domain,a.domain),c.set(i.name,a.name),h=a),0===h.domain.length&&i.domain.length+a.domain.length>0)throw['Cannot merge domains of "'+this.normalize(0,{strictMode:!1})[0]+'" and "'+r.normalize(0,{strictMode:!1})[0]+'". ({'+i.domain+"} and {"+a.domain+"})"];var f=new Map;n.forEach((function(e,t){f=f.set(t,[e[0].replaceTypeVariables(c),e[1]])})),h.isFree=i.isFree&&a.isFree,i.name<a.name?f.set(a.name,[i,h.isFree]):f.set(i.name,[a,h.isFree]);var l=h.domain;return f.has("$"+i.name)&&(l=t.mergeDomain(l,f.get("$"+i.name)[0].domain)),f.has("$"+a.name)&&(l=t.mergeDomain(l,f.get("$"+a.name)[0].domain)),f.set("$"+i.name,[new t(i.name,l),h.isFree]),f.set("$"+a.name,[new t(a.name,l),h.isFree]),[h,f]}if(a.getTypeVariables().has(i.name))throw new o.ElaborationError('Type clash. An expression of type "'+i.normalize()[0]+'" cannot have type "'+a.normalize()[0]+'" because of circularity.');if(i.isFree&&(a=a.makeFree()),i.admitsEquality(e)&&!a.admitsEquality(e)){var d=a.makeEqType(e,n);if(!d[0].admitsEquality(e))throw['Type "'+a.normalize()[0]+'" does not admit equality.',i,a];a=d[0],n=d[1]}if(i.domain.length>0&&0===t.mergeDomain(i.domain,[a]).length)throw['Type "'+a.normalize(0,{strictMode:!1})[0]+'" is not part of the domain of "'+i.normalize(0,{strictMode:!1})[0]+'" ({'+i.domain+"})."];return[a,n.set(i.name,[a,i.isFree])]}return i.merge(e,n,r)},t.prototype.makeEqType=function(e,n){if(this.admitsEquality(e))return[this,n];if(n.has(this.name)){var r=n.get(this.name)[0].makeEqType(e,n);if(r[0]instanceof t&&r[0].name!=="'"+this.name){n=r[1];var i=new t("'"+this.name,this.domain);i.isFree=this.isFree,n=n.set(i.name,[r[0],i.isFree])}}var o=new t("'"+this.name,this.domain);return[o,n.set(this.name,[o,this.isFree])]},t.prototype.getTypeVariables=function(e){void 0===e&&(e=!1);var t=new Map;return e&&!this.isFree||(t=t.set(this.name,this.domain)),t},t.prototype.getOrderedTypeVariables=function(){return[this.name]},t.prototype.replaceTypeVariables=function(e,n){if(void 0===n&&(n=new Set),e.has(this.name)){var r=new t(e.get(this.name),this.domain);return n.has(this.name)?r.isFree=!0:r.isFree=this.isFree,r}return this},t.prototype.admitsEquality=function(e){return"'"===this.name[1]},t.prototype.equals=function(e){return e instanceof u||e instanceof t&&this.name===e.name},t}(s);t.TypeVariable=c;var h=function(e){function t(t,n,r){void 0===n&&(n=!0),void 0===r&&(r=void 0);var i=e.call(this)||this;return i.elements=t,i.complete=n,i.sourceTyVar=r,i.tuplefy(),i.complete&&(i.sourceTyVar=void 0),i}return i(t,e),t.prototype.isResolved=function(){if(!this.complete)return!1;var e=!0;return this.elements.forEach((function(t,n){e=e&&t.isResolved()})),e},t.prototype.makeFree=function(){var e=new Map;return this.elements.forEach((function(t,n){e.set(n,t.makeFree())})),new t(e,this.complete,this.sourceTyVar)},t.prototype.replace=function(e,n){if(e.equals(this))return n;var r=new Map;return this.elements.forEach((function(t,i){r.set(i,t.replace(e,n))})),new t(r,this.complete,this.sourceTyVar)},t.prototype.flatten=function(e){var n=new Map;return this.elements.forEach((function(t,r){n.set(r,t.flatten(e))})),new t(n,this.complete,this.sourceTyVar)},t.prototype.instantiate=function(e,n,r){void 0===r&&(r=new Set);var i=new Map;return this.elements.forEach((function(t,o){i.set(o,t.instantiate(e,n,r))})),new t(i,this.complete,this.sourceTyVar)},t.prototype.qualify=function(e,n){var r=new Map;return this.elements.forEach((function(t,i){r.set(i,t.qualify(e,n))})),new t(r,this.complete,this.sourceTyVar)},t.prototype.propagate=function(e){void 0===e&&(e=new Map);var n=new Map;return this.elements.forEach((function(t,r){n.set(r,t.propagate(e))})),new t(n,this.complete,this.sourceTyVar)},t.prototype.merge=function(e,n,r){var i=this;if(r instanceof c||r instanceof u)return r.merge(e,n,this);if((r=r.instantiate(e,n))instanceof t){if(!this.complete&&r.complete)return r.merge(e,n,this);var o=new Map,a=n;r.elements.forEach((function(t,n){if(i.complete&&!i.elements.has(n))throw["Records don't agree on members (\""+n+'" occurs only once.)',i.instantiate(e,a),r.instantiate(e,a)];if(i.elements.has(n)){var s=t.merge(e,a,i.elements.get(n));o=o.set(n,s[0]),a=s[1]}else o=o.set(n,t.instantiate(e,a))})),r.complete?this.elements.forEach((function(t,n){if(!r.elements.has(n))throw["Records don't agree on members (\""+n+'" occurs only once.)',i.instantiate(e,a),r.instantiate(e,a)]})):this.elements.forEach((function(t,n){o=o.set(n,t.instantiate(e,a))}));var s=this.complete?void 0:this.sourceTyVar;if(void 0===s&&!r.complete&&void 0!==(s=r.sourceTyVar)){var p=a.get(s);void 0!==p&&(a=a.set(s,[new t(o,this.complete||r.complete,s),p[1]]))}return[new t(o,this.complete||r.complete,s),a]}throw['Cannot merge "'+this.instantiate(e,n).normalize()[0]+'" and "'+r.instantiate(e,n).normalize()[0]+'".',this.typeName(),r.typeName()]},t.prototype.makeEqType=function(e,n){var r=new Map;return this.elements.forEach((function(t,i){var o=t.makeEqType(e,n);r.set(i,o[0]),n=o[1]})),[new t(r,this.complete,this.sourceTyVar),n]},t.prototype.getTypeVariables=function(e){void 0===e&&(e=!1);var t=new Map;return this.elements.forEach((function(n){n.getTypeVariables(e).forEach((function(e,n){t=t.has(n)?t.set(n,c.mergeDomain(e,t.get(n))):t.set(n,e)}))})),t},t.prototype.getOrderedTypeVariables=function(){var e=[];return this.elements.forEach((function(t){e=e.concat(t.getOrderedTypeVariables())})),e},t.prototype.replaceTypeVariables=function(e,n){void 0===n&&(n=new Set);var r=new Map;return this.elements.forEach((function(t,i){r=r.set(i,t.replaceTypeVariables(e,n))})),new t(r,this.complete,this.sourceTyVar)},t.prototype.getType=function(e){if(!this.elements.has(e))throw new o.ElaborationError("Tried accessing non-existing record part.");return this.elements.get(e)},t.prototype.hasType=function(e){return this.elements.has(e)},t.prototype.setType=function(e,t){if(this.complete)throw new o.ElaborationError("Don't try to change a complete record.");this.elements=this.elements.set(e,t)},t.prototype.admitsEquality=function(e){var t=!0;return this.elements.forEach((function(n,r){n.admitsEquality(e)||(t=!1)})),t},t.prototype.typeName=function(){return"RecordType"},t.prototype.isTuple=function(){for(var e=1!==this.elements.size,t=1;t<=this.elements.size;++t)this.elements.has(""+t)||(e=!1);return e&&this.complete},t.prototype.tuplefy=function(){if(this.isTuple()){for(var e=new Map,t=1;t<=this.elements.size;++t){var n=this.elements.get(""+t);e=e.set(""+t,n)}this.elements=e}},t.prototype.toString=function(e){if(void 0===e&&(e={}),this.isTuple()&&this.complete){if(0===this.elements.size)return"unit";for(var n="",r=1;r<=this.elements.size;++r){r>1&&(n+=" * ");var i=this.elements.get(""+r);i instanceof f||i instanceof t&&0!==i.elements.size?n+="("+i.toString(e)+")":n+=i.toString(e)}return n+""}var o="{",a=!0;return this.elements.forEach((function(t,n){a?a=!1:o+=", ",o+=n+": "+t.toString(e)})),this.complete||(a||(o+=", "),o+="..."),o+"}"},t.prototype.simplify=function(){var e=new Map;return this.elements.forEach((function(t,n){e.set(n,t.simplify())})),new t(e,this.complete,this.sourceTyVar)},t.prototype.equals=function(e){if(e instanceof u)return!0;if(!(e instanceof t)||this.complete!==e.complete)return!1;if(this.elements.size!==e.elements.size)return!1;var n=!0;return this.elements.forEach((function(t,r){t.equals(e.elements.get(r))||(n=!1)})),n},t}(s);t.RecordType=h;var f=function(e){function t(t,n){var r=e.call(this)||this;return r.parameterType=t,r.returnType=n,r}return i(t,e),t.prototype.isResolved=function(){return this.parameterType.isResolved()&&this.returnType.isResolved()},t.prototype.makeFree=function(){return new t(this.parameterType.makeFree(),this.returnType.makeFree())},t.prototype.flatten=function(e){return new t(this.parameterType.flatten(e),this.returnType.flatten(e))},t.prototype.replace=function(e,n){return this.equals(e)?n:new t(this.parameterType.replace(e,n),this.returnType.replace(e,n))},t.prototype.instantiate=function(e,n,r){return void 0===r&&(r=new Set),new t(this.parameterType.instantiate(e,n,r),this.returnType.instantiate(e,n,r))},t.prototype.qualify=function(e,n){return new t(this.parameterType.qualify(e,n),this.returnType.qualify(e,n))},t.prototype.propagate=function(e){return void 0===e&&(e=new Map),new t(this.parameterType.propagate(e),this.returnType.propagate(e))},t.prototype.merge=function(e,n,r){if(r instanceof c||r instanceof u)return r.merge(e,n,this);var i=r.instantiate(e,n);if(i instanceof t){var o=this.parameterType.merge(e,n,i.parameterType),a=this.returnType.merge(e,o[1],i.returnType);return[new t(o[0],a[0]),a[1]]}throw['Cannot merge "'+this.instantiate(e,n).normalize()[0]+'" and "'+r.instantiate(e,n).normalize()[0]+'".',this.typeName(),r.typeName()]},t.prototype.makeEqType=function(e,t){return[this,t]},t.prototype.getTypeVariables=function(e){void 0===e&&(e=!1);var t=new Map;return this.parameterType.getTypeVariables(e).forEach((function(e,n){t=t.has(n)?t.set(n,c.mergeDomain(e,t.get(n))):t.set(n,e)})),this.returnType.getTypeVariables(e).forEach((function(e,n){t=t.has(n)?t.set(n,c.mergeDomain(e,t.get(n))):t.set(n,e)})),t},t.prototype.getOrderedTypeVariables=function(){var e=[];return e=(e=e.concat(this.parameterType.getOrderedTypeVariables())).concat(this.returnType.getOrderedTypeVariables())},t.prototype.replaceTypeVariables=function(e,n){return void 0===n&&(n=new Set),new t(this.parameterType.replaceTypeVariables(e,n),this.returnType.replaceTypeVariables(e,n))},t.prototype.admitsEquality=function(e){return!1},t.prototype.typeName=function(){return"FunctionType"},t.prototype.toString=function(e){return void 0===e&&(e={}),this.parameterType instanceof t?"("+this.parameterType.toString(e)+") → "+this.returnType.toString(e):this.parameterType.toString(e)+" → "+this.returnType.toString(e)},t.prototype.simplify=function(){return new t(this.parameterType.simplify(),this.returnType.simplify())},t.prototype.equals=function(e){return e instanceof u||e instanceof t&&this.parameterType.equals(e.parameterType)&&this.returnType.equals(e.returnType)},t}(s);t.FunctionType=f;var l=function(e){function t(t,n,r,i,o){void 0===n&&(n=[]),void 0===r&&(r=void 0),void 0===i&&(i=!1),void 0===o&&(o=0);var a=e.call(this)||this;return a.name=t,a.typeArguments=n,a.qualifiedName=r,a.opaque=i,a.id=o,a}return i(t,e),t.prototype.isResolved=function(){for(var e=0;e<this.typeArguments.length;++e)if(!this.typeArguments[e].isResolved())return!1;return!0},t.prototype.isOpaque=function(){return this.opaque},t.prototype.getOpaqueName=function(){return this.isOpaque()?this.name:"undefined"},t.prototype.makeFree=function(){for(var e=[],n=0;n<this.typeArguments.length;++n)e.push(this.typeArguments[n].makeFree());return new t(this.name,e,this.qualifiedName,this.opaque,this.id)},t.prototype.replace=function(e,n){if(this.equals(e))return n;for(var r=[],i=0;i<this.typeArguments.length;++i)r.push(this.typeArguments[i].replace(e,n));return new t(this.name,r,this.qualifiedName,this.opaque,this.id)},t.prototype.flatten=function(e){for(var n=[],r=0;r<this.typeArguments.length;++r)n.push(this.typeArguments[r].flatten(e));return new t(this.name,n,this.qualifiedName,this.opaque,this.id)},t.prototype.qualify=function(e,n){for(var r=[],i=0;i<this.typeArguments.length;++i)r.push(this.typeArguments[i].qualify(e,n));var o=new t(this.name,r,this.qualifiedName,this.opaque,this.id);return void 0!==e.getStaticType(this.name)&&(o.qualifiedName=n),o},t.prototype.propagate=function(e){void 0===e&&(e=new Map);for(var n=[],r=0;r<this.typeArguments.length;++r)n.push(this.typeArguments[r].propagate(e));return new t(this.name,n,this.qualifiedName,this.opaque,this.id)},t.prototype.instantiate=function(e,n,r){var i=this;void 0===r&&(r=new Set);var a=e.getStaticType(this.name);if(void 0!==this.qualifiedName){var s=e.getAndResolveStaticStructure(this.qualifiedName);a=void 0!==s?s.getType(this.name):void 0}if(void 0!==a&&a.type instanceof f)try{var u=a.type.getTypeVariables(),p=1,c=new Map;u.forEach((function(e,t){c=c.set(t,"'*"+i+p),++p}));var h=a.type.replaceTypeVariables(c),l=this.merge(e,n,h.parameterType,!0),d=e.getNestedState(e.id);return d.setStaticType(this.name,h.returnType,[],-1,a.allowsEquality),h.returnType.instantiate(d,l[1])}catch(e){if(!(e instanceof Array))throw e;throw new o.ElaborationError('Instantiating "'+this.normalize()[0]+'" failed: '+e[0])}else{if(void 0===a){if(this.id>0)throw new o.ElaborationError('Unbound type "'+this.name+"/"+this.id+'".');throw new o.ElaborationError('Unbound type "'+this.name+'".')}if(void 0!==a&&a.type.isOpaque())this.opaque=!0;else{if(!(void 0===a||a.type instanceof t&&this.typeArguments.length===a.type.typeArguments.length))throw new o.ElaborationError("Arity mismatch: "+this.normalize()[0]+" vs "+a.type.normalize()[0]+".");if(void 0!==a&&(!(a.type instanceof t)||this.id>a.type.id)){if(this.id>0)throw new o.ElaborationError('Unbound type "'+this.name+"/"+this.id+'".');throw new o.ElaborationError('Unbound type "'+this.name+'".')}}}for(var y=[],v=0;v<this.typeArguments.length;++v)y.push(this.typeArguments[v].instantiate(e,n,r));return new t(this.name,y,this.qualifiedName,this.opaque,this.id)},t.prototype.merge=function(e,n,r,i){if(void 0===i&&(i=!1),r instanceof c||r instanceof u)return r.merge(e,n,this);var o=this,a=r;if(!i){if(!((o=this.instantiate(e,n))instanceof t))return o.merge(e,n,r);a=r.instantiate(e,n)}var s=o;if(a instanceof t&&s.name===a.name&&s.id===a.id){for(var p=[],h=n,f=0;f<o.typeArguments.length;++f){var l=o.typeArguments[f].merge(e,h,a.typeArguments[f]);p.push(l[0]),h=l[1]}return[new t(s.name,p,s.qualifiedName,s.opaque,s.id),h]}throw['Cannot merge "'+this.instantiate(e,n).normalize()[0]+'" and "'+r.instantiate(e,n).normalize()[0]+'".',this.typeName(),r.typeName()]},t.prototype.makeEqType=function(e,n){var r=e.getStaticType(this.name);if(void 0!==this.qualifiedName){var i=e.getAndResolveStaticStructure(this.qualifiedName);r=void 0!==i?i.getType(this.name):void 0}if(void 0!==r&&!r.allowsEquality)return[this,n];for(var o=[],a=0;a<this.typeArguments.length;++a){var s=this.typeArguments[a].makeEqType(e,n);o.push(s[0]),n=s[1]}return[new t(this.name,o,this.qualifiedName,this.opaque,this.id),n]},t.prototype.getTypeVariables=function(e){void 0===e&&(e=!1);var t=new Map;if(this.typeArguments.length>0)for(var n=0;n<this.typeArguments.length;++n)this.typeArguments[n].getTypeVariables(e).forEach((function(e,n){t=t.has(n)?t.set(n,c.mergeDomain(e,t.get(n))):t.set(n,e)}));return t},t.prototype.getOrderedTypeVariables=function(){for(var e=[],t=0;t<this.typeArguments.length;++t)e=e.concat(this.typeArguments[t].getOrderedTypeVariables());return e},t.prototype.replaceTypeVariables=function(e,n){for(var r=[],i=0;i<this.typeArguments.length;++i)r.push(this.typeArguments[i].replaceTypeVariables(e,n));return new t(this.name,r,this.qualifiedName,this.opaque,this.id)},t.prototype.admitsEquality=function(e){var n=e.getStaticType(this.name);if(void 0!==this.qualifiedName){var r=e.getAndResolveStaticStructure(this.qualifiedName);n=void 0!==r?r.getType(this.name):void 0}if(void 0===n)return!0;var i=e.getNestedState(e.id);i.setStaticType(this.name,this,[],this.typeArguments.length,!0);for(var o=0;o<this.typeArguments.length;++o)if(!this.typeArguments[o].admitsEquality(i))return!1;var a=function(r){var o=e.getStaticValue(n.constructors[r]);if(void 0===o)return"continue";for(var a=o[0];a instanceof p;)a=a.type;if(a instanceof t)return"continue";var s=a.parameterType,u=s.getTypeVariables(),c=new Map;return u.forEach((function(e,t){t.startsWith("''")||(c=c.set(t,"'"+t))})),(s=s.replaceTypeVariables(c)).admitsEquality(i)?void 0:{value:!1}};for(o=0;o<n.constructors.length;++o){var s=a(o);if("object"==typeof s)return s.value}return n.allowsEquality},t.prototype.typeName=function(){return"CustomType"},t.prototype.toString=function(e){void 0===e&&(e={});var t="";(this.typeArguments.length>1||1===this.typeArguments.length&&(this.typeArguments[0]instanceof f||this.typeArguments[0]instanceof h&&"unit"!==this.typeArguments[0].toString(e)))&&(t+="(");for(var n=0;n<this.typeArguments.length;++n)n>0&&(t+=", "),t+=this.typeArguments[n].toString(e);if((this.typeArguments.length>1||1===this.typeArguments.length&&(this.typeArguments[0]instanceof f||this.typeArguments[0]instanceof h&&"unit"!==this.typeArguments[0].toString(e)))&&(t+=")"),this.typeArguments.length>0&&(t+=" "),void 0!==this.qualifiedName)for(n=0;n<this.qualifiedName.qualifiers.length;++n)t+=this.qualifiedName.qualifiers[n].getText()+".";return t+=this.name,this.id>0&&(t+="/"+this.id),t},t.prototype.simplify=function(){for(var e=[],n=0;n<this.typeArguments.length;++n)e.push(this.typeArguments[n].simplify());return new t(this.name,e,this.qualifiedName,this.opaque,this.id)},t.prototype.equals=function(e){if(e instanceof u)return!0;if(!(e instanceof t)||this.name!==e.name||this.id!==e.id)return!1;for(var n=0;n<this.typeArguments.length;++n)if(!this.typeArguments[n].equals(e.typeArguments[n]))return!1;return!0},t}(s);t.CustomType=l;var d=function(e){function t(t){var n=e.call(this)||this;return n.elements=t,n}return i(t,e),t.prototype.typeName=function(){return"TupleType"},t.prototype.toString=function(e){void 0===e&&(e={});for(var t="(",n=0;n<this.elements.length;++n)n>0&&(t+=" * "),t+=this.elements[n].toString(e);return t+")"},t.prototype.simplify=function(){for(var e=new Map,t=0;t<this.elements.length;++t)e.set(""+(t+1),this.elements[t].simplify());return new h(e,!0)},t.prototype.equals=function(e){return this.simplify().equals(e)},t}(s);t.TupleType=d},function(e,t,n){"use strict";var r,i=this&&this.__extends||(r=function(e,t){return(r=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)t.hasOwnProperty(n)&&(e[n]=t[n])})(e,t)},function(e,t){function n(){this.constructor=e}r(e,t),e.prototype=null===t?Object.create(t):(n.prototype=t.prototype,new n)});Object.defineProperty(t,"__esModule",{value:!0});var o=n(3),a=n(0),s=n(5);t.MAXINT=1073741823,t.MININT=-1073741824;var u=function(e){this.charactersLeft=e};t.PrintCounter=u;var p=function(){function e(){}return e.prototype.toString=function(e,t){return void 0===t&&(t=120),this.pcToString(e,new u(t))},e.prototype.equals=function(e){throw new a.InternalInterpreterError("Tried comparing incomparable things.")},e}();t.Value=p;var c=function(e){function t(t){var n=e.call(this)||this;return n.address=t,n}return i(t,e),t.prototype.equals=function(e){return this.address===e.address},t.prototype.typeName=function(){return"ReferenceValue"},t.prototype.pcToString=function(e,t){if(void 0===e){var n="$"+this.address;return t.charactersLeft-=n.length,n}if(void 0!==e.getCell(this.address))return t.charactersLeft-=4,"ref "+e.getCell(this.address).pcToString(e,t);throw new a.EvaluationError('Ouch, you may not de-reference "$'+this.address+'".')},t}(p);t.ReferenceValue=c;var h=function(e){function t(t){void 0===t&&(t=[]);var n=e.call(this)||this;return n.entries=t,n}return i(t,e),t.prototype.equals=function(e){if(this.entries.length!==e.entries.length)return!1;for(var t=0;t<this.entries.length;++t)if(!this.entries[t].equals(e.entries[t]))return!1;return!0},t.prototype.typeName=function(){return"VectorValue"},t.prototype.pcToString=function(e,t){var n="#[";t.charactersLeft-=3;for(var r=0;r<this.entries.length;++r){if(r>0&&(n+=", ",t.charactersLeft-=2),!(t.charactersLeft>0)){n+="…";break}var i=0;r<this.entries.length&&(i=Math.floor(t.charactersLeft/2)),t.charactersLeft-=i,n+=this.entries[r].pcToString(e,t),t.charactersLeft+=i}return n+"]"},t}(p);t.VectorValue=h;var f=function(e){function t(t,n){var r=e.call(this)||this;return r.address=t,r.length=n,r}return i(t,e),t.prototype.equals=function(e){return this.address===e.address},t.prototype.typeName=function(){return"ArrayValue"},t.prototype.pcToString=function(e,t){if(void 0===e){var n="[|$"+this.address+"...$"+(this.address+this.length-1)+"|]";return t.charactersLeft-=n.length,n}var r="[|";t.charactersLeft-=4;for(var i=0;i<this.length;++i){if(i>0&&(r+=", ",t.charactersLeft-=2),!(t.charactersLeft>0)){r+="…";break}if(void 0===e.getCell(this.address+i))throw new a.EvaluationError('Ouch, you may not de-reference "$'+(this.address+i)+'".');var o=0;i<this.length&&(o=Math.floor(t.charactersLeft/2)),t.charactersLeft-=o,r+=e.getCell(this.address+i).pcToString(e,t),t.charactersLeft+=o}return r+"|]"},t}(p);t.ArrayValue=f;var l=function(e){function t(t){var n=e.call(this)||this;return n.value=t,n}return i(t,e),t.prototype.equals=function(e){return this.value===e.value},t.prototype.typeName=function(){return"BoolValue"},t.prototype.pcToString=function(e,t){return this.value?(t.charactersLeft-=4,"true"):(t.charactersLeft-=5,"false")},t}(p);t.BoolValue=l;var d=function(e){function t(t){var n=e.call(this)||this;return n.value=t,n}return i(t,e),t.prototype.typeName=function(){return"CharValue"},t.prototype.pcToString=function(e,t){return t.charactersLeft-=1,"#"+new y(this.value).pcToString(e,t)},t.prototype.compareTo=function(e){return this.value<e.value?-1:this.value>e.value?1:0},t.prototype.equals=function(e){return this.value===e.value},t}(p);t.CharValue=d;var y=function(e){function t(t){var n=e.call(this)||this;return n.value=t,n}return i(t,e),t.implode=function(e){for(var n="";"nil"!==e.constructorName;){if("::"!==e.constructorName)throw new a.InternalInterpreterError("Is this a char list? I can't implode \""+e.constructorName+'".');var r=e.argument;if(!(r instanceof g))throw new a.InternalInterpreterError("Is this a char list? I can't implode \""+e.constructorName+'".');var i=r.getValue("1"),o=r.getValue("2");if(!(i instanceof d&&o instanceof E))throw new a.InternalInterpreterError("Is this a char list? I can't implode \""+e.constructorName+'".');n+=i.value,e=o}return new t(n)},t.prototype.typeName=function(){return"StringValue"},t.prototype.pcToString=function(e,t){var n="";t.charactersLeft-=2;for(var r=0,i=this.value;r<i.length;r++){var o=i[r];if(t.charactersLeft<0){n+="…";break}switch(t.charactersLeft-=1,o){case"\n":n+="\\n";break;case"\t":n+="\\t";break;case"\r":n+="\\r";break;case"":n+="\\a";break;case"\b":n+="\\b";break;case"\v":n+="\\v";break;case"\f":n+="\\f";break;case"":n+="\\127";break;case"ÿ":n+="\\255";break;default:if(o.charCodeAt(0)<32){var a="\\^"+String.fromCharCode(o.charCodeAt(0)+64);n+=a,t.charactersLeft-=a.length-1}else n+=o}}return'"'+n+'"'},t.prototype.equals=function(e){return this.value===e.value},t.prototype.compareTo=function(e){return this.value<e.value?-1:this.value>e.value?1:0},t.prototype.concat=function(e){return new t(this.value+e.value)},t.prototype.explode=function(){for(var e=new E("nil"),t=this.value.length-1;t>=0;--t)e=new E("::",new g(new Map([["1",new d(this.value[t])],["2",e]])));return e},t}(p);t.StringValue=y;var v=function(e){function n(t){var n=e.call(this)||this;return n.value=t,n}return i(n,e),n.prototype.typeName=function(){return"Word"},n.prototype.pcToString=function(e,t){var n=""+this.value;return t.charactersLeft-=n.length,n},n.prototype.compareTo=function(e){if(e instanceof n){var t=e.value;return this.value<t?-1:this.value>t?1:0}return 2},n.prototype.negate=function(){return new n(-this.value)},n.prototype.equals=function(e){return 0===this.compareTo(e)},n.prototype.add=function(e){return new n(this.value+e.value)},n.prototype.multiply=function(e){return new n(this.value*e.value)},n.prototype.divide=function(e){return new n(Math.floor(this.value/e.value))},n.prototype.modulo=function(e){return new n(this.value%e.value)},n.prototype.toReal=function(){return new w(this.value)},n.prototype.hasOverflow=function(){return this.value>t.MAXINT||this.value<t.MININT},n}(p);t.Word=v;var m=function(e){function n(t){var n=e.call(this)||this;return n.value=t,n}return i(n,e),n.prototype.typeName=function(){return"Integer"},n.prototype.pcToString=function(e,t){var n=""+this.value;return t.charactersLeft-=n.length,n.replace(/-/,"~")},n.prototype.compareTo=function(e){if(e instanceof n){var t=e.value;return this.value<t?-1:this.value>t?1:0}return!1},n.prototype.equals=function(e){return 0===this.compareTo(e)},n.prototype.negate=function(){return new n(-this.value)},n.prototype.add=function(e){return new n(this.value+e.value)},n.prototype.multiply=function(e){return new n(this.value*e.value)},n.prototype.divide=function(e){return new n(Math.floor(this.value/e.value))},n.prototype.modulo=function(e){return new n(this.value-Math.floor(this.value/e.value)*e.value)},n.prototype.toReal=function(){return new w(this.value)},n.prototype.hasOverflow=function(){return this.value>t.MAXINT||this.value<t.MININT},n}(p);t.Integer=m;var w=function(e){function t(t){var n=e.call(this)||this;return n.value=t,n}return i(t,e),t.prototype.typeName=function(){return"Real"},t.prototype.pcToString=function(e,t){var n=""+this.value;return-1===n.search(/\./)&&(n+=".0"),t.charactersLeft-=n.length,n.replace(/-/,"~")},t.prototype.compareTo=function(e){if(e instanceof t){var n=e.value;return this.value<n?-1:this.value>n?1:0}return!1},t.prototype.equals=function(e){return 0===this.compareTo(e)},t.prototype.negate=function(){return new t(-this.value)},t.prototype.add=function(e){return new t(this.value+e.value)},t.prototype.multiply=function(e){return new t(this.value*e.value)},t.prototype.divide=function(e){return new t(this.value/e.value)},t.prototype.toInteger=function(){return new m(Math.floor(this.value))},t.prototype.hasOverflow=function(){return!1},t}(p);t.Real=w;var g=function(e){function t(t){void 0===t&&(t=new Map);var n=e.call(this)||this;return n.entries=t,n}return i(t,e),t.prototype.typeName=function(){return"RecordValue"},t.prototype.pcToString=function(e,t){for(var n=this,r=1!==this.entries.size,i=1;i<=this.entries.size;++i)this.entries.has(""+i)||(r=!1);if(r){var o="(";t.charactersLeft-=2;for(i=1;i<=this.entries.size;++i){i>1&&(o+=", ",t.charactersLeft-=2);var s=this.entries.get(""+i);if(void 0===s)throw new a.InternalInterpreterError("How did we loose this value? It was there before. I promise…");if(!(t.charactersLeft>0)){o+="…";break}var u=0;i<this.entries.size&&(u=Math.floor(t.charactersLeft/2)),t.charactersLeft-=u,o+=s.pcToString(e,t),t.charactersLeft+=u}return o+")"}var p="{";t.charactersLeft-=2;var c=!0,h=!1,f=0;return this.entries.forEach((function(r,i){if(!h){if(c?c=!1:(p+=", ",t.charactersLeft-=2),t.charactersLeft>0){var o=0;f<n.entries.size&&(o=Math.floor(t.charactersLeft/2)),t.charactersLeft-=o,p+=i+" = "+r.pcToString(e,t),t.charactersLeft+=o}else p+="…",h=!0;++f}})),p+"}"},t.prototype.getValue=function(e){if(!this.entries.has(e))throw new a.EvaluationError("Tried accessing non-existing record part.");return this.entries.get(e)},t.prototype.hasValue=function(e){return this.entries.has(e)},t.prototype.equals=function(e){var n=this;if(!(e instanceof t))return!1;var r=!1;return this.entries.forEach((function(t,n){e.entries.has(n)||(r=!0),t.equals(e.entries.get(n))||(r=!0)})),!r&&(e.entries.forEach((function(t,i){n.entries.has(i)||(r=!0),t.equals(e.entries.get(i))||(r=!0)})),!r)},t}(p);t.RecordValue=g;var T=function(e){function t(t,n,r){var i=e.call(this)||this;return i.state=t,i.recursives=n,i.body=r,i}return i(t,e),t.prototype.typeName=function(){return"FunctionValue"},t.prototype.pcToString=function(e,t){return t.charactersLeft-=2,"fn"},t.prototype.compute=function(e,n,r){for(var i=this.state.getNestedState(this.state.id),a=0;a<this.recursives.length;++a)this.recursives[a][1]instanceof t?i.setDynamicValue(this.recursives[a][0],new t(this.state,this.recursives,this.recursives[a][1].body),o.IdentifierStatus.VALUE_VARIABLE):i.setDynamicValue(this.recursives[a][0],this.recursives[a][1],o.IdentifierStatus.VALUE_VARIABLE);e.push({next:this.body,params:{state:i,recResult:void 0,modifiable:r,value:n}})},t.prototype.equals=function(e){throw new a.InternalInterpreterError('You simply cannot compare "'+this.pcToString(void 0,new u(20))+'" and "'+e.pcToString(void 0,new u(20))+'".')},t}(p);t.FunctionValue=T;var E=function(e){function t(t,n,r){void 0===n&&(n=void 0),void 0===r&&(r=0);var i=e.call(this)||this;return i.constructorName=t,i.argument=n,i.id=r,i}return i(t,e),t.prototype.typeName=function(){return"ConstructedValue"},t.prototype.pcToString=function(e,n){if("::"===this.constructorName){var r="[";n.charactersLeft-=2;for(var i=this;"nil"!==i.constructorName;){if("::"!==i.constructorName)throw new a.InternalInterpreterError('Is this even a list? 1 "'+i.constructorName+'".');var o=i.argument;if(!(o instanceof g&&2===o.entries.size))throw new a.InternalInterpreterError('Is this even a list? 3 "'+i.constructorName+'".');var u=o.getValue("1"),c=o.getValue("2");if(!(u instanceof p&&c instanceof t))throw new a.InternalInterpreterError('Is this even a list? 2 "'+i.constructorName+'".');if(i!==this&&(r+=", ",n.charactersLeft-=2),!(n.charactersLeft>0)){r+="…";break}var h=0;"nil"!==c.constructorName&&(h=Math.floor(n.charactersLeft/2)),n.charactersLeft-=h,r+=u.pcToString(e,n),n.charactersLeft+=h,i=c}return r+"]"}if("nil"===this.constructorName)return n.charactersLeft-=2,"[]";if(void 0!==e){var f=e.getInfixStatus(new s.IdentifierToken(this.constructorName));if(void 0!==f&&f.infix&&this.argument instanceof g&&2===this.argument.entries.size){var l=this.argument.getValue("1"),d=this.argument.getValue("2");if(l instanceof p&&d instanceof p){n.charactersLeft-=4+this.constructorName.length;h=Math.floor(n.charactersLeft/2);n.charactersLeft-=h;r="(";if(n.charactersLeft>0?r+=l.pcToString(e,n):r+="…",n.charactersLeft+=h,r+=" "+this.constructorName,this.id>0)r+=y="/"+this.id,n.charactersLeft-=y.length;return n.charactersLeft>0?r+=" "+d.pcToString(e,n):r+=" …",r+")"}}}var y,v="";(v+=this.constructorName,n.charactersLeft-=this.constructorName.length+1,this.id>0)&&(v+=y="/"+this.id,n.charactersLeft-=y.length);return this.argument&&(n.charactersLeft>0?(v+=" ",this.argument instanceof t&&this.argument.argument?v+="(":this.argument instanceof x&&this.argument.argument&&(v+="("),v+=this.argument.pcToString(e,n),this.argument instanceof t&&this.argument.argument?v+=")":this.argument instanceof x&&this.argument.argument&&(v+=")")):v+=" …"),v},t.prototype.equals=function(e){return e instanceof I&&(e=e.construct()),e instanceof t&&(this.constructorName===e.constructorName&&this.id===e.id&&(void 0!==this.argument?void 0===e.argument||this.argument.equals(e.argument):void 0===e.argument))},t}(p);t.ConstructedValue=E;var x=function(e){function t(t,n,r,i){void 0===n&&(n=void 0),void 0===r&&(r=0),void 0===i&&(i=0);var o=e.call(this)||this;return o.constructorName=t,o.argument=n,o.id=r,o.evalId=i,o}return i(t,e),t.prototype.typeName=function(){return"ExceptionValue"},t.prototype.pcToString=function(e,t){var n=this.constructorName;if(t.charactersLeft-=this.constructorName.length+1,this.id>0){var r="/"+this.id;n+=r,t.charactersLeft-=r.length}return this.argument&&(t.charactersLeft>0?n+=" "+this.argument.pcToString(e,t):n+=" …"),n},t.prototype.equals=function(e){return e instanceof V&&(e=e.construct()),e instanceof t&&(this.constructorName===e.constructorName&&this.id===e.id&&this.evalId===e.evalId&&(void 0!==this.argument?void 0===e.argument||this.argument.equals(e.argument):void 0===e.argument))},t}(p);t.ExceptionValue=x;var S=function(e){function t(t,n){var r=e.call(this)||this;return r.name=t,r.apply=n,r}return i(t,e),t.prototype.typeName=function(){return"PredefinedFunction"},t.prototype.pcToString=function(e,t){return t.charactersLeft-=2,"fn"},t.prototype.equals=function(e){return e instanceof t&&this.name===e.name},t}(p);t.PredefinedFunction=S;var I=function(e){function t(t,n,r){void 0===n&&(n=0),void 0===r&&(r=0);var i=e.call(this)||this;return i.constructorName=t,i.numArgs=n,i.id=r,i}return i(t,e),t.prototype.typeName=function(){return"ValueConstructor"},t.prototype.equals=function(e){return e instanceof t&&(this.constructorName===e.constructorName&&this.id===e.id)},t.prototype.construct=function(e){return void 0===e&&(e=void 0),new E(this.constructorName,e,this.id)},t.prototype.pcToString=function(e,t){var n=this.constructorName;if(t.charactersLeft-=this.constructorName.length,this.id>0){var r="/"+this.id;n+=r,t.charactersLeft-=r.length}return n},t}(p);t.ValueConstructor=I;var V=function(e){function t(t,n,r,i){void 0===n&&(n=0),void 0===r&&(r=0),void 0===i&&(i=0);var o=e.call(this)||this;return o.exceptionName=t,o.numArgs=n,o.id=r,o.evalId=i,o}return i(t,e),t.prototype.typeName=function(){return"ExceptionConstructor"},t.prototype.equals=function(e){return e instanceof t&&(this.exceptionName===e.exceptionName&&this.id===e.id&&this.evalId===e.evalId)},t.prototype.construct=function(e){return void 0===e&&(e=void 0),new x(this.exceptionName,e,this.id,this.evalId)},t.prototype.pcToString=function(e,t){var n=this.exceptionName;if(t.charactersLeft-=this.exceptionName.length,this.id>0){var r="/"+this.id;n+=r,t.charactersLeft-=r.length}return n},t}(p);t.ExceptionConstructor=V},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var r=n(1),i=n(2),o=n(5),a=n(0);!function(e){e[e.VALUE_VARIABLE=0]="VALUE_VARIABLE",e[e.VALUE_CONSTRUCTOR=1]="VALUE_CONSTRUCTOR",e[e.EXCEPTION_CONSTRUCTOR=2]="EXCEPTION_CONSTRUCTOR"}(t.IdentifierStatus||(t.IdentifierStatus={}));var s=function(){function e(e,t,n,r){void 0===r&&(r=!0),this.type=e,this.constructors=t,this.arity=n,this.allowsEquality=r}return e.prototype.toString=function(){return"TypeInformation("+this.type+", ["+this.constructors+"], arity = "+this.arity+", allowsEquality = "+this.allowsEquality+")"},e}();t.TypeInformation=s;var u=function(e,t,n,r){this.paramName=e,this.param=t,this.body=n,this.state=r};t.DynamicFunctorInformation=u;var p=function(){function e(e,t,n){this.typeInterface=e,this.valueInterface=t,this.structureInterface=n}return e.prototype.extend=function(e){for(var t in e.typeInterface)e.typeInterface.hasOwnProperty(t)&&(this.typeInterface[t]=e.typeInterface[t]);for(var t in e.valueInterface)e.valueInterface.hasOwnProperty(t)&&(this.valueInterface[t]=e.valueInterface[t]);for(var t in e.structureInterface)e.structureInterface.hasOwnProperty(t)&&(this.structureInterface[t]=e.structureInterface[t]);return this},e}();t.DynamicInterface=p;var c=function(e,t,n){void 0===t&&(t=0),void 0===n&&(n=!1),this.infix=e,this.precedence=t,this.rightAssociative=n};t.InfixStatus=c;var h=function(){function e(e,t,n,r,i){this.typeEnvironment=e,this.valueEnvironment=t,this.structureEnvironment=n,this.signatureEnvironment=r,this.functorEnvironment=i}return e.prototype.getValue=function(e){if(this.valueEnvironment.hasOwnProperty(e))return this.valueEnvironment[e]},e.prototype.getType=function(e){if(this.typeEnvironment.hasOwnProperty(e))return this.typeEnvironment[e]},e.prototype.getStructure=function(e){if(this.structureEnvironment.hasOwnProperty(e))return this.structureEnvironment[e]},e.prototype.getSignature=function(e){if(this.signatureEnvironment.hasOwnProperty(e))return this.signatureEnvironment[e]},e.prototype.getFunctor=function(e){if(this.functorEnvironment.hasOwnProperty(e))return this.functorEnvironment[e]},e.prototype.setValue=function(e,t,n){this.valueEnvironment[e]=[t,n]},e.prototype.setType=function(e,t){this.typeEnvironment[e]=t},e.prototype.setStructure=function(e,t){this.structureEnvironment[e]=t},e.prototype.setSignature=function(e,t){this.signatureEnvironment[e]=t},e.prototype.setFunctor=function(e,t){this.functorEnvironment[e]=t},e.prototype.extend=function(e){for(var t in e.typeEnvironment)e.typeEnvironment.hasOwnProperty(t)&&(this.typeEnvironment[t]=e.typeEnvironment[t]);for(var t in e.valueEnvironment)e.valueEnvironment.hasOwnProperty(t)&&(this.valueEnvironment[t]=e.valueEnvironment[t]);for(var t in e.structureEnvironment)e.structureEnvironment.hasOwnProperty(t)&&(this.structureEnvironment[t]=e.structureEnvironment[t]);for(var t in e.signatureEnvironment)e.signatureEnvironment.hasOwnProperty(t)&&(this.signatureEnvironment[t]=e.signatureEnvironment[t]);for(var t in e.functorEnvironment)e.functorEnvironment.hasOwnProperty(t)&&(this.functorEnvironment[t]=e.functorEnvironment[t]);return this},e.prototype.restrict=function(t){var n=new e({},{},{},this.signatureEnvironment,this.functorEnvironment);for(var r in t.typeInterface)if(t.typeInterface.hasOwnProperty(r)&&this.typeEnvironment.hasOwnProperty(r)){for(var i=new Set,o=[],a=0;a<this.typeEnvironment[r].length;++a)i=i.add(this.typeEnvironment[r][a]);for(a=0;a<t.typeInterface[r].length;++a)i.has(t.typeInterface[r][a])&&o.push(t.typeInterface[r][a]);n.typeEnvironment[r]=o}for(var r in t.valueInterface)t.valueInterface.hasOwnProperty(r)&&this.valueEnvironment.hasOwnProperty(r)&&(n.valueEnvironment[r]=[this.valueEnvironment[r][0],t.valueInterface[r]]);for(var r in t.structureInterface)t.structureInterface.hasOwnProperty(r)&&this.structureEnvironment.hasOwnProperty(r)&&(n.structureEnvironment[r]=this.structureEnvironment[r].restrict(t.structureInterface[r]));return n},e}();t.DynamicBasis=h;var f=function(){function e(e,t,n,r,i){this.typeEnvironment=e,this.valueEnvironment=t,this.structureEnvironment=n,this.signatureEnvironment=r,this.functorEnvironment=i}return e.prototype.getValue=function(e){if(this.valueEnvironment.hasOwnProperty(e))return this.valueEnvironment[e]},e.prototype.getType=function(e){if(this.typeEnvironment.hasOwnProperty(e))return this.typeEnvironment[e]},e.prototype.getStructure=function(e){if(this.structureEnvironment.hasOwnProperty(e))return this.structureEnvironment[e]},e.prototype.getSignature=function(e){if(this.signatureEnvironment.hasOwnProperty(e))return this.signatureEnvironment[e]},e.prototype.getFunctor=function(e){if(this.functorEnvironment.hasOwnProperty(e))return this.functorEnvironment[e]},e.prototype.setValue=function(e,t,n){this.valueEnvironment[e]=[t,n]},e.prototype.deleteValue=function(e){this.valueEnvironment[e]=void 0},e.prototype.setType=function(e,t,n,r,i){this.typeEnvironment[e]=new s(t,n,r,i)},e.prototype.setStructure=function(e,t){this.structureEnvironment[e]=t},e.prototype.setSignature=function(e,t){this.signatureEnvironment[e]=t},e.prototype.setFunctor=function(e,t){this.functorEnvironment[e]=t},e.prototype.extend=function(e){for(var t in e.typeEnvironment)e.typeEnvironment.hasOwnProperty(t)&&(this.typeEnvironment[t]=e.typeEnvironment[t]);for(var t in e.valueEnvironment)e.valueEnvironment.hasOwnProperty(t)&&(this.valueEnvironment[t]=e.valueEnvironment[t]);for(var t in e.structureEnvironment)e.structureEnvironment.hasOwnProperty(t)&&(this.structureEnvironment[t]=e.structureEnvironment[t]);for(var t in e.signatureEnvironment)e.signatureEnvironment.hasOwnProperty(t)&&(this.signatureEnvironment[t]=e.signatureEnvironment[t]);for(var t in e.functorEnvironment)e.functorEnvironment.hasOwnProperty(t)&&(this.functorEnvironment[t]=e.functorEnvironment[t]);return this},e}();t.StaticBasis=f;var l=function(){function e(e,t,n,r,i,o,a,s,u,p,c,h,f){void 0===a&&(a=[0,new Map]),void 0===s&&(s={}),void 0===u&&(u={}),void 0===p&&(p=[]),void 0===c&&(c=!1),void 0===h&&(h=!1),void 0===f&&(f=[]),this.id=e,this.parent=t,this.staticBasis=n,this.dynamicBasis=r,this.memory=i,this.exceptionEvalId=o,this.freeTypeVariables=a,this.infixEnvironment=s,this.valueIdentifierId=u,this.warns=p,this.insideLocalDeclBody=c,this.localDeclStart=h,this.loadedModules=f}return e.allowsRebind=function(e){return void 0==={true:!1,false:!1,nil:!1,"::":!1,"=":!1,ref:!1,":=":!1,"!":!1}[e]},e.prototype.printBinding=function(e,t,n,o,a){void 0===o&&(o={}),void 0===a&&(a=!0);var s,u,p=void 0===o.boldText?function(e){return e}:o.boldText,c=void 0===o.italicText?function(e){return e}:o.italicText,h=void 0===o.escapeText?function(e){return e}:o.escapeText;void 0!==t&&(s=t[0]),void 0!==n&&(u=n[0]);var f="";return(s instanceof i.ValueConstructor||n instanceof r.CustomType&&n+""!="exn")&&a?f+="con":t instanceof i.ExceptionConstructor||n+""=="exn"?f+="exn":f+="val",s?u&&u.isOpaque()?f+=" "+p(e+" = <"+h(u.getOpaqueName())+">"):f+=" "+p(e+" = "+h(s.toString(this))):f+=" "+p(e),u?f+": "+c(h(u.toString(o)))+";":f+": undefined;"},e.prototype.printBasis=function(e,t,n,i){void 0===n&&(n={}),void 0===i&&(i=0);var o="",a=void 0===n.fullSymbol?"":n.fullSymbol,s=void 0===n.emptySymbol?"":n.emptySymbol,u=0===i?a:s,p=" ".repeat(i*(void 0===n.indent?2:n.indent)),c=void 0===n.boldText?function(e){return e}:n.boldText,h=void 0===n.escapeText?function(e){return e}:n.escapeText;if(void 0===e&&void 0!==t){for(var f in t.valueEnvironment)t.valueEnvironment.hasOwnProperty(f)&&(o+=u+" "+p+this.printBinding(f,void 0,t.getValue(f),n)+"\n");for(var f in t.typeEnvironment){if(t.typeEnvironment.hasOwnProperty(f))if(void 0!==(w=t.getType(f))&&w.type instanceof r.CustomType){o+=u+" "+p+"datatype "+c(h(w.type.toString(n)))+" : {\n";for(var l=0,d=w.constructors;l<d.length;l++){var y=d[l];o+=s+" "+p+this.printBinding(y,void 0,t.getValue(y),n)+"\n"}o+=s+" "+p+"};\n"}}for(var f in t.typeEnvironment){if(t.typeEnvironment.hasOwnProperty(f))void 0!==(w=t.getType(f))&&w.type instanceof r.FunctionType&&(o+=u+" "+p+"type "+c(h(w.type.parameterType.toString(n))+" = "+h(w.type.returnType.toString(n)))+";\n")}for(var f in t.structureEnvironment)t.structureEnvironment.hasOwnProperty(f)&&(o+=u+" "+p+"structure "+c(h(f))+": sig\n",o+=t?this.printBasis(void 0,t.getStructure(f),n,i+1):this.printBasis(void 0,void 0,n,i+1),o+=s+" "+p+"end;\n")}else if(void 0!==t&&void 0!==e){for(var f in e.valueEnvironment)e.valueEnvironment.hasOwnProperty(f)&&(o+=t?u+" "+p+this.printBinding(f,e.valueEnvironment[f],t.getValue(f),n,!1)+"\n":u+" "+p+this.printBinding(f,e.valueEnvironment[f],void 0,n,!1)+"\n");for(var f in e.typeEnvironment){if(e.typeEnvironment.hasOwnProperty(f))if(t.typeEnvironment.hasOwnProperty(f))if(void 0!==(w=t.getType(f))&&w.type instanceof r.CustomType){o+=u+" "+p+"datatype "+c(h(w.type.toString(n)))+" = {\n";for(var v=0,m=w.constructors;v<m.length;v++){y=m[v];o+=s+" "+p+this.printBinding(y,e.valueEnvironment[y],t.getValue(y),n)+"\n"}o+=s+" "+p+"};\n"}}for(var f in e.typeEnvironment){var w;if(e.typeEnvironment.hasOwnProperty(f))if(t.typeEnvironment.hasOwnProperty(f))void 0!==(w=t.getType(f))&&w.type instanceof r.FunctionType&&(o+=u+" "+p+"type "+c(h(w.type.parameterType.toString(n)+" = "+w.type.returnType.toString(n)))+";\n")}for(var f in e.structureEnvironment)e.structureEnvironment.hasOwnProperty(f)&&(o+=u+" "+p+"structure "+c(h(f))+" = struct\n",o+=t?this.printBasis(e.getStructure(f),t.getStructure(f),n,i+1):this.printBasis(e.getStructure(f),void 0,n,i+1),o+=s+" "+p+"end;\n")}return o},e.prototype.toString=function(e){void 0===e&&(e={});var t=void 0===e.stopId?this.id:e.stopId,n=this.getDynamicChanges(t-1),r=this.getStaticChanges(t-1);return this.printBasis(n,r,e,0)},e.prototype.getNestedState=function(t){void 0===t&&(t=void 0),void 0===t&&(t=this.id+1);var n=new e(t,this,new f({},{},{},{},{}),new h({},{},{},{},{}),[this.memory[0],{}],this.exceptionEvalId,[this.freeTypeVariables[0],new Map]);n.insideLocalDeclBody=this.insideLocalDeclBody;for(var r=0,i=this.loadedModules;r<i.length;r++){var o=i[r];n.loadedModules.push(o)}return n},e.prototype.hasModule=function(e){for(var t=0,n=this.loadedModules;t<n.length;t++){if(n[t]===e)return!0}return!1},e.prototype.registerModule=function(e){this.loadedModules.push(e)},e.prototype.getIdChanges=function(e){if(this.id<=e)return{};var t={};for(var n in void 0!==this.parent&&(t=this.parent.getIdChanges(e)),this.valueIdentifierId)this.valueIdentifierId.hasOwnProperty(n)&&(t[n]=this.valueIdentifierId[n]);return t},e.prototype.getMemoryChanges=function(e){if(this.id<=e)return[];var t=[];for(var n in void 0!==this.parent&&(t=this.parent.getMemoryChanges(e)),this.memory[1])this.memory[1].hasOwnProperty(n)&&t.push([+n,this.memory[1][n]]);return t},e.prototype.getDynamicChanges=function(e){if(this.id<=e)return new h({},{},{},{},{});var t=new h({},{},{},{},{});return void 0!==this.parent&&(t=this.parent.getDynamicChanges(e)),t=t.extend(this.dynamicBasis)},e.prototype.getDynamicLocalDeclChanges=function(e){if(this.id<=e||this.localDeclStart)return new h({},{},{},{},{});var t=new h({},{},{},{},{});return void 0!==this.parent&&(t=this.parent.getDynamicLocalDeclChanges(e)),t=t.extend(this.dynamicBasis)},e.prototype.getStaticChanges=function(e){if(this.id<=e)return new f({},{},{},{},{});var t=new f({},{},{},{},{});return void 0!==this.parent&&(t=this.parent.getStaticChanges(e)),t=t.extend(this.staticBasis)},e.prototype.getCell=function(e){return void 0!==this.memory[1][e]?this.memory[1][e]:void 0===this.parent?void 0:this.parent.getCell(e)},e.prototype.getTypeVariableBinds=function(e){void 0===e&&(e=0);var t=this.freeTypeVariables;if(void 0===this.parent||this.parent.id<e){var n=new Map;return t[1].forEach((function(e,t){n.set(t,e)})),[t[0],n]}var r=this.parent.getTypeVariableBinds(e);return t[1].forEach((function(e,t){r[1].set(t,e)})),[Math.max(t[0],r[0]),r[1]]},e.prototype.getStaticValue=function(e,t){if(void 0===t&&(t=0),!e.startsWith("__arg")&&!e.startsWith("'*")){var n=this.staticBasis.getValue(e);return void 0!==n||void 0===this.parent||this.parent.id<t?void 0!==n?[n[0],n[1]]:n:this.parent.getStaticValue(e,t)}},e.prototype.getStaticType=function(e,t){void 0===t&&(t=0);var n=this.staticBasis.getType(e);return void 0!==n||void 0===this.parent||this.parent.id<t?n:this.parent.getStaticType(e,t)},e.prototype.getStaticStructure=function(e,t){void 0===t&&(t=0);var n=this.staticBasis.getStructure(e);return void 0!==n||void 0===this.parent||this.parent.id<t?n:this.parent.getStaticStructure(e,t)},e.prototype.getAndResolveStaticStructure=function(e,t){void 0===t&&(t=0);var n=void 0;if(0===e.qualifiers.length)throw new a.EvaluationError("Unqualified LongIdentifierToken are too unqualified to be useful here.");n=this.getStaticStructure(e.qualifiers[0].getText(),t);for(var r=1;r<e.qualifiers.length;++r){if(void 0===n)return n;n=n.getStructure(e.qualifiers[r].getText())}return n},e.prototype.getStaticSignature=function(e,t){void 0===t&&(t=0);var n=this.staticBasis.getSignature(e);return void 0!==n||void 0===this.parent||this.parent.id<t?n:this.parent.getStaticSignature(e,t)},e.prototype.getStaticFunctor=function(e,t){void 0===t&&(t=0);var n=this.staticBasis.getFunctor(e);return void 0!==n||void 0===this.parent||this.parent.id<t?n:this.parent.getStaticFunctor(e,t)},e.prototype.getDynamicValue=function(e,t){void 0===t&&(t=0);var n=this.dynamicBasis.getValue(e);return void 0!==n||void 0===this.parent||this.parent.id<t?void 0!==n?[n[0],n[1]]:n:this.parent.getDynamicValue(e,t)},e.prototype.getDynamicType=function(e,t){void 0===t&&(t=0);var n=this.dynamicBasis.getType(e);return void 0!==n||void 0===this.parent||this.parent.id<t?void 0!==n?[n[0],n[1]]:n:this.parent.getDynamicType(e,t)},e.prototype.getDynamicStructure=function(e,t){void 0===t&&(t=0);var n=this.dynamicBasis.getStructure(e);return void 0!==n||void 0===this.parent||this.parent.id<t?n:this.parent.getDynamicStructure(e,t)},e.prototype.getAndResolveDynamicStructure=function(e,t){void 0===t&&(t=0);var n=void 0;if(0===e.qualifiers.length)throw new a.EvaluationError("Unqualified LongIdentifierToken are too unqualified to be useful here.");n=this.getDynamicStructure(e.qualifiers[0].getText(),t);for(var r=1;r<e.qualifiers.length;++r){if(void 0===n)return n;n=n.getStructure(e.qualifiers[r].getText())}return n},e.prototype.getDynamicSignature=function(e,t){void 0===t&&(t=0);var n=this.dynamicBasis.getSignature(e);return void 0!==n||void 0===this.parent||this.parent.id<t?n:this.parent.getDynamicSignature(e,t)},e.prototype.getDynamicFunctor=function(e,t){void 0===t&&(t=0);var n=this.dynamicBasis.getFunctor(e);return void 0!==n||void 0===this.parent||this.parent.id<t?n:this.parent.getDynamicFunctor(e,t)},e.prototype.getInfixStatus=function(e,t){if(void 0===t&&(t=0),e.isVid()||e instanceof o.LongIdentifierToken)return this.infixEnvironment.hasOwnProperty(e.getText())||!this.parent||this.parent.id<t?this.infixEnvironment[e.getText()]:this.parent.getInfixStatus(e,t);throw new a.InternalInterpreterError('You gave me some "'+e.getText()+'" ('+e.typeName()+") but I only want (Long)IdentifierToken.")},e.prototype.getValueIdentifierId=function(e,t){return void 0===t&&(t=0),this.valueIdentifierId.hasOwnProperty(e)?this.valueIdentifierId[e]:!this.parent||this.parent.id<t?0:this.parent.getValueIdentifierId(e,t)},e.prototype.getWarnings=function(){return this.warns},e.prototype.incrementValueIdentifierId=function(e,t){if(void 0===t&&(t=void 0),void 0===t||this.id===t)this.valueIdentifierId[e]=this.getValueIdentifierId(e,t)+1;else{if(t>this.id||void 0===this.parent)throw new a.InternalInterpreterError('State with id "'+t+'" does not exist.');this.parent.incrementValueIdentifierId(e,t)}},e.prototype.setCell=function(e,t){e>=this.memory[0]&&(this.memory[0]=e+1),this.memory[1][e]=t},e.prototype.setNewCell=function(e){return this.memory[1][this.memory[0]]=e,new i.ReferenceValue(this.memory[0]++)},e.prototype.getNextExceptionEvalId=function(){return this.exceptionEvalId++},e.prototype.deleteStaticValue=function(e){this.staticBasis.deleteValue(e),void 0!==this.parent&&this.parent.deleteStaticValue(e)},e.prototype.setStaticValue=function(e,t,n,r){if(void 0===r&&(r=void 0),void 0===r||r===this.id)this.staticBasis.setValue(e,t,n);else{if(r>this.id||void 0===this.parent)throw new a.InternalInterpreterError('State with id "'+r+'" does not exist.');this.parent.setStaticValue(e,t,n,r)}},e.prototype.setStaticType=function(e,t,n,r,i,o){if(void 0===o&&(o=void 0),void 0===o||o===this.id)this.staticBasis.setType(e,t,n,r,i);else{if(o>this.id||void 0===this.parent)throw new a.InternalInterpreterError('State with id "'+o+'" does not exist.');this.parent.setStaticType(e,t,n,r,i,o)}},e.prototype.setStaticStructure=function(e,t,n){if(void 0===n&&(n=void 0),void 0===n||n===this.id)this.staticBasis.setStructure(e,t);else{if(n>this.id||void 0===this.parent)throw new a.InternalInterpreterError('State with id "'+n+'" does not exist.');this.parent.setStaticStructure(e,t,n)}},e.prototype.setStaticSignature=function(e,t,n){if(void 0===n&&(n=void 0),void 0===n||n===this.id)this.staticBasis.setSignature(e,t);else{if(n>this.id||void 0===this.parent)throw new a.InternalInterpreterError('State with id "'+n+'" does not exist.');this.parent.setStaticSignature(e,t,n)}},e.prototype.setStaticFunctor=function(e,t,n){if(void 0===n&&(n=void 0),void 0===n||n===this.id)this.staticBasis.setFunctor(e,t);else{if(n>this.id||void 0===this.parent)throw new a.InternalInterpreterError('State with id "'+n+'" does not exist.');this.parent.setStaticFunctor(e,t,n)}},e.prototype.setDynamicValue=function(e,t,n,r){if(void 0===r&&(r=void 0),void 0===r||r===this.id)this.dynamicBasis.setValue(e,t,n);else{if(r>this.id||void 0===this.parent)throw new a.InternalInterpreterError('State with id "'+r+'" does not exist.');this.parent.setDynamicValue(e,t,n,r)}},e.prototype.setDynamicType=function(e,t,n){if(void 0===n&&(n=void 0),void 0===n||n===this.id)this.dynamicBasis.setType(e,t);else{if(n>this.id||void 0===this.parent)throw new a.InternalInterpreterError('State with id "'+n+'" does not exist.');this.parent.setDynamicType(e,t,n)}},e.prototype.setDynamicStructure=function(e,t,n){if(void 0===n&&(n=void 0),void 0===n||n===this.id)this.dynamicBasis.setStructure(e,t);else{if(n>this.id||void 0===this.parent)throw new a.InternalInterpreterError('State with id "'+n+'" does not exist.');this.parent.setDynamicStructure(e,t,n)}},e.prototype.setDynamicSignature=function(e,t,n){if(void 0===n&&(n=void 0),void 0===n||n===this.id)this.dynamicBasis.setSignature(e,t);else{if(n>this.id||void 0===this.parent)throw new a.InternalInterpreterError('State with id "'+n+'" does not exist.');this.parent.setDynamicSignature(e,t,n)}},e.prototype.setDynamicFunctor=function(e,t,n){if(void 0===n&&(n=void 0),void 0===n||n===this.id)this.dynamicBasis.setFunctor(e,t);else{if(n>this.id||void 0===this.parent)throw new a.InternalInterpreterError('State with id "'+n+'" does not exist.');this.parent.setDynamicFunctor(e,t,n)}},e.prototype.setInfixStatus=function(e,t,n,r,i){if(void 0===i&&(i=void 0),void 0===i||i===this.id)(e.isVid()||e instanceof o.LongIdentifierToken)&&(this.infixEnvironment[e.getText()]=new c(r,t,n));else{if(i>this.id||void 0===this.parent)throw new a.InternalInterpreterError('State with id "'+i+'" does not exist.');this.parent.setInfixStatus(e,t,n,r,i)}},e.prototype.setValueIdentifierId=function(e,t,n){if(void 0===n&&(n=void 0),void 0===n||n===this.id)this.valueIdentifierId[e]=t;else{if(n>this.id||void 0===this.parent)throw new a.InternalInterpreterError('State with id "'+n+'" does not exist.');this.parent.setValueIdentifierId(e,t,n)}},e.prototype.addWarning=function(e,t){if(void 0===t&&(t=void 0),void 0===t||t===this.id)this.warns.push(e);else{if(t>this.id||void 0===this.parent)throw new a.InternalInterpreterError('State with id "'+t+'" does not exist.');this.parent.addWarning(e,t)}},e.prototype.setWarnings=function(e,t){if(void 0===t&&(t=void 0),void 0===t||t===this.id)this.warns=e;else{if(t>this.id||void 0===this.parent)throw new a.InternalInterpreterError('State with id "'+t+'" does not exist.');this.parent.setWarnings(e,t)}},e}();t.State=l},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var r=n(0),i=n(1),o=n(2),a=n(8),s=n(10),u=n(13),p=n(14),c=n(15),h=n(17),f=n(18),l=n(19),d=n(20),y=n(21),v=n(22),m=n(23),w=n(24);t.intType=new i.CustomType("int"),t.realType=new i.CustomType("real"),t.wordType=new i.CustomType("word"),t.boolType=new i.CustomType("bool"),t.stringType=new i.CustomType("string"),t.charType=new i.CustomType("char"),t.overflowException=new o.ExceptionConstructor("Overflow",0,0,3),t.domainException=new o.ExceptionConstructor("Domain",0,0,4),t.sizeException=new o.ExceptionConstructor("Size",0,0,5),t.chrException=new o.ExceptionConstructor("Chr",0,0,6),t.subscriptException=new o.ExceptionConstructor("Subscript",0,0,7),t.failException=new o.ExceptionConstructor("Fail",1,0,8),t.STDLIB={__Base:{native:void 0,code:"fun o (f,g) x = f (g x);\n infix 3 o;\n datatype order = LESS | EQUAL | GREATER;\n\n exception Domain;\n exception Size;\n exception Chr;\n exception Subscript;\n exception Fail of string;\n\n fun not true = false | not false = true;\n\n (* fun ! (a : 'A ref): 'A = ! a;\n fun op := ((a, b) : ('A ref * 'A)): unit = a := b;\n fun ref (a : 'A): 'A ref = ref a; *)\n\n fun ignore a = ();\n infix 0 before;\n fun a before (b: unit) = a;",requires:void 0},Array:u.ARRAY_LIB,Char:p.CHAR_LIB,Eval:c.EVAL_LIB,Int:h.INT_LIB,List:f.LIST_LIB,Listsort:l.LISTSORT_LIB,Math:d.MATH_LIB,Option:{native:void 0,code:"structure Option = struct\n exception Option;\n\n datatype 'a option = NONE | SOME of 'a;\n\n fun getOpt (NONE, a) = a\n | getOpt (SOME x, a) = x;\n\n fun isSome NONE = false\n | isSome (SOME _) = true;\n\n fun valOf (SOME x) = x\n | valOf NONE = raise Option;\n\n fun filter f x = if f x then SOME x else NONE;\n\n fun join NONE = NONE\n | join (SOME (SOME x)) = SOME x;\n\n fun app f (SOME v) = f v\n | app f NONE = ();\n\n fun map f NONE = NONE\n | map f (SOME v) = SOME(f v);\n\n fun mapPartial f NONE = NONE\n | mapPartial f (SOME v) = f v;\n\n fun compose (f, g) a = case g a of\n NONE => NONE\n | SOME v => SOME (f v);\n\n fun composePartial (f, g) a = case g a of\n NONE => NONE\n | SOME v => (f v);\n end;\n open Option;",requires:void 0},Random:y.RANDOM_LIB,Real:v.REAL_LIB,String:m.STRING_LIB,Vector:w.VECTOR_LIB,Version:{native:void 0,code:'structure Version = struct\n val version = "'+s.VERSION+'";\n val branch = "'+s.BRANCH_NAME+'";\n val commit = "'+s.COMMIT_HASH+'";\n val buildDate = "'+s.BUILD_DATE+'";\n val message = "'+s.COMMIT_MESSAGE+'";\n end;',requires:void 0}},t.loadModule=function e(n,i,o){if(!t.STDLIB.hasOwnProperty(i))throw new r.InternalInterpreterError('The module "'+i+'" does not exist. Auuuu~');if(n.hasModule(i))return n;var s=t.STDLIB[i];if(void 0!==s.requires)for(var u=0,p=s.requires;u<p.length;u++){var c=p[u];n.hasModule(c)||(n=e(n,c,o))}return void 0!==s.native&&(n=s.native(n,o)),void 0!==s.code&&(n=a.interpret(s.code,n,o).state),n.registerModule(i),n}},function(e,t,n){"use strict";var r,i=this&&this.__extends||(r=function(e,t){return(r=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)t.hasOwnProperty(n)&&(e[n]=t[n])})(e,t)},function(e,t){function n(){this.constructor=e}r(e,t),e.prototype=null===t?Object.create(t):(n.prototype=t.prototype,new n)});Object.defineProperty(t,"__esModule",{value:!0});var o=function(){function e(e){this.text=e}return e.prototype.typeName=function(){return"CommentToken"},e.prototype.getText=function(){return this.text},e.prototype.isValidRecordLabel=function(){return!1},e.prototype.isVid=function(){return!1},e}();t.CommentToken=o;var a=function(){function e(e){this.text=e}return e.prototype.typeName=function(){return"KeywordToken"},e.prototype.getText=function(){return this.text},e.prototype.isValidRecordLabel=function(){return!1},e.prototype.isVid=function(){return!1},e}();t.KeywordToken=a;var s=function(){function e(){}return e.prototype.typeName=function(){return"ConstantToken"},e.prototype.isVid=function(){return!1},e}();t.ConstantToken=s;var u=function(e){function t(t,n){var r=e.call(this)||this;return r.text=t,r.value=n,r}return i(t,e),t.prototype.typeName=function(){return"IntegerConstantToken"},t.prototype.getText=function(){return""+this.value},t.prototype.isValidRecordLabel=function(){return!1},t}(s);t.IntegerConstantToken=u;var p=function(e){function t(t,n){var r=e.call(this)||this;return r.text=t,r.value=n,r}return i(t,e),t.prototype.typeName=function(){return"RealConstantToken"},t.prototype.getText=function(){return this.text},t.prototype.isValidRecordLabel=function(){return!1},t}(s);t.RealConstantToken=p;var c=function(e){function t(t,n){var r=e.call(this)||this;return r.text=t,r.value=n,r}return i(t,e),t.prototype.typeName=function(){return"WordConstantToken"},t.prototype.getText=function(){return""+this.value},t.prototype.isValidRecordLabel=function(){return!1},t}(s);t.WordConstantToken=c;var h=function(e){function t(t,n){var r=e.call(this)||this;return r.text=t,r.value=n,r}return i(t,e),t.prototype.typeName=function(){return"CharacterConstantToken"},t.prototype.getText=function(){return""+this.text},t.prototype.isValidRecordLabel=function(){return!1},t}(s);t.CharacterConstantToken=h;var f=function(e){function t(t,n){var r=e.call(this)||this;return r.text=t,r.value=n,r}return i(t,e),t.prototype.typeName=function(){return"StringConstantToken"},t.prototype.getText=function(){return""+this.text},t.prototype.isValidRecordLabel=function(){return!1},t}(s);t.StringConstantToken=f;var l=function(){function e(e){this.text=e,this.opPrefixed=!1}return e.prototype.typeName=function(){return"IdentifierToken"},e.prototype.getText=function(){return this.text},e.prototype.isValidRecordLabel=function(){return!0},e.prototype.isVid=function(){return!0},e}();t.IdentifierToken=l;var d=function(e){function t(t){return e.call(this,t)||this}return i(t,e),t.prototype.typeName=function(){return"AlphanumericIdentifierToken"},t.prototype.getText=function(){return this.text},t.prototype.isValidRecordLabel=function(){return!0},t}(l);t.AlphanumericIdentifierToken=d;var y=function(){function e(e){this.text=e}return e.prototype.typeName=function(){return"TypeVariableToken"},e.prototype.getText=function(){return this.text},e.prototype.isValidRecordLabel=function(){return!1},e.prototype.isVid=function(){return!1},e}();t.TypeVariableToken=y;var v=function(e){function t(t){return e.call(this,t)||this}return i(t,e),t.prototype.typeName=function(){return"EqualityTypeVariableToken"},t.prototype.getText=function(){return this.text},t.prototype.isValidRecordLabel=function(){return!1},t.prototype.isVid=function(){return!1},t}(y);t.EqualityTypeVariableToken=v;var m=function(e){function t(){var t=e.call(this,"*")||this;return t.opPrefixed=!1,t}return i(t,e),t.prototype.typeName=function(){return"StarToken"},t.prototype.getText=function(){return this.text},t.prototype.isValidRecordLabel=function(){return!0},t.prototype.isVid=function(){return!0},t}(a);t.StarToken=m;var w=function(e){function t(){var t=e.call(this,"=")||this;return t.opPrefixed=!1,t}return i(t,e),t.prototype.typeName=function(){return"EqualsToken"},t.prototype.getText=function(){return this.text},t.prototype.isValidRecordLabel=function(){return!1},t.prototype.isVid=function(){return!0},t}(a);t.EqualsToken=w;var g=function(e){function t(t,n){return e.call(this,t,n)||this}return i(t,e),t.prototype.typeName=function(){return"NumericToken"},t.prototype.getText=function(){return this.text},t.prototype.isValidRecordLabel=function(){return!0},t.prototype.isVid=function(){return!1},t}(u);t.NumericToken=g;var T=function(){function e(e,t,n){this.text=e,this.qualifiers=t,this.id=n,this.opPrefixed=!1}return e.prototype.typeName=function(){return"LongIdentifierToken"},e.prototype.getText=function(){for(var e="",t=0;t<this.qualifiers.length;++t)t>0&&(e+="."),e+=this.qualifiers[t].getText();return e+"."+this.id.getText()},e.prototype.isValidRecordLabel=function(){return!1},e.prototype.isVid=function(){return!1},e}();t.LongIdentifierToken=T},function(e,t,n){"use strict";var r,i=this&&this.__extends||(r=function(e,t){return(r=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)t.hasOwnProperty(n)&&(e[n]=t[n])})(e,t)},function(e,t){function n(){this.constructor=e}r(e,t),e.prototype=null===t?Object.create(t):(n.prototype=t.prototype,new n)});Object.defineProperty(t,"__esModule",{value:!0});var o=n(7),a=n(5),s=n(1),u=n(3),p=n(0),c=n(2),h=function(){function e(){}return e.prototype.elaborate=function(e,t,n,r,i,o){throw void 0===t&&(t=new Map),void 0===n&&(n="'*t0"),void 0===r&&(r=new Map),void 0===i&&(i=!1),void 0===o&&(o={}),new p.InternalInterpreterError("Not yet implemented.")},e.prototype.evaluate=function(e,t){throw new p.InternalInterpreterError("Not yet implemented.")},e.prototype.toString=function(){throw new p.InternalInterpreterError("Not yet implemented.")},e.prototype.simplify=function(){throw new p.InternalInterpreterError("Not yet implemented.")},e.prototype.assertUniqueBinding=function(e,t){return new Set},e}();t.Declaration=h;var f=function(e){function t(t,n,r){void 0===r&&(r=0);var i=e.call(this)||this;return i.typeVariableSequence=t,i.valueBinding=n,i.id=r,i}return i(t,e),t.prototype.assertUniqueBinding=function(e,t){for(var n=0;n<this.valueBinding.length;++n)this.valueBinding[n].pattern.assertUniqueBinding(e,t),this.valueBinding[n].expression.assertUniqueBinding(e,t);return new Set},t.prototype.simplify=function(){for(var e=[],n=0;n<this.valueBinding.length;++n)e.push(new b(this.valueBinding[n].isRecursive,this.valueBinding[n].pattern.simplify(),this.valueBinding[n].expression.simplify()));return new t(this.typeVariableSequence,e,this.id)},t.prototype.elaborate=function(e,t,n,r,i,a){for(var c=[],h=[],f=[],l=[],d=t,y=0,v=function(){if(m.valueBinding[y].isRecursive){for(var t=y;t<m.valueBinding.length;++t){for(var a=m.valueBinding[t].pattern;a instanceof o.TypedExpression;)a=a.expression;var u=a.name.getText();c.push([u,new s.TypeVariableBind("'a",new s.TypeVariableBind("'b",new s.FunctionType(new s.TypeVariable("'a"),new s.TypeVariable("'b"))))])}return"break"}var p=!1;try{var v=e.getNestedState(e.id),w=new Map;d.forEach((function(e,t){w=w.set(t,e)}));var g=new Map;r.forEach((function(e,t){g=g.set(t,null)})),m.valueBinding[y].getType(m.typeVariableSequence,v,w,n,g,i)}catch(e){p=!0}var T=m.valueBinding[y].getType(m.typeVariableSequence,e,d,n,r,i);l=l.concat(T[1]),d=T[2],n=T[3],e.valueIdentifierId=T[4];for(t=0;t<T[0].length;++t)f.push(p),h.push(T[0][t])},m=this;y<this.valueBinding.length;++y){if("break"===v())break}for(var w=e.getNestedState(e.id),g=0;g<c.length;++g){if(!(a&&!0===a.allowSuccessorML||c[g][1].isResolved()))throw new p.ElaborationError("Unresolved record type.");w.setStaticValue(c[g][0],c[g][1],u.IdentifierStatus.VALUE_VARIABLE)}var T=l,E=new Map;d.forEach((function(e,t){E=E.set(t,e)}));for(var x=n,S=w.valueIdentifierId,I=this.valueBinding.length-y+1,V=0;V<I*I+1;++V){l=T,d=new Map,E.forEach((function(e,t){d=d.set(t,e)})),n=x,w.valueIdentifierId=S;var k=!1,b=function(t){var o=!1;if(!i)try{var s=w.getNestedState(e.id),c=new Map;d.forEach((function(e,t){c=c.set(t,e)})),A.valueBinding[t].getType(A.typeVariableSequence,s,c,n,new Map,i)}catch(e){o=!0}var h=A.valueBinding[t].getType(A.typeVariableSequence,w,d,n,r,i);l=l.concat(h[1]),d=h[2],n=h[3],w.valueIdentifierId=h[4];for(var f=0;f<h[0].length;++f){var y=w.getStaticValue(h[0][f][0]);if(void 0!==y&&y[0].normalize()[0].equals(h[0][f][1].normalize()[0])||(k=!0),!(a&&!0===a.allowSuccessorML||h[0][f][1].isResolved()))throw new p.ElaborationError("Unresolved record type.");o||(r=r.set(h[0][f][0],h[0][f][1])),w.setStaticValue(h[0][f][0],h[0][f][1],u.IdentifierStatus.VALUE_VARIABLE)}},A=this;for(g=y;g<this.valueBinding.length;++g)b(g);if(!k)break;if(V===I*I)throw new p.ElaborationError("My brain trembles; too much circularity.")}for(g=0;g<h.length;++g){if(!(a&&!0===a.allowSuccessorML||h[g][1].isResolved()))throw new p.ElaborationError("Unresolved record type.");f[g]||(r=r.set(h[g][0],h[g][1])),w.setStaticValue(h[g][0],h[g][1],u.IdentifierStatus.VALUE_VARIABLE)}return[w,l,d,n]},t.prototype.evaluate=function(e,t){var n=e.state;void 0===e.step&&(e.result=[],e.recursives=[],e.isRec=!1,e.step=-1);var r=e.result,i=e.recursives,o=e.isRec,a=e.step;if(a>=0){var s=e.recResult;if(void 0===s)throw new p.InternalInterpreterError("How is this undefined? "+JSON.stringify(s));if(this.valueBinding[a].isRecursive&&(o=!0),s.hasThrown)return{newState:n,value:s.value,hasThrown:!0};var h=this.valueBinding[a].pattern.matches(n,s.value);if(void 0===h)return{newState:n,value:new c.ExceptionValue("Bind",void 0,0,1),hasThrown:!0};for(var f=0;f<h.length;++f)o?i.push(h[f]):r.push(h[f])}if(++a<this.valueBinding.length)return e.step=a,e.isRec=o,t.push({next:this,params:e}),void t.push({next:this.valueBinding[a].expression,params:{state:n,modifiable:e.modifiable,recResult:void 0}});var l=n.getNestedState(n.id);for(f=0;f<i.length;++f){if("="===i[f][0])throw new p.EvaluationError("All declarations are equal, but some declarations are more equal than others.");i[f][1]instanceof c.FunctionValue?l.setDynamicValue(i[f][0],new c.FunctionValue(i[f][1].state,i,i[f][1].body),u.IdentifierStatus.VALUE_VARIABLE):l.setDynamicValue(i[f][0],i[f][1],u.IdentifierStatus.VALUE_VARIABLE)}for(f=0;f<r.length;++f){if("="===r[f][0])throw new p.EvaluationError("All declarations are equal, but some declarations are more equal than others.");l.setDynamicValue(r[f][0],r[f][1],u.IdentifierStatus.VALUE_VARIABLE)}return{newState:l,value:void 0,hasThrown:!1}},t.prototype.toString=function(){for(var e="val",t=0;t<this.typeVariableSequence.length;++t)e+=" "+this.typeVariableSequence.toString();for(t=0;t<this.valueBinding.length;++t)t>0&&(e+=" and"),e+=" "+this.valueBinding[t];return e+";"},t}(h);t.ValueDeclaration=f;var l=function(e){function t(t,n){void 0===n&&(n=0);var r=e.call(this)||this;return r.typeBinding=t,r.id=n,r}return i(t,e),t.prototype.simplify=function(){for(var e=[],n=0;n<this.typeBinding.length;++n)e.push(new L(this.typeBinding[n].typeVariableSequence,this.typeBinding[n].name,this.typeBinding[n].type.simplify()));return new t(e,this.id)},t.prototype.elaborate=function(e,t,n,r,i,o){for(var a=function(n){for(var r=new Set,i=[],o=0,a=u.typeBinding[n].typeVariableSequence;o<a.length;o++){var c=a[o];r=r.add(c.toString())}if(u.typeBinding[n].type.instantiate(e,t).getTypeVariables().forEach((function(e,t){r.has(t)||i.push(t)})),i.length>0)throw p.ElaborationError.getUnguarded(i);var h=e.getStaticType(u.typeBinding[n].name.getText());if(void 0!==h&&h.type instanceof s.CustomType)throw new p.ElaborationError("Nnaaa~ Redefining types as aliases is not yet implemented.");e.setStaticType(u.typeBinding[n].name.getText(),new s.FunctionType(new s.CustomType(u.typeBinding[n].name.getText(),u.typeBinding[n].typeVariableSequence),u.typeBinding[n].type.instantiate(e,t)),[],u.typeBinding[n].typeVariableSequence.length,!0)},u=this,c=0;c<this.typeBinding.length;++c)a(c);return[e,[],t,n]},t.prototype.evaluate=function(e,t){for(var n=e.state,r=0;r<this.typeBinding.length;++r)n.setDynamicType(this.typeBinding[r].name.getText(),[]);return{newState:n,value:void 0,hasThrown:!1}},t.prototype.toString=function(){for(var e="type",t=0;t<this.typeBinding.length;++t)t>0&&(e+=" and"),e+=" <stuff> "+this.typeBinding[t].name.getText(),e+=" = "+this.typeBinding[t].type;return e+";"},t}(h);t.TypeDeclaration=l;var d=function(e){function t(t,n,r,i){void 0===r&&(r=0),void 0===i&&(i={});var o=e.call(this)||this;if(o.datatypeBinding=t,o.typeBinding=n,o.id=r,o.givenIds=i,void 0!==o.typeBinding)throw new p.FeatureDisabledError('Who is "withtype"?');return o}return i(t,e),t.prototype.simplify=function(){for(var e=[],n=0;n<this.datatypeBinding.length;++n){for(var r=[],i=0;i<this.datatypeBinding[n].type.length;++i)void 0!==this.datatypeBinding[n].type[i][1]?r.push([this.datatypeBinding[n].type[i][0],this.datatypeBinding[n].type[i][1].simplify()]):r.push(this.datatypeBinding[n].type[i]);e.push(new R(this.datatypeBinding[n].typeVariableSequence,this.datatypeBinding[n].name,r))}return new t(e,void 0,this.id)},t.prototype.elaborate=function(e,t,n,r,i,o){for(var a=[],s=0;s<this.datatypeBinding.length;++s){for(var c=this.datatypeBinding[s].getType(e,i,r),h=0;h<c[0].length;++h){if(!u.State.allowsRebind(c[0][h][0]))throw new p.ElaborationError('You simply cannot rebind "'+c[0][h][0]+'".');e.setStaticValue(c[0][h][0],c[0][h][1],u.IdentifierStatus.VALUE_CONSTRUCTOR),a.push(c[0][h][1])}e.setStaticType(c[2][0],c[1],c[2][1],this.datatypeBinding[s].typeVariableSequence.length,!0),e.incrementValueIdentifierId(c[2][0])}for(s=0;s<a.length;++s)a[s].instantiate(e,new Map);return[e,[],t,n]},t.prototype.evaluate=function(e,t){for(var n=e.state,r=e.modifiable,i=0;i<this.datatypeBinding.length;++i){for(var o=this.datatypeBinding[i].compute(n,r),a=0;a<o[0].length;++a){if(!u.State.allowsRebind(o[0][a][0]))throw new p.EvaluationError('You simply cannot rebind "'+o[0][a][0]+'".');n.setDynamicValue(o[0][a][0],o[0][a][1],u.IdentifierStatus.VALUE_CONSTRUCTOR)}n.setDynamicType(o[1][0],o[1][1]),void 0===this.givenIds[o[1][0]]&&(r.incrementValueIdentifierId(o[1][0]),this.givenIds[o[1][0]]=n.getValueIdentifierId(o[1][0]))}return{newState:n,value:void 0,hasThrown:!1}},t.prototype.toString=function(){for(var e="datatype",t=0;t<this.datatypeBinding.length;++t){t>0&&(e+=" and"),e+=" "+this.datatypeBinding[t].name.getText()+" =";for(var n=0;n<this.datatypeBinding[t].type.length;++n)n>0&&(e+=" |"),e+=" "+this.datatypeBinding[t].type[n][0].getText(),void 0!==this.datatypeBinding[t].type[n][1]&&(e+=" of "+this.datatypeBinding[t].type[n][1])}return e+";"},t}(h);t.DatatypeDeclaration=d;var y=function(e){function t(t,n,r){void 0===r&&(r=0);var i=e.call(this)||this;return i.name=t,i.oldname=n,i.id=r,i}return i(t,e),t.prototype.simplify=function(){return this},t.prototype.elaborate=function(e,t,n,r,i,o){var u=void 0;if(this.oldname instanceof a.LongIdentifierToken){var c=e.getAndResolveStaticStructure(this.oldname);void 0!==c&&(u=c.getType(this.oldname.id.getText()))}else u=e.getStaticType(this.oldname.getText());if(void 0===u)throw new p.ElaborationError('The datatype "'+this.oldname.getText()+"\" doesn't exist.");var h=u.type.instantiate(e,t);return e.setStaticType(this.name.getText(),new s.FunctionType(new s.CustomType(this.name.getText(),h.typeArguments,this.oldname instanceof a.LongIdentifierToken?this.oldname:void 0),h),[],u.arity,u.allowsEquality),[e,[],t,n]},t.prototype.evaluate=function(e,t){var n=e.state,r=[];if(this.oldname instanceof a.LongIdentifierToken){var i=n.getAndResolveDynamicStructure(this.oldname);void 0!==i&&(r=i.getType(this.oldname.id.getText()))}else r=n.getDynamicType(this.oldname.getText());if(void 0===r)throw new p.EvaluationError('The datatype "'+this.oldname.getText()+'" does not exist.');return n.setDynamicType(this.name.getText(),r),{newState:n,value:void 0,hasThrown:!1}},t.prototype.toString=function(){return"datatype "+this.name.getText()+" = datatype "+this.oldname.getText()+";"},t}(h);t.DatatypeReplication=y;var v=function(e){function t(t,n){void 0===n&&(n=0);var r=e.call(this)||this;return r.bindings=t,r.id=n,r}return i(t,e),t.prototype.simplify=function(){return this},t.prototype.toString=function(){return"exception <stuff>;"},t.prototype.elaborate=function(e,t,n,r,i,o){var a=new Set;t.forEach((function(e,t){t.includes("!")&&(a=a.add(t.substring(1)))}));for(var s=0;s<this.bindings.length;++s)e=this.bindings[s].elaborate(e,i,a,o);return[e,[],t,n]},t.prototype.evaluate=function(e,t){for(var n=e.state,r=0;r<this.bindings.length;++r)this.bindings[r].evaluate(n,e.modifiable);return{newState:n,value:void 0,hasThrown:!1}},t}(h);t.ExceptionDeclaration=v;var m=function(e){function t(t,n,r){void 0===r&&(r=0);var i=e.call(this)||this;return i.declaration=t,i.body=n,i.id=r,i}return i(t,e),t.prototype.assertUniqueBinding=function(e,t){return this.declaration.assertUniqueBinding(e,t),this.body.assertUniqueBinding(e,t),new Set},t.prototype.simplify=function(){return new t(this.declaration.simplify(),this.body.simplify(),this.id)},t.prototype.elaborate=function(e,t,n,r,i,o){var a=[e.getNestedState(0).getNestedState(e.id),[],t,n],s=new Map;r.forEach((function(e,t){s=s.set(t,e)}));var u=this.declaration.elaborate(a[0],t,n,s,!1,o);e.valueIdentifierId=u[0].getIdChanges(0);var p=u[0].getNestedState(e.id);return a=this.body.elaborate(p,u[2],u[3],s,i,o),p.parent=e,[a[0],u[1].concat(a[1]),a[2],a[3]]},t.prototype.evaluate=function(e,t){var n=e.state,r=e.modifiable;void 0===e.step&&(e.step=-1);var i=e.step;if(-1===i){var o=n.getNestedState(0),a=o.getNestedState(n.id);return o.insideLocalDeclBody||(o.localDeclStart=!0),e.nstate=a,e.step=i+1,t.push({next:this,params:e}),void t.push({next:this.declaration,params:{state:a,modifiable:r,recResult:void 0}})}if(0===i){if(void 0===(c=e.recResult)||void 0===c.newState)throw new p.InternalInterpreterError("How is this undefined?");var s=c.newState;return c.hasThrown?{newState:n,value:c.value,hasThrown:!0}:((a=s.getNestedState(n.id)).insideLocalDeclBody=!0,e.nstate=a,e.res=c,e.step=i+1,t.push({next:this,params:e}),void t.push({next:this.body,params:{state:a,modifiable:r,recResult:void 0}}))}var u=e.recResult,c=(a=e.nstate,e.res);if(void 0===u||void 0===c)throw new p.InternalInterpreterError("How is this undefined?");return a.parent=n,void 0!==u.newState&&(u.newState.insideLocalDeclBody=n.insideLocalDeclBody),u},t.prototype.toString=function(){var e="local "+this.declaration;return e+=" in "+this.body,e+=" end;"},t}(h);t.LocalDeclaration=m;var w=function(e){function t(t,n){void 0===n&&(n=0);var r=e.call(this)||this;return r.names=t,r.id=n,r}return i(t,e),t.prototype.simplify=function(){return this},t.prototype.elaborate=function(e,t,n,r,i,o){for(var s=0;s<this.names.length;++s){var u=void 0;if(this.names[s]instanceof a.LongIdentifierToken?void 0!==(u=e.getAndResolveStaticStructure(this.names[s]))&&(u=u.getStructure(this.names[s].id.getText())):u=e.getStaticStructure(this.names[s].getText()),void 0===u)throw new p.EvaluationError('Undefined module "'+this.names[s].getText()+'".');e.staticBasis.extend(u)}return[e,[],t,n]},t.prototype.evaluate=function(e,t){for(var n=e.state,r=0;r<this.names.length;++r){var i=void 0;if(this.names[r]instanceof a.LongIdentifierToken?void 0!==(i=n.getAndResolveDynamicStructure(this.names[r]))&&(i=i.getStructure(this.names[r].id.getText())):i=n.getDynamicStructure(this.names[r].getText()),void 0===i)throw new p.EvaluationError('Undefined module "'+this.names[r].getText()+'".');n.dynamicBasis.extend(i)}return{newState:n,value:void 0,hasThrown:!1}},t.prototype.toString=function(){for(var e="open",t=0;t<this.names.length;++t)e+=" "+this.names[t].getText();return e+";"},t}(h);t.OpenDeclaration=w;var g=function(e){function t(t){void 0===t&&(t=0);var n=e.call(this)||this;return n.id=t,n}return i(t,e),t.prototype.simplify=function(){return this},t.prototype.elaborate=function(e,t,n,r,i,o){return[e,[],t,n]},t.prototype.evaluate=function(e,t){return{newState:e.state,value:void 0,hasThrown:!1}},t.prototype.toString=function(){return" ;"},t}(h);t.EmptyDeclaration=g;var T=function(e){function t(t,n){void 0===n&&(n=0);var r=e.call(this)||this;return r.declarations=t,r.id=n,r}return i(t,e),t.prototype.assertUniqueBinding=function(e,t){for(var n=0;n<this.declarations.length;++n)this.declarations[n].assertUniqueBinding(e,t);return new Set},t.prototype.simplify=function(){for(var e=[],n=0;n<this.declarations.length;++n)e.push(this.declarations[n].simplify());return new t(e,this.id)},t.prototype.elaborate=function(e,t,n,r,i,o){for(var a=[],s=t,u=n,c=function(n){i&&(s=new Map,e.getTypeVariableBinds()[1].forEach((function(e,t){s=s.set(t,e)})),r=new Map);var c=h.declarations[n].elaborate(e.getNestedState(h.declarations[n].id),s,u,r,i,o);e=c[0],a=a.concat(c[1]),s=c[2];var f=new Map;if(i&&(f=t),c[2].forEach((function(t,n){if("~"===n[1]){var r=t[0].instantiate(e,c[2]).normalize(e.freeTypeVariables[0],o);e.parent.getTypeVariableBinds()[1].has(n)||a.push(new p.Warning(0,'The free type variable "'+n+'" has been instantiated to "'+r[0]+'".\n')),f=f.set(n,[r[0],!0])}else i||(f=f.set(n,t))})),s=f,i)for(var l in e.freeTypeVariables[1]=f,e.staticBasis.valueEnvironment)if(e.staticBasis.valueEnvironment.hasOwnProperty(l)){var d=e.staticBasis.valueEnvironment[l],y=d[0].normalize(e.freeTypeVariables[0],o);e.freeTypeVariables[0]=y[1],e.setStaticValue(l,y[0],d[1])}u=c[3]},h=this,f=0;f<this.declarations.length;++f)c(f);if(!i){var l=new Map,d=new Map,y=new Set;s.forEach((function(e,t){d=l.set(t,e)})),s.forEach((function(t,n){if(!y.has(n)&&(l=l.set(n,t),n.startsWith("@"))){var r=n.substr(1);if(y=y.add(r),d.has(r)){var i=d.get(r);try{var o=i[0].merge(e,d,t[0]);l=l.set(r,[o[0],i[1]||t[1]])}catch(e){if(!(e instanceof Array))throw e;throw new p.ElaborationError('Cannot merge "'+i[0].normalize()[0]+'" and "'+t[0].normalize()[0]+'" :'+e[0]+".")}}else l=l.set(r,t)}})),s=l}return[e,a,s,u]},t.prototype.evaluate=function(e,t){var n=e.state;void 0===e.step&&(e.step=-1);var r=e.step;if(r>=0){var i=e.recResult;if(void 0===i||void 0===i.newState)throw new p.InternalInterpreterError("How is this undefined?");if(i.hasThrown)return{newState:i.newState,value:i.value,hasThrown:!0};n=i.newState}if(++r<this.declarations.length){var o=n.getNestedState(this.declarations[r].id);return e.step=r,e.state=n,t.push({next:this,params:e}),void t.push({next:this.declarations[r],params:{state:o,modifiable:e.modifiable,recResult:void 0}})}return{newState:n,value:void 0,hasThrown:!1}},t.prototype.toString=function(){for(var e="",t=0;t<this.declarations.length;++t)t>0&&(e+=" "),e+=this.declarations[t];return e},t}(h);t.SequentialDeclaration=T;var E=function(e){function t(t,n,r){void 0===r&&(r=0);var i=e.call(this)||this;return i.typeVariableSequence=t,i.functionValueBinding=n,i.id=r,i}return i(t,e),t.prototype.simplify=function(){for(var e=[],t=0;t<this.functionValueBinding.length;++t)e.push(this.functionValueBinding[t].simplify());return new f(this.typeVariableSequence,e,this.id)},t}(h);t.FunctionDeclaration=E;var x=function(e){function t(t){var n=e.call(this)||this;return n.expression=t,n}return i(t,e),t.prototype.simplify=function(){return new f([],[new b(!1,new o.Tuple([]),this.expression)]).simplify()},t}(h);t.Evaluation=x;var S=function(e){function t(t,n,r,i){void 0===i&&(i=0);var o=e.call(this)||this;if(o.datatypeBinding=t,o.typeBinding=n,o.declaration=r,o.id=i,void 0!==o.typeBinding)throw new p.FeatureDisabledError('Who is "withtype"?');return o}return i(t,e),t.prototype.simplify=function(){for(var e=new d(this.datatypeBinding,void 0,this.id),t=[],n=0;n<this.datatypeBinding.length;++n)t.push(new L(this.datatypeBinding[n].typeVariableSequence,this.datatypeBinding[n].name,new s.CustomType(this.datatypeBinding[n].name.getText(),this.datatypeBinding[n].typeVariableSequence)));var r=new l(t,this.id);return new m(e,new T([r,this.declaration],this.id),this.id).simplify()},t}(h);t.AbstypeDeclaration=S;var I=function(e){function t(t,n,r){void 0===n&&(n=0),void 0===r&&(r=0);var i=e.call(this)||this;return i.operators=t,i.precedence=n,i.id=r,i}return i(t,e),t.prototype.simplify=function(){return this},t.prototype.elaborate=function(e,t,n,r){return[e,[],t,n]},t.prototype.setInfixStatus=function(e){for(var t=0;t<this.operators.length;++t)e.setInfixStatus(this.operators[t],this.precedence,!1,!0)},t.prototype.evaluate=function(e,t){var n=e.state;return this.setInfixStatus(n),{newState:n,value:void 0,hasThrown:!1}},t.prototype.toString=function(){var e="infix";e+=" "+this.precedence;for(var t=0;t<this.operators.length;++t)e+=" "+this.operators[t].getText();return e+";"},t}(h);t.InfixDeclaration=I;var V=function(e){function t(t,n,r){void 0===n&&(n=0),void 0===r&&(r=0);var i=e.call(this)||this;return i.operators=t,i.precedence=n,i.id=r,i}return i(t,e),t.prototype.simplify=function(){return this},t.prototype.elaborate=function(e,t,n,r){return[e,[],t,n]},t.prototype.setInfixStatus=function(e){for(var t=0;t<this.operators.length;++t)e.setInfixStatus(this.operators[t],this.precedence,!0,!0)},t.prototype.evaluate=function(e,t){var n=e.state;return this.setInfixStatus(n),{newState:n,value:void 0,hasThrown:!1}},t.prototype.toString=function(){var e="infixr";e+=" "+this.precedence;for(var t=0;t<this.operators.length;++t)e+=" "+this.operators[t].getText();return e+";"},t}(h);t.InfixRDeclaration=V;var k=function(e){function t(t,n){void 0===n&&(n=0);var r=e.call(this)||this;return r.operators=t,r.id=n,r}return i(t,e),t.prototype.simplify=function(){return this},t.prototype.elaborate=function(e,t,n,r){return[e,[],t,n]},t.prototype.setInfixStatus=function(e){for(var t=0;t<this.operators.length;++t)e.setInfixStatus(this.operators[t],0,!1,!1)},t.prototype.evaluate=function(e,t){var n=e.state;return this.setInfixStatus(n),{newState:n,value:void 0,hasThrown:!1}},t.prototype.toString=function(){for(var e="nonfix",t=0;t<this.operators.length;++t)e+=" "+this.operators[t].getText();return e+";"},t}(h);t.NonfixDeclaration=k;var b=function(){function e(e,t,n){this.isRecursive=e,this.pattern=t,this.expression=n}return e.prototype.toString=function(){var e="";return this.isRecursive&&(e+="rec "),e+=this.pattern,(e+=" = ")+this.expression},e.prototype.getType=function(e,t,n,r,i,a){var u=t.getNestedState(t.id),c=n,h=this.expression.getType(u,c,r,new Set,!1,i),f=h[1],l=this.pattern.matchType(u,h[4],h[0]);try{for(var d=new o.Match([[this.pattern,this.expression]]).checkExhaustiveness(t),y=[],v=new Set,m=0,w=d;m<w.length;m++){var g=w[m];v.has(g.message)||(v.add(g.message),y.push(new p.Warning(-1===g.type?-1:0,g.message)))}f=f.concat(y)}catch(e){}var T=new Set;if(void 0===l)throw new p.ElaborationError('Type clash. An expression of type "'+h[0]+'" cannot be assigned to "'+l[1]+'".');for(var E=[],x=new Set,S=0;S<e.length;++S){if(x.has(e[S].name))throw new p.ElaborationError('I will not let a duplicate type variable name "'+e[S].name+'" disturb my Happy Sugar Life.');x=x.add(e[S].name);var I=e[S].instantiate(t,l[2]);if(!(I instanceof s.TypeVariable)||I.domain.length>0||e[S].admitsEquality(t)!==I.admitsEquality(t))throw new p.ElaborationError('Type clash. An expression of explicit type "'+e[S]+'" cannot have type "'+I.normalize()[0]+'".');E.push(I)}this.expression.getExplicitTypeVariables().forEach((function(e){var n=e.instantiate(t,l[2]);if(!(n instanceof s.TypeVariable)||n.domain.length>0||e.admitsEquality(t)!==n.admitsEquality(t))throw new p.ElaborationError('Type clash. An expression of explicit type "'+e+'" cannot have type "'+n.normalize()[0]+'".')}));var V=!this.isRecursive&&!this.expression.isSafe(t),k=!1,b=function(e){if("="===l[0][e][0])throw new p.ElaborationError("All declarations are equal, but some declarations are more equal than others.");l[0][e][1]=l[0][e][1].instantiate(t,l[2]),a||(i=i.set(l[0][e][0],l[0][e][1]));for(var n=l[0][e][1].getTypeVariables(),r=l[0][e][1].getTypeVariables(!0),o=new Set,u=E.length-1;u>=0;--u)if(n.has(E[u].name)){var c=n.get(E[u].name);l[2].has("$"+E[u].name)&&(c=s.TypeVariable.mergeDomain(c,l[2].get("$"+E[u].name)[0].domain)),l[0][e][1]=new s.TypeVariableBind(E[u].name,l[0][e][1],c),l[0][e][1].isFree=0===l[0][e][1].domain.length&&(V||r.has(E[u].name)),k=k||l[0][e][1].isFree,o.add(E[u].name)}E=[],l[0][e][1].getTypeVariables().forEach((function(e,t){if((a||!T.has(t))&&!o.has(t)){var n=e;l[2].has("$"+t)&&(n=s.TypeVariable.mergeDomain(n,l[2].get("$"+t)[0].domain)),E.push(new s.TypeVariable(t,n))}}));for(u=E.length-1;u>=0;--u)l[0][e][1]=new s.TypeVariableBind(E[u].name,l[0][e][1],E[u].domain),l[0][e][1].isFree=0===l[0][e][1].domain.length&&(V||r.has(E[u].name)),k=k||l[0][e][1].isFree};for(S=0;S<l[0].length;++S)b(S);return k&&a&&f.push(new p.Warning(0,"Free type variables at top level.\n")),[l[0],f,l[2],h[2],h[5]]},e}();t.ValueBinding=b;var A=function(){function e(e,t){this.parameters=e,this.name=t}return e.prototype.simplify=function(){if(void 0===this.name)throw new p.InternalInterpreterError("This function isn't ready to be simplified yet.");for(var e,t=[],n=[],r=0;r<this.parameters[0][0].length;++r)t.push(new o.ValueIdentifier(new a.IdentifierToken("__arg"+r)));for(r=0;r<this.parameters.length;++r){var i=void 0;i=1===this.parameters[r][0].length?this.parameters[r][0][0]:new o.Tuple(this.parameters[r][0]),void 0===this.parameters[r][1]?n.push([i,this.parameters[r][2]]):n.push([i,new o.TypedExpression(this.parameters[r][2],this.parameters[r][1])])}e=1!==t.length?new o.Tuple(t).simplify():t[0];var s,u=new o.Match(n);s=new o.CaseAnalysis(e,u);for(r=this.parameters[0][0].length-1;r>=0;--r)s=new o.Lambda(new o.Match([[new o.ValueIdentifier(new a.IdentifierToken("__arg"+r)),s]]));return new b(!0,this.name,s.simplify())},e.prototype.toString=function(){for(var e="",t=0;t<this.parameters.length;++t){t>0&&(e+=" | "),e+=this.name.name.getText();for(var n=0;n<this.parameters[t][0].length;++n)e+=" "+this.parameters[t][0][n];void 0!==this.parameters[t][1]&&(e+=": "+this.parameters[t][1]),e+=" = "+this.parameters[t][2]}return e},e}();t.FunctionValueBinding=A;var L=function(e,t,n){this.typeVariableSequence=e,this.name=t,this.type=n};t.TypeBinding=L;var R=function(){function e(e,t,n,r){void 0===r&&(r={}),this.typeVariableSequence=e,this.name=t,this.type=n,this.givenIds=r}return e.prototype.getType=function(e,t,n){var r=[],i=[],o=e.getNestedState(e.id),a=e.getValueIdentifierId(this.name.getText());o.incrementValueIdentifierId(this.name.getText());var u=new s.CustomType(this.name.getText(),this.typeVariableSequence,void 0,!1,0),c=new s.CustomType(this.name.getText(),this.typeVariableSequence,void 0,!1,a);o.setStaticType(this.name.getText(),c,[],this.typeVariableSequence.length,!0);for(var h=function(e){var t=c;if(void 0!==f.type[e][1]){var n=f.type[e][1].replace(u,c);t=new s.FunctionType(n,t)}for(var o=new Set,a=0;a<f.typeVariableSequence.length;++a){if(o.has(f.typeVariableSequence[a].name))throw new p.ElaborationError("I'm not interested in duplicate type variable names such as \""+f.typeVariableSequence[a]+'".');o=o.add(f.typeVariableSequence[a].name)}var h=[];if(t.getTypeVariables().forEach((function(e,n){o.has(n)?t=new s.TypeVariableBind(n,t,e):h.push(n)})),h.length>0)throw p.ElaborationError.getUnguarded(h);i.push([f.type[e][0].getText(),t]),r.push(f.type[e][0].getText())},f=this,l=0;l<this.type.length;++l)h(l);return[i,c,[this.name.getText(),r]]},e.prototype.compute=function(e,t){for(var n=[],r=[],i=0;i<this.type.length;++i){var o=0;void 0!==this.type[i][1]&&(o=1);var a=-1;void 0===this.givenIds[this.type[i][0].getText()]?(a=t.getValueIdentifierId(this.type[i][0].getText()),t.incrementValueIdentifierId(this.type[i][0].getText()),this.givenIds[this.type[i][0].getText()]=a):a=this.givenIds[this.type[i][0].getText()],r.push([this.type[i][0].getText(),new c.ValueConstructor(this.type[i][0].getText(),o,a)]),n.push(this.type[i][0].getText())}return[r,[this.name.getText(),n]]},e}();t.DatatypeBinding=R;var B=function(){function e(e,t){this.name=e,this.type=t}return e.prototype.elaborate=function(e,t,n,r){if(void 0!==this.type){var i=this.type.simplify().instantiate(e,new Map),o=[];if(i.getTypeVariables().forEach((function(e,t){o.push(t)})),t&&o.length>0)throw p.ElaborationError.getUnguarded(o);e.setStaticValue(this.name.getText(),new s.FunctionType(i.makeFree(),new s.CustomType("exn")),u.IdentifierStatus.EXCEPTION_CONSTRUCTOR)}else e.setStaticValue(this.name.getText(),new s.CustomType("exn"),u.IdentifierStatus.EXCEPTION_CONSTRUCTOR);return e},e.prototype.evaluate=function(e,t){var n=0;void 0!==this.type&&(n=1);var r=e.getValueIdentifierId(this.name.getText());e.incrementValueIdentifierId(this.name.getText());var i=t.getNextExceptionEvalId();if(!u.State.allowsRebind(this.name.getText()))throw new p.EvaluationError('You simply cannot rebind "'+this.name.getText()+'".');e.setDynamicValue(this.name.getText(),new c.ExceptionConstructor(this.name.getText(),n,r,i),u.IdentifierStatus.EXCEPTION_CONSTRUCTOR)},e}();t.DirectExceptionBinding=B;var C=function(){function e(e,t){this.name=e,this.oldname=t}return e.prototype.elaborate=function(e,t,n,r){void 0===n&&(n=new Set);var i=void 0;if(this.oldname instanceof a.LongIdentifierToken){var o=e.getAndResolveStaticStructure(this.oldname);void 0!==o&&(i=o.getValue(this.oldname.id.getText()))}else i=e.getStaticValue(this.oldname.getText());if(void 0===i)throw new p.ElaborationError('Unbound value identifier "'+this.oldname.getText()+'".');if(i[1]!==u.IdentifierStatus.EXCEPTION_CONSTRUCTOR)throw new p.ElaborationError('You cannot transform "'+i[0]+'" into an exception.');return e.setStaticValue(this.name.getText(),i[0].normalize()[0],u.IdentifierStatus.EXCEPTION_CONSTRUCTOR),e},e.prototype.evaluate=function(e,t){var n=void 0;if(this.oldname instanceof a.LongIdentifierToken){var r=e.getAndResolveDynamicStructure(this.oldname);void 0!==r&&(n=r.getValue(this.oldname.id.getText()))}else n=e.getDynamicValue(this.oldname.getText());if(void 0===n)throw new p.EvaluationError('Unbound value identifier "'+this.oldname.getText()+'".');if(n[1]!==u.IdentifierStatus.EXCEPTION_CONSTRUCTOR)throw new p.EvaluationError('You cannot transform "'+n[0].toString(e,40)+'" into an exception.');e.setDynamicValue(this.name.getText(),n[0],u.IdentifierStatus.EXCEPTION_CONSTRUCTOR)},e}();t.ExceptionAlias=C},function(e,t,n){"use strict";var r,i=this&&this.__extends||(r=function(e,t){return(r=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)t.hasOwnProperty(n)&&(e[n]=t[n])})(e,t)},function(e,t){function n(){this.constructor=e}r(e,t),e.prototype=null===t?Object.create(t):(n.prototype=t.prototype,new n)});Object.defineProperty(t,"__esModule",{value:!0});var o=n(1),a=n(6),s=n(5),u=n(3),p=n(0),c=n(2),h=function(){function e(){}return e.prototype.getType=function(e,t,n,r,i,o){throw void 0===t&&(t=new Map),void 0===n&&(n="'*t0"),void 0===r&&(r=new Set),void 0===i&&(i=!1),void 0===o&&(o=new Map),new p.InternalInterpreterError('Called "getType" on a derived form.')},e.prototype.compute=function(e,t){throw new p.InternalInterpreterError('Called "getValue" on a derived form.')},e.prototype.isSafe=function(e){return!0},e.prototype.getExplicitTypeVariables=function(){return new Set},e.prototype.toString=function(){throw new p.InternalInterpreterError("You humans can't seem to write bug-free code. What an inferior species.")},e.prototype.assertUniqueBinding=function(e,t){return new Set},e}();t.Expression=h;var f=function(e){function t(t){var n=e.call(this)||this;return n.token=t,n}return i(t,e),t.prototype.matchType=function(e,t,n){return[[],this.getType(e,t)[0],t]},t.prototype.subsumes=function(e,n){for(;n instanceof v;)n=n.expression;return n instanceof t&&this.toString()===n.toString()},t.prototype.cover=function(e,t){throw new p.InternalInterpreterError("一昨日来やがれ。")},t.prototype.matches=function(e,t){var n=this.compute({state:e,modifiable:e,recResult:void 0},[]);if(void 0===n||void 0===n.value)throw new p.InternalInterpreterError("Right now, I'm the happiest interpreter in the world!");return n.value.equals(t)?[]:void 0},t.prototype.getType=function(e,t,n,r,i,a){if(void 0===t&&(t=new Map),void 0===n&&(n="'*t0"),void 0===r&&(r=new Set),void 0===i&&(i=!1),void 0===a&&(a=new Map),this.token instanceof s.IntegerConstantToken||this.token instanceof s.NumericToken)return[new o.CustomType("int"),[],n,r,t,e.valueIdentifierId];if(this.token instanceof s.RealConstantToken)return[new o.CustomType("real"),[],n,r,t,e.valueIdentifierId];if(this.token instanceof s.WordConstantToken)return[new o.CustomType("word"),[],n,r,t,e.valueIdentifierId];if(this.token instanceof s.CharacterConstantToken)return[new o.CustomType("char"),[],n,r,t,e.valueIdentifierId];if(this.token instanceof s.StringConstantToken)return[new o.CustomType("string"),[],n,r,t,e.valueIdentifierId];throw new p.InternalInterpreterError('"'+this+'" does not seem to be a valid constant.')},t.prototype.simplify=function(){return this},t.prototype.toString=function(){return this.token.getText()},t.prototype.compute=function(e,t){var n=void 0;if(this.token instanceof s.IntegerConstantToken||this.token instanceof s.NumericToken?n=new c.Integer(this.token.value):this.token instanceof s.RealConstantToken?n=new c.Real(this.token.value):this.token instanceof s.WordConstantToken?n=new c.Word(this.token.value):this.token instanceof s.CharacterConstantToken?n=new c.CharValue(this.token.value):this.token instanceof s.StringConstantToken&&(n=new c.StringValue(this.token.value)),void 0===n)throw new p.EvaluationError("You sure that this is a constant?");return{newState:void 0,value:n,hasThrown:!1}},t}(h);t.Constant=f;var l=function(e){function t(t){var n=e.call(this)||this;return n.name=t,n}return i(t,e),t.prototype.getConstructorName=function(e){var t=this.name.getText(),n=e.getStaticValue(t);if(void 0!==n&&n[1]!==u.IdentifierStatus.VALUE_VARIABLE)return t},t.prototype.getConstructorList=function(e){var t=this.name.getText(),n=e.getStaticValue(t);if(void 0!==n&&n[1]!==u.IdentifierStatus.VALUE_VARIABLE){if(n[1]===u.IdentifierStatus.VALUE_CONSTRUCTOR){for(var r=n[0];r instanceof o.TypeVariableBind;)r=r.type;if(r instanceof o.FunctionType&&(r=r.returnType),!(r instanceof o.CustomType))return;var i=r.name,a=e.getStaticType(i);if(void 0===a)return;return a.constructors}return["__exn"]}},t.prototype.getType=function(e,t,n,r,i,a){void 0===t&&(t=new Map),void 0===n&&(n="'*t0"),void 0===r&&(r=new Set),void 0===i&&(i=!1),void 0===a&&(a=new Map);var c=void 0;if(this.name instanceof s.LongIdentifierToken){var h=e.getAndResolveStaticStructure(this.name);if(void 0!==h&&void 0!==(c=h.getValue(this.name.id.getText()))){var f=new u.State(0,void 0,h,e.dynamicBasis,[0,{}],4);c=[c[0].qualify(f,this.name),c[1]]}}else{var l=a.get(this.name.getText());c=void 0!==l?[l,u.IdentifierStatus.VALUE_VARIABLE]:e.getStaticValue(this.name.getText())}if(void 0===c)throw new p.ElaborationError('Unbound value identifier "'+this.name.getText()+'".');for(var d=new Set,y=new Set,v=new Map;c[0]instanceof o.TypeVariableBind;)c[0].isFree?(y=y.add(c[0].name),v=v.set(c[0].name,c[0].name)):d=d.add(c[0].name),c[0]=c[0].type;d=d.add("*");var m=[];d.forEach((function(i){var a=n=o.TypeVariable.getUnusedTypeVariableName(e,n,r,t,d);"'"===i[1]&&(a="'"+a),m.push(a),v=v.set(i,a)}));for(var w=0;w<m.length;++w)r=r.add(m[w]);return[c[0].replaceTypeVariables(v,y).instantiate(e,t),[],n,r,t,e.valueIdentifierId]},t.prototype.matchType=function(e,t,n){if(this.name instanceof s.LongIdentifierToken)throw new p.ElaborationError("Variable names in patterns cannot be qualified.");var r=e.getStaticValue(this.name.getText());if(void 0===r||r[1]===u.IdentifierStatus.VALUE_VARIABLE)return[[[this.name.getText(),n.instantiate(e,t)]],n.instantiate(e,t),t];var i=this.getType(e,t,"'*g0");i[3].forEach((function(e){var t="'*p"+e.substring(3);"'"===e[1]&&(t="''*p"+e.substring(4)),i[4]=i[4].set(e,[new o.TypeVariable(t),!1])})),r[0]=i[0],t=i[4];try{var a=n.merge(e,t,r[0]);return[[],a[0],a[1]]}catch(e){if(!(e instanceof Array))throw e;throw new p.ElaborationError('Type clash: "'+n.normalize()[0]+'" vs. "'+r[0].normalize()[0]+'": '+e[0])}},t.prototype.subsumes=function(e,n){for(;n instanceof v;)n=n.expression;var r=this.getConstructorName(e);return void 0===r||n instanceof t&&r===n.getConstructorName(e)},t.prototype.cover=function(e,t){return[]},t.prototype.matches=function(e,t){var n=void 0;if(this.name instanceof s.LongIdentifierToken){var r=e.getAndResolveDynamicStructure(this.name);void 0!==r&&(n=r.getValue(this.name.id.getText()))}else n=e.getDynamicValue(this.name.getText());if(void 0===n||n[1]===u.IdentifierStatus.VALUE_VARIABLE)return[[this.name.getText(),t]];try{if(t.equals(n[0]))return[]}catch(e){return[[this.name.getText(),t]]}},t.prototype.simplify=function(){return this},t.prototype.toString=function(){return this.name.getText()},t.prototype.compute=function(e,t){var n=e.state,r=void 0;if(this.name instanceof s.LongIdentifierToken){var i=n.getAndResolveDynamicStructure(this.name);void 0!==i&&(r=i.getValue(this.name.id.getText()))}else r=n.getDynamicValue(this.name.getText());if(void 0===r)throw new p.EvaluationError('Unbound value identifier "'+this.name.getText()+'".');return r[1]===u.IdentifierStatus.VALUE_CONSTRUCTOR&&0===r[0].numArgs?{newState:void 0,value:r[0].construct(),hasThrown:!1}:r[1]===u.IdentifierStatus.EXCEPTION_CONSTRUCTOR&&0===r[0].numArgs?{newState:void 0,value:r[0].construct(),hasThrown:!1}:{newState:void 0,value:r[0],hasThrown:!1}},t.prototype.assertUniqueBinding=function(e,t){if(t.has(this.name.getText()))return new Set;var n=e.getStaticValue(this.name.getText());if(void 0!==n&&n[1]!==u.IdentifierStatus.VALUE_VARIABLE)return new Set;var r=e.getDynamicValue(this.name.getText());return void 0!==r&&r[1]!==u.IdentifierStatus.VALUE_VARIABLE?new Set:(new Set).add(this.name.getText())},t}(h);t.ValueIdentifier=l;var d=function(e){function t(t,n){var r=e.call(this)||this;r.complete=t,r.entries=n,r.entries.sort();for(var i=1;i<r.entries.length;++i)if(r.entries[i][0]===r.entries[i-1][0])throw new p.ElaborationError('Label "'+r.entries[i][0]+'" occurs more than once in the same record.');return r}return i(t,e),t.prototype.hasConstant=function(){for(var e=0,n=this.entries;e<n.length;e++){var r=n[e];if(r instanceof f)return!0;if(r instanceof t&&r.hasConstant())return!0}return!1},t.prototype.subsumes=function(e,n){for(;n instanceof v;)n=n.expression;if(!(n instanceof t))return!1;for(var r=0,i=0;r<this.entries.length||i<n.entries.length;){var o=r<this.entries.length?this.entries[r]:void 0,a=i<n.entries.length?n.entries[i]:void 0;if(void 0===a||void 0!==o&&o[0]<a[0]){if(void 0===o)break;if(o[1].subsumes(e,new x)){++r;continue}return!1}if(void 0!==o&&void 0!==a&&o[0]===a[0]){if(o[1].subsumes(e,a[1])){++r,++i;continue}return!1}if(void 0===o||void 0!==a&&o[0]>a[0]){if(void 0===a)break;if((new x).subsumes(e,a[1])){++i;continue}return!1}}return!0},t.prototype.getExplicitTypeVariables=function(){for(var e=new Set,t=0;t<this.entries.length;++t)this.entries[t][1].getExplicitTypeVariables().forEach((function(t){e=e.add(t)}));return e},t.prototype.hasEntry=function(e){for(var t=0;t<this.entries.length;++t)if(this.entries[t][0]===e)return!0;return!1},t.prototype.getEntry=function(e){for(var t=0;t<this.entries.length;++t)if(this.entries[t][0]===e)return this.entries[t][1];throw new p.InternalInterpreterError('Yeah, "'+e+'" would be nice to have.')},t.prototype.isSafe=function(e){for(var t=0;t<this.entries.length;++t)if(!this.entries[t][1].isSafe(e))return!1;return!0},t.prototype.matchType=function(e,t,n){if(n instanceof o.RecordType||(n=n.instantiate(e,t)),n instanceof o.TypeVariable||n instanceof o.RecordType&&!n.complete){var r=new Map,i="",a=!1;if(n instanceof o.TypeVariable)i=n.name,a=n.isFree;else{if(!(n instanceof o.RecordType&&void 0!==n.sourceTyVar))throw new p.InternalInterpreterError("An incomplete record type just died.");if(i=n.sourceTyVar,!t.has(i))throw new p.InternalInterpreterError("An incomplete record type just died.");a=t.get(i)[1]}for(var s=0;s<this.entries.length;++s){var u=new o.TypeVariable(i+"*"+this.entries[s][0]);u.isFree=a,r=r.set(this.entries[s][0],u)}var c=new o.RecordType(r,this.complete,this.complete?void 0:i);if(t.has("@"+i)){var h=t.get("@"+i);try{var f=h[0].merge(e,t,c);t=t.set("@"+i,[f[0],a]),this.complete&&(t=t.set(i,[f[0],a]))}catch(e){if(!(e instanceof Array))throw e;throw new p.ElaborationError('Type mismatch "'+h[0].normalize()[0]+'" vs. "'+c.normalize()[0]+'": '+e[0])}}else t=t.set("@"+i,[c,a]);n=c}if(!(n instanceof o.RecordType))throw new p.ElaborationError('Expected pattern of a record type, got "'+n.typeName()+'".');if(this.complete&&n.complete&&this.entries.length!==n.elements.size)throw new p.ElaborationError("Expected a record type with "+this.entries.length+" entries, but the given record has "+n.elements.size+" entries.");var l=[],d=new Map,y=t,v=new Set;for(s=0;s<this.entries.length;++s){if(v=v.add(this.entries[s][0]),!n.hasType(this.entries[s][0])){if(n.complete)throw new p.ElaborationError('Record is missing entry "'+this.entries[s][0]+'".');n.setType(this.entries[s][0],new o.TypeVariable("*z"+s+"*"+n.toString().length+"*"))}var m=this.entries[s][1].matchType(e,y,n.getType(this.entries[s][0]));l=l.concat(m[0]),d=d.set(this.entries[s][0],m[1]),y=m[2]}var w=new o.RecordType(d,this.complete||n.complete);try{return[l,(f=w.merge(e,y,n))[0],f[1]]}catch(e){if(!(e instanceof Array))throw e;throw new p.ElaborationError('Type mismatch "'+n.normalize()[0]+'" vs. "'+w.normalize()[0]+'": '+e[0])}},t.prototype.cover=function(e,n){if(0===this.entries.length)return 0===n.length?[new p.Warning(-1,"Pattern matching is not exhaustive.\n")]:[];for(var r=this.entries[0][0],i=[],o=new Map,a=new x,s=[],u=!1,c=[],h=[],d=[],y=[],v=[],w=void 0,g=new Set,T=function(n){if(void 0!==w)return v.push(new p.Warning(0,'Rules after "'+w+'" unused in pattern matching.\n')),"break";if(!(n instanceof t))throw new p.InternalInterpreterError("Pipiru piru piru pipiru pii!");n.subsumes(e,E)&&(w=n.toString());for(var T=[],S=void 0,I=0,V=n.entries;I<V.length;I++){var k=V[I];k[0]===r?(S=k[1])instanceof m&&T.push([k[0],S.argument]):T.push(k)}if(void 0===S&&(S=a),S instanceof l)if(void 0===S.getConstructorName(e))S=a;else if(0===c.length){if(void 0===(_=S.getConstructorList(e)))throw new p.InternalInterpreterError("Pipiru piru piru pipiru pii!");c=_}if(i.push(S),S instanceof t){if(S.hasConstant())return"continue";var b=[];y.push([!1,!1]);for(var A=0;A<h.length;++A){var L=S.subsumes(e,h[A]),R=h[A].subsumes(e,S);if(L)y[A][0]=!0,y[h.length][1]=!0,(B=o.get(A+"")).push(new t(n.complete,T)),o=o.set(A+"",B);R&&(y[A][1]=!0,y[h.length][0]=!0,b.push(new t(n.complete,d[A])))}return b.push(new t(n.complete,T)),o=o.set(h.length+"",s.concat(b)),h.push(S),d.push(T),"continue"}var B,C=!1,O=S.toString();if(S instanceof m){C=!0;var N=S.func;if(!(N instanceof l))throw new p.InternalInterpreterError("There. Just another unfortunate accident.");if(O=N.name.getText(),0===c.length){var _;if(void 0===(_=N.getConstructorList(e)))throw new p.InternalInterpreterError("Pipiru piru piru pipiru pii!");c=_}}if(O+=S.constructor.name,C&&(g=g.add(O)),S instanceof f)return u=!0,"continue";if(S instanceof x){s.push(new t(n.complete,T));var P=new Map;return o.forEach((function(e,r){e.push(new t(n.complete,T)),P=P.set(r,e)})),o=P,"continue"}o.has(O)?((B=o.get(O)).push(new t(n.complete,T)),o=o.set(O,B)):o=o.set(O,s.concat([new t(n.complete,T)]))},E=this,S=0,I=n;S<I.length;S++){if("break"===T(I[S]))break}v=v.concat(a.cover(e,i).filter((function(e){return-1===e.type})));for(var V=[],k=1;k<this.entries.length;++k)V.push(this.entries[k]);var b=new t(!0,V),A=[];A.push([this.entries[0][0],new x]);for(k=1;k<this.entries.length;++k)A.push(this.entries[k]);var L=new t(!0,A);return o.forEach((function(n,i){if(g.has(i)){for(var o=[],a=0,s=n;a<s.length;a++){var u=s[a];if(u instanceof t)if(u.hasEntry(r))o.push(u);else{var p=[];p.push([r,new x]);for(var c=0;c<u.entries.length;++c)p.push(u.entries[c]);o.push(new t(!0,p))}else o.push(u)}v=v.concat(L.cover(e,o).filter((function(e){return-1===e.type})))}else v=v.concat(b.cover(e,n).filter((function(e){return-1===e.type})))})),(u||0===o.size||o.size<c.length)&&(v=v.concat(b.cover(e,s))),v},t.prototype.matches=function(e,t){if(t instanceof c.RecordValue&&(!this.complete||this.entries.length===t.entries.size)){for(var n=[],r=0;r<this.entries.length;++r){if(!t.hasValue(this.entries[r][0]))return;var i=this.entries[r][1].matches(e,t.getValue(this.entries[r][0]));if(void 0===i)return i;for(var o=0;o<i.length;++o)n.push(i[o])}return n}},t.prototype.getType=function(e,t,n,r,i,a){void 0===t&&(t=new Map),void 0===n&&(n="'*t0"),void 0===r&&(r=new Set),void 0===i&&(i=!1),void 0===a&&(a=new Map);for(var s=new Map,c=[],h=t,f=0;f<this.entries.length;++f){var d=this.entries[f][0],y=this.entries[f][1];if(s.has(d))throw new p.ElaborationError('Label "'+d+'" occurs more than once in the same record.');if(y instanceof l&&i){var v=e.getStaticValue(y.name.getText());if(void 0!==v&&v[1]!==u.IdentifierStatus.VALUE_VARIABLE&&v[0]instanceof o.FunctionType)throw new p.ElaborationError("Unary constructor in the pattern needs an argument.")}var m=y.getType(e,h,n,r,i,a);c=c.concat(m[1]),n=m[2],r=m[3],m[4].forEach((function(e,t){h=h.set(t,e)})),e.valueIdentifierId=m[5],s=s.set(d,m[0])}return[new o.RecordType(s,this.complete),c,n,r,h,e.valueIdentifierId]},t.prototype.simplify=function(){for(var e=[],n=0;n<this.entries.length;++n){var r=this.entries[n];e.push([r[0],r[1].simplify()])}return new t(this.complete,e)},t.prototype.toString=function(){for(var e=1!==this.entries.length,t=0;t<this.entries.length;++t)this.entries[t][0]!==""+(t+1)&&(e=!1);var n="{";if(e){n="(";for(t=0;t<this.entries.length;++t)t>0&&(n+=", "),n+=this.entries[t][1].toString();return n+")"}var r=!0;for(t=0;t<this.entries.length;++t)r||(n+=", "),r=!1,n+=this.entries[t][0]+" = "+this.entries[t][1];return this.complete||(r||(n+=", "),n+="..."),n+"}"},t.prototype.compute=function(e,t){var n=e.state;void 0===e.step&&(e.step=-1,e.nentr=new Map);var r=e.nentr,i=e.step;if(i>=0){var o=e.recResult;if(void 0===o)throw new p.InternalInterpreterError("Namjala Latak");if(o.hasThrown)return{newState:void 0,value:o.value,hasThrown:!0};r=r.set(this.entries[i][0],o.value)}return++i<this.entries.length?(e.step=i,e.nentr=r,t.push({next:this,params:e}),void t.push({next:this.entries[i][1],params:{state:n,modifiable:e.modifiable,recResult:void 0}})):{newState:void 0,value:new c.RecordValue(r),hasThrown:!1}},t.prototype.assertUniqueBinding=function(e,t){for(var n=new Set,r=0;r<this.entries.length;++r){this.entries[r][1].assertUniqueBinding(e,t).forEach((function(e){if(n.has(e))throw new p.ParserError("Don't try to rebind \""+e+'" "'+e+'" in the same pattern... Sorry, I stuttered.');n=n.add(e)}))}return n},t}(h);t.Record=d;var y=function(e){function t(t,n){var r=e.call(this)||this;return r.declaration=t,r.expression=n,r}return i(t,e),t.prototype.simplify=function(){return new t(this.declaration.simplify(),this.expression.simplify())},t.prototype.toString=function(){var e="let "+this.declaration;return e+=" in "+this.expression+" end"},t.prototype.isSafe=function(e){return!1},t.prototype.getType=function(e,t,n,r,i,o){void 0===t&&(t=new Map),void 0===n&&(n="'*t0"),void 0===r&&(r=new Set),void 0===i&&(i=!1),void 0===o&&(o=new Map);var a=new Map;o.forEach((function(e,t){a=a.set(t,e)}));var s=e.getNestedState(e.id),u=this.declaration.elaborate(s,t,n,a,!1),p=this.expression.getType(u[0],u[2],u[3],r,i,a);return[p[0],u[1].concat(p[1]),p[2],p[3],p[4],p[5]]},t.prototype.compute=function(e,t){var n=e.state;void 0===e.step&&(e.step=-1);var r=e.step;if(-1===r){var i=n.getNestedState(0).getNestedState(n.id);return e.step=r+1,e.state=n,t.push({next:this,params:e}),void t.push({next:this.declaration,params:{state:i,modifiable:e.modifiable,recResult:void 0}})}if(0===r){var o=e.recResult;if(void 0===o||void 0===o.newState)throw new p.InternalInterpreterError("You see, even I sleep at night and wake up in the morning");i=o.newState;return o.hasThrown?{newState:void 0,value:o.value,hasThrown:!0}:void t.push({next:this.expression,params:{state:i,modifiable:e.modifiable,recResult:void 0}})}var a=e.recResult;if(void 0===a)throw new p.InternalInterpreterError('I just gave this "dying" a try...');return{newState:void 0,value:a.value,hasThrown:a.hasThrown}},t.prototype.assertUniqueBinding=function(e,t){return this.declaration.assertUniqueBinding(e,t),this.expression.assertUniqueBinding(e,t),new Set},t}(h);t.LocalDeclarationExpression=y;var v=function(e){function t(t,n){var r=e.call(this)||this;return r.expression=t,r.typeAnnotation=n,r}return i(t,e),t.prototype.getExplicitTypeVariables=function(){var e=new Set;return this.typeAnnotation.getTypeVariables().forEach((function(t,n){e=e.add(new o.TypeVariable(n,t))})),e},t.prototype.isSafe=function(e){return this.expression.isSafe(e)},t.prototype.matchType=function(e,t,n){var r=this.expression.matchType(e,t,n);try{var i=r[1].merge(e,r[2],this.typeAnnotation.instantiate(e,r[2]));return this.expression.matchType(e,i[1],i[0])}catch(e){if(!(e instanceof Array))throw e;throw new p.ElaborationError('The annotated type "'+this.typeAnnotation+'" does not match the expression\'s type "'+r[1].normalize()[0]+'": '+e[0])}},t.prototype.subsumes=function(e,t){return this.expression.subsumes(e,t)},t.prototype.cover=function(e,t){throw new p.InternalInterpreterError("一昨日来やがれ。")},t.prototype.matches=function(e,t){return this.expression.matches(e,t)},t.prototype.getType=function(e,t,n,r,i,o){void 0===t&&(t=new Map),void 0===n&&(n="'*t0"),void 0===r&&(r=new Set),void 0===i&&(i=!1),void 0===o&&(o=new Map);var a=this.expression.getType(e,t,n,r,i,o);try{var s=this.typeAnnotation.instantiate(e,a[4]),u=a[0].merge(e,a[4],s);return[u[0],a[1],a[2],a[3],u[1],a[5]]}catch(e){if(!(e instanceof Array))throw e;throw new p.ElaborationError('The specified type "'+this.typeAnnotation+'" does not match the annotated expression\'s type "'+a[0].normalize()[0]+'": '+e[0])}},t.prototype.simplify=function(){return new t(this.expression.simplify(),this.typeAnnotation.simplify())},t.prototype.toString=function(){var e="( "+this.expression;return(e+=": "+this.typeAnnotation)+" )"},t.prototype.compute=function(e,t){return this.expression.compute(e,t)},t.prototype.assertUniqueBinding=function(e,t){return this.expression.assertUniqueBinding(e,t)},t}(h);t.TypedExpression=v;var m=function(e){function t(t,n){var r=e.call(this)||this;return r.func=t,r.argument=n,r}return i(t,e),t.prototype.getExplicitTypeVariables=function(){var e=new Set;return this.func.getExplicitTypeVariables().forEach((function(t){e=e.add(t)})),this.argument.getExplicitTypeVariables().forEach((function(t){e=e.add(t)})),e},t.prototype.isSafe=function(e){if(!(this.func instanceof l))return!1;var t=e.getStaticValue(this.func.name.getText());return void 0!==t&&"ref"!==this.func.name.getText()&&t[1]!==u.IdentifierStatus.VALUE_VARIABLE},t.prototype.matchType=function(e,t,n){if(!(this.func instanceof l))throw new p.ElaborationError("Non-identifier applied to a pattern.");var r=e.getStaticValue(this.func.name.getText());if(void 0===r||r[1]===u.IdentifierStatus.VALUE_VARIABLE)throw new p.ElaborationError('Expected a constructor, "'+this.func.name.getText()+"\" isn't.");var i=this.func.getType(e,t,"'g0");if(i[3].forEach((function(e){var t="'p"+e.substring(2);"'"===e[1]&&(t="''p"+e.substring(3)),i[4]=i[4].set(e,[new o.TypeVariable(t),!1])})),r[0]=i[0],t=i[4],!(r[0]instanceof o.FunctionType))throw new p.ElaborationError("This is truly more...slothful.");try{var a=r[0],s=a.returnType.merge(e,t,n),c=this.argument.matchType(e,s[1],a.parameterType.instantiate(e,s[1]));return[c[0],s[0],c[2]]}catch(e){if(!(e instanceof Array))throw e;throw new p.ElaborationError("Merge failed: "+e[0])}},t.prototype.subsumes=function(e,n){for(;n instanceof v;)n=n.expression;return n instanceof t&&this.func.subsumes(e,n.func)},t.prototype.cover=function(e,n){return this.argument.cover(e,n.map((function(e){if(!(e instanceof t))throw new p.InternalInterpreterError("I received much data that did not compute.");return e.argument})))},t.prototype.matches=function(e,t){if(t instanceof c.FunctionValue)throw new p.EvaluationError("You simply cannot match function values.");if(t instanceof c.ConstructedValue)return this.func instanceof l&&this.func.name.getText()===t.constructorName&&"ref"!==this.func.name.getText()?void 0!==t.argument?this.argument.matches(e,t.argument):[]:void 0;if(t instanceof c.ExceptionValue){var n=void 0,r=void 0;if(this.func.name instanceof s.LongIdentifierToken){var i=e.getAndResolveDynamicStructure(this.func.name);void 0!==i&&(r=this.func.name.id.getText(),n=i.getValue(r))}else r=this.func.name.getText(),n=e.getDynamicValue(r);if(void 0===n)throw new p.InternalInterpreterError("How did you match something that does not exist?");var o=n[0];return this.func instanceof l&&o instanceof c.ExceptionConstructor&&r===t.constructorName&&o.id===t.id&&o.evalId===t.evalId?void 0!==t.argument?this.argument.matches(e,t.argument):[]:void 0}if(t instanceof c.PredefinedFunction)throw new p.EvaluationError("You simply cannot match predefined functions.");if(t instanceof c.ReferenceValue)return this.func instanceof l&&"ref"===this.func.name.getText()?this.argument.matches(e,e.getCell(t.address)):void 0;throw new p.EvaluationError("Help me, I'm broken. ("+t.typeName()+").")},t.prototype.getType=function(e,t,n,r,i,a){if(void 0===t&&(t=new Map),void 0===n&&(n="'*t0"),void 0===r&&(r=new Set),void 0===i&&(i=!1),void 0===a&&(a=new Map),i&&this.func instanceof l)if(this.func.name instanceof s.LongIdentifierToken){var c=e.getAndResolveStaticStructure(this.func.name);if(void 0===c||void 0===c.getValue(this.func.name.id.getText()))throw new p.ElaborationError('"'+this.func.name.getText()+'" is not a constructor.')}else{var h=e.getStaticValue(this.func.name.getText());if(void 0===h||h[1]===u.IdentifierStatus.VALUE_VARIABLE)throw new p.ElaborationError('"'+this.func.name.getText()+'" is not a constructor.')}var f=this.func.getType(e,t,n,r,i,a);e.valueIdentifierId=f[5],f[0]instanceof o.FunctionType&&f[0].returnType+""=="exn"&&(this.argument=new v(this.argument,f[0].parameterType));var d=new Map;f[4].forEach((function(e,t){d=d.set(t,e)}));var y=this.argument.getType(e,d,f[2],f[3],i,a);if(y[4].forEach((function(e,t){f[4]=f[4].set(t,e)})),f[0]=f[0].instantiate(e,f[4]),f[0]instanceof o.TypeVariable){var m=new o.TypeVariable(f[0].name+"*a"),w=new o.TypeVariable(f[0].name+"*b");m.isFree=f[0].isFree,w.isFree=f[0].isFree;var g=new o.FunctionType(m,w);f[4]=f[4].set(f[0].name,[g,f[0].isFree]),f[0]=g}if(f[0]instanceof o.AnyType&&(f[0]=new o.FunctionType(new o.AnyType,new o.AnyType)),!(f[0]instanceof o.FunctionType))throw new p.ElaborationError('"'+this.func+'" of type "'+f[0].normalize()[0]+'" is not a function.');try{var T=f[0].parameterType.merge(e,f[4],y[0]),E=f[0].returnType;return f[0].parameterType instanceof o.RecordType&&!f[0].parameterType.complete&&(E=E.replace(f[0].parameterType,T[0])),[E.instantiate(e,T[1]),f[1].concat(y[1]),y[2],y[3],T[1],y[5]]}catch(e){if(!(e instanceof Array))throw e;throw new p.ElaborationError('Type clash. Functions of type "'+f[0].normalize()[0]+'" cannot take an argument of type "'+y[0].normalize()[0]+'": '+e[0])}},t.prototype.simplify=function(){return new t(this.func.simplify(),this.argument.simplify())},t.prototype.toString=function(){var e="( "+this.func;return(e+=" "+this.argument)+" )"},t.prototype.compute=function(e,t){var n=e.state,r=e.modifiable;void 0===e.step&&(e.step=-1);var i=e.step;if(-1===i)return e.step=i+1,e.state=n,t.push({next:this,params:e}),void t.push({next:this.func,params:{state:n,modifiable:r,recResult:void 0}});if(0===i){if(void 0===(o=e.recResult))throw new p.InternalInterpreterError("So you see, squids are evil. I will eat them. I will eat them ALL.");return o.hasThrown?o:(e.step=i+1,e.state=n,e.funcVal=o,t.push({next:this,params:e}),void t.push({next:this.argument,params:{state:n,modifiable:r,recResult:void 0}}))}if(1===i){var o=e.funcVal,a=e.recResult;if(void 0===o||void 0===o.value)throw new p.InternalInterpreterError("I'm fabulous down to my very core, so praise me, human.");if(void 0===a||void 0===a.value)throw new p.InternalInterpreterError("I guess I really am trash, aren't I?");if(a.hasThrown)return{newState:void 0,value:a.value,hasThrown:!0};if(o.value instanceof c.FunctionValue)return void o.value.compute(t,a.value,r);if(o.value instanceof c.ValueConstructor)return{newState:void 0,value:o.value.construct(a.value),hasThrown:!1};if(o.value instanceof c.ExceptionConstructor)return{newState:void 0,value:o.value.construct(a.value),hasThrown:!1};if(o.value instanceof c.PredefinedFunction){for(var s,u=0,h=(s=o.value.apply(a.value,e))[2];u<h.length;u++){var f=h[u];r.addWarning(f)}return{newState:void 0,value:s[0],hasThrown:s[1]}}throw new p.EvaluationError('Cannot evaluate the function "'+this.func+'" ('+o[0].typeName()+").")}if(void 0===(s=e.recResult))throw new p.InternalInterpreterError("No! Stop! Hoshimaru, Stop!");return{newState:void 0,value:s.value,hasThrown:s.hasThrown}},t.prototype.assertUniqueBinding=function(e,t){var n=this.func.assertUniqueBinding(e,t),r=this.argument.assertUniqueBinding(e,t);return this.func instanceof l&&0===n.size?r:new Set},t}(h);t.FunctionApplication=m;var w=function(e){function t(t,n){var r=e.call(this)||this;return r.expression=t,r.match=n,r}return i(t,e),t.prototype.getExplicitTypeVariables=function(){return this.expression.getExplicitTypeVariables()},t.prototype.isSafe=function(e){return this.expression.isSafe(e)},t.prototype.simplify=function(){return new t(this.expression.simplify(),this.match.simplify())},t.prototype.toString=function(){var e="( "+this.expression+" )";return e+=" handle "+this.match},t.prototype.getType=function(e,t,n,r,i,a){void 0===t&&(t=new Map),void 0===n&&(n="'*t0"),void 0===r&&(r=new Set),void 0===i&&(i=!1),void 0===a&&(a=new Map);var s=this.match.getType(e,t,n,r,i,!1,a);if(!(s[0]instanceof o.FunctionType))throw new p.ElaborationError('You can only handle things of type "exn" and not "'+s[0].parameterType.normalize()[0]+'".');try{s[0].parameterType.merge(e,s[4],new o.CustomType("exn"))}catch(e){throw new p.ElaborationError('You can only handle things of type "exn" and not "'+s[0].parameterType.normalize()[0]+'".')}var u=s[0].returnType;e.valueIdentifierId=s[5];var c=this.expression.getType(e,s[4],s[2],s[3],i,a);try{var h=u.merge(e,c[4],c[0]);return[h[0],s[1].concat(c[1]),c[2],c[3],h[1],c[5]]}catch(e){if(!(e instanceof Array))throw e;throw new p.ElaborationError('The "handle" cannot change the type of the expression from "'+c[0].normalize()[0]+'" to "'+u.normalize()[0]+'": '+e[0])}},t.prototype.compute=function(e,t){var n=e.state;if(void 0===e.recResult)return t.push({next:this,params:e}),void t.push({next:this.expression,params:{state:n,modifiable:e.modifiable,recResult:void 0}});var r=e.recResult;if(void 0===r||void 0===r.value)throw new p.InternalInterpreterError("Try removing this jumper and that one over there.");if(void 0===e.exprResult)return r.hasThrown?(e.exprResult=r,t.push({next:this,params:e}),void t.push({next:this.match,params:{state:n,modifiable:e.modifiable,recResult:void 0,value:r.value}})):r;r=e.exprResult;var i=e.recResult;if(void 0===r||void 0===r.value||void 0===i||void 0===i.value)throw new p.InternalInterpreterError("How is this undefined?");return i.hasThrown&&i.value.equals(new c.ExceptionValue("Match",void 0,0,0))?{newState:void 0,value:r.value,hasThrown:r.hasThrown}:{newState:void 0,value:i.value,hasThrown:i.hasThrown}},t.prototype.assertUniqueBinding=function(e,t){return this.expression.assertUniqueBinding(e,t),this.match.assertUniqueBinding(e,t),new Set},t}(h);t.HandleException=w;var g=function(e){function t(t){var n=e.call(this)||this;return n.expression=t,n}return i(t,e),t.prototype.getExplicitTypeVariables=function(){return this.expression.getExplicitTypeVariables()},t.prototype.simplify=function(){return new t(this.expression.simplify())},t.prototype.isSafe=function(e){return!1},t.prototype.toString=function(){return"raise "+this.expression},t.prototype.getType=function(e,t,n,r,i,a){void 0===t&&(t=new Map),void 0===n&&(n="'*t0"),void 0===r&&(r=new Set),void 0===i&&(i=!1),void 0===a&&(a=new Map);var s=this.expression.getType(e,t,n,r,i,a);try{var u=s[0].merge(e,s[4],new o.CustomType("exn"));return[new o.TypeVariable(s[2]),s[1],s[2]+"0",s[3],u[1],s[5]]}catch(e){if(!(e instanceof Array))throw e;throw new p.ElaborationError("Raising anything but exceptions will only raise exceptions: "+e[0])}},t.prototype.compute=function(e,t){var n=e.state;if(void 0===e.recResult)return t.push({next:this,params:e}),void t.push({next:this.expression,params:{state:n,modifiable:e.modifiable,recResult:void 0}});var r=e.recResult;if(void 0===r||void 0===r.value)throw new p.InternalInterpreterError("I know I only killed four squids this month...but last month I killed at least ten!");if(!(r.value instanceof c.ExceptionValue))throw new p.EvaluationError('Cannot "raise" value of type "'+r.value.typeName()+'" (type must be "exn").');return{newState:n,value:r.value,hasThrown:!0}},t.prototype.assertUniqueBinding=function(e,t){return this.expression.assertUniqueBinding(e,t),new Set},t}(h);t.RaiseException=g;var T=function(e){function t(t){var n=e.call(this)||this;return n.match=t,n}return i(t,e),t.prototype.getExplicitTypeVariables=function(){return this.match.getExplicitTypeVariables()},t.prototype.simplify=function(){return new t(this.match.simplify())},t.prototype.toString=function(){return"(fn "+this.match+")"},t.prototype.getType=function(e,t,n,r,i,o){return void 0===t&&(t=new Map),void 0===n&&(n="'*t0"),void 0===r&&(r=new Set),void 0===i&&(i=!1),void 0===o&&(o=new Map),this.match.getType(e,t,n,r,i,!0,o)},t.prototype.compute=function(e,t){var n=e.state,r=n.getNestedState(n.id);return r.insideLocalDeclBody&&(r.dynamicBasis=n.getDynamicLocalDeclChanges(-1),r.insideLocalDeclBody=!1),{newState:void 0,value:new c.FunctionValue(r,[],this.match),hasThrown:!1}},t.prototype.assertUniqueBinding=function(e,t){return this.match.assertUniqueBinding(e,t),new Set},t}(h);t.Lambda=T;var E=function(){function e(e){this.matches=e}return e.prototype.getExplicitTypeVariables=function(){for(var e=new Set,t=0;t<this.matches.length;++t)this.matches[t][0].getExplicitTypeVariables().forEach((function(t){e=e.add(t)})),this.matches[t][1].getExplicitTypeVariables().forEach((function(t){e=e.add(t)}));return e},e.prototype.toString=function(){for(var e="",t=0;t<this.matches.length;++t)t>0&&(e+=" | "),e+=this.matches[t][0],e+=" => "+this.matches[t][1];return e},e.prototype.compute=function(e,t){var n=e.state,r=e.value;if(void 0===r)throw new p.InternalInterpreterError("How is this undefined?");for(var i=0;i<this.matches.length;++i){var o=n.getNestedState(n.id),a=this.matches[i][0].matches(o,r);if(void 0!==a){for(var s=0;s<a.length;++s)o.setDynamicValue(a[s][0],a[s][1],u.IdentifierStatus.VALUE_VARIABLE);return void t.push({next:this.matches[i][1],params:{state:o,modifiable:e.modifiable,recResult:void 0}})}}return{newState:void 0,value:new c.ExceptionValue("Match",void 0,0,0),hasThrown:!0}},e.prototype.getType=function(e,t,n,r,i,a,s){void 0===t&&(t=new Map),void 0===n&&(n="'*t0"),void 0===r&&(r=new Set),void 0===i&&(i=!1),void 0===a&&(a=!0),void 0===s&&(s=new Map);for(var c=new o.FunctionType(new o.AnyType,new o.AnyType),h=[],f=t,d=new Map,y=function(a){var y;if(v.matches[a][0]instanceof l){var m=e.getStaticValue(v.matches[a][0].name.getText());if(void 0!==m&&m[1]!==u.IdentifierStatus.VALUE_VARIABLE&&m[0]instanceof o.FunctionType)throw new p.ElaborationError('Unary constructor "'+v.matches[a][0].name.getText()+'" in the pattern needs an argument.')}var w=new Map;s.forEach((function(e,t){w=w.set(t,e)}));var g=v.matches[a][0].assertUniqueBinding(e,new Set);g.forEach((function(i){n=o.TypeVariable.getUnusedTypeVariableName(e,n,r,t),r=r.add(n),w=w.set(i,new o.TypeVariable(n))}));var T=new Map;f.forEach((function(e,t){T=T.set(t,e)}));var E=v.matches[a][0].getType(e,f,n,r,!0,w);e.valueIdentifierId=E[5],h=h.concat(E[1]);var x=v.matches[a][1].getType(e,E[4],E[2],E[3],i,w);h=h.concat(x[1]),e.valueIdentifierId=x[5],n=x[2],r=x[3],w.forEach((function(e,t){g.has(t)||(s=s.set(t,e))}));var S=new o.FunctionType(E[0],x[0]);try{y=c.merge(e,x[4],S),c=y[0],f=y[1],c=c.instantiate(e,f)}catch(e){if(!(e instanceof Array))throw e;throw new p.ElaborationError("Match rules disagree on type: "+e[0])}c=c.instantiate(e,f),f.forEach((function(e,t){"*"!==t[1]||"*"!==t[2]?T=T.set(t,e):d=d.set(t,e)})),f=T},v=this,m=0;m<this.matches.length;++m)y(m);var w=new Map;if(f.forEach((function(e,t){w=w.set(t,e)})),d.forEach((function(e,t){w=w.set(t,e)})),a)try{for(var g=this.checkExhaustiveness(e),T=[],E=new Set,x=0,S=g;x<S.length;x++){var I=S[x];E.has(I.message)||(E.add(I.message),T.push(new p.Warning(-1===I.type?-1:0,I.message)))}h=h.concat(T)}catch(e){h.push(new p.Warning(0,'How should I know whether "'+this+"\" is exhaustive? Do I look like friggin' WIKIP***A to you?!\n"+e.message+"\n"))}return[c,h,n,r,f,e.valueIdentifierId]},e.prototype.checkExhaustiveness=function(e){return(new x).cover(e,this.matches.map((function(e){return e[0]})))},e.prototype.simplify=function(){for(var t=[],n=0;n<this.matches.length;++n){var r=this.matches[n];t.push([r[0].simplify(),r[1].simplify()])}return new e(t)},e.prototype.assertUniqueBinding=function(e,t){for(var n=0;n<this.matches.length;++n)this.matches[n][0].assertUniqueBinding(e,t),this.matches[n][1].assertUniqueBinding(e,t);return new Set},e}();t.Match=E;var x=function(e){function t(){return e.call(this)||this}return i(t,e),t.prototype.getType=function(e,t,n,r,i,a){void 0===t&&(t=new Map),void 0===n&&(n="'*t0"),void 0===r&&(r=new Set),void 0===i&&(i=!1),void 0===a&&(a=new Map);for(var s=+n.substring(3)+1,u="";;++s)if(n="'"+n[1]+n[2]+s,!r.has(n)&&!t.has(n)&&void 0===e.getStaticValue(n))return u=n,[new o.TypeVariable(u),[],u,r.add(u),t,e.valueIdentifierId]},t.prototype.compute=function(e,t){throw new p.InternalInterpreterError("Wildcards are far too wild to have a value.")},t.prototype.matchType=function(e,t,n){return[[],n,t]},t.prototype.subsumes=function(e,t){return!0},t.prototype.cover=function(e,n){for(var r=!1,i=!1,o=[],a=new Set,s=[],u=new Map,c=new Map,h=new Set,y=[],w=0;w<n.length;++w){for(var g=n[w];g instanceof v;)g=g.expression;if(a.has(g.toString())&&o.push(new p.Warning(0,'Duplicate rule for "'+g+'" in pattern matching.\n')),a.add(g.toString()),g instanceof d){for(var T=0,E=g.entries;T<E.length;T++){var x=E[T];h.add(x[0])}y.push(g)}else if(!(g instanceof f)){if(g instanceof t){r=!0,i=!0,w+1<n.length&&o.push(new p.Warning(w,'Rules after "'+g+'" unused in pattern matching.\n'));break}if(g instanceof l){if(void 0===(S=g.getConstructorName(e))){r=!0,i=!0,w+1<n.length&&o.push(new p.Warning(w,'Rules after "'+g+'" unused in pattern matching.\n'));break}if(0===s.length){if(void 0===(k=g.getConstructorList(e)))throw new p.InternalInterpreterError("There. Just another unfortunate accident.");s=k}u.has(S)?o.push(new p.Warning(0,'Duplicate rule for "'+g+'" in pattern matching.\n')):(u=u.set(S,[g]),c=c.set(S,g))}else{if(g instanceof m){var S,V=g.func;if(!(V instanceof l))throw new p.InternalInterpreterError("There. Just another unfortunate accident.");if(void 0===(S=V.getConstructorName(e)))throw new p.InternalInterpreterError("There. Just another unfortunate accident.");if(0===s.length){var k;if(void 0===(k=V.getConstructorList(e)))throw new p.InternalInterpreterError("There. Just another unfortunate accident.");s=k}if(u.has(S)){var b=u.get(S);b.push(g),u=u.set(S,b)}else u=u.set(S,[g]),c=c.set(S,new m(g.func,new t))}if(g instanceof I)throw new p.PatternMatchError("Vector pattern are not checked for exhaustiveness.")}}}if(0!==s.length){if(!i){r=!0;for(w=0;w<s.length;++w)c.has(s[w])?o=o.concat(c.get(s[w]).cover(e,u.get(s[w]))):r=i}}else if(!r&&0!==y.length){var A=[];return h.forEach((function(e){A.push([e,new t])})),o.concat(new d(!0,A).cover(e,y))}return r||o.push(new p.Warning(-1,"Pattern matching is not exhaustive.\n")),o},t.prototype.matches=function(e,t){return[]},t.prototype.simplify=function(){return this},t.prototype.toString=function(){return"_"},t.prototype.assertUniqueBinding=function(e,t){return new Set},t}(h);t.Wildcard=x;var S=function(e){function t(t,n,r){var i=e.call(this)||this;return i.identifier=t,i.typeAnnotation=n,i.pattern=r,i}return i(t,e),t.prototype.getType=function(e,t,n,r,i,o){if(void 0===t&&(t=new Map),void 0===n&&(n="'*t0"),void 0===r&&(r=new Set),void 0===i&&(i=!1),void 0===o&&(o=new Map),!i)throw new p.InternalInterpreterError("Layered patterns are far too layered to have a type.");var a=new l(this.identifier).getType(e,t,n,r,!0,o),s=a[0];if(void 0!==this.typeAnnotation)try{t=(c=s.merge(e,a[4],this.typeAnnotation))[1],s=c[0]}catch(e){if(!(e instanceof Array))throw e;throw new p.ElaborationError("Wrong type annotation: "+e[0])}var u=this.pattern.getType(e,t,a[2],a[3],!0,o);try{var c;t=(c=s.merge(e,u[4],u[0]))[1],s=c[0]}catch(e){if(!(e instanceof Array))throw e;throw new p.ElaborationError("Wrong type annotation: "+e[0])}return[s,a[1].concat(u[1]),u[2],u[3],t,e.valueIdentifierId]},t.prototype.compute=function(e,t){throw new p.InternalInterpreterError("Layered patterns are far too layered to have a value.")},t.prototype.matchType=function(e,t,n){var r=n;if(void 0!==this.typeAnnotation)try{var i=n.merge(e,t,this.typeAnnotation);t=i[1],r=i[0]}catch(e){if(!(e instanceof Array))throw e;throw new p.ElaborationError("Wrong type annotation: "+e[0])}var o=this.pattern.matchType(e,t,r);return[[[this.identifier.getText(),r]].concat(o[0]),n,o[2]]},t.prototype.subsumes=function(e,t){throw new p.PatternMatchError("Layered patterns are not checked for exhaustiveness.")},t.prototype.cover=function(e,t){throw new p.PatternMatchError("Layered patterns are not checked for exhaustiveness.")},t.prototype.matches=function(e,t){var n=this.pattern.matches(e,t);return void 0===n?n:[[this.identifier.getText(),t]].concat(n)},t.prototype.simplify=function(){return this.typeAnnotation?new t(this.identifier,this.typeAnnotation.simplify(),this.pattern.simplify()):new t(this.identifier,void 0,this.pattern.simplify())},t.prototype.toString=function(){return this.identifier.getText()+" as "+this.pattern},t.prototype.assertUniqueBinding=function(e,t){var n=this.pattern.assertUniqueBinding(e,t),r=e.getStaticValue(this.identifier.getText());if(void 0!==r&&r[1]!==u.IdentifierStatus.VALUE_VARIABLE)return n;var i=e.getDynamicValue(this.identifier.getText());if(void 0!==i&&i[1]!==u.IdentifierStatus.VALUE_VARIABLE)return n;if(n.has(this.identifier.getText()))throw new p.ParserError('No matter from which end you start eating this pattern,rebinding "'+this.identifier.getText()+'" is still a bad idea.');return n.add(this.identifier.getText())},t}(h);t.LayeredPattern=S;var I=function(e){function t(t){var n=e.call(this)||this;return n.expressions=t,n}return i(t,e),t.prototype.getType=function(e,t,n,r,i,a){if(void 0===t&&(t=new Map),void 0===n&&(n="'*t0"),void 0===r&&(r=new Set),void 0===i&&(i=!1),void 0===a&&(a=new Map),0===this.expressions.length)return[new o.CustomType("vector",[new o.AnyType]),[],n,r,t,e.valueIdentifierId];for(var s=this.expressions[0].getType(e,t,n,r,i),u=s[0],c=0;c<this.expressions.length;++c){s=this.expressions[c].getType(e,s[4],s[2],s[3],i);try{var h=u.merge(e,s[4],s[0]);s[4]=h[1],u=h[0]}catch(e){if(!(e instanceof Array))throw e;throw new p.ElaborationError("Type clash in vector entries: "+e[0])}}return[new o.CustomType("vector",[u]),s[1],s[2],s[3],s[4],s[5]]},t.prototype.compute=function(e,t){for(var n=[],r=0;r<this.expressions.length;++r){var i=this.expressions[r].compute(e,t);if(void 0===i||void 0===i.value)throw new p.InternalInterpreterError("NG");n.push(i.value)}return{newState:void 0,value:new c.VectorValue(n),hasThrown:!1}},t.prototype.getExplicitTypeVariables=function(){return new Set},t.prototype.matchType=function(e,t,n){if(!(n instanceof o.CustomType)||"vector"!==n.name)throw new p.ElaborationError('Vectors like only vectors, not "'+n+'". Stay cool.');for(var r=n.typeArguments[0],i=[],a=0;a<this.expressions.length;++a){var s=this.expressions[a].matchType(e,t,r);r=s[1],i=i.concat(s[0]),t=s[2]}return[i,new o.CustomType("vector",[r]),t]},t.prototype.subsumes=function(e,t){throw new p.PatternMatchError("Vector patterns are not checked for exhaustiveness.")},t.prototype.cover=function(e,t){throw new p.PatternMatchError("Vector patterns are not checked for exhaustiveness.")},t.prototype.matches=function(e,t){if(!(t instanceof c.VectorValue))throw new p.ElaborationError('Vectors like only vectors, not "'+t+'". Stay cool.');for(var n=[],r=0;r<this.expressions.length;++r){var i=this.expressions[r].matches(e,t.entries[r]);void 0!==i&&(n=n.concat(i))}return n},t.prototype.simplify=function(){for(var e=[],n=0;n<this.expressions.length;++n)e.push(this.expressions[n].simplify());return new t(e)},t.prototype.toString=function(){for(var e="#[ ",t=0;t<this.expressions.length;++t)t>0&&(e+=", "),e+=this.expressions[t];return e+" ]"},t}(h);t.Vector=I;var V=function(e){function t(t,n){var r=e.call(this)||this;return r.left=t,r.right=n,r}return i(t,e),t.prototype.getType=function(e,t,n,r,i,o){void 0===t&&(t=new Map),void 0===n&&(n="'*t0"),void 0===r&&(r=new Set),void 0===i&&(i=!1),void 0===o&&(o=new Map);var a=this.left.getType(e,t,n,r,i),s=this.right.getType(e,a[4],a[2],a[3],i);try{var u=a[0].merge(e,s[4],s[0]);return[u[0],a[1].concat(s[1]),s[2],s[3],u[1],s[5]]}catch(e){if(!(e instanceof Array))throw e;throw new p.ElaborationError("Both patterns of a conjunctive pattern must have the same type.")}},t.prototype.simplify=function(){return new t(this.left.simplify(),this.right.simplify())},t.prototype.matchType=function(e,t,n){throw new p.InternalInterpreterError("「ニャ-、ニャ-」")},t.prototype.subsumes=function(e,t){throw new p.PatternMatchError("Conjuctive patterns are not checked for exhaustiveness.")},t.prototype.cover=function(e,t){throw new p.PatternMatchError("Conjuctive patterns are not checked for exhaustiveness.")},t.prototype.matches=function(e,t){var n=this.left.matches(e,t);if(void 0!==n){for(var r=e.getNestedState(e.id),i=0,o=n;i<o.length;i++){var a=o[i];r.setDynamicValue(a[0],a[1],u.IdentifierStatus.VALUE_VARIABLE)}var s=this.right.matches(r,t);if(void 0!==s)return n.concat(s)}},t.prototype.assertUniqueBinding=function(e,t){return new Set},t}(h);t.ConjunctivePattern=V;var k=function(e){function t(t,n){var r=e.call(this)||this;return r.left=t,r.right=n,r}return i(t,e),t.prototype.getType=function(e,t,n,r,i,o){void 0===t&&(t=new Map),void 0===n&&(n="'*t0"),void 0===r&&(r=new Set),void 0===i&&(i=!1),void 0===o&&(o=new Map);var a=this.left.getType(e,t,n,r,i),s=this.right.getType(e,a[4],a[2],a[3],i);try{var u=a[0].merge(e,s[4],s[0]);return[u[0],a[1].concat(s[1]),s[2],s[3],u[1],s[5]]}catch(e){if(!(e instanceof Array))throw e;throw new p.ElaborationError("Both patterns of a disjunctive pattern must have the same type.")}},t.prototype.simplify=function(){return new t(this.left.simplify(),this.right.simplify())},t.prototype.matchType=function(e,t,n){throw new p.InternalInterpreterError("「ニャ-、ニャ-」")},t.prototype.subsumes=function(e,t){throw new p.PatternMatchError("Disjunctive patterns are not checked for exhaustiveness.")},t.prototype.cover=function(e,t){throw new p.PatternMatchError("Disjunctive patterns are not checked for exhaustiveness.")},t.prototype.matches=function(e,t){var n=this.left.matches(e,t);return void 0!==n?n:this.right.matches(e,t)},t.prototype.assertUniqueBinding=function(e,t){return new Set},t}(h);t.DisjunctivePattern=k;var b=function(e){function t(t,n,r){var i=e.call(this)||this;return i.pattern=t,i.nested=n,i.expression=r,i}return i(t,e),t.prototype.getType=function(e,t,n,r,i,o){throw void 0===t&&(t=new Map),void 0===n&&(n="'*t0"),void 0===r&&(r=new Set),void 0===i&&(i=!1),void 0===o&&(o=new Map),new p.InternalInterpreterError("「ニャ-、ニャ-」")},t.prototype.simplify=function(){return new t(this.pattern.simplify(),this.nested.simplify(),this.expression.simplify())},t.prototype.matchType=function(e,t,n){throw new p.InternalInterpreterError("「ニャ-、ニャ-」")},t.prototype.subsumes=function(e,t){throw new p.PatternMatchError("Nested matches are not checked for exhaustiveness.")},t.prototype.cover=function(e,t){throw new p.PatternMatchError("Nested matches are not checked for exhaustiveness.")},t.prototype.matches=function(e,t){if(void 0!==this.pattern.matches(e,t))throw new p.InternalInterpreterError("「ニャ-、ニャ-」")},t.prototype.assertUniqueBinding=function(e,t){return new Set},t.prototype.toString=function(){return"( "+this.pattern+" with "+this.nested+" = "+this.expression+" )"},t}(h);t.NestedMatch=b;var A=function(e){function t(t,n){var r=e.call(this)||this;return r.expressions=t,r.operators=n,r}return i(t,e),t.prototype.matchType=function(e,t,n){return this.reParse(e).matchType(e,t,n)},t.prototype.subsumes=function(e,t){throw new p.InternalInterpreterError("一昨日来やがれ。")},t.prototype.cover=function(e,t){throw new p.InternalInterpreterError("一昨日来やがれ。")},t.prototype.matches=function(e,t){return this.reParse(e).matches(e,t)},t.prototype.simplify=function(){throw new p.InternalInterpreterError("Ouch, I'm not fully parsed.")},t.prototype.reParse=function(e){for(var t=this.operators,n=this.expressions,r=[],i=0;i<n.length;++i)r.push([i]);t.sort((function(t,n){var r=t[0],i=t[1],o=n[0],a=n[1],s=e.getInfixStatus(r),u=e.getInfixStatus(o);if(s.precedence>u.precedence)return-1;if(s.precedence<u.precedence)return 1;if(s.rightAssociative){if(i>a)return-1;if(i<a)return 1}else{if(i>a)return 1;if(i<a)return-1}return 0}));for(i=0;i<t.length;++i){if(i>0){var o=e.getInfixStatus(t[i][0]),a=e.getInfixStatus(t[i-1][0]);if(o.precedence===a.precedence&&o.rightAssociative!==a.rightAssociative&&(r[t[i-1][1]+1]===r[t[i][1]]||r[t[i-1][1]]===r[t[i][1]+1]))throw new p.ParserError("Could you ever imagine left associatives and right associatives living together in peace?")}for(var s=n[t[i][1]],u=n[t[i][1]+1],c=new m(new l(t[i][0]),new _([s,u])),h=r[t[i][1]],f=0,d=r[t[i][1]+1];f<d.length;f++){var y=d[f];h.push(y)}for(var v=0,w=h;v<w.length;v++){r[y=w[v]]=h,n[y]=c}}return n[0]},t}(h);t.InfixExpression=A;var L=new l(new s.IdentifierToken("false")),R=new l(new s.IdentifierToken("true")),B=new l(new s.IdentifierToken("nil")),C=new l(new s.IdentifierToken("::")),O=function(e){function t(t,n){var r=e.call(this)||this;return r.leftOperand=t,r.rightOperand=n,r}return i(t,e),t.prototype.simplify=function(){return new D(this.leftOperand,this.rightOperand,L).simplify()},t.prototype.toString=function(){return"( "+this.leftOperand+" andalso "+this.rightOperand+" )"},t}(h);t.Conjunction=O;var N=function(e){function t(t,n){var r=e.call(this)||this;return r.leftOperand=t,r.rightOperand=n,r}return i(t,e),t.prototype.simplify=function(){return new D(this.leftOperand,R,this.rightOperand).simplify()},t.prototype.toString=function(){return"( "+this.leftOperand+" orelse "+this.rightOperand+" )"},t}(h);t.Disjunction=N;var _=function(e){function t(t){var n=e.call(this)||this;return n.expressions=t,n}return i(t,e),t.prototype.matchType=function(e,t,n){return this.simplify().matchType(e,t,n)},t.prototype.subsumes=function(e,t){return this.simplify().subsumes(e,t)},t.prototype.cover=function(e,t){return this.simplify().cover(e,t)},t.prototype.matches=function(e,t){return this.simplify().matches(e,t)},t.prototype.simplify=function(){for(var e=[],t=0;t<this.expressions.length;++t)e.push([""+(t+1),this.expressions[t].simplify()]);return new d(!0,e)},t.prototype.toString=function(){for(var e="( ",t=0;t<this.expressions.length;++t)t>0&&(e+=", "),e+=this.expressions[t];return e+" )"},t}(h);t.Tuple=_;var P=function(e){function t(t){var n=e.call(this)||this;return n.expressions=t,n}return i(t,e),t.prototype.matchType=function(e,t,n){return this.simplify().matchType(e,t,n)},t.prototype.subsumes=function(e,t){return this.simplify().subsumes(e,t)},t.prototype.cover=function(e,t){return this.simplify().cover(e,t)},t.prototype.matches=function(e,t){return this.simplify().matches(e,t)},t.prototype.simplify=function(){for(var e=B,t=this.expressions.length-1;t>=0;--t){var n=new _([this.expressions[t],e]).simplify();e=new m(C,n)}return e},t.prototype.toString=function(){for(var e="[ ",t=0;t<this.expressions.length;++t)t>0&&(e+=", "),e+=this.expressions[t];return e+" ]"},t}(h);t.List=P;var q=function(e){function t(t){var n=e.call(this)||this;return n.expressions=t,n}return i(t,e),t.prototype.simplify=function(){for(var e=this.expressions.length-1,t=new E([[new x,this.expressions[e]]]),n=new U(this.expressions[e-1],t),r=e-2;r>=0;--r)t=new E([[new x,n]]),n=new U(this.expressions[r],t);return n.simplify()},t.prototype.toString=function(){for(var e="( ",t=0;t<this.expressions.length;++t)t>0&&(e+="; "),e+=this.expressions[t];return e+" )"},t}(h);t.Sequence=q;var M=function(e){function t(t){var n=e.call(this)||this;return n.label=t,n}return i(t,e),t.prototype.simplify=function(){return new T(new E([[new d(!1,[[this.label.text,new l(new s.IdentifierToken("__rs"))]]),new l(new s.IdentifierToken("__rs"))]]))},t.prototype.toString=function(){return"#"+this.label.getText()},t}(h);t.RecordSelector=M;var U=function(e){function t(t,n){var r=e.call(this)||this;return r.expression=t,r.match=n,r}return i(t,e),t.prototype.simplify=function(){return new m(new T(this.match.simplify()),this.expression.simplify())},t.prototype.toString=function(){return"case "+this.expression+" of "+this.match},t}(h);t.CaseAnalysis=U;var D=function(e){function t(t,n,r){var i=e.call(this)||this;return i.condition=t,i.consequence=n,i.alternative=r,i}return i(t,e),t.prototype.simplify=function(){var e=new E([[R,this.consequence],[L,this.alternative]]);return new U(this.condition,e).simplify()},t.prototype.toString=function(){return"if "+this.condition+" then "+this.consequence+" else "+this.alternative},t}(h);t.Conditional=D;var F=function(e){function t(t,n){var r=e.call(this)||this;return r.condition=t,r.body=n,r}return i(t,e),t.prototype.simplify=function(){var e=new l(new s.IdentifierToken("__whl")),t=new m(e,new _([])),n=new D(this.condition,new q([this.body,t]),new _([])),r=new a.ValueBinding(!0,e,new T(new E([[new _([]),n]]))),i=new a.ValueDeclaration([],[r]);return new y(i,t).simplify()},t.prototype.toString=function(){return"( while "+this.condition+" do "+this.body+" )"},t}(h);t.While=F;var K=function(e){function t(t,n){var r=e.call(this)||this;return r.pattern=t,r.condition=n,r}return i(t,e),t.prototype.simplify=function(){return new b(this.pattern.simplify(),R,this.condition.simplify())},t.prototype.matchType=function(e,t,n){throw new p.InternalInterpreterError("「ニャ-、ニャ-」")},t.prototype.subsumes=function(e,t){throw new p.PatternMatchError("Patterns with a pattern guard are not checked for exhaustiveness.")},t.prototype.cover=function(e,t){throw new p.PatternMatchError("Patterns with a pattern guard are not checked for exhaustiveness.")},t.prototype.matches=function(e,t){throw new p.InternalInterpreterError("「ニャ-、ニャ-」")},t.prototype.toString=function(){return"( "+this.pattern+" if "+this.condition+" )"},t}(h);t.PatternGuard=K},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var r=n(9),i=n(4),o=n(0),a=n(11);t.Lexer=a;var s=n(12);t.Parser=s;var u=n(25);t.Evaluator=u;var p=n(6);t.Declarations=p;var c=n(0);t.Errors=c;var h=n(7);t.Expressions=h;var f=n(5);t.Tokens=f;var l=n(1);t.Types=l;var d=n(2);t.Values=d;var y=n(10);function v(){var e=[];for(var t in i.STDLIB)Object.prototype.hasOwnProperty.call(i.STDLIB,t)&&"_"!==t[0]&&e.push(t);return e}t.Version=y,function(e){for(var n in e)t.hasOwnProperty(n)||(t[n]=e[n])}(n(3)),t.interpret=function(e,t,n){void 0===t&&(t=r.getInitialState()),void 0===n&&(n={allowSuccessorML:!1,disableElaboration:!1,allowVector:!0,strictMode:!0,realEquality:!1});var i=t.getNestedState(),p=a.lex(e,n),c=s.parse(p,i,n);if(c=c.simplify(),i=t.getNestedState(),!0===n.disableElaboration){var h=u.evaluate(t.getNestedState(),c);if(void 0===h||void 0===h.newState)throw new o.InternalInterpreterError("How is this undefined?");return{state:h.newState,evaluationErrored:h.hasThrown,error:h.value,warnings:h.newState.getWarnings()}}var f=c.elaborate(i,new Map,"'*t0",new Map,!0,n);if(i=f[0],!0===n.disableEvaluation)return{state:i,evaluationErrored:!1,error:void 0,warnings:f[1]};var l=u.evaluate(t.getNestedState(),c);if(void 0===l||void 0===l.newState)throw new o.InternalInterpreterError("How is this undefined?");for(var d=0;d<f[1].length;++d)l.newState.addWarning(f[1][d]);if(l.hasThrown)return{state:l.newState,evaluationErrored:!0,error:l.value,warnings:l.newState.getWarnings()};for(var y=l.newState;y.id>t.id;){if(void 0!==y.dynamicBasis){for(var d in y.freeTypeVariables=i.getTypeVariableBinds(y.id),y.dynamicBasis.valueEnvironment){if(Object.prototype.hasOwnProperty.call(y.dynamicBasis.valueEnvironment,d))void 0!==(v=i.getStaticValue(d,y.id))&&y.setStaticValue(d,v[0],v[1])}for(var d in y.dynamicBasis.typeEnvironment){if(Object.prototype.hasOwnProperty.call(y.dynamicBasis.typeEnvironment,d))void 0!==(v=i.getStaticType(d,y.id))&&y.setStaticType(d,v.type,v.constructors,v.arity,v.allowsEquality)}for(var d in y.dynamicBasis.structureEnvironment){if(Object.prototype.hasOwnProperty.call(y.dynamicBasis.structureEnvironment,d))void 0!==(v=i.getStaticStructure(d,y.id))&&y.setStaticStructure(d,v)}for(var d in y.dynamicBasis.signatureEnvironment){if(Object.prototype.hasOwnProperty.call(y.dynamicBasis.signatureEnvironment,d))void 0!==(v=i.getStaticSignature(d,y.id))&&y.setStaticSignature(d,v)}for(var d in y.dynamicBasis.functorEnvironment){var v;if(Object.prototype.hasOwnProperty.call(y.dynamicBasis.functorEnvironment,d))void 0!==(v=i.getStaticFunctor(d,y.id))&&y.setStaticFunctor(d,v)}}if(void 0===i.parent)break;for(y=y.parent;i.id>y.id&&void 0!==i.parent;)i=i.parent}return{state:l.newState,evaluationErrored:!1,error:l.value,warnings:l.newState.getWarnings()}},t.getAvailableModules=v,t.getFirstState=function(e,t){if(void 0===e&&(e=v()),void 0===t&&(t={}),!0===t.noModules)return r.getInitialState(t);for(var n=i.loadModule(r.getInitialState(t),"__Base",t),o=0,a=e;o<a.length;o++){var s=a[o];n=i.loadModule(n,s,t)}return n}},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var r=n(3),i=n(1),o=n(2),a=n(0),s=new i.CustomType("real"),u=new i.CustomType("bool"),p=new i.CustomType("string"),c=new i.CustomType("char");function h(e){return new i.FunctionType(new i.TupleType([e,e]),e).simplify()}function f(e){return new i.FunctionType(new i.TupleType([e,e]),u).simplify()}var l=new i.TypeVariable("'a"),d=new i.TypeVariable("''b"),y=new i.TypeVariable("'iw"),v=new i.TypeVariable("'ir"),m=new i.TypeVariable("'iwr"),w=new i.TypeVariable("'any"),g=new o.ExceptionConstructor("Match",0,0,0),T=new o.ExceptionConstructor("Bind",0,0,1),E=new o.ExceptionConstructor("Div",0,0,2),x=new o.ExceptionConstructor("Overflow",0,0,3);function S(e){return new i.TypeVariableBind("'iw",e,[new i.CustomType("int"),new i.CustomType("word")]).propagate()}function I(e){return new i.TypeVariableBind("'ir",e,[new i.CustomType("int"),s]).propagate()}function V(e){return new i.TypeVariableBind("'iwr",e,[new i.CustomType("int"),new i.CustomType("word"),s]).propagate()}function k(e){return new i.TypeVariableBind("'any",e,[new i.CustomType("int"),new i.CustomType("word"),s,new i.CustomType("string"),new i.CustomType("char")]).propagate()}var b=new r.State(0,void 0,new r.StaticBasis({unit:new r.TypeInformation(new i.FunctionType(new i.CustomType("unit"),new i.TupleType([])).simplify(),[],0,!0),bool:new r.TypeInformation(new i.CustomType("bool"),["true","false"],0,!0),int:new r.TypeInformation(new i.CustomType("int"),[],0,!0),word:new r.TypeInformation(new i.CustomType("word"),[],0,!0),real:new r.TypeInformation(s,[],0,!1),string:new r.TypeInformation(new i.CustomType("string"),[],0,!0),char:new r.TypeInformation(new i.CustomType("char"),[],0,!0),list:new r.TypeInformation(new i.CustomType("list",[l]),["nil","::"],1,!0),array:new r.TypeInformation(new i.CustomType("array",[l]),[],1,!0),vector:new r.TypeInformation(new i.CustomType("vector",[l]),[],1,!0),ref:new r.TypeInformation(new i.CustomType("ref",[l]),["ref"],1,!0),exn:new r.TypeInformation(new i.CustomType("exn"),[],0,!1)},{div:[S(h(y)),r.IdentifierStatus.VALUE_VARIABLE],mod:[S(h(y)),r.IdentifierStatus.VALUE_VARIABLE],"*":[V(h(m)),r.IdentifierStatus.VALUE_VARIABLE],"/":[h(s),r.IdentifierStatus.VALUE_VARIABLE],"+":[V(h(m)),r.IdentifierStatus.VALUE_VARIABLE],"-":[V(h(m)),r.IdentifierStatus.VALUE_VARIABLE],"<":[k(f(w)),r.IdentifierStatus.VALUE_VARIABLE],"<=":[k(f(w)),r.IdentifierStatus.VALUE_VARIABLE],">":[k(f(w)),r.IdentifierStatus.VALUE_VARIABLE],">=":[k(f(w)),r.IdentifierStatus.VALUE_VARIABLE],"=":[new i.TypeVariableBind("''b",new i.FunctionType(new i.TupleType([d,d]),u)).simplify(),r.IdentifierStatus.VALUE_VARIABLE],"<>":[new i.TypeVariableBind("''b",new i.FunctionType(new i.TupleType([d,d]),u)).simplify(),r.IdentifierStatus.VALUE_VARIABLE],true:[new i.CustomType("bool"),r.IdentifierStatus.VALUE_CONSTRUCTOR],false:[new i.CustomType("bool"),r.IdentifierStatus.VALUE_CONSTRUCTOR],nil:[new i.TypeVariableBind("'a",new i.CustomType("list",[l])),r.IdentifierStatus.VALUE_CONSTRUCTOR],"::":[new i.TypeVariableBind("'a",new i.FunctionType(new i.TupleType([l,new i.CustomType("list",[l])]),new i.CustomType("list",[l]))).simplify(),r.IdentifierStatus.VALUE_CONSTRUCTOR],Match:[new i.CustomType("exn"),r.IdentifierStatus.EXCEPTION_CONSTRUCTOR],Bind:[new i.CustomType("exn"),r.IdentifierStatus.EXCEPTION_CONSTRUCTOR],Div:[new i.CustomType("exn"),r.IdentifierStatus.EXCEPTION_CONSTRUCTOR],Overflow:[new i.CustomType("exn"),r.IdentifierStatus.EXCEPTION_CONSTRUCTOR],"^":[h(p),r.IdentifierStatus.VALUE_VARIABLE],explode:[new i.FunctionType(p,new i.CustomType("list",[c])).simplify(),r.IdentifierStatus.VALUE_VARIABLE],implode:[new i.FunctionType(new i.CustomType("list",[c]),p).simplify(),r.IdentifierStatus.VALUE_VARIABLE],"~":[I(new i.FunctionType(v,v)),r.IdentifierStatus.VALUE_VARIABLE],abs:[I(new i.FunctionType(v,v)),r.IdentifierStatus.VALUE_VARIABLE],print:[new i.TypeVariableBind("'a",new i.FunctionType(l,new i.TupleType([]))).simplify(),r.IdentifierStatus.VALUE_VARIABLE],printLn:[new i.TypeVariableBind("'a",new i.FunctionType(l,new i.TupleType([]))).simplify(),r.IdentifierStatus.VALUE_VARIABLE],":=":[new i.TypeVariableBind("'a",new i.FunctionType(new i.TupleType([new i.CustomType("ref",[l]),l]),new i.TupleType([]))).simplify(),r.IdentifierStatus.VALUE_VARIABLE],ref:[new i.TypeVariableBind("'a",new i.FunctionType(l,new i.CustomType("ref",[l]))),r.IdentifierStatus.VALUE_CONSTRUCTOR],"!":[new i.TypeVariableBind("'a",new i.FunctionType(new i.CustomType("ref",[l]),l)),r.IdentifierStatus.VALUE_VARIABLE]},{},{},{}),new r.DynamicBasis({unit:[],bool:["true","false"],int:[],word:[],real:[],string:[],char:[],list:["nil","::"],array:[],vector:[],ref:["ref"],exn:[]},{div:[new o.PredefinedFunction("div",(function(e,t){if(e instanceof o.RecordValue){var n=e.getValue("1"),r=e.getValue("2");if(n instanceof o.Integer&&r instanceof o.Integer)return 0===r.value?[E.construct(),!0,[]]:[n.divide(r),!1,[]];if(n instanceof o.Word&&r instanceof o.Word)return 0===r.value?[E.construct(),!0,[]]:[n.divide(r),!1,[]]}throw new a.InternalInterpreterError('Called "div" on value of the wrong type ('+e.typeName()+").")})),r.IdentifierStatus.VALUE_VARIABLE],mod:[new o.PredefinedFunction("mod",(function(e,t){if(e instanceof o.RecordValue){var n=e.getValue("1"),r=e.getValue("2");if(n instanceof o.Integer&&r instanceof o.Integer)return 0===r.value?[E.construct(),!0,[]]:[n.modulo(r),!1,[]];if(n instanceof o.Word&&r instanceof o.Word)return 0===r.value?[E.construct(),!0,[]]:[n.modulo(r),!1,[]]}throw new a.InternalInterpreterError('Called "mod" on value of the wrong type ('+e.typeName()+").")})),r.IdentifierStatus.VALUE_VARIABLE],"*":[new o.PredefinedFunction("*",(function(e,t){if(e instanceof o.RecordValue){var n,r=e.getValue("1"),i=e.getValue("2");if(r instanceof o.Integer&&i instanceof o.Integer)return(n=r.multiply(i)).hasOverflow()?[x.construct(),!0,[]]:[n,!1,[]];if(r instanceof o.Word&&i instanceof o.Word)return(n=r.multiply(i)).hasOverflow()?[x.construct(),!0,[]]:[n,!1,[]];if(r instanceof o.Real&&i instanceof o.Real)return(n=r.multiply(i)).hasOverflow()?[x.construct(),!0,[]]:[n,!1,[]]}throw new a.InternalInterpreterError('Called "*" on value of the wrong type ('+e.typeName()+").")})),r.IdentifierStatus.VALUE_VARIABLE],"/":[new o.PredefinedFunction("/",(function(e,t){if(e instanceof o.RecordValue){var n=e.getValue("1"),r=e.getValue("2");if(n instanceof o.Real&&r instanceof o.Real)return 0===r.value?[E.construct(),!0,[]]:[n.divide(r),!1,[]]}throw new a.InternalInterpreterError('Called "/" on value of the wrong type ('+e.typeName()+").")})),r.IdentifierStatus.VALUE_VARIABLE],"+":[new o.PredefinedFunction("+",(function(e,t){if(e instanceof o.RecordValue){var n,r=e.getValue("1"),i=e.getValue("2");if(r instanceof o.Integer&&i instanceof o.Integer)return(n=r.add(i)).hasOverflow()?[x.construct(),!0,[]]:[n,!1,[]];if(r instanceof o.Word&&i instanceof o.Word)return(n=r.add(i)).hasOverflow()?[x.construct(),!0,[]]:[n,!1,[]];if(r instanceof o.Real&&i instanceof o.Real)return(n=r.add(i)).hasOverflow()?[x.construct(),!0,[]]:[n,!1,[]]}throw new a.InternalInterpreterError('Called "+" on value of the wrong type ('+e.typeName()+").")})),r.IdentifierStatus.VALUE_VARIABLE],"-":[new o.PredefinedFunction("-",(function(e,t){if(e instanceof o.RecordValue){var n,r=e.getValue("1"),i=e.getValue("2");if(r instanceof o.Integer&&i instanceof o.Integer)return(n=r.add(i.negate())).hasOverflow()?[x.construct(),!0,[]]:[n,!1,[]];if(r instanceof o.Word&&i instanceof o.Word)return(n=r.add(i.negate())).hasOverflow()?[x.construct(),!0,[]]:[n,!1,[]];if(r instanceof o.Real&&i instanceof o.Real)return(n=r.add(i.negate())).hasOverflow()?[x.construct(),!0,[]]:[n,!1,[]]}throw new a.InternalInterpreterError('Called "-" on value of the wrong type ('+e.typeName()+").")})),r.IdentifierStatus.VALUE_VARIABLE],"<":[new o.PredefinedFunction("<",(function(e,t){if(e instanceof o.RecordValue){var n=e.getValue("1"),r=e.getValue("2");if(n instanceof o.Integer&&r instanceof o.Integer)return[new o.BoolValue(n.compareTo(r)<0),!1,[]];if(n instanceof o.Word&&r instanceof o.Word)return[new o.BoolValue(n.compareTo(r)<0),!1,[]];if(n instanceof o.Real&&r instanceof o.Real)return[new o.BoolValue(n.compareTo(r)<0),!1,[]];if(n instanceof o.StringValue&&r instanceof o.StringValue)return[new o.BoolValue(n.compareTo(r)<0),!1,[]];if(n instanceof o.CharValue&&r instanceof o.CharValue)return[new o.BoolValue(n.compareTo(r)<0),!1,[]]}throw new a.InternalInterpreterError('Called "<" on value of the wrong type ('+e.typeName()+").")})),r.IdentifierStatus.VALUE_VARIABLE],">":[new o.PredefinedFunction("<",(function(e,t){if(e instanceof o.RecordValue){var n=e.getValue("1"),r=e.getValue("2");if(n instanceof o.Integer&&r instanceof o.Integer)return[new o.BoolValue(n.compareTo(r)>0),!1,[]];if(n instanceof o.Word&&r instanceof o.Word)return[new o.BoolValue(n.compareTo(r)>0),!1,[]];if(n instanceof o.Real&&r instanceof o.Real)return[new o.BoolValue(n.compareTo(r)>0),!1,[]];if(n instanceof o.StringValue&&r instanceof o.StringValue)return[new o.BoolValue(n.compareTo(r)>0),!1,[]];if(n instanceof o.CharValue&&r instanceof o.CharValue)return[new o.BoolValue(n.compareTo(r)>0),!1,[]]}throw new a.InternalInterpreterError('Called ">" on value of the wrong type ('+e.typeName()+").")})),r.IdentifierStatus.VALUE_VARIABLE],"<=":[new o.PredefinedFunction("<",(function(e,t){if(e instanceof o.RecordValue){var n=e.getValue("1"),r=e.getValue("2");if(n instanceof o.Integer&&r instanceof o.Integer)return[new o.BoolValue(n.compareTo(r)<=0),!1,[]];if(n instanceof o.Word&&r instanceof o.Word)return[new o.BoolValue(n.compareTo(r)<=0),!1,[]];if(n instanceof o.Real&&r instanceof o.Real)return[new o.BoolValue(n.compareTo(r)<=0),!1,[]];if(n instanceof o.StringValue&&r instanceof o.StringValue)return[new o.BoolValue(n.compareTo(r)<=0),!1,[]];if(n instanceof o.CharValue&&r instanceof o.CharValue)return[new o.BoolValue(n.compareTo(r)<=0),!1,[]]}throw new a.InternalInterpreterError('Called "<=" on value of the wrong type ('+e.typeName()+").")})),r.IdentifierStatus.VALUE_VARIABLE],">=":[new o.PredefinedFunction("<",(function(e,t){if(e instanceof o.RecordValue){var n=e.getValue("1"),r=e.getValue("2");if(n instanceof o.Integer&&r instanceof o.Integer)return[new o.BoolValue(n.compareTo(r)>=0),!1,[]];if(n instanceof o.Word&&r instanceof o.Word)return[new o.BoolValue(n.compareTo(r)>=0),!1,[]];if(n instanceof o.Real&&r instanceof o.Real)return[new o.BoolValue(n.compareTo(r)>=0),!1,[]];if(n instanceof o.StringValue&&r instanceof o.StringValue)return[new o.BoolValue(n.compareTo(r)>=0),!1,[]];if(n instanceof o.CharValue&&r instanceof o.CharValue)return[new o.BoolValue(n.compareTo(r)>=0),!1,[]]}throw new a.InternalInterpreterError('Called ">=" on value of the wrong type ('+e.typeName()+").")})),r.IdentifierStatus.VALUE_VARIABLE],"=":[new o.PredefinedFunction("=",(function(e,t){if(e instanceof o.RecordValue){var n=e.getValue("1"),r=e.getValue("2");return[new o.BoolValue(n.equals(r)),!1,[]]}throw new a.InternalInterpreterError('Called "=" on value of the wrong type ('+e.typeName()+").")})),r.IdentifierStatus.VALUE_VARIABLE],"<>":[new o.PredefinedFunction("=",(function(e,t){if(e instanceof o.RecordValue){var n=e.getValue("1"),r=e.getValue("2");return[new o.BoolValue(!n.equals(r)),!1,[]]}throw new a.InternalInterpreterError('Called "<>" on value of the wrong type ('+e.typeName()+").")})),r.IdentifierStatus.VALUE_VARIABLE],true:[new o.BoolValue(!0),r.IdentifierStatus.VALUE_CONSTRUCTOR],false:[new o.BoolValue(!1),r.IdentifierStatus.VALUE_CONSTRUCTOR],nil:[new o.ValueConstructor("nil"),r.IdentifierStatus.VALUE_CONSTRUCTOR],"::":[new o.ValueConstructor("::",1),r.IdentifierStatus.VALUE_CONSTRUCTOR],Match:[g,r.IdentifierStatus.EXCEPTION_CONSTRUCTOR],Bind:[T,r.IdentifierStatus.EXCEPTION_CONSTRUCTOR],Div:[E,r.IdentifierStatus.EXCEPTION_CONSTRUCTOR],Overflow:[x,r.IdentifierStatus.EXCEPTION_CONSTRUCTOR],"^":[new o.PredefinedFunction("^",(function(e,t){if(e instanceof o.RecordValue){var n=e.getValue("1"),r=e.getValue("2");if(n instanceof o.StringValue&&r instanceof o.StringValue)return[n.concat(r),!1,[]]}throw new a.InternalInterpreterError('Called "^" on value of the wrong type ('+e.typeName()+").")})),r.IdentifierStatus.VALUE_VARIABLE],explode:[new o.PredefinedFunction("explode",(function(e,t){if(e instanceof o.StringValue)return[e.explode(),!1,[]];throw new a.InternalInterpreterError('Called "explode" on value of the wrong type ('+e.typeName()+").")})),r.IdentifierStatus.VALUE_VARIABLE],implode:[new o.PredefinedFunction("implode",(function(e,t){if(e instanceof o.ConstructedValue)return[o.StringValue.implode(e),!1,[]];throw new a.InternalInterpreterError('Called "implode" on value of the wrong type ('+e.typeName()+").")})),r.IdentifierStatus.VALUE_VARIABLE],"~":[new o.PredefinedFunction("~",(function(e,t){var n;if(e instanceof o.Integer)return(n=e.negate()).hasOverflow()?[x.construct(),!0,[]]:[n,!1,[]];if(e instanceof o.Real)return(n=e.negate()).hasOverflow()?[x.construct(),!0,[]]:[n,!1,[]];throw new a.InternalInterpreterError('Called "~" on something weird.')})),r.IdentifierStatus.VALUE_VARIABLE],abs:[new o.PredefinedFunction("~",(function(e,t){var n;if(e instanceof o.Integer)return e.value>=0?[e,!1,[]]:(n=e.negate()).hasOverflow()?[x.construct(),!0,[]]:[n,!1,[]];if(e instanceof o.Real)return e.value>=0?[e,!1,[]]:(n=e.negate()).hasOverflow()?[x.construct(),!0,[]]:[n,!1,[]];throw new a.InternalInterpreterError('Called "~" on something weird.')})),r.IdentifierStatus.VALUE_VARIABLE],print:[new o.PredefinedFunction("print",(function(e,t){var n=[];return e instanceof o.StringValue?n.push(new a.Warning(-2,e.value)):n.push(new a.Warning(-2,e.toString(void 0,1e18))),[new o.RecordValue,!1,n]})),r.IdentifierStatus.VALUE_VARIABLE],printLn:[new o.PredefinedFunction("printLn",(function(e,t){var n=[];return e instanceof o.StringValue?n.push(new a.Warning(-2,e.value+"\n")):n.push(new a.Warning(-2,e.toString(void 0,1e18)+"\n")),[new o.RecordValue,!1,n]})),r.IdentifierStatus.VALUE_VARIABLE],":=":[new o.PredefinedFunction(":=",(function(e,t){if(e instanceof o.RecordValue){var n=e.getValue("1"),r=e.getValue("2");if(n instanceof o.ReferenceValue)return t.modifiable.setCell(n.address,r),[new o.RecordValue,!1,[]]}throw new a.InternalInterpreterError('Called ":=" on value of the wrong type ('+e.typeName()+").")})),r.IdentifierStatus.VALUE_VARIABLE],ref:[new o.PredefinedFunction("ref",(function(e,t){return[t.modifiable.setNewCell(e),!1,[]]})),r.IdentifierStatus.VALUE_VARIABLE],"!":[new o.PredefinedFunction("!",(function(e,t){if(e instanceof o.ReferenceValue){var n=t.modifiable.getCell(e.address);if(void 0===n)throw new a.InternalInterpreterError("Neko-sempai, I think that I crashed. What shall I do now?");return[n,!1,[]]}throw new a.InternalInterpreterError('Called "!" on value of the wrong type ('+e.typeName()+").")})),r.IdentifierStatus.VALUE_VARIABLE]},{},{},{}),[0,{}],4,[0,new Map],{div:new r.InfixStatus(!0,7,!1),mod:new r.InfixStatus(!0,7,!1),"*":new r.InfixStatus(!0,7,!1),"/":new r.InfixStatus(!0,7,!1),"+":new r.InfixStatus(!0,6,!1),"-":new r.InfixStatus(!0,6,!1),"<":new r.InfixStatus(!0,4,!1),">":new r.InfixStatus(!0,4,!1),"<=":new r.InfixStatus(!0,4,!1),">=":new r.InfixStatus(!0,4,!1),"::":new r.InfixStatus(!0,5,!0),"=":new r.InfixStatus(!0,4,!1),"<>":new r.InfixStatus(!0,4,!1),":=":new r.InfixStatus(!0,3,!1),"^":new r.InfixStatus(!0,6,!1)},{Match:1,Bind:1,Div:1,Overflow:1,int:1,real:1,string:1,char:1,unit:1,word:1,list:1,bool:1});t.getInitialState=function(e){void 0===e&&(e={});var t=b.getNestedState();return!0===e.realEquality&&t.setStaticType("real",s,[],0,!0),t}},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.VERSION="1.5.1",t.BRANCH_NAME="master",t.COMMIT_HASH="0189955",t.BUILD_DATE="Thu 02 Apr 2020 10:46:06 PM UTC",t.COMMIT_MESSAGE="squids"},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var r=n(0),i=n(5),o=n(2),a=new Set(["abstype","and","andalso","as","case","datatype","do","else","end","exception","fn","fun","handle","if","in","infix","infixr","let","local","nonfix","of","op","open","orelse","raise","rec","then","type","val","with","withtype","while","(",")","[","]","{","}",",",":",";","...","_","|","=","=>","->","#","eqtype","functor","signature","struct","include","sharing","structure","where","sig",":>"]),s=new Set(["!","%","&","$","#","+","-","/",":","<","=",">","?","@","\\","~","`","^","|","*"]),u=new Map([["→","->"],["Λ","fn"]]),p=new Map([["α","'a"],["β","'b"],["γ","'c"],["δ","'d"],["ε","'e"],["ζ","'f"],["η","'g"],["θ","'h"],["ι","'i"],["κ","'k"],["λ","'l"],["μ","'m"],["ν","'n"],["ξ","'j"],["ο","'o"],["π","'p"],["ρ","'r"],["σ","'s"],["τ","'t"],["υ","'u"],["φ","'v"],["χ","'x"],["ψ","'q"],["ω","'w"]]);function c(e){return void 0!==e&&u.has(e)?u.get(e):e}function h(e){return void 0!==e&&p.has(e)?p.get(e):e}function f(e,t){if(void 0===t&&(t={}),void 0===e)return!1;if(e>="a"&&e<="z"||e>="A"&&e<="Z"||e>="0"&&e<="9"||"'"===e||"_"===e)return!0;if(!0===t.allowUnicode){if(s.has(e)||a.has(e)||"."===e)return!1;if(!0!==t.allowUnicodeTypeVariables||h(e)===e)return/^[\S]$/u.test(e)}return!1}function l(e,t){return void 0===t&&(t={}),void 0!==e&&s.has(e)}function d(e,t){return void 0===t&&(t={}),void 0!==e&&(" "===e||"\t"===e||"\n"===e||"\f"===e)}function y(e,t,n){return void 0===n&&(n={}),void 0!==e&&(e>="0"&&e<="9"||t&&(e>="a"&&e<="f"||e>="A"&&e<="F"))}function v(e){for(var t="";d(e.peek());)t+=e.next();return t}function m(e,t){void 0===t&&(t={});var n="";if("("===e.peek()&&"*"===e.peek(1)){n+=e.next()+e.next();for(var o=1;o>0;){var a=""+e.peek()+e.peek(1);if(void 0===e.peek()||void 0===e.peek(1))throw new r.IncompleteError("And it's just not enough.");"(*"===a?(++o,n+=e.next()):"*)"===a&&(--o,n+=e.next()),n+=e.next()}return new i.CommentToken(n)}throw new r.InternalInterpreterError("That was a bad comment...")}function w(e,t,n){void 0===n&&(n=-1);for(var r="";y(e.peek(),t)&&r.length!==n;)r+=e.next();return r}function g(e,t,n,a,s){if(void 0===n&&(n=!1),void 0===a&&(a=!1),void 0===s&&(s=!1),n&&a)throw new r.InternalInterpreterError("There is no such thing as a real word.");if(n)return new i.RealConstantToken(e,parseFloat(t));var u=parseInt(t,s?16:10);if(u>o.MAXINT)throw new r.LexerError('"'+u+'", whoa, it\'s over "'+o.MAXINT+'".');if(u<o.MININT)throw new r.LexerError('"'+u+'", whoa, it\'s under "'+o.MININT+'".');if(a)return new i.WordConstantToken(e,u);var p=e.charAt(0);return y(p,!1)&&"0"!==p?new i.NumericToken(e,u):new i.IntegerConstantToken(e,u)}function T(e,t){void 0===t&&(t={});var n="",r="",i=!1,o=!1,a=!1,s=!1;if("~"===e.peek()&&(n+=e.next(),s=!0,r+="-"),"0"===e.peek()&&("w"===e.peek(1)||"x"===e.peek(1))){n+=e.next(),"w"===e.peek()&&(o=!0),"x"===e.peek(o?1:0)&&(i=!0);var u=o&&i?2:1;if(s&&o||!y(e.peek(u),i))return g(n,r+="0",!1,!1,!1);for(var p=0;p<u;++p)n+=e.next()}var c=w(e,i);if(r+=c,n+=c,i||o)return g(n,r,!1,o,i);if("."===e.peek()){if(!y(e.peek(1),!1))return g(n,r);n+=e.peek(),r+=e.next(),n+=c=w(e,!1),r+=c,a=!0}if("e"===e.peek()||"E"===e.peek()){if(y(e.peek(1),!1))n+=e.next(),r+="e",n+=c=w(e,!1),r+=c;else{if("~"!==e.peek(1)||!y(e.peek(2),!1))return g(n,r,a);r+="e-",n+=e.next()+e.next(),n+=c=w(e,!1),r+=c}a=!0}return g(n,r,a)}function E(e,t){if(void 0===t&&(t={}),'"'!==e.next())throw new r.InternalInterpreterError("That was not a string.");for(var n='"',o="";'"'!==e.peek();)if("\\"===e.peek())if(n+=e.next(),d(e.peek())){if(n+=v(e),"\\"!==e.peek()){var a=e.next();throw new r.LexerError('Found non-whitespace character "'+a+'" in whitespace escape sequence.')}n+=e.next()}else{switch(h=e.peek()){case"a":n+=e.next(),o+="";break;case"b":n+=e.next(),o+="\b";break;case"t":n+=e.next(),o+="\t";break;case"n":n+=e.next(),o+="\n";break;case"v":n+=e.next(),o+="\v";break;case"f":n+=e.next(),o+="\f";break;case"r":n+=e.next(),o+="\r";break;case'"':n+=e.next(),o+='"';break;case"\\":n+=e.next(),o+="\\";break;case"^":n+=e.next();var s=(c=e.next()).charCodeAt(0);if(s<64||s>95)throw new r.LexerError('"'+String.fromCharCode(s)+'" does not represent a valid control character.');n+=c,o+=String.fromCharCode(s-64);break;case"u":if(n+=e.next(),4!==(p=w(e,!0,4)).length)throw new r.LexerError("A Unicode escape sequence must consist of four digits.");var u=parseInt(p,16);n+=p,o+=String.fromCharCode(u);break;default:if(!y(h,!1))throw h=e.next(),new r.LexerError('Invalid escape sequence "\\'+h+'".');var p;if(3!==(p=w(e,!1,3)).length)throw new r.LexerError("A numeric escape sequence must consist of three digits.");u=parseInt(p,10);n+=p,o+=String.fromCharCode(u)}}else{var c,h=(c=e.next()).charCodeAt(0);if(n+=c,(h<33||h>126)&&32!==h&&h<128){var f="";throw 9===h&&(f=" (tab)"),10===h&&(f=" (newline)"),13===h&&(f=" (carriage return)"),new r.LexerError('A string may not contain the character "'+h+'"'+f+".")}o+=String.fromCharCode(h)}if('"'!==e.next())throw new r.InternalInterpreterError("This string will never end.");return new i.StringConstantToken(n+'"',o)}function x(e,t){if(void 0===t&&(t={}),"#"!==e.next())throw new r.InternalInterpreterError("That was not a character.");var n=E(e);if(1!==n.value.length)throw new r.LexerError('"'+n.value+'" is not a valid character constant, as its length '+n.value.length+" is larger than the expected length 1.");return new i.CharacterConstantToken("#"+n.text,n.value)}function S(e,t){void 0===t&&(t={});var n,o="",s=e.peek();if(!0===t.allowUnicodeTypeVariables&&h(s)!==s)return e.next(),new i.TypeVariableToken(h(s));if(!0===t.allowUnicode&&c(s)!==s)return e.next(),new i.KeywordToken(c(s));if(l(s,t))n=l;else{if(!f(s,t)||y(s,!1,t)||"_"===s){if(void 0!==s&&a.has(s))return new i.KeywordToken(e.next());if("."===s&&"."===e.peek(1)&&"."===e.peek(2))return e.next(),e.next(),e.next(),new i.KeywordToken("...");throw s=e.next(),new r.LexerError('Invalid token "'+s+'" (\\u'+s.charCodeAt(0).toString(16).toUpperCase()+").")}n=f}do{o+=e.next()}while(n(e.peek(),t));if("*"===o)return new i.StarToken;if("="===o)return new i.EqualsToken;if(a.has(o))return new i.KeywordToken(o);if("'"===s){if("'"===o.charAt(1)){if(2===o.length)throw new r.LexerError('Invalid type variable "'+o+'". Delete Her.');return new i.EqualityTypeVariableToken(o)}if(o.length>=2)return new i.TypeVariableToken(o);if(!0===t.allowUnicodeTypeVariables&&h(e.peek())!==e.peek())return new i.EqualityTypeVariableToken("'"+h(e.next()));throw new r.LexerError("The noise, it won't STOP: Invalid type variable \""+o+'".')}return f(s,t)?new i.AlphanumericIdentifierToken(o):new i.IdentifierToken(o)}function I(e,t){void 0===t&&(t={});var n=S(e,t),o=n.text;if("."===e.peek()&&"."===e.peek(1)&&"."===e.peek(2))return n;if("."!==e.peek())return n;var a=[];do{if(!(n instanceof i.AlphanumericIdentifierToken))throw new r.LexerError('Expected a structure name before "." (got "'+n.typeName()+'".');if("."===e.peek()&&"."===e.peek(1)&&"."===e.peek(2))return new i.LongIdentifierToken(o,a,n);o+=e.next(),a.push(n),o+=(n=S(e,t)).text}while("."===e.peek());if(!(n instanceof i.IdentifierToken||n instanceof i.StarToken)||n instanceof i.TypeVariableToken)throw new r.LexerError('"'+n.text+'" is not allowed in a long identifier.');return new i.LongIdentifierToken(o,a,n)}function V(e,t){if(void 0===t&&(t={}),v(e),!e.eos())return y(e.peek(),!1)||"~"===e.peek()&&y(e.peek(1),!1)?T(e,t):'"'===e.peek()?E(e,t):"#"===e.peek()&&'"'===e.peek(1)?x(e,t):"("===e.peek()&&"*"===e.peek(1)?m(e,t):I(e,t)}function k(e,t){void 0===t&&(t={});for(var n=[];!e.eos();){var r=V(e,t);if(void 0===r)break;!0!==t.allowCommentToken&&r instanceof i.CommentToken||n.push(r)}return n}t.resolveUnicodeKeyword=c,t.resolveUnicodeTypeVariable=h,t.isAlphanumeric=f,t.isSymbolic=l,t.isWhitespace=d,t.isNumber=y,t.lexComment=m,t.lexNumber=T,t.lexString=E,t.lexCharacter=x,t.lexIdentifierOrKeyword=S,t.lexLongIdentifierOrKeyword=I,t.nextToken=V,t.lexStream=k,t.lex=function(e,t){void 0===t&&(t={});var n=0;return k({peek:function(t){if(void 0===t&&(t=0),!(n+t>=e.length))return e.charAt(n+t)},next:function(){if(n>=e.length)throw new r.IncompleteError("♪ Da~ango, dango, dango, dango, da~ango daikazoku~ ♪");return n++,e.charAt(n-1)},eos:function(){return n>=e.length}},t)}},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var r=n(7),i=n(1),o=n(0),a=n(5),s=n(6),u=n(16),p=function(){function e(e,t,n,r){if(this.tokens=e,this.state=t,this.currentId=n,this.options=r,this.position=0,this.newcons=new Set,void 0===this.state)throw new o.InternalInterpreterError("What are you, stupid? Hurry up and give me a state already!")}return e.prototype.assertFinished=function(){if(this.position<=this.tokens.length-1)throw new o.ParserError('Junk after declaration: "'+this.currentToken().getText()+'".')},e.prototype.assertKeywordToken=function(e,t){if(void 0===t&&(t=void 0),!(e instanceof a.KeywordToken))throw new o.ParserError('Expected a reserved word, got "'+e.getText()+'" ('+e.typeName()+").");if(void 0!==t&&e.text!==t)throw new o.ParserError('Expected "'+t+'" but got "'+e.text+'".')},e.prototype.assertVidToken=function(e){if(!e.isVid())throw new o.ParserError('Expected an identifier, got "'+e.getText()+'" ('+e.typeName()+").")},e.prototype.assertIdentifierToken=function(e){if(!(e instanceof a.IdentifierToken))throw new o.ParserError('Expected an identifier, got "'+e.getText()+'" ('+e.typeName()+").")},e.prototype.assertVidOrLongToken=function(e){if(!(e.isVid()||e instanceof a.LongIdentifierToken))throw new o.ParserError('Expected an identifier, got "'+e.getText()+'" ('+e.typeName()+").")},e.prototype.assertIdentifierOrLongToken=function(e){if(!(e instanceof a.IdentifierToken||e instanceof a.LongIdentifierToken))throw new o.ParserError('Expected an identifier, got "'+e.getText()+'" ('+e.typeName()+").")},e.prototype.assertRecordLabelToken=function(e){if(!e.isValidRecordLabel())throw new o.ParserError('Expected a record label "'+e.getText()+'" ('+e.typeName()+").")},e.prototype.checkVidOrLongToken=function(e){return e.isVid()||e instanceof a.LongIdentifierToken},e.prototype.checkIdentifierOrLongToken=function(e){return e instanceof a.IdentifierToken||e instanceof a.LongIdentifierToken},e.prototype.checkKeywordToken=function(e,t){return void 0===t&&(t=void 0),e instanceof a.KeywordToken&&(void 0===t||e.text===t)},e.prototype.guardStarToken=function(e){return e instanceof a.StarToken?new a.IdentifierToken("*"):e},e.prototype.parseOpIdentifierToken=function(e){void 0===e&&(e=!1);var t=this.currentToken(),n=this.checkKeywordToken(t,"op");n&&++this.position,e?this.assertIdentifierOrLongToken(this.currentToken()):this.assertIdentifierToken(this.guardStarToken(this.currentToken()));var r=this.currentToken();return r.opPrefixed=n,++this.position,r},e.prototype.parseAtomicExpression=function(){var e=this.currentToken();if(this.checkKeywordToken(e,"op")){++this.position;var t=this.currentToken();return this.assertVidOrLongToken(t),t.opPrefixed=!0,++this.position,new r.ValueIdentifier(t)}if(this.checkKeywordToken(e,"{"))return++this.position,this.parseExpressionRow();if(this.checkKeywordToken(e,"(")){if(++this.position,this.checkKeywordToken(this.currentToken(),")"))return++this.position,new r.Tuple([]);for(var n=[this.parseExpression()],i=!1,s=!1;;){t=this.currentToken();if(!this.checkKeywordToken(t,",")||i){if(this.checkKeywordToken(t,";")&&!s){if(++this.position,i=!0,!this.options.allowSuccessorML||!this.checkKeywordToken(this.currentToken(),")")){n.push(this.parseExpression());continue}t=this.currentToken()}if(!this.checkKeywordToken(t,")"))throw new o.ParserError('Expected ",", ";" or ")" but got "'+t.getText()+'".');if(++this.position,1===n.length)return n[0];if(s)return new r.Tuple(n);if(i)return new r.Sequence(n);n.push(this.parseExpression())}else++this.position,s=!0,n.push(this.parseExpression())}}if(this.checkKeywordToken(e,"[")){if(++this.position,this.checkKeywordToken(this.currentToken(),"]"))return++this.position,new r.List([]);for(n=[this.parseExpression()];;){t=this.currentToken();if(!this.checkKeywordToken(t,",")){if(this.checkKeywordToken(t,"]"))return++this.position,new r.List(n);throw new o.ParserError('Expected "," or "]" but found "'+t.getText()+'".')}++this.position,n.push(this.parseExpression())}}if(this.checkKeywordToken(e,"#")){++this.position;var u=this.currentToken();if(this.options.allowVector&&this.checkKeywordToken(u,"[")){if(++this.position,this.checkKeywordToken(this.currentToken(),"]"))return++this.position,new r.Vector([]);for(n=[this.parseExpression()];;){t=this.currentToken();if(!this.checkKeywordToken(t,",")){if(this.checkKeywordToken(t,"]"))return++this.position,new r.Vector(n);throw new o.ParserError('Expected "," or "]" but found "'+t.getText()+'".')}++this.position,n.push(this.parseExpression())}}return this.assertRecordLabelToken(u),++this.position,new r.RecordSelector(u)}if(this.checkKeywordToken(e,"let")){++this.position;var p=this.state;this.state=this.state.getNestedState(this.state.id);var c=new Set;this.newcons.forEach((function(e){c=c.add(e)}));var h=this.parseDeclaration();this.assertKeywordToken(this.currentToken(),"in"),++this.position;for(var f=[this.parseExpression()],l=this.currentToken();this.checkKeywordToken(l,";");){if(++this.position,this.options.allowSuccessorML&&this.checkKeywordToken(this.currentToken(),"end")){l=this.currentToken();break}f.push(this.parseExpression()),l=this.currentToken()}return this.assertKeywordToken(l,"end"),++this.position,this.state=p,this.newcons=c,f.length>=2?new r.LocalDeclarationExpression(h,new r.Sequence(f)):new r.LocalDeclarationExpression(h,f[0])}if(e instanceof a.ConstantToken)return++this.position,new r.Constant(e);if(e.isVid()||e instanceof a.LongIdentifierToken){if(++this.position,void 0!==this.state.getInfixStatus(e)&&this.state.getInfixStatus(e).infix)throw new o.ParserError('Infix operator "'+e.getText()+'" appeared in non-infix context without "op".');return new r.ValueIdentifier(e)}throw new o.ParserError('Expected atomic expression, "'+e.getText()+'" found.')},e.prototype.parseExpressionRow=function(){for(var e=[],t=!0;;){var n=this.currentToken();if(this.checkKeywordToken(n,"}"))return++this.position,new r.Record(!0,e);if(t||!this.checkKeywordToken(n,",")){if(t=!1,!n.isValidRecordLabel())throw new o.ParserError('Expected "}", or identifier, got "'+n.getText()+'".');++this.position;var i=this.currentToken();this.assertKeywordToken(i,"="),++this.position,e.push([n.getText(),this.parseExpression()])}else++this.position}},e.prototype.parseApplicationExpression=function(){for(var e=this.parseAtomicExpression();;){var t=this.position,n=this.currentToken();if(this.checkVidOrLongToken(n)&&void 0!==this.state.getInfixStatus(n)&&this.state.getInfixStatus(n).infix)break;try{var i=this.parseAtomicExpression();e=new r.FunctionApplication(e,i)}catch(e){if(e instanceof o.IncompleteError)throw e;this.position=t;break}}return e},e.prototype.parseInfixExpression=function(){for(var e=[],t=[],n=0;;){e.push(this.parseApplicationExpression());var i=this.currentToken();if(!this.checkVidOrLongToken(i)||void 0===this.state.getInfixStatus(i)||!this.state.getInfixStatus(i).infix)break;++this.position,t.push([i,n++])}return 0===n?e[0]:new r.InfixExpression(e,t).reParse(this.state)},e.prototype.parseAppendedExpression=function(){var e=this.currentToken();if(this.checkKeywordToken(e,"raise"))return++this.position,new r.RaiseException(this.parseExpression());if(this.checkKeywordToken(e,"if")){++this.position;var t=this.parseExpression();this.assertKeywordToken(this.currentToken(),"then"),++this.position;var n=this.parseExpression();return this.options.allowSuccessorML&&!this.checkKeywordToken(this.currentToken(),"else")?new r.Conditional(t,n,new r.Tuple([])):(this.assertKeywordToken(this.currentToken(),"else"),++this.position,new r.Conditional(t,n,this.parseExpression()))}if(this.checkKeywordToken(e,"case")){++this.position;t=this.parseExpression();return this.assertKeywordToken(this.currentToken(),"of"),++this.position,new r.CaseAnalysis(t,this.parseMatch())}if(this.checkKeywordToken(e,"while")){++this.position;t=this.parseExpression();return this.assertKeywordToken(this.currentToken(),"do"),++this.position,new r.While(t,this.parseExpression())}if(this.checkKeywordToken(e,"fn"))return++this.position,new r.Lambda(this.parseMatch());for(var i=this.parseInfixExpression(),o=this.currentToken();this.checkKeywordToken(o,":");)++this.position,i=new r.TypedExpression(i,this.parseType()),o=this.currentToken();return i},e.prototype.parseExpression=function(){var e=this.parseAppendedExpression(),t=this.currentToken();if(this.checkKeywordToken(t,"andalso")||this.checkKeywordToken(t,"orelse")){for(var n=[[e,[0]]],i=[],o=0;;){if(this.checkKeywordToken(t,"orelse"))i.push([1,o++]),++this.position;else{if(!this.checkKeywordToken(t,"andalso"))break;i.push([0,o++]),++this.position}n.push([this.parseAppendedExpression(),[o]]),t=this.currentToken()}i.sort();for(var a=0;a<i.length;++a){var s=n[i[a][1]][0],u=n[i[a][1]+1][0],p=void 0;p=0===i[a][0]?new r.Conjunction(s,u):new r.Disjunction(s,u);for(var c=n[i[a][1]][1],h=0,f=n[i[a][1]+1][1];h<f.length;h++){var l=f[h];c.push(l)}for(var d=0,y=c;d<y.length;d++){n[l=y[d]]=[p,c]}}e=n[0][0]}for(t=this.currentToken();this.checkKeywordToken(t,"handle");)++this.position,e=new r.HandleException(e,this.parseMatch()),t=this.currentToken();return e},e.prototype.parseSimpleStructureExpression=function(){var e=this.currentToken();if(this.checkKeywordToken(e,"struct")){++this.position;var t=this.parseDeclaration(!1,!0);return this.assertKeywordToken(this.currentToken(),"end"),++this.position,new u.StructureExpression(t)}if(this.checkKeywordToken(e,"let")){++this.position;t=this.parseDeclaration(!1,!0);this.assertKeywordToken(this.currentToken(),"in"),++this.position;var n=this.parseStructureExpression();return this.assertKeywordToken(this.currentToken(),"end"),++this.position,new u.LocalDeclarationStructureExpression(t,n)}if(e instanceof a.IdentifierToken)if(++this.position,this.checkKeywordToken(this.currentToken(),"(")){++this.position;var r=this.position;try{n=this.parseStructureExpression();return this.assertKeywordToken(this.currentToken(),")"),++this.position,new u.FunctorApplication(e,n)}catch(n){this.position=r;t=this.parseDeclaration(!1,!0);return this.assertKeywordToken(this.currentToken(),")"),++this.position,new u.FunctorApplication(e,new u.StructureExpression(t))}}else--this.position;if(this.checkIdentifierOrLongToken(e))return++this.position,new u.StructureIdentifier(e);throw new o.ParserError("Expected a simple structure expression.")},e.prototype.parseStructureExpression=function(){for(var e=this.parseSimpleStructureExpression();;)if(this.checkKeywordToken(this.currentToken(),":"))++this.position,e=new u.TransparentConstraint(e,this.parseSignatureExpression());else{if(!this.checkKeywordToken(this.currentToken(),":>"))break;++this.position,e=new u.OpaqueConstraint(e,this.parseSignatureExpression())}return e},e.prototype.parseSimpleSignatureExpression=function(){var e=this.currentToken();if(this.checkKeywordToken(e,"sig")){++this.position;var t=this.parseSpecification();return this.assertKeywordToken(this.currentToken(),"end"),++this.position,new u.SignatureExpression(t)}if(e instanceof a.IdentifierToken)return++this.position,new u.SignatureIdentifier(e);throw new o.ParserError("Expected a simple signature expression.")},e.prototype.parseSignatureExpression=function(){for(var e=this.parseSimpleSignatureExpression(),t=!0;this.checkKeywordToken(this.currentToken(),"where")||!t&&this.checkKeywordToken(this.currentToken(),"and");){t=!1,++this.position,this.assertKeywordToken(this.currentToken(),"type"),++this.position;var n=this.parseTypeVarSequence();this.assertIdentifierOrLongToken(this.currentToken());var r=this.currentToken();++this.position,this.assertKeywordToken(this.currentToken(),"="),++this.position,e=new u.TypeRealisation(e,n,r,this.parseType())}return e},e.prototype.parseSimpleSpecification=function(){var e=this.currentToken();if(this.checkKeywordToken(e,"val")){++this.position;for(var t=[];;){this.assertIdentifierOrLongToken(this.currentToken());var n=this.currentToken();if(++this.position,this.assertKeywordToken(this.currentToken(),":"),++this.position,t.push([n,this.parseType()]),!this.checkKeywordToken(this.currentToken(),"and"))break;++this.position}return new u.ValueSpecification(t)}if(this.checkKeywordToken(e,"type")){++this.position;t=[];for(var r=this.position;;){var i=this.parseTypeVarSequence();if(this.assertIdentifierToken(this.currentToken()),t.push([i,this.currentToken()]),++this.position,this.checkKeywordToken(this.currentToken(),"=")){var o=[];for(this.position=r;;){i=this.parseTypeVarSequence(),this.assertIdentifierToken(this.currentToken());n=this.currentToken();if(++this.position,this.assertKeywordToken(this.currentToken(),"="),++this.position,o.push([i,n,this.parseType()]),!this.checkKeywordToken(this.currentToken(),"and"))break;++this.position}return new u.TypeAliasSpecification(o)}if(!this.checkKeywordToken(this.currentToken(),"and"))break;++this.position}return new u.TypeSpecification(t)}if(this.checkKeywordToken(e,"eqtype")){++this.position;for(t=[];;){i=this.parseTypeVarSequence();if(this.assertIdentifierToken(this.currentToken()),t.push([i,this.currentToken()]),++this.position,!this.checkKeywordToken(this.currentToken(),"and"))break;++this.position}return new u.EqualityTypeSpecification(t)}if(this.checkKeywordToken(e,"datatype")){if(++this.position,this.position+2<this.tokens.length&&this.checkKeywordToken(this.tokens[this.position+2],"datatype")){this.assertIdentifierToken(this.currentToken());var a=this.currentToken();++this.position,this.assertKeywordToken(this.currentToken(),"="),++this.position,this.assertKeywordToken(this.currentToken(),"datatype"),++this.position,this.assertIdentifierOrLongToken(this.currentToken());var s=this.currentToken();return++this.position,new u.DatatypeReplicationSpecification(a,s)}for(t=[];;){i=this.parseTypeVarSequence();this.assertIdentifierToken(this.currentToken());a=this.currentToken();++this.position,this.assertKeywordToken(this.currentToken(),"="),++this.position,!0===this.options.allowSuccessorML&&this.checkKeywordToken(this.currentToken(),"|")&&++this.position;for(var p=[];;){this.assertIdentifierToken(this.currentToken());var c=this.currentToken();++this.position;var h=void 0;if(this.checkKeywordToken(this.currentToken(),"of")&&(++this.position,h=this.parseType()),p.push([c,h]),!this.checkKeywordToken(this.currentToken(),"|"))break;++this.position}if(t.push([i,a,p]),!this.checkKeywordToken(this.currentToken(),"and"))break;++this.position}return new u.DatatypeSpecification(t)}if(this.checkKeywordToken(e,"exception")){++this.position;for(t=[];;){this.assertIdentifierToken(this.currentToken());a=this.currentToken();++this.position;h=void 0;if(this.checkKeywordToken(this.currentToken(),"of")&&(++this.position,h=this.parseType()),t.push([a,h]),!this.checkKeywordToken(this.currentToken(),"and"))break;++this.position}return new u.ExceptionSpecification(t)}if(this.checkKeywordToken(e,"structure")){++this.position;for(t=[];;){this.assertIdentifierToken(this.currentToken());a=this.currentToken();if(++this.position,this.assertKeywordToken(this.currentToken(),":"),++this.position,t.push([a,this.parseSignatureExpression()]),!this.checkKeywordToken(this.currentToken(),"and"))break;++this.position}return new u.StructureSpecification(t)}if(this.checkKeywordToken(e,"include")){++this.position;var f=[],l=this.position;try{for(;;)f.push(this.parseSignatureExpression()),l=this.position}catch(e){this.position=l}return new u.IncludeSpecification(f)}return new u.EmptySpecification},e.prototype.parseSequentialSpecification=function(){for(var e=[];;){var t=this.parseSimpleSpecification();if(t instanceof u.EmptySpecification)break;e.push(t),this.checkKeywordToken(this.currentToken(),";")&&++this.position}return new u.SequentialSpecification(e)},e.prototype.parseSpecification=function(){for(var e=this.parseSequentialSpecification();this.checkKeywordToken(this.currentToken(),"sharing");){++this.position,this.assertKeywordToken(this.currentToken(),"type"),++this.position,this.assertIdentifierOrLongToken(this.currentToken());var t=[this.currentToken()];for(++this.position;this.checkKeywordToken(this.currentToken(),"=");)++this.position,this.assertIdentifierOrLongToken(this.currentToken()),t.push(this.currentToken()),++this.position;if(t.length<2)throw new o.ParserError('A "sharing" expression requires at least 2 type names.');e=new u.SharingSpecification(e,t)}return e},e.prototype.parseMatch=function(){this.options.allowSuccessorML&&this.checkKeywordToken(this.currentToken(),"|")&&++this.position;for(var e=[];;){var t=this.parsePattern();t.simplify().assertUniqueBinding(this.state,this.newcons),this.assertKeywordToken(this.currentToken(),"=>"),++this.position;var n=this.parseExpression();if(e.push([t,n]),!this.checkKeywordToken(this.currentToken(),"|"))break;++this.position}return new r.Match(e)},e.prototype.parsePatternRow=function(){for(var e=[],t=!0,n=!0;;){var i=this.currentToken();if(this.checkKeywordToken(i,"}"))return++this.position,new r.Record(n,e);if(!n)throw new o.ParserError("Record wildcard must appear as last element of the record.");if(t||!this.checkKeywordToken(i,","))if(t=!1,this.checkKeywordToken(i,"..."))n=!1,++this.position;else{if(!i.isValidRecordLabel()){if(this.checkKeywordToken(i,"as")&&this.options.allowSuccessorML)throw new o.ParserError("Layered pattern inside of record patters are disallowed in SuccessorML mode.");throw new o.ParserError('Expected "}", "...", "as", or an identifier, got "'+i.getText()+'".')}++this.position;var s=this.currentToken();if(!(s instanceof a.KeywordToken))throw new o.ParserError('Expected ":", "as", ",", or "=", got '+s.getText()+'".');if("="===s.text){++this.position,e.push([i.getText(),this.parsePattern()]);continue}var u=void 0;if(i instanceof a.NumericToken)throw new o.ParserError('You cannot assign to "'+i.getText()+'".');var p=new r.ValueIdentifier(i);":"===s.text&&(++this.position,u=this.parseType(),s=this.currentToken()),"as"!==s.text||this.options.allowSuccessorML?void 0!==u&&(p=new r.TypedExpression(p,u)):(++this.position,p=new r.LayeredPattern(p.name,u,this.parsePattern()),s=this.currentToken()),e.push([i.getText(),p])}else++this.position}},e.prototype.parseAtomicPattern=function(){if(this.position>=this.tokens.length)throw new o.ParserError("Unexpected end of token stream");var e=this.currentToken();if(this.checkKeywordToken(e,"op")){++this.position;var t=this.currentToken();this.assertVidOrLongToken(t),t.opPrefixed=!0,++this.position;var n=this.position;try{if(!(t instanceof a.LongIdentifierToken)){var i=this.currentToken(),s=void 0;return this.checkKeywordToken(i,":")&&(++this.position,s=this.parseType(),i=this.currentToken()),this.assertKeywordToken(i,"as"),++this.position,new r.LayeredPattern(t,s,this.parsePattern())}}catch(e){this.position=n}return new r.ValueIdentifier(t)}if(this.checkKeywordToken(e,"_"))return++this.position,new r.Wildcard;if(this.checkKeywordToken(e,"{"))return++this.position,this.parsePatternRow();if(this.checkKeywordToken(e,"(")){if(++this.position,this.checkKeywordToken(this.currentToken(),")"))return++this.position,new r.Tuple([]);for(var u=[this.parsePattern()];;){t=this.currentToken();if(!this.checkKeywordToken(t,",")){if(this.checkKeywordToken(t,")"))return++this.position,1===u.length?u[0]:new r.Tuple(u);throw new o.ParserError('Expected "," or ")", but got "'+t.getText()+'".')}++this.position,u.push(this.parsePattern())}}if(this.options.allowVector&&this.checkKeywordToken(e,"#")&&this.checkKeywordToken(this.nextToken(),"[")){if(++this.position,++this.position,this.checkKeywordToken(this.currentToken(),"]"))return++this.position,new r.Vector([]);for(u=[this.parsePattern()];;){t=this.currentToken();if(!this.checkKeywordToken(t,",")){if(this.checkKeywordToken(t,"]"))return++this.position,new r.Vector(u);throw new o.ParserError('Expected "," or "]" but found "'+t.getText()+'".')}++this.position,u.push(this.parsePattern())}}if(this.checkKeywordToken(e,"[")){if(++this.position,this.checkKeywordToken(this.currentToken(),"]"))return++this.position,new r.List([]);for(u=[this.parsePattern()];;){t=this.currentToken();if(!this.checkKeywordToken(t,",")){if(this.checkKeywordToken(t,"]"))return++this.position,new r.List(u);throw new o.ParserError('Expected "," or "]" but found "'+t.getText()+'".')}++this.position,u.push(this.parsePattern())}}else{if(e instanceof a.ConstantToken){if(e instanceof a.RealConstantToken&&!0!==this.options.realEquality)throw new o.ParserError('I am not interested in real constants such as "'+e.getText()+'" appearing in patterns.');return++this.position,new r.Constant(e)}if(e.isVid()&&"="!==e.getText()||e instanceof a.LongIdentifierToken){++this.position;n=this.position;try{if(!(e instanceof a.LongIdentifierToken)){i=this.currentToken(),s=void 0;return this.checkKeywordToken(i,":")&&(++this.position,s=this.parseType(),i=this.currentToken()),this.assertKeywordToken(i,"as"),++this.position,e instanceof a.KeywordToken&&(e=new a.IdentifierToken(e.getText())),new r.LayeredPattern(e,s,this.parsePattern())}}catch(e){this.position=n}return new r.ValueIdentifier(e)}}throw new o.ParserError('Expected atomic pattern but got "'+e.getText()+'".')},e.prototype.parseApplicationPattern=function(){var e=this.position,t=this.currentToken(),n=this.parseAtomicPattern();if(n instanceof r.ValueIdentifier&&void 0!==this.state.getInfixStatus(n.name)&&this.state.getInfixStatus(n.name).infix&&!(e>0&&this.checkKeywordToken(this.tokens[e-1],"op")||this.checkKeywordToken(t,"op")))throw new o.ParserError('Infix operator "'+n+'" appeared in non-infix context without "op".');for(;;){var i=this.position,a=this.currentToken();if(this.checkVidOrLongToken(a)&&void 0!==this.state.getInfixStatus(a)&&this.state.getInfixStatus(a).infix)break;var s=!1;try{var u=this.parseAtomicPattern();if(n instanceof r.Wildcard)throw s=!0,new o.ParserError("You cannot apply a pattern to a wildcard.");n=new r.FunctionApplication(n,u)}catch(e){if(s)throw e;this.position=i;break}}return n},e.prototype.parseInfixPattern=function(){for(var e=[],t=[],n=0;;){e.push(this.parseApplicationPattern());var i=this.currentToken();if(!this.checkIdentifierOrLongToken(i)||void 0===this.state.getInfixStatus(i)||!this.state.getInfixStatus(i).infix)break;++this.position,t.push([i,n++])}return 0===n?e[0]:new r.InfixExpression(e,t).reParse(this.state)},e.prototype.parsePattern=function(){for(var e=this.parseInfixPattern();;){if(!this.checkKeywordToken(this.currentToken(),":")){if(!0===this.options.allowSuccessorML){if(this.checkKeywordToken(this.currentToken(),"as")){++this.position,e=new r.ConjunctivePattern(e,this.parsePattern());continue}if(this.checkKeywordToken(this.currentToken(),"|")){++this.position,e=new r.DisjunctivePattern(e,this.parseInfixPattern());continue}if(this.checkKeywordToken(this.currentToken(),"with")){++this.position;var t=this.parsePattern();this.assertKeywordToken(this.currentToken(),"="),++this.position,e=new r.NestedMatch(e,t,this.parseExpression());continue}if(this.checkKeywordToken(this.currentToken(),"if")){++this.position,e=new r.PatternGuard(e,this.parseExpression());continue}}break}++this.position,e=new r.TypedExpression(e,this.parseType())}return e},e.prototype.parseTypeRow=function(){for(var e=new Map,t=!0;;){var n=this.currentToken();if(this.checkKeywordToken(n,"}"))return++this.position,new i.RecordType(e,!0);if(t||!this.checkKeywordToken(n,",")){if(t=!1,n.isValidRecordLabel()){++this.position;var r=this.currentToken();if(!(r instanceof a.KeywordToken))throw new o.ParserError('Expected ":".');if(":"===r.text){if(++this.position,e.has(n.getText()))throw new o.ParserError('Duplicate record label "'+n.getText()+'".');e.set(n.getText(),this.parseType());continue}throw new o.ParserError('Expected ":".')}throw new o.ParserError('Expected "}", or an identifier, got "'+n.getText()+'".')}++this.position}},e.prototype.parseSimpleType=function(){var e=this.currentToken();if(e instanceof a.TypeVariableToken)return++this.position,new i.TypeVariable(e.getText());if(this.checkIdentifierOrLongToken(e))return++this.position,e instanceof a.LongIdentifierToken?new i.CustomType(e.id.getText(),[],e):new i.CustomType(e.getText(),[]);if(this.checkKeywordToken(e,"{"))return++this.position,this.parseTypeRow();if(this.checkKeywordToken(e,"(")){if(++this.position,this.checkKeywordToken(this.currentToken(),")"))throw new o.ParserError('Use "{}" or "unit" to denote the unit type.');for(var t=[this.parseType()];;){var n=this.currentToken();if(!this.checkKeywordToken(n,",")){if(this.checkKeywordToken(n,")")){if(++this.position,1===t.length)return t[0];this.assertIdentifierOrLongToken(this.currentToken());var r=this.currentToken();return++this.position,new i.CustomType(r.getText(),t)}throw new o.ParserError('Expected "," or ")", got "'+n.getText()+'".')}++this.position,t.push(this.parseType())}}throw new o.ParserError('Expected either "(" or "{" got "'+e.getText()+'".')},e.prototype.parseType=function(){var e=this.parseTupleType(),t=this.currentToken();if(!this.checkKeywordToken(t,"->"))return e;++this.position;var n=this.parseType();return new i.FunctionType(e,n)},e.prototype.parseTupleType=function(){for(var e=[this.parseCustomType()];this.checkKeywordToken(this.currentToken(),"*");)++this.position,e.push(this.parseCustomType());return 1===e.length?e[0]:new i.TupleType(e)},e.prototype.parseCustomType=function(){for(var e=this.parseSimpleType();this.position<this.tokens.length;){var t=this.currentToken();if(!this.checkIdentifierOrLongToken(t))return e;++this.position,e=t instanceof a.LongIdentifierToken?new i.CustomType(t.id.getText(),[e],t):new i.CustomType(t.getText(),[e])}return e},e.prototype.parseValueBinding=function(){var e=this.currentToken();if(this.checkKeywordToken(e,"rec")){++this.position;var t=this.parseValueBinding();return t.isRecursive=!0,t}var n=this.parsePattern();return n.simplify().assertUniqueBinding(this.state,this.newcons),this.assertKeywordToken(this.currentToken(),"="),++this.position,new s.ValueBinding(!1,n,this.parseExpression())},e.prototype.parseFunctionValueBinding=function(){var e=[],t=-1,n=void 0;for(!0===this.options.allowSuccessorML&&this.checkKeywordToken(this.currentToken(),"|")&&++this.position;;){var i=[],a=void 0,u=void 0;if(this.checkKeywordToken(this.currentToken(),"(")){var p=this.position;try{var c=this.parsePattern(),h=!1,f=[];for(c instanceof r.FunctionApplication||(h=!0);!h&&c instanceof r.FunctionApplication;)f.push(c.argument),c=c.func;if(c instanceof r.ValueIdentifier||(h=!0),h)throw new o.ParserError("Nyaboron is sad. Did you forget a function name?");u=c;for(var l=f.length-1;l>=0;--l)i.push(f[l])}catch(e){var d=!1;try{this.position=p,++this.position;var y=this.parseAtomicPattern();if(this.assertVidOrLongToken(this.currentToken()),u=new r.ValueIdentifier(this.currentToken()),void 0===this.state.getInfixStatus(this.currentToken())||!this.state.getInfixStatus(this.currentToken()).infix)throw new o.ParserError('"'+this.currentToken().getText()+'" does not have infix status.');if(!0!==this.options.allowSuccessorML&&"="===this.currentToken().getText())throw d=!0,new o.FeatureDisabledError('Why would you try to rebind "="?');++this.position;var v=this.parseAtomicPattern();for(this.assertKeywordToken(this.currentToken(),")"),++this.position,i.push(new r.Tuple([y,v]));!this.checkKeywordToken(this.currentToken(),"=")&&!this.checkKeywordToken(this.currentToken(),":");){if((c=this.parseAtomicPattern())instanceof r.ValueIdentifier&&void 0!==this.state.getInfixStatus(c.name)&&this.state.getInfixStatus(c.name).infix)throw new o.ParserError('Cute little infix identifiers such as "'+c+'" sure should play somewhere else.');i.push(c)}}catch(t){if(!d)throw e;throw t}}}else{var m=this.position,w=!1,g=!1;try{var T=this.parseOpIdentifierToken();if(u=new r.ValueIdentifier(T),void 0!==this.state.getInfixStatus(u.name)&&this.state.getInfixStatus(u.name).infix&&!u.name.opPrefixed)throw w=!0,new o.ParserError('Missing "op".');for(;!this.checkKeywordToken(this.currentToken(),"=")&&!this.checkKeywordToken(this.currentToken(),":");){if((c=this.parseAtomicPattern())instanceof r.ValueIdentifier&&void 0!==this.state.getInfixStatus(c.name)&&this.state.getInfixStatus(c.name).infix)throw g=!0,new o.ParserError('Cute little infix identifiers such as "'+c+'" sure should play somewhere else.');i.push(c)}}catch(e){if(w)throw e;w=!1;try{this.position=m;y=this.parseAtomicPattern();if(this.assertVidOrLongToken(this.currentToken()),u=new r.ValueIdentifier(this.currentToken()),void 0===this.state.getInfixStatus(this.currentToken())||!this.state.getInfixStatus(this.currentToken()).infix){if(g)throw w=!0,e;throw new o.ParserError('"'+this.currentToken().getText()+'" does not have infix status.')}++this.position;v=this.parseAtomicPattern();i.push(new r.Tuple([y,v]))}catch(t){throw e}}}if(this.checkKeywordToken(this.currentToken(),":")&&(++this.position,a=this.parseType()),this.assertKeywordToken(this.currentToken(),"="),++this.position,-1===t)t=i.length;else if(2!==t&&3!==t&&t!==i.length)throw new o.ParserError("Different number of arguments.");if(0===t)throw new o.ParserError('Functions need arguments to survive. Rely on "val" instead.');if(void 0===n)n=u;else if(u.name.getText()!==n.name.getText())throw new o.ParserError('Different function names in different cases ("'+u.name.getText()+'" vs. "'+n.name.getText()+'")');if(new r.Tuple(i).simplify().assertUniqueBinding(this.state,this.newcons),e.push([i,a,this.parseExpression()]),!this.checkKeywordToken(this.currentToken(),"|"))break;++this.position}return new s.FunctionValueBinding(e,n)},e.prototype.parseTypeBinding=function(){var e=this.parseTypeVarSequence();this.assertIdentifierToken(this.currentToken());var t=this.currentToken();return++this.position,this.assertKeywordToken(this.currentToken(),"="),++this.position,new s.TypeBinding(e,t,this.parseType())},e.prototype.parseTypeBindingSeq=function(){for(var e=[];e.push(this.parseTypeBinding()),this.checkKeywordToken(this.currentToken(),"and");)++this.position;return e},e.prototype.parseExceptionBinding=function(){var e=this.parseOpIdentifierToken();if(this.checkKeywordToken(this.currentToken(),"of")){++this.position;var t=this.parseType();return new s.DirectExceptionBinding(e,t)}if(this.checkKeywordToken(this.currentToken(),"=")){++this.position;var n=this.parseOpIdentifierToken(!0);return new s.ExceptionAlias(e,n)}return new s.DirectExceptionBinding(e,void 0)},e.prototype.parseDatatypeBinding=function(){var e=this.parseTypeVarSequence();this.assertIdentifierToken(this.currentToken());var t=this.currentToken();++this.position,this.assertKeywordToken(this.currentToken(),"="),++this.position;var n=[];for(!0===this.options.allowSuccessorML&&this.checkKeywordToken(this.currentToken(),"|")&&++this.position;;){var r=this.parseOpIdentifierToken();if(this.newcons=this.newcons.add(r.getText()),this.checkKeywordToken(this.currentToken(),"of")){++this.position;var i=this.parseType();n.push([r,i])}else n.push([r,void 0]);if(!this.checkKeywordToken(this.currentToken(),"|"))break;++this.position}return new s.DatatypeBinding(e,t,n)},e.prototype.parseDatatypeBindingSeq=function(){for(var e=[];e.push(this.parseDatatypeBinding()),this.checkKeywordToken(this.currentToken(),"and");)++this.position;return e},e.prototype.parseStructureBinding=function(){this.assertIdentifierToken(this.currentToken());var e=this.currentToken();if(++this.position,this.checkKeywordToken(this.currentToken(),":")){++this.position;var t=this.parseSignatureExpression();this.assertKeywordToken(this.currentToken(),"="),++this.position;var n=this.parseStructureExpression();return new u.StructureBinding(e,new u.TransparentConstraint(n,t))}if(this.checkKeywordToken(this.currentToken(),":>")){++this.position;t=this.parseSignatureExpression();this.assertKeywordToken(this.currentToken(),"="),++this.position;n=this.parseStructureExpression();return new u.StructureBinding(e,new u.OpaqueConstraint(n,t))}return this.assertKeywordToken(this.currentToken(),"="),++this.position,new u.StructureBinding(e,this.parseStructureExpression())},e.prototype.parseStructureBindingSeq=function(){for(var e=[];e.push(this.parseStructureBinding()),this.checkKeywordToken(this.currentToken(),"and");)++this.position;return e},e.prototype.parseSignatureBinding=function(){this.assertIdentifierToken(this.currentToken());var e=this.currentToken();return++this.position,this.assertKeywordToken(this.currentToken(),"="),++this.position,new u.SignatureBinding(e,this.parseSignatureExpression())},e.prototype.parseSignatureBindingSeq=function(){for(var e=[];e.push(this.parseSignatureBinding()),this.checkKeywordToken(this.currentToken(),"and");)++this.position;return e},e.prototype.parseFunctorBinding=function(){this.assertIdentifierToken(this.currentToken());var e=this.currentToken();if(++this.position,this.assertKeywordToken(this.currentToken(),"("),++this.position,this.currentToken()instanceof a.IdentifierToken){var t=this.currentToken();++this.position,this.assertKeywordToken(this.currentToken(),":"),++this.position;var n=this.parseSignatureExpression();if(this.assertKeywordToken(this.currentToken(),")"),++this.position,this.checkKeywordToken(this.currentToken(),":")){++this.position;var r=this.parseSignatureExpression();return this.assertKeywordToken(this.currentToken(),"="),++this.position,new u.FunctorBinding(e,t,n,new u.TransparentConstraint(this.parseStructureExpression(),r))}if(this.checkKeywordToken(this.currentToken(),":>")){++this.position;r=this.parseSignatureExpression();return this.assertKeywordToken(this.currentToken(),"="),++this.position,new u.FunctorBinding(e,t,n,new u.OpaqueConstraint(this.parseStructureExpression(),r))}return this.assertKeywordToken(this.currentToken(),"="),++this.position,new u.FunctorBinding(e,t,n,this.parseStructureExpression())}var i=this.parseSpecification(),o=new u.SignatureExpression(i);this.assertKeywordToken(this.currentToken(),")"),++this.position;var p=!1,c=void 0;this.checkKeywordToken(this.currentToken(),":")?(++this.position,c=this.parseSignatureExpression()):this.checkKeywordToken(this.currentToken(),":>")&&(p=!0,++this.position,c=this.parseSignatureExpression()),this.assertKeywordToken(this.currentToken(),"="),++this.position;var h=this.parseStructureExpression(),f=new a.AlphanumericIdentifierToken("__farg");return void 0!==c&&(h=p?new u.OpaqueConstraint(h,c):new u.TransparentConstraint(h,c)),h=new u.LocalDeclarationStructureExpression(new s.OpenDeclaration([f]),h),new u.FunctorBinding(e,f,o,h)},e.prototype.parseFunctorBindingSeq=function(){for(var e=[];e.push(this.parseFunctorBinding()),this.checkKeywordToken(this.currentToken(),"and");)++this.position;return e},e.prototype.parseTypeVarSequence=function(e){void 0===e&&(e=!1);var t=this.currentToken(),n=[];if(t instanceof a.TypeVariableToken)return n.push(new i.TypeVariable(t.text)),++this.position,n;if(this.checkKeywordToken(t,"("))for(++this.position;;){if(!((t=this.currentToken())instanceof a.TypeVariableToken)){if(e)return;throw new o.ParserError("Expected a type varible.")}if(n.push(new i.TypeVariable(t.text)),++this.position,t=this.currentToken(),!this.checkKeywordToken(t,",")){if(this.checkKeywordToken(t,")")){++this.position;break}throw new o.ParserError('Expected "," or ")" but got "'+t.getText()+'".')}++this.position}return n},e.prototype.parseDeclaration=function(e,t){void 0===e&&(e=!1),void 0===t&&(t=!1);for(var n=[],r=this.currentId++;this.position<this.tokens.length;){var i=this.parseSimpleDeclaration(e,t);if(i instanceof s.EmptyDeclaration){if(this.position>=this.tokens.length||this.checkKeywordToken(this.currentToken(),"in")||this.checkKeywordToken(this.currentToken(),"end")||this.checkKeywordToken(this.currentToken(),")"))break}else n.push(i),this.checkKeywordToken(this.currentToken(),";")&&++this.position}return new s.SequentialDeclaration(n,r)},e.prototype.parseSimpleDeclaration=function(e,t){void 0===e&&(e=!1),void 0===t&&(t=!1);var n=this.currentToken(),i=this.currentId++;if(this.checkKeywordToken(n,"val")){++this.position,void 0===(l=this.parseTypeVarSequence(!0))&&(--this.position,l=[]);for(var p=[],c=!1;;){var h=this.parseValueBinding();if(h.isRecursive){c=!0;for(var f=h.pattern;f instanceof r.TypedExpression;)f=f.expression;if(!(h.expression instanceof r.Lambda))throw new o.ParserError('Using "rec" requires binding a lambda.');if(!(f instanceof r.ValueIdentifier||f instanceof r.Wildcard))throw new o.ParserError('Using "rec" requires binding to a single identifier and not "'+f.toString(0,!0)+'".')}if(h.isRecursive=c,p.push(h),!this.checkKeywordToken(this.currentToken(),"and"))break;++this.position}return new s.ValueDeclaration(l,p,i)}if(this.checkKeywordToken(n,"fun")){var l;++this.position,void 0===(l=this.parseTypeVarSequence(!0))&&(--this.position,l=[]);for(var d=[];d.push(this.parseFunctionValueBinding()),this.checkKeywordToken(this.currentToken(),"and");)++this.position;return new s.FunctionDeclaration(l,d,i)}if(this.checkKeywordToken(n,"type"))return++this.position,new s.TypeDeclaration(this.parseTypeBindingSeq(),i);if(this.checkKeywordToken(n,"datatype")){if(this.position+3<this.tokens.length&&this.checkKeywordToken(this.tokens[this.position+3],"datatype")){++this.position;var y=this.currentToken();this.assertIdentifierToken(y),++this.position,this.assertKeywordToken(this.currentToken(),"="),++this.position,this.assertKeywordToken(this.currentToken(),"datatype"),++this.position;var v=this.currentToken();return this.assertIdentifierOrLongToken(v),++this.position,new s.DatatypeReplication(y,v,i)}++this.position;var m=this.parseDatatypeBindingSeq();if(this.checkKeywordToken(this.currentToken(),"withtype")){++this.position;var w=this.parseTypeBindingSeq();return new s.DatatypeDeclaration(m,w,i)}return new s.DatatypeDeclaration(m,void 0,i)}if(this.checkKeywordToken(n,"abstype")){++this.position;var g=this.state;this.state=this.state.getNestedState(this.state.id);var T=new Set;this.newcons.forEach((function(e){T=T.add(e)}));m=this.parseDatatypeBindingSeq();var E=void 0;this.checkKeywordToken(this.currentToken(),"withtype")&&(++this.position,E=this.parseTypeBindingSeq()),this.assertKeywordToken(this.currentToken(),"with"),++this.position;var x=this.parseDeclaration();return this.assertKeywordToken(this.currentToken(),"end"),++this.position,this.state=g,this.newcons=T,new s.AbstypeDeclaration(m,E,x,i)}if(this.checkKeywordToken(n,"exception")){++this.position;for(var S=[];S.push(this.parseExceptionBinding()),this.checkKeywordToken(this.currentToken(),"and");)++this.position;return new s.ExceptionDeclaration(S,i)}if(this.checkKeywordToken(n,"local")){++this.position;g=this.state;this.state=this.state.getNestedState(this.state.id);var I=new Set;this.newcons.forEach((function(e){I=I.add(e)}));x=this.parseDeclaration(!1,t);this.assertKeywordToken(this.currentToken(),"in"),++this.position;var V=this.parseDeclaration(!1,t);return this.assertKeywordToken(this.currentToken(),"end"),++this.position,this.state=g,this.newcons=I,new s.LocalDeclaration(x,V,i)}if(this.checkKeywordToken(n,"open")){++this.position;for(var k=[];this.checkIdentifierOrLongToken(this.currentToken());)k.push(this.currentToken()),++this.position;if(0===k.length)throw new o.ParserError('Empty "open" declaration.');return new s.OpenDeclaration(k,i)}if(this.checkKeywordToken(n,"infix")){++this.position;var b=0;if(this.currentToken()instanceof a.IntegerConstantToken){if(1!==this.currentToken().text.length)throw new o.ParserError("Precedences may only be single digits.");b=this.currentToken().value,++this.position}for(k=[];this.currentToken().isVid();)k.push(this.currentToken()),++this.position;if(0===k.length)throw new o.ParserError('Empty "infix" declaration.');return(A=new s.InfixDeclaration(k,b,i)).setInfixStatus(this.state),A}if(this.checkKeywordToken(n,"infixr")){++this.position;b=0;if(this.currentToken()instanceof a.IntegerConstantToken){if(1!==this.currentToken().text.length)throw new o.ParserError("Precedences may only be single digits.");b=this.currentToken().value,++this.position}for(k=[];this.currentToken().isVid();)k.push(this.currentToken()),++this.position;if(0===k.length)throw new o.ParserError('Empty "infixr" declaration.');return(A=new s.InfixRDeclaration(k,b,i)).setInfixStatus(this.state),A}if(this.checkKeywordToken(n,"nonfix")){++this.position;for(k=[];this.currentToken().isVid();)k.push(this.currentToken()),++this.position;if(0===k.length)throw new o.ParserError('Empty "nonfix" declaration.');var A;return(A=new s.NonfixDeclaration(k,i)).setInfixStatus(this.state),A}if(this.options.allowSuccessorML&&this.checkKeywordToken(n,"do"))return++this.position,new s.Evaluation(this.parseExpression());if((!0===this.options.allowStructuresAnywhere||t)&&this.checkKeywordToken(n,"structure"))return++this.position,new u.StructureDeclaration(this.parseStructureBindingSeq());if((!0===this.options.allowSignaturesAnywhere||e)&&this.checkKeywordToken(n,"signature"))return++this.position,new u.SignatureDeclaration(this.parseSignatureBindingSeq());if((!0===this.options.allowFunctorsAnywhere||e)&&this.checkKeywordToken(n,"functor"))return++this.position,new u.FunctorDeclaration(this.parseFunctorBindingSeq());if(this.checkKeywordToken(n,";"))return++this.position,new s.EmptyDeclaration(i);if(this.checkKeywordToken(n,"in")||this.checkKeywordToken(n,"end")||this.checkKeywordToken(n,")"))return new s.EmptyDeclaration(i);if(e){if(this.position>0&&!this.checkKeywordToken(this.tokens[this.position-1],";"))throw new o.ParserError('A single top-level expression must be separated from preceeding declarations by a ";".');var L=this.parseExpression(),R=new s.ValueBinding(!1,new r.ValueIdentifier(new a.AlphanumericIdentifierToken("it")),L);return this.assertKeywordToken(this.currentToken(),";"),new s.ValueDeclaration([],[R],i)}throw new o.ParserError('Expected a declaration, found "'+n.getText()+'".')},e.prototype.currentToken=function(){if(this.position>=this.tokens.length)throw new o.IncompleteError("More input, I'm starving. ~nyan.");return this.tokens[this.position]},e.prototype.nextToken=function(){if(this.position+1>=this.tokens.length)throw new o.IncompleteError("More input, I'm starving. ~nyan.");return this.tokens[this.position+1]},e}();t.Parser=p,t.parse=function(e,t,n){void 0===n&&(n={});var r=new p(e,t,t.id,n),i=r.parseDeclaration(!0,!0);return r.assertFinished(),i}},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var r=n(3),i=n(1),o=n(2),a=n(0),s=n(4);t.ARRAY_LIB={native:function(e){var t=new r.DynamicBasis({},{},{},{},{}),n=new r.StaticBasis({},{},{},{},{}),u=new i.CustomType("array",[new i.TypeVariable("'a")]),p=new i.CustomType("list",[new i.TypeVariable("'a")]);return n.setType("array",u,[],1,!0),t.setType("array",[]),t.setValue("array",new o.PredefinedFunction("array",(function(e,t){if(e instanceof o.RecordValue&&2===e.entries.size){var n=e.getValue("1"),r=e.getValue("2");if(n instanceof o.Integer){var i=n.value;if(i<0)return[s.sizeException.construct(),!0,[]];var u=new o.ArrayValue(t.modifiable.memory[0]+1,i);t.modifiable.setNewCell(u);for(var p=0;p<i;++p)t.modifiable.setNewCell(r);return[u,!1,[]]}throw new a.InternalInterpreterError("std type mismatch")}throw new a.InternalInterpreterError("std type mismatch")})),r.IdentifierStatus.VALUE_VARIABLE),n.setValue("array",new i.FunctionType(new i.TupleType([s.intType,new i.TypeVariable("'a")]).simplify(),u),r.IdentifierStatus.VALUE_VARIABLE),t.setValue("fromList",new o.PredefinedFunction("fromList",(function(e,t){var n=new o.ArrayValue(t.modifiable.memory[0]+1,0);if(t.modifiable.setNewCell(n),e instanceof o.ConstructedValue){for(var r=e;"nil"!==r.constructorName;){if("::"!==r.constructorName)throw new a.InternalInterpreterError("std type mismatch");var i=r.argument;if(!(i instanceof o.RecordValue&&2===i.entries.size))throw new a.InternalInterpreterError("std type mismatch");var s=i.getValue("1"),u=i.getValue("2");if(!(s instanceof o.Value&&u instanceof o.ConstructedValue))throw new a.InternalInterpreterError("std type mismatch");t.modifiable.setNewCell(s),n.length++,r=u}return[n,!1,[]]}throw new a.InternalInterpreterError("std type mismatch")})),r.IdentifierStatus.VALUE_VARIABLE),n.setValue("fromList",new i.FunctionType(p,u),r.IdentifierStatus.VALUE_VARIABLE),t.setValue("sub",new o.PredefinedFunction("sub",(function(e,t){if(e instanceof o.RecordValue&&2===e.entries.size){var n=e.getValue("1"),r=e.getValue("2");if(n instanceof o.ArrayValue&&r instanceof o.Integer){var i=r.value;return i<0||i>=n.length?[s.subscriptException.construct(),!0,[]]:[t.modifiable.getCell(n.address+i),!1,[]]}throw new a.InternalInterpreterError("std type mismatch")}throw new a.InternalInterpreterError("std type mismatch")})),r.IdentifierStatus.VALUE_VARIABLE),n.setValue("sub",new i.FunctionType(new i.TupleType([u,s.intType]).simplify(),new i.TypeVariable("'a")),r.IdentifierStatus.VALUE_VARIABLE),t.setValue("update",new o.PredefinedFunction("update",(function(e,t){if(e instanceof o.RecordValue&&3===e.entries.size){var n=e.getValue("1"),r=e.getValue("2"),i=e.getValue("3");if(n instanceof o.ArrayValue&&r instanceof o.Integer){var u=r.value;return u<0||u>=n.length?[s.subscriptException.construct(),!0,[]]:(t.modifiable.setCell(n.address+u,i),[new o.RecordValue,!1,[]])}throw new a.InternalInterpreterError("std type mismatch")}throw new a.InternalInterpreterError("std type mismatch")})),r.IdentifierStatus.VALUE_VARIABLE),n.setValue("update",new i.FunctionType(new i.TupleType([u,s.intType,new i.TypeVariable("'a")]),new i.TupleType([])).simplify(),r.IdentifierStatus.VALUE_VARIABLE),t.setValue("length",new o.PredefinedFunction("length",(function(e,t){if(e instanceof o.ArrayValue)return[new o.Integer(e.length),!1,[]];throw new a.InternalInterpreterError("std type mismatch")})),r.IdentifierStatus.VALUE_VARIABLE),n.setValue("length",new i.FunctionType(u,s.intType),r.IdentifierStatus.VALUE_VARIABLE),e.setDynamicStructure("Array",t),e.setStaticStructure("Array",n),e},code:"signature ARRAY = sig\n (* eqtype 'a array = 'a array *)\n (* type 'a vector = 'a Vector.vector *)\n (* val maxLen : int *)\n val array : int * 'a -> 'a array\n val fromList : 'a list -> 'a array\n val tabulate : int * (int -> 'a) -> 'a array\n val length : 'a array -> int\n val sub : 'a array * int -> 'a\n val update : 'a array * int * 'a -> unit\n val vector : 'a array -> 'a vector\n val copy : {src : 'a array, dst : 'a array, di : int} -> unit\n val copyVec : {src : 'a vector, dst : 'a array, di : int} -> unit\n val appi : (int * 'a -> unit) -> 'a array -> unit\n val app : ('a -> unit) -> 'a array -> unit\n val modifyi : (int * 'a -> 'a) -> 'a array -> unit\n val modify : ('a -> 'a) -> 'a array -> unit\n val foldli : (int * 'a * 'b -> 'b) -> 'b -> 'a array -> 'b\n val foldri : (int * 'a * 'b -> 'b) -> 'b -> 'a array -> 'b\n val foldl : ('a * 'b -> 'b) -> 'b -> 'a array -> 'b\n val foldr : ('a * 'b -> 'b) -> 'b -> 'a array -> 'b\n val findi : (int * 'a -> bool) -> 'a array -> (int * 'a) option\n val find : ('a -> bool) -> 'a array -> 'a option\n val exists : ('a -> bool) -> 'a array -> bool\n val all : ('a -> bool) -> 'a array -> bool\n val collate : ('a * 'a -> order) -> 'a array * 'a array -> order\n end;\n\n structure Array :> ARRAY = struct\n open Array;\n fun tabulate (n, f) = fromList (List.tabulate (n, f));\n\n fun vector arr = Vector.tabulate (length arr, fn i => sub (arr, i));\n\n fun copy {src, dst, di} = if di < 0 orelse length dst < di + length src then raise Subscript\n else\n let\n val len = length src\n fun loop index = if index = len then ()\n else ( update(dst, index + di, sub(src, index)); loop (index + 1))\n in\n loop 0\n end;\n fun copyVec {src, dst, di} = if di < 0 orelse length dst < di + Vector.length src then raise Subscript\n else\n let\n val len = Vector.length src\n fun loop index = if index = len then ()\n else ( update(dst, index + di, Vector.sub(src, index)); loop (index + 1))\n in\n loop 0\n end;\n\n fun appi p arr = let\n val len = length arr\n fun loop index = if index = len then ()\n else (p(index, sub(arr, index)); loop (index +1))\n in\n loop 0\n end;\n fun app p = appi (fn (_, v) => p v);\n\n fun modifyi p arr =\n let\n val len = length arr\n fun loop index = if index = len then ()\n else ( update(arr, index, p(index, sub(arr, index))); loop (index +1))\n in\n loop 0\n end;\n\n fun modifyi p arr =\n let\n val len = length arr\n fun loop index = if index = len then ()\n else ( update(arr, index, p(index, sub(arr, index))); loop (index +1))\n in\n loop 0\n end;\n fun modify p = modifyi (fn (_, v) => p v);\n\n fun foldli f init arr =\n let\n val len = length arr\n fun loop (i, b) =\n if i = len then b\n else loop (i + 1, f (i, sub (arr, i), b))\n in\n loop (0, init)\n end;\n fun foldri f init arr =\n let\n val len = length arr\n fun loop (i, b) =\n if i = ~1 then b\n else loop (i - 1, f (i, sub (arr, i), b))\n in\n loop (len - 1, init)\n end;\n fun foldl f init arr = foldli (fn (_, a, x) => f(a, x)) init arr;\n fun foldr f init arr = foldri (fn (_, a, x) => f(a, x)) init arr;\n\n fun findi f arr =\n let\n val len = length arr\n fun loop index =\n if index = Array.length arr then NONE\n else\n let\n val el = sub(arr, index)\n in\n if f (index, el) then SOME (index, el) else loop (index+1)\n end\n in\n loop 0\n end;\n fun find f arr = case findi (fn (_, v) => f v) arr of NONE => NONE\n | SOME (_, v) => SOME v;\n fun exists p arr = case find p arr of NONE => false\n | SOME _ => true;\n\n fun all p = foldl (fn (v, acc) => p v andalso acc) true;\n fun collate p (a1, a2) =\n let\n val length1 = length a1\n val length2 = length a2\n fun loop index =\n if index = length1 andalso index = length2 then EQUAL\n else if index = length1 then LESS\n else if index = length2 then GREATER\n else case p (sub (a1, index), sub (a2, index)) of\n EQUAL => loop (index + 1)\n | l => l\n in\n loop 0\n end;\n end;",requires:["Option","List","Vector"]}},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var r=n(3),i=n(1),o=n(2),a=n(0),s=n(4);t.CHAR_LIB={native:function(e){return e.setDynamicValue("ord",new o.PredefinedFunction("ord",(function(e,t){if(e instanceof o.CharValue){var n=e.value;return[new o.Integer(n.charCodeAt(0)),!1,[]]}throw new a.InternalInterpreterError("std type mismatch")})),r.IdentifierStatus.VALUE_VARIABLE),e.setStaticValue("ord",new i.FunctionType(s.charType,s.intType),r.IdentifierStatus.VALUE_VARIABLE),e.setDynamicValue("chr",new o.PredefinedFunction("chr",(function(e,t){if(e instanceof o.Integer){var n=e.value;return n<0||n>255?[s.chrException.construct(),!0,[]]:[new o.CharValue(String.fromCharCode(n)),!1,[]]}throw new a.InternalInterpreterError("std type mismatch")})),r.IdentifierStatus.VALUE_VARIABLE),e.setStaticValue("chr",new i.FunctionType(s.intType,s.charType),r.IdentifierStatus.VALUE_VARIABLE),e},code:'structure Char = struct\n fun isLower c = #"a" <= c andalso c <= #"z"\n fun isUpper c = #"A" <= c andalso c <= #"Z"\n fun isDigit c = #"0" <= c andalso c <= #"9"\n fun isAlpha c = isLower c orelse isUpper c\n fun isHexDigit c = #"0" <= c andalso c <= #"9"\n orelse #"a" <= c andalso c <= #"f"\n orelse #"A" <= c andalso c <= #"F"\n fun isAlphaNum c = isAlpha c orelse isDigit c\n fun isPrint c = c >= #" " andalso c < #"\\127"\n fun isSpace c = c = #" " orelse #"\\009" <= c andalso c <= #"\\013"\n fun isGraph c = isPrint c andalso not (isSpace c)\n fun isPunct c = isGraph c andalso not (isAlphaNum c)\n fun isAscii c = c <= #"\\127"\n fun isCntrl c = c < #" " orelse c >= #"\\127"\n\n fun toLower c =\n if #"A" <= c andalso c <= #"Z" then chr (ord c + 32)\n else c;\n fun toUpper c =\n if #"a" <= c andalso c <= #"z" then chr (ord c - 32)\n else c;\n\n fun compare (a, b) = Int.compare(ord a, ord b);\n fun op< (a, b) = Int.compare(ord a, ord b) = LESS;\n fun op> (a, b) = Int.compare(ord a, ord b) = GREATER;\n fun op<= (a, b) = Int.compare(ord a, ord b) <> GREATER;\n fun op>= (a, b) = Int.compare(ord a, ord b) <> LESS;\n\n val ord = ord;\n val chr = chr;\n val maxOrd = 255;\n val maxChar = chr maxOrd;\n val minChar = chr 0;\n\n fun succ c = if c = maxChar then raise Chr else chr(ord c + 1)\n fun pred c = if c = minChar then raise Chr else chr(ord c - 1)\n\n fun contains s = let\n val table = Array.array(maxOrd + 1, false)\n val l = explode s\n in\n (List.app (fn x => Array.update(table, ord x, true)) l; fn c => Array.sub(table, ord c))\n end;\n fun notContains s = let\n val table = Array.array(maxOrd + 1, false)\n val l = explode s\n in\n (List.app (fn x => Array.update(table, ord x, true)) l; fn c => not (Array.sub(table, ord c)))\n end;\n end;',requires:["Int","Array","List"]}},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var r=n(3),i=n(1),o=n(2),a=n(0),s=n(11),u=n(12),p=n(6),c=n(7),h=n(4);t.EVAL_LIB={native:function(e){var t=new r.DynamicBasis({},{},{},{},{}),n=new r.StaticBasis({},{},{},{},{});return t.setValue("evalExp",new o.PredefinedFunction("symbolic_eval",(function(e,t){if(!(e instanceof o.StringValue))throw new a.InternalInterpreterError("This std type mismatch reigns supreme!");var n=e.value;try{var r=s.lex(n+";",{}),i=new u.Parser(r,t.state,t.state.id,{}).parseExpression();i=i.simplify();var h=[];h.push({next:i,params:{state:t.state.getNestedState(),modifiable:t.state.getNestedState(),recResult:void 0}});for(var f=void 0,l="",d=new Map,y=function(){var e=h.pop();if(void 0===e)throw new a.InternalInterpreterError("バトル、バトルしたい!");var t=e.next,n=e.params;n.recResult=f,f=t instanceof p.Declaration?t.evaluate(n,h):t.compute(n,h);var r=e.next.toString();if(1===n.step&&!r.includes("__arg"))if(f&&f.value)l+=r+" → "+f.value.toString(n.state)+"\n";else{var i=new Map;d.forEach((function(e,t){r.includes(t)?r=r.replace(t,e):i.set(t,e)})),d=i,l+=r+"\n"}f&&f.value&&"fn"!==f.value.toString(n.state)&&(e.next instanceof c.ValueIdentifier||e.next instanceof c.Record||d.set(e.next.toString(),f.value.toString(n.state)))};h.length>0;)y();return void 0!==f&&void 0!==f.value&&(l+=f.value.toString(void 0)+"\n"),[new o.RecordValue,!1,[new a.Warning(-2,l)]]}catch(e){return[new o.RecordValue,!1,[new a.Warning(-1,e.message)]]}})),r.IdentifierStatus.VALUE_VARIABLE),n.setValue("evalExp",new i.FunctionType(h.stringType,new i.TupleType([])).simplify(),r.IdentifierStatus.VALUE_VARIABLE),e.setDynamicStructure("Eval",t),e.setStaticStructure("Eval",n),e},code:void 0,requires:void 0}},function(e,t,n){"use strict";var r,i=this&&this.__extends||(r=function(e,t){return(r=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)t.hasOwnProperty(n)&&(e[n]=t[n])})(e,t)},function(e,t){function n(){this.constructor=e}r(e,t),e.prototype=null===t?Object.create(t):(n.prototype=t.prototype,new n)});Object.defineProperty(t,"__esModule",{value:!0});var o=n(7),a=n(6),s=n(5),u=n(1),p=n(3),c=n(0),h=n(2),f=n(9),l=function(e){function t(t){var n=e.call(this)||this;return n.structureDeclaration=t,n}return i(t,e),t.prototype.simplify=function(){return new t(this.structureDeclaration.simplify())},t.prototype.elaborate=function(e,t,n,r){var i=e.getNestedState(0).getNestedState(e.id),o=this.structureDeclaration.elaborate(i,t,n,r,!0);return e.valueIdentifierId=o[0].valueIdentifierId,[o[0].getStaticChanges(0),o[1],o[2],o[3]]},t.prototype.computeStructure=function(e,t,n){if(void 0===e.recResult){var r=e.state,i=r.getNestedState(0).getNestedState(r.id);return t.push({next:n,params:e}),void t.push({next:this.structureDeclaration,params:{state:i,modifiable:e.modifiable,recResult:void 0}})}var o=e.recResult;if(void 0===o||void 0===o.newState)throw new c.InternalInterpreterError("RAINBOW!");i=o.newState;return o.hasThrown?o.value:i.getDynamicChanges(0)},t.prototype.toString=function(){return"struct "+this.structureDeclaration+" end"},t}(o.Expression);t.StructureExpression=l;var d=function(e){function t(t){var n=e.call(this)||this;return n.identifier=t,n}return i(t,e),t.prototype.simplify=function(){return this},t.prototype.elaborate=function(e,t,n,r){var i=void 0;if(this.identifier instanceof s.LongIdentifierToken){var o=e.getAndResolveStaticStructure(this.identifier);void 0!==o&&(i=o.getStructure(this.identifier.id.getText()))}else i=e.getStaticStructure(this.identifier.getText());if(void 0===i)throw new c.ElaborationError('Undefined module "'+this.identifier.getText()+'".');return[i,[],t,n]},t.prototype.computeStructure=function(e,t,n){var r=e.state,i=void 0;if(this.identifier instanceof s.LongIdentifierToken){var o=r.getAndResolveDynamicStructure(this.identifier);void 0!==o&&(i=o.getStructure(this.identifier.id.getText()))}else i=r.getDynamicStructure(this.identifier.getText());if(void 0===i)throw new c.EvaluationError('Undefined module "'+this.identifier.getText()+'".');return i},t.prototype.toString=function(){return this.identifier.getText()},t}(o.Expression);t.StructureIdentifier=d;var y=function(e){function t(t,n){var r=e.call(this)||this;return r.structureExpression=t,r.signatureExpression=n,r}return i(t,e),t.restrict=function(e,n,r,i,o){var a=new p.StaticBasis({},{},{},{},{}),s=r.getNestedState(r.id);s.staticBasis=n;var h=r.getNestedState(r.id);for(var f in h.staticBasis=e,e.typeEnvironment)if(e.typeEnvironment.hasOwnProperty(f)){if(!n.typeEnvironment.hasOwnProperty(f))throw new c.ElaborationError('Signature mismatch: Unimplemented type "'+f+'".');var l=e.typeEnvironment[f],d=n.typeEnvironment[f];if(l.arity!==d.arity)throw new c.ElaborationError('Signature mismatch: Implementation of type "'+f+'" has the wrong arity.');try{var y=l.type,v=d.type;!(l.type instanceof u.FunctionType)&&d.type instanceof u.FunctionType&&(v=d.type.parameterType);var m=y.merge(s,i,v);a.setType(f,d.type.instantiate(h,m[1]),l.constructors,l.arity,l.allowsEquality),i=m[1]}catch(e){if(!(e instanceof Array))throw e;throw new c.ElaborationError('Signature mismatch: Wrong implementation of type "'+f+'": '+e[0])}}for(var f in e.valueEnvironment)if(e.valueEnvironment.hasOwnProperty(f)){if(!n.valueEnvironment.hasOwnProperty(f))throw new c.ElaborationError('Signature mismatch: Unimplemented value "'+f+'".');l=e.valueEnvironment[f],d=n.valueEnvironment[f];for(var w=new Map,g=l[0].getTypeVariables(),T=d[0].getTypeVariables();d[0]instanceof u.TypeVariableBind;){for(;;){var E=+o.substring(3);if(o=S="'"+o[1]+o[2]+(E+1),!i.has(S)&&!g.has(S)&&!T.has(S)){"'"===d[0].name[1]&&(S="'"+S),w=w.set(d[0].name,S);break}}d[0]=d[0].type}d[0]=d[0].replaceTypeVariables(w);for(var x=l[0];x instanceof u.TypeVariableBind;){for(;;){var S;E=+o.substring(3);if(o=S="'"+o[1]+o[2]+(E+1),!i.has(S)&&!g.has(S)&&!T.has(S)){"'"===x.name[1]&&(S="'"+S),w=w.set(x.name,S);break}}x=x.type}x=x.replaceTypeVariables(w);try{var I=x.merge(s,i,d[0]);if(I[0].getTypeVariables().size<x.getTypeVariables().size)throw new c.ElaborationError('Signature mismatch: Implementation of value "'+f+'" has type "'+I[0].normalize()[0]+'" which is less general than the required type "'+x.normalize()[0]+'".');a.setValue(f,l[0].instantiate(s,I[1]),l[1])}catch(e){if(!(e instanceof Array))throw e;throw new c.ElaborationError('Signature mismatch: Wrong implementation of value "'+f+'": '+e[0])}}for(var f in e.structureEnvironment)if(e.structureEnvironment.hasOwnProperty(f)){if(!n.structureEnvironment.hasOwnProperty(f))throw new c.ElaborationError('Unimplemented structure "'+f+'".');try{var V=t.restrict(e.getStructure(f),n.getStructure(f),s,i,o);a.setStructure(f,V[0]),i=V[2],o=V[3]}catch(e){throw new c.ElaborationError('Signature Mismatch: Wrong implementation of structure "'+f+'": '+e.message)}}return[a,[],i,o]},t.prototype.simplify=function(){return new t(this.structureExpression.simplify(),this.signatureExpression.simplify())},t.prototype.elaborate=function(e,n,r,i){var o=this.structureExpression.elaborate(e,n,r,i),a=this.signatureExpression.elaborate(e,o[2],o[3],i);return t.restrict(a[0],o[0],e,a[2],a[3])},t.prototype.computeStructure=function(e,t,n){var r=this.structureExpression.computeStructure(e,t,n);if(void 0!==r){if(r instanceof h.Value)return r;var i=this.signatureExpression.computeInterface(e.state);return r.restrict(i)}},t.prototype.toString=function(){return this.structureExpression+" : "+this.signatureExpression},t}(o.Expression);t.TransparentConstraint=y;var v=function(e){function t(t,n){var r=e.call(this)||this;return r.structureExpression=t,r.signatureExpression=n,r}return i(t,e),t.restrict=function(e,n,r,i,o){var a=new p.StaticBasis({},{},{},{},{}),s=r.getNestedState(r.id);s.staticBasis=n;var h=r.getNestedState(r.id);for(var f in h.staticBasis=e,h=h.getNestedState(r.id),e.typeEnvironment)if(e.typeEnvironment.hasOwnProperty(f)){if(!n.typeEnvironment.hasOwnProperty(f))throw new c.ElaborationError('Signature mismatch: Unimplemented type "'+f+'".');var l=e.typeEnvironment[f],d=n.typeEnvironment[f];if(l.arity!==d.arity)throw new c.ElaborationError('Signature mismatch: Implementation of type "'+f+'" has the wrong arity.');try{var y=l.type,v=d.type;!(l.type instanceof u.FunctionType)&&d.type instanceof u.FunctionType&&(v=d.type.parameterType);var m=y.merge(s,i,v);y=new u.CustomType(y.name,y.typeArguments,y.qualifiedName,!0),a.setType(f,y,[],l.arity,l.allowsEquality),h.staticBasis.setType(f,y,l.constructors,l.arity,l.allowsEquality),i=m[1]}catch(e){if(!(e instanceof Array))throw e;throw new c.ElaborationError('Signature mismatch: Wrong implementation of type "'+f+'": '+e[0])}}for(var f in e.valueEnvironment)if(e.valueEnvironment.hasOwnProperty(f)){if(!n.valueEnvironment.hasOwnProperty(f))throw new c.ElaborationError('Signature mismatch: Unimplemented value "'+f+'".');l=e.valueEnvironment[f],d=n.valueEnvironment[f];for(var w=new Map,g=l[0].getTypeVariables(),T=d[0].getTypeVariables(),E=d[0];E instanceof u.TypeVariableBind;){for(;;){var x=+o.substring(3);if(o=I="'"+o[1]+o[2]+(x+1),!i.has(I)&&!g.has(I)&&!T.has(I)){"'"===E.name[1]&&(I="'"+I),w=w.set(E.name,I);break}}E=E.type}E=E.replaceTypeVariables(w);for(var S=l[0];S instanceof u.TypeVariableBind;){for(;;){var I;x=+o.substring(3);if(o=I="'"+o[1]+o[2]+(x+1),!i.has(I)&&!g.has(I)&&!T.has(I)){"'"===S.name[1]&&(I="'"+I),w=w.set(S.name,I);break}}S=S.type}S=S.replaceTypeVariables(w);try{var V=S.merge(s,i,E);if(V[0].getTypeVariables().size<S.getTypeVariables().size)throw new c.ElaborationError('Signature mismatch: Implementation of value "'+f+'" has type "'+V[0].normalize()[0]+'" which is less general than the required type "'+l[0]+'".');a.setValue(f,l[0].instantiate(h,i),l[1])}catch(e){if(!(e instanceof Array))throw e;throw new c.ElaborationError('Signature mismatch: Wrong implementation of type "'+f+'": '+e[0])}}for(var f in e.structureEnvironment)if(e.structureEnvironment.hasOwnProperty(f)){if(!n.structureEnvironment.hasOwnProperty(f))throw new c.ElaborationError('Unimplemented structure "'+f+'".');try{var k=t.restrict(e.getStructure(f),n.getStructure(f),s,i,o);a.setStructure(f,k[0]),i=k[2],o=k[3]}catch(e){throw new c.ElaborationError('Signature Mismatch: Wrong implementation of structure "'+f+'": '+e.message)}}return[a,[],i,o]},t.prototype.simplify=function(){return new t(this.structureExpression.simplify(),this.signatureExpression.simplify())},t.prototype.elaborate=function(e,n,r,i){var o=this.structureExpression.elaborate(e,n,r,i),a=this.signatureExpression.elaborate(e,o[2],o[3],i);return t.restrict(a[0],o[0],e,a[2],a[3])},t.prototype.computeStructure=function(e,t,n){var r=this.structureExpression.computeStructure(e,t,n);if(void 0!==r){if(r instanceof h.Value)return r;var i=this.signatureExpression.computeInterface(e.state);return r.restrict(i)}},t.prototype.toString=function(){return this.structureExpression+" :> "+this.signatureExpression},t}(o.Expression);t.OpaqueConstraint=v;var m=function(e){function t(t,n){var r=e.call(this)||this;return r.functorId=t,r.structureExpression=n,r}return i(t,e),t.prototype.simplify=function(){return new t(this.functorId,this.structureExpression.simplify())},t.prototype.elaborate=function(e,t,n,r){var i=this.structureExpression.elaborate(e,t,n,r),o=e.getStaticFunctor(this.functorId.getText());if(void 0===o)throw new c.EvaluationError('Undefined functor "'+this.functorId.getText()+'".');var a=new p.StaticBasis({},{},{},{},{});a.extend(o[1]);var s=a.extend(y.restrict(o[0],i[0],e,t,n)[0]);for(var u in s.valueEnvironment)if(s.valueEnvironment.hasOwnProperty(u)){var h=s.valueEnvironment[u];if(void 0!==h&&void 0!==h[0]){var f=e.getNestedState(e.id),l={};l[o[2]]=s,f.staticBasis=new p.StaticBasis({},{},l,{},{}),s.valueEnvironment[u]=[h[0].instantiate(f,i[2]),h[1]]}}return[s,i[1],i[2],i[3]]},t.prototype.computeStructure=function(e,t,n){var r=e.state,i=r.getDynamicFunctor(this.functorId.getText());if(void 0===i)throw new c.EvaluationError('Undefined functor "'+this.functorId.getText()+'".');if(void 0===e.funappres){if(void 0===(o=this.structureExpression.computeStructure(e,t,n)))return;if(o instanceof h.Value)return o;e.funappres=o}var o=e.funappres;if(void 0===e.nstate){var a=i.state.getNestedState(i.state.id);a.setDynamicStructure(i.paramName.getText(),o.restrict(i.param)),e.nstate=a}e.state=e.nstate;var s=i.body.computeStructure(e,t,n);return e.state=r,s},t.prototype.toString=function(){return this.functorId.getText()+"( "+this.structureExpression+" )"},t}(o.Expression);t.FunctorApplication=m;var w=function(e){function t(t,n){var r=e.call(this)||this;return r.declaration=t,r.expression=n,r}return i(t,e),t.prototype.simplify=function(){return new t(this.declaration.simplify(),this.expression.simplify())},t.prototype.elaborate=function(e,t,n,r){var i=e.getNestedState(e.id);t.forEach((function(n,r){"*"===r[1]&&"*"===r[2]&&i.setStaticValue(r.substring(3),n[0].instantiate(e,t),p.IdentifierStatus.VALUE_VARIABLE)}));var o=this.declaration.elaborate(i,t,n,r);n=o[3];var a=new Map;t.forEach((function(e,t){a=a.set(t,[e[0].instantiate(o[0],o[2]),e[1]])}));var s=this.expression.elaborate(o[0],o[2],n,r);return[s[0],o[1].concat(s[1]),s[2],s[3]]},t.prototype.toString=function(){return"let "+this.declaration+" in "+this.expression+" end"},t.prototype.computeStructure=function(e,t,n){var r=e.state;if(void 0===e.ldseRes){if(void 0===e.recResult){var i=r.getNestedState(0).getNestedState(r.id);return t.push({next:n,params:e}),void t.push({next:this.declaration,params:{state:i,modifiable:e.modifiable,recResult:void 0}})}e.ldseRes=e.recResult,e.recResult=void 0}var o=e.ldseRes;if(void 0===o||void 0===o.newState)throw new c.InternalInterpreterError("Anpan.");i=o.newState;if(o.hasThrown)return o.value;e.state=i;var a=this.expression.computeStructure(e,t,n);return e.state=r,a},t}(o.Expression);t.LocalDeclarationStructureExpression=w;var g=function(e){function t(t){var n=e.call(this)||this;return n.specification=t,n}return i(t,e),t.prototype.simplify=function(){return new t(this.specification.simplify())},t.prototype.elaborate=function(e,t,n,r){return this.specification.elaborate(e,t,n,r)},t.prototype.computeInterface=function(e){return this.specification.computeInterface(e)},t.prototype.toString=function(){return"sig "+this.specification+" end"},t}(o.Expression);t.SignatureExpression=g;var T=function(e){function t(t){var n=e.call(this)||this;return n.identifier=t,n}return i(t,e),t.prototype.simplify=function(){return this},t.prototype.elaborate=function(e,t,n,r){var i=void 0;if(this.identifier instanceof s.LongIdentifierToken){var o=e.getAndResolveStaticStructure(this.identifier);void 0!==o&&(i=o.getSignature(this.identifier.id.getText()))}else i=e.getStaticSignature(this.identifier.getText());if(void 0===i)throw new c.EvaluationError('Undefined signature "'+this.identifier.getText()+'".');return[i,[],t,n]},t.prototype.computeInterface=function(e){var t=void 0;if(this.identifier instanceof s.LongIdentifierToken){var n=e.getAndResolveDynamicStructure(this.identifier);void 0!==n&&(t=n.getSignature(this.identifier.id.getText()))}else t=e.getDynamicSignature(this.identifier.getText());if(void 0===t)throw new c.EvaluationError('Undefined signature "'+this.identifier.getText()+'".');return t},t.prototype.toString=function(){return this.identifier.getText()},t}(o.Expression);t.SignatureIdentifier=T;var E=function(e){function t(t,n,r,i){var o=e.call(this)||this;return o.signatureExpression=t,o.tyvarseq=n,o.name=r,o.type=i,o}return i(t,e),t.prototype.simplify=function(){return new t(this.signatureExpression.simplify(),this.tyvarseq,this.name,this.type.simplify())},t.prototype.elaborate=function(e,t,n,r){var i=this.signatureExpression.elaborate(e,t,n,r),o=e.getNestedState(0);o.staticBasis=i[0];var a=void 0,p=i[0],h=this.name.getText();if(this.name instanceof s.LongIdentifierToken?void 0!==(p=o.getAndResolveStaticStructure(this.name))&&(a=p.getType(this.name.id.getText()),h=this.name.id.getText()):a=o.getStaticType(this.name.getText()),void 0===a||void 0===p)throw new c.ElaborationError('Undefined type "'+this.name.getText()+'".');return p.setType(h,new u.FunctionType(a.type,this.type),[],this.tyvarseq.length,a.allowsEquality),i},t.prototype.computeInterface=function(e){return this.signatureExpression.computeInterface(e)},t.prototype.toString=function(){return this.signatureExpression+" where type <stuff> "+this.name.getText()+" = "+this.type},t}(o.Expression);t.TypeRealisation=E;var x=function(e){function t(t){var n=e.call(this)||this;return n.structureBinding=t,n}return i(t,e),t.prototype.elaborate=function(e,t,n,r,i){for(var o=[],a=0;a<this.structureBinding.length;++a){var s=this.structureBinding[a].elaborate(e,t,n,r);e=s[0],o=o.concat(s[1]),t=s[2],n=s[3]}return[e,o,t,n]},t.prototype.evaluate=function(e,t){void 0===e.whichBind&&(e.whichBind=0);var n=e.whichBind,r=this.structureBinding[n].evaluate(e,t,this);if(void 0!==r){if(r.hasThrown)return r;if(e.state=r.newState,e.whichBind=e.whichBind+1,e.recResult=void 0,e.whichBind===this.structureBinding.length)return{newState:e.state,value:void 0,hasThrown:!1};t.push({next:this,params:e})}},t.prototype.simplify=function(){for(var e=[],n=0;n<this.structureBinding.length;++n)e.push(this.structureBinding[n].simplify());return new t(e)},t.prototype.toString=function(){for(var e="structure",t=0;t<this.structureBinding.length;++t)e+=" "+this.structureBinding[t];return e+";"},t}(a.Declaration);t.StructureDeclaration=x;var S=function(e){function t(t){var n=e.call(this)||this;return n.signatureBinding=t,n}return i(t,e),t.prototype.elaborate=function(e,t,n,r){void 0===t&&(t=new Map),void 0===n&&(n="'*t0"),void 0===r&&(r=new Map);for(var i=[],o=0;o<this.signatureBinding.length;++o){var a=this.signatureBinding[o].elaborate(e,t,n,r);e=a[0],i=i.concat(a[1]),t=a[2],n=a[3]}return[e,i,t,n]},t.prototype.evaluate=function(e,t){for(var n=e.state,r=0;r<this.signatureBinding.length;++r)n=this.signatureBinding[r].evaluate(n);return{newState:n,value:void 0,hasThrown:!1}},t.prototype.simplify=function(){for(var e=[],n=0;n<this.signatureBinding.length;++n)e.push(this.signatureBinding[n].simplify());return new t(e)},t.prototype.toString=function(){for(var e="structure",t=0;t<this.signatureBinding.length;++t)e+=" "+this.signatureBinding[t];return e+";"},t}(a.Declaration);t.SignatureDeclaration=S;var I=function(e){function t(t){var n=e.call(this)||this;return n.functorBinding=t,n}return i(t,e),t.prototype.elaborate=function(e,t,n,r){var i;void 0===t&&(t=new Map),void 0===n&&(n="'*t0"),void 0===r&&(r=new Map);for(var o=[],a=0;a<this.functorBinding.length;++a){var s;e=(i=this.functorBinding[a].elaborate(e,t,n,r))[0],s=i[1],t=i[2],n=i[3],o=o.concat(s)}return[e,o,t,n]},t.prototype.evaluate=function(e,t){for(var n=e.state,r=0;r<this.functorBinding.length;++r)n=this.functorBinding[r].evaluate(n);return{newState:n,value:void 0,hasThrown:!1}},t.prototype.simplify=function(){for(var e=[],n=0;n<this.functorBinding.length;++n)e.push(this.functorBinding[n].simplify());return new t(e)},t.prototype.toString=function(){for(var e="functor",t=0;t<this.functorBinding.length;++t)e+=" "+this.functorBinding[t];return e+";"},t}(a.Declaration);t.FunctorDeclaration=I;var V=function(){function e(e,t){this.name=e,this.binding=t}return e.prototype.simplify=function(){return new e(this.name,this.binding.simplify())},e.prototype.elaborate=function(e,t,n,r){var i=this.binding.elaborate(e,t,n,r);return e.setStaticStructure(this.name.getText(),i[0]),[e,i[1],i[2],i[3]]},e.prototype.evaluate=function(e,t,n){var r=this.binding.computeStructure(e,t,n);if(void 0!==r){var i=e.state;return r instanceof h.Value?{newState:i,value:r,hasThrown:!0}:(i.setDynamicStructure(this.name.getText(),r),{newState:i,value:void 0,hasThrown:!1})}},e.prototype.toString=function(){return this.name.getText()+" = "+this.binding},e}();t.StructureBinding=V;var k=function(){function e(e,t){this.name=e,this.binding=t}return e.prototype.simplify=function(){return new e(this.name,this.binding.simplify())},e.prototype.elaborate=function(e,t,n,r){var i=this.binding.elaborate(e,t,n,r);return e.setStaticSignature(this.name.getText(),i[0]),[e,i[1],i[2],i[3]]},e.prototype.evaluate=function(e){return e.setDynamicSignature(this.name.getText(),this.binding.computeInterface(e)),e},e.prototype.toString=function(){return this.name.getText()+" = "+this.binding},e}();t.SignatureBinding=k;var b=function(){function e(e,t,n,r){this.name=e,this.signatureName=t,this.signatureBinding=n,this.binding=r}return e.prototype.simplify=function(){return new e(this.name,this.signatureName,this.signatureBinding.simplify(),this.binding.simplify())},e.prototype.elaborate=function(e,t,n,r){void 0===t&&(t=new Map),void 0===n&&(n="'*t0"),void 0===r&&(r=new Map);var i=this.signatureBinding.elaborate(e,t,n,r),o=e.getNestedState(e.id);o.setStaticStructure(this.signatureName.getText(),i[0]);var a=this.binding.elaborate(o,i[2],i[3],r);return e.setStaticFunctor(this.name.getText(),[i[0],a[0],this.signatureName.getText()]),[e,i[1].concat(a[1]),a[2],a[3]]},e.prototype.evaluate=function(e){var t=this.signatureBinding.computeInterface(e),n=f.getInitialState().getNestedState(e.id);return n.dynamicBasis=e.getDynamicChanges(-1),e.setDynamicFunctor(this.name.getText(),new p.DynamicFunctorInformation(this.signatureName,t,this.binding,n)),e},e.prototype.toString=function(){return this.name.getText()+"( "+this.signatureName+" : "+this.signatureBinding+" ) = "+this.binding},e}();t.FunctorBinding=b;var A=function(){function e(){}return e.prototype.simplify=function(){return this},e}();t.Specification=A;var L=function(e){function t(t){var n=e.call(this)||this;return n.valueDescription=t,n}return i(t,e),t.prototype.elaborate=function(e,t,n,r){for(var i=new p.StaticBasis({},{},{},{},{}),o=function(n){var r=a.valueDescription[n][1].simplify().instantiate(e,t);r.getTypeVariables().forEach((function(e,t){r=new u.TypeVariableBind(t,r,e)})),i.setValue(a.valueDescription[n][0].getText(),r,p.IdentifierStatus.VALUE_VARIABLE)},a=this,s=0;s<this.valueDescription.length;++s)o(s);return[i,[],t,n]},t.prototype.computeInterface=function(e){for(var t={},n=0;n<this.valueDescription.length;++n)t[this.valueDescription[n][0].getText()]=p.IdentifierStatus.VALUE_VARIABLE;return new p.DynamicInterface({},t,{})},t}(A);t.ValueSpecification=L;var R=function(e){function t(t){var n=e.call(this)||this;return n.typeDescription=t,n}return i(t,e),t.prototype.elaborate=function(e,t,n,r){for(var i=new p.StaticBasis({},{},{},{},{}),o=0;o<this.typeDescription.length;++o)i.setType(this.typeDescription[o][1].getText(),new u.CustomType(this.typeDescription[o][1].getText(),this.typeDescription[o][0]),[],this.typeDescription[o][0].length,!1);return[i,[],t,n]},t.prototype.computeInterface=function(e){for(var t={},n=0;n<this.typeDescription.length;++n)t[this.typeDescription[n][1].getText()]=[];return new p.DynamicInterface(t,{},{})},t}(A);t.TypeSpecification=R;var B=function(e){function t(t){var n=e.call(this)||this;return n.typeDescription=t,n}return i(t,e),t.prototype.elaborate=function(e,t,n,r){for(var i=new p.StaticBasis({},{},{},{},{}),o=0;o<this.typeDescription.length;++o)i.setType(this.typeDescription[o][1].getText(),new u.CustomType(this.typeDescription[o][1].getText(),this.typeDescription[o][0]),[],this.typeDescription[o][0].length,!0);return[i,[],t,n]},t.prototype.computeInterface=function(e){for(var t={},n=0;n<this.typeDescription.length;++n)t[this.typeDescription[n][1].getText()]=[];return new p.DynamicInterface(t,{},{})},t}(A);t.EqualityTypeSpecification=B;var C=function(e){function t(t){var n=e.call(this)||this;return n.datatypeDescription=t,n}return i(t,e),t.prototype.elaborate=function(e,t,n,r){for(var i=new p.StaticBasis({},{},{},{},{}),o=0;o<this.datatypeDescription.length;++o){for(var a=[],s=new u.CustomType(this.datatypeDescription[o][1].getText(),this.datatypeDescription[o][0]),c=function(e){if(a.push(h.datatypeDescription[o][2][e][0].getText()),void 0===h.datatypeDescription[o][2][e][1]){var t=s;t.getTypeVariables().forEach((function(e,n){t=new u.TypeVariableBind(n,t,e)})),i.setValue(h.datatypeDescription[o][2][e][0].getText(),t,p.IdentifierStatus.VALUE_CONSTRUCTOR)}else{var n=new u.FunctionType(h.datatypeDescription[o][2][e][1],s);n.getTypeVariables().forEach((function(e,t){n=new u.TypeVariableBind(t,n,e)})),i.setValue(h.datatypeDescription[o][2][e][0].getText(),n,p.IdentifierStatus.VALUE_CONSTRUCTOR)}},h=this,f=0;f<this.datatypeDescription[o][2].length;++f)c(f);i.setType(this.datatypeDescription[o][1].getText(),s,a,this.datatypeDescription[o][0].length,!0)}return[i,[],t,n]},t.prototype.computeInterface=function(e){for(var t={},n={},r=0;r<this.datatypeDescription.length;++r){for(var i=[],o=0;o<this.datatypeDescription[r][2].length;++o)t[this.datatypeDescription[r][2][o][0].getText()]=p.IdentifierStatus.VALUE_CONSTRUCTOR,i.push(this.datatypeDescription[r][2][o][0].getText());n[this.datatypeDescription[r][1].getText()]=i}return new p.DynamicInterface(n,t,{})},t.prototype.simplify=function(){for(var e=[],n=0;n<this.datatypeDescription.length;++n){for(var r=[],i=0;i<this.datatypeDescription[n][2].length;++i)void 0===this.datatypeDescription[n][2][i][1]?r.push(this.datatypeDescription[n][2][i]):r.push([this.datatypeDescription[n][2][i][0],this.datatypeDescription[n][2][i][1].simplify()]);e.push([this.datatypeDescription[n][0],this.datatypeDescription[n][1],r])}return new t(e)},t}(A);t.DatatypeSpecification=C;var O=function(e){function t(t,n){var r=e.call(this)||this;return r.name=t,r.oldname=n,r}return i(t,e),t.prototype.elaborate=function(e,t,n,r){var i=void 0;if(this.oldname instanceof s.LongIdentifierToken){var o=e.getAndResolveStaticStructure(this.oldname);void 0!==o&&(i=o.getType(this.oldname.id.getText()))}else i=e.getStaticType(this.oldname.getText());if(void 0===i)throw new c.ElaborationError('The datatype "'+this.oldname.getText()+"\" doesn't exist.");var a=i.type.instantiate(e,t),h=new p.StaticBasis({},{},{},{},{});return h.setType(this.name.getText(),new u.FunctionType(new u.CustomType(this.name.getText(),a.typeArguments,this.oldname instanceof s.LongIdentifierToken?this.oldname:void 0),a),[],i.arity,i.allowsEquality),[h,[],t,n]},t.prototype.computeInterface=function(e){var t=void 0;if(this.oldname instanceof s.LongIdentifierToken){var n=e.getAndResolveDynamicStructure(this.oldname);void 0!==n&&(t=n.getType(this.oldname.id.getText()))}else t=e.getDynamicType(this.oldname.getText());if(void 0===t)throw new c.EvaluationError('The datatype "'+this.oldname.getText()+'" does not exist.');for(var r={},i=0;i<t.length;++i)r[t[i]]=p.IdentifierStatus.VALUE_CONSTRUCTOR;var o={};return o[this.name.getText()]=t,new p.DynamicInterface(o,r,{})},t}(A);t.DatatypeReplicationSpecification=O;var N=function(e){function t(t){var n=e.call(this)||this;return n.exceptionDescription=t,n}return i(t,e),t.prototype.elaborate=function(e,t,n,r){for(var i=new p.StaticBasis({},{},{},{},{}),o=function(t){if(void 0!==a.exceptionDescription[t][1]){var n=a.exceptionDescription[t][1].simplify().instantiate(e,new Map),r=[];if(n.getTypeVariables().forEach((function(e,t){r.push(t)})),r.length>0)throw c.ElaborationError.getUnguarded(r);i.setValue(a.exceptionDescription[t][0].getText(),new u.FunctionType(n,new u.CustomType("exn")).normalize()[0],p.IdentifierStatus.EXCEPTION_CONSTRUCTOR)}else i.setValue(a.exceptionDescription[t][0].getText(),new u.CustomType("exn").normalize()[0],p.IdentifierStatus.EXCEPTION_CONSTRUCTOR)},a=this,s=0;s<this.exceptionDescription.length;++s)o(s);return[i,[],t,n]},t.prototype.computeInterface=function(e){for(var t={},n=0;n<this.exceptionDescription.length;++n)t[this.exceptionDescription[n][0].getText()]=p.IdentifierStatus.EXCEPTION_CONSTRUCTOR;return new p.DynamicInterface({},t,{})},t.prototype.simplify=function(){for(var e=[],n=0;n<this.exceptionDescription.length;++n)void 0===this.exceptionDescription[n][1]?e.push(this.exceptionDescription[n]):e.push([this.exceptionDescription[n][0],this.exceptionDescription[n][1].simplify()]);return new t(e)},t}(A);t.ExceptionSpecification=N;var _=function(e){function t(t){var n=e.call(this)||this;return n.structureDescription=t,n}return i(t,e),t.prototype.elaborate=function(e,t,n,r){for(var i=new p.StaticBasis({},{},{},{},{}),o=[],a=t,s=n,u=0;u<this.structureDescription.length;++u){var c=this.structureDescription[u][1].elaborate(e,a,s,r);o.concat(c[1]),a=c[2],s=c[3],i.setStructure(this.structureDescription[u][0].getText(),c[0])}return[i,o,a,s]},t.prototype.computeInterface=function(e){for(var t={},n=0;n<this.structureDescription.length;++n)t[this.structureDescription[n][0].getText()]=this.structureDescription[n][1].computeInterface(e);return new p.DynamicInterface({},{},t)},t.prototype.simplify=function(){for(var e=[],n=0;n<this.structureDescription.length;++n)e.push([this.structureDescription[n][0],this.structureDescription[n][1].simplify()]);return new t(e)},t}(A);t.StructureSpecification=_;var P=function(e){function t(t){var n=e.call(this)||this;return n.expression=t,n}return i(t,e),t.prototype.elaborate=function(e,t,n,r){for(var i=new p.StaticBasis({},{},{},{},{}),o=[],a=0;a<this.expression.length;++a){var s=this.expression[a].elaborate(e,t,n,r);i=i.extend(s[0]),o=o.concat(s[1]),t=s[2],n=s[3]}return[i,o,t,n]},t.prototype.computeInterface=function(e){for(var t=new p.DynamicInterface({},{},{}),n=0;n<this.expression.length;++n)t=t.extend(this.expression[n].computeInterface(e));return t},t.prototype.simplify=function(){for(var e=[],n=0;n<this.expression.length;++n)e.push(this.expression[n].simplify());return new t(e)},t}(A);t.IncludeSpecification=P;var q=function(e){function t(){return e.call(this)||this}return i(t,e),t.prototype.elaborate=function(e,t,n,r){return[new p.StaticBasis({},{},{},{},{}),[],t,n]},t.prototype.computeInterface=function(e){return new p.DynamicInterface({},{},{})},t}(A);t.EmptySpecification=q;var M=function(e){function t(t){var n=e.call(this)||this;return n.specifications=t,n}return i(t,e),t.prototype.elaborate=function(e,t,n,r){for(var i=new p.StaticBasis({},{},{},{},{}),o=[],a=e,s=0;s<this.specifications.length;++s){var u=this.specifications[s].elaborate(a,t,n,r);i=i.extend(u[0]),o=o.concat(u[1]),t=u[2],n=u[3],(a=a.getNestedState(a.id)).staticBasis=u[0]}return[i,o,t,n]},t.prototype.computeInterface=function(e){for(var t=new p.DynamicInterface({},{},{}),n=0;n<this.specifications.length;++n)t=t.extend(this.specifications[n].computeInterface(e));return t},t.prototype.simplify=function(){for(var e=[],n=0;n<this.specifications.length;++n)e.push(this.specifications[n].simplify());return new t(e)},t}(A);t.SequentialSpecification=M;var U=function(e){function t(t,n){var r=e.call(this)||this;return r.specification=t,r.typeNames=n,r}return i(t,e),t.prototype.elaborate=function(e,t,n,r){var i=this.specification.elaborate(e,t,n,r),o=e.getNestedState(0);o.staticBasis=i[0];for(var a=[],p=[],h=[],f=!1,l=0;l<this.typeNames.length;++l){var d=void 0,y=i[0],v=this.typeNames[l].getText();if(this.typeNames[l]instanceof s.LongIdentifierToken?void 0!==(y=o.getAndResolveStaticStructure(this.typeNames[l]))&&(d=y.getType(this.typeNames[l].id.getText()),v=this.typeNames[l].id.getText()):d=o.getStaticType(this.typeNames[l].getText()),void 0===d||void 0===y)throw new c.ElaborationError('Undefined type "'+this.typeNames[l].getText()+'".');f=f||d.allowsEquality,a.push(d),p.push(y),h.push(v)}for(l=1;l<this.typeNames.length;++l)p[l].setType(h[l],new u.FunctionType(a[l].type,a[0].type),[],0,f);return i},t.prototype.computeInterface=function(e){return this.specification.computeInterface(e)},t}(A);t.SharingSpecification=U;var D=function(e){function t(t){var n=e.call(this)||this;return n.alias=t,n}return i(t,e),t.prototype.elaborate=function(e,t,n,r){throw new c.InternalInterpreterError("And you don't seem to understand…")},t.prototype.computeInterface=function(e){throw new c.InternalInterpreterError("Being an interpreter is suffering.")},t.prototype.simplify=function(){for(var e=[],t=0;t<this.alias.length;++t)e.push([this.alias[t][0],this.alias[t][1]]);var n=new g(new R(e));for(t=0;t<this.alias.length;++t)n=new E(n,this.alias[t][0],this.alias[t][1],this.alias[t][2]);return new P([n]).simplify()},t}(A);t.TypeAliasSpecification=D},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var r=n(3),i=n(1),o=n(2),a=n(0),s=n(4);t.INT_LIB={native:function(e){var t=new r.DynamicBasis({},{},{},{},{}),n=new r.StaticBasis({},{},{},{},{});return t.setValue("toString",new o.PredefinedFunction("toString",(function(e,t){if(e instanceof o.Integer)return[new o.StringValue(e.toString(void 0)),!1,[]];throw new a.InternalInterpreterError("std type mismatch")})),r.IdentifierStatus.VALUE_VARIABLE),n.setValue("toString",new i.FunctionType(s.intType,s.stringType),r.IdentifierStatus.VALUE_VARIABLE),e.setDynamicStructure("Int",t),e.setStaticStructure("Int",n),e},code:"structure Int = struct\n open Int;\n fun compare (x, y: int) = if x < y then LESS else if x > y then GREATER else EQUAL;\n\n val minInt = SOME ~"+-o.MININT+";\n val maxInt = SOME "+o.MAXINT+";\n fun max (x, y) = if x < y then y else x : int;\n fun min (x, y) = if x > y then y else x : int;\n end;",requires:["Option"]}},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var r=n(3),i=n(1),o=n(2);t.LIST_LIB={native:function(e){var t=new r.DynamicBasis({},{},{},{},{}),n=new r.StaticBasis({},{},{},{},{});return n.setType("list",new i.CustomType("list",[new i.TypeVariable("'a")]),["nil","::"],1,!0),n.setValue("nil",new i.TypeVariableBind("'a",new i.CustomType("list",[new i.TypeVariable("'a")])),r.IdentifierStatus.VALUE_CONSTRUCTOR),n.setValue("::",new i.TypeVariableBind("'a",new i.FunctionType(new i.TupleType([new i.TypeVariable("'a"),new i.CustomType("list",[new i.TypeVariable("'a")])]),new i.CustomType("list",[new i.TypeVariable("'a")]))).simplify(),r.IdentifierStatus.VALUE_CONSTRUCTOR),t.setType("list",["nil","::"]),t.setValue("nil",new o.ValueConstructor("nil"),r.IdentifierStatus.VALUE_CONSTRUCTOR),t.setValue("::",new o.ValueConstructor("::",1),r.IdentifierStatus.VALUE_CONSTRUCTOR),e.setDynamicStructure("List",t),e.setStaticStructure("List",n),e},code:"structure List : sig\n datatype 'a list = nil | :: of 'a * 'a list;\n val rev: 'a list -> 'a list;\n end = struct\n open List;\n fun rev' nil ys = ys\n | rev' (x::xs) ys = rev' xs (x::ys)\n fun rev xs = rev' xs nil;\n end;\n\n structure List = struct\n exception Empty;\n open List;\n\n fun hd nil = raise Empty\n | hd (x::xr) = x;\n\n fun tl nil = raise Empty\n | tl (x::xr) = xr;\n\n fun null nil = true\n | null (x::xr) = false;\n\n fun map f nil = nil\n | map f (x::xr) = (f x) :: (map f xr);\n\n infixr 5 @;\n fun [] @ ys = ys\n | (x::xr) @ ys = x :: (xr @ ys);\n\n fun length nil = 0\n | length (x::xr) = 1 + length xr;\n\n fun foldr f e [] = e\n | foldr f e (x::xr) = f(x, foldr f e xr);\n\n fun foldl f e [] = e\n | foldl f e (x::xr) = foldl f (f(x, e)) xr;\n end;\n open List;\n infixr 5 @;\n\n structure List = struct\n open List;\n\n fun concat nil = nil\n | concat (x::xr) = x @ concat xr;\n\n fun tabulate (n, f) = let\n fun h i = if i < n then f i :: h (i + 1) else []\n in\n if n < 0 then raise Size else h 0\n end;\n\n fun exists p [] = false\n | exists p (x::xr) = p x orelse exists p xr;\n\n fun all p [] = true\n | all p (x::xr) = p x andalso all p xr;\n\n fun filter p [] = []\n | filter p (x::xr) = if p x then x :: filter p xr else filter p xr;\n\n fun collate (compare : 'a * 'a -> order) p = case p of\n (nil, _::_) => LESS\n | (nil, nil) => EQUAL\n | (_::_, nil) => GREATER\n | (x::xr, y::yr) => case compare (x, y) of\n EQUAL => collate compare (xr, yr)\n | s => s;\n\n fun nth ([], _) = raise Subscript\n | nth (x::xs, 0) = x\n | nth (x::xs, n) = nth (xs, n - 1);\n\n fun last [x] = x\n | last (x::xs) = last xs\n | last [] = raise Empty;\n\n fun getItem [] = NONE\n | getItem x = SOME (hd x, tl x);\n\n fun take (x, 0) = []\n | take ([], _) = raise Subscript\n | take (x::xs, n) = x :: take (xs, n - 1);\n\n fun drop (x, 0) = x\n | drop ([], _) = raise Subscript\n | drop (x::xs, n) = drop (xs, n - 1);\n\n fun revAppend (l1, l2) = (rev l1) @ l2;\n\n fun app (f: 'a -> unit) [] = ()\n | app (f: 'a -> unit) (x::xs) = (f x; app f xs);\n\n fun mapPartial f l\n = ((map valOf) o (filter isSome) o (map f)) l;\n\n fun find f [] = NONE\n | find f (x::xs) = if f x then SOME x else find f xs;\n\n fun partition f [] = ([], [])\n | partition f (x::xs) = let\n val tmp = partition f xs\n in\n if f x then (x :: #1 tmp, #2 tmp)\n else (#1 tmp, x :: #2 tmp)\n end;\n end;",requires:["Option"]}},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.LISTSORT_LIB={native:void 0,code:"structure Listsort : sig\n val sort: ('a * 'a -> order) -> 'a list -> 'a list;\n val sorted: ('a * 'a -> order) -> 'a list -> bool;\n val mergeUniq: ('a * 'a -> order) -> 'a list * 'a list -> 'a list;\n val merge: ('a * 'a -> order) -> 'a list * 'a list -> 'a list;\n val eqclasses: ('a * 'a -> order) -> 'a list -> 'a list list;\n end = struct\n fun take ordr x1 xr [] = x1 :: xr\n | take ordr x1 xr (y1::yr) = (case ordr(x1, y1) of\n LESS => x1 :: take ordr y1 yr xr\n | _ => y1 :: take ordr x1 xr yr);\n\n fun takeUniq ordr x1 xr [] = x1 :: xr\n | takeUniq ordr x1 xr (y1::yr) = (case ordr(x1, y1) of\n LESS => x1 :: takeUniq ordr y1 yr xr\n | GREATER => y1 :: takeUniq ordr x1 xr yr\n | EQUAL => takeUniq ordr x1 xr yr);\n\n fun merge ordr ([], ys) = ys\n | merge ordr (x1::xr, ys) = take ordr x1 xr ys;\n\n fun mergeUniq ordr ([], ys) = ys\n | mergeUniq ordr (x1::xr, ys) = takeUniq ordr x1 xr ys;\n\n fun mergepairs ordr l1 [] k = [l1]\n | mergepairs ordr l1 (l2::lr) k =\n if k mod 2 = 1 then l1::l2::lr\n else mergepairs ordr (merge ordr (l1, l2)) lr (k div 2);\n\n fun nextrun ordr run [] = (run, [])\n | nextrun ordr run (x::xr) =\n if ordr(x, List.hd run) = LESS then (run, x::xr)\n else nextrun ordr (x::run) xr;\n\n fun sorting ordr [] ls r = List.hd(mergepairs ordr [] ls 0)\n | sorting ordr (x::xs) ls r = let\n val (revrun, tail) = nextrun ordr [x] xs\n in\n sorting ordr tail (mergepairs ordr (List.rev revrun) ls (r+1)) (r+1)\n end;\n\n fun group ordr last rest cs1 css = case rest of\n [] => cs1 :: css\n | r1::rr => if ordr(r1, last) = EQUAL then group ordr r1 rr (r1 :: cs1) css\n else group ordr r1 rr [r1] (cs1 :: css);\n\n fun sort ordr [] = []\n | sort ordr [x] = [x]\n | sort ordr [x1, x2] = (case ordr(x1, x2) of\n GREATER => [x2, x1]\n | _ => [x1, x2])\n | sort ordr xs = sorting ordr xs [] 0;\n\n fun sorted ordr [] = true\n | sorted ordr [x] = true\n | sorted ordr (x1::x2::xr) =\n ordr(x1, x2) <> GREATER andalso sorted ordr (x2::xr);\n\n fun eqclasses ordr xs = let\n val xs = List.rev (sort ordr xs)\n in\n case xs of\n [] => []\n | x1::xr => group ordr x1 xr [x1] []\n end;\n end;\n structure List = struct\n open List;\n open Listsort;\n end;",requires:["List"]}},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var r=n(3),i=n(1),o=n(2),a=n(0),s=n(4);t.MATH_LIB={native:function(e){var t=new r.DynamicBasis({},{},{},{},{}),n=new r.StaticBasis({},{},{},{},{});return t.setValue("sqrt",new o.PredefinedFunction("sqrt",(function(e,t){if(e instanceof o.Real){var n=e.value;return n<0?[s.domainException.construct(),!0,[]]:[new o.Real(Math.sqrt(n)),!1,[]]}throw new a.InternalInterpreterError("std type mismatch")})),r.IdentifierStatus.VALUE_VARIABLE),n.setValue("sqrt",new i.FunctionType(s.realType,s.realType),r.IdentifierStatus.VALUE_VARIABLE),t.setValue("sin",new o.PredefinedFunction("sin",(function(e,t){if(e instanceof o.Real){var n=e.value;return[new o.Real(Math.sin(n)),!1,[]]}throw new a.InternalInterpreterError("std type mismatch")})),r.IdentifierStatus.VALUE_VARIABLE),n.setValue("sin",new i.FunctionType(s.realType,s.realType),r.IdentifierStatus.VALUE_VARIABLE),t.setValue("cos",new o.PredefinedFunction("cos",(function(e,t){if(e instanceof o.Real){var n=e.value;return[new o.Real(Math.cos(n)),!1,[]]}throw new a.InternalInterpreterError("std type mismatch")})),r.IdentifierStatus.VALUE_VARIABLE),n.setValue("cos",new i.FunctionType(s.realType,s.realType),r.IdentifierStatus.VALUE_VARIABLE),t.setValue("tan",new o.PredefinedFunction("tan",(function(e,t){if(e instanceof o.Real){var n=e.value;return[new o.Real(Math.tan(n)),!1,[]]}throw new a.InternalInterpreterError("std type mismatch")})),r.IdentifierStatus.VALUE_VARIABLE),n.setValue("tan",new i.FunctionType(s.realType,s.realType),r.IdentifierStatus.VALUE_VARIABLE),t.setValue("asin",new o.PredefinedFunction("asin",(function(e,t){if(e instanceof o.Real){var n=e.value;return[new o.Real(Math.asin(n)),!1,[]]}throw new a.InternalInterpreterError("std type mismatch")})),r.IdentifierStatus.VALUE_VARIABLE),n.setValue("asin",new i.FunctionType(s.realType,s.realType),r.IdentifierStatus.VALUE_VARIABLE),t.setValue("acos",new o.PredefinedFunction("acos",(function(e,t){if(e instanceof o.Real){var n=e.value;return[new o.Real(Math.acos(n)),!1,[]]}throw new a.InternalInterpreterError("std type mismatch")})),r.IdentifierStatus.VALUE_VARIABLE),n.setValue("acos",new i.FunctionType(s.realType,s.realType),r.IdentifierStatus.VALUE_VARIABLE),t.setValue("atan",new o.PredefinedFunction("atan",(function(e,t){if(e instanceof o.Real){var n=e.value;return[new o.Real(Math.atan(n)),!1,[]]}throw new a.InternalInterpreterError("std type mismatch")})),r.IdentifierStatus.VALUE_VARIABLE),n.setValue("atan",new i.FunctionType(s.realType,s.realType),r.IdentifierStatus.VALUE_VARIABLE),t.setValue("atan2",new o.PredefinedFunction("atan2",(function(e,t){if(e instanceof o.RecordValue){var n=e.getValue("1"),r=e.getValue("2");if(n instanceof o.Real&&r instanceof o.Real){var i=n.value,s=r.value;return[new o.Real(Math.atan2(i,s)),!1,[]]}throw new a.InternalInterpreterError("std type mismatch")}throw new a.InternalInterpreterError("std type mismatch")})),r.IdentifierStatus.VALUE_VARIABLE),n.setValue("atan2",new i.FunctionType(new i.TupleType([s.realType,s.realType]),s.realType).simplify(),r.IdentifierStatus.VALUE_VARIABLE),t.setValue("exp",new o.PredefinedFunction("exp",(function(e,t){if(e instanceof o.Real){var n=e.value;return[new o.Real(Math.exp(n)),!1,[]]}throw new a.InternalInterpreterError("std type mismatch")})),r.IdentifierStatus.VALUE_VARIABLE),n.setValue("exp",new i.FunctionType(s.realType,s.realType),r.IdentifierStatus.VALUE_VARIABLE),t.setValue("pow",new o.PredefinedFunction("pow",(function(e,t){if(e instanceof o.RecordValue){var n=e.getValue("1"),r=e.getValue("2");if(n instanceof o.Real&&r instanceof o.Real){var i=n.value,s=r.value;return[new o.Real(Math.pow(i,s)),!1,[]]}throw new a.InternalInterpreterError("std type mismatch")}throw new a.InternalInterpreterError("std type mismatch")})),r.IdentifierStatus.VALUE_VARIABLE),n.setValue("pow",new i.FunctionType(new i.TupleType([s.realType,s.realType]),s.realType).simplify(),r.IdentifierStatus.VALUE_VARIABLE),t.setValue("ln",new o.PredefinedFunction("ln",(function(e,t){if(e instanceof o.Real){var n=e.value;return[new o.Real(Math.log(n)),!1,[]]}throw new a.InternalInterpreterError("std type mismatch")})),r.IdentifierStatus.VALUE_VARIABLE),n.setValue("ln",new i.FunctionType(s.realType,s.realType),r.IdentifierStatus.VALUE_VARIABLE),t.setValue("log10",new o.PredefinedFunction("log10",(function(e,t){if(e instanceof o.Real){var n=e.value;return[new o.Real(Math.log10(n)),!1,[]]}throw new a.InternalInterpreterError("std type mismatch")})),r.IdentifierStatus.VALUE_VARIABLE),n.setValue("log10",new i.FunctionType(s.realType,s.realType),r.IdentifierStatus.VALUE_VARIABLE),t.setValue("sinh",new o.PredefinedFunction("sinh",(function(e,t){if(e instanceof o.Real){var n=e.value;return[new o.Real(Math.sinh(n)),!1,[]]}throw new a.InternalInterpreterError("std type mismatch")})),r.IdentifierStatus.VALUE_VARIABLE),n.setValue("sinh",new i.FunctionType(s.realType,s.realType),r.IdentifierStatus.VALUE_VARIABLE),t.setValue("cosh",new o.PredefinedFunction("cosh",(function(e,t){if(e instanceof o.Real){var n=e.value;return[new o.Real(Math.cosh(n)),!1,[]]}throw new a.InternalInterpreterError("std type mismatch")})),r.IdentifierStatus.VALUE_VARIABLE),n.setValue("cosh",new i.FunctionType(s.realType,s.realType),r.IdentifierStatus.VALUE_VARIABLE),t.setValue("tanh",new o.PredefinedFunction("tanh",(function(e,t){if(e instanceof o.Real){var n=e.value;return[new o.Real(Math.tanh(n)),!1,[]]}throw new a.InternalInterpreterError("std type mismatch")})),r.IdentifierStatus.VALUE_VARIABLE),n.setValue("tanh",new i.FunctionType(s.realType,s.realType),r.IdentifierStatus.VALUE_VARIABLE),t.setValue("pi",new o.Real(3.14159265359),r.IdentifierStatus.VALUE_VARIABLE),n.setValue("pi",s.realType,r.IdentifierStatus.VALUE_VARIABLE),t.setValue("e",new o.Real(2.71828182846),r.IdentifierStatus.VALUE_VARIABLE),n.setValue("e",s.realType,r.IdentifierStatus.VALUE_VARIABLE),e.setDynamicStructure("Math",t),e.setStaticStructure("Math",n),e},code:"signature MATH = sig\n (* type real *)\n val pi : real\n val e : real\n val sqrt : real -> real\n val sin : real -> real\n val cos : real -> real\n val tan : real -> real\n val asin : real -> real\n val acos : real -> real\n val atan : real -> real\n val atan2 : real * real -> real\n val exp : real -> real\n val pow : real * real -> real\n val ln : real -> real\n val log10 : real -> real\n val sinh : real -> real\n val cosh : real -> real\n val tanh : real -> real\n end;\n\n structure Math :> MATH = struct\n open Math;\n end;",requires:void 0}},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var r=n(3),i=n(1),o=n(2),a=n(4);t.RANDOM_LIB={native:function(e){var t=new r.DynamicBasis({},{},{},{},{}),n=new r.StaticBasis({},{},{},{},{});return t.setValue("date",new o.PredefinedFunction("toString",(function(e,t){return[new o.Integer((new Date).getMilliseconds()+(new Date).getSeconds()),!1,[]]})),r.IdentifierStatus.VALUE_VARIABLE),n.setValue("date",new i.FunctionType(new i.TupleType([]).simplify(),a.intType),r.IdentifierStatus.VALUE_VARIABLE),e.setDynamicStructure("Random",t),e.setStaticStructure("Random",n),e},code:'signature RANDOM = sig\n type rand;\n\n val randSeed: real -> rand;\n val rand: unit -> rand;\n (* val toString : rand -> string; *)\n (* val fromString : string -> rand; *)\n\n val randReal: rand -> real;\n val randRealList: int * rand -> real list;\n val randRange: int * int -> rand -> int;\n val randRangeList: int * int -> int * rand -> int list;\n end;\n\n structure Random :> RANDOM = struct\n (* mosml random *)\n open Random;\n\n type rand = {seedref : real ref};\n\n val a = 16807.0;\n val m = 2147483647.0;\n\n fun nextrand seed = let\n val t = a*seed\n in\n t - m * Real.fromInt(Real.floor(t/m))\n end;\n\n fun randSeed seed = if\n seed > 0.0 orelse seed < 0.0\n then\n {seedref = ref (nextrand seed)}\n else\n raise Fail "Random.randSeed: bad seed 0.0";\n\n (* fun toString {seedref} = Int.toString (Real.round (!seedref)); *)\n (* fun fromString s = case Int.fromString s of\n NONE => raise Fail "Random.fromString: given string is invalid"\n | SOME 0 => raise Fail "Random.fromString: given string is invalid"\n | SOME x => {seedref = ref (Real.fromInt x)}; *)\n\n fun rand () = randSeed (Real.fromInt (date ()));\n\n fun randReal {seedref} = (seedref := nextrand (!seedref); !seedref / m);\n\n fun randRealList (n, {seedref}) = let\n fun h 0 seed res = (seedref := seed; res)\n | h i seed res = h (i-1) (nextrand seed) (seed / m :: res)\n in\n h n (!seedref) []\n end;\n\n fun randRange (min, max) = if min >= max then raise Fail "Random.randRange: empty range" else let\n val scale = (Real.fromInt max - Real.fromInt min) / m\n in\n fn {seedref} =>\n (seedref := nextrand (!seedref); Real.floor(Real.fromInt min + scale * (!seedref)))\n end;\n\n fun randRangeList (min, max) = if min >= max then raise Fail "Random.randRangeList: empty range"\n else let\n val scale = (Real.fromInt max - Real.fromInt min) / m\n in\n fn (n, {seedref}) => let\n fun h 0 seed res = (seedref := seed; res)\n | h i seed res = h (i-1) (nextrand seed)\n (Real.floor(Real.fromInt min + scale * seed) :: res)\n in\n h n (!seedref) []\n end\n end;\n end;',requires:["Real"]}},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var r=n(3),i=n(1),o=n(2),a=n(0),s=n(4);t.REAL_LIB={native:function(e){var t=new r.DynamicBasis({},{},{},{},{}),n=new r.StaticBasis({},{},{},{},{});return t.setValue("fromInt",new o.PredefinedFunction("fromInt",(function(e,t){if(e instanceof o.Integer){var n=e.value;return[new o.Real(n),!1,[]]}throw new a.InternalInterpreterError("std type mismatch")})),r.IdentifierStatus.VALUE_VARIABLE),n.setValue("fromInt",new i.FunctionType(s.intType,s.realType),r.IdentifierStatus.VALUE_VARIABLE),t.setValue("round",new o.PredefinedFunction("round",(function(e,t){if(e instanceof o.Real){var n=e.value,r=new o.Integer(Math.round(n));return r.hasOverflow()?[s.overflowException.construct(),!0,[]]:[r,!1,[]]}throw new a.InternalInterpreterError("std type mismatch")})),r.IdentifierStatus.VALUE_VARIABLE),n.setValue("round",new i.FunctionType(s.realType,s.intType),r.IdentifierStatus.VALUE_VARIABLE),t.setValue("floor",new o.PredefinedFunction("floor",(function(e,t){if(e instanceof o.Real){var n=e.value,r=new o.Integer(Math.floor(n));return r.hasOverflow()?[s.overflowException.construct(),!0,[]]:[r,!1,[]]}throw new a.InternalInterpreterError("std type mismatch")})),r.IdentifierStatus.VALUE_VARIABLE),n.setValue("floor",new i.FunctionType(s.realType,s.intType),r.IdentifierStatus.VALUE_VARIABLE),t.setValue("ceil",new o.PredefinedFunction("ceil",(function(e,t){if(e instanceof o.Real){var n=e.value,r=new o.Integer(Math.ceil(n));return r.hasOverflow()?[s.overflowException.construct(),!0,[]]:[r,!1,[]]}throw new a.InternalInterpreterError("std type mismatch")})),r.IdentifierStatus.VALUE_VARIABLE),n.setValue("ceil",new i.FunctionType(s.realType,s.intType),r.IdentifierStatus.VALUE_VARIABLE),t.setValue("toString",new o.PredefinedFunction("toString",(function(e,t){if(e instanceof o.Real)return[new o.StringValue(e.toString(void 0)),!1,[]];throw new a.InternalInterpreterError("std type mismatch")})),r.IdentifierStatus.VALUE_VARIABLE),n.setValue("toString",new i.FunctionType(s.realType,s.stringType),r.IdentifierStatus.VALUE_VARIABLE),e.setDynamicStructure("Real",t),e.setStaticStructure("Real",n),e},code:"signature REAL = sig\n (* type real *)\n\n structure Math : MATH\n\n (* val radix : int *)\n (* val precision : int *)\n\n (* val maxFinite : real *)\n (* val minPos : real *)\n (* val minNormalPos : real *)\n\n (* val posInf : real *)\n (* val negInf : real *)\n\n (* val + : real * real -> real *)\n (* val - : real * real -> real *)\n (* val * : real * real -> real *)\n (* val / : real * real -> real *)\n (* val rem : real * real -> real *)\n (* val *+ : real * real * real -> real *)\n (* val *- : real * real * real -> real *)\n (* val ~ : real -> real *)\n (* val abs : real -> real *)\n\n (* val min : real * real -> real *)\n (* val max : real * real -> real *)\n\n (* val sign : real -> int *)\n (* val signBit : real -> bool *)\n (* val sameSign : real * real -> bool *)\n (* val copySign : real * real -> real *)\n\n val compare : real * real -> order\n (* val compareReal : real * real -> IEEEReal.real_order *)\n (* val < : real * real -> bool *)\n (* val <= : real * real -> bool *)\n (* val > : real * real -> bool *)\n (* val >= : real * real -> bool *)\n (* val == : real * real -> bool *)\n (* val != : real * real -> bool *)\n (* val ?= : real * real -> bool *)\n (* val unordered : real * real -> bool *)\n\n (* val isFinite : real -> bool *)\n (* val isNan : real -> bool *)\n (* val isNormal : real -> bool *)\n (* val class : real -> IEEEReal.float_class *)\n\n (* val toManExp : real -> {man : real, exp : int} *)\n (* val fromManExp : {man : real, exp : int} -> real *)\n (* val split : real -> {whole : real, frac : real} *)\n (* val realMod : real -> real *)\n\n (* val nextAfter : real * real -> real *)\n (* val checkFloat : real -> real *)\n\n (* val realFloor : real -> real *)\n (* val realCeil : real -> real *)\n (* val realTrunc : real -> real *)\n (* val realRound : real -> real *)\n val floor : real -> int\n val ceil : real -> int\n (* val trunc : real -> int *)\n val round : real -> int\n (* val toInt : IEEEReal.rounding_mode -> real -> int *)\n (* val toLargeInt : IEEEReal.rounding_mode -> real -> LargeInt.int *)\n val fromInt : int -> real\n (* val fromLargeInt : LargeInt.int -> real *)\n (* val toLarge : real -> LargeReal.real *)\n (* val fromLarge : IEEEReal.rounding_mode -> LargeReal.real -> real *)\n\n (* val fmt : StringCvt.realfmt -> real -> string *)\n val toString : real -> string\n (* val scan : (char, 'a) StringCvt.reader -> (real, 'a) StringCvt.reader *)\n (* val fromString : string -> real option *)\n\n (* val toDecimal : real -> IEEEReal.decimal_approx *)\n (* val fromDecimal : IEEEReal.decimal_approx -> real option *)\n end;\n\n structure Real = struct\n open Real;\n structure Math : MATH = struct\n open Math;\n end\n fun compare (x, y: real) = if x < y then LESS else if x > y then GREATER else EQUAL;\n end;\n\n structure LargeReal :> REAL = struct\n open Real;\n end;\n structure Real :> REAL = struct\n open Real;\n end;",requires:["Math"]}},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var r=n(3),i=n(1);t.STRING_LIB={native:function(e){var t=new r.DynamicBasis({},{},{},{},{}),n=new r.StaticBasis({},{},{},{},{});return n.setType("string",new i.CustomType("string",[]),[],0,!0),t.setType("string",[]),n.setType("char",new i.CustomType("char",[]),[],0,!0),t.setType("char",[]),e.setDynamicStructure("String",t),e.setStaticStructure("String",n),e},code:'structure String : sig\n eqtype string\n eqtype char\n val size : string -> int\n val sub : string * int -> char\n val extract : string * int * int option -> string\n val substring : string * int * int -> string\n val ^ : string * string -> string\n val concat : string list -> string\n val concatWith : string -> string list -> string\n val str : char -> string\n val implode : char list -> string\n val explode : string -> char list\n val map : (char -> char) -> string -> string\n val translate : (char -> string) -> string -> string\n val tokens : (char -> bool) -> string -> string list\n val fields : (char -> bool) -> string -> string list\n val isPrefix : string -> string -> bool\n val isSubstring : string -> string -> bool\n val isSuffix : string -> string -> bool\n val compare : string * string -> order\n val collate : (char * char -> order)\n -> string * string -> order\n val < : string * string -> bool\n val <= : string * string -> bool\n val > : string * string -> bool\n val >= : string * string -> bool\n end = struct\n open String;\n\n fun size s = List.length (explode s);\n fun sub (s,i) = List.nth (explode s, i);\n fun extract (s, i, NONE) = implode (List.drop (explode s, i))\n | extract (s, i, SOME j) = implode (List.take (List.drop (explode s, i), j));\n fun substring (s, i, j) = extract (s, i, SOME j);\n val op^ = op^;\n\n fun cc2 b ([], y) = y\n | cc2 b (x::xs, y) = cc2 b (xs, y^b^x);\n fun concat a = cc2 "" (a, "");\n fun concatWith b [] = ""\n | concatWith b (a::c) = a ^ (cc2 b (c, ""));\n\n fun str c = implode [c];\n val implode = implode;\n val explode = explode;\n fun map f s = implode(List.map f (explode s));\n fun translate f s = concat(List.map f (explode s));\n\n\n fun cmp f ([], []) = EQUAL\n | cmp f ([], _) = LESS\n | cmp f (_, []) = GREATER\n | cmp f (x::xs, y::ys) = let\n val tmp = f (x, y);\n in\n if tmp <> EQUAL then tmp else cmp f (xs, ys)\n end;\n\n fun matchPrefix ([], _) = true\n | matchPrefix (_, []) = false\n | matchPrefix (x::xs, y::ys) = if x <> y then false else matchPrefix (xs, ys);\n\n fun matchSubstring ([], _) = true\n | matchSubstring (_, []) = false\n | matchSubstring (x, y::ys) = if matchPrefix (x, y::ys) then true\n else matchSubstring (x, ys);\n\n fun getFields (f, [], tmp, x) = (implode tmp) :: x\n | getFields (f, (r::rs), tmp, x) = if f r then\n getFields (f, rs, [], (implode tmp)::x)\n else\n getFields (f, rs, r::tmp, x);\n\n fun tokens f s = List.filter (fn t => t <> "") (getFields (f, rev (explode s), [], []));\n fun fields f s = getFields (f, rev (explode s), [], []);\n\n fun isPrefix a b = matchPrefix (explode a, explode b);\n fun isSubstring a b = matchSubstring (explode a, explode b);\n fun isSuffix a b = matchPrefix (rev (explode a), rev (explode b));\n\n fun compare (a, b) = cmp Char.compare (explode a, explode b);\n fun collate f (a, b) = cmp f (explode a, explode b);\n\n fun op< (a, b) = compare (a, b) = LESS;\n fun op> (a, b) = compare (a, b) = GREATER;\n fun op<= (a, b) = compare (a, b) <> GREATER;\n fun op>= (a, b) = compare (a, b) <> LESS;\n end;',requires:["Char","List"]}},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var r=n(3),i=n(1),o=n(2),a=n(0),s=n(4);t.VECTOR_LIB={native:function(e){var t=new r.DynamicBasis({},{},{},{},{}),n=new r.StaticBasis({},{},{},{},{}),u=new i.CustomType("vector",[new i.TypeVariable("'a")]),p=new i.CustomType("list",[new i.TypeVariable("'a")]);return n.setType("vector",u,[],1,!0),t.setType("vector",[]),t.setValue("fromList",new o.PredefinedFunction("fromList",(function(e,t){var n=new o.VectorValue([]);if(e instanceof o.ConstructedValue){for(var r=e;"nil"!==r.constructorName;){if("::"!==r.constructorName)throw new a.InternalInterpreterError("std type mismatch");var i=r.argument;if(!(i instanceof o.RecordValue&&2===i.entries.size))throw new a.InternalInterpreterError("std type mismatch");var s=i.getValue("1"),u=i.getValue("2");if(!(s instanceof o.Value&&u instanceof o.ConstructedValue))throw new a.InternalInterpreterError("std type mismatch");n.entries.push(s),r=u}return[n,!1,[]]}throw new a.InternalInterpreterError("std type mismatch")})),r.IdentifierStatus.VALUE_VARIABLE),n.setValue("fromList",new i.FunctionType(p,u),r.IdentifierStatus.VALUE_VARIABLE),t.setValue("sub",new o.PredefinedFunction("sub",(function(e,t){if(e instanceof o.RecordValue&&2===e.entries.size){var n=e.getValue("1"),r=e.getValue("2");if(n instanceof o.VectorValue&&r instanceof o.Integer){var i=r.value;return i<0||i>=n.entries.length?[s.subscriptException.construct(),!0,[]]:[n.entries[i],!1,[]]}throw new a.InternalInterpreterError("std type mismatch")}throw new a.InternalInterpreterError("std type mismatch")})),r.IdentifierStatus.VALUE_VARIABLE),n.setValue("sub",new i.FunctionType(new i.TupleType([u,s.intType]).simplify(),new i.TypeVariable("'a")),r.IdentifierStatus.VALUE_VARIABLE),t.setValue("update",new o.PredefinedFunction("update",(function(e,t){if(e instanceof o.RecordValue&&3===e.entries.size){var n=e.getValue("1"),r=e.getValue("2"),i=e.getValue("3");if(n instanceof o.VectorValue&&r instanceof o.Integer){var u=r.value;if(u<0||u>=n.entries.length)return[s.subscriptException.construct(),!0,[]];var p=new o.VectorValue(n.entries.slice());return p.entries[u]=i,[p,!1,[]]}throw new a.InternalInterpreterError("std type mismatch")}throw new a.InternalInterpreterError("std type mismatch")})),r.IdentifierStatus.VALUE_VARIABLE),n.setValue("update",new i.FunctionType(new i.TupleType([u,s.intType,new i.TypeVariable("'a")]).simplify(),u),r.IdentifierStatus.VALUE_VARIABLE),t.setValue("length",new o.PredefinedFunction("length",(function(e,t){if(e instanceof o.VectorValue)return[new o.Integer(e.entries.length),!1,[]];throw new a.InternalInterpreterError("std type mismatch")})),r.IdentifierStatus.VALUE_VARIABLE),n.setValue("length",new i.FunctionType(u,s.intType),r.IdentifierStatus.VALUE_VARIABLE),e.setDynamicStructure("Vector",t),e.setStaticStructure("Vector",n),e},code:"structure Vector :> sig\n (* eqtype 'a vector = 'a vector *)\n (* val maxLen : int *)\n val fromList : 'a list -> 'a vector\n val tabulate : int * (int -> 'a) -> 'a vector\n val length : 'a vector -> int\n val sub : 'a vector * int -> 'a\n val update : 'a vector * int * 'a -> 'a vector\n val concat : 'a vector list -> 'a vector\n val appi : (int * 'a -> unit) -> 'a vector -> unit\n val app : ('a -> unit) -> 'a vector -> unit\n val mapi : (int * 'a -> 'b) -> 'a vector -> 'b vector\n val map : ('a -> 'b) -> 'a vector -> 'b vector\n val foldli : (int * 'a * 'b -> 'b) -> 'b -> 'a vector -> 'b\n val foldri : (int * 'a * 'b -> 'b) -> 'b -> 'a vector -> 'b\n val foldl : ('a * 'b -> 'b) -> 'b -> 'a vector -> 'b\n val foldr : ('a * 'b -> 'b) -> 'b -> 'a vector -> 'b\n val findi : (int * 'a -> bool) -> 'a vector -> (int * 'a) option\n val find : ('a -> bool) -> 'a vector -> 'a option\n val exists : ('a -> bool) -> 'a vector -> bool\n val all : ('a -> bool) -> 'a vector -> bool\n val collate : ('a * 'a -> order) -> 'a vector * 'a vector -> order\n end = struct\n open Vector;\n fun tabulate (n, f) = fromList (List.tabulate (n, f));\n\n fun foldli f init vec = let\n val len = length vec\n fun loop (i, b) =\n if i = len then b\n else loop (i + 1, f (i, sub (vec, i), b))\n in\n loop (0, init)\n end;\n fun foldri f init vec = let\n val len = length vec\n fun loop (i, b) =\n if i = ~1 then b\n else loop (i - 1, f (i, sub (vec, i), b))\n in\n loop (len - 1, init)\n end;\n fun foldl f init vec = foldli (fn (_, a, x) => f(a, x)) init vec;\n fun foldr f init vec = foldri (fn (_, a, x) => f(a, x)) init vec;\n\n fun concat l = fromList (List.concat (List.map (foldr (fn (a, b) => (a::b)) []) l));\n\n fun appi f vec = List.app f (foldri (fn (i,a,l) => (i,a)::l) [] vec);\n fun app f vec = List.app f (foldr (fn (a,l) => a::l) [] vec);\n fun mapi f vec = fromList (List.map f (foldri (fn (i,a,l) => (i,a)::l) [] vec));\n fun map f vec = fromList (List.map f (foldr (fn (a,l) => a::l) [] vec));\n\n fun findi f vec = let\n val len = length vec\n fun loop index =\n if index = Vector.length vec then NONE\n else let\n val el = sub(vec, index)\n in if f (index, el) then SOME (index, el) else loop (index+1)\n end\n in\n loop 0\n end;\n fun find f vec = case findi (fn (_, v) => f v) vec of NONE => NONE\n | SOME (_, v) => SOME v;\n fun exists p vec = case find p vec of NONE => false\n | SOME _ => true;\n\n fun all p vec = foldl (fn (v, acc) => p v andalso acc) true vec;\n fun collate p (v1, v2) = let\n val length1 = length v1\n val length2 = length v2\n fun loop index =\n if index = length1 andalso index = length2 then EQUAL\n else if index = length1 then LESS\n else if index = length2 then GREATER\n else case p (sub (v1, index), sub (v2, index)) of\n EQUAL => loop (index + 1)\n | l => l\n in loop 0\n end;\n end;\n val vector = Vector.fromList;",requires:["Option","List"]}},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var r=n(6),i=n(0);t.evaluate=function(e,t){var n=e.getNestedState(),o=[];o.push({next:t,params:{state:e,modifiable:n,recResult:void 0}});for(var a=void 0;o.length>0;){var s=o.pop();if(void 0===s)throw new i.InternalInterpreterError("How is this undefined?");var u=s.next,p=s.params;p.recResult=a,a=u instanceof r.Declaration?u.evaluate(p,o):u.compute(p,o)}if(void 0!==a){var c=a.newState;if(void 0!==c){c.setWarnings(n.getWarnings());for(var h=0,f=n.getMemoryChanges(e.id);h<f.length;h++){var l=f[h];c.setCell(l[0],l[1])}var d=n.getIdChanges(e.id);for(var y in d)d.hasOwnProperty(y)&&c.setValueIdentifierId(y,d[y]);c.exceptionEvalId=n.exceptionEvalId}}return a}}])}));