@harmoniclabs/pebble 0.1.0-dev5 → 0.1.0-dev7
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/dist/IR/IRHash.d.ts +3 -3
- package/dist/IR/IRHash.js +47 -52
- package/dist/IR/IRNodes/IRApp.d.ts +12 -8
- package/dist/IR/IRNodes/IRApp.js +34 -20
- package/dist/IR/IRNodes/IRCase.d.ts +11 -7
- package/dist/IR/IRNodes/IRCase.js +33 -32
- package/dist/IR/IRNodes/IRConst.d.ts +7 -5
- package/dist/IR/IRNodes/IRConst.js +23 -13
- package/dist/IR/IRNodes/IRConstr.d.ts +11 -7
- package/dist/IR/IRNodes/IRConstr.js +34 -37
- package/dist/IR/IRNodes/IRDelayed.d.ts +12 -9
- package/dist/IR/IRNodes/IRDelayed.js +22 -18
- package/dist/IR/IRNodes/IRError.d.ts +9 -6
- package/dist/IR/IRNodes/IRError.js +12 -5
- package/dist/IR/IRNodes/IRForced.d.ts +9 -6
- package/dist/IR/IRNodes/IRForced.js +22 -18
- package/dist/IR/IRNodes/IRFunc.d.ts +14 -10
- package/dist/IR/IRNodes/IRFunc.js +35 -38
- package/dist/IR/IRNodes/IRHoisted.d.ts +16 -9
- package/dist/IR/IRNodes/IRHoisted.js +36 -18
- package/dist/IR/IRNodes/IRLetted.d.ts +14 -34
- package/dist/IR/IRNodes/IRLetted.js +65 -297
- package/dist/IR/IRNodes/IRNative/IRNativeTag.d.ts +3 -3
- package/dist/IR/IRNodes/IRNative/IRNativeTag.js +4 -4
- package/dist/IR/IRNodes/IRNative/index.d.ts +10 -8
- package/dist/IR/IRNodes/IRNative/index.js +56 -18
- package/dist/IR/IRNodes/IRNative/isForcedNative.d.ts +2 -0
- package/dist/IR/IRNodes/IRNative/isForcedNative.js +1 -1
- package/dist/IR/IRNodes/IRRecursive.d.ts +18 -10
- package/dist/IR/IRNodes/IRRecursive.js +36 -44
- package/dist/IR/IRNodes/IRSelfCall.d.ts +10 -24
- package/dist/IR/IRNodes/IRSelfCall.js +25 -87
- package/dist/IR/IRNodes/IRVar.d.ts +11 -19
- package/dist/IR/IRNodes/IRVar.js +26 -54
- package/dist/IR/IRNodes/utils/dependsByDbns.d.ts +1 -1
- package/dist/IR/IRNodes/utils/dependsByDbns.js +5 -11
- package/dist/IR/IRNodes/utils/hashVarSym.d.ts +1 -0
- package/dist/IR/IRNodes/utils/hashVarSym.js +37 -0
- package/dist/IR/IRNodes/utils/makeArrayLikeProxy.d.ts +2 -1
- package/dist/IR/IRTerm.d.ts +7 -0
- package/dist/IR/toUPLC/CompilerOptions.d.ts +5 -0
- package/dist/IR/toUPLC/CompilerOptions.js +10 -1
- package/dist/IR/toUPLC/_internal/_modifyChildFromTo.js +3 -0
- package/dist/IR/toUPLC/_internal/findAll.js +2 -73
- package/dist/IR/toUPLC/_internal/getDebruijnInTerm.js +7 -34
- package/dist/IR/toUPLC/_internal/iterTree.js +3 -17
- package/dist/IR/toUPLC/common_hoisted.d.ts +2 -0
- package/dist/IR/toUPLC/common_hoisted.js +4 -0
- package/dist/IR/toUPLC/compileIRToUPLC.d.ts +1 -1
- package/dist/IR/toUPLC/compileIRToUPLC.js +91 -14
- package/dist/IR/toUPLC/ctx/ToUplcCtx.d.ts +16 -0
- package/dist/IR/toUPLC/ctx/ToUplcCtx.js +67 -0
- package/dist/IR/toUPLC/subRoutines/_comptimeDropN.d.ts +8 -0
- package/dist/IR/toUPLC/subRoutines/_comptimeDropN.js +95 -0
- package/dist/IR/toUPLC/subRoutines/handleHoistedAndReturnRoot/index.js +7 -54
- package/dist/IR/toUPLC/subRoutines/handleLetted/groupByScope.d.ts +6 -13
- package/dist/IR/toUPLC/subRoutines/handleLetted/groupByScope.js +65 -71
- package/dist/IR/toUPLC/subRoutines/handleLetted/index.js +44 -170
- package/dist/IR/toUPLC/subRoutines/handleRecursiveTerms.js +7 -3
- package/dist/IR/toUPLC/subRoutines/hoistForcedNatives.js +3 -2
- package/dist/IR/toUPLC/subRoutines/inlineSingleUseAndReturnRoot/InlineSingleUseCtx.d.ts +22 -0
- package/dist/IR/toUPLC/subRoutines/inlineSingleUseAndReturnRoot/InlineSingleUseCtx.js +59 -0
- package/dist/IR/toUPLC/subRoutines/inlineSingleUseAndReturnRoot/inlineSingleUseAndReturnRoot.d.ts +0 -0
- package/dist/IR/toUPLC/subRoutines/inlineSingleUseAndReturnRoot/inlineSingleUseAndReturnRoot.js +217 -0
- package/dist/IR/toUPLC/subRoutines/markRecursiveHoistsAsForced.js +12 -49
- package/dist/IR/toUPLC/subRoutines/performUplcOptimizationsAndReturnRoot/expandFuncsAndReturnRoot.d.ts +1 -1
- package/dist/IR/toUPLC/subRoutines/performUplcOptimizationsAndReturnRoot/expandFuncsAndReturnRoot.js +11 -14
- package/dist/IR/toUPLC/subRoutines/performUplcOptimizationsAndReturnRoot/{index.d.ts → performUplcOptimizationsAndReturnRoot.d.ts} +0 -2
- package/dist/IR/toUPLC/subRoutines/performUplcOptimizationsAndReturnRoot/performUplcOptimizationsAndReturnRoot.js +151 -0
- package/dist/IR/toUPLC/subRoutines/removeUnusuedVarsAndReturnRoot/RemoveUnusedVarsCtx.d.ts +11 -0
- package/dist/IR/toUPLC/subRoutines/removeUnusuedVarsAndReturnRoot/RemoveUnusedVarsCtx.js +46 -0
- package/dist/IR/toUPLC/subRoutines/removeUnusuedVarsAndReturnRoot/removeUnusuedVarsAndReturnRoot.d.ts +2 -0
- package/dist/IR/toUPLC/subRoutines/removeUnusuedVarsAndReturnRoot/removeUnusuedVarsAndReturnRoot.js +80 -0
- package/dist/IR/toUPLC/subRoutines/replaceHoistedWithLetted.js +18 -11
- package/dist/IR/toUPLC/subRoutines/replaceNatives/nativeToIR.d.ts +45 -0
- package/dist/IR/toUPLC/subRoutines/replaceNatives/nativeToIR.js +277 -478
- package/dist/IR/toUPLC/subRoutines/rewriteNativesAppliedToConstantsAndReturnRoot.d.ts +2 -0
- package/dist/IR/toUPLC/subRoutines/rewriteNativesAppliedToConstantsAndReturnRoot.js +85 -0
- package/dist/IR/toUPLC/subRoutines/sanifyTree.js +1 -0
- package/dist/IR/toUPLC/utils/getApplicationTerms.d.ts +6 -0
- package/dist/IR/toUPLC/utils/getApplicationTerms.js +37 -0
- package/dist/IR/tree_utils/_ir_lazyChooseList.d.ts +2 -2
- package/dist/IR/tree_utils/_ir_lazyChooseList.js +4 -2
- package/dist/IR/tree_utils/_ir_lazyIfThenElse.d.ts +1 -1
- package/dist/IR/tree_utils/_ir_lazyIfThenElse.js +4 -2
- package/dist/IR/tree_utils/_ir_let.d.ts +2 -1
- package/dist/IR/tree_utils/_ir_let.js +6 -2
- package/dist/IR/utils/isClosedIRTerm.d.ts +1 -0
- package/dist/IR/utils/isClosedIRTerm.js +40 -26
- package/dist/IR/utils/positiveIntAsBytes.d.ts +1 -0
- package/dist/IR/utils/positiveIntAsBytes.js +4 -4
- package/dist/IR/utils/showIR.d.ts +10 -21
- package/dist/IR/utils/showIR.js +66 -64
- package/dist/ast/nodes/common/Identifier.d.ts +1 -0
- package/dist/ast/nodes/common/Identifier.js +3 -0
- package/dist/ast/nodes/expr/CaseExpr.d.ts +5 -5
- package/dist/ast/nodes/expr/ElemAccessExpr.d.ts +2 -2
- package/dist/ast/nodes/expr/ParentesizedExpr.d.ts +1 -1
- package/dist/ast/nodes/expr/PebbleExpr.d.ts +2 -1
- package/dist/ast/nodes/expr/PropAccessExpr.d.ts +3 -3
- package/dist/ast/nodes/expr/TernaryExpr.d.ts +3 -3
- package/dist/ast/nodes/expr/TypeConversionExpr.d.ts +2 -1
- package/dist/ast/nodes/expr/TypeConversionExpr.js +2 -0
- package/dist/ast/nodes/expr/binary/BinaryExpr.d.ts +42 -42
- package/dist/ast/nodes/expr/functions/CallExpr.d.ts +1 -1
- package/dist/ast/nodes/expr/functions/FuncExpr.d.ts +2 -1
- package/dist/ast/nodes/expr/functions/FuncExpr.js +6 -0
- package/dist/ast/nodes/expr/litteral/LitContextExpr.d.ts +6 -0
- package/dist/ast/nodes/expr/litteral/LitContextExpr.js +6 -0
- package/dist/ast/nodes/expr/litteral/LitFailExpr.d.ts +6 -0
- package/dist/ast/nodes/expr/litteral/LitFailExpr.js +6 -0
- package/dist/ast/nodes/expr/litteral/LitteralExpr.d.ts +3 -1
- package/dist/ast/nodes/expr/litteral/LitteralExpr.js +5 -1
- package/dist/ast/nodes/statements/AssertStmt.d.ts +2 -2
- package/dist/ast/nodes/statements/AssignmentStmt.d.ts +1 -1
- package/dist/ast/nodes/statements/BlockStmt.d.ts +1 -1
- package/dist/ast/nodes/statements/FailStmt.d.ts +1 -1
- package/dist/ast/nodes/statements/ForOfStmt.d.ts +4 -2
- package/dist/ast/nodes/statements/ForOfStmt.js +6 -0
- package/dist/ast/nodes/statements/ForStmt.d.ts +6 -4
- package/dist/ast/nodes/statements/ForStmt.js +6 -0
- package/dist/ast/nodes/statements/IfStmt.d.ts +8 -5
- package/dist/ast/nodes/statements/IfStmt.js +13 -0
- package/dist/ast/nodes/statements/MatchStmt.d.ts +13 -4
- package/dist/ast/nodes/statements/MatchStmt.js +22 -1
- package/dist/ast/nodes/statements/PebbleStmt.d.ts +2 -1
- package/dist/ast/nodes/statements/PebbleStmt.js +3 -1
- package/dist/ast/nodes/statements/ReturnStmt.d.ts +1 -1
- package/dist/ast/nodes/statements/WhileStmt.d.ts +4 -2
- package/dist/ast/nodes/statements/WhileStmt.js +6 -0
- package/dist/ast/nodes/statements/declarations/ContractDecl.d.ts +17 -0
- package/dist/ast/nodes/statements/declarations/ContractDecl.js +22 -0
- package/dist/ast/nodes/statements/declarations/VarDecl/ArrayLikeDeconstr.d.ts +1 -1
- package/dist/ast/nodes/statements/declarations/VarDecl/HasInit.d.ts +1 -1
- package/dist/ast/nodes/statements/declarations/VarDecl/NamedDeconstructVarDecl.d.ts +1 -1
- package/dist/ast/nodes/statements/declarations/VarDecl/SimpleVarDecl.d.ts +2 -1
- package/dist/ast/nodes/statements/declarations/VarDecl/SimpleVarDecl.js +6 -0
- package/dist/ast/nodes/statements/declarations/VarDecl/SingleDeconstructVarDecl.d.ts +1 -1
- package/dist/compiler/AstCompiler/AstCompiler.d.ts +7 -2
- package/dist/compiler/AstCompiler/AstCompiler.js +129 -25
- package/dist/compiler/AstCompiler/internal/_deriveContractBody/_deriveContractBody.d.ts +10 -0
- package/dist/compiler/AstCompiler/internal/_deriveContractBody/_deriveContractBody.js +777 -0
- package/dist/compiler/AstCompiler/internal/exprs/_compileBinaryExpr.js +1 -1
- package/dist/compiler/AstCompiler/internal/exprs/_compileExpr.js +5 -1
- package/dist/compiler/AstCompiler/internal/exprs/_compileFuncExpr.js +7 -4
- package/dist/compiler/AstCompiler/internal/exprs/_compileLitteralExpr.js +8 -2
- package/dist/compiler/AstCompiler/internal/exprs/_compilePropAccessExpr.js +1 -1
- package/dist/compiler/AstCompiler/internal/exprs/_compileTypeConversionExpr.js +2 -1
- package/dist/compiler/AstCompiler/internal/exprs/_compileUnaryPrefixExpr.js +1 -1
- package/dist/compiler/AstCompiler/internal/exprs/_compileVarAccessExpr.js +3 -1
- package/dist/compiler/AstCompiler/internal/statements/_compileAssignmentStmt.js +8 -8
- package/dist/compiler/AstCompiler/internal/statements/_compileMatchStmt.d.ts +2 -2
- package/dist/compiler/AstCompiler/internal/statements/_compileMatchStmt.js +48 -24
- package/dist/compiler/AstCompiler/internal/statements/_compileStatement.js +4 -1
- package/dist/compiler/AstCompiler/internal/statements/_compileVarStmt.d.ts +2 -1
- package/dist/compiler/AstCompiler/internal/statements/_compileVarStmt.js +4 -3
- package/dist/compiler/AstCompiler/internal/types/_compileDataEncodedConcreteType.js +1 -1
- package/dist/compiler/AstCompiler/internal/types/_compileSopEncodedConcreteType.js +4 -1
- package/dist/compiler/AstCompiler/scope/AstScope.d.ts +1 -0
- package/dist/compiler/AstCompiler/scope/AstScope.js +9 -3
- package/dist/compiler/AstCompiler/utils/getPropAccessReturnType.js +6 -4
- package/dist/compiler/Compiler.js +7 -1
- package/dist/compiler/TirCompiler/compileTirProgram.js +4 -1
- package/dist/compiler/TirCompiler/expressify/ExpressifyCtx.d.ts +17 -5
- package/dist/compiler/TirCompiler/expressify/ExpressifyCtx.js +79 -49
- package/dist/compiler/TirCompiler/expressify/determineReassignedVariablesAndReturn.js +13 -2
- package/dist/compiler/TirCompiler/expressify/expressify.d.ts +2 -1
- package/dist/compiler/TirCompiler/expressify/expressify.js +102 -41
- package/dist/compiler/TirCompiler/expressify/expressifyForStmt.d.ts +2 -1
- package/dist/compiler/TirCompiler/expressify/expressifyForStmt.js +77 -12
- package/dist/compiler/TirCompiler/expressify/expressifyIfBranch.js +1 -1
- package/dist/compiler/TirCompiler/expressify/expressifyVarAssignmentStmt.d.ts +1 -2
- package/dist/compiler/TirCompiler/expressify/expressifyVarAssignmentStmt.js +16 -9
- package/dist/compiler/TirCompiler/expressify/expressifyVarDecl.js +6 -8
- package/dist/compiler/TirCompiler/expressify/expressifyVars.js +146 -13
- package/dist/compiler/TirCompiler/expressify/flattenSopNamedDeconstructInplace_addTopDestructToCtx_getNestedDeconstruct.js +1 -0
- package/dist/compiler/internalVar.d.ts +1 -1
- package/dist/compiler/internalVar.js +31 -24
- package/dist/compiler/io/CompilerIoApi.d.ts +1 -1
- package/dist/compiler/io/IOutputStream.d.ts +1 -0
- package/dist/compiler/io/IOutputStream.js +18 -3
- package/dist/compiler/path/getAbsolutePath.js +4 -6
- package/dist/compiler/tir/expressions/ITirExpr.d.ts +2 -0
- package/dist/compiler/tir/expressions/TirAssertAndContinueExpr.d.ts +4 -2
- package/dist/compiler/tir/expressions/TirAssertAndContinueExpr.js +16 -2
- package/dist/compiler/tir/expressions/TirCallExpr.d.ts +3 -1
- package/dist/compiler/tir/expressions/TirCallExpr.js +16 -1
- package/dist/compiler/tir/expressions/TirCaseExpr.d.ts +6 -1
- package/dist/compiler/tir/expressions/TirCaseExpr.js +105 -60
- package/dist/compiler/tir/expressions/TirElemAccessExpr.d.ts +3 -1
- package/dist/compiler/tir/expressions/TirElemAccessExpr.js +9 -1
- package/dist/compiler/tir/expressions/TirFailExpr.d.ts +3 -1
- package/dist/compiler/tir/expressions/TirFailExpr.js +9 -1
- package/dist/compiler/tir/expressions/TirFromDataExpr.d.ts +3 -2
- package/dist/compiler/tir/expressions/TirFromDataExpr.js +85 -56
- package/dist/compiler/tir/expressions/TirFuncExpr.d.ts +4 -10
- package/dist/compiler/tir/expressions/TirFuncExpr.js +30 -13
- package/dist/compiler/tir/expressions/TirHoistedExpr.d.ts +3 -1
- package/dist/compiler/tir/expressions/TirHoistedExpr.js +8 -0
- package/dist/compiler/tir/expressions/TirInlineClosedIR.d.ts +4 -1
- package/dist/compiler/tir/expressions/TirInlineClosedIR.js +8 -0
- package/dist/compiler/tir/expressions/TirLettedExpr.d.ts +6 -3
- package/dist/compiler/tir/expressions/TirLettedExpr.js +20 -7
- package/dist/compiler/tir/expressions/TirNativeFunc.d.ts +9 -5
- package/dist/compiler/tir/expressions/TirNativeFunc.js +58 -22
- package/dist/compiler/tir/expressions/TirParentesizedExpr.d.ts +3 -1
- package/dist/compiler/tir/expressions/TirParentesizedExpr.js +6 -0
- package/dist/compiler/tir/expressions/TirPropAccessExpr.d.ts +3 -1
- package/dist/compiler/tir/expressions/TirPropAccessExpr.js +9 -1
- package/dist/compiler/tir/expressions/TirTernaryExpr.d.ts +3 -1
- package/dist/compiler/tir/expressions/TirTernaryExpr.js +16 -5
- package/dist/compiler/tir/expressions/TirToDataExpr.d.ts +3 -1
- package/dist/compiler/tir/expressions/TirToDataExpr.js +56 -25
- package/dist/compiler/tir/expressions/TirTraceIfFalseExpr.d.ts +3 -1
- package/dist/compiler/tir/expressions/TirTraceIfFalseExpr.js +21 -4
- package/dist/compiler/tir/expressions/TirTypeConversionExpr.d.ts +3 -1
- package/dist/compiler/tir/expressions/TirTypeConversionExpr.js +9 -1
- package/dist/compiler/tir/expressions/TirVariableAccessExpr.d.ts +6 -3
- package/dist/compiler/tir/expressions/TirVariableAccessExpr.js +22 -8
- package/dist/compiler/tir/expressions/ToIRTermCtx.d.ts +19 -20
- package/dist/compiler/tir/expressions/ToIRTermCtx.js +74 -50
- package/dist/compiler/tir/expressions/binary/TirBinaryExpr.d.ts +41 -0
- package/dist/compiler/tir/expressions/binary/TirBinaryExpr.js +180 -4
- package/dist/compiler/tir/expressions/litteral/TirLitArrExpr.d.ts +4 -2
- package/dist/compiler/tir/expressions/litteral/TirLitArrExpr.js +8 -2
- package/dist/compiler/tir/expressions/litteral/TirLitFailExpr.d.ts +17 -0
- package/dist/compiler/tir/expressions/litteral/TirLitFailExpr.js +21 -0
- package/dist/compiler/tir/expressions/litteral/TirLitFalseExpr.d.ts +4 -1
- package/dist/compiler/tir/expressions/litteral/TirLitFalseExpr.js +4 -0
- package/dist/compiler/tir/expressions/litteral/TirLitHexBytesExpr.d.ts +4 -1
- package/dist/compiler/tir/expressions/litteral/TirLitHexBytesExpr.js +5 -0
- package/dist/compiler/tir/expressions/litteral/TirLitIntExpr.d.ts +4 -1
- package/dist/compiler/tir/expressions/litteral/TirLitIntExpr.js +4 -0
- package/dist/compiler/tir/expressions/litteral/TirLitNamedObjExpr.d.ts +3 -1
- package/dist/compiler/tir/expressions/litteral/TirLitNamedObjExpr.js +5 -0
- package/dist/compiler/tir/expressions/litteral/TirLitObjExpr.d.ts +3 -1
- package/dist/compiler/tir/expressions/litteral/TirLitObjExpr.js +5 -0
- package/dist/compiler/tir/expressions/litteral/TirLitStrExpr.d.ts +4 -1
- package/dist/compiler/tir/expressions/litteral/TirLitStrExpr.js +4 -0
- package/dist/compiler/tir/expressions/litteral/TirLitThisExpr.d.ts +4 -1
- package/dist/compiler/tir/expressions/litteral/TirLitThisExpr.js +7 -3
- package/dist/compiler/tir/expressions/litteral/TirLitTrueExpr.d.ts +4 -1
- package/dist/compiler/tir/expressions/litteral/TirLitTrueExpr.js +4 -0
- package/dist/compiler/tir/expressions/litteral/TirLitUndefExpr.d.ts +4 -1
- package/dist/compiler/tir/expressions/litteral/TirLitUndefExpr.js +4 -0
- package/dist/compiler/tir/expressions/litteral/TirLitVoidExpr.d.ts +4 -1
- package/dist/compiler/tir/expressions/litteral/TirLitVoidExpr.js +4 -0
- package/dist/compiler/tir/expressions/litteral/TirLitteralExpr.d.ts +2 -1
- package/dist/compiler/tir/expressions/litteral/TirLitteralExpr.js +3 -1
- package/dist/compiler/tir/expressions/unary/TirUnaryExclamation.d.ts +4 -2
- package/dist/compiler/tir/expressions/unary/TirUnaryExclamation.js +8 -3
- package/dist/compiler/tir/expressions/unary/TirUnaryMinus.d.ts +4 -2
- package/dist/compiler/tir/expressions/unary/TirUnaryMinus.js +8 -2
- package/dist/compiler/tir/expressions/unary/TirUnaryPlus.d.ts +3 -1
- package/dist/compiler/tir/expressions/unary/TirUnaryPlus.js +6 -0
- package/dist/compiler/tir/expressions/unary/TirUnaryTilde.d.ts +4 -2
- package/dist/compiler/tir/expressions/unary/TirUnaryTilde.js +8 -2
- package/dist/compiler/tir/program/TypedProgram.d.ts +3 -2
- package/dist/compiler/tir/program/TypedProgram.js +9 -0
- package/dist/compiler/tir/program/stdScope/stdScope.js +135 -149
- package/dist/compiler/tir/statements/TirAssertStmt.d.ts +2 -0
- package/dist/compiler/tir/statements/TirAssertStmt.js +10 -0
- package/dist/compiler/tir/statements/TirAssignmentStmt.d.ts +2 -0
- package/dist/compiler/tir/statements/TirAssignmentStmt.js +8 -0
- package/dist/compiler/tir/statements/TirBlockStmt.d.ts +2 -0
- package/dist/compiler/tir/statements/TirBlockStmt.js +16 -0
- package/dist/compiler/tir/statements/TirBreakStmt.d.ts +2 -0
- package/dist/compiler/tir/statements/TirBreakStmt.js +8 -0
- package/dist/compiler/tir/statements/TirContinueStmt.d.ts +2 -0
- package/dist/compiler/tir/statements/TirContinueStmt.js +8 -0
- package/dist/compiler/tir/statements/TirFailStmt.d.ts +2 -0
- package/dist/compiler/tir/statements/TirFailStmt.js +8 -0
- package/dist/compiler/tir/statements/TirForOfStmt.d.ts +2 -0
- package/dist/compiler/tir/statements/TirForOfStmt.js +14 -0
- package/dist/compiler/tir/statements/TirForStmt.d.ts +2 -0
- package/dist/compiler/tir/statements/TirForStmt.js +21 -0
- package/dist/compiler/tir/statements/TirIfStmt.d.ts +2 -0
- package/dist/compiler/tir/statements/TirIfStmt.js +16 -0
- package/dist/compiler/tir/statements/TirMatchStmt.d.ts +2 -0
- package/dist/compiler/tir/statements/TirMatchStmt.js +30 -0
- package/dist/compiler/tir/statements/TirReturnStmt.d.ts +2 -0
- package/dist/compiler/tir/statements/TirReturnStmt.js +8 -0
- package/dist/compiler/tir/statements/TirStmt.d.ts +2 -0
- package/dist/compiler/tir/statements/TirVarDecl/TirArrayLikeDeconstr.d.ts +2 -0
- package/dist/compiler/tir/statements/TirVarDecl/TirArrayLikeDeconstr.js +30 -0
- package/dist/compiler/tir/statements/TirVarDecl/TirNamedDeconstructVarDecl.d.ts +3 -1
- package/dist/compiler/tir/statements/TirVarDecl/TirNamedDeconstructVarDecl.js +28 -0
- package/dist/compiler/tir/statements/TirVarDecl/TirSimpleVarDecl.d.ts +3 -0
- package/dist/compiler/tir/statements/TirVarDecl/TirSimpleVarDecl.js +13 -0
- package/dist/compiler/tir/statements/TirVarDecl/TirSingleDeconstructVarDecl.d.ts +3 -1
- package/dist/compiler/tir/statements/TirVarDecl/TirSingleDeconstructVarDecl.js +28 -0
- package/dist/compiler/tir/statements/TirWhileStmt.d.ts +2 -0
- package/dist/compiler/tir/statements/TirWhileStmt.js +14 -0
- package/dist/compiler/tir/types/utils/canAssignTo.js +1 -1
- package/dist/diagnostics/DiagnosticEmitter.js +1 -1
- package/dist/diagnostics/diagnosticMessages.generated.d.ts +10 -1
- package/dist/diagnostics/diagnosticMessages.generated.js +20 -2
- package/dist/parser/Parser.d.ts +8 -3
- package/dist/parser/Parser.js +180 -32
- package/dist/parser/Precedence.js +1 -0
- package/dist/tokenizer/Token.d.ts +81 -72
- package/dist/tokenizer/Token.js +82 -72
- package/dist/tokenizer/utils/tokenFromKeyword.js +32 -10
- package/dist/tokenizer/utils/tokenIsAlsoIdentifier.js +10 -0
- package/dist/utils/BitUtils/index.js +1 -1
- package/dist/utils/UPLCFlatUtils/index.js +1 -1
- package/dist/utils/array/keepSortedArrInplace.js +1 -0
- package/package.json +3 -1
- package/dist/IR/IRNodes/utils/isClosedAtDbn.d.ts +0 -2
- package/dist/IR/IRNodes/utils/isClosedAtDbn.js +0 -22
- package/dist/IR/toUPLC/_internal/_irToUplc.d.ts +0 -9
- package/dist/IR/toUPLC/_internal/_irToUplc.js +0 -156
- package/dist/IR/toUPLC/subRoutines/handleLetted/incrementUnboundDbns.d.ts +0 -9
- package/dist/IR/toUPLC/subRoutines/handleLetted/incrementUnboundDbns.js +0 -73
- package/dist/IR/toUPLC/subRoutines/inlineSingleUseApplications.d.ts +0 -1
- package/dist/IR/toUPLC/subRoutines/inlineSingleUseApplications.js +0 -12
- package/dist/IR/toUPLC/subRoutines/performUplcOptimizationsAndReturnRoot/index.js +0 -227
- package/dist/IR/tree_utils/_ir_apps.d.ts +0 -3
- package/dist/IR/tree_utils/_ir_apps.js +0 -8
- package/dist/compiler/TirCompiler/internal/_compileHoistedDeps.d.ts +0 -5
- package/dist/compiler/TirCompiler/internal/_compileHoistedDeps.js +0 -37
|
@@ -3,20 +3,64 @@ import { getUniqueInternalName } from "../../internalVar.js";
|
|
|
3
3
|
import { TirLitNamedObjExpr } from "../../tir/expressions/litteral/TirLitNamedObjExpr.js";
|
|
4
4
|
import { TirCallExpr } from "../../tir/expressions/TirCallExpr.js";
|
|
5
5
|
import { TirFuncExpr } from "../../tir/expressions/TirFuncExpr.js";
|
|
6
|
+
import { TirPropAccessExpr } from "../../tir/expressions/TirPropAccessExpr.js";
|
|
6
7
|
import { TirVariableAccessExpr } from "../../tir/expressions/TirVariableAccessExpr.js";
|
|
8
|
+
import { TirUnaryExclamation } from "../../tir/expressions/unary/TirUnaryExclamation.js";
|
|
9
|
+
import { TirAssignmentStmt } from "../../tir/statements/TirAssignmentStmt.js";
|
|
7
10
|
import { TirBlockStmt } from "../../tir/statements/TirBlockStmt.js";
|
|
8
11
|
import { TirBreakStmt } from "../../tir/statements/TirBreakStmt.js";
|
|
9
12
|
import { TirContinueStmt } from "../../tir/statements/TirContinueStmt.js";
|
|
13
|
+
import { TirForOfStmt } from "../../tir/statements/TirForOfStmt.js";
|
|
10
14
|
import { TirForStmt } from "../../tir/statements/TirForStmt.js";
|
|
11
15
|
import { TirIfStmt } from "../../tir/statements/TirIfStmt.js";
|
|
12
16
|
import { TirReturnStmt } from "../../tir/statements/TirReturnStmt.js";
|
|
13
17
|
import { TirSimpleVarDecl } from "../../tir/statements/TirVarDecl/TirSimpleVarDecl.js";
|
|
18
|
+
import { TirBoolT } from "../../tir/types/TirNativeType/index.js";
|
|
14
19
|
import { TirFuncT } from "../../tir/types/TirNativeType/native/function.js";
|
|
20
|
+
import { getListTypeArg } from "../../tir/types/utils/getListTypeArg.js";
|
|
15
21
|
import { expressifyFuncBody } from "./expressify.js";
|
|
16
22
|
import { isExpressifyFuncParam } from "./ExpressifyCtx.js";
|
|
17
|
-
|
|
23
|
+
import { expressifyVars } from "./expressifyVars.js";
|
|
24
|
+
export function loopToForStmt(stmt) {
|
|
18
25
|
if (stmt instanceof TirForStmt)
|
|
19
26
|
return stmt;
|
|
27
|
+
if (stmt instanceof TirForOfStmt) {
|
|
28
|
+
// convert for of to for
|
|
29
|
+
const partialListName = getUniqueInternalName("for_of_partial_list");
|
|
30
|
+
const iterElemType = getListTypeArg(stmt.iterable.type);
|
|
31
|
+
if (!iterElemType)
|
|
32
|
+
throw new Error("Iterable type is not a list");
|
|
33
|
+
const varRange = stmt.elemDeclaration.range;
|
|
34
|
+
const partialListVar = new TirSimpleVarDecl(partialListName, // name
|
|
35
|
+
stmt.iterable.type, // type
|
|
36
|
+
stmt.iterable, // initial value
|
|
37
|
+
false, // is constant
|
|
38
|
+
varRange // range
|
|
39
|
+
);
|
|
40
|
+
const partialListVarAccess = new TirVariableAccessExpr({
|
|
41
|
+
isDefinedOutsideFuncScope: false,
|
|
42
|
+
variableInfos: {
|
|
43
|
+
name: partialListVar.name,
|
|
44
|
+
type: partialListVar.type,
|
|
45
|
+
isConstant: false,
|
|
46
|
+
},
|
|
47
|
+
}, varRange);
|
|
48
|
+
// `!partialList.isEmpty()`
|
|
49
|
+
const runCondition = new TirUnaryExclamation(new TirCallExpr(new TirPropAccessExpr(partialListVarAccess.clone(), new Identifier("isEmpty", varRange), new TirFuncT([], new TirBoolT()), varRange), [], // args
|
|
50
|
+
new TirBoolT(), varRange), new TirBoolT(), varRange);
|
|
51
|
+
const updatePartialList = new TirAssignmentStmt(partialListVarAccess.clone(), new TirCallExpr(new TirPropAccessExpr(partialListVarAccess.clone(), new Identifier("tail", varRange), new TirFuncT([], stmt.iterable.type), varRange), [], // args
|
|
52
|
+
stmt.iterable.type, varRange), varRange);
|
|
53
|
+
let body = stmt.body instanceof TirBlockStmt ? stmt.body : new TirBlockStmt([stmt.body], stmt.range);
|
|
54
|
+
const elemDecl = stmt.elemDeclaration;
|
|
55
|
+
elemDecl.initExpr = new TirCallExpr(new TirPropAccessExpr(partialListVarAccess.clone(), new Identifier("head", varRange), new TirFuncT([], iterElemType), varRange), [], // args
|
|
56
|
+
iterElemType, varRange);
|
|
57
|
+
body.stmts.unshift(elemDecl);
|
|
58
|
+
return new TirForStmt([partialListVar], // init
|
|
59
|
+
runCondition, // condition
|
|
60
|
+
[updatePartialList], // update
|
|
61
|
+
body, // loopBody
|
|
62
|
+
stmt.range);
|
|
63
|
+
}
|
|
20
64
|
// convert while to for
|
|
21
65
|
return new TirForStmt([], // no init
|
|
22
66
|
stmt.condition, // condition
|
|
@@ -25,14 +69,24 @@ export function whileToFor(stmt) {
|
|
|
25
69
|
stmt.range);
|
|
26
70
|
}
|
|
27
71
|
export function expressifyForStmt(ctx, stmt, returnType, bodyStateType, initState) {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
72
|
+
let loopBody = stmt.body instanceof TirBlockStmt ? stmt.body : new TirBlockStmt([stmt.body], stmt.range);
|
|
73
|
+
loopBody = new TirBlockStmt(loopBody.stmts.slice(), loopBody.range);
|
|
74
|
+
// add final loop updates
|
|
75
|
+
if (Array.isArray(stmt.update))
|
|
76
|
+
for (const updateStmt of stmt.update) {
|
|
77
|
+
loopBody.stmts.push(updateStmt);
|
|
78
|
+
}
|
|
79
|
+
// ALWAYS add a final `continue;` to the end of the loop body
|
|
35
80
|
loopBody.stmts.push(new TirContinueStmt(loopBody.range.atEnd()));
|
|
81
|
+
if (stmt.condition) {
|
|
82
|
+
loopBody = new TirBlockStmt([
|
|
83
|
+
new TirIfStmt(stmt.condition,
|
|
84
|
+
// then
|
|
85
|
+
loopBody,
|
|
86
|
+
// else
|
|
87
|
+
new TirBlockStmt([new TirBreakStmt(stmt.condition.range)], stmt.condition.range), stmt.condition.range)
|
|
88
|
+
], loopBody.range);
|
|
89
|
+
}
|
|
36
90
|
const loopFuncName = getUniqueInternalName("loop");
|
|
37
91
|
const loopFuncType = new TirFuncT(bodyStateType.constructors[0].fields.map(f => f.type), returnType);
|
|
38
92
|
const loopReplacements = {
|
|
@@ -105,11 +159,22 @@ export function expressifyForStmt(ctx, stmt, returnType, bodyStateType, initStat
|
|
|
105
159
|
for (const { name, type } of bodyStateType.constructors[0].fields) {
|
|
106
160
|
loopCompilationCtx.setFuncParam(name, type);
|
|
107
161
|
}
|
|
108
|
-
|
|
162
|
+
const loopFuncExpr = new TirFuncExpr(loopFuncName, // func name
|
|
163
|
+
// func params
|
|
164
|
+
bodyStateType.constructors[0].fields.map(f => new TirSimpleVarDecl(f.name, f.type, undefined, // no initial value
|
|
109
165
|
false, // is constant
|
|
110
|
-
stmt.range)),
|
|
166
|
+
stmt.range)),
|
|
167
|
+
// func return type
|
|
168
|
+
returnType,
|
|
169
|
+
// func body
|
|
170
|
+
new TirBlockStmt([
|
|
111
171
|
new TirReturnStmt(expressifyFuncBody(loopCompilationCtx, loopBody.stmts, loopReplacements, [] // assertions
|
|
112
172
|
), stmt.range)
|
|
113
|
-
], stmt.range),
|
|
114
|
-
|
|
173
|
+
], stmt.range),
|
|
174
|
+
// func range
|
|
175
|
+
stmt.range, true // is loop
|
|
176
|
+
);
|
|
177
|
+
return new TirCallExpr(loopFuncExpr,
|
|
178
|
+
// loop call init args
|
|
179
|
+
initState.values.map(v => expressifyVars(ctx, v.clone())), returnType, stmt.range);
|
|
115
180
|
}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
1
|
import { TirAssignmentStmt } from "../../tir/statements/TirAssignmentStmt.js";
|
|
2
|
-
import { TirSimpleVarDecl } from "../../tir/statements/TirVarDecl/TirSimpleVarDecl.js";
|
|
3
2
|
import { ExpressifyCtx } from "./ExpressifyCtx.js";
|
|
4
|
-
export declare function expressifyVarAssignmentStmt(ctx: ExpressifyCtx, stmt: TirAssignmentStmt):
|
|
3
|
+
export declare function expressifyVarAssignmentStmt(ctx: ExpressifyCtx, stmt: TirAssignmentStmt): void;
|
|
@@ -1,20 +1,27 @@
|
|
|
1
1
|
import { getUniqueInternalName } from "../../internalVar.js";
|
|
2
|
-
import { TirLettedExpr } from "../../tir/expressions/TirLettedExpr.js";
|
|
3
|
-
import { TirSimpleVarDecl } from "../../tir/statements/TirVarDecl/TirSimpleVarDecl.js";
|
|
4
2
|
import { expressifyVars } from "./expressifyVars.js";
|
|
5
3
|
export function expressifyVarAssignmentStmt(ctx, stmt) {
|
|
4
|
+
// since we no longer return a new TirSimpleVarDecl,
|
|
5
|
+
// we need to expressify the assigned expression here
|
|
6
|
+
//
|
|
7
|
+
// !!! IMPORTANT !!! we MUST NOT do it if we instead returned a new TirSimpleVarDecl,
|
|
8
|
+
// otherwise it would be re-processed, casing bugs
|
|
6
9
|
const assignedExpr = expressifyVars(ctx, stmt.assignedExpr);
|
|
7
10
|
const originalName = stmt.varIdentifier.resolvedValue.variableInfos.name;
|
|
8
|
-
const latestVarNameSSA = ctx.
|
|
11
|
+
const latestVarNameSSA = ctx.getVariableSSA(originalName);
|
|
9
12
|
if (!latestVarNameSSA) {
|
|
10
|
-
throw new Error("re-assigning constant variable");
|
|
13
|
+
throw new Error("re-assigning constant variable '" + originalName + "'");
|
|
11
14
|
}
|
|
12
15
|
const newUniqueName = getUniqueInternalName(originalName);
|
|
13
|
-
|
|
16
|
+
ctx.setNewVariableName(originalName, newUniqueName);
|
|
14
17
|
// point to the same object
|
|
15
|
-
ctx.
|
|
16
|
-
ctx.lettedConstants.set(newUniqueName, new TirLettedExpr(newUniqueName, assignedExpr, stmt.range));
|
|
18
|
+
ctx.introduceLettedConstant(newUniqueName, assignedExpr, stmt.range);
|
|
17
19
|
// will replace re-assignment in body
|
|
18
|
-
return new TirSimpleVarDecl(
|
|
19
|
-
|
|
20
|
+
// return new TirSimpleVarDecl(
|
|
21
|
+
// newUniqueName,
|
|
22
|
+
// stmt.varIdentifier.resolvedValue.variableInfos.type,
|
|
23
|
+
// assignedExpr,
|
|
24
|
+
// true, // isConst
|
|
25
|
+
// stmt.range,
|
|
26
|
+
// );
|
|
20
27
|
}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { TirLettedExpr } from "../../tir/expressions/TirLettedExpr.js";
|
|
2
1
|
import { TirArrayLikeDeconstr } from "../../tir/statements/TirVarDecl/TirArrayLikeDeconstr.js";
|
|
3
2
|
import { TirNamedDeconstructVarDecl } from "../../tir/statements/TirVarDecl/TirNamedDeconstructVarDecl.js";
|
|
4
3
|
import { TirSimpleVarDecl } from "../../tir/statements/TirVarDecl/TirSimpleVarDecl.js";
|
|
@@ -9,26 +8,25 @@ export function expressifyVarDecl(ctx, stmt) {
|
|
|
9
8
|
if (stmt.initExpr)
|
|
10
9
|
expressifyVars(ctx, stmt.initExpr);
|
|
11
10
|
if (stmt instanceof TirSimpleVarDecl) {
|
|
12
|
-
if (stmt.isConst) {
|
|
13
|
-
void ctx.
|
|
14
|
-
|
|
15
|
-
stmt.isConst = true;
|
|
11
|
+
if (!stmt.isConst) {
|
|
12
|
+
void ctx.setNewVariableName(stmt.name, stmt.name);
|
|
13
|
+
// stmt.isConst = true;
|
|
16
14
|
}
|
|
17
|
-
ctx.
|
|
15
|
+
ctx.introduceLettedConstant(stmt.name, stmt.initExpr, stmt.range);
|
|
18
16
|
}
|
|
19
17
|
if (stmt instanceof TirNamedDeconstructVarDecl
|
|
20
18
|
|| stmt instanceof TirSingleDeconstructVarDecl) {
|
|
21
19
|
for (const [_field, varDecl] of stmt.fields)
|
|
22
20
|
expressifyVarDecl(ctx, varDecl);
|
|
23
21
|
if (stmt.rest)
|
|
24
|
-
ctx.
|
|
22
|
+
ctx.setNewVariableName(stmt.rest, stmt.rest);
|
|
25
23
|
return;
|
|
26
24
|
}
|
|
27
25
|
if (stmt instanceof TirArrayLikeDeconstr) {
|
|
28
26
|
for (const varDecl of stmt.elements)
|
|
29
27
|
expressifyVarDecl(ctx, varDecl);
|
|
30
28
|
if (stmt.rest)
|
|
31
|
-
ctx.
|
|
29
|
+
ctx.setNewVariableName(stmt.rest, stmt.rest);
|
|
32
30
|
return;
|
|
33
31
|
}
|
|
34
32
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { SourceRange } from "../../../ast/Source/SourceRange.js";
|
|
2
2
|
import { isTirBinaryExpr } from "../../tir/expressions/binary/TirBinaryExpr.js";
|
|
3
3
|
import { TirLitArrExpr } from "../../tir/expressions/litteral/TirLitArrExpr.js";
|
|
4
|
+
import { TirLitFailExpr } from "../../tir/expressions/litteral/TirLitFailExpr.js";
|
|
4
5
|
import { TirLitFalseExpr } from "../../tir/expressions/litteral/TirLitFalseExpr.js";
|
|
5
6
|
import { TirLitHexBytesExpr } from "../../tir/expressions/litteral/TirLitHexBytesExpr.js";
|
|
6
7
|
import { TirLitIntExpr } from "../../tir/expressions/litteral/TirLitIntExpr.js";
|
|
@@ -32,11 +33,17 @@ import { TirVariableAccessExpr } from "../../tir/expressions/TirVariableAccessEx
|
|
|
32
33
|
import { TirUnaryExclamation } from "../../tir/expressions/unary/TirUnaryExclamation.js";
|
|
33
34
|
import { TirUnaryMinus } from "../../tir/expressions/unary/TirUnaryMinus.js";
|
|
34
35
|
import { TirUnaryPlus } from "../../tir/expressions/unary/TirUnaryPlus.js";
|
|
36
|
+
import { isTirUnaryPrefixExpr } from "../../tir/expressions/unary/TirUnaryPrefixExpr.js";
|
|
35
37
|
import { TirUnaryTilde } from "../../tir/expressions/unary/TirUnaryTilde.js";
|
|
38
|
+
import { bool_t } from "../../tir/program/stdScope/stdScope.js";
|
|
36
39
|
import { TirReturnStmt } from "../../tir/statements/TirReturnStmt.js";
|
|
37
40
|
import { TirArrayLikeDeconstr } from "../../tir/statements/TirVarDecl/TirArrayLikeDeconstr.js";
|
|
38
41
|
import { TirNamedDeconstructVarDecl } from "../../tir/statements/TirVarDecl/TirNamedDeconstructVarDecl.js";
|
|
39
42
|
import { TirSimpleVarDecl } from "../../tir/statements/TirVarDecl/TirSimpleVarDecl.js";
|
|
43
|
+
import { TirAliasType } from "../../tir/types/TirAliasType.js";
|
|
44
|
+
import { TirFuncT, TirListT } from "../../tir/types/TirNativeType/index.js";
|
|
45
|
+
import { TirDataStructType, TirSoPStructType } from "../../tir/types/TirStructType.js";
|
|
46
|
+
import { getListTypeArg } from "../../tir/types/utils/getListTypeArg.js";
|
|
40
47
|
import { getUnaliased } from "../../tir/types/utils/getUnaliased.js";
|
|
41
48
|
import { expressify, expressifyFuncBody } from "./expressify.js";
|
|
42
49
|
import { isExpressifyFuncParam } from "./ExpressifyCtx.js";
|
|
@@ -54,6 +61,7 @@ export function expressifyVars(ctx, expr) {
|
|
|
54
61
|
if (
|
|
55
62
|
// isTirLitteralExpr( expr )
|
|
56
63
|
expr instanceof TirLitVoidExpr
|
|
64
|
+
|| expr instanceof TirLitFailExpr
|
|
57
65
|
|| expr instanceof TirLitUndefExpr
|
|
58
66
|
|| expr instanceof TirLitTrueExpr
|
|
59
67
|
|| expr instanceof TirLitFalseExpr
|
|
@@ -75,22 +83,26 @@ export function expressifyVars(ctx, expr) {
|
|
|
75
83
|
if (expr instanceof TirPropAccessExpr) {
|
|
76
84
|
const objectExpr = expressifyVars(ctx, expr.object);
|
|
77
85
|
expr.object = objectExpr;
|
|
78
|
-
return
|
|
86
|
+
return expressifyPropAccess(ctx, expr);
|
|
79
87
|
}
|
|
80
88
|
if (expr instanceof TirVariableAccessExpr) {
|
|
81
89
|
const originalVarName = expr.resolvedValue.variableInfos.name;
|
|
82
90
|
const resolvedVariable = ctx.getVariable(originalVarName);
|
|
83
91
|
if (!resolvedVariable)
|
|
84
92
|
return expr; // variable not found, keep the original expression
|
|
93
|
+
// if variable was shadowed
|
|
85
94
|
if (isExpressifyFuncParam(resolvedVariable)) {
|
|
86
|
-
//
|
|
95
|
+
// !!! IMPORTANT !!!
|
|
96
|
+
// we must clone the expression to avoid modifying other instances of it elsewhere
|
|
97
|
+
// THIS IS CRUCIAL I SPENT A DAY DEBUGGING THIS
|
|
98
|
+
expr = expr.clone();
|
|
87
99
|
expr.resolvedValue.variableInfos.name = resolvedVariable.name;
|
|
88
100
|
return expr;
|
|
89
101
|
}
|
|
90
102
|
// resovledVariable instanceof TirVariableAccessExpr
|
|
91
|
-
return resolvedVariable;
|
|
103
|
+
return resolvedVariable.clone();
|
|
92
104
|
}
|
|
93
|
-
if (
|
|
105
|
+
if (isTirUnaryPrefixExpr(expr)) {
|
|
94
106
|
const modifiedExpr = expressifyVars(ctx, expr.operand);
|
|
95
107
|
expr.operand = modifiedExpr;
|
|
96
108
|
return expr;
|
|
@@ -102,10 +114,19 @@ export function expressifyVars(ctx, expr) {
|
|
|
102
114
|
return expr;
|
|
103
115
|
}
|
|
104
116
|
if (expr instanceof TirFuncExpr) {
|
|
105
|
-
expressify(expr, undefined, ctx);
|
|
117
|
+
expressify(expr, undefined, ctx.program, ctx);
|
|
106
118
|
return expr;
|
|
107
119
|
}
|
|
108
120
|
if (expr instanceof TirCallExpr) {
|
|
121
|
+
while (expr.func instanceof TirParentesizedExpr)
|
|
122
|
+
expr.func = expr.func.expr;
|
|
123
|
+
if (expr.func instanceof TirPropAccessExpr) {
|
|
124
|
+
for (let i = 0; i < expr.args.length; i++) {
|
|
125
|
+
const arg = expressifyVars(ctx, expr.args[i]);
|
|
126
|
+
expr.args[i] = arg;
|
|
127
|
+
}
|
|
128
|
+
return expressifyMethodCall(ctx, expr);
|
|
129
|
+
}
|
|
109
130
|
const func = expressifyVars(ctx, expr.func);
|
|
110
131
|
expr.func = func;
|
|
111
132
|
for (let i = 0; i < expr.args.length; i++) {
|
|
@@ -193,17 +214,18 @@ export function expressifyVars(ctx, expr) {
|
|
|
193
214
|
}
|
|
194
215
|
if (expr instanceof TirInlineClosedIR)
|
|
195
216
|
return expr;
|
|
196
|
-
const
|
|
217
|
+
const tsEnsureExhautstiveCheck = expr;
|
|
197
218
|
console.error(expr);
|
|
198
219
|
throw new Error("unreachable::expressifyVars");
|
|
199
220
|
}
|
|
200
|
-
function
|
|
221
|
+
function expressifyPropAccess(ctx, propAccessExpr) {
|
|
201
222
|
let expr = propAccessExpr.object;
|
|
202
223
|
const prop = propAccessExpr.prop.text;
|
|
203
224
|
while (expr instanceof TirParentesizedExpr)
|
|
204
225
|
expr = expr.expr;
|
|
205
226
|
if (expr instanceof TirLitVoidExpr
|
|
206
227
|
|| expr instanceof TirLitUndefExpr
|
|
228
|
+
|| expr instanceof TirLitFailExpr
|
|
207
229
|
|| expr instanceof TirLitTrueExpr
|
|
208
230
|
|| expr instanceof TirLitFalseExpr
|
|
209
231
|
// methods on these should have already been converted to functions
|
|
@@ -230,7 +252,7 @@ function getVarAccessFromPropAccess(ctx, propAccessExpr) {
|
|
|
230
252
|
let varName = ctx.properties.get("this")?.get(prop);
|
|
231
253
|
if (!varName)
|
|
232
254
|
throw new Error(`Property '${prop}' does not exist on 'this'`);
|
|
233
|
-
varName = ctx.
|
|
255
|
+
varName = ctx.getVariableSSA(varName)?.latestName ?? varName;
|
|
234
256
|
const expr = ctx.getVariable(varName);
|
|
235
257
|
if (isExpressifyFuncParam(expr)) {
|
|
236
258
|
return new TirVariableAccessExpr({
|
|
@@ -244,6 +266,7 @@ function getVarAccessFromPropAccess(ctx, propAccessExpr) {
|
|
|
244
266
|
}
|
|
245
267
|
return expr;
|
|
246
268
|
}
|
|
269
|
+
// expressify as normal variable
|
|
247
270
|
if (expr instanceof TirLitObjExpr
|
|
248
271
|
|| expr instanceof TirLitNamedObjExpr) {
|
|
249
272
|
const valIdx = expr.fieldNames.findIndex(f => f.text === prop);
|
|
@@ -269,7 +292,7 @@ function getVarAccessFromPropAccess(ctx, propAccessExpr) {
|
|
|
269
292
|
|| expr instanceof TirVariableAccessExpr) {
|
|
270
293
|
let varName = ctx.properties.get(expr.varName)?.get(prop);
|
|
271
294
|
if (varName) {
|
|
272
|
-
varName = ctx.
|
|
295
|
+
varName = ctx.getVariableSSA(varName)?.latestName ?? varName;
|
|
273
296
|
const result = ctx.getVariable(varName);
|
|
274
297
|
if (isExpressifyFuncParam(result)) {
|
|
275
298
|
return new TirVariableAccessExpr({
|
|
@@ -288,8 +311,10 @@ function getVarAccessFromPropAccess(ctx, propAccessExpr) {
|
|
|
288
311
|
}
|
|
289
312
|
const objType = getUnaliased(expr.type);
|
|
290
313
|
if (!isSingleConstrStruct(objType)) {
|
|
291
|
-
|
|
292
|
-
|
|
314
|
+
// IMPORTANT: we only care about fields here
|
|
315
|
+
// any methods should have already been converted to functions
|
|
316
|
+
console.error(objType, expr.toString());
|
|
317
|
+
throw new Error(`cannot access property '${prop}' on non-struct type`);
|
|
293
318
|
}
|
|
294
319
|
const ctor = objType.constructors[0];
|
|
295
320
|
const fIdx = ctor.fields.findIndex(f => f.name === prop);
|
|
@@ -315,6 +340,114 @@ function getVarAccessFromPropAccess(ctx, propAccessExpr) {
|
|
|
315
340
|
fType, propAccessExpr.range);
|
|
316
341
|
}
|
|
317
342
|
;
|
|
318
|
-
const
|
|
343
|
+
const tsEnsureExhautstiveCheck = expr;
|
|
319
344
|
throw new Error("Invalid property access expression");
|
|
320
345
|
}
|
|
346
|
+
function expressifyMethodCall(ctx, methodCall) {
|
|
347
|
+
const methodPropAccess = methodCall.func;
|
|
348
|
+
if (!(methodPropAccess instanceof TirPropAccessExpr))
|
|
349
|
+
throw new Error("Invalid method call expression");
|
|
350
|
+
const methodIdentifierProp = methodPropAccess.prop;
|
|
351
|
+
const methodName = methodIdentifierProp.text;
|
|
352
|
+
const objectExpr = expressifyVars(ctx, methodPropAccess.object);
|
|
353
|
+
let objectType = objectExpr.type;
|
|
354
|
+
while (objectType instanceof TirAliasType) {
|
|
355
|
+
const aliasMethds = objectType.methodsNamesPtr;
|
|
356
|
+
const tirMethodName = aliasMethds.get(methodName);
|
|
357
|
+
if (!tirMethodName) {
|
|
358
|
+
objectType = objectType.aliased;
|
|
359
|
+
continue;
|
|
360
|
+
}
|
|
361
|
+
const funcExpr = ctx.program.functions.get(tirMethodName);
|
|
362
|
+
if (!funcExpr)
|
|
363
|
+
throw new Error(`Definition of method '${methodName}' on type '${objectType.toString()}' is missing.`);
|
|
364
|
+
return new TirCallExpr(funcExpr, [objectExpr, ...methodCall.args], methodCall.type, SourceRange.join(methodIdentifierProp.range, methodCall.range.atEnd()));
|
|
365
|
+
}
|
|
366
|
+
if (objectType instanceof TirDataStructType
|
|
367
|
+
|| objectType instanceof TirSoPStructType) {
|
|
368
|
+
const structMethods = objectType.methodNamesPtr;
|
|
369
|
+
const tirMethodName = structMethods.get(methodName);
|
|
370
|
+
if (!tirMethodName)
|
|
371
|
+
throw new Error(`Method '${methodName}' does not exist on type '${objectType.toString()}'`);
|
|
372
|
+
const funcExpr = ctx.program.functions.get(tirMethodName);
|
|
373
|
+
if (!funcExpr)
|
|
374
|
+
throw new Error(`Definition of method '${methodName}' on type '${objectType.toString()}' is missing.`);
|
|
375
|
+
return new TirCallExpr(funcExpr, [objectExpr, ...methodCall.args], methodCall.type, SourceRange.join(methodIdentifierProp.range, methodCall.range.atEnd()));
|
|
376
|
+
}
|
|
377
|
+
if (objectType instanceof TirListT) {
|
|
378
|
+
const result = expressifyListMethodCall(ctx, objectExpr, methodCall, methodName, objectType, SourceRange.join(methodIdentifierProp.range, methodCall.range.atEnd()));
|
|
379
|
+
if (result)
|
|
380
|
+
return result;
|
|
381
|
+
}
|
|
382
|
+
throw new Error(`not implemented::expressifyMethodCall for type '${objectType.toString()}' (method name: '${methodName}')`);
|
|
383
|
+
// const tsEnsureExhautstiveCheck: never = objectType;
|
|
384
|
+
throw new Error(`Cannot call method '${methodName}' on non-struct type '${objectType.toString()}'`);
|
|
385
|
+
}
|
|
386
|
+
function expressifyListMethodCall(ctx, objectExpr, methodCall, methodName, listType, exprRange) {
|
|
387
|
+
const elemsType = getListTypeArg(listType);
|
|
388
|
+
if (!elemsType)
|
|
389
|
+
throw new Error("Invalid list type");
|
|
390
|
+
if (methodName === "length") {
|
|
391
|
+
if (methodCall.args.length !== 0)
|
|
392
|
+
throw new Error(`Method 'length' of type 'list' takes 0 arguments, ${methodCall.args.length} provided`);
|
|
393
|
+
return new TirCallExpr(TirNativeFunc._length(elemsType), [objectExpr], methodCall.type, exprRange);
|
|
394
|
+
}
|
|
395
|
+
if (methodName === "some") {
|
|
396
|
+
if (methodCall.args.length !== 1)
|
|
397
|
+
throw new Error(`Method 'includes' of type 'list' takes 1 argument, ${methodCall.args.length} provided`);
|
|
398
|
+
return new TirCallExpr(TirNativeFunc._some(elemsType), [methodCall.args[0], objectExpr], methodCall.type, exprRange);
|
|
399
|
+
}
|
|
400
|
+
if (methodName === "every") {
|
|
401
|
+
if (methodCall.args.length !== 1)
|
|
402
|
+
throw new Error(`Method 'every' of type 'list' takes 1 argument, ${methodCall.args.length} provided`);
|
|
403
|
+
return new TirCallExpr(TirNativeFunc._every(elemsType), [methodCall.args[0], objectExpr], methodCall.type, exprRange);
|
|
404
|
+
}
|
|
405
|
+
if (methodName === "includes") {
|
|
406
|
+
if (methodCall.args.length !== 1)
|
|
407
|
+
throw new Error(`Method 'includes' of type 'list' takes 1 argument, ${methodCall.args.length} provided`);
|
|
408
|
+
return new TirCallExpr(TirNativeFunc._some(elemsType), [
|
|
409
|
+
new TirCallExpr(TirNativeFunc._equals(elemsType), [methodCall.args[0]], new TirFuncT([elemsType], bool_t), methodCall.args[0].range),
|
|
410
|
+
objectExpr
|
|
411
|
+
], methodCall.type, exprRange);
|
|
412
|
+
}
|
|
413
|
+
if (methodName === "head") {
|
|
414
|
+
if (methodCall.args.length !== 0)
|
|
415
|
+
throw new Error(`Method 'head' of type 'list' takes 0 arguments, ${methodCall.args.length} provided`);
|
|
416
|
+
return new TirCallExpr(TirNativeFunc.headList(elemsType), [objectExpr], methodCall.type, exprRange);
|
|
417
|
+
}
|
|
418
|
+
if (methodName === "tail") {
|
|
419
|
+
if (methodCall.args.length !== 0)
|
|
420
|
+
throw new Error(`Method 'tail' of type 'list' takes 0 arguments, ${methodCall.args.length} provided`);
|
|
421
|
+
return new TirCallExpr(TirNativeFunc.tailList(elemsType), [objectExpr], methodCall.type, exprRange);
|
|
422
|
+
}
|
|
423
|
+
if (methodName === "isEmpty") {
|
|
424
|
+
if (methodCall.args.length !== 0)
|
|
425
|
+
throw new Error(`Method 'isEmpty' of type 'list' takes 0 arguments, ${methodCall.args.length} provided`);
|
|
426
|
+
return new TirCallExpr(TirNativeFunc.nullList(elemsType), [objectExpr], methodCall.type, exprRange);
|
|
427
|
+
}
|
|
428
|
+
if (methodName === "find") {
|
|
429
|
+
if (methodCall.args.length !== 1)
|
|
430
|
+
throw new Error(`Method 'find' of type 'list' takes 1 argument, ${methodCall.args.length} provided`);
|
|
431
|
+
// const finalType = getUnaliased( methodCall.type );
|
|
432
|
+
// console.log( finalType );
|
|
433
|
+
return new TirCallExpr(TirNativeFunc._findSopOptional(elemsType), [methodCall.args[0], objectExpr], methodCall.type, exprRange);
|
|
434
|
+
}
|
|
435
|
+
// TODO
|
|
436
|
+
/*
|
|
437
|
+
{
|
|
438
|
+
isEmpty: new TirFuncT( [], bool_t ),
|
|
439
|
+
show: new TirFuncT( [], bytes_t ),
|
|
440
|
+
reverse: new TirFuncT( [], new TirListT( elemsType ) ),
|
|
441
|
+
find: new TirFuncT([
|
|
442
|
+
new TirFuncT( [elemsType], bool_t )
|
|
443
|
+
], new TirSopOptT( elemsType ) ),
|
|
444
|
+
filter: new TirFuncT([
|
|
445
|
+
new TirFuncT( [elemsType], bool_t )
|
|
446
|
+
], new TirListT( elemsType ) ),
|
|
447
|
+
prepend: new TirFuncT( [elemsType], new TirListT( elemsType ) ),
|
|
448
|
+
map: new TirFuncT([
|
|
449
|
+
new TirFuncT([ elemsType ], mapReturnT )
|
|
450
|
+
], new TirListT( mapReturnT ) ),
|
|
451
|
+
};
|
|
452
|
+
*/
|
|
453
|
+
}
|
|
@@ -15,6 +15,7 @@ export function flattenSopNamedDeconstructInplace_addTopDestructToCtx_getNestedD
|
|
|
15
15
|
if (varDecl instanceof TirSimpleVarDecl) {
|
|
16
16
|
restFields.set(fName, varDecl.name);
|
|
17
17
|
ctx.introduceFuncParams([varDecl]);
|
|
18
|
+
ctx.setNewVariableName(fName, varDecl.name); // added to fix reassigned variables on non-terminating statements
|
|
18
19
|
if (isSingleConstrStruct(varDecl.type)) {
|
|
19
20
|
const structType = getUnaliased(varDecl.type);
|
|
20
21
|
const constr = structType.constructors[0];
|
|
@@ -6,8 +6,8 @@ export declare const PEBBLE_INTERNAL_IDENTIFIER_SEPARATOR = "#";
|
|
|
6
6
|
* Creates and tracks unique internal variable names for the Pebble compiler
|
|
7
7
|
*/
|
|
8
8
|
export declare class UidGenerator {
|
|
9
|
+
private counter;
|
|
9
10
|
constructor();
|
|
10
|
-
private readonly uids;
|
|
11
11
|
getUid(): string;
|
|
12
12
|
/**
|
|
13
13
|
* Generates a unique internal variable name
|
|
@@ -1,39 +1,46 @@
|
|
|
1
|
-
import { isObject } from "@harmoniclabs/obj-utils";
|
|
2
|
-
import { toHex } from "@harmoniclabs/uint8array-utils";
|
|
3
1
|
/** invalid char for normal js identifiers */
|
|
4
2
|
export const PEBBLE_INTERNAL_IDENTIFIER_PREFIX = "§";
|
|
5
3
|
/** invalid char for normal js identifiers */
|
|
6
4
|
export const PEBBLE_INTERNAL_IDENTIFIER_SEPARATOR = "#";
|
|
7
5
|
// Keep getRandomBytes outside the class as requested
|
|
8
|
-
let getRandomBytes = (bytes) => {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
6
|
+
// let getRandomBytes = (bytes: Uint8Array) => {
|
|
7
|
+
// for (let i = 0; i < bytes.length; i++)
|
|
8
|
+
// bytes[i] = ((Math.random() * 0x100) >>> 0);
|
|
9
|
+
// return bytes;
|
|
10
|
+
// }
|
|
11
|
+
//
|
|
12
|
+
// try {
|
|
13
|
+
// if (
|
|
14
|
+
// typeof globalThis !== "undefined"
|
|
15
|
+
// && typeof globalThis.crypto !== "undefined"
|
|
16
|
+
// && isObject(globalThis.crypto)
|
|
17
|
+
// && typeof globalThis.crypto.getRandomValues === "function"
|
|
18
|
+
// ) getRandomBytes = globalThis.crypto.getRandomValues.bind(globalThis.crypto);
|
|
19
|
+
// } catch {}
|
|
20
|
+
//
|
|
21
|
+
// const uidSet = new Set<string>();
|
|
22
22
|
/**
|
|
23
23
|
* Creates and tracks unique internal variable names for the Pebble compiler
|
|
24
24
|
*/
|
|
25
25
|
export class UidGenerator {
|
|
26
|
+
counter;
|
|
26
27
|
constructor() {
|
|
27
|
-
this.uids = uidSet;
|
|
28
|
+
// this.uids = uidSet;
|
|
29
|
+
this.counter = 0n;
|
|
28
30
|
}
|
|
29
|
-
uids
|
|
31
|
+
// private readonly uids: Set<string>;
|
|
32
|
+
// getUid(): string {
|
|
33
|
+
// const bytes = new Uint8Array(Math.max(1, Math.log1p(this.uids.size) >>> 0));
|
|
34
|
+
// let uid: string;
|
|
35
|
+
// do {
|
|
36
|
+
// uid = toHex(getRandomBytes(bytes));
|
|
37
|
+
// } while( this.uids.has( uid ) );
|
|
38
|
+
// this.uids.add(uid);
|
|
39
|
+
// return uid;
|
|
40
|
+
// }
|
|
30
41
|
getUid() {
|
|
31
|
-
const
|
|
32
|
-
|
|
33
|
-
do {
|
|
34
|
-
uid = toHex(getRandomBytes(bytes));
|
|
35
|
-
} while (this.uids.has(uid));
|
|
36
|
-
this.uids.add(uid);
|
|
42
|
+
const uid = this.counter.toString(36);
|
|
43
|
+
this.counter++;
|
|
37
44
|
return uid;
|
|
38
45
|
}
|
|
39
46
|
/**
|
|
@@ -4,7 +4,7 @@ import { IOutputStream } from "./IOutputStream.js";
|
|
|
4
4
|
/** Compiler API options. */
|
|
5
5
|
export interface CompilerIoApi {
|
|
6
6
|
/** Standard output stream to use. */
|
|
7
|
-
|
|
7
|
+
stdout: IOutputStream;
|
|
8
8
|
/** Standard error stream to use. */
|
|
9
9
|
readonly stderr: IOutputStream;
|
|
10
10
|
/** Reads a file from disk (or memory). */
|
|
@@ -4,6 +4,7 @@ export interface IOutputStream {
|
|
|
4
4
|
write(chunk: Uint8Array | string): void;
|
|
5
5
|
}
|
|
6
6
|
export declare class ConsoleLogStream implements IOutputStream {
|
|
7
|
+
private _pending;
|
|
7
8
|
write(chunk: Uint8Array | string): void;
|
|
8
9
|
}
|
|
9
10
|
export declare class ConsoleErrorStream implements IOutputStream {
|
|
@@ -1,11 +1,26 @@
|
|
|
1
1
|
import { fromUtf8, concatUint8Array, toUtf8 } from "@harmoniclabs/uint8array-utils";
|
|
2
2
|
export class ConsoleLogStream {
|
|
3
|
+
_pending = "";
|
|
3
4
|
write(chunk) {
|
|
4
|
-
|
|
5
|
-
|
|
5
|
+
const newChunk = (chunk instanceof Uint8Array) ? toUtf8(chunk) : chunk.toString();
|
|
6
|
+
if (newChunk.includes("\n")) {
|
|
7
|
+
const parts = newChunk.split("\n");
|
|
8
|
+
if (parts.length === 1) {
|
|
9
|
+
// only one \n
|
|
10
|
+
console.log(this._pending + parts[0]);
|
|
11
|
+
this._pending = "";
|
|
12
|
+
}
|
|
13
|
+
else {
|
|
14
|
+
// multiple \n
|
|
15
|
+
console.log(this._pending + parts[0]);
|
|
16
|
+
for (let i = 1; i < parts.length - 1; i++) {
|
|
17
|
+
console.log(parts[i]);
|
|
18
|
+
}
|
|
19
|
+
this._pending = parts[parts.length - 1];
|
|
20
|
+
}
|
|
6
21
|
}
|
|
7
22
|
else {
|
|
8
|
-
|
|
23
|
+
this._pending += newChunk;
|
|
9
24
|
}
|
|
10
25
|
}
|
|
11
26
|
}
|
|
@@ -58,17 +58,15 @@ export function getEnvRelativePath(filePath, projectRoot) {
|
|
|
58
58
|
if (!(typeof filePath === 'string' &&
|
|
59
59
|
typeof projectRoot === 'string'))
|
|
60
60
|
return undefined;
|
|
61
|
+
projectRoot = projectRoot.trim();
|
|
62
|
+
if (!projectRoot.endsWith(PATH_DELIMITER))
|
|
63
|
+
projectRoot += PATH_DELIMITER;
|
|
61
64
|
if (isAbsolutePath(filePath))
|
|
62
65
|
return filePath;
|
|
63
|
-
projectRoot = projectRoot.trim();
|
|
64
66
|
filePath = getAbsolutePath(filePath.trim(), projectRoot);
|
|
65
67
|
if (!filePath)
|
|
66
68
|
return undefined;
|
|
67
|
-
|
|
68
|
-
projectRoot = projectRoot + PATH_DELIMITER;
|
|
69
|
-
while (filePath.startsWith(PATH_DELIMITER))
|
|
70
|
-
filePath = filePath.slice(PATH_DELIMITER.length);
|
|
71
|
-
return projectRoot + filePath;
|
|
69
|
+
return filePath.startsWith(projectRoot) ? filePath : projectRoot + filePath;
|
|
72
70
|
}
|
|
73
71
|
/**
|
|
74
72
|
* Takes a relative path and an absolute path, and returns the absolute path
|