UNPKG

entropy-engine

Version:
2 lines 206 kB
/*! For license information please see 0.0.9.js.LICENSE.txt */ var ee;(()=>{var e={768:function(e){e.exports=(()=>{"use strict";var e={d:(t,n)=>{for(var i in n)e.o(n,i)&&!e.o(t,i)&&Object.defineProperty(t,i,{enumerable:!0,get:n[i]})},o:(e,t)=>Object.prototype.hasOwnProperty.call(e,t),r:e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})}},t={};e.r(t),e.d(t,{Context:()=>Z,ESArray:()=>U,ESBoolean:()=>$,ESError:()=>Re,ESErrorPrimitive:()=>O,ESFunction:()=>M,ESJSBinding:()=>N,ESNamespace:()=>B,ESNumber:()=>D,ESObject:()=>R,ESPrimitive:()=>C,ESString:()=>j,ESSymbol:()=>L,ESType:()=>A,ESUndefined:()=>I,ExpectedCharError:()=>Me,IS_NODE_INSTANCE:()=>h,IllegalCharError:()=>Be,ImportError:()=>$e,IndexError:()=>je,InvalidOperationError:()=>Le,InvalidRuntimeError:()=>ze,InvalidSyntaxError:()=>Ne,KEYWORDS:()=>p,N_array:()=>ce,N_binOp:()=>ie,N_break:()=>Te,N_class:()=>ge,N_continue:()=>ke,N_emptyObject:()=>he,N_for:()=>le,N_functionCall:()=>de,N_functionDefinition:()=>pe,N_if:()=>se,N_indexed:()=>me,N_namespace:()=>xe,N_number:()=>be,N_objectLiteral:()=>ue,N_primWrapper:()=>Ce,N_return:()=>ve,N_statements:()=>fe,N_string:()=>we,N_unaryOp:()=>re,N_undefined:()=>Se,N_varAssign:()=>oe,N_variable:()=>_e,N_while:()=>ae,N_yield:()=>ye,Node:()=>ne,ReferenceError:()=>Ue,TestFailed:()=>Ge,TypeError:()=>De,colours:()=>V,deepClone:()=>Oe,digits:()=>i,doubleCharTokens:()=>_,global:()=>l,identifierChars:()=>r,importCache:()=>m,indent:()=>Ae,init:()=>He,interpretResult:()=>te,libs:()=>d,multiLineCommentEnd:()=>a,multiLineCommentStart:()=>s,now:()=>v,primitiveMethods:()=>T,refreshPerformanceNow:()=>y,run:()=>Ye,runningInNode:()=>f,setGlobalContext:()=>c,singleCharTokens:()=>w,singleLineComment:()=>o,sleep:()=>Pe,str:()=>Ee,stringSurrounds:()=>u,strip:()=>G,tokenType:()=>g,tokenTypeString:()=>b,tripleCharTokens:()=>S,tt:()=>x,types:()=>k,validURI:()=>Ie,wrap:()=>z});class n{constructor(e,t,n,i="(unknown)"){this.idx=e,this.ln=t,this.col=n,this.file=i}advance(e=""){return this.idx++,this.col++,"\n"===e&&(this.ln++,this.col=0),this}get clone(){return new n(this.idx,this.ln,this.col,this.file)}get str(){return`File ${this.file}, ${this.ln+1}:${this.col+1}`}get isUnknown(){return-2===this.idx}static get unknown(){return new n(-2,-2,-2,"(unknown)")}}const i="0123456789",r="_$abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ",o="//",s="/*",a="*/";let l;const c=e=>{l=e},u=["'","`",'"'];let h="undefined"==typeof window;const f=()=>{h=!0},d={print:console.log},p=["var","let","global","local","mutable","const","if","else","while","for","in","continue","break","func","return","yield","class","extends","namespace","export"];let v=()=>0;function y(e){return t=this,void 0,i=function*(){v=e?()=>Date.now():()=>{try{return null===performance||void 0===performance?void 0:performance.now()}catch(e){return 0}}},new((n=void 0)||(n=Promise))((function(e,r){function o(e){try{a(i.next(e))}catch(e){r(e)}}function s(e){try{a(i.throw(e))}catch(e){r(e)}}function a(t){var i;t.done?e(t.value):(i=t.value,i instanceof n?i:new n((function(e){e(i)}))).then(o,s)}a((i=i.apply(t,[])).next())}));var t,n,i}y(h);const m={};var g;!function(e){e[e.NUMBER=0]="NUMBER",e[e.STRING=1]="STRING",e[e.ENDSTATEMENT=2]="ENDSTATEMENT",e[e.IDENTIFIER=3]="IDENTIFIER",e[e.KEYWORD=4]="KEYWORD",e[e.COMMA=5]="COMMA",e[e.ASSIGN=6]="ASSIGN",e[e.ADD=7]="ADD",e[e.SUB=8]="SUB",e[e.MUL=9]="MUL",e[e.DIV=10]="DIV",e[e.POW=11]="POW",e[e.OPAREN=12]="OPAREN",e[e.CPAREN=13]="CPAREN",e[e.OBRACES=14]="OBRACES",e[e.CBRACES=15]="CBRACES",e[e.OSQUARE=16]="OSQUARE",e[e.CSQUARE=17]="CSQUARE",e[e.EQUALS=18]="EQUALS",e[e.NOTEQUALS=19]="NOTEQUALS",e[e.NOT=20]="NOT",e[e.GT=21]="GT",e[e.LT=22]="LT",e[e.GTE=23]="GTE",e[e.LTE=24]="LTE",e[e.AND=25]="AND",e[e.OR=26]="OR",e[e.COLON=27]="COLON",e[e.DOT=28]="DOT",e[e.EOF=29]="EOF",e[e.BITWISE_OR=30]="BITWISE_OR",e[e.BITWISE_AND=31]="BITWISE_AND",e[e.BITWISE_NOT=32]="BITWISE_NOT"}(g||(g={}));let x=g;const b={[x.NUMBER]:"Number",[x.STRING]:"String",[x.ENDSTATEMENT]:";",[x.IDENTIFIER]:"Identifier",[x.KEYWORD]:"Keyword",[x.COMMA]:",",[x.OBRACES]:"{",[x.CBRACES]:"}",[x.OPAREN]:"(",[x.CPAREN]:")",[x.OSQUARE]:"[",[x.CSQUARE]:"]",[x.ASSIGN]:"=",[x.ADD]:"+",[x.SUB]:"-",[x.MUL]:"*",[x.DIV]:"/",[x.POW]:"^",[x.EQUALS]:"==",[x.NOTEQUALS]:"!=",[x.NOT]:"!",[x.GT]:">",[x.LT]:"<",[x.GTE]:">=",[x.LTE]:"<=",[x.AND]:"&&",[x.OR]:"||",[x.COLON]:":",[x.DOT]:".",[x.EOF]:"End of File",[x.BITWISE_AND]:"&",[x.BITWISE_OR]:"|",[x.BITWISE_NOT]:"~"},w={"*":x.MUL,"/":x.DIV,"+":x.ADD,"-":x.SUB,"(":x.OPAREN,")":x.CPAREN,"^":x.POW,"{":x.OBRACES,"}":x.CBRACES,",":x.COMMA,"[":x.OSQUARE,"]":x.CSQUARE,";":x.ENDSTATEMENT,":":x.COLON,".":x.DOT,"=":x.ASSIGN,">":x.GT,"<":x.LT,"!":x.NOT,"|":x.BITWISE_OR,"&":x.BITWISE_AND,"~":x.BITWISE_NOT},_={"==":x.EQUALS,"!=":x.NOTEQUALS,">=":x.GTE,"<=":x.LTE,"+=":x.ASSIGN,"-=":x.ASSIGN,"*=":x.ASSIGN,"/=":x.ASSIGN,"&&":x.AND,"||":x.OR},S={},T=["__add__","__subtract__","__multiply__","__divide__","__pow__","__eq__","__gt__","__lt__","__and__","__or__","__bool__","__setProperty__","__getProperty__","__call__"],k={};class C{constructor(e,t=k.any){this.self=this,this.isa=(e,t)=>new $(t===this.__type__),this.is=(e,t)=>new $(t===this),this.valueOf=()=>this.__value__,this.typeName=()=>this.__type__.__name__,this.hasProperty=(e,t)=>new $(this.hasOwnProperty(Ee(t))),this.describe=(e,t)=>{this.info.isBuiltIn||(this.info.description=Ee(t))},this.detail=(e,t)=>{if(this.info.isBuiltIn)return;const i=G(t,e);if("object"!=typeof i)return new De(n.unknown,"object",this.typeName(),Ee(this));this.info=Object.assign(Object.assign({},this.info),i),this.info.isBuiltIn=!1},this.__type__=t||this,this.__value__=e,this.info={}}__add__(e,t){return new Le("",this)}__subtract__(e,t){return new Le("",this)}__multiply__(e,t){return new Le("",this)}__divide__(e,t){return new Le("",this)}__pow__(e,t){return new Le("__pow__",this)}__eq__(e,t){return new Le("__eq__",this)}__gt__(e,t){return new Le("__gt__",this)}__lt__(e,t){return new Le("__lt__",this)}__and__(e,t){return new Le("__and__",this)}__or__(e,t){return new Le("__or__",this)}__bool__(e){return new Le("__bool__",this)}__setProperty__(e,t,n){return new Le("__setProperty__",this,`[${Ee(t)}] = ${Ee(n)}`)}__call__(e,...t){return new Le("__call__",this)}}class O extends C{constructor(e=new Re(n.unknown,"Unknown","Error not specified")){super(e,k.error),this.__getProperty__=(e,t)=>{if(this.self.hasOwnProperty(Ee(t))){const e=this.self[Ee(t)];return"function"==typeof e?new M(e):z(e)}return new je(n.unknown,t.valueOf(),this)},this.cast=({})=>new Re(n.unknown,"TypeError","Cannot cast type 'error'"),this.str=()=>new j(`<Error: ${this.valueOf().str}>`),this.__eq__=(e,t)=>new $(t instanceof O&&this.valueOf().constructor===t.valueOf().constructor),this.__bool__=()=>new $(!0),this.bool=this.__bool__,this.clone=()=>new O(this.valueOf())}}function E(e,t,i,r,o){if(!(t instanceof A))return new De(n.unknown,"Type",typeof t,t);const s=new M((({context:e},...n)=>{const s=new Z;if(s.parent=e,t.__extends__){let e=E(s,t.__extends__,i,r,o);if(e instanceof Re)return e}const a=null==t?void 0:t.__init__;if(!a)return;a.this_=r,a.__closure__=s;const l=a.__call__({context:s},...n);return l instanceof Re?l:void 0}),void 0,"super",r);let a=e.setOwn("super",s);if(a instanceof Re)return a;const l=P(t,{context:e},[],!1,i);return l instanceof Re?l:void 0}function P(e,{context:t},n,i=!0,r={}){var o;if(e.__isPrimitive__){if(n.length<1)return new I;switch(e.__name__){case"Undefined":case"Type":return n.length<1?new A:new j(n[0].__type__.__name__);case"String":return new j(n[0].str().valueOf());case"Array":return new U(n);case"Number":return new D(n[0].valueOf());case"Function":return new M(n[0].valueOf());case"Boolean":return new $(n[0].bool().valueOf());default:return z(n[0])}}const s=new Z;s.parent=null===(o=e.__init__)||void 0===o?void 0:o.__closure__;const a=new R;if(e.__extends__){let n=E(s,e.__extends__,r,a,t);if(n instanceof Re)return n}a.__value__=r;for(let t of e.__methods__){const e=t.clone();e.this_=a,r[t.name]=e,-1!==T.indexOf(t.name)&&(a[t.name]=e.__call__)}if(i&&e.__init__){e.__init__.this_=a,e.__init__.__closure__=s;const t=e.__init__.__call__({context:s},...n);if(t instanceof Re)return t}return a.__type__=e,e.__instances__.push(a),a}class A extends C{constructor(e=!1,t="(anon)",i=[],r,o){super(void 0,null==k?void 0:k.type),this.__instances__=[],this.clone=()=>new A(this.__isPrimitive__,this.__name__,this.__methods__,this.__extends__,this.__init__),this.isa=({},e)=>new $(e===k.type),this.cast=({},e)=>new Le("cast",this),this.includesType=(e,t)=>{var n,i,r,o,s,a;return this.equals(e,k.any).bool().valueOf()||t.equals(e,k.any).bool().valueOf()||!0===(null===(n=this.__extends__)||void 0===n?void 0:n.equals(e,t).valueOf())||!0===(null===(i=this.__extends__)||void 0===i?void 0:i.equals(e,k.any).valueOf())||!0===(null===(r=this.__extends__)||void 0===r?void 0:r.includesType(e,t).valueOf())||!0===(null===(o=t.__extends__)||void 0===o?void 0:o.equals(e,this).valueOf())||!0===(null===(s=t.__extends__)||void 0===s?void 0:s.equals(e,k.any).valueOf())||!0===(null===(a=t.__extends__)||void 0===a?void 0:a.includesType(e,this).valueOf())?new $(!0):this.equals(e,t)},this.equals=({},e)=>new $(e.__name__===this.__name__&&e.__isPrimitive__===this.__isPrimitive__&&Object.is(this.valueOf(),e.valueOf())),this.__call__=({context:e},...t)=>P(this,{context:e},t||[]),this.str=()=>new j(`<Type: ${this.__name__}>`),this.__bool__=()=>new $(!0),this.bool=this.__bool__,this.__getProperty__=({},e)=>{if(this.self.hasOwnProperty(Ee(e))){const t=this.self[Ee(e)];return"function"==typeof t?new M(t):z(t)}return new je(n.unknown,e.valueOf(),this)},this.__isPrimitive__=e,this.__name__=t,this.info.name=t,this.__extends__=r,this.__methods__=i,o&&(o.name=t,this.__init__=o),k.type||(this.__type__=this)}}class I extends C{constructor(){super(void 0,k.undefined),this.cast=({context:e},t)=>{switch(t){case k.number:return new D;case k.string:return new j;case k.array:return new U;case k.undefined:return new I;case k.type:return new A;case k.error:return new O;case k.object:case k.any:return new R;case k.function:return new M((()=>{}));case k.boolean:return new $;default:return t instanceof A?t.__call__({context:e}):new Re(n.unknown,"TypeError",`Cannot cast to type '${Ee(t.typeName())}'`)}},this.str=()=>new j("<Undefined>"),this.__eq__=({},e)=>new $(e instanceof I||void 0===e||void 0===e.valueOf()),this.__bool__=()=>new $,this.bool=this.__bool__,this.clone=()=>new I,this.__getProperty__=({},e)=>{if(this.self.hasOwnProperty(Ee(e))){const t=this.self[Ee(e)];return"function"==typeof t?new M(t):z(t)}return new je(n.unknown,e.valueOf(),this)},this.info={name:"undefined",description:"Not defined, not a value.",file:"built-in",isBuiltIn:!0}}}class R extends C{constructor(e={}){super(e,k.object),this.isa=(e,t)=>t===k.object?new $(!0):t instanceof A?this.__type__.includesType(e,t):new De(n.unknown,"TypeError","type",Ee(t.typeName()),Ee(t)),this.cast=({},e)=>e===k.number?new D(this.valueOf()?1:0):new Re(n.unknown,"TypeError",`Cannot cast boolean to type '${Ee(e.typeName())}'`),this.str=()=>{let e=Ee(this.valueOf());return"\n"===e[e.length-1]&&(e=e.substr(0,e.length-1)),new j(`<ESObject ${e}>`)},this.__eq__=({context:e},t)=>{if(!(t instanceof R))return new $;if(t.keys.length!==this.keys.length)return new $;for(let n of this.keys){const i=n.valueOf(),r=this.valueOf()[i],o=t.valueOf()[i];if(!r){if(o)return new $;continue}if(!r.__eq__)return new $;const s=r.__eq__({context:e},o);if(s instanceof Re)return s;if(!s.valueOf())return new $}return new $(!0)},this.__bool__=()=>new $(!0),this.bool=this.__bool__,this.__add__=({context:e},t)=>{if(!(t instanceof R))return new De(n.unknown,"object",t.typeName().valueOf(),t);let i={};for(let t of this.keys){const n=t.valueOf(),r=this.__getProperty__({context:e},t);if(r instanceof Re)return r;i[n]=r}for(let n of t.keys){const r=n.valueOf();if(i.hasOwnProperty(r))continue;const o=t.__getProperty__({context:e},n);if(o instanceof Re)return o;i[r]=o}return new R(i)},this.__subtract__=(e,t)=>{let i=[];if(t instanceof j)i=[Ee(t)];else{if(!(t instanceof U))return new De(n.unknown,"array | string",t.typeName().valueOf(),t);i=G(t,e)}if(!Array.isArray(i))return new De(n.unknown,"array | string",t.typeName().valueOf(),t);let r={};for(let t of this.keys){const n=t.valueOf();if(-1===i.indexOf(n)){let i=this.__getProperty__(e,t);if(i instanceof Re)return i;r[n]=i}}return new R(r)},this.__getProperty__=({},e)=>{if(!(e instanceof j))return new De(n.unknown,"string",e.typeName(),Ee(e));const t=e.valueOf();if(this.valueOf().hasOwnProperty(t))return this.valueOf()[t];if(this.self.hasOwnProperty(t)){const e=this.self[t];return"function"==typeof e?new M(e):z(e)}return new I},this.__setProperty__=({},e,t)=>{if(!(e instanceof j))return new De(n.unknown,"string",e.typeName(),Ee(e));this.__value__[e.valueOf()]=t},this.hasProperty=(e,t)=>{const n=Ee(t);return this.valueOf().hasOwnProperty(Ee(n))?new $(!0):new $(this.hasOwnProperty(n))},this.clone=()=>{const e=new R;let t={},n=this.valueOf();for(let e of Object.keys(n))t[e]=n[e];return e.__value__=t,e}}get keys(){return Object.keys(this.valueOf()).map((e=>new j(e)))}set keys(e){}}class B extends C{constructor(e,t,i=!1){super(t,k.object),this.cast=({})=>new Re(n.unknown,"TypeError","Cannot cast type 'namespace'"),this.clone=()=>{let e={},t=this.valueOf();for(let n of Object.keys(t))e[n]=t[n];return new B(this.name,e)},this.str=()=>{const e=Object.keys(this.valueOf());return new j(`<Namespace ${Ee(this.name)}${e.length>0?": ":""}${e.slice(0,5)}${e.length>=5?"...":""}>`)},this.__eq__=({},e)=>new $(this===e),this.__bool__=()=>new $(!0),this.bool=this.__bool__,this.__getProperty__=({},e)=>{if(e instanceof j&&this.valueOf().hasOwnProperty(e.valueOf())){const t=this.valueOf()[e.valueOf()];if(t.isAccessible)return t.value}if(!(e instanceof j))return new De(n.unknown,"string",e.typeName());if(this.self.hasOwnProperty(Ee(e))){const t=this.self[Ee(e)];return"function"==typeof t?new M(t):z(t)}return new je(n.unknown,e.valueOf(),this.self)},this.info.name=Ee(e),this.mutable=i}get name(){return new j(this.info.name)}set name(e){this.info.name=e.valueOf()}__setProperty__({},e,t){if(!(e instanceof j))return new De(n.unknown,"string",e.typeName().valueOf(),Ee(e));let i=Ee(e);if(!this.mutable)return new De(n.unknown,"mutable","immutable",`${Ee(this.name)}`);t instanceof C||(t=z(t));const r=this.__value__[i];return r?r.isConstant?new De(n.unknown,"mutable","immutable",`${Ee(this.name)}.${i}`):r.isAccessible?void(r.value=t):new De(n.unknown,"accessible","inaccessible",`${Ee(this.name)}.${i}`):new Re(n.unknown,"SymbolError",`Symbol ${i} is not declared in namespace ${Ee(this.name)}.`)}}class N extends C{constructor(e,t="<AnonNative>",i=!1){super(e,k.object),this.cast=({})=>new Re(n.unknown,"TypeError","Cannot cast native object"),this.clone=()=>new N(this.__value__),this.str=()=>{try{return new j(JSON.stringify(this.__value__))}catch(e){return new j(`${this.__value__}`)}},this.__eq__=({},e)=>new $(this===e),this.__bool__=()=>new $(!0),this.bool=this.__bool__,this.__getProperty__=(e,t)=>{const i=Ee(t),r=this.valueOf(),o=r[i];if(void 0===o){if(this.self.hasOwnProperty(i)){const e=this.self[Ee(i)];return"function"==typeof e?new M(e):z(e)}return new je(n.unknown,i,this)}return o instanceof C?o:"function"==typeof o?new M((({context:t},...n)=>r[i](...n.map((t=>G(t,e)))))):new N(o)},this.__call__=(e,...t)=>{if("function"!=typeof this.__value__)return new De(n.unknown,"function",typeof this.__value__,Ee(this));let i;try{i=new this.__value__(...t.map((t=>G(t,e))))}catch(n){i=this.__value__(...t.map((t=>G(t,e))))}return i instanceof C?i:new N(i)},this.hasProperty=(e,t)=>new $(!(this.__getProperty__(e,t)instanceof Re)),this.info.name=Ee(t)}}k.type=new A(!0,"Type"),k.undefined=new A(!0,"Undefined"),k.string=new A(!0,"String"),k.array=new A(!0,"Array"),k.number=new A(!0,"Number"),k.any=new A(!0,"Any"),k.function=new A(!0,"Function"),k.bool=new A(!0,"Boolean"),k.object=new A(!0,"Object"),k.error=new A(!0,"Error"),k.any.info={name:"any",description:"Matches any other type",file:"built-in",isBuiltIn:!0},k.number.info={name:"any",description:"The ES Number type. Is a a double-precision 64-bit binary format IEEE 754 value, like double in Java and C#",file:"built-in",isBuiltIn:!0},k.string.info={name:"string",description:"The ES String type. Holds an array of characters, and can be defined with any of ', \" and `. Can be indexed like an array.",file:"built-in",isBuiltIn:!0},k.bool.info={name:"bool",description:"The ES Bool type. Exactly two instances exist, true and false.",file:"built-in",isBuiltIn:!0},k.function.info={name:"function",description:"The ES Function type. Is a block of code which executes when called and takes in 0+ parameters.",file:"built-in",isBuiltIn:!0},k.array.info={name:"array",description:"The ES Array type. Defines a set of items of any type which can be accessed by an index with [].",file:"built-in",isBuiltIn:!0},k.object.info={name:"object",description:"The ES Object type. Similar to JS objects or python dictionaries.",file:"built-in",isBuiltIn:!0},k.error.info={name:"error",description:"The ES Error type. Call to throw an error.",file:"built-in",isBuiltIn:!0},k.type.info={name:"type",description:"The ES Type type. Call to get the type of a value at a string.",file:"built-in",isBuiltIn:!0};class M extends C{constructor(e=(()=>{}),t=[],i="(anon)",r=new R,o=k.any,s=l){super(e,k.function),this.cast=({},e)=>new Re(n.unknown,"TypeError","Cannot cast type 'function'"),this.clone=()=>new M(this.__value__,this.arguments_,this.name,this.this_,this.returnType,this.__closure__),this.valueOf=()=>this,this.str=()=>new j(`<Func: ${this.name}>`),this.__eq__=({},e)=>new $(e instanceof M&&this.__value__===e.__value__),this.__bool__=()=>new $(!0),this.bool=this.__bool__,this.__call__=({context:e},...t)=>(this.__closure__.path=e.path,function(e,t,i){var r;let o=e;(e=t.__closure__).path=o.path;const s=t.__value__,a=function(e,t,i){const r=new Z;r.parent=i;let o=Math.max(e.length,t.arguments_.length);for(let s=0;s<o;s++){let o=new I,a=k.any;if(!t.arguments_[s])continue;const l=t.arguments_[s];if(!(l.type instanceof A))return new De(n.unknown,"Type",typeof l.type,l.type);if(e[s]instanceof C&&(a=e[s].__type__,o=e[s]),!l.type.includesType({context:i},a).bool().valueOf())return new De(n.unknown,l.type.__name__,a.__name__,Ee(o));r.setOwn(l.name,o,{forceThroughConst:!0})}let s=r.setOwn("args",new U(e),{forceThroughConst:!0});return s instanceof Re?s:r}(i,t,e);if(a instanceof Re)return a;let l=null!==(r=t.this_)&&void 0!==r?r:new R;if(!(l instanceof R))return new De(n.unknown,"object",typeof l,l,"'this' must be an object");let c=a.setOwn("this",l);return c instanceof Re?c:s instanceof ne?function(e,t,i,r){var o,s,a,l;const c=r.interpret(t);return c.error?c.error:(void 0!==c.funcReturn&&(c.val=c.funcReturn,c.funcReturn=void 0),!1===e.returnType.includesType({context:t},null!==(s=null===(o=c.val)||void 0===o?void 0:o.__type__)&&void 0!==s?s:k.any).valueOf()?new De(n.unknown,e.returnType.__name__,(null===(a=c.val)||void 0===a?void 0:a.typeName().valueOf())||"undefined",null===(l=c.val)||void 0===l?void 0:l.str().valueOf(),"(from function return)"):c.val?c.val:new I)}(t,a,0,s):"function"==typeof s?function(e,t,n,i){for(let e=n.length;e<i.length;e++)n.push(new I);const r=i({context:t},...n);return r instanceof Re||r instanceof C?r:new I}(0,a,i,s):new De(n.unknown,"function",typeof s)}(this.__closure__,this,t)),this.__getProperty__=({},e)=>{if(this.self.hasOwnProperty(Ee(e))){const t=this.self[Ee(e)];return"function"==typeof t?new M(t):z(t)}return new je(n.unknown,e.valueOf(),this)},this.arguments_=t,this.info.name=i,this.this_=r,this.returnType=o,this.__closure__=s,this.info.returnType=Ee(o),this.info.args=t.map((e=>({name:e.name,defaultValue:Ee(e.defaultValue),type:e.type.info.name,required:!0})))}get name(){var e;return null!==(e=this.info.name)&&void 0!==e?e:"(anonymous)"}set name(e){this.info.name=e}}class D extends C{constructor(e=0){super(e,k.number),this.cast=({},e)=>{switch(e){case k.number:return this;case k.string:return this.str();case k.array:return new U(new Array(this.valueOf()));default:return new Re(n.unknown,"TypeError",`Cannot cast to type '${Ee(e.typeName())}'`)}},this.str=()=>new j(this.valueOf().toString()),this.__add__=({},e)=>e instanceof D?new D(this.valueOf()+e.valueOf()):new De(n.unknown,"Number",e.typeName().valueOf(),e.valueOf()),this.__subtract__=({},e)=>e instanceof D?new D(this.valueOf()-e.valueOf()):new De(n.unknown,"Number",e.typeName().valueOf(),e.valueOf()),this.__multiply__=({},e)=>e instanceof D?new D(this.valueOf()*e.valueOf()):new De(n.unknown,"Number",e.typeName().valueOf(),e.valueOf()),this.__divide__=({},e)=>e instanceof D?new D(this.valueOf()/e.valueOf()):new De(n.unknown,"Number",e.typeName().valueOf(),e.valueOf()),this.__pow__=({},e)=>e instanceof D?new D(Math.pow(this.valueOf(),e.valueOf())):new De(n.unknown,"Number",e.typeName().valueOf(),e.valueOf()),this.__eq__=({},e)=>new $(e instanceof D&&this.valueOf()===e.valueOf()),this.__gt__=({},e)=>e instanceof D?new $(this.valueOf()>e.valueOf()):new De(n.unknown,"Number",e.typeName().valueOf(),e.valueOf()),this.__lt__=({},e)=>e instanceof D?new $(this.valueOf()<e.valueOf()):new De(n.unknown,"Number",e.typeName().valueOf(),e.valueOf()),this.__bool__=()=>new $(this.valueOf()>0),this.bool=this.__bool__,this.clone=()=>new D(this.valueOf()),this.__getProperty__=({},e)=>{if(this.self.hasOwnProperty(Ee(e))){const t=this.self[Ee(e)];return"function"==typeof t?new M(t):z(t)}return new je(n.unknown,e.valueOf(),this)}}}class $ extends C{constructor(e=!1){super(Boolean(e),k.bool),this.__getProperty__=(e,t)=>{if(this.self.hasOwnProperty(Ee(t))){const e=this.self[Ee(t)];return"function"==typeof e?new M(e):z(e)}return new je(n.unknown,t.valueOf(),this)},this.cast=(e,t)=>t===k.number?new D(this.valueOf()?1:0):new Re(n.unknown,"TypeError",`Cannot cast boolean to type '${Ee(t.typeName())}'`),this.__eq__=(e,t)=>t instanceof $?new $(this.valueOf()===t.valueOf()):new De(n.unknown,"Boolean",t.typeName().valueOf(),t.valueOf()),this.__bool__=()=>this,this.__and__=(e,t)=>new $(this.valueOf()&&t.bool().valueOf()),this.__or__=(e,t)=>new $(this.valueOf()||t.bool().valueOf()),this.str=()=>new j(this.valueOf()?"true":"false"),this.clone=()=>new $(this.valueOf()),this.bool=()=>this,this.info={name:Ee(e),description:`Boolean global constant which evaluates to ${Ee(e)}, the opposite of ${Ee(!e)}`,file:"built-in",isBuiltIn:!0,helpLink:"https://en.wikipedia.org/wiki/Boolean_expression"}}}class U extends C{constructor(e=[]){super(e,k.array),this.cast=({},e)=>{switch(e){case k.number:return new D(this.len);case k.boolean:return this.bool();default:return new Re(n.unknown,"TypeError",`Cannot cast boolean to type '${Ee(e.typeName())}'`)}},this.str=()=>new j(Ee(this.valueOf())),this.__eq__=({context:e},t)=>{if(!(t instanceof U))return new $;if(t.len!==this.len)return new $;for(let n=0;n<this.len;n++){const i=this.valueOf()[n],r=t.valueOf()[n];if(!i){if(r)return new $;continue}if(!i.__eq__)return new $;const o=i.__eq__({context:e},r);if(o instanceof Re)return o;if(!o.valueOf())return new $}return new $(!0)},this.__add__=({context:e},t)=>t instanceof U?new U([...this.valueOf(),...t.valueOf()]):new De(n.unknown,"array",t.typeName().valueOf(),t),this.__bool__=()=>new $(this.valueOf().length>0),this.bool=this.__bool__,this.__getProperty__=({},e)=>{if(e instanceof j&&this.self.hasOwnProperty(Ee(e))){const t=this.self[Ee(e)];return"function"==typeof t?new M(t):z(t)}if(!(e instanceof D))return new I;let t=e.valueOf();for(;t<0;)t=this.valueOf().length+t;return t<this.valueOf().length?this.valueOf()[t]:new I},this.add=({},e,t=new D(this.len-1))=>{if(!(e instanceof C))throw"adding non-primitive to array: "+Ee(e);return this.len++,this.__value__.splice(t.valueOf(),0,e),new D(this.len)},this.contains=({},e)=>{for(let t of this.__value__)if(e.valueOf()==t.valueOf())return!0;return!1},this.clone=()=>{const e=[];for(let t of this.valueOf())e.push(t);return new U(e)},this.len=e.length}__setProperty__({},e,t){if(!(e instanceof D))return;t instanceof C||(t=z(t));let n=e.valueOf();for(;n<0;)n=this.valueOf().length+n;this.__value__[n]=t}}class j extends C{constructor(e=""){super(e,k.string),this.str=()=>this,this.cast=({},e)=>{switch(e){case k.number:const t=parseFloat(this.valueOf());return isNaN(t)?new Re(n.unknown,"TypeError","This string is not a valid number"):new D(t);case k.string:return this;case k.array:return new U(this.valueOf().split("").map((e=>new j(e))));default:return new Re(n.unknown,"TypeError",`Cannot cast to type '${Ee(e.typeName())}'`)}},this.__add__=({},e)=>e instanceof j?new j(this.valueOf()+e.valueOf()):new De(n.unknown,"String",e.typeName().valueOf(),e.valueOf()),this.__multiply__=({},e)=>e instanceof D?new j(this.valueOf().repeat(e.valueOf())):new De(n.unknown,"Number",e.typeName().valueOf(),e.valueOf()),this.__eq__=({},e)=>new $(e instanceof j&&this.valueOf()===e.valueOf()),this.__gt__=({},e)=>e instanceof j?new $(this.valueOf().length>e.valueOf().length):new De(n.unknown,"String",e.typeName().valueOf(),e.valueOf()),this.__lt__=({},e)=>e instanceof j?new $(this.valueOf().length<e.valueOf().length):new De(n.unknown,"String",e.typeName().valueOf(),e.valueOf()),this.__bool__=()=>new $(this.valueOf().length>0),this.bool=this.__bool__,this.len=()=>new D(this.valueOf().length),this.clone=()=>new j(this.valueOf()),this.__getProperty__=(e,t)=>{if(t instanceof j&&this.self.hasOwnProperty(Ee(t))){const e=this.self[Ee(t)];return"function"==typeof e?new M(e):z(e)}if(!(t instanceof D))return new j;let n=t.valueOf();for(;n<0;)n=this.valueOf().length+n;return n<this.valueOf().length?new j(this.valueOf()[n]):new j}}__setProperty__({},e,t){if(!(e instanceof D))return;t instanceof j||(t=new j(Ee(t)));let n=e.valueOf();for(;n<0;)n=this.valueOf().length+n;const i=t.str().valueOf();let r=this.__value__.substr(0,n),o=this.__value__.substr(n+i.length);this.__value__=r+i+o}}class L{constructor(e,t,n={}){var i,r;this.clone=()=>new L(this.value.clone(),this.identifier,{isConstant:this.isConstant,isAccessible:this.isAccessible}),this.str=()=>new j(`<Symbol: ${this.identifier}>`),this.value=e,this.identifier=t,this.isConstant=null!==(i=n.isConstant)&&void 0!==i&&i,this.isAccessible=null===(r=n.isAccessible)||void 0===r||r}}function z(e,t=!1){return e instanceof C?e:null==e?new I:e instanceof Re?new O(e):e instanceof L?e.value:"number"==typeof e?new D(e):"string"==typeof e?new j(e):"boolean"==typeof e?new $(e):"bigint"==typeof e?new D(Number(e)):"symbol"==typeof e?new j(String(e)):new N(e,void 0,t)}function G(e,t){if(null!=e){if(!(e instanceof C))return e;if(e instanceof U)return e.valueOf().map((e=>G(e,t)),t);if(e instanceof R){let n={};for(let i in e.valueOf())n[i]=G(e.valueOf()[i],t);return n}if(!(e instanceof I))return e instanceof M?(...n)=>{const i=e.__call__(t,...n.map((e=>z(e))));return i instanceof Re?i:G(i,t)}:e instanceof A?e:e.valueOf()}}const F={red:31,yellow:33,green:32,cyan:36,blue:34,grey:2},W={};for(let e of Object.keys(F))W[e]=t=>(t||(t=""),h?`[${F[e]}m`+t+"":`<span style="color: ${e}">${t}</span>`);const V=W,q={range:[({context:e},t)=>{if(!(t instanceof D))return new De(n.unknown,"Number",t.typeName().valueOf(),t.valueOf());const i=t.valueOf();try{return new U([...Array(i).keys()].map((e=>new D(e))))}catch(e){return new Re(n.unknown,"RangeError",`Cannot make range of length '${Ee(t)}'`)}},{args:[{name:"N",type:"Number"}],description:"Generates an array of integers given N. Starts at 0 and goes to N-1. Can be used like for i in range(10) ..., similarly to python.",returns:"array of numbers from 0 to N-1",returnType:"number[] | RangeError"}],log:[({context:e},...t)=>{console.log(...t.map((e=>Ee(e))))},{args:[{name:"...values",type:"any[]"}],description:"Uses console.log to log all values",returnType:"void"}],parseNum:[({context:e},t)=>{try{const e=parseFloat(Ee(t));return isNaN(e)?new Re(n.unknown,"TypeError",`Cannot convert '${Ee(t)}' to a number.`):new D(e)}catch(e){return new Re(n.unknown,"TypeError",`Cannot convert '${Ee(t)}' to a number.`)}},{args:[{name:"num",type:"any"}],description:"Converts a string of digits into a number. Works with decimals and integers. Calls .str() on value before using native JS 'parseFloat' function. Returns TypeError if the string can't be converted into a number.",returnType:"number | TypeError"}],help:[({context:e},...t)=>{if(!t.length)return new j("Visit https://entropygames.io/entropy-script for help with Entropy Script!\nTry 'help(<anything>)' for help about a particular object.");let n="";for(const e of t){if(!(e instanceof C))return void console.log("Invalid arg not primitive: "+Ee(e));const t=e.info;if(n+=`${V.yellow(`Help on '${t.name||"(anonymous)"}'`)}:\n \n ${V.yellow("Value")}: ${Ae(Ae(Ee(e)))}\n ${V.yellow("Type")}: '${Ee(e.typeName())}'\n ${V.yellow("Location")}: ${t.file||V.yellow("(unknown)")}\n \n ${V.green(t.description)||"No description."}\n \n ${t.helpLink?V.cyan(t.helpLink+"\n\n"):""}\n`,t.args&&e instanceof M){const e=t.args.length,i=t.args.filter((e=>e.required)).length;n+=e==i?V.yellow(` Arguments (${e}): \n`):V.yellow(` Arguments (${i}-${e}): \n`);for(const[e,i]of t.args.entries())n+="object"!=typeof i?` ${e+1}. INVALID ARG INFO`:` ${e+1}. ${i.name}${!1===i.required?V.yellow(" (optional) "):" "}{${i.type}} ${i.description||""}\n`;n+="\n\n",t.returns&&(n+=` Returns: ${t.returns}\n\n`),t.returnType&&(n+=` Return Type: ${t.returnType}\n\n`)}if(t.contents&&(e instanceof R||e instanceof B)){n+=" Properties: \n ";for(let e of t.contents)n+=e.name+"\n "}}return console.log(n),t.length>1?new U(t):t?t[0]:void 0},{args:[{name:"value",type:"any"}],description:"logs info on value",returns:"value passed in"}],delete:[({context:e},t)=>{const i=Ee(t);if(!e.has(i))return new Re(n.unknown,"DeleteError",`Identifier '${i}' not found in the current context`);e.set(i,new I)},{name:"delete",args:[{name:"identifier",type:"string"}],description:"Deletes a variable from the current context"}],__path:[({context:e})=>new j(e.path),{name:"__path",args:[],description:"Returns the current path"}],__symbols:[({context:e})=>z(e.keys),{name:"__allSymbols",args:[],description:"Returns an array of the names of all symbols in the current context"}],using:[({context:e},t,i)=>{if(!(t instanceof B||t instanceof N))return new De(n.unknown,"Namespace",Ee(t.typeName()));let r=!0;i&&(i.bool().valueOf()||(r=!1));const o=t.valueOf();r?e=e.root:e.parent&&(e=e.parent);for(const t of Object.keys(o))e.setOwn(t,o[t].value,{isConstant:o[t].isConstant,isAccessible:o[t].isAccessible,forceThroughConst:!0})},{name:"using",args:[{name:"module",type:"namespace"},{name:"global",type:"bool"}],description:"Adds contents of a namespace to the global context"}],sleep:[({context:e},t,i)=>t instanceof D?i instanceof M?void Pe(t.valueOf()).then((()=>{const t=i.__call__({context:e});t instanceof Re&&console.log(t.str)})):new De(n.unknown,"function",Ee(i.typeName()),Ee(i)):new De(n.unknown,"number",Ee(t.typeName()),Ee(t)),{name:"sleep",args:[{name:"n",type:"number"},{name:"callback",type:"function"}],description:"Waits n milliseconds and then executes the callback"}]},H={ascii:{asciiToChar:(e,t)=>t instanceof D?new j(String.fromCharCode(t.valueOf())):new De(n.unknown,"number",Ee(t.typeName()),Ee(t)),charToAscii:(e,t)=>t instanceof j?new D(Ee(t).charCodeAt(0)):new De(n.unknown,"string",Ee(t.typeName()),Ee(t))},json:{parse:(e,t)=>new R(JSON.parse(Ee(t))),stringify:(e,t)=>t instanceof R?new j(JSON.stringify(G(t,e))):new De(n.unknown,"object",Ee(t.typeName()),Ee(t))}},Y={};function Q(e,t){const n={},i=e.valueOf();for(const e of Object.keys(i))n[e]=new L(i[e],e);return new N(n,t)}function K(e){return e in H||e in Y}function J(e){if(e in Y)return Y[e];if(e in H){const t=Q(new N(H[e]),e);return Y[e]=t,t}}function X(e,t,i){q.import=[({context:i},r,o)=>{if(h)return new Re(n.unknown,"ImportError","Is running in node instance but trying to run browser import function");const s=r.str();if(K(Ee(s)))return J(Ee(s));try{fetch(Ee(s)).then((e=>e.text())).then((r=>{return a=this,void 0,c=function*(){const a=new Z;a.parent=e;const l=yield Ye(r);l.error?t(new $e(n.unknown,Ee(s),l.error.str).str):o instanceof M&&o.__call__({context:i},new B(s,a.getSymbolTableAsDict()))},new((l=void 0)||(l=Promise))((function(e,t){function n(e){try{r(c.next(e))}catch(e){t(e)}}function i(e){try{r(c.throw(e))}catch(e){t(e)}}function r(t){var r;t.done?e(t.value):(r=t.value,r instanceof l?r:new l((function(e){e(r)}))).then(n,i)}r((c=c.apply(a,[])).next())}));var a,l,c}))}catch(e){return new Re(n.unknown,"ImportError",e.toString())}},{}],q.print=[({context:e},...n)=>{let i="";for(let e of n)i+=Ee(e);t(i)},{}],q.input=[({context:e},t,n)=>{i(t.valueOf(),(t=>{let i=null==n?void 0:n.valueOf();if(i instanceof M){let n=i.__call__({context:e},new j(t));n instanceof Re&&console.log(n.str)}else"function"==typeof i&&i(t);return new j("'input()' does not return anything. Pass in a function as the second argument, which will take the user input as an argument.")}))},{}];for(let t in q){const n=new M(q[t][0],[],t,void 0,void 0,e);n.info=q[t][1],n.info.name=t,n.info.isBuiltIn=!0,n.info.file="built-in",e.set(t,n,{global:!0,isConstant:!0})}!function(e){const t={false:new $(!1),true:new $(!0),nil:new I,any:k.any,number:k.number,string:k.string,bool:k.bool,function:k.function,array:k.array,object:k.object,type:k.type,error:k.error,undefined:k.undefined};for(let n in t){const i=t[n];e.set(n,i,{global:!0,isConstant:!0})}}(e);const r=function(){if(Y.math=new N(Math),!h){const e=(()=>{if(h)return new ze;const e=window;return void 0!==e&&"$"in e?{$:new N(e.$,"jquery"),window:new N(e,"window"),document:new N(e.document,"document")}:new Ue(n.unknown,"$ must be property of window to use dom library")})();if(e instanceof Re)return e;H.dom=e}}();if(r)return r;e.initialisedAsGlobal=!0}class Z{constructor(){this.symbolTable={},this.initialisedAsGlobal=!1,this.deleted=!1,this.path_=""}get path(){return this.path_||!this.parent?this.path_:this.parent.path}set path(e){this.path_=e}get parent(){return this.parent_}set parent(e){e!=this?this.parent_=e:console.error(V.red("Setting context parent to self"))}has(e){return void 0!==this.get(e)}hasOwn(e){return this.symbolTable[e]instanceof L}get(e){let t=this.getSymbol(e);return t instanceof Re||null==t?t:t.value}getRawSymbolTableAsDict(){const e={};for(let t in this.symbolTable)e[t]=this.symbolTable[t].value;return e}getSymbolTableAsDict(){const e={};for(let t in this.symbolTable)e[t]=this.symbolTable[t];return e}getSymbol(e){let t=this.symbolTable[e];if(void 0!==t&&!t.isAccessible)return new De(n.unknown,"assessable","inaccessible",t.identifier);if(void 0===t&&this.parent){let i=this.parent.getSymbol(e);if(i instanceof Re)return i;if(!i)return new Ue(n.unknown,e);t=i}return t}set(e,t,n={}){let i=this;if(n.global)i=this.root;else{for(;!i.hasOwn(e)&&void 0!==i.parent;)i=i.parent;i.hasOwn(e)||(i=this)}return i.setOwn(e,t,n)}setOwn(e,t,i={}){if(t instanceof C||(t=z(t)),i.global&&!this.initialisedAsGlobal&&(i.global=!1),!i.forceThroughConst){let t=this.symbolTable[e];if(null==t?void 0:t.isConstant)return new De(n.unknown,"dynamic","constant",e)}this.symbolTable[e]=new L(t,e,i)}remove(e){delete this.symbolTable[e]}clear(){for(let e in this.symbolTable)this.remove(e);this.parent=void 0,this.deleted=!0}get root(){let e=this;for(;e.parent;)e=e.parent;return e}get keys(){return Object.keys(this.symbolTable)}resetAsGlobal(){var e,t;if(!this.initialisedAsGlobal)return;const n=this.root.get("print"),i=this.root.get("input");n instanceof C&&i instanceof C?(this.symbolTable={},this.initialisedAsGlobal=!1,X(this,(null===(e=n.valueOf())||void 0===e?void 0:e.func)||console.log,(null===(t=i.valueOf())||void 0===t?void 0:t.func)||(()=>{}))):console.error("Error with print and input functions.")}clone(){const e=new Z;return e.parent=this.parent,e.deleted=this.deleted,e.initialisedAsGlobal=this.initialisedAsGlobal,e.symbolTable=Object.assign(Object.assign({},e.symbolTable),this.symbolTable),e}deepClone(){var e;let t=this.clone();return t.parent=null===(e=t.parent)||void 0===e?void 0:e.deepClone(),t}log(){console.log("---- CONTEXT ----");for(let e in this.symbolTable){const t=this.symbolTable[e];let n=e;t.isConstant&&(n+=" (CONST)"),t.isAccessible||(n+=" (INACCESSIBLE)"),n+=": ",n+=Ee(this.symbolTable[e].value),console.log(n)}console.log("-----------------")}}function ee(e,t){var i;let r;const o=e.type.interpret(t);if(o.error)return o.error;if(!(o.val instanceof A))return new De(n.unknown,"Type",typeof o.val,o.val,"Argument can't be undefined");let s;if(r=o.val,e.defaultValue){let n=null===(i=e.defaultValue)||void 0===i?void 0:i.interpret(t);if(n.error)return n.error;n.val instanceof C&&(s=n.val)}return{name:e.name,type:r,defaultValue:s}}class te{constructor(){this.val=new I,this.shouldBreak=!1,this.shouldContinue=!1}}class ne{constructor(e,t=!1){this.pos=e,this.isTerminal=t}interpret(e){var t;const i=v(),r=new te,o=this.interpret_(e);o instanceof Re?r.error=o:o instanceof te?(r.val=o.val,r.error=o.error,r.funcReturn=o.funcReturn,r.shouldBreak=o.shouldBreak,r.shouldContinue=o.shouldContinue):r.val=o,r.error&&r.error.pos.isUnknown&&(r.error.pos=this.pos),r.val instanceof C||(r.error=new De(n.unknown,"Primitive","Native JS value",Ee(r.val)),r.val=new I),(t=r.val.info).file||(t.file=this.pos.file),ne.interprets++;let s=v()-i;return ne.totalTime+=s,s>ne.maxTime&&(ne.maxTime=s),r}}ne.interprets=0,ne.totalTime=0,ne.maxTime=0;class ie extends ne{constructor(e,t,n,i){super(e),this.left=t,this.opTok=n,this.right=i}interpret_(e){const t=this.left.interpret(e);if(t.error)return t.error;const n=this.right.interpret(e);if(n.error)return n.error;const i=t.val,r=n.val;if(void 0===i)return new De(this.opTok.pos,"~undefined","undefined",i,"N_binOp.interpret_");if(void 0===r)return new De(this.opTok.pos,"~undefined","undefined",r,"N_binOp.interpret_");switch(this.opTok.type){case x.LTE:{const t=i.__lt__({context:e},r),n=i.__eq__({context:e},r);return t instanceof Re?t:n instanceof Re?n:t.__or__({context:e},n)}case x.GTE:{const t=i.__gt__({context:e},r),n=i.__eq__({context:e},r);return t instanceof Re?t:n instanceof Re?n:t.__or__({context:e},n)}case x.NOTEQUALS:{const t=i.__eq__({context:e},r);return t instanceof Re?t:new $(!t.bool().valueOf())}case x.ADD:return i.__add__({context:e},r);case x.SUB:return i.__subtract__({context:e},r);case x.MUL:return i.__multiply__({context:e},r);case x.DIV:return i.__divide__({context:e},r);case x.POW:return i.__pow__({context:e},r);case x.EQUALS:return i.__eq__({context:e},r);case x.LT:return i.__lt__({context:e},r);case x.GT:return i.__gt__({context:e},r);case x.AND:return i.__and__({context:e},r);case x.OR:return i.__or__({context:e},r);default:return new Ne(this.opTok.pos,`Invalid binary operator: ${b[this.opTok.type]}`)}}}class re extends ne{constructor(e,t,n){super(e),this.a=t,this.opTok=n}interpret_(e){var t,n,i;const r=this.a.interpret(e);if(r.error)return r.error;switch(this.opTok.type){case x.SUB:case x.ADD:if(!(r.val instanceof D))return new De(this.pos,"Number",(null===(t=r.val)||void 0===t?void 0:t.typeName().toString())||"undefined_",null===(n=r.val)||void 0===n?void 0:n.valueOf());const e=r.val.valueOf();return new D(this.opTok.type===x.SUB?-e:Math.abs(e));case x.NOT:return new $(!(null===(i=null==r?void 0:r.val)||void 0===i?void 0:i.bool().valueOf()));default:return new Ne(this.opTok.pos,`Invalid unary operator: ${b[this.opTok.type]}`)}}}class oe extends ne{constructor(e,t,n,i="=",r=!1,o=!1,s=!1,a=!1,l=k.any){super(e),this.value=n,this.varNameTok=t,this.isGlobal=r,this.assignType=i,this.isConstant=s,this.isDeclaration=a,this.isLocal=o,this.type=l instanceof A?new Ce(l):l}interpret_(e){var t,n,i,r;if(this.isDeclaration&&e.hasOwn(this.varNameTok.value))return new Ne(this.pos,`Symbol '${this.varNameTok.value}' already exists, and cannot be redeclared`);const o=this.value.interpret(e),s=this.type.interpret(e);if(o.error)return o.error;if(s.error)return s.error;if(!(s.val&&s.val instanceof A))return new De(this.varNameTok.pos,"Type",null!==(n=null===(t=s.val)||void 0===t?void 0:t.typeName().valueOf())&&void 0!==n?n:"undefined",null===(i=s.val)||void 0===i?void 0:i.str(),"@ !typeRes.val || !(typeRes.val instanceof ESType)");if(!o.val)return new De(this.varNameTok.pos,"~undefined","undefined","N_varAssign.interpret_");if(!s.val.includesType({context:e},o.val.__type__).bool().valueOf())return new De(this.varNameTok.pos,Ee(s.val),Ee(null===(r=o.val)||void 0===r?void 0:r.typeName()),Ee(o.val));if(this.isDeclaration)return"="!==this.assignType?new Ne(this.pos,`Cannot declare variable with operator '${this.assignType}'`):(e.setOwn(this.varNameTok.value,o.val,{global:!1,isConstant:this.isConstant}),o.val);if("="===this.assignType){let t=o.val;void 0===t&&(t=new I);const n=e.set(this.varNameTok.value,t,{global:this.isGlobal,isConstant:this.isConstant});if(n instanceof Re)return n}else{if(this.isDeclaration)return new Ne(this.pos,`Cannot declare variable with operator '${this.assignType}'`);const t=e.get(this.varNameTok.value);if(t instanceof Re)return t;if(null==t)return new Ne(this.pos,`Cannot declare variable with operator '${this.assignType}'`);let n,i=o.val;switch(this.assignType[0]){case"*":n=t.__multiply__({context:e},i);break;case"/":n=t.__divide__({context:e},i);break;case"+":n=t.__add__({context:e},i);break;case"-":n=t.__subtract__({context:e},i);break;default:return new Re(this.pos,"AssignError",`Cannot find assignType of ${this.assignType[0]}`)}if(n instanceof Re)return n;let r=e.set(this.varNameTok.value,n,{global:this.isGlobal,isConstant:this.isConstant});if(r instanceof Re)return r;o.val=n}return"(anonymous)"!==o.val.info.name&&o.val.info.name||(o.val.info.name=this.varNameTok.value),o}}class se extends ne{constructor(e,t,n,i){super(e),this.comparison=t,this.ifFalse=i,this.ifTrue=n}interpret_(e){var t;let n=new Z;n.parent=e;let i=new te,r=this.comparison.interpret(e);if(r.error)return r;if(null===(t=r.val)||void 0===t?void 0:t.bool().valueOf()){if(i=this.ifTrue.interpret(n),i.val=new I,i.error)return i}else if(this.ifFalse&&(i=this.ifFalse.interpret(n),i.val=new I,i.error))return i;return i}}class ae extends ne{constructor(e,t,n){super(e),this.comparison=t,this.loop=n}interpret_(e){var t,n;let i=new Z;for(i.parent=e;;){let r=this.comparison.interpret(e);if(r.error)return r;if(!(null===(n=null===(t=r.val)||void 0===t?void 0:t.bool())||void 0===n?void 0:n.valueOf()))break;let o=this.loop.interpret(i);if(o.error)return o;if(o.shouldBreak)break}return new I}}class le extends ne{constructor(e,t,n,i,r,o){super(e),this.body=t,this.array=n,this.identifier=i,this.isGlobalId=r,this.isConstId=o}interpret_(e){var t,n,i,r,o,s,a,l;let c=new Z;c.parent=e;const u=this.array.interpret(e);if(u.error)return u;if(-1===["Array","Number","Object","String","Any"].indexOf((null===(t=u.val)||void 0===t?void 0:t.typeName().valueOf())||""))return new De(this.identifier.pos,"Array | Number | Object | String",typeof u.val+" | "+(null===(n=u.val)||void 0===n?void 0:n.typeName()));function h(e,t,n,i,r){c.set(t,n,{global:i,isConstant:r});const o=e.interpret(c);return o.error||void 0!==o.funcReturn?o:o.shouldBreak?(o.shouldBreak=!1,"break"):void(o.shouldContinue&&(o.shouldContinue=!1))}if(u.val instanceof D||"number"==typeof(null===(i=u.val)||void 0===i?void 0:i.valueOf()))for(let e=0;e<u.val.valueOf();e++){const t=h(this.body,this.identifier.value,new D(e),this.isGlobalId,this.isConstId);if("break"===t)break;if(t&&(t.error||void 0!==t.funcReturn))return t}else if(u.val instanceof R||"number"==typeof(null===(r=u.val)||void 0===r?void 0:r.valueOf())&&!Array.isArray(null===(o=u.val)||void 0===o?void 0:o.valueOf()))for(let e in null===(s=u.val)||void 0===s?void 0:s.valueOf()){const t=h(this.body,this.identifier.value,new j(e),this.isGlobalId,this.isConstId);if("break"===t)break;if(t&&(t.error||void 0!==t.funcReturn))return t}else{if(!(u.val instanceof U||Array.isArray(null===(a=u.val)||void 0===a?void 0:a.valueOf())))return new De(this.identifier.pos,"Array | Number | Object | String",typeof u.val);for(let e of null===(l=u.val)||void 0===l?void 0:l.valueOf()){const t=h(this.body,this.identifier.value,e,this.isGlobalId,this.isConstId);if("break"===t)break;if(t&&(t.error||void 0!==t.funcReturn))return t}}return new I}}class ce extends ne{constructor(e,t,n=!1){super(e),this.items=t,this.shouldClone=n}interpret_(e){let t=new te,n=[];for(let t of this.items){const i=t.interpret(e);if(i.error||void 0!==i.funcReturn)return i;if(!i.val)continue;let r=i.val;this.shouldClone&&(r=r.clone()),n.push(r)}return t.val=new U(n),t}}class ue extends ne{constructor(e,t){super(e),this.properties=t}interpret_(e){let t={};for(const[n,i]of this.properties){const r=i.interpret(e);if(r.error)return r.error;const o=n.interpret(e);if(o.error)return o.error;o.val&&r.val&&(t[o.val.valueOf()]=r.val)}return new R(t)}}class he extends ne{constructor(e){super(e)}interpret_(e){return new R({})}}class fe extends ne{constructor(e,t){super(e),this.items=t}interpret_(e){let t;for(let n of this.items){const i=n.interpret(e);if(i.error||void 0!==i.funcReturn||i.shouldBreak||i.shouldContinue)return i;t=i.val}return t||new I}}class de extends ne{constructor(e,t,n){super(e),this.arguments=n,this.to=t}interpret_(e){let{val:t,error:n}=this.to.interpret(e);if(n)return n;if(!t)return new De(this.pos,"any","undefined",void 0,"On function call");let i=[];for(let t of this.arguments){const n=t.interpret(e);if(n.error)return n.error;n.val&&i.push(n.val)}const r=t.__call__({context:e},...i);return r instanceof Re&&r.traceback.push({position:this.pos,line:`${t.info.name||"<AnonFunction>"}(${i.map(Ee).join(", ")})`}),r}}class pe extends ne{constructor(e,t,n,i,r="(anon)",o=new R,s=""){super(e),this.arguments=n,this.body=t,this.name=r,this.this_=o,this.returnType=i,this.description=s}interpret_(e){var t,n,i;let r=[];for(let t of this.arguments){const n=ee(t,e);if(n instanceof Re)return n;r.push(n)}const o=this.returnType.interpret(e);return o.error?o.error:o.val instanceof A?new M(this.body,r,this.name,this.this_,o.val,e):new De(this.returnType.pos,"Type",null!==(n=null===(t=o.val)||void 0===t?void 0:t.typeName().valueOf())&&void 0!==n?n:"<Undefined>",null===(i=o.val)||void 0===i?void 0:i.str().valueOf(),`On func '${this.name}' return type`)}}class ve extends ne{constructor(e,t){super(e),this.value=t}interpret_(e){const t=new te;if(void 0===this.value)return t.funcReturn=new I,t;let n=this.value.interpret(e);return n.error?n.error:(t.funcReturn=n.val,t)}}class ye extends ne{constructor(e,t){super(e),this.value=t}interpret_(e){var t;const n=new te;if(void 0===this.value)return n.funcReturn=new I,n;let i=this.value.interpret(e);return i.error?i.error:((null===(t=i.val)||void 0===t?void 0:t.bool().valueOf())&&(n.funcReturn=i.val),n)}}class me extends ne{constructor(e,t,n){super(e),this.base=t,this.index=n}interpret_(e){var t;let n=this.base.interpret(e);if(n.error)return n;let i=this.index.interpret(e);if(i.error)return i;const r=i.val,o=n.val;if(!o||!r)return new I;if(void 0!==this.value){let n=this.value.interpret(e);if(n.error)return n;const i=z(o.__getProperty__({context:e},r));let s,a=n.val;if(null!==(t=this.assignType)&&void 0!==t||(this.assignType="="),!a)return new De(this.pos,"~undefined","undefined","undefined","N_indexed.interpret_");switch(this.assignType[0]){case"*":s=i.__multiply__({context:e},a);break;case"/":s=i.__divide__({context:e},a);break;case"+":s=i.__add__({context:e},a);break;case"-":s=i.__subtract__({context:e},a);break;case"=":s=a;break;default:return new Re(this.pos,"AssignError",`Cannot find assignType of ${this.assignType[0]}`)}if(s instanceof Re)return s;if(!o.__setProperty__)return new De(this.pos,"mutable","immutable",o.valueOf());const l=o.__setProperty__({context:e},r,null!=s?s:new I);if(l instanceof Re)return l}return o.__getProperty__({context:e},r)}}class ge extends ne{constructor(e,t,n,i,r="<anon class>"){super(e),this.init=i,this.methods=t,this.name=r,this.extends_=n,this.instances=[]}interpret_(e){var t,n,i;const r=[];for(let n of this.methods){const i=n.interpret(e);if(i.error)return i.error;if(!(i.val instanceof M))return new De(this.pos,"Function",(null===(t=i.val)||void 0===t?void 0:t.typeName().valueOf())||"undefined","method on "+this.name);r.push(i.val)}let o,s;if(this.extends_){const t=this.extends_.interpret(e);if(t.error)return t.error;if(!(t.val instanceof A))return new De(this.pos,"Function",(null===(n=t.val)||void 0===n?void 0:n.typeName().valueOf())||"undefined","method on "+this.name);o=t.val}if(this.init){const t=this.init.interpret(e);if(t.error)return t.error;if(!(t.val instanceof M))return new De(this.pos,"Function",(null===(i=t.val)||void 0===i?void 0:i.typeName().valueOf())||"undefined","method on "+this.name);s=t.val}return new A(!1,this.name,r,o,s)}}class xe extends ne{constructor(e,t,n="(anon)",i=!1){super(e),this.name=n,this.statements=t,this.mutable=i}interpret_(e){const t=new Z;t.parent=e;const n=this.statements.interpret(t);return n.error?n:new B(new j(this.name),t.getSymbolTableAsDict(),this.mutable)}}class be extends ne{constructor(e,t){super(e,!0),this.a=t}interpret_(e){let t=this.a.value;if("number"!=typeof t)return new De(this.pos,"number",typeof t);const n=new te;return n.val=new D(t),n}}class we extends ne{constructor(e,t){super(e,!0),this.a=t}interpret_(e){let t=this.a.value;if("string"!=typeof t)return new De(this.pos,"string",typeof t);const n=new te;return n.val=new j(t),n}}class _e extends ne{constructor(e){super(e.pos,!0),this.a=e}interpret_(e){if(!e.has(this.a.value))return new Ue(this.a.pos,this.a.value);let t=new te,n=e.getSymbol(this.a.value);return n?n instanceof Re?n:(t.val=n.value,t):new I}}class Se extends ne{constructor(e=n.unknown){super(e,!0)}interpr