@lewin671/python-vm 0.1.3 → 0.1.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Lewin671
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # @lewin671/python-vm
2
2
 
3
- [![License](https://img.shields.io/github/license/Lewin671/python-compiler-ts)](https://github.com/Lewin671/python-compiler-ts/blob/main/LICENSE)
3
+ [![License](https://img.shields.io/github/license/Lewin671/python-vm)](https://github.com/Lewin671/python-vm/blob/main/LICENSE)
4
4
  [![NPM Version](https://img.shields.io/npm/v/@lewin671/python-vm)](https://www.npmjs.com/package/@lewin671/python-vm)
5
5
 
6
6
  A high-performance Python compiler and Virtual Machine (VM) implemented entirely in TypeScript. This project aims to provide a robust, Python-compliant execution environment within the JavaScript ecosystem, featuring a complete compilation pipeline from source code to bytecode.
@@ -0,0 +1,12 @@
1
+ #!/usr/bin/env node
2
+ "use strict";var x=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports);var It=x(Re=>{"use strict";Object.defineProperty(Re,"__esModule",{value:!0});Re.TokenType=void 0;var St;(function(e){e[e.KEYWORD=0]="KEYWORD",e[e.IDENTIFIER=1]="IDENTIFIER",e[e.NUMBER=2]="NUMBER",e[e.STRING=3]="STRING",e[e.BOOLEAN=4]="BOOLEAN",e[e.NONE=5]="NONE",e[e.OPERATOR=6]="OPERATOR",e[e.LPAREN=7]="LPAREN",e[e.RPAREN=8]="RPAREN",e[e.LBRACKET=9]="LBRACKET",e[e.RBRACKET=10]="RBRACKET",e[e.LBRACE=11]="LBRACE",e[e.RBRACE=12]="RBRACE",e[e.ASSIGN=13]="ASSIGN",e[e.COLON=14]="COLON",e[e.COMMA=15]="COMMA",e[e.DOT=16]="DOT",e[e.AT=17]="AT",e[e.EOF=18]="EOF",e[e.INDENT=19]="INDENT",e[e.DEDENT=20]="DEDENT",e[e.NEWLINE=21]="NEWLINE"})(St||(Re.TokenType=St={}))});var bt=x(ge=>{"use strict";Object.defineProperty(ge,"__esModule",{value:!0});ge.ASTNodeType=void 0;var Ot;(function(e){e.PROGRAM="Program",e.EXPRESSION_STATEMENT="ExpressionStatement",e.BINARY_OPERATION="BinaryOperation",e.UNARY_OPERATION="UnaryOperation",e.BOOL_OPERATION="BoolOperation",e.COMPARE="Compare",e.CALL="Call",e.ATTRIBUTE="Attribute",e.SUBSCRIPT="Subscript",e.IF_EXPRESSION="IfExpression",e.LIST_LITERAL="ListLiteral",e.TUPLE_LITERAL="TupleLiteral",e.DICT_LITERAL="DictLiteral",e.SET_LITERAL="SetLiteral",e.NUMBER_LITERAL="NumberLiteral",e.STRING_LITERAL="StringLiteral",e.BOOLEAN_LITERAL="BooleanLiteral",e.NONE_LITERAL="NoneLiteral",e.IDENTIFIER="Identifier",e.ASSIGNMENT="Assignment",e.AUG_ASSIGNMENT="AugAssignment",e.ASSERT_STATEMENT="AssertStatement",e.RAISE_STATEMENT="RaiseStatement",e.PASS_STATEMENT="PassStatement",e.BREAK_STATEMENT="BreakStatement",e.CONTINUE_STATEMENT="ContinueStatement",e.RETURN_STATEMENT="ReturnStatement",e.YIELD="Yield",e.GLOBAL_STATEMENT="GlobalStatement",e.NONLOCAL_STATEMENT="NonlocalStatement",e.DELETE_STATEMENT="DeleteStatement",e.IMPORT_STATEMENT="ImportStatement",e.IF_STATEMENT="IfStatement",e.WHILE_STATEMENT="WhileStatement",e.FOR_STATEMENT="ForStatement",e.TRY_STATEMENT="TryStatement",e.WITH_STATEMENT="WithStatement",e.FUNCTION_DEF="FunctionDef",e.CLASS_DEF="ClassDef",e.LAMBDA="Lambda",e.MATCH_STATEMENT="MatchStatement",e.MATCH_PATTERN_VALUE="MatchPatternValue",e.MATCH_PATTERN_WILDCARD="MatchPatternWildcard",e.MATCH_PATTERN_CAPTURE="MatchPatternCapture",e.MATCH_PATTERN_SEQUENCE="MatchPatternSequence",e.MATCH_PATTERN_OR="MatchPatternOr",e.LIST_COMP="ListComp",e.DICT_COMP="DictComp",e.SET_COMP="SetComp",e.GENERATOR_EXPR="GeneratorExpr",e.SLICE="Slice",e.STARRED="Starred",e.STAR_ARG="StarArg",e.KW_ARG="KwArg",e.KEYWORD_ARG="KeywordArg",e.VAR_ARG="VarArg",e.PARAM="Param",e.COMPREHENSION="Comprehension",e.KEY_VALUE="KeyValue"})(Ot||(ge.ASTNodeType=Ot={}))});var Pt=x(Ne=>{"use strict";Object.defineProperty(Ne,"__esModule",{value:!0});Ne.CompareOp=Ne.OpCode=void 0;var Rt;(function(e){e[e.LOAD_CONST=0]="LOAD_CONST",e[e.LOAD_NAME=1]="LOAD_NAME",e[e.STORE_NAME=2]="STORE_NAME",e[e.DELETE_NAME=3]="DELETE_NAME",e[e.LOAD_FAST=4]="LOAD_FAST",e[e.STORE_FAST=5]="STORE_FAST",e[e.DELETE_FAST=6]="DELETE_FAST",e[e.LOAD_GLOBAL=7]="LOAD_GLOBAL",e[e.STORE_GLOBAL=8]="STORE_GLOBAL",e[e.DELETE_GLOBAL=9]="DELETE_GLOBAL",e[e.LOAD_ATTR=10]="LOAD_ATTR",e[e.STORE_ATTR=11]="STORE_ATTR",e[e.DELETE_ATTR=12]="DELETE_ATTR",e[e.LOAD_SUBSCR=13]="LOAD_SUBSCR",e[e.STORE_SUBSCR=14]="STORE_SUBSCR",e[e.DELETE_SUBSCR=15]="DELETE_SUBSCR",e[e.POP_TOP=16]="POP_TOP",e[e.DUP_TOP=17]="DUP_TOP",e[e.DUP_TOP_TWO=18]="DUP_TOP_TWO",e[e.ROT_TWO=19]="ROT_TWO",e[e.ROT_THREE=20]="ROT_THREE",e[e.BINARY_ADD=21]="BINARY_ADD",e[e.BINARY_SUBTRACT=22]="BINARY_SUBTRACT",e[e.BINARY_MULTIPLY=23]="BINARY_MULTIPLY",e[e.BINARY_DIVIDE=24]="BINARY_DIVIDE",e[e.BINARY_FLOOR_DIVIDE=25]="BINARY_FLOOR_DIVIDE",e[e.BINARY_MODULO=26]="BINARY_MODULO",e[e.BINARY_POWER=27]="BINARY_POWER",e[e.BINARY_LSHIFT=28]="BINARY_LSHIFT",e[e.BINARY_RSHIFT=29]="BINARY_RSHIFT",e[e.BINARY_AND=30]="BINARY_AND",e[e.BINARY_XOR=31]="BINARY_XOR",e[e.BINARY_OR=32]="BINARY_OR",e[e.INPLACE_ADD=33]="INPLACE_ADD",e[e.INPLACE_SUBTRACT=34]="INPLACE_SUBTRACT",e[e.INPLACE_MULTIPLY=35]="INPLACE_MULTIPLY",e[e.INPLACE_DIVIDE=36]="INPLACE_DIVIDE",e[e.INPLACE_FLOOR_DIVIDE=37]="INPLACE_FLOOR_DIVIDE",e[e.INPLACE_MODULO=38]="INPLACE_MODULO",e[e.INPLACE_POWER=39]="INPLACE_POWER",e[e.INPLACE_LSHIFT=40]="INPLACE_LSHIFT",e[e.INPLACE_RSHIFT=41]="INPLACE_RSHIFT",e[e.INPLACE_AND=42]="INPLACE_AND",e[e.INPLACE_XOR=43]="INPLACE_XOR",e[e.INPLACE_OR=44]="INPLACE_OR",e[e.UNARY_POSITIVE=45]="UNARY_POSITIVE",e[e.UNARY_NEGATIVE=46]="UNARY_NEGATIVE",e[e.UNARY_NOT=47]="UNARY_NOT",e[e.UNARY_INVERT=48]="UNARY_INVERT",e[e.COMPARE_OP=49]="COMPARE_OP",e[e.JUMP_FORWARD=50]="JUMP_FORWARD",e[e.JUMP_ABSOLUTE=51]="JUMP_ABSOLUTE",e[e.POP_JUMP_IF_FALSE=52]="POP_JUMP_IF_FALSE",e[e.POP_JUMP_IF_TRUE=53]="POP_JUMP_IF_TRUE",e[e.JUMP_IF_FALSE_OR_POP=54]="JUMP_IF_FALSE_OR_POP",e[e.JUMP_IF_TRUE_OR_POP=55]="JUMP_IF_TRUE_OR_POP",e[e.BUILD_LIST=56]="BUILD_LIST",e[e.BUILD_TUPLE=57]="BUILD_TUPLE",e[e.BUILD_SET=58]="BUILD_SET",e[e.BUILD_MAP=59]="BUILD_MAP",e[e.BUILD_SLICE=60]="BUILD_SLICE",e[e.UNPACK_SEQUENCE=61]="UNPACK_SEQUENCE",e[e.UNPACK_EX=62]="UNPACK_EX",e[e.BUILD_CONST_KEY_MAP=63]="BUILD_CONST_KEY_MAP",e[e.LIST_APPEND=64]="LIST_APPEND",e[e.SET_ADD=65]="SET_ADD",e[e.MAP_ADD=66]="MAP_ADD",e[e.CALL_FUNCTION=67]="CALL_FUNCTION",e[e.CALL_FUNCTION_KW=68]="CALL_FUNCTION_KW",e[e.CALL_FUNCTION_EX=69]="CALL_FUNCTION_EX",e[e.MAKE_FUNCTION=70]="MAKE_FUNCTION",e[e.RETURN_VALUE=71]="RETURN_VALUE",e[e.YIELD_VALUE=72]="YIELD_VALUE",e[e.GET_ITER=73]="GET_ITER",e[e.FOR_ITER=74]="FOR_ITER",e[e.SETUP_FINALLY=75]="SETUP_FINALLY",e[e.SETUP_WITH=76]="SETUP_WITH",e[e.WITH_EXCEPT_START=77]="WITH_EXCEPT_START",e[e.POP_BLOCK=78]="POP_BLOCK",e[e.RAISE_VARARGS=79]="RAISE_VARARGS",e[e.IMPORT_NAME=80]="IMPORT_NAME",e[e.IMPORT_FROM=81]="IMPORT_FROM",e[e.IMPORT_STAR=82]="IMPORT_STAR",e[e.LOAD_BUILD_CLASS=83]="LOAD_BUILD_CLASS",e[e.PRINT_ITEM=84]="PRINT_ITEM",e[e.PRINT_NEWLINE=85]="PRINT_NEWLINE",e[e.EVAL_AST=86]="EVAL_AST"})(Rt||(Ne.OpCode=Rt={}));var gt;(function(e){e[e.LT=0]="LT",e[e.LE=1]="LE",e[e.EQ=2]="EQ",e[e.NE=3]="NE",e[e.GT=4]="GT",e[e.GE=5]="GE",e[e.IN=6]="IN",e[e.NOT_IN=7]="NOT_IN",e[e.IS=8]="IS",e[e.IS_NOT=9]="IS_NOT"})(gt||(Ne.CompareOp=gt={}))});var Lt=x(xt=>{"use strict";Object.defineProperty(xt,"__esModule",{value:!0})});var W=x(ne=>{"use strict";var Es=ne&&ne.__createBinding||(Object.create?(function(e,t,s,n){n===void 0&&(n=s);var r=Object.getOwnPropertyDescriptor(t,s);(!r||("get"in r?!t.__esModule:r.writable||r.configurable))&&(r={enumerable:!0,get:function(){return t[s]}}),Object.defineProperty(e,n,r)}):(function(e,t,s,n){n===void 0&&(n=s),e[n]=t[s]})),Pe=ne&&ne.__exportStar||function(e,t){for(var s in e)s!=="default"&&!Object.prototype.hasOwnProperty.call(t,s)&&Es(t,e,s)};Object.defineProperty(ne,"__esModule",{value:!0});Pe(It(),ne);Pe(bt(),ne);Pe(Pt(),ne);Pe(Lt(),ne)});var Ct=x(xe=>{"use strict";Object.defineProperty(xe,"__esModule",{value:!0});xe.Lexer=void 0;var b=W(),$e=class{constructor(t){this.pos=0,this.line=1,this.column=1,this.tokens=[],this.indentStack=[0],this.atLineStart=!0,this.code=t}tokenize(){let t=0,s=(c,o)=>({type:c,value:o,line:this.line,column:this.column-o.length}),n=(c=1)=>{for(let o=0;o<c;o++)this.code[this.pos]===`
3
+ `?(this.line++,this.column=1):this.column++,this.pos++},r=(c=0)=>this.code[this.pos+c]||"",i=c=>{let o=this.indentStack[this.indentStack.length-1];if(c>o)t===0&&this.tokens.push(s(b.TokenType.INDENT,"")),this.indentStack.push(c);else if(c<o){for(;c<this.indentStack[this.indentStack.length-1];)t===0&&this.tokens.push(s(b.TokenType.DEDENT,"")),this.indentStack.pop();if(c!==this.indentStack[this.indentStack.length-1])throw new Error(`Indentation error at line ${this.line}`)}};for(;this.pos<this.code.length;){if(this.atLineStart){let o=0;for(;r()===" "||r()===" ";)o+=r()===" "?4:1,n();if(r()===`
4
+ `||r()==="#"){if(r()==="#")for(;this.pos<this.code.length&&r()!==`
5
+ `;)n();r()===`
6
+ `&&n(),this.atLineStart=!0;continue}i(o),this.atLineStart=!1}if(this.pos>=this.code.length)break;let c=r();if(c===" "||c===" "){n();continue}if(c==="#"){for(;this.pos<this.code.length&&r()!==`
7
+ `;)n();continue}if(c===`
8
+ `){t===0&&this.tokens.push(s(b.TokenType.NEWLINE,`
9
+ `)),n(),this.atLineStart=!0;continue}if(/[0-9]/.test(c)||c==="."&&/[0-9]/.test(r(1))){let o="",p=!1;for(c==="."&&(p=!0,o+=".",n());this.pos<this.code.length&&/[0-9]/.test(r());)o+=r(),n();if(r()==="."&&!p)for(p=!0,o+=".",n();this.pos<this.code.length&&/[0-9]/.test(r());)o+=r(),n();(r()==="j"||r()==="J")&&(o+=r(),n()),this.tokens.push(s(b.TokenType.NUMBER,o));continue}if(c==='"'||c==="'"||(c==="f"||c==="F")&&(r(1)==='"'||r(1)==="'")){let o="",p=c;(c==="f"||c==="F")&&(o=c,p=r(1),n());let E=o+p;n();let y=r()===p&&r(1)===p;for(y&&(E+=p+p,n(2));this.pos<this.code.length&&!(!y&&r()===p||y&&r()===p&&r(1)===p&&r(2)===p);)r()==="\\"?(E+=r(),n(),this.pos<this.code.length&&(E+=r(),n())):(E+=r(),n());if(!y&&r()===p)E+=p,n();else if(y&&r()===p&&r(1)===p&&r(2)===p)E+=p+p+p,n(3);else throw new Error(`Unterminated string at line ${this.line}`);this.tokens.push(s(b.TokenType.STRING,E));continue}if(/[a-zA-Z_]/.test(c)){let o="";for(;this.pos<this.code.length&&/[a-zA-Z0-9_]/.test(r());)o+=r(),n();o==="def"||o==="class"||o==="if"||o==="elif"||o==="else"||o==="for"||o==="while"||o==="return"||o==="break"||o==="continue"||o==="pass"||o==="in"||o==="is"||o==="and"||o==="or"||o==="not"||o==="lambda"||o==="yield"||o==="try"||o==="except"||o==="finally"||o==="with"||o==="as"||o==="global"||o==="nonlocal"||o==="assert"||o==="raise"||o==="del"||o==="match"||o==="case"||o==="import"||o==="async"?this.tokens.push(s(b.TokenType.KEYWORD,o)):o==="True"||o==="False"?this.tokens.push(s(b.TokenType.BOOLEAN,o)):o==="None"?this.tokens.push(s(b.TokenType.NONE,o)):this.tokens.push(s(b.TokenType.IDENTIFIER,o));continue}switch(c){case"+":r(1)==="="?(this.tokens.push(s(b.TokenType.OPERATOR,"+=")),n(2)):(this.tokens.push(s(b.TokenType.OPERATOR,"+")),n());break;case"-":r(1)==="="?(this.tokens.push(s(b.TokenType.OPERATOR,"-=")),n(2)):(this.tokens.push(s(b.TokenType.OPERATOR,"-")),n());break;case"*":r(1)==="*"?r(2)==="="?(this.tokens.push(s(b.TokenType.OPERATOR,"**=")),n(3)):(this.tokens.push(s(b.TokenType.OPERATOR,"**")),n(2)):r(1)==="="?(this.tokens.push(s(b.TokenType.OPERATOR,"*=")),n(2)):(this.tokens.push(s(b.TokenType.OPERATOR,"*")),n());break;case"/":r(1)==="/"?r(2)==="="?(this.tokens.push(s(b.TokenType.OPERATOR,"//=")),n(3)):(this.tokens.push(s(b.TokenType.OPERATOR,"//")),n(2)):r(1)==="="?(this.tokens.push(s(b.TokenType.OPERATOR,"/=")),n(2)):(this.tokens.push(s(b.TokenType.OPERATOR,"/")),n());break;case"%":r(1)==="="?(this.tokens.push(s(b.TokenType.OPERATOR,"%=")),n(2)):(this.tokens.push(s(b.TokenType.OPERATOR,"%")),n());break;case"=":r(1)==="="?(this.tokens.push(s(b.TokenType.OPERATOR,"==")),n(2)):(this.tokens.push(s(b.TokenType.ASSIGN,"=")),n());break;case"!":if(r(1)==="=")this.tokens.push(s(b.TokenType.OPERATOR,"!=")),n(2);else throw new Error(`Unexpected character '!' at line ${this.line}`);break;case"&":this.tokens.push(s(b.TokenType.OPERATOR,"&")),n();break;case"|":this.tokens.push(s(b.TokenType.OPERATOR,"|")),n();break;case"^":this.tokens.push(s(b.TokenType.OPERATOR,"^")),n();break;case"~":this.tokens.push(s(b.TokenType.OPERATOR,"~")),n();break;case"<":r(1)==="<"?(this.tokens.push(s(b.TokenType.OPERATOR,"<<")),n(2)):r(1)==="="?(this.tokens.push(s(b.TokenType.OPERATOR,"<=")),n(2)):(this.tokens.push(s(b.TokenType.OPERATOR,"<")),n());break;case">":r(1)===">"?(this.tokens.push(s(b.TokenType.OPERATOR,">>")),n(2)):r(1)==="="?(this.tokens.push(s(b.TokenType.OPERATOR,">=")),n(2)):(this.tokens.push(s(b.TokenType.OPERATOR,">")),n());break;case"(":this.tokens.push(s(b.TokenType.LPAREN,"(")),n(),t++;break;case")":this.tokens.push(s(b.TokenType.RPAREN,")")),n(),t--;break;case"[":this.tokens.push(s(b.TokenType.LBRACKET,"[")),n(),t++;break;case"]":this.tokens.push(s(b.TokenType.RBRACKET,"]")),n(),t--;break;case"{":this.tokens.push(s(b.TokenType.LBRACE,"{")),n(),t++;break;case"}":this.tokens.push(s(b.TokenType.RBRACE,"}")),n(),t--;break;case":":this.tokens.push(s(b.TokenType.COLON,":")),n();break;case",":this.tokens.push(s(b.TokenType.COMMA,",")),n();break;case".":this.tokens.push(s(b.TokenType.DOT,".")),n();break;case"@":this.tokens.push(s(b.TokenType.AT,"@")),n();break;case" ":case" ":n();break;default:throw new Error(`Unexpected character '${c}' at line ${this.line}, column ${this.column}`)}}for(;this.indentStack.length>1;)this.tokens.push(s(b.TokenType.DEDENT,"")),this.indentStack.pop();return this.tokens.push(s(b.TokenType.EOF,"")),this.tokens}};xe.Lexer=$e});var Ce=x(Le=>{"use strict";Object.defineProperty(Le,"__esModule",{value:!0});Le.Lexer=void 0;var _s=Ct();Object.defineProperty(Le,"Lexer",{enumerable:!0,get:function(){return _s.Lexer}})});var Bt=x(w=>{"use strict";Object.defineProperty(w,"__esModule",{value:!0});w.parseStringLiteral=As;w.parseLiteral=Ns;w.parseIdentifier=ms;w.parseArguments=ks;w.parseSlice=Ss;w.parsePatternAtom=Is;w.parsePattern=Os;w.parseLambdaParameters=bs;w.parseLambda=Rs;w.parseAtom=gs;w.parsePostfix=Ps;w.parseUnary=xs;w.parsePower=Ls;w.parseFactor=Cs;w.parseTerm=Bs;w.parseShift=ws;w.parseBitAnd=vs;w.parseBitXor=Ms;w.parseBitOr=Ds;w.parseComparison=Fs;w.parseNot=Us;w.parseAnd=Ys;w.parseOr=Gs;w.parseIfExpression=js;w.parseExpression=Vs;w.parseExpressionNoIf=Ws;w.parseComprehension=Ks;var T=W();function As(){let e="";for(;this.match(T.TokenType.STRING);)e+=this.consume().value;return{type:T.ASTNodeType.STRING_LITERAL,value:e}}function Ns(){let e=this.peek();if(!e)throw new Error("Expected literal");if(e.type===T.TokenType.NUMBER)return this.consume(),{type:T.ASTNodeType.NUMBER_LITERAL,value:e.value};if(e.type===T.TokenType.STRING)return this.parseStringLiteral();if(e.type===T.TokenType.BOOLEAN)return this.consume(),{type:T.ASTNodeType.BOOLEAN_LITERAL,value:e.value==="True"};if(e.type===T.TokenType.NONE)return this.consume(),{type:T.ASTNodeType.NONE_LITERAL,value:null};throw new Error(`Unexpected token type for literal: ${T.TokenType[e.type]}`)}function ms(){let e=this.expect(T.TokenType.IDENTIFIER);return{type:T.ASTNodeType.IDENTIFIER,name:e.value}}function ks(){let e=[];if(!this.match(T.TokenType.RPAREN))for(;;){if(this.match(T.TokenType.OPERATOR,"*")||this.match(T.TokenType.OPERATOR,"**")){let t=this.consume().value,s=this.parseExpression();e.push({type:t==="*"?"StarArg":"KwArg",value:s})}else if(this.match(T.TokenType.IDENTIFIER)&&this.peek(1)?.type===T.TokenType.ASSIGN){let t=this.consume().value;this.consume();let s=this.parseExpression();e.push({type:"KeywordArg",name:t,value:s})}else e.push(this.parseExpression());if(!this.match(T.TokenType.COMMA)||(this.consume(),this.match(T.TokenType.RPAREN)))break}return e}function Ss(){let e=null,t=null,s=null;return this.match(T.TokenType.COLON)||(e=this.parseExpression()),this.match(T.TokenType.COLON)?(this.consume(),!this.match(T.TokenType.COLON)&&!this.match(T.TokenType.RBRACKET)&&(t=this.parseExpression()),this.match(T.TokenType.COLON)&&(this.consume(),this.match(T.TokenType.RBRACKET)||(s=this.parseExpression())),{type:T.ASTNodeType.SLICE,start:e,end:t,step:s}):e}function Is(){if(this.match(T.TokenType.NUMBER)||this.match(T.TokenType.STRING)||this.match(T.TokenType.BOOLEAN)||this.match(T.TokenType.NONE))return{type:T.ASTNodeType.MATCH_PATTERN_VALUE,value:this.parseLiteral()};if(this.match(T.TokenType.IDENTIFIER)){let e=this.consume().value;return e==="_"?{type:T.ASTNodeType.MATCH_PATTERN_WILDCARD}:{type:T.ASTNodeType.MATCH_PATTERN_CAPTURE,name:e}}if(this.match(T.TokenType.LBRACKET)){this.consume();let e=[];if(!this.match(T.TokenType.RBRACKET))for(e.push(this.parsePattern());this.match(T.TokenType.COMMA)&&(this.consume(),!this.match(T.TokenType.RBRACKET));)e.push(this.parsePattern());return this.expect(T.TokenType.RBRACKET),{type:T.ASTNodeType.MATCH_PATTERN_SEQUENCE,elements:e}}throw new Error(`Unexpected token in pattern: ${this.peek()?.value}`)}function Os(){let e=this.parsePatternAtom();if(this.match(T.TokenType.OPERATOR,"|")){let t=[e];for(;this.match(T.TokenType.OPERATOR,"|");)this.consume(),t.push(this.parsePatternAtom());e={type:T.ASTNodeType.MATCH_PATTERN_OR,patterns:t}}return e}function bs(){let e=[];if(this.match(T.TokenType.COLON))return e;for(;;){if(this.match(T.TokenType.OPERATOR,"*"))this.consume(),e.push(`*${this.expect(T.TokenType.IDENTIFIER).value}`);else if(this.match(T.TokenType.OPERATOR,"**"))this.consume(),e.push(`**${this.expect(T.TokenType.IDENTIFIER).value}`);else{let t=this.expect(T.TokenType.IDENTIFIER).value;this.match(T.TokenType.ASSIGN)&&(this.consume(),this.parseExpression()),e.push(t)}if(!this.match(T.TokenType.COMMA))break;this.consume()}return e}function Rs(){this.consume();let e=this.parseLambdaParameters();this.expect(T.TokenType.COLON);let t=this.parseExpression();return{type:T.ASTNodeType.LAMBDA,params:e,body:t}}function gs(){if(this.match(T.TokenType.LPAREN)){if(this.consume(),this.match(T.TokenType.RPAREN))return this.consume(),{type:T.ASTNodeType.TUPLE_LITERAL,elements:[]};let e=this.parseExpression();if(this.match(T.TokenType.KEYWORD,"for")){let t=this.parseComprehension(e);return this.expect(T.TokenType.RPAREN),{type:T.ASTNodeType.GENERATOR_EXPR,expression:e,comprehension:t}}if(this.match(T.TokenType.COMMA)){let t=[e];for(;this.match(T.TokenType.COMMA)&&(this.consume(),!this.match(T.TokenType.RPAREN));)t.push(this.parseExpression());return this.expect(T.TokenType.RPAREN),{type:T.ASTNodeType.TUPLE_LITERAL,elements:t}}return this.expect(T.TokenType.RPAREN),e}if(this.match(T.TokenType.KEYWORD,"yield")){this.consume();let e=this.match(T.TokenType.NEWLINE)||this.match(T.TokenType.COMMA)||this.match(T.TokenType.RPAREN)?null:this.parseExpression();return{type:T.ASTNodeType.YIELD,value:e}}if(this.match(T.TokenType.KEYWORD,"lambda"))return this.parseLambda();if(this.match(T.TokenType.LBRACKET)){if(this.consume(),this.match(T.TokenType.RBRACKET))return this.consume(),{type:T.ASTNodeType.LIST_LITERAL,elements:[]};let e=this.parseExpression();if(this.match(T.TokenType.KEYWORD,"for")){let s=this.parseComprehension(e);return this.expect(T.TokenType.RBRACKET),{type:T.ASTNodeType.LIST_COMP,expression:e,comprehension:s}}let t=[e];for(;this.match(T.TokenType.COMMA)&&(this.consume(),!this.match(T.TokenType.RBRACKET));)t.push(this.parseExpression());return this.expect(T.TokenType.RBRACKET),{type:T.ASTNodeType.LIST_LITERAL,elements:t}}if(this.match(T.TokenType.LBRACE)){if(this.consume(),this.match(T.TokenType.RBRACE))return this.consume(),{type:T.ASTNodeType.DICT_LITERAL,entries:[]};let e=this.parseExpression();if(this.match(T.TokenType.COLON)){this.consume();let s=this.parseExpression();if(this.match(T.TokenType.KEYWORD,"for")){let r=this.parseComprehension({type:"KeyValue",key:e,value:s});return this.expect(T.TokenType.RBRACE),{type:T.ASTNodeType.DICT_COMP,key:e,value:s,comprehension:r}}let n=[{key:e,value:s}];for(;this.match(T.TokenType.COMMA)&&(this.consume(),!this.match(T.TokenType.RBRACE));){let r=this.parseExpression();this.expect(T.TokenType.COLON);let i=this.parseExpression();n.push({key:r,value:i})}return this.expect(T.TokenType.RBRACE),{type:T.ASTNodeType.DICT_LITERAL,entries:n}}if(this.match(T.TokenType.KEYWORD,"for")){let s=this.parseComprehension(e);return this.expect(T.TokenType.RBRACE),{type:T.ASTNodeType.SET_COMP,expression:e,comprehension:s}}let t=[e];for(;this.match(T.TokenType.COMMA)&&(this.consume(),!this.match(T.TokenType.RBRACE));)t.push(this.parseExpression());return this.expect(T.TokenType.RBRACE),{type:T.ASTNodeType.SET_LITERAL,elements:t}}if(this.match(T.TokenType.IDENTIFIER)){let e=this.consume().value;return{type:T.ASTNodeType.IDENTIFIER,name:e}}return this.parseLiteral()}function Ps(){let e=this.parseAtom();for(;this.match(T.TokenType.LPAREN)||this.match(T.TokenType.LBRACKET)||this.match(T.TokenType.DOT)&&this.peek(1)?.type===T.TokenType.IDENTIFIER;)if(this.match(T.TokenType.LPAREN)){this.consume();let t=this.parseArguments();this.expect(T.TokenType.RPAREN),e={type:T.ASTNodeType.CALL,callee:e,args:t}}else if(this.match(T.TokenType.LBRACKET)){this.consume();let t=this.parseSlice();this.expect(T.TokenType.RBRACKET),e={type:T.ASTNodeType.SUBSCRIPT,object:e,index:t}}else if(this.match(T.TokenType.DOT)){this.consume();let t=this.expect(T.TokenType.IDENTIFIER).value;e={type:T.ASTNodeType.ATTRIBUTE,object:e,name:t}}return e}function xs(){if(this.match(T.TokenType.OPERATOR,"+")||this.match(T.TokenType.OPERATOR,"-")||this.match(T.TokenType.OPERATOR,"~")){let e=this.consume().value,t=this.parseUnary();return{type:T.ASTNodeType.UNARY_OPERATION,operator:e,operand:t}}if(this.match(T.TokenType.KEYWORD)&&this.peek()?.value==="not"){this.consume();let e=this.parseUnary();return{type:T.ASTNodeType.UNARY_OPERATION,operator:"not",operand:e}}return this.parsePostfix()}function Ls(){let e=this.parseUnary();if(this.match(T.TokenType.OPERATOR,"**")){this.consume();let t=this.parsePower();e={type:T.ASTNodeType.BINARY_OPERATION,operator:"**",left:e,right:t}}return e}function Cs(){let e=this.parsePower();for(;this.match(T.TokenType.OPERATOR,"*")||this.match(T.TokenType.OPERATOR,"/")||this.match(T.TokenType.OPERATOR,"//")||this.match(T.TokenType.OPERATOR,"%");){let t=this.consume().value,s=this.parsePower();e={type:T.ASTNodeType.BINARY_OPERATION,operator:t,left:e,right:s}}return e}function Bs(){let e=this.parseFactor();for(;this.match(T.TokenType.OPERATOR,"+")||this.match(T.TokenType.OPERATOR,"-");){let t=this.consume().value,s=this.parseFactor();e={type:T.ASTNodeType.BINARY_OPERATION,operator:t,left:e,right:s}}return e}function ws(){let e=this.parseTerm();for(;this.match(T.TokenType.OPERATOR,"<<")||this.match(T.TokenType.OPERATOR,">>");){let t=this.consume().value,s=this.parseTerm();e={type:T.ASTNodeType.BINARY_OPERATION,operator:t,left:e,right:s}}return e}function vs(){let e=this.parseShift();for(;this.match(T.TokenType.OPERATOR,"&");){this.consume();let t=this.parseShift();e={type:T.ASTNodeType.BINARY_OPERATION,operator:"&",left:e,right:t}}return e}function Ms(){let e=this.parseBitAnd();for(;this.match(T.TokenType.OPERATOR,"^");){this.consume();let t=this.parseBitAnd();e={type:T.ASTNodeType.BINARY_OPERATION,operator:"^",left:e,right:t}}return e}function Ds(){let e=this.parseBitXor();for(;this.match(T.TokenType.OPERATOR,"|");){this.consume();let t=this.parseBitXor();e={type:T.ASTNodeType.BINARY_OPERATION,operator:"|",left:e,right:t}}return e}function Fs(){let e=this.parseBitOr(),t=[],s=[];for(;;){if(this.match(T.TokenType.KEYWORD,"not")&&this.peek(1)?.type===T.TokenType.KEYWORD&&this.peek(1)?.value==="in"){this.consume(),this.consume(),t.push("not in"),s.push(this.parseBitOr());continue}if(this.match(T.TokenType.KEYWORD,"is")&&this.peek(1)?.type===T.TokenType.KEYWORD&&this.peek(1)?.value==="not"){this.consume(),this.consume(),t.push("is not"),s.push(this.parseBitOr());continue}if(this.match(T.TokenType.OPERATOR,"==")||this.match(T.TokenType.OPERATOR,"!=")||this.match(T.TokenType.OPERATOR,"<")||this.match(T.TokenType.OPERATOR,">")||this.match(T.TokenType.OPERATOR,"<=")||this.match(T.TokenType.OPERATOR,">=")||this.match(T.TokenType.KEYWORD,"in")||this.match(T.TokenType.KEYWORD,"is")){t.push(this.consume().value),s.push(this.parseBitOr());continue}break}return t.length===0?e:{type:T.ASTNodeType.COMPARE,left:e,ops:t,comparators:s}}function Us(){if(this.match(T.TokenType.KEYWORD,"not")){this.consume();let e=this.parseNot();return{type:T.ASTNodeType.UNARY_OPERATION,operator:"not",operand:e}}return this.parseComparison()}function Ys(){let e=this.parseNot();for(;this.match(T.TokenType.KEYWORD,"and");){this.consume();let t=this.parseNot();e={type:T.ASTNodeType.BOOL_OPERATION,operator:"and",values:[e,t]}}return e}function Gs(){let e=this.parseAnd();for(;this.match(T.TokenType.KEYWORD,"or");){this.consume();let t=this.parseAnd();e={type:T.ASTNodeType.BOOL_OPERATION,operator:"or",values:[e,t]}}return e}function js(){let e=this.parseOr();if(this.match(T.TokenType.KEYWORD,"if")){this.consume();let t=this.parseOr();this.expect(T.TokenType.KEYWORD,"else");let s=this.parseIfExpression();return{type:T.ASTNodeType.IF_EXPRESSION,test:t,consequent:e,alternate:s}}return e}function Vs(){return this.parseIfExpression()}function Ws(){return this.parseOr()}function Ks(e){let t=[];for(;this.match(T.TokenType.KEYWORD,"for");){this.consume();let s=this.parseTarget();this.expect(T.TokenType.KEYWORD,"in");let n=this.parseExpressionNoIf(),r=[];for(;this.match(T.TokenType.KEYWORD,"if");)this.consume(),r.push(this.parseExpression());t.push({target:s,iter:n,ifs:r})}return{type:"Comprehension",clauses:t,expression:e}}});var wt=x(Ie=>{"use strict";Object.defineProperty(Ie,"__esModule",{value:!0});Ie.parsePostfixTarget=qs;Ie.parseTargetElement=$s;Ie.parseTarget=Hs;var v=W();function qs(){let e=this.parseAtom();for(;this.match(v.TokenType.LBRACKET)||this.match(v.TokenType.DOT)&&this.peek(1)?.type===v.TokenType.IDENTIFIER;)if(this.match(v.TokenType.LBRACKET)){this.consume();let t=this.parseSlice();this.expect(v.TokenType.RBRACKET),e={type:v.ASTNodeType.SUBSCRIPT,object:e,index:t}}else if(this.match(v.TokenType.DOT)){this.consume();let t=this.expect(v.TokenType.IDENTIFIER).value;e={type:v.ASTNodeType.ATTRIBUTE,object:e,name:t}}return e}function $s(){if(this.match(v.TokenType.OPERATOR,"*")){this.consume();let e=this.parseTargetElement();return{type:v.ASTNodeType.STARRED,target:e}}if(this.match(v.TokenType.IDENTIFIER))return this.parsePostfixTarget();if(this.match(v.TokenType.LPAREN)){this.consume();let e=this.parseTarget();return this.expect(v.TokenType.RPAREN),e}if(this.match(v.TokenType.LBRACKET)){this.consume();let e=[];if(!this.match(v.TokenType.RBRACKET))for(e.push(this.parseTarget());this.match(v.TokenType.COMMA)&&(this.consume(),!this.match(v.TokenType.RBRACKET));)e.push(this.parseTarget());return this.expect(v.TokenType.RBRACKET),{type:v.ASTNodeType.LIST_LITERAL,elements:e}}return this.parsePostfixTarget()}function Hs(){if(this.match(v.TokenType.OPERATOR,"*")){this.consume();let t=this.parseTargetElement();return{type:v.ASTNodeType.STARRED,target:t}}let e=this.parseTargetElement();if(this.match(v.TokenType.COMMA)){let t=[e];for(;this.match(v.TokenType.COMMA)&&(this.consume(),!(this.match(v.TokenType.NEWLINE)||this.match(v.TokenType.EOF)));)t.push(this.parseTargetElement());return{type:v.ASTNodeType.TUPLE_LITERAL,elements:t}}return e}});var vt=x(K=>{"use strict";Object.defineProperty(K,"__esModule",{value:!0});K.parseExpressionStatement=zs;K.parseExpressionList=Xs;K.parseAssignmentOrExpression=Js;K.parseBlock=Qs;K.parseIfStatement=Zs;K.parseWhileStatement=en;K.parseForStatement=tn;K.parseFunctionParameters=sn;K.parseFunctionDef=nn;K.parseClassDef=rn;K.parseDecorators=on;K.parseTryStatement=an;K.parseWithStatement=cn;K.parseMatchStatement=un;K.parseImportStatement=ln;K.parseStatement=pn;K.parseProgram=hn;var f=W();function zs(){return{type:f.ASTNodeType.EXPRESSION_STATEMENT,expression:this.parseExpression()}}function Xs(){let e=this.parseExpression();if(this.match(f.TokenType.COMMA)){let t=[e];for(;this.match(f.TokenType.COMMA)&&(this.consume(),!(this.match(f.TokenType.NEWLINE)||this.match(f.TokenType.RPAREN)||this.match(f.TokenType.RBRACKET)||this.match(f.TokenType.RBRACE)));)t.push(this.parseExpression());return{type:f.ASTNodeType.TUPLE_LITERAL,elements:t}}return e}function Js(){let e=this.pos,t=[];for(;;){let n=this.pos;try{let r=this.parseTarget();if(this.match(f.TokenType.ASSIGN)){this.consume(),t.push(r);continue}}catch{}this.pos=n;break}if(t.length>0){let n=this.parseExpressionList();return{type:f.ASTNodeType.ASSIGNMENT,targets:t,value:n}}this.pos=e;let s=null;try{s=this.parseTarget()}catch{}if(s&&this.match(f.TokenType.OPERATOR)&&["+=","-=","*=","/=","%=","//=","**="].includes(this.peek()?.value||"")){let n=this.consume().value,r=this.parseExpressionList();return{type:f.ASTNodeType.AUG_ASSIGNMENT,target:s,operator:n,value:r}}return this.pos=e,this.parseExpressionStatement()}function Qs(){this.expect(f.TokenType.NEWLINE),this.expect(f.TokenType.INDENT);let e=[];for(;!this.match(f.TokenType.DEDENT)&&!this.match(f.TokenType.EOF);){let t=this.parseStatement();e.push(t),this.skipNewlines()}return this.expect(f.TokenType.DEDENT),e}function Zs(){this.expect(f.TokenType.KEYWORD,"if");let e=this.parseExpression();this.expect(f.TokenType.COLON);let t=this.parseBlock(),s=[];for(;this.match(f.TokenType.KEYWORD,"elif");){this.consume();let r=this.parseExpression();this.expect(f.TokenType.COLON);let i=this.parseBlock();s.push({test:r,body:i})}let n=[];return this.match(f.TokenType.KEYWORD,"else")&&(this.consume(),this.expect(f.TokenType.COLON),n=this.parseBlock()),{type:f.ASTNodeType.IF_STATEMENT,test:e,body:t,elifs:s,orelse:n}}function en(){this.expect(f.TokenType.KEYWORD,"while");let e=this.parseExpression();this.expect(f.TokenType.COLON);let t=this.parseBlock();return{type:f.ASTNodeType.WHILE_STATEMENT,test:e,body:t}}function tn(){this.expect(f.TokenType.KEYWORD,"for");let e=this.parseTarget();this.expect(f.TokenType.KEYWORD,"in");let t=this.parseExpression();this.expect(f.TokenType.COLON);let s=this.parseBlock();return{type:f.ASTNodeType.FOR_STATEMENT,target:e,iter:t,body:s}}function sn(){let e=[];if(!this.match(f.TokenType.RPAREN))for(;;){if(this.match(f.TokenType.OPERATOR,"*")){this.consume();let t=this.expect(f.TokenType.IDENTIFIER).value;e.push({type:f.ASTNodeType.VAR_ARG,name:t})}else if(this.match(f.TokenType.OPERATOR,"**")){this.consume();let t=this.expect(f.TokenType.IDENTIFIER).value;e.push({type:f.ASTNodeType.KW_ARG,name:t})}else if(this.match(f.TokenType.IDENTIFIER)){let t=this.consume().value,s=null;this.match(f.TokenType.ASSIGN)&&(this.consume(),s=this.parseExpression()),e.push({type:f.ASTNodeType.PARAM,name:t,defaultValue:s})}if(!this.match(f.TokenType.COMMA)||(this.consume(),this.match(f.TokenType.RPAREN)))break}return e}function nn(e=[]){this.expect(f.TokenType.KEYWORD,"def");let t=this.expect(f.TokenType.IDENTIFIER).value;this.expect(f.TokenType.LPAREN);let s=this.parseFunctionParameters();this.expect(f.TokenType.RPAREN),this.expect(f.TokenType.COLON);let n=this.parseBlock();return{type:f.ASTNodeType.FUNCTION_DEF,name:t,params:s,body:n,decorators:e}}function rn(e=[]){this.expect(f.TokenType.KEYWORD,"class");let t=this.expect(f.TokenType.IDENTIFIER).value,s=[];if(this.match(f.TokenType.LPAREN)){if(this.consume(),!this.match(f.TokenType.RPAREN))for(s.push(this.parseExpression());this.match(f.TokenType.COMMA)&&(this.consume(),!this.match(f.TokenType.RPAREN));)s.push(this.parseExpression());this.expect(f.TokenType.RPAREN)}this.expect(f.TokenType.COLON);let n=this.parseBlock();return{type:f.ASTNodeType.CLASS_DEF,name:t,bases:s,body:n,decorators:e}}function on(){let e=[];for(;this.match(f.TokenType.AT);){this.consume();let t=this.parseExpression();e.push(t),this.expect(f.TokenType.NEWLINE)}return e}function an(){this.expect(f.TokenType.KEYWORD,"try"),this.expect(f.TokenType.COLON);let e=this.parseBlock(),t=[];for(;this.match(f.TokenType.KEYWORD,"except");){this.consume();let r=null,i=null;this.match(f.TokenType.COLON)||(r=this.parseExpression(),this.match(f.TokenType.KEYWORD,"as")&&(this.consume(),i=this.expect(f.TokenType.IDENTIFIER).value)),this.expect(f.TokenType.COLON);let c=this.parseBlock();t.push({exceptionType:r,name:i,body:c})}let s=[];this.match(f.TokenType.KEYWORD,"else")&&(this.consume(),this.expect(f.TokenType.COLON),s=this.parseBlock());let n=[];return this.match(f.TokenType.KEYWORD,"finally")&&(this.consume(),this.expect(f.TokenType.COLON),n=this.parseBlock()),{type:f.ASTNodeType.TRY_STATEMENT,body:e,handlers:t,orelse:s,finalbody:n}}function cn(){this.expect(f.TokenType.KEYWORD,"with");let e=[];for(;;){let s=this.parseExpression(),n=null;if(this.match(f.TokenType.KEYWORD,"as")&&(this.consume(),n=this.parseTarget()),e.push({context:s,target:n}),!this.match(f.TokenType.COMMA))break;this.consume()}this.expect(f.TokenType.COLON);let t=this.parseBlock();return{type:f.ASTNodeType.WITH_STATEMENT,items:e,body:t}}function un(){this.expect(f.TokenType.KEYWORD,"match");let e=this.parseExpression();this.expect(f.TokenType.COLON),this.expect(f.TokenType.NEWLINE),this.expect(f.TokenType.INDENT);let t=[];for(;!this.match(f.TokenType.DEDENT)&&!this.match(f.TokenType.EOF);){this.expect(f.TokenType.KEYWORD,"case");let s=this.parsePattern(),n=null;this.match(f.TokenType.KEYWORD,"if")&&(this.consume(),n=this.parseExpression()),this.expect(f.TokenType.COLON);let r=this.parseBlock();t.push({pattern:s,guard:n,body:r})}return this.expect(f.TokenType.DEDENT),{type:f.ASTNodeType.MATCH_STATEMENT,subject:e,cases:t}}function ln(){this.expect(f.TokenType.KEYWORD,"import");let e=[],t=()=>{let s=this.expect(f.TokenType.IDENTIFIER).value;for(;this.match(f.TokenType.DOT);)this.consume(),s+=`.${this.expect(f.TokenType.IDENTIFIER).value}`;let n=null;this.match(f.TokenType.KEYWORD,"as")&&(this.consume(),n=this.expect(f.TokenType.IDENTIFIER).value),e.push({name:s,alias:n})};for(t();this.match(f.TokenType.COMMA);)this.consume(),t();return{type:f.ASTNodeType.IMPORT_STATEMENT,names:e}}function pn(){if(this.skipNewlines(),this.match(f.TokenType.AT)){let e=this.parseDecorators(),t=!1;if(this.match(f.TokenType.KEYWORD,"async")&&(this.consume(),t=!0),!this.match(f.TokenType.KEYWORD,"def")&&!this.match(f.TokenType.KEYWORD,"class"))throw new Error("Decorators must be followed by def or class");let s;if(this.match(f.TokenType.KEYWORD,"def"))s=this.parseFunctionDef(e),t&&(s.isAsync=!0);else if(s=this.parseClassDef(e),t)throw new Error("async keyword cannot be used with class definitions");return s}if(this.match(f.TokenType.KEYWORD,"async")){if(this.consume(),!this.match(f.TokenType.KEYWORD,"def"))throw new Error("async must be followed by def");let e=this.parseFunctionDef();return e.isAsync=!0,e}if(this.match(f.TokenType.KEYWORD,"import"))return this.parseImportStatement();if(this.match(f.TokenType.KEYWORD,"def"))return this.parseFunctionDef();if(this.match(f.TokenType.KEYWORD,"class"))return this.parseClassDef();if(this.match(f.TokenType.KEYWORD,"if"))return this.parseIfStatement();if(this.match(f.TokenType.KEYWORD,"for"))return this.parseForStatement();if(this.match(f.TokenType.KEYWORD,"while"))return this.parseWhileStatement();if(this.match(f.TokenType.KEYWORD,"try"))return this.parseTryStatement();if(this.match(f.TokenType.KEYWORD,"with"))return this.parseWithStatement();if(this.match(f.TokenType.KEYWORD,"match"))return this.parseMatchStatement();if(this.match(f.TokenType.KEYWORD,"return")){this.consume();let e=this.match(f.TokenType.NEWLINE)?null:this.parseExpressionList();return{type:f.ASTNodeType.RETURN_STATEMENT,value:e}}if(this.match(f.TokenType.KEYWORD,"break"))return this.consume(),{type:f.ASTNodeType.BREAK_STATEMENT};if(this.match(f.TokenType.KEYWORD,"continue"))return this.consume(),{type:f.ASTNodeType.CONTINUE_STATEMENT};if(this.match(f.TokenType.KEYWORD,"pass"))return this.consume(),{type:f.ASTNodeType.PASS_STATEMENT};if(this.match(f.TokenType.KEYWORD,"assert")){this.consume();let e=this.parseExpression(),t=null;return this.match(f.TokenType.COMMA)&&(this.consume(),t=this.parseExpression()),{type:f.ASTNodeType.ASSERT_STATEMENT,test:e,message:t}}if(this.match(f.TokenType.KEYWORD,"raise")){this.consume();let e=this.match(f.TokenType.NEWLINE)?null:this.parseExpression();return{type:f.ASTNodeType.RAISE_STATEMENT,exception:e}}if(this.match(f.TokenType.KEYWORD,"global")){this.consume();let e=[];for(e.push(this.expect(f.TokenType.IDENTIFIER).value);this.match(f.TokenType.COMMA);)this.consume(),e.push(this.expect(f.TokenType.IDENTIFIER).value);return{type:f.ASTNodeType.GLOBAL_STATEMENT,names:e}}if(this.match(f.TokenType.KEYWORD,"nonlocal")){this.consume();let e=[];for(e.push(this.expect(f.TokenType.IDENTIFIER).value);this.match(f.TokenType.COMMA);)this.consume(),e.push(this.expect(f.TokenType.IDENTIFIER).value);return{type:f.ASTNodeType.NONLOCAL_STATEMENT,names:e}}if(this.match(f.TokenType.KEYWORD,"del")){this.consume();let e=this.parseExpression();return{type:f.ASTNodeType.DELETE_STATEMENT,target:e}}return this.parseAssignmentOrExpression()}function hn(){let e=[];for(this.skipNewlines();this.pos<this.tokens.length&&!this.match(f.TokenType.EOF);){let t=this.parseStatement();e.push(t),this.skipNewlines()}return this.expect(f.TokenType.EOF),{type:f.ASTNodeType.PROGRAM,body:e}}});var Mt=x(re=>{"use strict";var Tn=re&&re.__createBinding||(Object.create?(function(e,t,s,n){n===void 0&&(n=s);var r=Object.getOwnPropertyDescriptor(t,s);(!r||("get"in r?!t.__esModule:r.writable||r.configurable))&&(r={enumerable:!0,get:function(){return t[s]}}),Object.defineProperty(e,n,r)}):(function(e,t,s,n){n===void 0&&(n=s),e[n]=t[s]})),fn=re&&re.__setModuleDefault||(Object.create?(function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}):function(e,t){e.default=t}),Xe=re&&re.__importStar||(function(){var e=function(t){return e=Object.getOwnPropertyNames||function(s){var n=[];for(var r in s)Object.prototype.hasOwnProperty.call(s,r)&&(n[n.length]=r);return n},e(t)};return function(t){if(t&&t.__esModule)return t;var s={};if(t!=null)for(var n=e(t),r=0;r<n.length;r++)n[r]!=="default"&&Tn(s,t,n[r]);return fn(s,t),s}})();Object.defineProperty(re,"__esModule",{value:!0});re.Parser=void 0;var Be=W(),M=Xe(Bt()),He=Xe(wt()),$=Xe(vt()),ze=class{constructor(t){this.pos=0,this.parseStringLiteral=M.parseStringLiteral,this.parseLiteral=M.parseLiteral,this.parseIdentifier=M.parseIdentifier,this.parseArguments=M.parseArguments,this.parseSlice=M.parseSlice,this.parsePatternAtom=M.parsePatternAtom,this.parsePattern=M.parsePattern,this.parseLambdaParameters=M.parseLambdaParameters,this.parseLambda=M.parseLambda,this.parseAtom=M.parseAtom,this.parsePostfix=M.parsePostfix,this.parsePostfixTarget=He.parsePostfixTarget,this.parseTargetElement=He.parseTargetElement,this.parseTarget=He.parseTarget,this.parseUnary=M.parseUnary,this.parsePower=M.parsePower,this.parseFactor=M.parseFactor,this.parseTerm=M.parseTerm,this.parseShift=M.parseShift,this.parseBitAnd=M.parseBitAnd,this.parseBitXor=M.parseBitXor,this.parseBitOr=M.parseBitOr,this.parseComparison=M.parseComparison,this.parseNot=M.parseNot,this.parseAnd=M.parseAnd,this.parseOr=M.parseOr,this.parseIfExpression=M.parseIfExpression,this.parseExpression=M.parseExpression,this.parseExpressionNoIf=M.parseExpressionNoIf,this.parseComprehension=M.parseComprehension,this.parseExpressionStatement=$.parseExpressionStatement,this.parseExpressionList=$.parseExpressionList,this.parseAssignmentOrExpression=$.parseAssignmentOrExpression,this.parseBlock=$.parseBlock,this.parseIfStatement=$.parseIfStatement,this.parseWhileStatement=$.parseWhileStatement,this.parseForStatement=$.parseForStatement,this.parseFunctionParameters=$.parseFunctionParameters,this.parseFunctionDef=$.parseFunctionDef,this.parseClassDef=$.parseClassDef,this.parseDecorators=$.parseDecorators,this.parseTryStatement=$.parseTryStatement,this.parseWithStatement=$.parseWithStatement,this.parseMatchStatement=$.parseMatchStatement,this.parseImportStatement=$.parseImportStatement,this.parseStatement=$.parseStatement,this.parseProgram=$.parseProgram,this.tokens=t}peek(t=0){return this.pos+t<this.tokens.length?this.tokens[this.pos+t]:null}consume(){if(this.pos>=this.tokens.length)throw new Error("Unexpected end of input");return this.tokens[this.pos++]}match(t,s){let n=this.peek();return!!n&&n.type===t&&(s===void 0||n.value===s)}expect(t,s){let n=this.peek();if(!n)throw new Error(`Expected ${Be.TokenType[t]}${s?` "${s}"`:""}, but got end of input`);if(n.type!==t)throw new Error(`Expected ${Be.TokenType[t]}${s?` "${s}"`:""}, but got ${Be.TokenType[n.type]} "${n.value}" at line ${n.line}`);if(s!==void 0&&n.value!==s)throw new Error(`Expected "${s}", but got "${n.value}" at line ${n.line}`);return this.consume()}skipNewlines(){for(;this.match(Be.TokenType.NEWLINE);)this.consume()}parse(){return this.parseProgram()}};re.Parser=ze});var ve=x(we=>{"use strict";Object.defineProperty(we,"__esModule",{value:!0});we.Parser=void 0;var yn=Mt();Object.defineProperty(we,"Parser",{enumerable:!0,get:function(){return yn.Parser}})});var Qe=x(Me=>{"use strict";Object.defineProperty(Me,"__esModule",{value:!0});Me.Linearizer=void 0;var fe=W(),Je=class{linearize(t,s,n,r,i=0,c,o,p){let E=this.orderBlocks(t.entry),y=[],O=new Map,_=0;for(let a=0;a<E.length;a++){let h=E[a];if(O.set(h.id,_),!h){console.error("Linearizer: block is undefined at index",a);continue}if(!h.instructions){console.error("Linearizer: block.instructions is undefined for block",h.id);continue}_+=h.instructions.length,h.jumpTarget&&(_+=1);let m=!(a===E.length-1)&&E[a+1]===h.next;h.next&&!m&&(_+=1)}for(let a=0;a<E.length;a++){let h=E[a];for(let N of h.instructions){if(N.opcode===fe.OpCode.SETUP_FINALLY&&N.arg!==void 0){let I=O.get(N.arg);if(I!==void 0){y.push({...N,arg:I,offset:y.length});continue}}if(N.opcode===fe.OpCode.FOR_ITER&&N.arg!==void 0){let I=O.get(N.arg);if(I!==void 0){y.push({...N,arg:I,offset:y.length});continue}}y.push({...N,offset:y.length})}if(h.jumpTarget){let N;h.jumpCondition==="if_false"?N=fe.OpCode.POP_JUMP_IF_FALSE:h.jumpCondition==="if_true"?N=fe.OpCode.POP_JUMP_IF_TRUE:h.jumpCondition==="if_false_or_pop"?N=fe.OpCode.JUMP_IF_FALSE_OR_POP:h.jumpCondition==="if_true_or_pop"?N=fe.OpCode.JUMP_IF_TRUE_OR_POP:N=fe.OpCode.JUMP_ABSOLUTE;let I=O.get(h.jumpTarget.id);y.push({opcode:N,arg:I,offset:y.length})}let m=!(a===E.length-1)&&E[a+1]===h.next;if(h.next&&!m){let N=O.get(h.next.id);y.push({opcode:fe.OpCode.JUMP_ABSOLUTE,arg:N,offset:y.length})}}let l={instructions:y,constants:s,names:n,varnames:r,argcount:i};return c!==void 0&&(l.params=c),o!==void 0&&(l.globals=o),p!==void 0&&(l.nonlocals=p),l}orderBlocks(t){let s=[],n=new Set;function r(i){n.has(i)||(n.add(i),s.push(i),i.next&&r(i.next),i.jumpTarget&&r(i.jumpTarget),i.exceptionTarget&&r(i.exceptionTarget))}return r(t),s}};Me.Linearizer=Je});var Ze=x(De=>{"use strict";Object.defineProperty(De,"__esModule",{value:!0});De.parseStringToken=void 0;var dn=e=>{let t=e,s=!1;(t.startsWith("f")||t.startsWith("F"))&&(s=!0,t=t.slice(1));let n=t[0];return t.startsWith(n.repeat(3))?{value:t.slice(3,-3),isFString:s}:{value:t.slice(1,-1).replace(/\\n/g,`
10
+ `).replace(/\\t/g," ").replace(/\\"/g,'"').replace(/\\'/g,"'"),isFString:s}};De.parseStringToken=dn});var Dt=x(Fe=>{"use strict";Object.defineProperty(Fe,"__esModule",{value:!0});Fe.CFGBuilder=void 0;var u=W(),et=Qe(),En=Ze(),tt=class e{constructor(t=0,s=[]){this.blocks=[],this.blockIdCounter=0,this.constants=[],this.names=[],this.varnames=[],this.argcount=0,this.globalVars=new Set,this.nonlocalVars=new Set,this.loopStack=[],this.argcount=t,this.varnames=[...s],this.currentBlock=this.createBlock()}createBlock(){let t={id:this.blockIdCounter++,instructions:[]};return this.blocks.push(t),t}addInstruction(t,s){this.currentBlock.instructions.push(s!==void 0?{opcode:t,arg:s}:{opcode:t})}getConstantIndex(t){let s=this.constants.findIndex(n=>n===t);return s!==-1?s:(this.constants.push(t),this.constants.length-1)}getNameIndex(t){let s=this.names.indexOf(t);return s!==-1?s:(this.names.push(t),this.names.length-1)}getVarIndex(t){let s=this.varnames.indexOf(t);return s!==-1?s:(this.varnames.push(t),this.varnames.length-1)}build(t){let s=this.currentBlock;return this.visit(t),(this.currentBlock.instructions.length===0||this.currentBlock.instructions[this.currentBlock.instructions.length-1].opcode!==u.OpCode.RETURN_VALUE)&&(this.addInstruction(u.OpCode.LOAD_CONST,this.getConstantIndex(null)),this.addInstruction(u.OpCode.RETURN_VALUE)),{entry:s,blocks:this.blocks}}getConstants(){return this.constants}getNames(){return this.names}getVarnames(){return this.varnames}getArgcount(){return this.argcount}getGlobals(){return Array.from(this.globalVars)}getNonlocals(){return Array.from(this.nonlocalVars)}visit(t){if(t)switch(t.type){case u.ASTNodeType.PROGRAM:for(let s of t.body)this.visit(s);break;case u.ASTNodeType.EXPRESSION_STATEMENT:this.visit(t.expression),this.addInstruction(u.OpCode.POP_TOP);break;case u.ASTNodeType.ASSIGNMENT:this.visit(t.value);for(let s=0;s<t.targets.length;s++)s<t.targets.length-1&&this.addInstruction(u.OpCode.DUP_TOP),this.visitTarget(t.targets[s],"store");break;case u.ASTNodeType.AUG_ASSIGNMENT:if(t.target.type===u.ASTNodeType.SUBSCRIPT){let s=t.target;this.visit(s.object),this.visit(s.index),this.addInstruction(u.OpCode.DUP_TOP_TWO),this.addInstruction(u.OpCode.LOAD_SUBSCR),this.visit(t.value),this.addInplaceOperation(t.operator.slice(0,-1)),this.addInstruction(u.OpCode.ROT_THREE),this.addInstruction(u.OpCode.STORE_SUBSCR)}else if(t.target.type===u.ASTNodeType.ATTRIBUTE){let s=t.target;this.visit(s.object),this.addInstruction(u.OpCode.DUP_TOP),this.addInstruction(u.OpCode.LOAD_ATTR,this.getNameIndex(s.name)),this.visit(t.value),this.addInplaceOperation(t.operator.slice(0,-1)),this.addInstruction(u.OpCode.STORE_ATTR,this.getNameIndex(s.name))}else this.visit(t.target),this.visit(t.value),this.addInplaceOperation(t.operator.slice(0,-1)),this.visitTarget(t.target,"store");break;case u.ASTNodeType.NUMBER_LITERAL:{let s=t.value;if(typeof s=="string"){let r=s.replace(/_/g,""),i=r.toLowerCase();if(i.endsWith("j")){let o=i.slice(0,-1),E={__complex__:!0,re:0,im:o===""||o==="+"?1:o==="-"?-1:parseFloat(o)};this.addInstruction(u.OpCode.LOAD_CONST,this.getConstantIndex(E));break}if(/[.eE]/.test(r)){let o=new Number(parseFloat(r));this.addInstruction(u.OpCode.LOAD_CONST,this.getConstantIndex(o));break}let c=BigInt(r);this.addInstruction(u.OpCode.LOAD_CONST,this.getConstantIndex(c));break}let n=typeof s=="number"&&!Number.isInteger(s)?new Number(s):BigInt(s);this.addInstruction(u.OpCode.LOAD_CONST,this.getConstantIndex(n));break}case u.ASTNodeType.STRING_LITERAL:{let{value:s,isFString:n}=(0,En.parseStringToken)(t.value),r=n?{__fstring__:s}:s;this.addInstruction(u.OpCode.LOAD_CONST,this.getConstantIndex(r));break}case u.ASTNodeType.BOOLEAN_LITERAL:case u.ASTNodeType.NONE_LITERAL:this.addInstruction(u.OpCode.LOAD_CONST,this.getConstantIndex(t.value));break;case u.ASTNodeType.IDENTIFIER:this.globalVars.has(t.name)?this.addInstruction(u.OpCode.LOAD_GLOBAL,this.getNameIndex(t.name)):this.nonlocalVars.has(t.name)?this.addInstruction(u.OpCode.LOAD_NAME,this.getNameIndex(t.name)):this.varnames.includes(t.name)?this.addInstruction(u.OpCode.LOAD_FAST,this.getVarIndex(t.name)):this.addInstruction(u.OpCode.LOAD_NAME,this.getNameIndex(t.name));break;case u.ASTNodeType.COMPREHENSION:break;case u.ASTNodeType.BINARY_OPERATION:this.visit(t.left),this.visit(t.right),this.addBinaryOperation(t.operator);break;case u.ASTNodeType.UNARY_OPERATION:this.visit(t.operand),this.addUnaryOperation(t.operator);break;case u.ASTNodeType.BOOL_OPERATION:this.visitBoolOp(t);break;case u.ASTNodeType.IF_EXPRESSION:this.visitIfExpression(t);break;case u.ASTNodeType.COMPARE:{let s=t.ops||[];if(s.length===0)this.visit(t.left);else if(s.length===1)this.visit(t.left),this.visit(t.comparators[0]),this.addCompareOperation(s[0]);else{let n=this.createBlock(),r=this.createBlock();this.visit(t.left);for(let i=0;i<s.length;i++)if(this.visit(t.comparators[i]),i<s.length-1&&(this.addInstruction(u.OpCode.DUP_TOP),this.addInstruction(u.OpCode.ROT_THREE)),this.addCompareOperation(s[i]),i<s.length-1){let c=this.createBlock();this.currentBlock.jumpCondition="if_false_or_pop",this.currentBlock.jumpTarget=r,this.currentBlock.next=c,this.currentBlock=c}this.currentBlock.next=n,this.currentBlock=r,this.addInstruction(u.OpCode.ROT_TWO),this.addInstruction(u.OpCode.POP_TOP),this.currentBlock.next=n,this.currentBlock=n}break}case u.ASTNodeType.CALL:this.visit(t.callee);{let s=t.args,n=s.some(i=>i&&i.type===u.ASTNodeType.STAR_ARG),r=s.some(i=>i&&i.type===u.ASTNodeType.KW_ARG);if(n||r){let i=s.find(o=>o&&o.type===u.ASTNodeType.STAR_ARG);i&&"value"in i?this.visit(i.value):this.addInstruction(u.OpCode.BUILD_TUPLE,0);let c=s.find(o=>o&&o.type===u.ASTNodeType.KW_ARG);c&&"value"in c?(this.visit(c.value),this.addInstruction(u.OpCode.CALL_FUNCTION_EX,1)):this.addInstruction(u.OpCode.CALL_FUNCTION_EX,0)}else{let i=[],c=[];for(let o of s)o&&o.type===u.ASTNodeType.KEYWORD_ARG?c.push(o):i.push(o);for(let o of i)this.visit(o);for(let o of c)this.visit(o.value);if(c.length>0){for(let o of c)this.addInstruction(u.OpCode.LOAD_CONST,this.getConstantIndex(o.name));this.addInstruction(u.OpCode.BUILD_TUPLE,c.length),this.addInstruction(u.OpCode.CALL_FUNCTION_KW,i.length+c.length)}else this.addInstruction(u.OpCode.CALL_FUNCTION,i.length)}}break;case u.ASTNodeType.IF_STATEMENT:this.visitIf(t);break;case u.ASTNodeType.WHILE_STATEMENT:this.visitWhile(t);break;case u.ASTNodeType.FOR_STATEMENT:this.visitFor(t);break;case u.ASTNodeType.FUNCTION_DEF:this.visitFunctionDef(t);break;case u.ASTNodeType.CLASS_DEF:{let s=new e(0,[]),n=s.build({type:u.ASTNodeType.PROGRAM,body:t.body}),i=new et.Linearizer().linearize(n,s.getConstants(),s.getNames(),s.getVarnames(),0,[],s.getGlobals(),s.getNonlocals());i.name=`< classbody ${t.name}> `,this.addInstruction(u.OpCode.LOAD_BUILD_CLASS),this.addInstruction(u.OpCode.LOAD_CONST,this.getConstantIndex(i)),this.addInstruction(u.OpCode.LOAD_CONST,this.getConstantIndex(i.name)),this.addInstruction(u.OpCode.MAKE_FUNCTION,0),this.addInstruction(u.OpCode.LOAD_CONST,this.getConstantIndex(t.name));for(let c of t.bases)this.visit(c);this.addInstruction(u.OpCode.CALL_FUNCTION,2+t.bases.length),this.addInstruction(u.OpCode.STORE_NAME,this.getNameIndex(t.name));break}case u.ASTNodeType.LAMBDA:this.visitLambda(t);break;case u.ASTNodeType.RETURN_STATEMENT:t.value?this.visit(t.value):this.addInstruction(u.OpCode.LOAD_CONST,this.getConstantIndex(null)),this.addInstruction(u.OpCode.RETURN_VALUE);break;case u.ASTNodeType.YIELD:t.value?this.visit(t.value):this.addInstruction(u.OpCode.LOAD_CONST,this.getConstantIndex(null)),this.addInstruction(u.OpCode.YIELD_VALUE);break;case u.ASTNodeType.ATTRIBUTE:this.visit(t.object),this.addInstruction(u.OpCode.LOAD_ATTR,this.getNameIndex(t.name));break;case u.ASTNodeType.SUBSCRIPT:this.visit(t.object),this.visit(t.index),this.addInstruction(u.OpCode.LOAD_SUBSCR);break;case u.ASTNodeType.LIST_LITERAL:for(let s of t.elements)this.visit(s);this.addInstruction(u.OpCode.BUILD_LIST,t.elements.length);break;case u.ASTNodeType.LIST_COMP:case u.ASTNodeType.DICT_COMP:case u.ASTNodeType.SET_COMP:case u.ASTNodeType.GENERATOR_EXPR:this.addInstruction(u.OpCode.LOAD_CONST,this.getConstantIndex(t)),this.addInstruction(u.OpCode.EVAL_AST);break;case u.ASTNodeType.TUPLE_LITERAL:for(let s of t.elements)this.visit(s);this.addInstruction(u.OpCode.BUILD_TUPLE,t.elements.length);break;case u.ASTNodeType.DICT_LITERAL:{let s=t.entries||[];for(let n of s)this.visit(n.key),this.visit(n.value);this.addInstruction(u.OpCode.BUILD_MAP,s.length);break}case u.ASTNodeType.SET_LITERAL:for(let s of t.elements)this.visit(s);this.addInstruction(u.OpCode.BUILD_SET,t.elements.length);break;case u.ASTNodeType.SLICE:t.start!==null&&t.start!==void 0?this.visit(t.start):this.addInstruction(u.OpCode.LOAD_CONST,this.getConstantIndex(null)),t.end!==null&&t.end!==void 0?this.visit(t.end):this.addInstruction(u.OpCode.LOAD_CONST,this.getConstantIndex(null)),t.step!==null&&t.step!==void 0?(this.visit(t.step),this.addInstruction(u.OpCode.BUILD_SLICE,3)):this.addInstruction(u.OpCode.BUILD_SLICE,2);break;case u.ASTNodeType.ASSERT_STATEMENT:{this.visit(t.test);let s=this.createBlock();this.currentBlock.jumpCondition="if_true",this.currentBlock.jumpTarget=s;let n=this.createBlock();this.currentBlock.next=n,this.currentBlock=n,this.addInstruction(u.OpCode.LOAD_NAME,this.getNameIndex("AssertionError")),t.message?(this.visit(t.message),this.addInstruction(u.OpCode.CALL_FUNCTION,1)):this.addInstruction(u.OpCode.CALL_FUNCTION,0),this.addInstruction(u.OpCode.RAISE_VARARGS,1),this.currentBlock=s;break}case u.ASTNodeType.RAISE_STATEMENT:{t.exception?(this.visit(t.exception),this.addInstruction(u.OpCode.RAISE_VARARGS,1)):this.addInstruction(u.OpCode.RAISE_VARARGS,0);break}case u.ASTNodeType.PASS_STATEMENT:break;case u.ASTNodeType.BREAK_STATEMENT:{if(this.loopStack.length===0)throw new Error("SyntaxError: break outside loop");let s=this.loopStack[this.loopStack.length-1];s.loopType==="for"&&this.addInstruction(u.OpCode.POP_TOP),this.currentBlock.next=s.breakTarget;let n=this.createBlock();n.reachable=!1,this.currentBlock=n;break}case u.ASTNodeType.CONTINUE_STATEMENT:{if(this.loopStack.length===0)throw new Error("SyntaxError: continue not properly in loop");let s=this.loopStack[this.loopStack.length-1];this.currentBlock.next=s.continueTarget;let n=this.createBlock();n.reachable=!1,this.currentBlock=n;break}case u.ASTNodeType.GLOBAL_STATEMENT:for(let s of t.names||[])this.globalVars.add(s);break;case u.ASTNodeType.NONLOCAL_STATEMENT:for(let s of t.names||[])this.nonlocalVars.add(s);break;case u.ASTNodeType.DELETE_STATEMENT:{let s=t.targets||(t.target?[t.target]:[]);for(let n of s)this.visitTarget(n,"delete");break}case u.ASTNodeType.IMPORT_STATEMENT:for(let s of t.names)this.addInstruction(u.OpCode.LOAD_CONST,this.getConstantIndex(0)),this.addInstruction(u.OpCode.LOAD_CONST,this.getConstantIndex(null)),this.addInstruction(u.OpCode.IMPORT_NAME,this.getNameIndex(s.name)),this.addInstruction(u.OpCode.STORE_NAME,this.getNameIndex(s.asname||s.name));break;case u.ASTNodeType.TRY_STATEMENT:this.visitTry(t);break;case u.ASTNodeType.WITH_STATEMENT:this.visitWith(t);break;case u.ASTNodeType.MATCH_STATEMENT:this.visitMatch(t);break;default:console.warn(`CFGBuilder: Unhandled node type ${t.type}`)}}addBinaryOperation(t){switch(t){case"+":this.addInstruction(u.OpCode.BINARY_ADD);break;case"-":this.addInstruction(u.OpCode.BINARY_SUBTRACT);break;case"*":this.addInstruction(u.OpCode.BINARY_MULTIPLY);break;case"/":this.addInstruction(u.OpCode.BINARY_DIVIDE);break;case"//":this.addInstruction(u.OpCode.BINARY_FLOOR_DIVIDE);break;case"%":this.addInstruction(u.OpCode.BINARY_MODULO);break;case"**":this.addInstruction(u.OpCode.BINARY_POWER);break;case"<<":this.addInstruction(u.OpCode.BINARY_LSHIFT);break;case">>":this.addInstruction(u.OpCode.BINARY_RSHIFT);break;case"&":this.addInstruction(u.OpCode.BINARY_AND);break;case"^":this.addInstruction(u.OpCode.BINARY_XOR);break;case"|":this.addInstruction(u.OpCode.BINARY_OR);break;default:throw new Error(`Unknown operator: ${t} `)}}addInplaceOperation(t){switch(t){case"+":this.addInstruction(u.OpCode.INPLACE_ADD);break;case"-":this.addInstruction(u.OpCode.INPLACE_SUBTRACT);break;case"*":this.addInstruction(u.OpCode.INPLACE_MULTIPLY);break;case"/":this.addInstruction(u.OpCode.INPLACE_DIVIDE);break;case"//":this.addInstruction(u.OpCode.INPLACE_FLOOR_DIVIDE);break;case"%":this.addInstruction(u.OpCode.INPLACE_MODULO);break;case"**":this.addInstruction(u.OpCode.INPLACE_POWER);break;case"<<":this.addInstruction(u.OpCode.INPLACE_LSHIFT);break;case">>":this.addInstruction(u.OpCode.INPLACE_RSHIFT);break;case"&":this.addInstruction(u.OpCode.INPLACE_AND);break;case"^":this.addInstruction(u.OpCode.INPLACE_XOR);break;case"|":this.addInstruction(u.OpCode.INPLACE_OR);break;default:throw new Error(`Unknown operator: ${t} `)}}addCompareOperation(t){let s;switch(t){case"<":s=u.CompareOp.LT;break;case"<=":s=u.CompareOp.LE;break;case"==":s=u.CompareOp.EQ;break;case"!=":s=u.CompareOp.NE;break;case">":s=u.CompareOp.GT;break;case">=":s=u.CompareOp.GE;break;case"in":s=u.CompareOp.IN;break;case"not in":s=u.CompareOp.NOT_IN;break;case"is":s=u.CompareOp.IS;break;case"is not":s=u.CompareOp.IS_NOT;break;default:throw new Error(`Unknown compare operator: ${t} `)}this.addInstruction(u.OpCode.COMPARE_OP,s)}visitTarget(t,s){if(s==="store")switch(t.type){case u.ASTNodeType.IDENTIFIER:this.globalVars.has(t.name)?this.addInstruction(u.OpCode.STORE_GLOBAL,this.getNameIndex(t.name)):this.nonlocalVars.has(t.name)?this.addInstruction(u.OpCode.STORE_NAME,this.getNameIndex(t.name)):this.varnames.includes(t.name)?this.addInstruction(u.OpCode.STORE_FAST,this.getVarIndex(t.name)):this.addInstruction(u.OpCode.STORE_NAME,this.getNameIndex(t.name));break;case u.ASTNodeType.STARRED:this.visitTarget(t.target,s);break;case u.ASTNodeType.ATTRIBUTE:this.visit(t.object),this.addInstruction(u.OpCode.ROT_TWO),this.addInstruction(u.OpCode.STORE_ATTR,this.getNameIndex(t.name));break;case u.ASTNodeType.SUBSCRIPT:this.visit(t.object),this.visit(t.index),this.addInstruction(u.OpCode.STORE_SUBSCR);break;case u.ASTNodeType.TUPLE_LITERAL:case u.ASTNodeType.LIST_LITERAL:{let n=t.elements||[],r=n.findIndex(i=>i&&i.type===u.ASTNodeType.STARRED);if(r===-1)this.addInstruction(u.OpCode.UNPACK_SEQUENCE,n.length);else{let i=r,c=n.length-r-1;this.addInstruction(u.OpCode.UNPACK_EX,i<<8|c)}for(let i of n)this.visitTarget(i,s);break}default:throw new Error(`Unsupported assignment target: ${t.type} `)}else if(s==="delete")switch(t.type){case u.ASTNodeType.IDENTIFIER:this.globalVars.has(t.name)?this.addInstruction(u.OpCode.DELETE_GLOBAL,this.getNameIndex(t.name)):this.nonlocalVars.has(t.name)?this.addInstruction(u.OpCode.DELETE_NAME,this.getNameIndex(t.name)):this.varnames.includes(t.name)?this.addInstruction(u.OpCode.DELETE_FAST,this.getVarIndex(t.name)):this.addInstruction(u.OpCode.DELETE_NAME,this.getNameIndex(t.name));break;case u.ASTNodeType.ATTRIBUTE:this.visit(t.object),this.addInstruction(u.OpCode.DELETE_ATTR,this.getNameIndex(t.name));break;case u.ASTNodeType.SUBSCRIPT:this.visit(t.object),this.visit(t.index),this.addInstruction(u.OpCode.DELETE_SUBSCR);break;case u.ASTNodeType.TUPLE_LITERAL:case u.ASTNodeType.LIST_LITERAL:for(let n of t.elements||[])this.visitTarget(n,s);break;default:throw new Error(`Unsupported delete target: ${t.type} `)}}visitIf(t){let s=this.createBlock(),n=t.orelse||[];if(t.elifs&&t.elifs.length>0){let c=t.orelse||[];for(let o=t.elifs.length-1;o>=0;o--){let p=t.elifs[o];c=[{type:u.ASTNodeType.IF_STATEMENT,test:p.test,body:p.body,orelse:c,elifs:[]}]}n=c}let r=n&&n.length>0?this.createBlock():null,i=this.createBlock();this.visit(t.test),this.currentBlock.jumpCondition="if_false",this.currentBlock.jumpTarget=r||i,this.currentBlock.next=s,this.currentBlock=s;for(let c of t.body)this.visit(c);if(!this.currentBlock.next&&!this.currentBlock.jumpTarget&&(this.currentBlock.next=i),r){this.currentBlock=r;for(let c of n)this.visit(c);!this.currentBlock.next&&!this.currentBlock.jumpTarget&&(this.currentBlock.next=i)}this.currentBlock=i}visitWhile(t){let s=this.createBlock(),n=this.createBlock(),r=this.createBlock();this.currentBlock.next=s,this.currentBlock=s,this.visit(t.test),this.currentBlock.jumpCondition="if_false",this.currentBlock.jumpTarget=r,this.currentBlock.next=n,this.currentBlock=n,this.loopStack.push({breakTarget:r,continueTarget:s,loopType:"while"});for(let i of t.body)this.visit(i);this.loopStack.pop(),this.currentBlock.reachable!==!1&&!this.currentBlock.next&&!this.currentBlock.jumpTarget?(process.env.DEBUG_CFG&&console.log(`WHILE: Adding jump - back from block ${this.currentBlock.id} to loop block ${s.id} `),this.currentBlock.next=s):process.env.DEBUG_CFG&&console.log(`WHILE: NOT adding jump - back from block ${this.currentBlock.id}: reachable = ${this.currentBlock.reachable}, hasNext = ${!!this.currentBlock.next}, hasJumpTarget = ${!!this.currentBlock.jumpTarget} `),this.currentBlock=r}visitFor(t){this.visit(t.iter),this.addInstruction(u.OpCode.GET_ITER);let s=this.createBlock(),n=this.createBlock(),r=this.createBlock();this.currentBlock.next=s,this.currentBlock=s,this.addInstruction(u.OpCode.FOR_ITER,r.id),this.currentBlock.exceptionTarget=r,this.currentBlock.next=n,this.currentBlock=n,this.loopStack.push({breakTarget:r,continueTarget:s,loopType:"for"}),this.visitTarget(t.target,"store");for(let i of t.body)this.visit(i);this.loopStack.pop(),this.currentBlock.reachable!==!1&&!this.currentBlock.next&&!this.currentBlock.jumpTarget?(process.env.DEBUG_CFG&&console.log(`FOR: Adding jump - back from block ${this.currentBlock.id} to loop block ${s.id} `),this.currentBlock.next=s):process.env.DEBUG_CFG&&console.log(`FOR: NOT adding jump - back from block ${this.currentBlock.id}: reachable = ${this.currentBlock.reachable}, hasNext = ${!!this.currentBlock.next}, hasJumpTarget = ${!!this.currentBlock.jumpTarget} `),this.currentBlock=r}visitFunctionDef(t){let s=this.containsYield(t.body||[]),n=t.params.map(_=>_.type===u.ASTNodeType.PARAM||_.type===u.ASTNodeType.VAR_ARG?_.name:_.type===u.ASTNodeType.KW_ARG&&_.name||""),r=this.findAssignedVariables(t.body||[]),i=[...n,...r],c=0;for(let _ of t.params)_.type===u.ASTNodeType.PARAM&&_.defaultValue&&(this.visit(_.defaultValue),c++);let o=t.decorators||[];for(let _ of o)this.visit(_);let p=new e(t.params.length,i),E=p.build({type:u.ASTNodeType.PROGRAM,body:t.body}),O=new et.Linearizer().linearize(E,p.getConstants(),p.getNames(),p.getVarnames(),p.getArgcount(),t.params,p.getGlobals(),p.getNonlocals());O.name=t.name,O.isGenerator=s,s&&(O.astBody=t.body||[]),this.addInstruction(u.OpCode.LOAD_CONST,this.getConstantIndex(O)),this.addInstruction(u.OpCode.LOAD_CONST,this.getConstantIndex(t.name)),this.addInstruction(u.OpCode.MAKE_FUNCTION,c);for(let _=0;_<o.length;_++)this.addInstruction(u.OpCode.CALL_FUNCTION,1);this.addInstruction(u.OpCode.STORE_NAME,this.getNameIndex(t.name))}containsYield(t){let s=n=>{if(!n)return!1;if(Array.isArray(n))return n.some(s);if(n.type===u.ASTNodeType.YIELD)return!0;for(let r of Object.values(n))if(r&&typeof r=="object"&&s(r))return!0;return!1};return s(t)}findAssignedVariables(t){let s=new Set,n=new Set,r=new Set,i=c=>{if(c){if(Array.isArray(c)){c.forEach(i);return}switch(c.type){case u.ASTNodeType.GLOBAL_STATEMENT:c.names&&c.names.forEach(o=>n.add(o));break;case u.ASTNodeType.NONLOCAL_STATEMENT:c.names&&c.names.forEach(o=>r.add(o));break;case u.ASTNodeType.ASSIGNMENT:c.targets&&c.targets.forEach(o=>this.extractAssignedNames(o,s));break;case u.ASTNodeType.AUG_ASSIGNMENT:c.target&&this.extractAssignedNames(c.target,s);break;case u.ASTNodeType.FOR_STATEMENT:c.target&&(Array.isArray(c.target)?c.target.forEach(o=>this.extractAssignedNames(o,s)):this.extractAssignedNames(c.target,s)),c.body&&i(c.body),c.orelse&&i(c.orelse);break;case u.ASTNodeType.FUNCTION_DEF:case u.ASTNodeType.CLASS_DEF:break;default:for(let o of Object.values(c))o&&typeof o=="object"&&i(o)}}};return i(t),n.forEach(c=>s.delete(c)),r.forEach(c=>s.delete(c)),Array.from(s)}extractAssignedNames(t,s){t&&(t.type===u.ASTNodeType.IDENTIFIER?s.add(t.name):t.type===u.ASTNodeType.TUPLE_LITERAL||t.type===u.ASTNodeType.LIST_LITERAL?t.elements&&t.elements.forEach(n=>this.extractAssignedNames(n,s)):t.type===u.ASTNodeType.STARRED&&this.extractAssignedNames(t.target,s))}visitLambda(t){let n=(Array.isArray(t.params)?t.params:[]).map(y=>typeof y=="string"?y.startsWith("**")?{type:"KwArg",name:y.slice(2)}:y.startsWith("*")?{type:"VarArg",name:y.slice(1)}:{type:"Param",name:y,defaultValue:null}:y),r=n.map(y=>y.name),i=new e(n.length,r),c={type:u.ASTNodeType.RETURN_STATEMENT,value:t.body},o=i.build({type:u.ASTNodeType.PROGRAM,body:[c]}),E=new et.Linearizer().linearize(o,i.getConstants(),i.getNames(),i.getVarnames(),i.getArgcount(),n,i.getGlobals(),i.getNonlocals());E.name="<lambda>",this.addInstruction(u.OpCode.LOAD_CONST,this.getConstantIndex(E)),this.addInstruction(u.OpCode.LOAD_CONST,this.getConstantIndex("<lambda>")),this.addInstruction(u.OpCode.MAKE_FUNCTION,0)}addUnaryOperation(t){switch(t){case"+":this.addInstruction(u.OpCode.UNARY_POSITIVE);break;case"-":this.addInstruction(u.OpCode.UNARY_NEGATIVE);break;case"not":this.addInstruction(u.OpCode.UNARY_NOT);break;case"~":this.addInstruction(u.OpCode.UNARY_INVERT);break;default:throw new Error(`Unknown unary operator: ${t} `)}}visitBoolOp(t){let s=t.operator==="and",n=t.values||[];if(n.length===0){this.addInstruction(u.OpCode.LOAD_CONST,this.getConstantIndex(!0));return}this.visit(n[0]);for(let r=1;r<n.length;r++){let i=this.createBlock();s?(this.currentBlock.jumpCondition="if_false_or_pop",this.currentBlock.jumpTarget=i):(this.currentBlock.jumpCondition="if_true_or_pop",this.currentBlock.jumpTarget=i);let c=this.createBlock();this.currentBlock.next=c,this.currentBlock=c,this.visit(n[r]),this.currentBlock.next=i,this.currentBlock=i}}visitIfExpression(t){this.visit(t.test);let s=this.createBlock(),n=this.createBlock(),r=this.createBlock();this.currentBlock.jumpCondition="if_false",this.currentBlock.jumpTarget=n,this.currentBlock.next=s;let i=t.consequent,c=t.alternate;this.currentBlock=s,this.visit(i),this.currentBlock.next=r,this.currentBlock=n,this.visit(c),this.currentBlock.next=r,this.currentBlock=r}visitTry(t){let s=t.handlers||[],n=t.orelse||[],r=t.finalbody||[],i=s.length>0,c=n.length>0,o=r.length>0,p=this.createBlock(),E=this.createBlock(),y=i?this.createBlock():null,O=o?this.createBlock():null;o&&(this.currentBlock.exceptionTarget=O,this.addInstruction(u.OpCode.SETUP_FINALLY,O.id)),i&&(this.currentBlock.exceptionTarget=y,o&&(y.exceptionTarget=O),this.addInstruction(u.OpCode.SETUP_FINALLY,y.id)),this.currentBlock.next=p,this.currentBlock=p;for(let _ of t.body||[])this.visit(_);if(i&&this.addInstruction(u.OpCode.POP_BLOCK),c)for(let _ of n)this.visit(_);if(o?(this.addInstruction(u.OpCode.POP_BLOCK),this.addInstruction(u.OpCode.LOAD_CONST,this.getConstantIndex(null)),this.currentBlock.jumpCondition="always",this.currentBlock.jumpTarget=O,delete this.currentBlock.next):this.currentBlock.next=E,i){this.currentBlock=y;let _=this.createBlock(),l=y;for(let a=0;a<s.length;a++){let h=s[a],m=a===s.length-1?_:this.createBlock(),N=this.createBlock();this.currentBlock=l,h.exceptionType?(this.addInstruction(u.OpCode.DUP_TOP),this.addInstruction(u.OpCode.LOAD_NAME,this.getNameIndex("isinstance")),this.addInstruction(u.OpCode.ROT_TWO),this.visit(h.exceptionType),this.addInstruction(u.OpCode.CALL_FUNCTION,2),this.currentBlock.jumpCondition="if_false",this.currentBlock.jumpTarget=m,this.currentBlock.next=N):this.currentBlock.next=N,this.currentBlock=N,h.name?this.addInstruction(u.OpCode.STORE_NAME,this.getNameIndex(h.name)):this.addInstruction(u.OpCode.POP_TOP);for(let I of h.body||[])this.visit(I);if(o?(this.addInstruction(u.OpCode.POP_BLOCK),this.addInstruction(u.OpCode.LOAD_CONST,this.getConstantIndex(null)),this.currentBlock.jumpCondition="always",this.currentBlock.jumpTarget=O,delete this.currentBlock.next):this.currentBlock.next=E,l=m,!h.exceptionType){l=_;break}}this.currentBlock=_,this.addInstruction(u.OpCode.RAISE_VARARGS,1)}if(o){this.currentBlock=O;let _=this.createBlock(),l=this.createBlock();this.addInstruction(u.OpCode.DUP_TOP),this.addInstruction(u.OpCode.LOAD_CONST,this.getConstantIndex(null)),this.addInstruction(u.OpCode.COMPARE_OP,u.CompareOp.IS),this.currentBlock.jumpCondition="if_false",this.currentBlock.jumpTarget=_,this.currentBlock.next=l,this.currentBlock=l,this.addInstruction(u.OpCode.POP_TOP);for(let a of r)this.visit(a);this.currentBlock.next=E,this.currentBlock=_;for(let a of r)this.visit(a);this.addInstruction(u.OpCode.RAISE_VARARGS,1)}this.currentBlock=E}visitWith(t){let s=t.items||[],n=t.body||[];this.processWithItems(s,0,n)}processWithItems(t,s,n){if(s>=t.length){for(let y of n)this.visit(y);return}let r=t[s],i=r.context,c=r.target;this.visit(i);let o=this.createBlock(),p=this.createBlock();this.currentBlock.exceptionTarget=o,this.addInstruction(u.OpCode.SETUP_WITH,o.id),this.currentBlock.next=p,this.currentBlock=p,c?this.visitTarget(c,"store"):this.addInstruction(u.OpCode.POP_TOP),this.processWithItems(t,s+1,n),this.addInstruction(u.OpCode.POP_BLOCK),this.addInstruction(u.OpCode.LOAD_CONST,this.getConstantIndex(null)),this.addInstruction(u.OpCode.DUP_TOP),this.addInstruction(u.OpCode.DUP_TOP),this.addInstruction(u.OpCode.CALL_FUNCTION,3),this.addInstruction(u.OpCode.POP_TOP);let E=this.createBlock();this.currentBlock.next=E,this.currentBlock=o,this.addInstruction(u.OpCode.WITH_EXCEPT_START),this.currentBlock.next=E,this.currentBlock=E}visitMatch(t){let s=t.subject;this.visit(s);let n=this.createBlock();for(let r of t.cases){let i=r.pattern,c=r.body,o=r.guard,p=this.createBlock(),E=this.createBlock();if(this.addInstruction(u.OpCode.DUP_TOP),this.compilePattern(i,p,E),this.currentBlock=E,o){let y=this.createBlock();this.visit(o),this.currentBlock.jumpCondition="if_false",this.currentBlock.jumpTarget=y;let O=this.createBlock();this.currentBlock.next=O,this.currentBlock=O,this.addInstruction(u.OpCode.POP_TOP);for(let _ of c)this.visit(_);this.currentBlock.next=n,this.currentBlock=y,this.currentBlock.next=p}else{this.addInstruction(u.OpCode.POP_TOP);for(let y of c)this.visit(y);this.currentBlock.next=n}this.currentBlock=p}this.addInstruction(u.OpCode.POP_TOP),this.currentBlock.next=n,this.currentBlock=n}compilePattern(t,s,n){switch(t.type){case u.ASTNodeType.MATCH_PATTERN_VALUE:{this.visit(t.value),this.addInstruction(u.OpCode.COMPARE_OP,u.CompareOp.EQ),this.currentBlock.jumpCondition="if_false",this.currentBlock.jumpTarget=s,this.currentBlock.next=n;break}case u.ASTNodeType.MATCH_PATTERN_OR:{for(let r=0;r<t.patterns.length;r++){let i=r===t.patterns.length-1,c=i?s:this.createBlock();i||this.addInstruction(u.OpCode.DUP_TOP),this.compilePattern(t.patterns[r],c,n),i||(this.currentBlock=c)}break}case u.ASTNodeType.MATCH_PATTERN_SEQUENCE:{this.addInstruction(u.OpCode.DUP_TOP),this.addInstruction(u.OpCode.LOAD_NAME,this.getNameIndex("isinstance")),this.addInstruction(u.OpCode.ROT_TWO),this.addInstruction(u.OpCode.LOAD_NAME,this.getNameIndex("list")),this.addInstruction(u.OpCode.CALL_FUNCTION,2);let r=this.createBlock(),i=this.createBlock();this.currentBlock.jumpCondition="if_false",this.currentBlock.jumpTarget=r,this.currentBlock.next=i,this.currentBlock=r,this.addInstruction(u.OpCode.POP_TOP),this.currentBlock.next=s,this.currentBlock=i,this.addInstruction(u.OpCode.DUP_TOP),this.addInstruction(u.OpCode.LOAD_NAME,this.getNameIndex("len")),this.addInstruction(u.OpCode.ROT_TWO),this.addInstruction(u.OpCode.CALL_FUNCTION,1),this.addInstruction(u.OpCode.LOAD_CONST,this.getConstantIndex(t.elements.length)),this.addInstruction(u.OpCode.COMPARE_OP,u.CompareOp.EQ);let c=this.createBlock(),o=this.createBlock();this.currentBlock.jumpCondition="if_false",this.currentBlock.jumpTarget=c,this.currentBlock.next=o,this.currentBlock=c,this.addInstruction(u.OpCode.POP_TOP),this.currentBlock.next=s,this.currentBlock=o,this.addInstruction(u.OpCode.UNPACK_SEQUENCE,t.elements.length);for(let p=0;p<t.elements.length;p++){let E=t.elements[p];E.type===u.ASTNodeType.MATCH_PATTERN_CAPTURE&&E.name?this.addInstruction(u.OpCode.STORE_NAME,this.getNameIndex(E.name)):this.addInstruction(u.OpCode.POP_TOP)}this.currentBlock.next=n;break}case u.ASTNodeType.MATCH_PATTERN_CAPTURE:t.name?this.addInstruction(u.OpCode.STORE_NAME,this.getNameIndex(t.name)):this.addInstruction(u.OpCode.POP_TOP),this.currentBlock.next=n;break;case u.ASTNodeType.MATCH_PATTERN_WILDCARD:this.addInstruction(u.OpCode.POP_TOP),this.currentBlock.next=n;break;default:this.addInstruction(u.OpCode.POP_TOP),this.currentBlock.next=n}}};Fe.CFGBuilder=tt});var Ut=x(Ue=>{"use strict";Object.defineProperty(Ue,"__esModule",{value:!0});Ue.Compiler=void 0;var Ft=W(),_n=Dt(),An=Qe(),st=class{compile(t){if(t.type!==Ft.ASTNodeType.PROGRAM)throw new Error(`Expected Program node, got ${t.type}`);let s=new _n.CFGBuilder,n=s.build(t),i=new An.Linearizer().linearize(n,s.getConstants(),s.getNames(),s.getVarnames(),0,[],s.getGlobals(),s.getNonlocals());return process.env.DEBUG_BYTECODE&&(console.log("Generated bytecode instructions:",i.instructions.map(c=>`${Ft.OpCode[c.opcode]} ${c.arg??""}`)),console.log("Generated names:",i.names)),i}};Ue.Compiler=st});var Yt=x(Ye=>{"use strict";Object.defineProperty(Ye,"__esModule",{value:!0});Ye.Compiler=void 0;var Nn=Ut();Object.defineProperty(Ye,"Compiler",{enumerable:!0,get:function(){return Nn.Compiler}})});var X=x(L=>{"use strict";var mn=L&&L.__createBinding||(Object.create?(function(e,t,s,n){n===void 0&&(n=s);var r=Object.getOwnPropertyDescriptor(t,s);(!r||("get"in r?!t.__esModule:r.writable||r.configurable))&&(r={enumerable:!0,get:function(){return t[s]}}),Object.defineProperty(e,n,r)}):(function(e,t,s,n){n===void 0&&(n=s),e[n]=t[s]})),kn=L&&L.__setModuleDefault||(Object.create?(function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}):function(e,t){e.default=t}),Sn=L&&L.__importStar||(function(){var e=function(t){return e=Object.getOwnPropertyNames||function(s){var n=[];for(var r in s)Object.prototype.hasOwnProperty.call(s,r)&&(n[n.length]=r);return n},e(t)};return function(t){if(t&&t.__esModule)return t;var s={};if(t!=null)for(var n=e(t),r=0;r<n.length;r++)n[r]!=="default"&&mn(s,t,n[r]);return kn(s,t),s}})();Object.defineProperty(L,"__esModule",{value:!0});L.PyFile=L.PySet=L.PyDict=L.PyGenerator=L.PyInstance=L.PyClass=L.PyFunction=L.Scope=L.Frame=L.PyException=L.ContinueSignal=L.BreakSignal=L.ReturnSignal=void 0;var me=Sn(require("fs")),nt=class{constructor(t){this.value=t}};L.ReturnSignal=nt;var rt=class{};L.BreakSignal=rt;var it=class{};L.ContinueSignal=it;var ie=class extends Error{constructor(t,s,n){super(s||t),this.pyType=t,this.pyValue=n}};L.PyException=ie;var ot=class{constructor(t,s){this.stack=[],this.pc=0,this.locals=[],this.blockStack=[],this.bytecode=t,this.scope=s,this.locals=new Array((t.varnames||[]).length).fill(void 0)}};L.Frame=ot;var at=class{constructor(t=null,s=!1){this.values=new Map,this.globals=new Set,this.nonlocals=new Set,this.locals=new Set,this.isClassScope=!1,this.parent=t,this.isClassScope=s}get(t){if(this.values.has(t))return this.values.get(t);if(this.locals.has(t))throw new ie("UnboundLocalError",`local variable '${t}' referenced before assignment`);if(this.nonlocals.has(t)&&this.parent){let n=this.findScopeWith(t,!0);if(n)return n.values.get(t)}let s=this.parent;for(;s&&s.isClassScope;)s=s.parent;if(s)return s.get(t);throw new ie("NameError",`name '${t}' is not defined`)}set(t,s){if(this.globals.has(t)&&this.parent){this.root().values.set(t,s);return}if(this.nonlocals.has(t)&&this.parent){let n=this.findScopeWith(t,!0);if(!n)throw new ie("NameError",`no binding for nonlocal '${t}' found`);process.env.DEBUG_NONLOCAL&&(console.log(`Setting nonlocal ${t} = ${s}`),console.log("Found scope:",n.values.has(t),n.values.get(t))),n.values.set(t,s);return}this.values.set(t,s)}root(){let t=this;for(;t.parent;)t=t.parent;return t}findScopeWith(t,s=!1){let n=s?this.parent:this;for(;n;){if(n.isClassScope){n=n.parent;continue}if(n.values.has(t)||n.locals.has(t))return n;n=n.parent}return null}};L.Scope=at;var ct=class{constructor(t,s,n,r,i,c=new Set,o){this.name=t,this.params=s,this.body=n,this.closure=r,this.isGenerator=i,this.localNames=c,o!==void 0&&(this.bytecode=o)}};L.PyFunction=ct;var Ge=class{constructor(t,s,n,r=!1){this.name=t,this.bases=s,this.attributes=n,this.isException=r}};L.PyClass=Ge;var je=class{constructor(t){this.klass=t,this.attributes=new Map}};L.PyInstance=je;var ut=class{constructor(t){this.iterator=t}next(t){let s=this.iterator.next(t===void 0?null:t);if(s.done)throw new ie("StopIteration","StopIteration");return s.value}send(t){let s=this.iterator.next(t===void 0?null:t);if(s.done)throw new ie("StopIteration","StopIteration");return s.value}throw(t){let s=this.iterator;if(t instanceof Ge&&t.isException&&(t=new je(t)),typeof s.throw!="function")throw new ie("TypeError","object is not an iterator");let n=s.throw(t);if(n.done)throw new ie("StopIteration","StopIteration");return n.value}close(){let t=this.iterator;return typeof t.return=="function"&&t.return(null),null}[Symbol.iterator](){return this.iterator}};L.PyGenerator=ut;var lt=class{constructor(){this.primitiveStore=new Map,this.objectStore=new Map}get size(){return this.primitiveStore.size+this.objectStore.size}set(t,s){let n=this.keyInfo(t),r=n.store.get(n.id);return r?(r.value=s,this):(n.store.set(n.id,{key:t,value:s}),this)}get(t){let s=this.keyInfo(t),n=s.store.get(s.id);return n?n.value:void 0}has(t){let s=this.keyInfo(t);return s.store.has(s.id)}delete(t){let s=this.keyInfo(t);return s.store.delete(s.id)}*entries(){for(let t of this.primitiveStore.values())yield[t.key,t.value];for(let t of this.objectStore.values())yield[t.key,t.value]}*keys(){for(let t of this.primitiveStore.values())yield t.key;for(let t of this.objectStore.values())yield t.key}*values(){for(let t of this.primitiveStore.values())yield t.value;for(let t of this.objectStore.values())yield t.value}[Symbol.iterator](){return this.keys()}keyInfo(t){let s=this.normalizeNumericKey(t);return s!==null?typeof s=="number"&&Number.isNaN(s)?{store:this.objectStore,id:t}:{store:this.primitiveStore,id:`n:${s.toString()}`}:typeof t=="string"?{store:this.primitiveStore,id:`s:${t}`}:t===null?{store:this.primitiveStore,id:"none"}:t===void 0?{store:this.primitiveStore,id:"undefined"}:{store:this.objectStore,id:t}}normalizeNumericKey(t){if(typeof t=="boolean")return t?1n:0n;if(typeof t=="bigint")return t;if(typeof t=="number"||t instanceof Number){let s=t.valueOf();return Number.isFinite(s)&&Number.isInteger(s)?BigInt(s):s}return null}};L.PyDict=lt;var pt=class{constructor(t){if(this.primitiveStore=new Map,this.objectStore=new Map,t)for(let s of t)this.add(s)}get size(){return this.primitiveStore.size+this.objectStore.size}add(t){let s=this.valueInfo(t);return s.store.has(s.id)||s.store.set(s.id,t),this}has(t){let s=this.valueInfo(t);return s.store.has(s.id)}delete(t){let s=this.valueInfo(t);return s.store.delete(s.id)}clear(){this.primitiveStore.clear(),this.objectStore.clear()}*values(){for(let t of this.primitiveStore.values())yield t;for(let t of this.objectStore.values())yield t}[Symbol.iterator](){return this.values()}valueInfo(t){let s=this.normalizeNumeric(t);return s!==null?typeof s=="number"&&Number.isNaN(s)?{store:this.objectStore,id:t}:{store:this.primitiveStore,id:`n:${s.toString()}`}:typeof t=="string"?{store:this.primitiveStore,id:`s:${t}`}:t===null?{store:this.primitiveStore,id:"none"}:t===void 0?{store:this.primitiveStore,id:"undefined"}:{store:this.objectStore,id:t}}normalizeNumeric(t){if(typeof t=="boolean")return t?1n:0n;if(typeof t=="bigint")return t;if(typeof t=="number"||t instanceof Number){let s=t.valueOf();return Number.isFinite(s)&&Number.isInteger(s)?BigInt(s):s}return null}};L.PySet=pt;var ht=class{constructor(t,s){this.path=t,this.mode=s,this.handle=null}open(){this.handle===null&&(this.mode.includes("w")?this.handle=me.openSync(this.path,"w"):this.mode.includes("r")?this.handle=me.openSync(this.path,"r"):this.handle=me.openSync(this.path,"r"))}write(t){this.open(),this.handle!==null&&me.writeSync(this.handle,t)}read(){return this.mode.includes("r")?me.readFileSync(this.path,"utf8"):""}close(){this.handle!==null&&(me.closeSync(this.handle),this.handle=null)}__enter__(){return this.open(),this}__exit__(){return this.close(),!1}};L.PyFile=ht});var Ee=x(S=>{"use strict";Object.defineProperty(S,"__esModule",{value:!0});S.pythonModulo=S.toComplex=S.isComplex=S.pyStr=S.pyRepr=S.pyTypeName=S.bigIntFloorDiv=S.numericCompare=S.numericEquals=S.shouldUseBigInt=S.toBigIntValue=S.toNumber=S.isNumericLike=S.isIntLike=S.isFloatLike=S.isFloatObject=S.isIntObject=S.isBigInt=S.isPyNone=S.parseStringToken=void 0;S.findLocalVariables=Wn;var z=X(),In=Ze();Object.defineProperty(S,"parseStringToken",{enumerable:!0,get:function(){return In.parseStringToken}});var On=e=>e===null;S.isPyNone=On;var bn=e=>typeof e=="bigint";S.isBigInt=bn;var Rn=e=>e instanceof Number&&e.__int__===!0;S.isIntObject=Rn;var gn=e=>e instanceof Number&&!(0,S.isIntObject)(e);S.isFloatObject=gn;var Pn=e=>(0,S.isFloatObject)(e)||typeof e=="number"&&!Number.isInteger(e);S.isFloatLike=Pn;var xn=e=>(0,S.isBigInt)(e)||e===!0||e===!1||typeof e=="number"&&Number.isInteger(e)||(0,S.isIntObject)(e);S.isIntLike=xn;var Ln=e=>(0,S.isBigInt)(e)||typeof e=="number"||e instanceof Number||typeof e=="boolean";S.isNumericLike=Ln;var Cn=e=>e instanceof Number?e.valueOf():typeof e=="boolean"?e?1:0:typeof e=="bigint"?Number(e):e;S.toNumber=Cn;var Bn=e=>typeof e=="bigint"?e:e instanceof Number?BigInt(Math.trunc(e.valueOf())):BigInt(e);S.toBigIntValue=Bn;var wn=(e,t)=>((0,S.isBigInt)(e)||(0,S.isBigInt)(t))&&!(0,S.isFloatLike)(e)&&!(0,S.isFloatLike)(t);S.shouldUseBigInt=wn;var vn=(e,t)=>{if((0,S.isNumericLike)(e)&&(0,S.isNumericLike)(t)){let s=e instanceof Number?e.valueOf():e,n=t instanceof Number?t.valueOf():t;return s==n}return e===t};S.numericEquals=vn;var Mn=(e,t)=>{if(!(0,S.isNumericLike)(e)||!(0,S.isNumericLike)(t))return null;let s=e instanceof Number?e.valueOf():e,n=t instanceof Number?t.valueOf():t;return{left:s,right:n}};S.numericCompare=Mn;var Dn=(e,t)=>{let s=e/t;return e%t===0n?s:e<0n!=t<0n?s-1n:s};S.bigIntFloorDiv=Dn;var Fn=e=>e===null?"NoneType":(0,S.isBigInt)(e)||(0,S.isIntObject)(e)?"int":e instanceof Number?"float":typeof e=="boolean"?"bool":typeof e=="number"?Number.isInteger(e)?"int":"float":typeof e=="string"?"str":Array.isArray(e)?e.__tuple__?"tuple":"list":e instanceof z.PySet?"set":e instanceof z.PyDict?"dict":e instanceof z.PyFunction?"function":e instanceof z.PyClass?"type":e instanceof z.PyInstance?e.klass.name:typeof e;S.pyTypeName=Fn;var Un=(e,t=new Set)=>{if(e===null)return"None";if(e instanceof Number){let n=e.valueOf();return Number.isNaN(n)?"nan":n===1/0?"inf":n===-1/0?"-inf":(0,S.isIntObject)(e)?String(n):Object.is(n,-0)?"-0.0":Number.isInteger(n)?`${n}.0`:String(n)}if(typeof e=="boolean")return e?"True":"False";if(typeof e=="number")return Number.isNaN(e)?"nan":Object.is(e,-0)?"-0.0":String(e);if(typeof e=="bigint")return e.toString();if(e&&e.__complex__){let n=e.im>=0?"+":"-",r=Math.abs(e.im);return`(${e.re}${n}${r}j)`}if(typeof e=="string")return`'${e.replace(/'/g,"\\'")}'`;if(Array.isArray(e)||e instanceof z.PySet||e instanceof z.PyDict){if(t.has(e))return Array.isArray(e)?e.__tuple__?"(...)":"[...]":"{...}";t.add(e);try{if(Array.isArray(e)){let n=e.map(r=>(0,S.pyRepr)(r,t)).join(", ");return e.__tuple__?e.length===1?`(${n},)`:`(${n})`:`[${n}]`}if(e instanceof z.PySet)return`{${Array.from(e.values()).map(r=>(0,S.pyRepr)(r,t)).join(", ")}}`;if(e instanceof z.PyDict)return`{${Array.from(e.entries()).map(([r,i])=>`${(0,S.pyRepr)(r,t)}: ${(0,S.pyRepr)(i,t)}`).join(", ")}}`}finally{t.delete(e)}}return e instanceof z.PyFunction?`<function ${e.name}>`:e instanceof z.PyClass?`<class '${e.name}'>`:e instanceof z.PyInstance?`<${e.klass.name} object>`:String(e)};S.pyRepr=Un;var Yn=e=>{if(typeof e=="string")return e;if(e&&e.__complex__)return(0,S.pyRepr)(e);if(e&&e.__typeName__)return`<class '${e.__typeName__}'>`;if(e instanceof z.PyException)return e.message;if(e instanceof z.PyInstance&&e.klass.isException){let t=e.attributes.get("message");return t==null?"":String(t)}return(0,S.pyRepr)(e)};S.pyStr=Yn;var Gn=e=>e&&e.__complex__;S.isComplex=Gn;var jn=e=>(0,S.isComplex)(e)?e:(0,S.isNumericLike)(e)?{__complex__:!0,re:(0,S.toNumber)(e),im:0}:{__complex__:!0,re:0,im:0};S.toComplex=jn;var Vn=(e,t)=>{if((0,S.shouldUseBigInt)(e,t)){let c=(0,S.toBigIntValue)(e),o=(0,S.toBigIntValue)(t);if(o===0n)throw new z.PyException("ZeroDivisionError","division by zero");let E=c%o!==0n&&c<0n!=o<0n,y=c/o-(E?1n:0n);return c-y*o}let s=(0,S.toNumber)(e),n=(0,S.toNumber)(t);if(n===0)throw new z.PyException("ZeroDivisionError","division by zero");let r=Math.floor(s/n),i=s-r*n;return(0,S.isFloatObject)(e)||(0,S.isFloatObject)(t)?new Number(i):i};S.pythonModulo=Vn;var j=W();function Wn(e){let t=new Set,s=new Set,n=new Set;function r(o){if(o){if(Array.isArray(o)){for(let p of o)r(p);return}switch(o.type){case j.ASTNodeType.ASSIGNMENT:for(let p of o.targets)i(p);break;case j.ASTNodeType.AUG_ASSIGNMENT:i(o.target);break;case j.ASTNodeType.FOR_STATEMENT:i(o.target),r(o.body),r(o.orelse);break;case j.ASTNodeType.WITH_STATEMENT:for(let p of o.items)p.target&&i(p.target);r(o.body);break;case j.ASTNodeType.TRY_STATEMENT:r(o.body);for(let p of o.handlers)p.name&&t.add(p.name),r(p.body);r(o.orelse),r(o.finalbody);break;case j.ASTNodeType.FUNCTION_DEF:t.add(o.name);break;case j.ASTNodeType.CLASS_DEF:t.add(o.name);break;case j.ASTNodeType.IMPORT_STATEMENT:for(let p of o.names){let E=p.alias||p.name.split(".")[0];t.add(E)}break;case j.ASTNodeType.GLOBAL_STATEMENT:for(let p of o.names)s.add(p);break;case j.ASTNodeType.NONLOCAL_STATEMENT:for(let p of o.names)n.add(p);break;case j.ASTNodeType.IF_STATEMENT:r(o.body);for(let p of o.elifs)r(p.body);r(o.orelse);break;case j.ASTNodeType.WHILE_STATEMENT:r(o.body),r(o.orelse);break;case j.ASTNodeType.MATCH_STATEMENT:for(let p of o.cases)c(p.pattern),r(p.body);break;case j.ASTNodeType.DELETE_STATEMENT:break}}}function i(o){if(o.type===j.ASTNodeType.IDENTIFIER)t.add(o.name);else if(o.type===j.ASTNodeType.TUPLE_LITERAL||o.type===j.ASTNodeType.LIST_LITERAL)for(let p of o.elements)p.type===j.ASTNodeType.STARRED?i(p.target):i(p)}function c(o){if(o)switch(o.type){case j.ASTNodeType.MATCH_PATTERN_CAPTURE:t.add(o.name);break;case j.ASTNodeType.MATCH_PATTERN_OR:if(o.patterns)for(let p of o.patterns)c(p);break;case j.ASTNodeType.MATCH_PATTERN_SEQUENCE:{let p=o.elements||o.patterns;if(p)for(let E of p)c(E);break}case"MatchAs":o.name&&t.add(o.name),o.pattern&&c(o.pattern);break;case"MatchSequence":if(o.patterns)for(let p of o.patterns)c(p);break;case"MatchMapping":if(o.patterns)for(let p of o.patterns)c(p);if(o.keys)for(let{pattern:p}of o.keys)c(p);break;case"MatchClass":if(o.patterns)for(let p of o.patterns)c(p);break}}r(e);for(let o of s)t.delete(o);for(let o of n)t.delete(o);return t}});var Gt=x(Tt=>{"use strict";Object.defineProperty(Tt,"__esModule",{value:!0});Tt.installBuiltins=Kn;var G=X(),U=Ee();function Kn(e){let t=new Map;t.set("print",(...a)=>{let h=" ",d=`
11
+ `;if(a.length>0){let N=a[a.length-1];if(N&&N.__kwargs__){let I=N.__kwargs__;h=I.sep!==void 0?I.sep:h,d=I.end!==void 0?I.end:d,a=a.slice(0,-1)}}let m=a.map(N=>(0,U.pyStr)(N)).join(h)+d;return process.stdout.write(m),null}),t.set("len",a=>{if(typeof a=="string"||Array.isArray(a))return a.length;if(a instanceof G.PyDict||a instanceof G.PySet)return a.size;throw new G.PyException("TypeError","object has no len()")}),t.set("range",(...a)=>{let h=0,d=0,m=1;a.length===1?d=(0,U.toNumber)(a[0]):a.length===2?(h=(0,U.toNumber)(a[0]),d=(0,U.toNumber)(a[1])):a.length>=3&&(h=(0,U.toNumber)(a[0]),d=(0,U.toNumber)(a[1]),m=(0,U.toNumber)(a[2]));let N=[];if(m===0)throw new G.PyException("ValueError","range() arg 3 must not be zero");if(m>0)for(let I=h;I<d;I+=m)N.push(I);else for(let I=h;I>d;I+=m)N.push(I);return N});let s=a=>Array.isArray(a)?[...a]:a instanceof G.PySet?Array.from(a.values()):a&&typeof a[Symbol.iterator]=="function"?Array.from(a):[];s.__typeName__="list",t.set("list",s);let n=a=>{let h=Array.isArray(a)?[...a]:a&&typeof a[Symbol.iterator]=="function"?Array.from(a):[];return h.__tuple__=!0,h};n.__typeName__="tuple",t.set("tuple",n);let r=a=>a instanceof G.PySet?new G.PySet(a):Array.isArray(a)?new G.PySet(a):a&&typeof a[Symbol.iterator]=="function"?new G.PySet(Array.from(a)):new G.PySet;r.__typeName__="set",t.set("set",r),t.set("sum",a=>a.some(h=>typeof h=="bigint")?a.reduce((h,d)=>h+(0,U.toBigIntValue)(d),0n):a.reduce((h,d)=>h+d,0)),t.set("max",(...a)=>{let h=a.length===1&&Array.isArray(a[0])?a[0]:a;return h.every(d=>(0,U.isNumericLike)(d)&&!(0,U.isFloatLike)(d))?h.reduce((d,m)=>(0,U.toBigIntValue)(m)>(0,U.toBigIntValue)(d)?m:d):Math.max(...h.map(d=>(0,U.toNumber)(d)))}),t.set("min",(...a)=>{let h=a.length===1&&Array.isArray(a[0])?a[0]:a;return h.every(d=>(0,U.isNumericLike)(d)&&!(0,U.isFloatLike)(d))?h.reduce((d,m)=>(0,U.toBigIntValue)(m)<(0,U.toBigIntValue)(d)?m:d):Math.min(...h.map(d=>(0,U.toNumber)(d)))}),t.set("abs",a=>typeof a=="bigint"?a<0n?-a:a:Math.abs((0,U.toNumber)(a)));let i=a=>{let h=Math.floor(a),d=a-h,m=1e-12;return d>.5+m?h+1:d<.5-m||h%2===0?h:h+1};t.set("round",(a,h)=>{if(h===void 0)return i(a);let d=Math.pow(10,h);return i(a*d)/d});let c=a=>{if(typeof a=="bigint")return a;let h=typeof a=="string"?a.trim():null;if(h&&/^[-+]?\\d+$/.test(h)){let N=BigInt(h),I=BigInt(Number.MAX_SAFE_INTEGER),P=BigInt(Number.MIN_SAFE_INTEGER);if(N>I||N<P)return N}let d=parseInt(a,10);if(Number.isNaN(d))throw new G.PyException("ValueError","Invalid integer");let m=new Number(d);return m.__int__=!0,m};c.__typeName__="int",t.set("int",c);let o=a=>{if(a===void 0)return new Number(0);if(a instanceof Number)return new Number(a.valueOf());if(typeof a=="number")return new Number(a);if(typeof a=="boolean")return new Number(a?1:0);if(typeof a=="string"){let d=a.trim();if(d.length===0)throw new G.PyException("ValueError","Invalid float");let m=d.toLowerCase();if(m==="nan"||m==="+nan"||m==="-nan")return new Number(NaN);if(m==="inf"||m==="+inf"||m==="infinity"||m==="+infinity")return new Number(1/0);if(m==="-inf"||m==="-infinity")return new Number(-1/0);let N=parseFloat(d);if(Number.isNaN(N))throw new G.PyException("ValueError","Invalid float");return new Number(N)}let h=parseFloat(a);if(Number.isNaN(h))throw new G.PyException("ValueError","Invalid float");return new Number(h)};o.__typeName__="float",t.set("float",o);let p=a=>(0,U.pyStr)(a);p.__typeName__="str",t.set("str",p);let E=a=>this.isTruthy(a,e);E.__typeName__="bool",t.set("bool",E),t.set("type",a=>({__typeName__:(0,U.pyTypeName)(a)}));let y=(a,h)=>a===h?!0:a.bases.some(d=>y(d,h));t.set("isinstance",(a,h)=>h instanceof G.PyClass?a instanceof G.PyInstance?y(a.klass,h):!1:h&&h.__typeName__?(0,U.pyTypeName)(a)===h.__typeName__:!1),t.set("enumerate",a=>(Array.isArray(a)?a:Array.from(a)).map((d,m)=>{let N=[m,d];return N.__tuple__=!0,N})),t.set("zip",(...a)=>{let h=a.map(N=>Array.isArray(N)?N:Array.from(N)),d=Math.min(...h.map(N=>N.length)),m=[];for(let N=0;N<d;N++){let I=h.map(P=>P[N]);I.__tuple__=!0,m.push(I)}return m}),t.set("sorted",a=>{let h=Array.isArray(a)?[...a]:Array.from(a);return h.every(d=>(0,U.isNumericLike)(d))?h.sort((d,m)=>(0,U.toNumber)(d)-(0,U.toNumber)(m)):h.sort()}),t.set("reversed",a=>(Array.isArray(a)?[...a]:Array.from(a)).reverse()),t.set("map",(a,h)=>(Array.isArray(h)?h:Array.from(h)).map(m=>this.callFunction(a,[m],e))),t.set("filter",(a,h)=>(Array.isArray(h)?h:Array.from(h)).filter(m=>this.isTruthy(this.callFunction(a,[m],e),e))),t.set("next",a=>{if(a instanceof G.PyGenerator)return a.next();if(a&&typeof a.next=="function"){let h=a.next();if(h.done)throw new G.PyException("StopIteration","StopIteration");return h.value}throw new G.PyException("TypeError","object is not an iterator")}),t.set("open",(a,h="r")=>{let d=new G.PyFile(String(a),String(h));try{d.open()}catch{throw new G.PyException("FileNotFoundError","File not found")}return d});let O=(a,h)=>new G.PyClass(a,h?[h]:[],new Map,!0),_=O("Exception");t.set("Exception",_),t.set("AssertionError",O("AssertionError",_)),t.set("AttributeError",O("AttributeError",_));let l=O("NameError",_);t.set("NameError",l),t.set("UnboundLocalError",O("UnboundLocalError",l)),t.set("ZeroDivisionError",O("ZeroDivisionError",_)),t.set("ValueError",O("ValueError",_)),t.set("TypeError",O("TypeError",_)),t.set("FileNotFoundError",O("FileNotFoundError",_)),t.set("StopIteration",O("StopIteration",_)),e.values=new Map([...t.entries()])}});var Vt=x(_e=>{"use strict";Object.defineProperty(_e,"__esModule",{value:!0});_e.callFunction=qn;_e.containsYield=$n;_e.evaluateComprehension=Hn;_e.generateComprehension=zn;_e.expressionHasYield=Xn;var jt=W(),oe=X();function qn(e,t,s,n={}){if(n||(n={}),e instanceof oe.PyFunction){let r=new oe.Scope(e.closure);r.locals=new Set(e.localNames),e.bytecode&&(e.bytecode.globals&&e.bytecode.globals.forEach(i=>r.globals.add(i)),e.bytecode.nonlocals&&e.bytecode.nonlocals.forEach(i=>r.nonlocals.add(i)));for(let i of e.params)if(i.type==="Param"){let c;t.length>0?c=t.shift():i.name in n?(c=n[i.name],delete n[i.name]):i.defaultEvaluated!==void 0?c=i.defaultEvaluated:i.defaultValue?c=this.evaluateExpression(i.defaultValue,s):c=null,r.set(i.name,c)}else if(i.type==="VarArg"){let c=[...t];c.__tuple__=!0,r.set(i.name,c),t=[]}else if(i.type==="KwArg"){let c=new oe.PyDict;for(let[o,p]of Object.entries(n))c.set(o,p);r.set(i.name,c),n={}}try{if(e.isGenerator){let c=this.executeBlockGenerator(e.body,r);return new oe.PyGenerator(c)}if(e.bytecode&&e.bytecode.instructions){let c=new oe.Frame(e.bytecode,r);for(let o=0;o<(e.bytecode.argcount||0);o++){let p=e.bytecode.varnames[o];c.locals[o]=r.values.get(p)}return this.executeFrame(c)}return this.executeBlock(e.body,r)}catch(i){if(i instanceof oe.ReturnSignal)return i.value;throw i}}if(e instanceof oe.PyClass){let r=new oe.PyInstance(e);e.isException&&t.length>0&&r.attributes.set("message",t[0]);let i=this.findClassAttribute(e,"__init__");return i instanceof oe.PyFunction&&this.callFunction(i,[r,...t],s,n),r}if(typeof e=="function")return Object.keys(n).length>0?e(...t,{__kwargs__:n}):e(...t);throw new oe.PyException("TypeError","object is not callable")}function $n(e){for(let t of e)if(t.type===jt.ASTNodeType.YIELD||t.expression&&this.expressionHasYield(t.expression)||t.value&&this.expressionHasYield(t.value)||t.body&&Array.isArray(t.body)&&this.containsYield(t.body))return!0;return!1}function Hn(e,t,s,n){let r=e.clauses||[],i=c=>{if(c>=r.length){s();return}let o=r[c],p=c===0&&n?n:t,E=this.evaluateExpression(o.iter,p),y=Array.isArray(E)?E:Array.from(E);for(let O of y)this.assignTarget(o.target,O,t),o.ifs.every(l=>this.isTruthy(this.evaluateExpression(l,t),t))&&i(c+1)};i(0)}function*zn(e,t,s,n){let r=e.clauses||[],i=this,c=o=>(function*(){if(o>=r.length){yield s();return}let p=r[o],E=o===0&&n?n:t,y=i.evaluateExpression(p.iter,E),O=Array.isArray(y)?y:Array.from(y);for(let _ of O)i.assignTarget(p.target,_,t),p.ifs.every(a=>i.isTruthy(i.evaluateExpression(a,t),t))&&(yield*c(o+1))})();return yield*c(0),null}function Xn(e){if(!e)return!1;if(e.type===jt.ASTNodeType.YIELD)return!0;for(let t of Object.keys(e)){let s=e[t];if(Array.isArray(s)){if(s.some(n=>n&&typeof n=="object"&&this.expressionHasYield(n)))return!0}else if(s&&typeof s=="object"&&this.expressionHasYield(s))return!0}return!1}});var qt=x(ye=>{"use strict";Object.defineProperty(ye,"__esModule",{value:!0});ye.TailCallStats=ye.TailCall=void 0;ye.detectTailCall=Jn;ye.handleTailCallFrame=Qn;var Wt=X(),Kt=W(),ft=class{constructor(t,s,n){this.func=t,this.args=s,this.scope=n}};ye.TailCall=ft;function Jn(e,t){let s=e.instructions;return t>=s.length||s[t].opcode!==Kt.OpCode.CALL_FUNCTION?!1:t+1<s.length?s[t+1].opcode===Kt.OpCode.RETURN_VALUE:!0}function Qn(e,t,s){if(!(t instanceof Wt.PyFunction))return this.callFunction(t,s,e.scope);if(!t.bytecode||!t.bytecode.instructions)return this.callFunction(t,s,e.scope);e.stack.length=0,e.pc=0;let n=new Wt.Scope(t.closure);n.locals=new Set(t.localNames),t.bytecode.globals&&t.bytecode.globals.forEach(i=>n.globals.add(i)),t.bytecode.nonlocals&&t.bytecode.nonlocals.forEach(i=>n.nonlocals.add(i));for(let i of t.params)if(i.type==="Param"){let c;s.length>0?c=s.shift():i.defaultEvaluated!==void 0?c=i.defaultEvaluated:i.defaultValue?c=this.evaluateExpression(i.defaultValue,e.scope):c=null,n.set(i.name,c)}else if(i.type==="VarArg"){let c=[...s];c.__tuple__=!0,n.set(i.name,c),s=[]}e.scope=n,e.bytecode=t.bytecode,e.locals=new Array((t.bytecode.varnames||[]).length).fill(void 0),e.blockStack.length=0;let r=t.bytecode.varnames||[];for(let i=0;i<(t.bytecode.argcount||0);i++){let c=r[i];e.locals[i]=n.values.get(c)}return{__tailCall__:!0}}var yt=class{constructor(){this.totalCalls=0,this.tailCalls=0,this.recursiveTailCalls=0}recordCall(){this.totalCalls++}recordTailCall(){this.tailCalls++}recordRecursiveTailCall(){this.recursiveTailCalls++}getOptimizationRatio(){return this.totalCalls>0?this.tailCalls/this.totalCalls*100:0}};ye.TailCallStats=yt});var Ht=x(ee=>{"use strict";Object.defineProperty(ee,"__esModule",{value:!0});ee.applyCompare=Zn;ee.iterableToArray=er;ee.matchValueEquals=Ve;ee.applyBindings=tr;ee.matchPattern=sr;ee.evaluateExpression=nr;ee.executeStatement=rr;ee.executeBlockGenerator=ir;ee.executeStatementGenerator=or;ee.executeBlock=ar;var D=W(),V=X(),$t=Ee();function Zn(e,t,s){switch(e){case D.CompareOp.EQ:return(0,$t.numericEquals)(t,s);case D.CompareOp.NE:return!(0,$t.numericEquals)(t,s);case D.CompareOp.LT:return t<s;case D.CompareOp.LE:return t<=s;case D.CompareOp.GT:return t>s;case D.CompareOp.GE:return t>=s;case D.CompareOp.IS:return t===s;case D.CompareOp.IS_NOT:return t!==s;case D.CompareOp.IN:return this.contains(s,t);case D.CompareOp.NOT_IN:return!this.contains(s,t);default:return!1}}function er(e){if(e instanceof V.PyDict)return Array.from(e.keys());if(e instanceof V.PySet)return Array.from(e.values());if(Array.isArray(e))return e;if(e&&typeof e[Symbol.iterator]=="function")return Array.from(e);throw new Error("Object is not iterable")}function Ve(e,t){if(Array.isArray(e)&&Array.isArray(t)){if(e.length!==t.length)return!1;for(let s=0;s<e.length;s++)if(!Ve(e[s],t[s]))return!1;return!0}if(e instanceof Map&&t instanceof Map){if(e.size!==t.size)return!1;for(let[s,n]of e.entries())if(!t.has(s)||!Ve(n,t.get(s)))return!1;return!0}return e===t}function tr(e,t){for(let[s,n]of e.entries())t.set(s,n)}function sr(e,t,s){switch(e.type){case D.ASTNodeType.MATCH_PATTERN_WILDCARD:return{matched:!0,bindings:new Map};case D.ASTNodeType.MATCH_PATTERN_CAPTURE:{let n=new Map;return n.set(e.name,t),{matched:!0,bindings:n}}case D.ASTNodeType.MATCH_PATTERN_VALUE:{let n=this.evaluateExpression(e.value,s);return{matched:Ve(t,n),bindings:new Map}}case D.ASTNodeType.MATCH_PATTERN_SEQUENCE:{if(!Array.isArray(t))return{matched:!1,bindings:new Map};if(t.length!==e.elements.length)return{matched:!1,bindings:new Map};let n=new Map;for(let r=0;r<e.elements.length;r++){let i=this.matchPattern(e.elements[r],t[r],s);if(!i.matched)return{matched:!1,bindings:new Map};for(let[c,o]of i.bindings.entries())n.set(c,o)}return{matched:!0,bindings:n}}case D.ASTNodeType.MATCH_PATTERN_OR:{for(let n of e.patterns){let r=this.matchPattern(n,t,s);if(r.matched)return r}return{matched:!1,bindings:new Map}}default:throw new Error(`Unsupported match pattern: ${e.type}`)}}function nr(e,t){throw new Error("evaluateExpression is deprecated, use bytecode")}function rr(e,t){throw new Error("executeStatement is deprecated, use bytecode")}function*ir(e,t){for(let s of e)yield*this.executeStatementGenerator(s,t);return null}function*or(e,t){let s=(i,c)=>i===c?!0:i.bases.some(o=>s(o,c)),n=i=>{if(i instanceof V.PyInstance&&i.klass.isException)return i;if(i instanceof V.PyClass&&i.isException)return new V.PyInstance(i);if(i instanceof V.PyException)try{let c=t.get(i.pyType);if(c instanceof V.PyClass){let o=new V.PyInstance(c);return i.message&&o.attributes.set("message",i.message),o}}catch{}return i},r=(i,c)=>{if(!i)return!0;let o=n(c);return i instanceof V.PyInstance&&i.klass.isException&&(i=i.klass),i instanceof V.PyClass&&i.isException?o instanceof V.PyInstance&&o.klass.isException?s(o.klass,i):o instanceof V.PyClass&&o.isException?s(o,i):!1:!1};switch(e.type){case D.ASTNodeType.EXPRESSION_STATEMENT:{let i=e.expression;if(i&&i.type===D.ASTNodeType.YIELD){yield i.value?this.evaluateExpression(i.value,t):null;return}i&&this.evaluateExpression(i,t);return}case D.ASTNodeType.ASSIGNMENT:{if(e.value&&e.value.type===D.ASTNodeType.YIELD){let o=yield e.value.value?this.evaluateExpression(e.value.value,t):null,p=o===void 0?null:o;for(let E of e.targets||[])this.assignTarget(E,p,t);return}let i=this.evaluateExpression(e.value,t);for(let c of e.targets||[])this.assignTarget(c,i,t);return}case D.ASTNodeType.AUG_ASSIGNMENT:{let i=this.evaluateExpression(e.target,t),c=this.evaluateExpression(e.value,t),o=this.applyInPlaceBinary(e.operator.slice(0,-1),i,c);this.assignTarget(e.target,o,t);return}case D.ASTNodeType.IF_STATEMENT:{this.isTruthy(this.evaluateExpression(e.test,t),t)?yield*this.executeBlockGenerator(e.body||[],t):yield*this.executeBlockGenerator(e.orelse||[],t);return}case D.ASTNodeType.WHILE_STATEMENT:{let i=!1;for(;this.isTruthy(this.evaluateExpression(e.test,t),t);)try{yield*this.executeBlockGenerator(e.body||[],t)}catch(c){if(c instanceof V.ContinueSignal)continue;if(c instanceof V.BreakSignal){i=!0;break}throw c}!i&&e.orelse&&e.orelse.length&&(yield*this.executeBlockGenerator(e.orelse,t));return}case D.ASTNodeType.FOR_STATEMENT:{let i=this.evaluateExpression(e.iter,t);if(!i||typeof i[Symbol.iterator]!="function")throw new V.PyException("TypeError",`'${typeof i}' object is not iterable`);let c=i[Symbol.iterator](),o=!1;for(;;){let p=c.next();if(p.done)break;this.assignTarget(e.target,p.value,t);try{yield*this.executeBlockGenerator(e.body||[],t)}catch(E){if(E instanceof V.ContinueSignal)continue;if(E instanceof V.BreakSignal){o=!0;break}throw E}}!o&&e.orelse&&e.orelse.length&&(yield*this.executeBlockGenerator(e.orelse,t));return}case D.ASTNodeType.BREAK_STATEMENT:throw new V.BreakSignal;case D.ASTNodeType.CONTINUE_STATEMENT:throw new V.ContinueSignal;case D.ASTNodeType.RETURN_STATEMENT:throw new V.ReturnSignal(e.value?this.evaluateExpression(e.value,t):null);case D.ASTNodeType.TRY_STATEMENT:{let i=!1;try{yield*this.executeBlockGenerator(e.body||[],t)}catch(c){i=!0;let o=!1,p=n(c);for(let E of e.handlers||[]){if(!E.exceptionType)o=!0;else{let y=this.evaluateExpression(E.exceptionType,t);o=r(y,p)}if(o){E.name&&t.set(E.name,p),yield*this.executeBlockGenerator(E.body||[],t);break}}if(!o)throw c}finally{e.finalbody&&e.finalbody.length&&(yield*this.executeBlockGenerator(e.finalbody,t))}!i&&e.orelse&&e.orelse.length&&(yield*this.executeBlockGenerator(e.orelse,t));return}default:{this.executeStatement(e,t);return}}}function ar(e,t){let s=null;for(let n of e)s=this.executeStatement(n,t);return s}});var zt=x(Y=>{"use strict";Object.defineProperty(Y,"__esModule",{value:!0});Y.executeBlock=Y.executeStatementGenerator=Y.executeBlockGenerator=Y.executeStatement=Y.evaluateExpression=Y.matchPattern=Y.applyBindings=Y.matchValueEquals=Y.iterableToArray=Y.applyCompare=void 0;Y.execute=ur;Y.executeFrame=lr;var k=W(),C=X(),cr=qt();function ur(e){let t=new C.Scope;this.installBuiltins(t);let s=new C.Frame(e,t);return this.executeFrame(s)}function lr(e){for(;;){let t=e.bytecode.instructions,{constants:s,names:n,varnames:r}=e.bytecode;if(e.pc===0){if(e.bytecode.globals)for(let y of e.bytecode.globals)e.scope.globals.has(y)||e.scope.globals.add(y);if(e.bytecode.nonlocals)for(let y of e.bytecode.nonlocals)e.scope.nonlocals.has(y)||e.scope.nonlocals.add(y)}let c=null,o=(y,O)=>y.replace(/\{([^}]+)\}/g,(_,l)=>{let{rawExpr:a,rawSpec:h}=this.splitFormatSpec(l),d=new C.Scope(O);if(r)for(let N=0;N<r.length;N++){let I=r[N];if(I!==void 0)if(O.values.has(I)){let P=O.values.get(I);process.env.DEBUG_NONLOCAL&&console.log(`renderFString: varname=${I}, scope.values.get=${P}`),d.values.set(I,P)}else e.locals[N]!==void 0&&(process.env.DEBUG_NONLOCAL&&console.log(`renderFString: varname=${I}, frame.locals[${N}]=${e.locals[N]}`),d.values.set(I,e.locals[N]))}let m=this.evaluateExpressionString(a.trim(),d);return this.applyFormatSpec(m,h?h.trim():"")}),p=y=>{if(y instanceof C.PyException)try{let O=e.scope.get(y.pyType);if(O instanceof C.PyClass){let _=new C.PyInstance(O);return y.message&&_.attributes.set("message",y.message),_}}catch{}return y},E=y=>{if(e.blockStack.length===0)return!1;let O=e.blockStack.pop();return e.stack.length=O.stackHeight,e.stack.push(p(y)),e.pc=O.handler,!0};for(;e.pc<t.length;){let y=t[e.pc++];if(!y)break;let{opcode:O,arg:_}=y;try{switch(O){case k.OpCode.LOAD_CONST:{let l=s[_];l&&typeof l=="object"&&typeof l.__fstring__=="string"?e.stack.push(o(l.__fstring__,e.scope)):e.stack.push(l)}break;case k.OpCode.LOAD_NAME:{let l=n[_],a=e.scope.get(l);e.stack.push(a);break}case k.OpCode.STORE_NAME:e.scope.set(n[_],e.stack.pop());break;case k.OpCode.LOAD_GLOBAL:{let l=n[_],a=e.scope;for(;a.parent!==null;)a=a.parent;let h=a.get(l);e.stack.push(h);break}case k.OpCode.STORE_GLOBAL:{let l=n[_],a=e.scope;for(;a.parent!==null;)a=a.parent;a.set(l,e.stack.pop());break}case k.OpCode.LOAD_FAST:{let l=r[_];if(l!==void 0&&e.scope.values.has(l)){let h=e.scope.values.get(l);e.locals[_]=h,e.stack.push(h);break}let a=e.locals[_];if(a===void 0)throw new C.PyException("UnboundLocalError",`local variable '${l}' referenced before assignment`);e.stack.push(a);break}case k.OpCode.STORE_FAST:{let l=e.stack.pop();e.locals[_]=l,r&&r[_]!==void 0&&e.scope.values.set(r[_],l);break}case k.OpCode.UNPACK_SEQUENCE:{let l=e.stack.pop(),a=Array.isArray(l)?l:Array.from(l);if(a.length!==_)throw new C.PyException("ValueError",`not enough values to unpack (expected ${_}, got ${a.length})`);for(let h=a.length-1;h>=0;h--)e.stack.push(a[h]);break}case k.OpCode.UNPACK_EX:{let l=e.stack.pop(),a=Array.isArray(l)?l:Array.from(l),h=_>>8&255,d=_&255;if(a.length<h+d)throw new C.PyException("ValueError","not enough values to unpack");let m=a.slice(h,a.length-d);for(let N=d-1;N>=0;N--)e.stack.push(a[a.length-d+N]);e.stack.push(m);for(let N=h-1;N>=0;N--)e.stack.push(a[N]);break}case k.OpCode.LOAD_ATTR:{let l=e.stack.pop();e.stack.push(this.getAttribute(l,n[_],e.scope));break}case k.OpCode.STORE_ATTR:{let l=e.stack.pop(),a=e.stack.pop();this.setAttribute(a,n[_],l);break}case k.OpCode.LOAD_SUBSCR:{let l=e.stack.pop(),a=e.stack.pop();e.stack.push(this.getSubscript(a,l));break}case k.OpCode.STORE_SUBSCR:{let l=e.stack.pop(),a=e.stack.pop(),h=e.stack.pop();if(Array.isArray(a)&&a.__tuple__)throw new C.PyException("TypeError","'tuple' object does not support item assignment");if(Array.isArray(a))if(l&&(l.__slice__||l.type===k.ASTNodeType.SLICE)){let d=l.start!==void 0?l.start:null,m=l.end!==void 0?l.end:null,N=l.step!==void 0?l.step:1,I=this.computeSliceBounds(a.length,d,m,N),P=this.computeSliceIndices(a.length,d,m,N);if(I.step!==1){if(!Array.isArray(h)||h.length!==P.length)throw new C.PyException("ValueError",`attempt to assign sequence of size ${Array.isArray(h)?h.length:1} to extended slice of size ${P.length}`);for(let q=0;q<P.length;q++)a[P[q]]=h[q]}else{let q=Array.isArray(h)?h:[h];a.splice(I.start,P.length,...q)}}else a[l]=h;else if(a instanceof C.PyDict)a.set(l,h);else throw new C.PyException("TypeError",`'${typeof a}' object does not support item assignment`);break}case k.OpCode.DELETE_SUBSCR:{let l=e.stack.pop(),a=e.stack.pop();if(Array.isArray(a))if(l&&(l.__slice__||l.type===k.ASTNodeType.SLICE)){let h=l.start!==void 0?l.start:null,d=l.end!==void 0?l.end:null,m=l.step!==void 0?l.step:1,N=this.computeSliceBounds(a.length,h,d,m);if(N.step===1)a.splice(N.start,N.end-N.start);else{let I=this.computeSliceIndices(a.length,h,d,m);I.sort((P,q)=>q-P);for(let P of I)a.splice(P,1)}}else{if(typeof l!="number")throw new C.PyException("TypeError","list indices must be integers or slices");a.splice(l,1)}else if(a instanceof C.PyDict)a.delete(l);else if(a instanceof C.PySet)a.delete(l);else throw new C.PyException("TypeError",`'${typeof a}' object does not support item deletion`);break}case k.OpCode.POP_TOP:c=e.stack.pop();break;case k.OpCode.DUP_TOP:{let l=e.stack[e.stack.length-1];e.stack.push(l);break}case k.OpCode.DUP_TOP_TWO:{let l=e.stack[e.stack.length-1],a=e.stack[e.stack.length-2];e.stack.push(a),e.stack.push(l);break}case k.OpCode.ROT_TWO:{let l=e.stack.pop(),a=e.stack.pop();e.stack.push(l),e.stack.push(a);break}case k.OpCode.ROT_THREE:{let l=e.stack.pop(),a=e.stack.pop(),h=e.stack.pop();e.stack.push(l),e.stack.push(h),e.stack.push(a);break}case k.OpCode.BINARY_ADD:{let l=e.stack.pop(),a=e.stack.pop();e.stack.push(this.applyBinary("+",a,l));break}case k.OpCode.BINARY_SUBTRACT:{let l=e.stack.pop(),a=e.stack.pop();e.stack.push(this.applyBinary("-",a,l));break}case k.OpCode.BINARY_MULTIPLY:{let l=e.stack.pop(),a=e.stack.pop();e.stack.push(this.applyBinary("*",a,l));break}case k.OpCode.BINARY_DIVIDE:{let l=e.stack.pop(),a=e.stack.pop();e.stack.push(this.applyBinary("/",a,l));break}case k.OpCode.BINARY_FLOOR_DIVIDE:{let l=e.stack.pop(),a=e.stack.pop();e.stack.push(this.applyBinary("//",a,l));break}case k.OpCode.BINARY_MODULO:{let l=e.stack.pop(),a=e.stack.pop();e.stack.push(this.applyBinary("%",a,l));break}case k.OpCode.BINARY_POWER:{let l=e.stack.pop(),a=e.stack.pop();e.stack.push(this.applyBinary("**",a,l));break}case k.OpCode.BINARY_AND:{let l=e.stack.pop(),a=e.stack.pop();e.stack.push(this.applyBinary("&",a,l));break}case k.OpCode.BINARY_XOR:{let l=e.stack.pop(),a=e.stack.pop();e.stack.push(this.applyBinary("^",a,l));break}case k.OpCode.BINARY_OR:{let l=e.stack.pop(),a=e.stack.pop();e.stack.push(this.applyBinary("|",a,l));break}case k.OpCode.BINARY_LSHIFT:{let l=e.stack.pop(),a=e.stack.pop();e.stack.push(this.applyBinary("<<",a,l));break}case k.OpCode.BINARY_RSHIFT:{let l=e.stack.pop(),a=e.stack.pop();e.stack.push(this.applyBinary(">>",a,l));break}case k.OpCode.INPLACE_ADD:{let l=e.stack.pop(),a=e.stack.pop();e.stack.push(this.applyInPlaceBinary("+",a,l));break}case k.OpCode.INPLACE_SUBTRACT:{let l=e.stack.pop(),a=e.stack.pop();e.stack.push(this.applyInPlaceBinary("-",a,l));break}case k.OpCode.INPLACE_MULTIPLY:{let l=e.stack.pop(),a=e.stack.pop();e.stack.push(this.applyInPlaceBinary("*",a,l));break}case k.OpCode.INPLACE_DIVIDE:{let l=e.stack.pop(),a=e.stack.pop();e.stack.push(this.applyInPlaceBinary("/",a,l));break}case k.OpCode.INPLACE_FLOOR_DIVIDE:{let l=e.stack.pop(),a=e.stack.pop();e.stack.push(this.applyInPlaceBinary("//",a,l));break}case k.OpCode.INPLACE_MODULO:{let l=e.stack.pop(),a=e.stack.pop();e.stack.push(this.applyInPlaceBinary("%",a,l));break}case k.OpCode.INPLACE_POWER:{let l=e.stack.pop(),a=e.stack.pop();e.stack.push(this.applyInPlaceBinary("**",a,l));break}case k.OpCode.INPLACE_AND:{let l=e.stack.pop(),a=e.stack.pop();e.stack.push(this.applyInPlaceBinary("&",a,l));break}case k.OpCode.INPLACE_XOR:{let l=e.stack.pop(),a=e.stack.pop();e.stack.push(this.applyInPlaceBinary("^",a,l));break}case k.OpCode.INPLACE_OR:{let l=e.stack.pop(),a=e.stack.pop();e.stack.push(this.applyInPlaceBinary("|",a,l));break}case k.OpCode.INPLACE_LSHIFT:{let l=e.stack.pop(),a=e.stack.pop();e.stack.push(this.applyInPlaceBinary("<<",a,l));break}case k.OpCode.INPLACE_RSHIFT:{let l=e.stack.pop(),a=e.stack.pop();e.stack.push(this.applyInPlaceBinary(">>",a,l));break}case k.OpCode.UNARY_POSITIVE:{let l=e.stack.pop();e.stack.push(+l);break}case k.OpCode.UNARY_NEGATIVE:{let l=e.stack.pop();e.stack.push(-l);break}case k.OpCode.UNARY_NOT:{let l=e.stack.pop();e.stack.push(!this.isTruthy(l,e.scope));break}case k.OpCode.UNARY_INVERT:{let l=e.stack.pop();typeof l=="bigint"?e.stack.push(~l):e.stack.push(~Number(l));break}case k.OpCode.COMPARE_OP:{let l=e.stack.pop(),a=e.stack.pop();e.stack.push(this.applyCompare(_,a,l));break}case k.OpCode.BUILD_LIST:{let l=[];for(let a=0;a<_;a++)l.unshift(e.stack.pop());e.stack.push(l);break}case k.OpCode.BUILD_TUPLE:{let l=[];for(let a=0;a<_;a++)l.unshift(e.stack.pop());l.__tuple__=!0,e.stack.push(l);break}case k.OpCode.BUILD_MAP:{let l=new C.PyDict,a=[];for(let h=0;h<_;h++){let d=e.stack.pop(),m=e.stack.pop();a.push({k:m,v:d})}for(let h=a.length-1;h>=0;h--)l.set(a[h].k,a[h].v);e.stack.push(l);break}case k.OpCode.BUILD_SET:{let l=new C.PySet;for(let a=0;a<_;a++)l.add(e.stack.pop());e.stack.push(l);break}case k.OpCode.BUILD_SLICE:{let l=_===3?e.stack.pop():null,a=e.stack.pop(),h=e.stack.pop();e.stack.push({__slice__:!0,start:h,end:a,step:l});break}case k.OpCode.JUMP_ABSOLUTE:e.pc=_;break;case k.OpCode.POP_JUMP_IF_FALSE:{let l=e.stack.pop();this.isTruthy(l,e.scope)||(e.pc=_);break}case k.OpCode.POP_JUMP_IF_TRUE:{let l=e.stack.pop();this.isTruthy(l,e.scope)&&(e.pc=_);break}case k.OpCode.JUMP_IF_FALSE_OR_POP:{let l=e.stack[e.stack.length-1];this.isTruthy(l,e.scope)?e.stack.pop():e.pc=_;break}case k.OpCode.JUMP_IF_TRUE_OR_POP:{let l=e.stack[e.stack.length-1];this.isTruthy(l,e.scope)?e.pc=_:e.stack.pop();break}case k.OpCode.GET_ITER:{let l=e.stack.pop();if(l&&typeof l[Symbol.iterator]=="function")e.stack.push(l[Symbol.iterator]());else throw new C.PyException("TypeError",`'${typeof l}' object is not iterable`);break}case k.OpCode.FOR_ITER:{let a=e.stack[e.stack.length-1].next();a.done?(e.stack.pop(),e.pc=_):e.stack.push(a.value);break}case k.OpCode.MAKE_FUNCTION:{let l=_||0,a=e.stack.pop(),h=e.stack.pop(),d=[];for(let q=0;q<l;q++)d.unshift(e.stack.pop());let m=h&&h.params?h.params.map(q=>({...q})):[];if(m.length>0&&l>0){let q=0;for(let Q=m.length-l;Q<m.length;Q++)m[Q]&&m[Q].type==="Param"&&(m[Q].defaultEvaluated=d[q++])}let N=!!(h&&h.isGenerator),I=h&&h.astBody?h.astBody:[],P=new C.PyFunction(a,m,I,e.scope,N,new Set,h);P.closure_shared_values=e.scope.values,e.stack.push(P);break}case k.OpCode.LOAD_BUILD_CLASS:{let l=e.scope;e.stack.push((a,h,...d)=>{let m=new C.Scope(l,!0);if(a instanceof C.PyFunction&&a.bytecode){let P=new C.Frame(a.bytecode,m);this.executeFrame(P)}else typeof a=="function"&&a();let N=new Map(m.values.entries()),I=d.some(P=>P instanceof C.PyClass&&P.isException);return new C.PyClass(String(h),d,N,I)});break}case k.OpCode.IMPORT_NAME:{e.stack.pop(),e.stack.pop();let l=n[_];e.stack.push(this.importModule(l,e.scope));break}case k.OpCode.RAISE_VARARGS:throw _>=2&&e.stack.pop(),(_>=1?e.stack.pop():null)||new C.PyException("RuntimeError","No exception to raise");case k.OpCode.SETUP_FINALLY:{e.blockStack.push({handler:_,stackHeight:e.stack.length});break}case k.OpCode.SETUP_WITH:{let l=e.stack.pop(),a=this.getAttribute(l,"__enter__",e.scope),h=this.getAttribute(l,"__exit__",e.scope),d=this.callFunction(a,[],e.scope);e.stack.push(h),e.stack.push(d),e.blockStack.push({handler:_,stackHeight:e.stack.length-1});break}case k.OpCode.WITH_EXCEPT_START:{let l=e.stack.pop(),a=e.stack.pop(),h=l instanceof C.PyInstance?l.klass:l.pyType||l,d=this.callFunction(a,[h,l,null],e.scope);if(!this.isTruthy(d,e.scope))throw l;break}case k.OpCode.POP_BLOCK:{e.blockStack.pop();break}case k.OpCode.CALL_FUNCTION:{let l=[];for(let d=0;d<_;d++)l.unshift(e.stack.pop());let a=e.stack.pop();if((0,cr.detectTailCall)(e.bytecode,e.pc)&&a instanceof C.PyFunction&&a.bytecode){e.stack.length=0,e.pc=0;let d=new C.Scope(a.closure);d.locals=new Set(a.localNames),a.bytecode.globals&&a.bytecode.globals.forEach(I=>d.globals.add(I)),a.bytecode.nonlocals&&a.bytecode.nonlocals.forEach(I=>d.nonlocals.add(I));let m=[...l];for(let I of a.params)if(I.type==="Param"){let P;m.length>0?P=m.shift():I.defaultEvaluated!==void 0?P=I.defaultEvaluated:I.defaultValue?P=this.evaluateExpression(I.defaultValue,e.scope):P=null,d.set(I.name,P)}else if(I.type==="VarArg"){let P=[...m];P.__tuple__=!0,d.set(I.name,P),m.length=0}e.scope=d,e.bytecode=a.bytecode,e.locals=new Array((a.bytecode.varnames||[]).length).fill(void 0),e.blockStack.length=0;let N=a.bytecode.varnames||[];for(let I=0;I<(a.bytecode.argcount||0);I++){let P=N[I];e.locals[I]=d.values.get(P)}break}else e.stack.push(this.callFunction(a,l,e.scope));break}case k.OpCode.CALL_FUNCTION_KW:{let l=e.stack.pop(),a=Array.isArray(l)?l:[],h=a.length,d=_,m=[];for(let Q=0;Q<d;Q++)m.unshift(e.stack.pop());let N=e.stack.pop(),I=d-h,P=m.slice(0,I),q={};for(let Q=0;Q<h;Q++)q[String(a[Q])]=m[I+Q];e.stack.push(this.callFunction(N,P,e.scope,q));break}case k.OpCode.CALL_FUNCTION_EX:{let l={};if(_===1){let m=e.stack.pop();if(m instanceof C.PyDict)for(let[N,I]of m.entries())l[String(N)]=I;else if(m&&typeof m=="object")for(let[N,I]of Object.entries(m))l[N]=I}let a=e.stack.pop(),h=e.stack.pop(),d=Array.isArray(a)?a:a?Array.from(a):[];e.stack.push(this.callFunction(h,d,e.scope,l));break}case k.OpCode.EVAL_AST:{let l=e.stack.pop();e.stack.push(this.evaluateExpression(l,e.scope));break}case k.OpCode.RETURN_VALUE:return e.stack.pop();default:throw new Error(`VM: Unknown opcode ${k.OpCode[O]} (${O}) at pc ${e.pc-1}`)}}catch(l){if(E(l))continue;throw l}}return c}}var ae=Ht();Object.defineProperty(Y,"applyCompare",{enumerable:!0,get:function(){return ae.applyCompare}});Object.defineProperty(Y,"iterableToArray",{enumerable:!0,get:function(){return ae.iterableToArray}});Object.defineProperty(Y,"matchValueEquals",{enumerable:!0,get:function(){return ae.matchValueEquals}});Object.defineProperty(Y,"applyBindings",{enumerable:!0,get:function(){return ae.applyBindings}});Object.defineProperty(Y,"matchPattern",{enumerable:!0,get:function(){return ae.matchPattern}});Object.defineProperty(Y,"evaluateExpression",{enumerable:!0,get:function(){return ae.evaluateExpression}});Object.defineProperty(Y,"executeStatement",{enumerable:!0,get:function(){return ae.executeStatement}});Object.defineProperty(Y,"executeBlockGenerator",{enumerable:!0,get:function(){return ae.executeBlockGenerator}});Object.defineProperty(Y,"executeStatementGenerator",{enumerable:!0,get:function(){return ae.executeStatementGenerator}});Object.defineProperty(Y,"executeBlock",{enumerable:!0,get:function(){return ae.executeBlock}})});var Xt=x(dt=>{"use strict";Object.defineProperty(dt,"__esModule",{value:!0});dt.evaluateExpressionGenerator=pr;var de=W();function*pr(e,t){switch(e.type){case de.ASTNodeType.YIELD:return yield e.value?yield*this.evaluateExpressionGenerator(e.value,t):null;case de.ASTNodeType.BINARY_OPERATION:{let s=yield*this.evaluateExpressionGenerator(e.left,t),n=yield*this.evaluateExpressionGenerator(e.right,t);return this.applyBinary(e.operator,s,n)}case de.ASTNodeType.UNARY_OPERATION:{let s=yield*this.evaluateExpressionGenerator(e.operand,t);return this.evaluateExpression({...e,operand:s},t)}case de.ASTNodeType.COMPARE:{let s=yield*this.evaluateExpressionGenerator(e.left,t),n=[];for(let r of e.comparators)n.push(yield*this.evaluateExpressionGenerator(r,t));return this.evaluateExpression({...e,left:s,comparators:n},t)}case de.ASTNodeType.CALL:{let s=yield*this.evaluateExpressionGenerator(e.callee,t),n=[],r={};for(let i of e.args)if(i.type==="KeywordArg")r[i.name]=yield*this.evaluateExpressionGenerator(i.value,t);else if(i.type==="StarArg"){let c=yield*this.evaluateExpressionGenerator(i.value,t);n.push(...Array.isArray(c)?c:Array.from(c))}else if(i.type==="KwArg"){let c=yield*this.evaluateExpressionGenerator(i.value,t);Object.assign(r,c)}else n.push(yield*this.evaluateExpressionGenerator(i,t));return this.callFunction(s,n,t,r)}case de.ASTNodeType.ATTRIBUTE:{let s=yield*this.evaluateExpressionGenerator(e.object,t);return this.getAttribute(s,e.name,t)}case de.ASTNodeType.SUBSCRIPT:{let s=yield*this.evaluateExpressionGenerator(e.object,t),n=yield*this.evaluateExpressionGenerator(e.index,t);return this.getSubscript(s,n)}case de.ASTNodeType.IF_EXPRESSION:{let s=yield*this.evaluateExpressionGenerator(e.test,t);return this.isTruthy(s,t)?yield*this.evaluateExpressionGenerator(e.consequent,t):yield*this.evaluateExpressionGenerator(e.alternate,t)}default:return this.evaluateExpression(e,t)}}});var Zt=x(te=>{"use strict";var hr=te&&te.__createBinding||(Object.create?(function(e,t,s,n){n===void 0&&(n=s);var r=Object.getOwnPropertyDescriptor(t,s);(!r||("get"in r?!t.__esModule:r.writable||r.configurable))&&(r={enumerable:!0,get:function(){return t[s]}}),Object.defineProperty(e,n,r)}):(function(e,t,s,n){n===void 0&&(n=s),e[n]=t[s]})),Tr=te&&te.__setModuleDefault||(Object.create?(function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}):function(e,t){e.default=t}),Qt=te&&te.__importStar||(function(){var e=function(t){return e=Object.getOwnPropertyNames||function(s){var n=[];for(var r in s)Object.prototype.hasOwnProperty.call(s,r)&&(n[n.length]=r);return n},e(t)};return function(t){if(t&&t.__esModule)return t;var s={};if(t!=null)for(var n=e(t),r=0;r<n.length;r++)n[r]!=="default"&&hr(s,t,n[r]);return Tr(s,t),s}})();Object.defineProperty(te,"__esModule",{value:!0});te.importModule=dr;te.createAsyncioModule=Er;te.loadModuleFromFile=_r;te.resolveModulePath=Ar;var Et=Qt(require("fs")),Jt=Qt(require("path")),fr=Ce(),yr=ve(),We=X();function dr(e,t){if(this.moduleCache.has(e))return this.moduleCache.get(e);let s;return e==="asyncio"?s=this.createAsyncioModule(t):s=this.loadModuleFromFile(e,t),this.moduleCache.set(e,s),s}function Er(e){return{__name__:"asyncio",run:t=>t instanceof We.PyFunction?this.callFunction(t,[],e):t instanceof We.PyGenerator?t.next():t}}function _r(e,t){let s=this.resolveModulePath(e);if(!s)throw new We.PyException("ImportError",`No module named '${e}'`);let n=Et.readFileSync(s,"utf-8"),i=new fr.Lexer(n).tokenize(),o=new yr.Parser(i).parse(),p=new We.Scope(t.root());return p.set("__name__",e),this.executeBlock(o.body,p),{__name__:e,__moduleScope__:p}}function Ar(e){for(let t of this.moduleSearchPaths){let s=Jt.join(t,`${e}.py`);if(Et.existsSync(s))return s;let n=Jt.join(t,e,"__init__.py");if(Et.existsSync(n))return n}return null}});var es=x(pe=>{"use strict";Object.defineProperty(pe,"__esModule",{value:!0});pe.evaluateExpression=kr;pe.evaluateExpressionString=Sr;pe.executeExpressionInline=Ir;pe.applyFormatSpec=Or;pe.splitFormatSpec=br;pe.applyWidth=Rr;pe.contains=gr;var F=W(),Nr=Ce(),mr=ve(),J=X(),H=Ee();function kr(e,t){switch(e.type){case F.ASTNodeType.NUMBER_LITERAL:{let s=e.value;if(typeof s=="number")return s;if(typeof s=="string"&&s.endsWith("j"))return{__complex__:!0,re:0,im:parseFloat(s.slice(0,-1))};if(s.includes("."))return new Number(parseFloat(s));let n=BigInt(s),r=BigInt(Number.MAX_SAFE_INTEGER),i=BigInt(Number.MIN_SAFE_INTEGER);return n>r||n<i?n:Number(s)}case F.ASTNodeType.STRING_LITERAL:{let{value:s,isFString:n}=(0,H.parseStringToken)(e.value);return n?s.replace(/\{([^}]+)\}/g,(r,i)=>{let{rawExpr:c,rawSpec:o}=this.splitFormatSpec(i),p=this.evaluateExpressionString(c.trim(),t);return this.applyFormatSpec(p,o?o.trim():"")}):s}case F.ASTNodeType.BOOLEAN_LITERAL:return e.value;case F.ASTNodeType.NONE_LITERAL:return null;case F.ASTNodeType.IDENTIFIER:return t.get(e.name);case F.ASTNodeType.LIST_LITERAL:return e.elements.map(s=>this.evaluateExpression(s,t));case F.ASTNodeType.LIST_COMP:{let s=[],n=new J.Scope(t);return this.evaluateComprehension(e.comprehension,n,()=>{s.push(this.evaluateExpression(e.expression,n))},t),s}case F.ASTNodeType.TUPLE_LITERAL:{let s=e.elements.map(n=>this.evaluateExpression(n,t));return s.__tuple__=!0,s}case F.ASTNodeType.SET_COMP:{let s=new J.PySet,n=new J.Scope(t);return this.evaluateComprehension(e.comprehension,n,()=>{s.add(this.evaluateExpression(e.expression,n))},t),s}case F.ASTNodeType.SET_LITERAL:return new J.PySet(e.elements.map(s=>this.evaluateExpression(s,t)));case F.ASTNodeType.DICT_LITERAL:{let s=[];for(let r of e.entries)s.push({key:this.evaluateExpression(r.key,t),value:this.evaluateExpression(r.value,t)});let n=new J.PyDict;for(let r of s)n.set(r.key,r.value);return n}case F.ASTNodeType.DICT_COMP:{let s=new J.PyDict,n=new J.Scope(t);return this.evaluateComprehension(e.comprehension,n,()=>{s.set(this.evaluateExpression(e.key,n),this.evaluateExpression(e.value,n))},t),s}case F.ASTNodeType.GENERATOR_EXPR:{let s=new J.Scope(t),n=function*(){yield*this.generateComprehension(e.comprehension,s,()=>this.evaluateExpression(e.expression,s),t)};return new J.PyGenerator(n.call(this))}case F.ASTNodeType.BINARY_OPERATION:{let s=this.evaluateExpression(e.left,t),n=this.evaluateExpression(e.right,t);return this.applyBinary(e.operator,s,n)}case F.ASTNodeType.UNARY_OPERATION:{let s=this.evaluateExpression(e.operand,t);switch(e.operator){case"not":return!this.isTruthy(s,t);case"+":return typeof s=="bigint"?s:+s;case"-":if((0,H.isIntObject)(s)){let n=new Number(-s.valueOf());return n.__int__=!0,n}return(0,H.isFloatObject)(s)?new Number(-s.valueOf()):-s;case"~":return~s;default:throw new J.PyException("TypeError",`unsupported unary operator ${e.operator} `)}}case F.ASTNodeType.BOOL_OPERATION:{if(e.operator==="and"){let n=this.evaluateExpression(e.values[0],t);return this.isTruthy(n,t)?this.evaluateExpression(e.values[1],t):n}let s=this.evaluateExpression(e.values[0],t);return this.isTruthy(s,t)?s:this.evaluateExpression(e.values[1],t)}case F.ASTNodeType.COMPARE:{let s=this.evaluateExpression(e.left,t);for(let n=0;n<e.ops.length;n++){let r=e.ops[n],i=this.evaluateExpression(e.comparators[n],t),c=!1;switch(r){case"==":c=(0,H.numericEquals)(s,i);break;case"!=":c=!(0,H.numericEquals)(s,i);break;case"<":{let o=(0,H.numericCompare)(s,i);o?c=o.left<o.right:c=s<i;break}case">":{let o=(0,H.numericCompare)(s,i);o?c=o.left>o.right:c=s>i;break}case"<=":{let o=(0,H.numericCompare)(s,i);o?c=o.left<=o.right:c=s<=i;break}case">=":{let o=(0,H.numericCompare)(s,i);o?c=o.left>=o.right:c=s>=i;break}case"in":c=this.contains(i,s);break;case"not in":c=!this.contains(i,s);break;case"is":c=s===i;break;case"is not":c=s!==i;break;default:throw new J.PyException("TypeError",`unsupported comparison ${r} `)}if(!c)return!1;s=i}return!0}case F.ASTNodeType.CALL:{let s=this.evaluateExpression(e.callee,t),n=[],r={};for(let i of e.args)if(i.type==="KeywordArg")r[i.name]=this.evaluateExpression(i.value,t);else if(i.type==="StarArg"){let c=this.evaluateExpression(i.value,t);n.push(...Array.isArray(c)?c:Array.from(c))}else if(i.type==="KwArg"){let c=this.evaluateExpression(i.value,t);Object.assign(r,c)}else n.push(this.evaluateExpression(i,t));return this.callFunction(s,n,t,r)}case F.ASTNodeType.ATTRIBUTE:{let s=this.evaluateExpression(e.object,t);return this.getAttribute(s,e.name,t)}case F.ASTNodeType.SUBSCRIPT:{let s=this.evaluateExpression(e.object,t);if(e.index&&e.index.type===F.ASTNodeType.SLICE){let r={type:F.ASTNodeType.SLICE,start:e.index.start?this.evaluateExpression(e.index.start,t):null,end:e.index.end?this.evaluateExpression(e.index.end,t):null,step:e.index.step?this.evaluateExpression(e.index.step,t):null};return this.getSubscript(s,r)}let n=this.evaluateExpression(e.index,t);return this.getSubscript(s,n)}case F.ASTNodeType.IF_EXPRESSION:{let s=this.evaluateExpression(e.test,t);return this.isTruthy(s,t)?this.evaluateExpression(e.consequent,t):this.evaluateExpression(e.alternate,t)}case F.ASTNodeType.LAMBDA:return new J.PyFunction("<lambda>",e.params.map(s=>({type:"Param",name:s})),[{type:F.ASTNodeType.RETURN_STATEMENT,value:e.body}],t,!1);default:throw new Error(`Unsupported expression type: ${e.type} `)}}function Sr(e,t){let s=`__f = ${e}
12
+ `,n=new Nr.Lexer(s).tokenize(),i=new mr.Parser(n).parse().body[0];return!i||i.type!==F.ASTNodeType.ASSIGNMENT?this.executeExpressionInline(e,t):this.evaluateExpression(i.value,t)}function Ir(e,t){let s=e.trim().split(/\s+/);return s.length===1&&s[0]&&t.values.has(s[0])?t.get(s[0]):e}function Or(e,t){if(!t)return(0,H.pyStr)(e);if(t.endsWith("%")){let s=t.split("."),n=t.includes(".")?parseInt(s[1],10):0;return(((0,H.isNumericLike)(e)?(0,H.toNumber)(e):parseFloat(e))*100).toFixed(n)+"%"}if(t.includes(".")){let s=t.split("."),n=s[0],r=parseInt(s[1].replace(/[^\d]/g,""),10),c=((0,H.isNumericLike)(e)?(0,H.toNumber)(e):parseFloat(e)).toFixed(r);return this.applyWidth(c,n)}return t==="d"?typeof e=="bigint"?e.toString():String(parseInt(e,10)):t==="b"?typeof e=="bigint"?e.toString(2):Number(e).toString(2):t==="x"?typeof e=="bigint"?e.toString(16):Number(e).toString(16):t==="o"?typeof e=="bigint"?e.toString(8):Number(e).toString(8):this.applyWidth(String(e),t)}function br(e){let t=0;for(let s=0;s<e.length;s++){let n=e[s];if((n==="("||n==="["||n==="{")&&t++,(n===")"||n==="]"||n==="}")&&(t=Math.max(0,t-1)),n===":"&&t===0)return{rawExpr:e.slice(0,s),rawSpec:e.slice(s+1)}}return{rawExpr:e,rawSpec:""}}function Rr(e,t){let s=t.match(/([<^>])?(\d+)/);if(!s)return e;let n=s[1]||">",r=parseInt(s[2],10);if(e.length>=r)return e;let i=r-e.length;if(n==="<")return e+" ".repeat(i);if(n==="^"){let c=Math.floor(i/2),o=i-c;return" ".repeat(c)+e+" ".repeat(o)}return" ".repeat(i)+e}function gr(e,t){return Array.isArray(e)?(0,H.isNumericLike)(t)?e.some(s=>(0,H.isNumericLike)(s)&&(0,H.numericEquals)(s,t)):e.includes(t):typeof e=="string"?e.includes(t):e instanceof J.PySet||e instanceof J.PyDict?e.has(t):!1}});var ts=x(ke=>{"use strict";Object.defineProperty(ke,"__esModule",{value:!0});ke.executeStatement=xr;ke.assignTarget=Lr;ke.toIterableArray=Cr;ke.deleteTarget=Br;var g=W(),R=X(),Pr=Ee();function xr(e,t){switch(e.type){case g.ASTNodeType.EXPRESSION_STATEMENT:return this.evaluateExpression(e.expression,t);case g.ASTNodeType.IMPORT_STATEMENT:{for(let s of e.names){let n=this.importModule(s.name,t),r=s.alias||s.name.split(".")[0];t.set(r,n)}return null}case g.ASTNodeType.ASSIGNMENT:{let s=this.evaluateExpression(e.value,t);for(let n of e.targets)this.assignTarget(n,s,t);return null}case g.ASTNodeType.AUG_ASSIGNMENT:{let s=e.target,n,r,i;if(s.type===g.ASTNodeType.IDENTIFIER){n=t.get(s.name);let c=this.evaluateExpression(e.value,t),o=this.applyInPlaceBinary(e.operator,n,c);t.set(s.name,o)}else if(s.type===g.ASTNodeType.ATTRIBUTE){r=this.evaluateExpression(s.object,t),n=this.getAttribute(r,s.name,t);let c=this.evaluateExpression(e.value,t),o=this.applyInPlaceBinary(e.operator,n,c);this.setAttribute(r,s.name,o)}else if(s.type===g.ASTNodeType.SUBSCRIPT){r=this.evaluateExpression(s.object,t),s.index&&s.index.type===g.ASTNodeType.SLICE?(i={type:g.ASTNodeType.SLICE,start:s.index.start?this.evaluateExpression(s.index.start,t):null,end:s.index.end?this.evaluateExpression(s.index.end,t):null,step:s.index.step?this.evaluateExpression(s.index.step,t):null},n=this.getSubscript(r,i)):(i=this.evaluateExpression(s.index,t),n=this.getSubscript(r,i));let c=this.evaluateExpression(e.value,t),o=this.applyInPlaceBinary(e.operator,n,c);if(Array.isArray(r)){if(r.__tuple__)throw new R.PyException("TypeError","'tuple' object does not support item assignment");if(i&&i.type===g.ASTNodeType.SLICE){let p=i.start!==null?i.start:null,E=i.end!==null?i.end:null,y=i.step!==null?i.step:null,O=y??1,_=this.toIterableArray(o);if(O===1){let l=this.computeSliceBounds(r.length,p,E,O);r.splice(l.start,l.end-l.start,..._)}else{let l=this.computeSliceIndices(r.length,p,E,O);if(_.length!==l.length)throw new R.PyException("ValueError",`attempt to assign sequence of size ${_.length} to extended slice of size ${l.length}`);for(let a=0;a<l.length;a++)r[l[a]]=_[a]}}else r[i]=o}else if(r instanceof R.PyDict)r.set(i,o);else throw new R.PyException("TypeError","unsupported subscript assignment")}else throw new R.PyException("TypeError","illegal expression for augmented assignment");return null}case g.ASTNodeType.IF_STATEMENT:{if(this.isTruthy(this.evaluateExpression(e.test,t),t))return this.executeBlock(e.body,t);for(let s of e.elifs)if(this.isTruthy(this.evaluateExpression(s.test,t),t))return this.executeBlock(s.body,t);return e.orelse?.length?this.executeBlock(e.orelse,t):null}case g.ASTNodeType.WHILE_STATEMENT:{for(;this.isTruthy(this.evaluateExpression(e.test,t),t);)try{this.executeBlock(e.body,t)}catch(s){if(s instanceof R.BreakSignal)break;if(s instanceof R.ContinueSignal)continue;throw s}return null}case g.ASTNodeType.FOR_STATEMENT:{let s=this.evaluateExpression(e.iter,t),n=this.iterableToArray(s);for(let r of n){this.assignTarget(e.target,r,t);try{this.executeBlock(e.body,t)}catch(i){if(i instanceof R.BreakSignal)break;if(i instanceof R.ContinueSignal)continue;throw i}}return null}case g.ASTNodeType.MATCH_STATEMENT:{let s=this.evaluateExpression(e.subject,t);for(let n of e.cases){let r=this.matchPattern(n.pattern,s,t);if(r.matched){if(n.guard){let i=new R.Scope(t);if(this.applyBindings(r.bindings,i),!this.isTruthy(this.evaluateExpression(n.guard,i),i))continue}return this.applyBindings(r.bindings,t),this.executeBlock(n.body,t)}}return null}case g.ASTNodeType.FUNCTION_DEF:{let s=(e.params||[]).map(c=>c.type==="Param"&&c.defaultValue?{...c,defaultEvaluated:this.evaluateExpression(c.defaultValue,t)}:c),n=t.isClassScope?t.parent:t,r=(0,Pr.findLocalVariables)(e.body);for(let c of e.params||[])c.name&&r.add(c.name);let i=new R.PyFunction(e.name,s,e.body,n,this.containsYield(e.body),r);if(t.set(e.name,i),e.decorators&&e.decorators.length>0){let c=i;for(let o of e.decorators.reverse()){let p=this.evaluateExpression(o,t);c=this.callFunction(p,[c],t)}t.set(e.name,c)}return null}case g.ASTNodeType.CLASS_DEF:{let s=e.bases?.map(o=>this.evaluateExpression(o,t))||[],n=new R.Scope(t,!0);this.executeBlock(e.body,n);let r=new Map(n.values.entries()),i=s.some(o=>o instanceof R.PyClass&&o.isException),c=new R.PyClass(e.name,s,r,i);if(t.set(e.name,c),e.decorators&&e.decorators.length>0){let o=c;for(let p of e.decorators.reverse()){let E=this.evaluateExpression(p,t);o=this.callFunction(E,[o],t)}t.set(e.name,o)}return null}case g.ASTNodeType.RETURN_STATEMENT:throw new R.ReturnSignal(e.value?this.evaluateExpression(e.value,t):null);case g.ASTNodeType.BREAK_STATEMENT:throw new R.BreakSignal;case g.ASTNodeType.CONTINUE_STATEMENT:throw new R.ContinueSignal;case g.ASTNodeType.PASS_STATEMENT:return null;case g.ASTNodeType.ASSERT_STATEMENT:{let s=this.evaluateExpression(e.test,t);if(!this.isTruthy(s,t)){let n=e.message?this.evaluateExpression(e.message,t):"Assertion failed";throw new R.PyException("AssertionError",String(n))}return null}case g.ASTNodeType.RAISE_STATEMENT:{let s=e.exception?this.evaluateExpression(e.exception,t):null;if(s instanceof R.PyException)throw s;if(s instanceof R.PyInstance&&s.klass.isException){let n=s.attributes.get("message");throw new R.PyException(s.klass.name,n?String(n):s.klass.name,s)}throw s instanceof R.PyClass&&s.isException?new R.PyException(s.name,s.name):new R.PyException("Exception",s?String(s):"Exception")}case g.ASTNodeType.TRY_STATEMENT:{let s=!1;try{this.executeBlock(e.body,t)}catch(n){s=!0;let r=!1;for(let i of e.handlers){if(!i.exceptionType)r=!0;else if(n instanceof R.PyException){let c=this.evaluateExpression(i.exceptionType,t);(c instanceof R.PyClass&&c.isException&&n.pyType===c.name||c instanceof R.PyInstance&&c.klass.isException&&n.pyType===c.klass.name)&&(r=!0)}if(r){i.name&&t.set(i.name,n instanceof R.PyException?n:new R.PyException("Exception",String(n))),this.executeBlock(i.body,t);break}}if(!r)throw n}finally{e.finalbody?.length&&this.executeBlock(e.finalbody,t)}return!s&&e.orelse?.length&&this.executeBlock(e.orelse,t),null}case g.ASTNodeType.WITH_STATEMENT:{for(let s of e.items){let n=this.evaluateExpression(s.context,t),r=this.getAttribute(n,"__enter__",t),i=this.getAttribute(n,"__exit__",t),c=this.callFunction(r,[],t);s.target&&this.assignTarget(s.target,c,t);try{this.executeBlock(e.body,t)}catch(o){throw this.callFunction(i,[o],t),o}this.callFunction(i,[null,null,null],t)}return null}case g.ASTNodeType.GLOBAL_STATEMENT:for(let s of e.names)t.globals.add(s);return null;case g.ASTNodeType.NONLOCAL_STATEMENT:for(let s of e.names)t.nonlocals.add(s);return null;case g.ASTNodeType.DELETE_STATEMENT:return this.deleteTarget(e.target,t),null;default:throw new Error(`Unsupported statement type: ${e.type}`)}}function Lr(e,t,s){if(e.type===g.ASTNodeType.IDENTIFIER){s.set(e.name,t);return}if(e.type===g.ASTNodeType.ATTRIBUTE){let n=this.evaluateExpression(e.object,s);this.setAttribute(n,e.name,t);return}if(e.type===g.ASTNodeType.SUBSCRIPT){let n=this.evaluateExpression(e.object,s),r;if(e.index&&e.index.type===g.ASTNodeType.SLICE?r={type:g.ASTNodeType.SLICE,start:e.index.start?this.evaluateExpression(e.index.start,s):null,end:e.index.end?this.evaluateExpression(e.index.end,s):null,step:e.index.step?this.evaluateExpression(e.index.step,s):null}:r=this.evaluateExpression(e.index,s),Array.isArray(n)){if(n.__tuple__)throw new R.PyException("TypeError","'tuple' object does not support item assignment");if(r&&r.type===g.ASTNodeType.SLICE){let i=r.start!==null?r.start:null,c=r.end!==null?r.end:null,o=r.step!==null?r.step:null,p=o??1,E=this.toIterableArray(t);if(p===1){let y=this.computeSliceBounds(n.length,i,c,p);n.splice(y.start,y.end-y.start,...E)}else{let y=this.computeSliceIndices(n.length,i,c,p);if(E.length!==y.length)throw new R.PyException("ValueError",`attempt to assign sequence of size ${E.length} to extended slice of size ${y.length}`);for(let O=0;O<y.length;O++)n[y[O]]=E[O]}}else n[r]=t;return}if(n instanceof R.PyDict){n.set(r,t);return}throw new R.PyException("TypeError","unsupported subscript assignment")}if(e.type===g.ASTNodeType.TUPLE_LITERAL||e.type===g.ASTNodeType.LIST_LITERAL){let n=e.elements,r=this.toIterableArray(t),i=n.findIndex(y=>y.type===g.ASTNodeType.STARRED);if(i===-1){for(let y=0;y<n.length;y++)this.assignTarget(n[y],r[y],s);return}let c=i,o=n.length-i-1;if(r.length<c+o)throw new R.PyException("ValueError","not enough values to unpack");for(let y=0;y<c;y++)this.assignTarget(n[y],r[y],s);let p=n[i],E=r.slice(c,r.length-o);this.assignTarget(p.target,E,s);for(let y=0;y<o;y++){let O=r.length-o+y,_=i+1+y;this.assignTarget(n[_],r[O],s)}return}throw new R.PyException("TypeError","invalid assignment target")}function Cr(e){if(Array.isArray(e))return e;if(e&&typeof e[Symbol.iterator]=="function")return Array.from(e);throw new R.PyException("TypeError","cannot unpack non-iterable")}function Br(e,t){if(e.type===g.ASTNodeType.SUBSCRIPT){let s=this.evaluateExpression(e.object,t),n;if(e.index&&e.index.type===g.ASTNodeType.SLICE?n={type:g.ASTNodeType.SLICE,start:e.index.start?this.evaluateExpression(e.index.start,t):null,end:e.index.end?this.evaluateExpression(e.index.end,t):null,step:e.index.step?this.evaluateExpression(e.index.step,t):null}:n=this.evaluateExpression(e.index,t),Array.isArray(s)){if(s.__tuple__)throw new R.PyException("TypeError","'tuple' object does not support item assignment");if(n&&n.type===g.ASTNodeType.SLICE){let r=n.start!==null?n.start:null,i=n.end!==null?n.end:null,c=n.step!==null?n.step:null,o=c??1;if(o===1){let p=this.computeSliceBounds(s.length,r,i,o);s.splice(p.start,p.end-p.start)}else{let p=this.computeSliceIndices(s.length,r,i,o);p.sort((E,y)=>y-E);for(let E of p)s.splice(E,1)}}else s.splice(n,1);return}if(s instanceof R.PyDict){s.delete(n);return}throw new R.PyException("TypeError","unsupported delete target")}throw new R.PyException("TypeError","unsupported delete target")}});var ns=x(se=>{"use strict";Object.defineProperty(se,"__esModule",{value:!0});se.applyInPlaceBinary=vr;se.applyBinary=Mr;se.formatPercent=Dr;se.getSubscript=Fr;se.computeSliceBounds=Ur;se.computeSliceIndices=Yr;se.normalizeSliceStep=Gr;se.getAttribute=jr;se.setAttribute=Vr;se.findClassAttribute=ss;var wr=W(),B=X(),A=Ee();function vr(e,t,s){return e==="+"&&Array.isArray(t)&&!t.__tuple__&&Array.isArray(s)?(t.push(...s),t):this.applyBinary(e,t,s)}function Mr(e,t,s){if((0,A.isComplex)(t)||(0,A.isComplex)(s)){let n=(0,A.toComplex)(t),r=(0,A.toComplex)(s);switch(e){case"+":return{__complex__:!0,re:n.re+r.re,im:n.im+r.im};case"-":return{__complex__:!0,re:n.re-r.re,im:n.im-r.im};case"*":return{__complex__:!0,re:n.re*r.re-n.im*r.im,im:n.re*r.im+n.im*r.re};default:throw new B.PyException("TypeError",`unsupported complex operator ${e}`)}}switch(e){case"+":if(Array.isArray(t)&&Array.isArray(s)){let n=[...t,...s];return t.__tuple__&&s.__tuple__&&(n.__tuple__=!0),n}return(0,A.isFloatLike)(t)||(0,A.isFloatLike)(s)?new Number((0,A.toNumber)(t)+(0,A.toNumber)(s)):(0,A.shouldUseBigInt)(t,s)?(0,A.toBigIntValue)(t)+(0,A.toBigIntValue)(s):t+s;case"-":if(t instanceof B.PySet&&s instanceof B.PySet){let n=new B.PySet(t);for(let r of s.values())n.delete(r);return n}return(0,A.isFloatLike)(t)||(0,A.isFloatLike)(s)?new Number((0,A.toNumber)(t)-(0,A.toNumber)(s)):(0,A.shouldUseBigInt)(t,s)?(0,A.toBigIntValue)(t)-(0,A.toBigIntValue)(s):t-s;case"*":if(typeof t=="string"&&(0,A.isIntLike)(s)){let n=(0,A.toNumber)(s);return n<=0?"":t.repeat(n)}if(typeof s=="string"&&(0,A.isIntLike)(t)){let n=(0,A.toNumber)(t);return n<=0?"":s.repeat(n)}if(Array.isArray(t)&&(0,A.isIntLike)(s)){let n=(0,A.toNumber)(s);if(n<=0){let i=[];return t.__tuple__&&(i.__tuple__=!0),i}let r=Array(n).fill(null).flatMap(()=>t);return t.__tuple__&&(r.__tuple__=!0),r}return(0,A.isFloatLike)(t)||(0,A.isFloatLike)(s)?new Number((0,A.toNumber)(t)*(0,A.toNumber)(s)):(0,A.shouldUseBigInt)(t,s)?(0,A.toBigIntValue)(t)*(0,A.toBigIntValue)(s):t*s;case"/":if(s===0||s===0n)throw new B.PyException("ZeroDivisionError","division by zero");return new Number((0,A.toNumber)(t)/(0,A.toNumber)(s));case"//":if(s===0||s===0n)throw new B.PyException("ZeroDivisionError","division by zero");return(0,A.isFloatLike)(t)||(0,A.isFloatLike)(s)?new Number(Math.floor((0,A.toNumber)(t)/(0,A.toNumber)(s))):(0,A.shouldUseBigInt)(t,s)?(0,A.bigIntFloorDiv)((0,A.toBigIntValue)(t),(0,A.toBigIntValue)(s)):Math.floor(t/s);case"%":return typeof t=="string"?this.formatPercent(t,s):(0,A.pythonModulo)(t,s);case"**":if((0,A.isIntLike)(t)&&(0,A.isIntLike)(s)&&!(0,A.isFloatLike)(t)&&!(0,A.isFloatLike)(s)){let n=(0,A.toNumber)(s);if(Number.isInteger(n)&&n>=0){let r=Math.pow((0,A.toNumber)(t),n);if((0,A.shouldUseBigInt)(t,s)||!Number.isSafeInteger(r))return(0,A.toBigIntValue)(t)**(0,A.toBigIntValue)(s)}}if((0,A.shouldUseBigInt)(t,s)){let n=(0,A.toBigIntValue)(s);return n<0n?new Number(Math.pow((0,A.toNumber)(t),(0,A.toNumber)(s))):(0,A.toBigIntValue)(t)**n}return Math.pow((0,A.toNumber)(t),(0,A.toNumber)(s));case"&":if(t instanceof B.PySet&&s instanceof B.PySet){let n=new B.PySet;for(let r of t.values())s.has(r)&&n.add(r);return n}return(0,A.shouldUseBigInt)(t,s)?(0,A.toBigIntValue)(t)&(0,A.toBigIntValue)(s):t&s;case"|":if(t instanceof B.PySet&&s instanceof B.PySet){let n=new B.PySet(t);for(let r of s.values())n.add(r);return n}return(0,A.shouldUseBigInt)(t,s)?(0,A.toBigIntValue)(t)|(0,A.toBigIntValue)(s):t|s;case"^":if(t instanceof B.PySet&&s instanceof B.PySet){let n=new B.PySet;for(let r of t.values())s.has(r)||n.add(r);for(let r of s.values())t.has(r)||n.add(r);return n}return(0,A.shouldUseBigInt)(t,s)?(0,A.toBigIntValue)(t)^(0,A.toBigIntValue)(s):t^s;case"<<":return(0,A.shouldUseBigInt)(t,s)?(0,A.toBigIntValue)(t)<<(0,A.toBigIntValue)(s):t<<s;case">>":return(0,A.shouldUseBigInt)(t,s)?(0,A.toBigIntValue)(t)>>(0,A.toBigIntValue)(s):t>>s;default:throw new B.PyException("TypeError",`unsupported operator ${e}`)}}function Dr(e,t){let s=Array.isArray(t)?t:[t],n=0;return e.replace(/%[sdfo]/g,r=>{let i=s[n++];return r==="%d"?typeof i=="bigint"?i.toString():String(parseInt(i,10)):String(r==="%f"?parseFloat(i):i)})}function Fr(e,t){if(t&&(t.type===wr.ASTNodeType.SLICE||t.__slice__)){let s=t.start!==void 0?t.start:null,n=t.end!==void 0?t.end:null,r=t.step!==void 0?t.step:1,i=this.computeSliceIndices(e.length,s,n,r),c=[];for(let o of i)c.push(e[o]);return typeof e=="string"?c.join(""):(Array.isArray(e)&&e.__tuple__&&(c.__tuple__=!0),c)}if(Array.isArray(e)||typeof e=="string"){let s=t;return(0,A.isIntLike)(s)&&(0,A.toNumber)(s)<0&&(s=e.length+(0,A.toNumber)(s)),(0,A.isIntLike)(s)&&(s=(0,A.toNumber)(s)),e[s]}return e instanceof B.PyDict?e.get(t):null}function Ur(e,t,s,n){let r=this.normalizeSliceStep(n),i=t!=null,c=s!=null,o=i?(0,A.toNumber)(t):null,p=c?(0,A.toNumber)(s):null;return o===null&&(o=r<0?e-1:0),p===null&&(p=r<0?-1:e),i&&o<0&&(o=e+o),c&&p<0&&(p=e+p),{start:o,end:p,step:r}}function Yr(e,t,s,n){let r=this.computeSliceBounds(e,t,s,n),i=[];for(let c=r.start;r.step>0?c<r.end:c>r.end;c+=r.step)i.push(c);return i}function Gr(e){let t=e!=null?(0,A.toNumber)(e):1;if(t===0)throw new B.PyException("ValueError","slice step cannot be zero");return t}function jr(e,t,s){if(e&&e.__moduleScope__&&e.__moduleScope__.values.has(t))return e.__moduleScope__.values.get(t);if(e instanceof B.PyInstance){if(e.attributes.has(t))return e.attributes.get(t);let n=this.findClassAttribute(e.klass,t);return n instanceof B.PyFunction?(...r)=>this.callFunction(n,[e,...r],s):n}if(e instanceof B.PyClass)return this.findClassAttribute(e,t);if(e instanceof B.PyFile){let n=e[t];return typeof n=="function"?n.bind(e):n}if(e instanceof B.PyGenerator){let n=e[t];return typeof n=="function"?n.bind(e):n}if((0,A.isComplex)(e)){if(t==="real")return new Number(e.re);if(t==="imag")return new Number(e.im)}if(typeof e=="string"){if(t==="upper")return()=>e.toUpperCase();if(t==="join")return n=>(Array.isArray(n)?n:Array.from(n)).map(i=>(0,A.pyStr)(i)).join(e);if(t==="replace")return(n,r)=>e.replace(n,r);if(t==="format")return(...n)=>{let r={};if(n.length>0){let c=n[n.length-1];c&&c.__kwargs__&&(r=c.__kwargs__,n=n.slice(0,-1))}let i=0;return e.replace(/\{([^{}]*)\}/g,(c,o)=>{if(o===""){let p=n[i++];return(0,A.pyStr)(p)}if(/^\d+$/.test(o)){let p=n[parseInt(o,10)];return(0,A.pyStr)(p)}return o in r?(0,A.pyStr)(r[o]):""})};if(t==="count")return n=>e.split(n).length-1;if(t==="split")return(n=" ")=>e.split(n);if(t==="strip")return()=>e.trim();if(t==="lower")return()=>e.toLowerCase();if(t==="startswith")return n=>e.startsWith(n);if(t==="endswith")return n=>e.endsWith(n)}if(Array.isArray(e)){if(t==="append")return n=>(e.push(n),null);if(t==="pop")return n=>n===void 0?e.pop():e.splice(n,1)[0];if(t==="extend")return n=>{let r=Array.isArray(n)?n:Array.from(n);return e.push(...r),null};if(t==="count")return n=>e.filter(r=>r===n).length;if(t==="index")return n=>e.indexOf(n);if(t==="sort")return(...n)=>{let r={};if(n.length>0){let p=n[n.length-1];p&&p.__kwargs__&&(r=p.__kwargs__,n=n.slice(0,-1))}let i=n.length>0?n[0]:null;"key"in r&&(i=r.key);let c="reverse"in r?!!r.reverse:!1,o=e.length;if(i){let p=[];for(let E=0;E<o;E++){let y=e[E],O=this.callFunction(i,[y],s);if(e.length!==o)throw new B.PyException("ValueError","list modified during sort");p.push({item:y,key:O})}if(p.sort((E,y)=>(0,A.isNumericLike)(E.key)&&(0,A.isNumericLike)(y.key)?(0,A.toNumber)(E.key)-(0,A.toNumber)(y.key):String(E.key).localeCompare(String(y.key))),e.length!==o)throw new B.PyException("ValueError","list modified during sort");e.length=0,e.push(...p.map(E=>E.item))}else if(e.every(p=>(0,A.isNumericLike)(p))){if(e.sort((p,E)=>(0,A.toNumber)(p)-(0,A.toNumber)(E)),e.length!==o)throw new B.PyException("ValueError","list modified during sort")}else if(e.sort(),e.length!==o)throw new B.PyException("ValueError","list modified during sort");return c&&e.reverse(),null}}if(e instanceof B.PyDict){if(t==="items")return()=>Array.from(e.entries()).map(([r,i])=>{let c=[r,i];return c.__tuple__=!0,c});let n=e[t];return typeof n=="function"?n.bind(e):n}if(e instanceof B.PySet){if(t==="add")return n=>(e.add(n),null);if(t==="update")return n=>{let r=Array.isArray(n)?n:Array.from(n);for(let i of r)e.add(i);return null};if(t==="remove")return n=>(e.delete(n),null)}return e&&typeof e=="object"&&e.__typeName__&&t==="__name__"?e.__typeName__:e&&e.__typeName__===void 0&&t==="__name__"?e.name:e[t]}function Vr(e,t,s){if(e&&e.__moduleScope__){e.__moduleScope__.values.set(t,s);return}if(e instanceof B.PyInstance){e.attributes.set(t,s);return}e[t]=s}function ss(e,t){if(e.attributes.has(t))return e.attributes.get(t);for(let s of e.bases){let n=ss(s,t);if(n!==void 0)return n}}});var is=x(_t=>{"use strict";Object.defineProperty(_t,"__esModule",{value:!0});_t.isTruthy=Wr;var Oe=X(),rs=Ee();function Wr(e,t){if(e==null)return!1;if(e instanceof Number)return e.valueOf()!==0;if(typeof e=="boolean")return e;if(typeof e=="number")return e!==0;if(typeof e=="bigint")return e!==0n;if(typeof e=="string"||Array.isArray(e))return e.length>0;if(e instanceof Oe.PyDict||e instanceof Oe.PySet)return e.size>0;if(e instanceof Oe.PyInstance){if(this.findClassAttribute(e.klass,"__bool__")!==void 0){let r=this.getAttribute(e,"__bool__",t),i=typeof r=="function"?r():r;if(typeof i!="boolean")throw new Oe.PyException("TypeError","__bool__ should return bool");return i}if(this.findClassAttribute(e.klass,"__len__")!==void 0){let r=this.getAttribute(e,"__len__",t),i=typeof r=="function"?r():r;if(!(0,rs.isNumericLike)(i))throw new Oe.PyException("TypeError","__len__ should return int");return(0,rs.toNumber)(i)!==0}}return!0}});var os=x(he=>{"use strict";var Kr=he&&he.__createBinding||(Object.create?(function(e,t,s,n){n===void 0&&(n=s);var r=Object.getOwnPropertyDescriptor(t,s);(!r||("get"in r?!t.__esModule:r.writable||r.configurable))&&(r={enumerable:!0,get:function(){return t[s]}}),Object.defineProperty(e,n,r)}):(function(e,t,s,n){n===void 0&&(n=s),e[n]=t[s]})),qr=he&&he.__exportStar||function(e,t){for(var s in e)s!=="default"&&!Object.prototype.hasOwnProperty.call(t,s)&&Kr(t,e,s)};Object.defineProperty(he,"__esModule",{value:!0});he.VirtualMachine=void 0;var $r=Gt(),be=Vt(),ce=zt(),Hr=Xt(),Ke=Zt(),Ae=es(),qe=ts(),ue=ns(),zr=is(),At=class{constructor(t=[process.cwd()]){this.moduleCache=new Map,this.execute=ce.execute,this.executeFrame=ce.executeFrame,this.installBuiltins=$r.installBuiltins,this.importModule=Ke.importModule,this.createAsyncioModule=Ke.createAsyncioModule,this.loadModuleFromFile=Ke.loadModuleFromFile,this.resolveModulePath=Ke.resolveModulePath,this.executeBlock=ce.executeBlock,this.iterableToArray=ce.iterableToArray,this.matchValueEquals=ce.matchValueEquals,this.matchPattern=ce.matchPattern,this.applyBindings=ce.applyBindings,this.applyCompare=ce.applyCompare,this.executeBlockGenerator=ce.executeBlockGenerator,this.executeStatementGenerator=ce.executeStatementGenerator,this.evaluateExpressionGenerator=Hr.evaluateExpressionGenerator,this.executeStatement=qe.executeStatement,this.assignTarget=qe.assignTarget,this.toIterableArray=qe.toIterableArray,this.deleteTarget=qe.deleteTarget,this.evaluateExpression=Ae.evaluateExpression,this.evaluateExpressionString=Ae.evaluateExpressionString,this.executeExpressionInline=Ae.executeExpressionInline,this.applyFormatSpec=Ae.applyFormatSpec,this.splitFormatSpec=Ae.splitFormatSpec,this.applyWidth=Ae.applyWidth,this.contains=Ae.contains,this.isTruthy=zr.isTruthy,this.applyBinary=ue.applyBinary,this.applyInPlaceBinary=ue.applyInPlaceBinary,this.formatPercent=ue.formatPercent,this.getSubscript=ue.getSubscript,this.computeSliceBounds=ue.computeSliceBounds,this.computeSliceIndices=ue.computeSliceIndices,this.normalizeSliceStep=ue.normalizeSliceStep,this.getAttribute=ue.getAttribute,this.setAttribute=ue.setAttribute,this.findClassAttribute=ue.findClassAttribute,this.callFunction=be.callFunction,this.containsYield=be.containsYield,this.evaluateComprehension=be.evaluateComprehension,this.generateComprehension=be.generateComprehension,this.expressionHasYield=be.expressionHasYield,this.moduleSearchPaths=t}};he.VirtualMachine=At;qr(X(),he)});var Nt=x(Te=>{"use strict";var Xr=Te&&Te.__createBinding||(Object.create?(function(e,t,s,n){n===void 0&&(n=s);var r=Object.getOwnPropertyDescriptor(t,s);(!r||("get"in r?!t.__esModule:r.writable||r.configurable))&&(r={enumerable:!0,get:function(){return t[s]}}),Object.defineProperty(e,n,r)}):(function(e,t,s,n){n===void 0&&(n=s),e[n]=t[s]})),Jr=Te&&Te.__exportStar||function(e,t){for(var s in e)s!=="default"&&!Object.prototype.hasOwnProperty.call(t,s)&&Xr(t,e,s)};Object.defineProperty(Te,"__esModule",{value:!0});Te.VirtualMachine=void 0;var Qr=os();Object.defineProperty(Te,"VirtualMachine",{enumerable:!0,get:function(){return Qr.VirtualMachine}});Jr(X(),Te)});var hs=x(Z=>{"use strict";var ps=Z&&Z.__createBinding||(Object.create?(function(e,t,s,n){n===void 0&&(n=s);var r=Object.getOwnPropertyDescriptor(t,s);(!r||("get"in r?!t.__esModule:r.writable||r.configurable))&&(r={enumerable:!0,get:function(){return t[s]}}),Object.defineProperty(e,n,r)}):(function(e,t,s,n){n===void 0&&(n=s),e[n]=t[s]})),Zr=Z&&Z.__setModuleDefault||(Object.create?(function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}):function(e,t){e.default=t}),ei=Z&&Z.__importStar||(function(){var e=function(t){return e=Object.getOwnPropertyNames||function(s){var n=[];for(var r in s)Object.prototype.hasOwnProperty.call(s,r)&&(n[n.length]=r);return n},e(t)};return function(t){if(t&&t.__esModule)return t;var s={};if(t!=null)for(var n=e(t),r=0;r<n.length;r++)n[r]!=="default"&&ps(s,t,n[r]);return Zr(s,t),s}})(),ti=Z&&Z.__exportStar||function(e,t){for(var s in e)s!=="default"&&!Object.prototype.hasOwnProperty.call(t,s)&&ps(t,e,s)};Object.defineProperty(Z,"__esModule",{value:!0});Z.PythonCompiler=void 0;var as=Ce(),cs=ve(),us=Yt(),ls=Nt(),si=ei(require("path")),mt=class{compile(t){let n=new as.Lexer(t).tokenize(),i=new cs.Parser(n).parse();return new us.Compiler().compile(i)}run(t){let s=this.compile(t);return new ls.VirtualMachine([process.cwd()]).execute(s)}runFile(t){let n=require("fs").readFileSync(t,"utf-8"),i=new as.Lexer(n).tokenize(),o=new cs.Parser(i).parse(),E=new us.Compiler().compile(o);return new ls.VirtualMachine([si.dirname(t),process.cwd()]).execute(E)}};Z.PythonCompiler=mt;ti(W(),Z)});var fs=x(le=>{"use strict";var ni=le&&le.__createBinding||(Object.create?(function(e,t,s,n){n===void 0&&(n=s);var r=Object.getOwnPropertyDescriptor(t,s);(!r||("get"in r?!t.__esModule:r.writable||r.configurable))&&(r={enumerable:!0,get:function(){return t[s]}}),Object.defineProperty(e,n,r)}):(function(e,t,s,n){n===void 0&&(n=s),e[n]=t[s]})),ri=le&&le.__setModuleDefault||(Object.create?(function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}):function(e,t){e.default=t}),ii=le&&le.__importStar||(function(){var e=function(t){return e=Object.getOwnPropertyNames||function(s){var n=[];for(var r in s)Object.prototype.hasOwnProperty.call(s,r)&&(n[n.length]=r);return n},e(t)};return function(t){if(t&&t.__esModule)return t;var s={};if(t!=null)for(var n=e(t),r=0;r<n.length;r++)n[r]!=="default"&&ni(s,t,n[r]);return ri(s,t),s}})();Object.defineProperty(le,"__esModule",{value:!0});le.Serializer=void 0;var Ts=ii(require("zlib")),kt=class{static serialize(t){let s=JSON.stringify(t,(n,r)=>typeof r=="bigint"?{__type:"bigint",value:r.toString()}:r);return Ts.gzipSync(s)}static deserialize(t){let s=Ts.gunzipSync(t).toString("utf-8");return JSON.parse(s,(n,r)=>r&&typeof r=="object"&&r.__type==="bigint"?BigInt(r.value):r)}};le.Serializer=kt});var oi=exports&&exports.__createBinding||(Object.create?(function(e,t,s,n){n===void 0&&(n=s);var r=Object.getOwnPropertyDescriptor(t,s);(!r||("get"in r?!t.__esModule:r.writable||r.configurable))&&(r={enumerable:!0,get:function(){return t[s]}}),Object.defineProperty(e,n,r)}):(function(e,t,s,n){n===void 0&&(n=s),e[n]=t[s]})),ai=exports&&exports.__setModuleDefault||(Object.create?(function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}):function(e,t){e.default=t}),ci=exports&&exports.__importStar||(function(){var e=function(t){return e=Object.getOwnPropertyNames||function(s){var n=[];for(var r in s)Object.prototype.hasOwnProperty.call(s,r)&&(n[n.length]=r);return n},e(t)};return function(t){if(t&&t.__esModule)return t;var s={};if(t!=null)for(var n=e(t),r=0;r<n.length;r++)n[r]!=="default"&&oi(s,t,n[r]);return ai(s,t),s}})();Object.defineProperty(exports,"__esModule",{value:!0});exports.PythonCompiler=void 0;var ds=hs();Object.defineProperty(exports,"PythonCompiler",{enumerable:!0,get:function(){return ds.PythonCompiler}});var Se=ci(require("fs")),ys=fs(),ui=Nt();function li(){let e=process.argv.slice(2);e.length===0&&(console.error("Usage:"),console.error(" python-compiler-ts <file.py> Run a Python source file directly"),console.error(" python-compiler-ts compile <file.py> Compile Python source to bytecode"),console.error(" python-compiler-ts run <file.json> Run compiled bytecode"),process.exit(1));let t=e[0],s=new ds.PythonCompiler;if(t==="compile"){let r=e[1];r||(console.error("Error: No input file specified for compilation"),process.exit(1));let i=e[2]||r+"c";Se.existsSync(r)||(console.error(`Error: File '${r}' not found`),process.exit(1));try{let c=Se.readFileSync(r,"utf-8"),o=s.compile(c),p=ys.Serializer.serialize(o);Se.writeFileSync(i,p),console.log(`Compiled '${r}' to '${i}'`)}catch(c){console.error("Compilation Error:",c instanceof Error?c.message:c),process.exit(1)}return}if(t==="run"){let r=e[1];r||(console.error("Error: No input file specified for running"),process.exit(1)),Se.existsSync(r)||(console.error(`Error: File '${r}' not found`),process.exit(1));try{let i=Se.readFileSync(r),c=ys.Serializer.deserialize(i);new ui.VirtualMachine([process.cwd()]).execute(c)}catch(i){console.error("Runtime Error:",i instanceof Error?i.message:i),process.exit(1)}return}let n=e[0];Se.existsSync(n)||(console.error(`Error: File '${n}' not found`),process.exit(1));try{s.runFile(n)}catch(r){console.error("Error:",r instanceof Error?r.message:r),process.exit(1)}}require.main===module&&li();
@@ -1 +1 @@
1
- {"version":3,"file":"execution.d.ts","sourceRoot":"","sources":["../../src/vm/execution.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,MAAM,CAAC;AAC3C,OAAO,EAAE,QAAQ,EAAkC,MAAM,UAAU,CAAC;AACpE,OAAO,EAAE,OAAO,EAAsE,KAAK,EAAE,MAAM,iBAAiB,CAAC;AAErH,wBAAgB,OAAO,CAAC,IAAI,EAAE,cAAc,EAAE,QAAQ,EAAE,QAAQ,GAAG,OAAO,CAMzE;AAED,wBAAgB,YAAY,CAAC,IAAI,EAAE,cAAc,EAAE,KAAK,EAAE,KAAK,GAAG,OAAO,CA+zBxE;AAED,OAAO,EACL,YAAY,EACZ,eAAe,EACf,gBAAgB,EAChB,aAAa,EACb,YAAY,EACZ,kBAAkB,EAClB,gBAAgB,EAChB,qBAAqB,EACrB,yBAAyB,EACzB,YAAY,GACb,MAAM,qBAAqB,CAAC"}
1
+ {"version":3,"file":"execution.d.ts","sourceRoot":"","sources":["../../src/vm/execution.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,MAAM,CAAC;AAC3C,OAAO,EAAE,QAAQ,EAAkC,MAAM,UAAU,CAAC;AACpE,OAAO,EAAE,OAAO,EAAsE,KAAK,EAAE,MAAM,iBAAiB,CAAC;AAErH,wBAAgB,OAAO,CAAC,IAAI,EAAE,cAAc,EAAE,QAAQ,EAAE,QAAQ,GAAG,OAAO,CAMzE;AAED,wBAAgB,YAAY,CAAC,IAAI,EAAE,cAAc,EAAE,KAAK,EAAE,KAAK,GAAG,OAAO,CAg1BxE;AAED,OAAO,EACL,YAAY,EACZ,eAAe,EACf,gBAAgB,EAChB,aAAa,EACb,YAAY,EACZ,kBAAkB,EAClB,gBAAgB,EAChB,qBAAqB,EACrB,yBAAyB,EACzB,YAAY,GACb,MAAM,qBAAqB,CAAC"}