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AE,SAAW,UAAY,EAAE,SAAQ,KAAK,QAE1E,EAAW,GAAG,MAC7B,CAvGA,QAAQ,0BACR,QAAQ,2BACR,QAAQ,oBACR,QAAQ,wBACR,QAAQ,wBACR,QAAQ,kCACR,QAAQ,+BACR,QAAQ,gCACR,QAAQ,6BACR,QAAQ,4BACR,QAAQ,gCACR,QAAQ,8BACR,QAAQ,+BACR,QAAQ,8BACR,QAAQ,+BACR,QAAQ,6BACR,QAAQ,gCACR,QAAQ,oCACR,QAAQ,6BACR,QAAQ,gCACR,QAAQ,gCACR,QAAQ,oCACR,QAAQ,gCACR,QAAQ,gCACR,QAAQ,mCACR,QAAQ,+BACR,QAAQ,kCACR,QAAQ,iCACR,QAAQ,qCACR,QAAQ,+BACR,QAAQ,gCACR,QAAQ,8BACR,QAAQ","file":"/npm/ts2c@3.0.0/ts2c.js","sourceRoot":"","sourcesContent":["/**\n * Minified by jsDelivr using Terser v5.39.0.\n * Original file: /npm/ts2c@3.0.0/ts2c.js\n *\n * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files\n */\n","\"use strict\";\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.transpile = transpile;\nconst parser_1 = require(\"./src/parser\");\nconst symbols_1 = require(\"./src/symbols\");\nconst typehelper_1 = require(\"./src/types/typehelper\");\nconst memory_1 = require(\"./src/memory\");\nconst ast_1 = require(\"./src/ast\");\nconst program_1 = require(\"./src/program\");\nconst common_1 = require(\"./src/common\");\nconst header_1 = require(\"./src/header\");\n// these imports are here only because it is necessary to run decorators\nrequire(\"./src/nodes/statements\");\nrequire(\"./src/nodes/expressions\");\nrequire(\"./src/nodes/call\");\nrequire(\"./src/nodes/literals\");\nrequire(\"./src/nodes/function\");\nrequire(\"./src/standard/global/parseInt\");\nrequire(\"./src/standard/global/isNaN\");\nrequire(\"./src/standard/array/forEach\");\nrequire(\"./src/standard/array/push\");\nrequire(\"./src/standard/array/pop\");\nrequire(\"./src/standard/array/unshift\");\nrequire(\"./src/standard/array/shift\");\nrequire(\"./src/standard/array/splice\");\nrequire(\"./src/standard/array/slice\");\nrequire(\"./src/standard/array/concat\");\nrequire(\"./src/standard/array/join\");\nrequire(\"./src/standard/array/indexOf\");\nrequire(\"./src/standard/array/lastIndexOf\");\nrequire(\"./src/standard/array/sort\");\nrequire(\"./src/standard/array/reverse\");\nrequire(\"./src/standard/string/search\");\nrequire(\"./src/standard/string/charCodeAt\");\nrequire(\"./src/standard/string/charAt\");\nrequire(\"./src/standard/string/concat\");\nrequire(\"./src/standard/string/substring\");\nrequire(\"./src/standard/string/slice\");\nrequire(\"./src/standard/string/toString\");\nrequire(\"./src/standard/string/indexOf\");\nrequire(\"./src/standard/string/lastIndexOf\");\nrequire(\"./src/standard/string/match\");\nrequire(\"./src/standard/number/number\");\nrequire(\"./src/standard/console/log\");\nrequire(\"./src/standard/typedarray/uint8array\");\nfunction transpile(sourceCode, options) {\n    const entryFilePath = (options === null || options === void 0 ? void 0 : options.fileName) || \"__main__.ts\";\n    const endOfPathPos = entryFilePath.lastIndexOf('/');\n    let baseDir = '';\n    let commonHeaderPath = 'common.h';\n    if (endOfPathPos > -1) {\n        baseDir = entryFilePath.substring(0, endOfPathPos);\n        commonHeaderPath = baseDir + '/common.h';\n    }\n    const performance = typeof process === 'object' ? require(\"node:perf_hooks\").performance : Date;\n    const startParse = performance.now();\n    var parseResult = (0, parser_1.parse)(entryFilePath, sourceCode, { useColors: options === null || options === void 0 ? void 0 : options.terminal });\n    console.log('parse:', performance.now() - startParse);\n    if (parseResult.fatalErrors.length > 0) {\n        if ((options === null || options === void 0 ? void 0 : options.terminal) && typeof process === 'object')\n            process.exit(1);\n        else {\n            const transpiledCode = '/*\\n' + parseResult.fatalErrors.join('\\n') + '\\n*/';\n            if (options === null || options === void 0 ? void 0 : options.multiFiles)\n                return [{ fileName: parseResult.rootNode.fileName.replace(/(\\.ts|\\.js)$/, '.c'), source: transpiledCode }];\n            else\n                return transpiledCode;\n        }\n    }\n    const startProcessAst = performance.now();\n    const symbolsHelper = new symbols_1.SymbolsHelper();\n    const { rootNodes, nodes } = (0, ast_1.collectSymbolsAndTransformAst)(parseResult.rootNode, entryFilePath, symbolsHelper);\n    nodes.sort((a, b) => b.rootId - a.rootId || a.start - b.start);\n    console.log('process ast:', performance.now() - startProcessAst);\n    const startInferTypes = performance.now();\n    const typeHelper = new typehelper_1.TypeHelper(symbolsHelper);\n    typeHelper.inferTypes(nodes);\n    console.log('infer types:', performance.now() - startInferTypes);\n    const startEscapeAnalysis = performance.now();\n    const memoryManager = new memory_1.MemoryManager(typeHelper, symbolsHelper, typeHelper.standardCallHelper);\n    memoryManager.scheduleNodeDisposals(nodes);\n    console.log('escape analysis:', performance.now() - startEscapeAnalysis);\n    const transpiled = [];\n    let commonFlags = null;\n    if (rootNodes.filter(n => !n.fileName.endsWith('.d.ts')).length > 1)\n        commonFlags = new program_1.HeaderFlags();\n    for (const rootNode of rootNodes) {\n        if (rootNode.fileName.endsWith('.d.ts'))\n            continue;\n        const startEmit = performance.now();\n        const program = new program_1.CProgram(rootNode, commonFlags, symbolsHelper, typeHelper, typeHelper.standardCallHelper, memoryManager);\n        const transpiledProgramCode = program[\"resolve\"]();\n        const transpiledFileName = rootNode.fileName.replace(/(\\.ts|\\.js)$/, '.c');\n        console.log('emit ' + transpiledFileName + ':', performance.now() - startEmit);\n        if (symbolsHelper.exportedSymbols[rootNode.id]) {\n            const startEmitHeader = performance.now();\n            const header = new header_1.CHeader(program, rootNode, symbolsHelper, typeHelper);\n            const transpiledHeaderCode = header[\"resolve\"]();\n            const transpiledHeaderFileName = rootNode.fileName.replace(/(\\.ts|\\.js)$/, '.h');\n            console.log('emit ' + transpiledHeaderFileName + ':', performance.now() - startEmitHeader);\n            transpiled.push({ fileName: transpiledHeaderFileName, source: transpiledHeaderCode });\n        }\n        transpiled.push({ fileName: transpiledFileName, source: transpiledProgramCode });\n    }\n    if (commonFlags !== null) {\n        const startEmitCommonHeader = performance.now();\n        transpiled.unshift({ fileName: commonHeaderPath, source: new common_1.CCommon(commonFlags, true)[\"resolve\"]() });\n        console.log('emit common.h:', performance.now() - startEmitCommonHeader);\n    }\n    if (options === null || options === void 0 ? void 0 : options.multiFiles)\n        return transpiled;\n    else if (transpiled.length > 1)\n        return transpiled.map(t => '/* File: ' + t.fileName + ' */\\n\\n' + t.source).join('\\n\\n');\n    else\n        return transpiled[0].source;\n}\n"]}