@harmoniclabs/pebble 0.1.10 → 0.3.0
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/CompilationCtx.d.ts +40 -0
- package/dist/IR/CompilationCtx.js +54 -0
- package/dist/IR/IRHash.d.ts +23 -2
- package/dist/IR/IRHash.js +10 -60
- package/dist/IR/IRNodes/IRConst.js +35 -4
- package/dist/IR/IRNodes/IRHoisted.d.ts +0 -1
- package/dist/IR/IRNodes/IRHoisted.js +4 -6
- package/dist/IR/IRNodes/IRLetted.d.ts +0 -1
- package/dist/IR/IRNodes/IRLetted.js +4 -6
- package/dist/IR/IRNodes/IRNative/IRNativeTag.d.ts +22 -2
- package/dist/IR/IRNodes/IRNative/IRNativeTag.js +26 -2
- package/dist/IR/IRNodes/IRNative/index.d.ts +16 -1
- package/dist/IR/IRNodes/IRNative/index.js +31 -2
- package/dist/IR/IRNodes/utils/hashVarSym.d.ts +0 -1
- package/dist/IR/IRNodes/utils/hashVarSym.js +27 -33
- package/dist/IR/toUPLC/CompilerOptions.d.ts +34 -7
- package/dist/IR/toUPLC/CompilerOptions.js +19 -10
- package/dist/IR/toUPLC/compileIRToUPLC.js +39 -3
- package/dist/IR/toUPLC/subRoutines/inlineSingleUseLetBindingsAndReturnRoot.d.ts +23 -0
- package/dist/IR/toUPLC/subRoutines/inlineSingleUseLetBindingsAndReturnRoot.js +263 -0
- package/dist/IR/toUPLC/subRoutines/introduceCaseForDualHeadTailAndReturnRoot.d.ts +35 -0
- package/dist/IR/toUPLC/subRoutines/introduceCaseForDualHeadTailAndReturnRoot.js +169 -0
- package/dist/IR/toUPLC/subRoutines/replaceHoistedWithLetted.d.ts +0 -1
- package/dist/IR/toUPLC/subRoutines/replaceHoistedWithLetted.js +6 -6
- package/dist/IR/toUPLC/subRoutines/replaceNatives/nativeToIR.d.ts +2 -3
- package/dist/IR/toUPLC/subRoutines/replaceNatives/nativeToIR.js +106 -65
- package/dist/IR/toUPLC/subRoutines/rewriteHeadTailInCaseConsAndReturnRoot.d.ts +30 -0
- package/dist/IR/toUPLC/subRoutines/rewriteHeadTailInCaseConsAndReturnRoot.js +95 -0
- package/dist/IR/toUPLC/subRoutines/rewriteNativesAppliedToConstantsAndReturnRoot.js +36 -5
- package/dist/IR/toUPLC/subRoutines/rewriteToCaseOverConstAndReturnRoot.d.ts +35 -0
- package/dist/IR/toUPLC/subRoutines/rewriteToCaseOverConstAndReturnRoot.js +169 -0
- package/dist/IR/tree_utils/_ir_caseList.d.ts +15 -0
- package/dist/IR/tree_utils/_ir_caseList.js +19 -0
- package/dist/IR/tree_utils/bytesToHex.d.ts +8 -0
- package/dist/IR/tree_utils/bytesToHex.js +69 -0
- package/dist/ast/nodes/expr/functions/FuncExpr.d.ts +16 -2
- package/dist/ast/nodes/expr/functions/FuncExpr.js +17 -0
- package/dist/ast/nodes/expr/litteral/LitteralExpr.d.ts +2 -1
- package/dist/ast/nodes/expr/litteral/LitteralExpr.js +2 -0
- package/dist/ast/nodes/expr/litteral/TemplateStrExpr.d.ts +30 -0
- package/dist/ast/nodes/expr/litteral/TemplateStrExpr.js +35 -0
- package/dist/ast/nodes/statements/ExportStmt.d.ts +3 -3
- package/dist/ast/nodes/statements/PebbleStmt.d.ts +4 -3
- package/dist/ast/nodes/statements/PebbleStmt.js +6 -2
- package/dist/ast/nodes/statements/TestParam.d.ts +18 -0
- package/dist/ast/nodes/statements/TestParam.js +18 -0
- package/dist/ast/nodes/statements/TestStmt.d.ts +5 -3
- package/dist/ast/nodes/statements/TestStmt.js +3 -1
- package/dist/ast/nodes/statements/UsingStmt.d.ts +32 -2
- package/dist/ast/nodes/statements/UsingStmt.js +39 -3
- package/dist/ast/nodes/statements/declarations/NamespaceDecl.d.ts +21 -0
- package/dist/ast/nodes/statements/declarations/NamespaceDecl.js +31 -0
- package/dist/ast/nodes/statements/declarations/StructDecl.d.ts +16 -2
- package/dist/ast/nodes/statements/declarations/StructDecl.js +15 -1
- package/dist/compiler/AstCompiler/AstCompiler.d.ts +27 -0
- package/dist/compiler/AstCompiler/AstCompiler.js +244 -7
- package/dist/compiler/AstCompiler/internal/_deriveContractBody/_deriveContractBody.js +16 -5
- package/dist/compiler/AstCompiler/internal/exprs/_compileCallExpr.js +97 -6
- package/dist/compiler/AstCompiler/internal/exprs/_compileCaseExpr.js +31 -0
- package/dist/compiler/AstCompiler/internal/exprs/_compileFuncExpr.js +12 -5
- package/dist/compiler/AstCompiler/internal/exprs/_compileIsExpr.js +12 -0
- package/dist/compiler/AstCompiler/internal/exprs/_compileLitteralExpr.js +59 -0
- package/dist/compiler/AstCompiler/internal/exprs/_compilePropAccessExpr.d.ts +2 -3
- package/dist/compiler/AstCompiler/internal/exprs/_compilePropAccessExpr.js +64 -0
- package/dist/compiler/AstCompiler/internal/exprs/_compileUnaryPrefixExpr.js +13 -1
- package/dist/compiler/AstCompiler/internal/exprs/_compileVarAccessExpr.js +2 -0
- package/dist/compiler/AstCompiler/internal/exprs/binary/_compileAddExpr.js +18 -5
- package/dist/compiler/AstCompiler/internal/exprs/binary/_compileEqualExpr.js +3 -1
- package/dist/compiler/AstCompiler/internal/exprs/binary/_compileGreaterThanEqualExpr.js +2 -1
- package/dist/compiler/AstCompiler/internal/exprs/binary/_compileGreaterThanExpr.js +2 -1
- package/dist/compiler/AstCompiler/internal/exprs/binary/_compileLessThanEqualExpr.js +2 -1
- package/dist/compiler/AstCompiler/internal/exprs/binary/_compileLessThanExpr.js +2 -1
- package/dist/compiler/AstCompiler/internal/exprs/binary/_compileMultExpr.js +24 -6
- package/dist/compiler/AstCompiler/internal/exprs/binary/_compileNotEqualExpr.js +2 -1
- package/dist/compiler/AstCompiler/internal/exprs/binary/_compileSubExpr.js +16 -5
- package/dist/compiler/AstCompiler/internal/statements/_compileMatchStmt.js +33 -20
- package/dist/compiler/AstCompiler/internal/statements/_compileStatement.js +4 -1
- package/dist/compiler/AstCompiler/internal/statements/_compileTestStmt.d.ts +15 -1
- package/dist/compiler/AstCompiler/internal/statements/_compileTestStmt.js +70 -30
- package/dist/compiler/AstCompiler/internal/statements/_compileUsingAliasStmt.d.ts +11 -0
- package/dist/compiler/AstCompiler/internal/statements/_compileUsingAliasStmt.js +26 -0
- package/dist/compiler/AstCompiler/internal/statements/_compileUsingStmt.d.ts +9 -4
- package/dist/compiler/AstCompiler/internal/statements/_compileUsingStmt.js +51 -10
- package/dist/compiler/AstCompiler/internal/types/_compileDataEncodedConcreteType.js +21 -2
- package/dist/compiler/AstCompiler/internal/types/_compileSopEncodedConcreteType.js +17 -2
- package/dist/compiler/AstCompiler/scope/AstScope.d.ts +70 -1
- package/dist/compiler/AstCompiler/scope/AstScope.js +91 -0
- package/dist/compiler/AstCompiler/utils/getPropAccessReturnType.js +36 -1
- package/dist/compiler/AstCompiler/utils/monomorphizeGeneric.d.ts +36 -0
- package/dist/compiler/AstCompiler/utils/monomorphizeGeneric.js +123 -0
- package/dist/compiler/AstCompiler/utils/resolveNamespaceChain.d.ts +28 -0
- package/dist/compiler/AstCompiler/utils/resolveNamespaceChain.js +95 -0
- package/dist/compiler/AstCompiler/utils/resolveNamespacePath.d.ts +37 -0
- package/dist/compiler/AstCompiler/utils/resolveNamespacePath.js +93 -0
- package/dist/compiler/Compiler.d.ts +9 -1
- package/dist/compiler/Compiler.js +218 -30
- package/dist/compiler/TirCompiler/expressify/ExpressifyCtx.js +1 -1
- package/dist/compiler/TirCompiler/expressify/expressify.js +30 -2
- package/dist/compiler/TirCompiler/expressify/expressifyForStmt.d.ts +2 -1
- package/dist/compiler/TirCompiler/expressify/expressifyForStmt.js +45 -7
- package/dist/compiler/TirCompiler/expressify/expressifyVars.d.ts +0 -1
- package/dist/compiler/TirCompiler/expressify/expressifyVars.js +49 -15
- package/dist/compiler/test/TestResult.d.ts +38 -0
- package/dist/compiler/test/TestResult.js +6 -0
- package/dist/compiler/test/fuzz/PRNG.d.ts +26 -0
- package/dist/compiler/test/fuzz/PRNG.js +59 -0
- package/dist/compiler/tir/expressions/TirCaseExpr.d.ts +9 -0
- package/dist/compiler/tir/expressions/TirCaseExpr.js +144 -122
- package/dist/compiler/tir/expressions/TirElemAccessExpr.js +2 -2
- package/dist/compiler/tir/expressions/TirExpr.d.ts +2 -1
- package/dist/compiler/tir/expressions/TirExpr.js +2 -0
- package/dist/compiler/tir/expressions/TirFromDataExpr.js +102 -67
- package/dist/compiler/tir/expressions/TirIsExpr.js +14 -1
- package/dist/compiler/tir/expressions/TirNativeFunc.d.ts +18 -2
- package/dist/compiler/tir/expressions/TirNativeFunc.js +55 -118
- package/dist/compiler/tir/expressions/TirShowExpr.d.ts +52 -0
- package/dist/compiler/tir/expressions/TirShowExpr.js +199 -0
- package/dist/compiler/tir/expressions/TirToDataExpr.js +3 -0
- package/dist/compiler/tir/expressions/TirTraceExpr.js +11 -7
- package/dist/compiler/tir/expressions/TirTypeConversionExpr.js +10 -0
- package/dist/compiler/tir/expressions/TirVariableAccessExpr.d.ts +2 -3
- package/dist/compiler/tir/expressions/TirVariableAccessExpr.js +1 -4
- package/dist/compiler/tir/expressions/ToIRTermCtx.d.ts +20 -3
- package/dist/compiler/tir/expressions/ToIRTermCtx.js +48 -3
- package/dist/compiler/tir/expressions/binary/TirBinaryExpr.d.ts +2 -2
- package/dist/compiler/tir/expressions/binary/TirBinaryExpr.js +45 -8
- package/dist/compiler/tir/expressions/litteral/TirLitEnumMemberExpr.d.ts +19 -0
- package/dist/compiler/tir/expressions/litteral/TirLitEnumMemberExpr.js +24 -0
- package/dist/compiler/tir/expressions/litteral/TirLitteralExpr.d.ts +2 -1
- package/dist/compiler/tir/expressions/litteral/TirLitteralExpr.js +2 -0
- package/dist/compiler/tir/expressions/unary/TirUnaryMinus.js +4 -1
- package/dist/compiler/tir/program/TypedProgram.d.ts +101 -0
- package/dist/compiler/tir/program/TypedProgram.js +43 -0
- package/dist/compiler/tir/program/stdScope/populateBuiltinInterfaces.d.ts +17 -0
- package/dist/compiler/tir/program/stdScope/populateBuiltinInterfaces.js +70 -0
- package/dist/compiler/tir/program/stdScope/populateStdNamespace.d.ts +22 -0
- package/dist/compiler/tir/program/stdScope/populateStdNamespace.js +619 -0
- package/dist/compiler/tir/program/stdScope/prelude/preludeTypesSrc.js +35 -2
- package/dist/compiler/tir/program/stdScope/stdScope.d.ts +8 -0
- package/dist/compiler/tir/program/stdScope/stdScope.js +84 -41
- package/dist/compiler/tir/statements/TirStmt.js +0 -1
- package/dist/compiler/tir/statements/TirTestStmt.d.ts +46 -0
- package/dist/compiler/tir/statements/TirTestStmt.js +35 -0
- package/dist/compiler/tir/types/TirEnumType.d.ts +21 -0
- package/dist/compiler/tir/types/TirEnumType.js +36 -0
- package/dist/compiler/tir/types/TirNativeType/TirNativeType.d.ts +53 -2
- package/dist/compiler/tir/types/TirNativeType/TirNativeType.js +58 -1
- package/dist/compiler/tir/types/TirNativeType/native/array.d.ts +16 -0
- package/dist/compiler/tir/types/TirNativeType/native/array.js +38 -0
- package/dist/compiler/tir/types/TirNativeType/native/index.d.ts +2 -0
- package/dist/compiler/tir/types/TirNativeType/native/index.js +2 -0
- package/dist/compiler/tir/types/TirNativeType/native/value.d.ts +18 -0
- package/dist/compiler/tir/types/TirNativeType/native/value.js +17 -0
- package/dist/compiler/tir/types/TirStructType.js +6 -1
- package/dist/compiler/tir/types/TirType.d.ts +3 -2
- package/dist/compiler/tir/types/TirType.js +7 -2
- package/dist/compiler/tir/types/utils/canAssignTo.js +36 -1
- package/dist/compiler/tir/types/utils/canCastTo.js +14 -1
- package/dist/compiler/tir/types/utils/getDeconstructableType.d.ts +2 -1
- package/dist/compiler/tir/types/utils/getDeconstructableType.js +2 -0
- package/dist/compiler/tir/types/utils/inferTypeArgs.d.ts +19 -0
- package/dist/compiler/tir/types/utils/inferTypeArgs.js +83 -0
- package/dist/compiler/tir/types/utils/normalizeEnumToInt.d.ts +10 -0
- package/dist/compiler/tir/types/utils/normalizeEnumToInt.js +17 -0
- package/dist/compiler/tir/types/utils/substituteTypeParams.d.ts +9 -0
- package/dist/compiler/tir/types/utils/substituteTypeParams.js +67 -0
- package/dist/diagnostics/diagnosticMessages.generated.d.ts +10 -0
- package/dist/diagnostics/diagnosticMessages.generated.js +20 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +2 -0
- package/dist/parser/Parser.d.ts +73 -3
- package/dist/parser/Parser.js +362 -46
- package/dist/tokenizer/Token.d.ts +106 -102
- package/dist/tokenizer/Token.js +111 -109
- package/dist/tokenizer/utils/tokenFromKeyword.js +11 -6
- package/dist/utils/semverSatisfies.d.ts +1 -0
- package/dist/utils/semverSatisfies.js +161 -0
- package/dist/version.generated.d.ts +1 -0
- package/dist/version.generated.js +2 -0
- package/package.json +5 -4
- package/dist/IR/tree_utils/_ir_lazyChooseList.d.ts +0 -3
- package/dist/IR/tree_utils/_ir_lazyChooseList.js +0 -7
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { constT } from "@harmoniclabs/uplc";
|
|
2
|
+
export class TirValueT {
|
|
3
|
+
clone() { return new TirValueT(); }
|
|
4
|
+
isConcrete() { return true; }
|
|
5
|
+
toString() { return "Value"; }
|
|
6
|
+
toAstName() { return "Value"; }
|
|
7
|
+
static toTirTypeKey() { return "Value"; }
|
|
8
|
+
toTirTypeKey() { return TirValueT.toTirTypeKey(); }
|
|
9
|
+
toConcreteTirTypeName() { return this.toTirTypeKey(); }
|
|
10
|
+
/**
|
|
11
|
+
* Native `Value` is bidirectionally reachable from `data` via
|
|
12
|
+
* `unValueData` / `valueData`, so it qualifies as data-encoded for
|
|
13
|
+
* the purposes of `data struct` field types.
|
|
14
|
+
*/
|
|
15
|
+
hasDataEncoding() { return true; }
|
|
16
|
+
toUplcConstType() { return constT.value; }
|
|
17
|
+
}
|
|
@@ -27,7 +27,12 @@ export class TirDataStructType {
|
|
|
27
27
|
this.constructors = constructors;
|
|
28
28
|
this.methodNamesPtr = methodNamesPtr;
|
|
29
29
|
this.untagged = untagged;
|
|
30
|
-
|
|
30
|
+
// `untagged === true` requires a single constructor — its runtime
|
|
31
|
+
// form is `listData(fields)` instead of `constrData(idx, fields)`.
|
|
32
|
+
if (untagged && constructors.length !== 1) {
|
|
33
|
+
throw new Error("untagged data struct must have exactly one constructor; got "
|
|
34
|
+
+ constructors.length);
|
|
35
|
+
}
|
|
31
36
|
this.narrowedFromParentCtorIdxs = narrowedFromParentCtorIdxs;
|
|
32
37
|
}
|
|
33
38
|
hasDataEncoding() { return true; }
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { TirAliasType } from "./TirAliasType.js";
|
|
2
2
|
import { TirStructType } from "./TirStructType.js";
|
|
3
|
+
import { TirEnumType } from "./TirEnumType.js";
|
|
3
4
|
import { TirNamedDestructableNativeType, TirNativeType } from "./TirNativeType/TirNativeType.js";
|
|
4
5
|
import { TirTypeParam } from "./TirTypeParam.js";
|
|
5
6
|
import { ConstType } from "@harmoniclabs/uplc";
|
|
@@ -28,7 +29,7 @@ export interface ITirType {
|
|
|
28
29
|
}
|
|
29
30
|
export type TirType = TirNativeType | TirCustomType | TirTypeParam;
|
|
30
31
|
export declare function isTirType(thing: any): thing is TirType;
|
|
31
|
-
export type TirCustomType = TirAliasType | TirStructType;
|
|
32
|
+
export type TirCustomType = TirAliasType | TirStructType | TirEnumType;
|
|
32
33
|
export declare function isTirCustomType(thing: any): thing is TirCustomType;
|
|
33
|
-
export type TirNamedDestructableType = TirNamedDestructableNativeType | TirStructType;
|
|
34
|
+
export type TirNamedDestructableType = TirNamedDestructableNativeType | TirStructType | TirEnumType;
|
|
34
35
|
export declare function isTirNamedDestructableType(thing: any): thing is TirNamedDestructableType;
|
|
@@ -1,16 +1,21 @@
|
|
|
1
1
|
import { isObject } from "@harmoniclabs/obj-utils";
|
|
2
2
|
import { TirAliasType } from "./TirAliasType.js";
|
|
3
3
|
import { isTirStructType } from "./TirStructType.js";
|
|
4
|
+
import { isTirEnumType } from "./TirEnumType.js";
|
|
4
5
|
import { isTirNamedDestructableNativeType, isTirNativeType } from "./TirNativeType/TirNativeType.js";
|
|
6
|
+
import { TirTypeParam } from "./TirTypeParam.js";
|
|
5
7
|
export function isTirType(thing) {
|
|
6
8
|
return isObject(thing) && (isTirNativeType(thing)
|
|
7
|
-
|| isTirCustomType(thing)
|
|
9
|
+
|| isTirCustomType(thing)
|
|
10
|
+
|| thing instanceof TirTypeParam);
|
|
8
11
|
}
|
|
9
12
|
export function isTirCustomType(thing) {
|
|
10
13
|
return isObject(thing) && (thing instanceof TirAliasType
|
|
11
|
-
|| isTirStructType(thing)
|
|
14
|
+
|| isTirStructType(thing)
|
|
15
|
+
|| isTirEnumType(thing));
|
|
12
16
|
}
|
|
13
17
|
export function isTirNamedDestructableType(thing) {
|
|
14
18
|
return isObject(thing) && (isTirStructType(thing)
|
|
19
|
+
|| isTirEnumType(thing)
|
|
15
20
|
|| isTirNamedDestructableNativeType(thing));
|
|
16
21
|
}
|
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import { TirAliasType } from "../TirAliasType.js";
|
|
2
|
-
import { TirUnConstrDataResultT, TirPairDataT } from "../TirNativeType/index.js";
|
|
2
|
+
import { TirBlsG1T, TirBlsG2T, TirMlResultT, TirUnConstrDataResultT, TirPairDataT } from "../TirNativeType/index.js";
|
|
3
3
|
import { TirBoolT } from "../TirNativeType/native/bool.js";
|
|
4
4
|
import { TirBytesT } from "../TirNativeType/native/bytes.js";
|
|
5
5
|
import { TirDataT } from "../TirNativeType/native/data.js";
|
|
6
6
|
import { TirFuncT } from "../TirNativeType/native/function.js";
|
|
7
7
|
import { TirIntT } from "../TirNativeType/native/int.js";
|
|
8
|
+
import { TirArrayT } from "../TirNativeType/native/array.js";
|
|
9
|
+
import { TirValueT } from "../TirNativeType/native/value.js";
|
|
8
10
|
import { TirLinearMapT } from "../TirNativeType/native/linearMap.js";
|
|
9
11
|
import { TirLinearMapEntryT } from "../TirNativeType/native/linearMapEntry.js";
|
|
10
12
|
import { TirListT } from "../TirNativeType/native/list.js";
|
|
@@ -13,6 +15,7 @@ import { TirSopOptT } from "../TirNativeType/native/Optional/sop.js";
|
|
|
13
15
|
import { TirStringT } from "../TirNativeType/native/string.js";
|
|
14
16
|
import { TirVoidT } from "../TirNativeType/native/void.js";
|
|
15
17
|
import { isTirStructType, TirDataStructType, TirSoPStructType } from "../TirStructType.js";
|
|
18
|
+
import { TirEnumType } from "../TirEnumType.js";
|
|
16
19
|
import { isTirNamedDestructableType } from "../TirType.js";
|
|
17
20
|
import { TirTypeParam } from "../TirTypeParam.js";
|
|
18
21
|
import { canCastToData } from "./canCastTo.js";
|
|
@@ -108,6 +111,10 @@ function uncheckedGetCanAssign(a, b, symbols) {
|
|
|
108
111
|
if (b instanceof TirIntT) {
|
|
109
112
|
if (a instanceof TirIntT)
|
|
110
113
|
return CanAssign.Yes;
|
|
114
|
+
// enum runtime representation is a plain int, so an enum value can
|
|
115
|
+
// flow directly into any int operation.
|
|
116
|
+
if (a instanceof TirEnumType)
|
|
117
|
+
return CanAssign.Yes;
|
|
111
118
|
if (a instanceof TirDataT)
|
|
112
119
|
return CanAssign.RequiresExplicitCast;
|
|
113
120
|
return CanAssign.No;
|
|
@@ -218,6 +225,19 @@ function uncheckedGetCanAssign(a, b, symbols) {
|
|
|
218
225
|
}
|
|
219
226
|
if (isTirStructType(a))
|
|
220
227
|
return CanAssign.No;
|
|
228
|
+
if (b instanceof TirEnumType) {
|
|
229
|
+
if (a instanceof TirEnumType
|
|
230
|
+
&& a.toTirTypeKey() === b.toTirTypeKey())
|
|
231
|
+
return CanAssign.Yes;
|
|
232
|
+
// `data` (e.g. datum/redeemer) can be decoded to an enum with an
|
|
233
|
+
// explicit cast; plain `int` cannot — there is no way to statically
|
|
234
|
+
// verify it is a valid tag.
|
|
235
|
+
if (a instanceof TirDataT)
|
|
236
|
+
return CanAssign.RequiresExplicitCast;
|
|
237
|
+
return CanAssign.No;
|
|
238
|
+
}
|
|
239
|
+
if (a instanceof TirEnumType)
|
|
240
|
+
return CanAssign.No;
|
|
221
241
|
if (b instanceof TirFuncT) {
|
|
222
242
|
if (!(a instanceof TirFuncT
|
|
223
243
|
&& a.argTypes.length === b.argTypes.length))
|
|
@@ -232,6 +252,21 @@ function uncheckedGetCanAssign(a, b, symbols) {
|
|
|
232
252
|
}
|
|
233
253
|
return currentDecision;
|
|
234
254
|
}
|
|
255
|
+
// BLS / ML-result are opaque atomic types: assignable only to themselves
|
|
256
|
+
if (b instanceof TirBlsG1T)
|
|
257
|
+
return a instanceof TirBlsG1T ? CanAssign.Yes : CanAssign.No;
|
|
258
|
+
if (b instanceof TirBlsG2T)
|
|
259
|
+
return a instanceof TirBlsG2T ? CanAssign.Yes : CanAssign.No;
|
|
260
|
+
if (b instanceof TirMlResultT)
|
|
261
|
+
return a instanceof TirMlResultT ? CanAssign.Yes : CanAssign.No;
|
|
262
|
+
// Native Value / Array<T>
|
|
263
|
+
if (b instanceof TirValueT)
|
|
264
|
+
return a instanceof TirValueT ? CanAssign.Yes : CanAssign.No;
|
|
265
|
+
if (b instanceof TirArrayT) {
|
|
266
|
+
if (!(a instanceof TirArrayT))
|
|
267
|
+
return CanAssign.No;
|
|
268
|
+
return uncheckedGetCanAssign(a.typeArg, b.typeArg, symbols);
|
|
269
|
+
}
|
|
235
270
|
const tsEnsureExhautstiveCheck = b;
|
|
236
271
|
return CanAssign.No;
|
|
237
272
|
}
|
|
@@ -12,6 +12,7 @@ import { TirSopOptT } from "../TirNativeType/native/Optional/sop.js";
|
|
|
12
12
|
import { TirStringT } from "../TirNativeType/native/string.js";
|
|
13
13
|
import { TirVoidT } from "../TirNativeType/native/void.js";
|
|
14
14
|
import { isTirStructType, TirDataStructType } from "../TirStructType.js";
|
|
15
|
+
import { TirEnumType } from "../TirEnumType.js";
|
|
15
16
|
import { CanAssign, getCanAssign } from "./canAssignTo.js";
|
|
16
17
|
export function canCastTo(a, b) {
|
|
17
18
|
if (!(a.isConcrete()
|
|
@@ -52,6 +53,8 @@ export function canCastTo(a, b) {
|
|
|
52
53
|
if (b instanceof TirIntT) {
|
|
53
54
|
if (a instanceof TirIntT)
|
|
54
55
|
return true;
|
|
56
|
+
if (a instanceof TirEnumType)
|
|
57
|
+
return true; // enum is an int at runtime
|
|
55
58
|
if (a instanceof TirDataT)
|
|
56
59
|
return true;
|
|
57
60
|
if (a instanceof TirBoolT)
|
|
@@ -113,6 +116,15 @@ export function canCastTo(a, b) {
|
|
|
113
116
|
}
|
|
114
117
|
return false;
|
|
115
118
|
}
|
|
119
|
+
if (b instanceof TirEnumType) {
|
|
120
|
+
if (a instanceof TirEnumType)
|
|
121
|
+
return a.toTirTypeKey() === b.toTirTypeKey();
|
|
122
|
+
// only `data` (e.g. datum/redeemer decoding) can be cast to enum;
|
|
123
|
+
// plain `int` cannot — there is no way to verify it is a valid tag.
|
|
124
|
+
if (a instanceof TirDataT)
|
|
125
|
+
return true;
|
|
126
|
+
return false;
|
|
127
|
+
}
|
|
116
128
|
if (b instanceof TirFuncT) {
|
|
117
129
|
if (!(a instanceof TirFuncT))
|
|
118
130
|
return false;
|
|
@@ -148,7 +160,8 @@ export function canCastToData(a) {
|
|
|
148
160
|
|| a instanceof TirStringT
|
|
149
161
|
|| a instanceof TirBoolT
|
|
150
162
|
|| a instanceof TirDataOptT
|
|
151
|
-
|| a instanceof TirDataStructType
|
|
163
|
+
|| a instanceof TirDataStructType
|
|
164
|
+
|| a instanceof TirEnumType)
|
|
152
165
|
return true;
|
|
153
166
|
if (a instanceof TirLinearMapT) {
|
|
154
167
|
const key = canCastToData(a.keyTypeArg);
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { TirEnumType } from "../TirEnumType.js";
|
|
1
2
|
import { TirDataT } from "../TirNativeType/native/data.js";
|
|
2
3
|
import { TirLinearMapT } from "../TirNativeType/native/linearMap.js";
|
|
3
4
|
import { TirListT } from "../TirNativeType/native/list.js";
|
|
@@ -5,5 +6,5 @@ import { TirDataOptT } from "../TirNativeType/native/Optional/data.js";
|
|
|
5
6
|
import { TirSopOptT } from "../TirNativeType/native/Optional/sop.js";
|
|
6
7
|
import { TirStructType } from "../TirStructType.js";
|
|
7
8
|
import { TirType } from "../TirType.js";
|
|
8
|
-
export type DeconstructableTirType = TirStructType | TirSopOptT | TirDataOptT | TirListT | TirLinearMapT | TirDataT;
|
|
9
|
+
export type DeconstructableTirType = TirStructType | TirEnumType | TirSopOptT | TirDataOptT | TirListT | TirLinearMapT | TirDataT;
|
|
9
10
|
export declare function getDeconstructableType(type: TirType): DeconstructableTirType | undefined;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { TirAliasType } from "../TirAliasType.js";
|
|
2
|
+
import { TirEnumType } from "../TirEnumType.js";
|
|
2
3
|
import { TirDataT } from "../TirNativeType/native/data.js";
|
|
3
4
|
import { TirLinearMapT } from "../TirNativeType/native/linearMap.js";
|
|
4
5
|
import { TirListT } from "../TirNativeType/native/list.js";
|
|
@@ -9,6 +10,7 @@ export function getDeconstructableType(type) {
|
|
|
9
10
|
while (type instanceof TirAliasType)
|
|
10
11
|
type = type.aliased;
|
|
11
12
|
if (isTirStructType(type)
|
|
13
|
+
|| type instanceof TirEnumType
|
|
12
14
|
|| type instanceof TirSopOptT
|
|
13
15
|
|| type instanceof TirDataOptT
|
|
14
16
|
|| type instanceof TirListT
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { TirType } from "../TirType.js";
|
|
2
|
+
/**
|
|
3
|
+
* Attempt to bind free `TirTypeParam`s in `formal` so that the result matches
|
|
4
|
+
* `actual`. Bindings are accumulated into `env`. Returns `true` on success.
|
|
5
|
+
*
|
|
6
|
+
* - Inconsistent bindings (`T = int` then `T = bytes`) cause failure.
|
|
7
|
+
* - Shape mismatches between concrete containers cause failure.
|
|
8
|
+
* - Unknown type-params in `formal` not yet in `env` are bound to `actual`'s
|
|
9
|
+
* matching position.
|
|
10
|
+
*
|
|
11
|
+
* This is intentionally syntactic — no subtyping, no widening. The caller
|
|
12
|
+
* passes already-unaliased argument types.
|
|
13
|
+
*/
|
|
14
|
+
export declare function inferTypeArgs(formal: TirType, actual: TirType, env: Map<symbol, TirType>): boolean;
|
|
15
|
+
/**
|
|
16
|
+
* Cheap structural equality for unaliased TirTypes — compares concrete TIR
|
|
17
|
+
* names. Sufficient for our inference consistency checks.
|
|
18
|
+
*/
|
|
19
|
+
export declare function tirTypeStructurallyEqual(a: TirType, b: TirType): boolean;
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { TirArrayT } from "../TirNativeType/native/array.js";
|
|
2
|
+
import { TirFuncT } from "../TirNativeType/native/function.js";
|
|
3
|
+
import { TirLinearMapT } from "../TirNativeType/native/linearMap.js";
|
|
4
|
+
import { TirLinearMapEntryT } from "../TirNativeType/native/linearMapEntry.js";
|
|
5
|
+
import { TirListT } from "../TirNativeType/native/list.js";
|
|
6
|
+
import { TirDataOptT } from "../TirNativeType/native/Optional/data.js";
|
|
7
|
+
import { TirSopOptT } from "../TirNativeType/native/Optional/sop.js";
|
|
8
|
+
import { TirTypeParam } from "../TirTypeParam.js";
|
|
9
|
+
import { getUnaliased } from "./getUnaliased.js";
|
|
10
|
+
/**
|
|
11
|
+
* Attempt to bind free `TirTypeParam`s in `formal` so that the result matches
|
|
12
|
+
* `actual`. Bindings are accumulated into `env`. Returns `true` on success.
|
|
13
|
+
*
|
|
14
|
+
* - Inconsistent bindings (`T = int` then `T = bytes`) cause failure.
|
|
15
|
+
* - Shape mismatches between concrete containers cause failure.
|
|
16
|
+
* - Unknown type-params in `formal` not yet in `env` are bound to `actual`'s
|
|
17
|
+
* matching position.
|
|
18
|
+
*
|
|
19
|
+
* This is intentionally syntactic — no subtyping, no widening. The caller
|
|
20
|
+
* passes already-unaliased argument types.
|
|
21
|
+
*/
|
|
22
|
+
export function inferTypeArgs(formal, actual, env) {
|
|
23
|
+
formal = getUnaliased(formal);
|
|
24
|
+
actual = getUnaliased(actual);
|
|
25
|
+
if (formal instanceof TirTypeParam) {
|
|
26
|
+
const existing = env.get(formal.symbol);
|
|
27
|
+
if (existing === undefined) {
|
|
28
|
+
env.set(formal.symbol, actual);
|
|
29
|
+
return true;
|
|
30
|
+
}
|
|
31
|
+
// consistency: existing binding must equal actual
|
|
32
|
+
return tirTypeStructurallyEqual(existing, actual);
|
|
33
|
+
}
|
|
34
|
+
// both must be the same shape and equal in arg-positions
|
|
35
|
+
if (formal instanceof TirListT && actual instanceof TirListT) {
|
|
36
|
+
return inferTypeArgs(formal.typeArg, actual.typeArg, env);
|
|
37
|
+
}
|
|
38
|
+
if (formal instanceof TirArrayT && actual instanceof TirArrayT) {
|
|
39
|
+
return inferTypeArgs(formal.typeArg, actual.typeArg, env);
|
|
40
|
+
}
|
|
41
|
+
if (formal instanceof TirFuncT && actual instanceof TirFuncT) {
|
|
42
|
+
if (formal.argTypes.length !== actual.argTypes.length)
|
|
43
|
+
return false;
|
|
44
|
+
for (let i = 0; i < formal.argTypes.length; i++) {
|
|
45
|
+
if (!inferTypeArgs(formal.argTypes[i], actual.argTypes[i], env))
|
|
46
|
+
return false;
|
|
47
|
+
}
|
|
48
|
+
return inferTypeArgs(formal.returnType, actual.returnType, env);
|
|
49
|
+
}
|
|
50
|
+
if (formal instanceof TirLinearMapT && actual instanceof TirLinearMapT) {
|
|
51
|
+
return (inferTypeArgs(formal.keyTypeArg, actual.keyTypeArg, env)
|
|
52
|
+
&& inferTypeArgs(formal.valTypeArg, actual.valTypeArg, env));
|
|
53
|
+
}
|
|
54
|
+
if (formal instanceof TirLinearMapEntryT && actual instanceof TirLinearMapEntryT) {
|
|
55
|
+
return (inferTypeArgs(formal.keyTypeArg, actual.keyTypeArg, env)
|
|
56
|
+
&& inferTypeArgs(formal.valTypeArg, actual.valTypeArg, env));
|
|
57
|
+
}
|
|
58
|
+
if (formal instanceof TirDataOptT && actual instanceof TirDataOptT) {
|
|
59
|
+
return inferTypeArgs(formal.typeArg, actual.typeArg, env);
|
|
60
|
+
}
|
|
61
|
+
if (formal instanceof TirSopOptT && actual instanceof TirSopOptT) {
|
|
62
|
+
return inferTypeArgs(formal.typeArg, actual.typeArg, env);
|
|
63
|
+
}
|
|
64
|
+
// base case: both concrete with no type-vars — must be the same type
|
|
65
|
+
return tirTypeStructurallyEqual(formal, actual);
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Cheap structural equality for unaliased TirTypes — compares concrete TIR
|
|
69
|
+
* names. Sufficient for our inference consistency checks.
|
|
70
|
+
*/
|
|
71
|
+
export function tirTypeStructurallyEqual(a, b) {
|
|
72
|
+
a = getUnaliased(a);
|
|
73
|
+
b = getUnaliased(b);
|
|
74
|
+
if (a instanceof TirTypeParam && b instanceof TirTypeParam) {
|
|
75
|
+
return a.symbol === b.symbol;
|
|
76
|
+
}
|
|
77
|
+
try {
|
|
78
|
+
return a.toConcreteTirTypeName() === b.toConcreteTirTypeName();
|
|
79
|
+
}
|
|
80
|
+
catch {
|
|
81
|
+
return false;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { TirIntT } from "../TirNativeType/native/int.js";
|
|
2
|
+
import { TirType } from "../TirType.js";
|
|
3
|
+
/**
|
|
4
|
+
* If `t` is an enum type (or alias of one), returns the shared `int` type
|
|
5
|
+
* (since enums lower to plain ints at runtime). Otherwise returns `t`.
|
|
6
|
+
*
|
|
7
|
+
* Use this to relax type checks for binary operators that treat enums as
|
|
8
|
+
* integers (arithmetic, comparison, equality).
|
|
9
|
+
*/
|
|
10
|
+
export declare function normalizeEnumToInt(t: TirType, int_t: TirIntT): TirType;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { TirAliasType } from "../TirAliasType.js";
|
|
2
|
+
import { TirEnumType } from "../TirEnumType.js";
|
|
3
|
+
/**
|
|
4
|
+
* If `t` is an enum type (or alias of one), returns the shared `int` type
|
|
5
|
+
* (since enums lower to plain ints at runtime). Otherwise returns `t`.
|
|
6
|
+
*
|
|
7
|
+
* Use this to relax type checks for binary operators that treat enums as
|
|
8
|
+
* integers (arithmetic, comparison, equality).
|
|
9
|
+
*/
|
|
10
|
+
export function normalizeEnumToInt(t, int_t) {
|
|
11
|
+
let probe = t;
|
|
12
|
+
while (probe instanceof TirAliasType)
|
|
13
|
+
probe = probe.aliased;
|
|
14
|
+
if (probe instanceof TirEnumType)
|
|
15
|
+
return int_t;
|
|
16
|
+
return t;
|
|
17
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { TirType } from "../TirType.js";
|
|
2
|
+
/**
|
|
3
|
+
* Walk a TirType tree and replace each `TirTypeParam` whose `symbol` is a key
|
|
4
|
+
* in `subst` with the corresponding concrete type. Containers (`List`, `Func`,
|
|
5
|
+
* `LinearMap`, optionals, aliases) are rebuilt with their substituted children.
|
|
6
|
+
*
|
|
7
|
+
* Returns the input unchanged when no substitution applies.
|
|
8
|
+
*/
|
|
9
|
+
export declare function substituteTypeParams(t: TirType, subst: Map<symbol, TirType>): TirType;
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { TirAliasType } from "../TirAliasType.js";
|
|
2
|
+
import { TirArrayT } from "../TirNativeType/native/array.js";
|
|
3
|
+
import { TirFuncT } from "../TirNativeType/native/function.js";
|
|
4
|
+
import { TirLinearMapT } from "../TirNativeType/native/linearMap.js";
|
|
5
|
+
import { TirLinearMapEntryT } from "../TirNativeType/native/linearMapEntry.js";
|
|
6
|
+
import { TirListT } from "../TirNativeType/native/list.js";
|
|
7
|
+
import { TirDataOptT } from "../TirNativeType/native/Optional/data.js";
|
|
8
|
+
import { TirSopOptT } from "../TirNativeType/native/Optional/sop.js";
|
|
9
|
+
import { TirTypeParam } from "../TirTypeParam.js";
|
|
10
|
+
/**
|
|
11
|
+
* Walk a TirType tree and replace each `TirTypeParam` whose `symbol` is a key
|
|
12
|
+
* in `subst` with the corresponding concrete type. Containers (`List`, `Func`,
|
|
13
|
+
* `LinearMap`, optionals, aliases) are rebuilt with their substituted children.
|
|
14
|
+
*
|
|
15
|
+
* Returns the input unchanged when no substitution applies.
|
|
16
|
+
*/
|
|
17
|
+
export function substituteTypeParams(t, subst) {
|
|
18
|
+
if (subst.size === 0)
|
|
19
|
+
return t;
|
|
20
|
+
if (t instanceof TirTypeParam) {
|
|
21
|
+
return subst.get(t.symbol) ?? t;
|
|
22
|
+
}
|
|
23
|
+
if (t instanceof TirListT) {
|
|
24
|
+
const sub = substituteTypeParams(t.typeArg, subst);
|
|
25
|
+
return sub === t.typeArg ? t : new TirListT(sub);
|
|
26
|
+
}
|
|
27
|
+
if (t instanceof TirArrayT) {
|
|
28
|
+
const sub = substituteTypeParams(t.typeArg, subst);
|
|
29
|
+
return sub === t.typeArg ? t : new TirArrayT(sub);
|
|
30
|
+
}
|
|
31
|
+
if (t instanceof TirFuncT) {
|
|
32
|
+
let changed = false;
|
|
33
|
+
const newArgs = t.argTypes.map(a => {
|
|
34
|
+
const s = substituteTypeParams(a, subst);
|
|
35
|
+
if (s !== a)
|
|
36
|
+
changed = true;
|
|
37
|
+
return s;
|
|
38
|
+
});
|
|
39
|
+
const newRet = substituteTypeParams(t.returnType, subst);
|
|
40
|
+
if (newRet !== t.returnType)
|
|
41
|
+
changed = true;
|
|
42
|
+
return changed ? new TirFuncT(newArgs, newRet) : t;
|
|
43
|
+
}
|
|
44
|
+
if (t instanceof TirLinearMapT) {
|
|
45
|
+
const k = substituteTypeParams(t.keyTypeArg, subst);
|
|
46
|
+
const v = substituteTypeParams(t.valTypeArg, subst);
|
|
47
|
+
return (k === t.keyTypeArg && v === t.valTypeArg) ? t : new TirLinearMapT(k, v);
|
|
48
|
+
}
|
|
49
|
+
if (t instanceof TirLinearMapEntryT) {
|
|
50
|
+
const k = substituteTypeParams(t.keyTypeArg, subst);
|
|
51
|
+
const v = substituteTypeParams(t.valTypeArg, subst);
|
|
52
|
+
return (k === t.keyTypeArg && v === t.valTypeArg) ? t : new TirLinearMapEntryT(k, v);
|
|
53
|
+
}
|
|
54
|
+
if (t instanceof TirDataOptT) {
|
|
55
|
+
const sub = substituteTypeParams(t.typeArg, subst);
|
|
56
|
+
return sub === t.typeArg ? t : new TirDataOptT(sub);
|
|
57
|
+
}
|
|
58
|
+
if (t instanceof TirSopOptT) {
|
|
59
|
+
const sub = substituteTypeParams(t.typeArg, subst);
|
|
60
|
+
return sub === t.typeArg ? t : new TirSopOptT(sub);
|
|
61
|
+
}
|
|
62
|
+
if (t instanceof TirAliasType) {
|
|
63
|
+
const sub = substituteTypeParams(t.aliased, subst);
|
|
64
|
+
return sub === t.aliased ? t : sub;
|
|
65
|
+
}
|
|
66
|
+
return t;
|
|
67
|
+
}
|
|
@@ -278,6 +278,16 @@ export declare enum DiagnosticCode {
|
|
|
278
278
|
_super_must_be_called_before_accessing_this_in_the_constructor_of_a_derived_class = 17009,
|
|
279
279
|
_super_must_be_called_before_accessing_a_property_of_super_in_the_constructor_of_a_derived_class = 17011,
|
|
280
280
|
Unkonwn_AST_node = 20000,
|
|
281
|
+
Namespace_0_has_no_exported_member_1 = 30001,
|
|
282
|
+
Namespace_path_is_incomplete_expected_a_value_type_function_or_interface = 30002,
|
|
283
|
+
_private_modifier_is_only_allowed_on_declarations_inside_a_namespace = 30003,
|
|
284
|
+
Namespaces_cannot_be_declared_here = 30004,
|
|
285
|
+
_0_is_not_a_namespace = 30005,
|
|
286
|
+
Enum_members_cannot_have_explicit_values = 30100,
|
|
287
|
+
Duplicate_enum_member_0 = 30101,
|
|
288
|
+
Enum_must_have_at_least_one_member = 30102,
|
|
289
|
+
Property_0_is_not_a_member_of_enum_1 = 30103,
|
|
290
|
+
Enum_member_pattern_cannot_have_fields = 30104,
|
|
281
291
|
Dev_was_too_lazy_to_add_a_prooper_error_message_Something_went_wrong = 42069
|
|
282
292
|
}
|
|
283
293
|
/** Translates a diagnostic code to its respective string. */
|
|
@@ -280,6 +280,16 @@ export var DiagnosticCode;
|
|
|
280
280
|
DiagnosticCode[DiagnosticCode["_super_must_be_called_before_accessing_this_in_the_constructor_of_a_derived_class"] = 17009] = "_super_must_be_called_before_accessing_this_in_the_constructor_of_a_derived_class";
|
|
281
281
|
DiagnosticCode[DiagnosticCode["_super_must_be_called_before_accessing_a_property_of_super_in_the_constructor_of_a_derived_class"] = 17011] = "_super_must_be_called_before_accessing_a_property_of_super_in_the_constructor_of_a_derived_class";
|
|
282
282
|
DiagnosticCode[DiagnosticCode["Unkonwn_AST_node"] = 20000] = "Unkonwn_AST_node";
|
|
283
|
+
DiagnosticCode[DiagnosticCode["Namespace_0_has_no_exported_member_1"] = 30001] = "Namespace_0_has_no_exported_member_1";
|
|
284
|
+
DiagnosticCode[DiagnosticCode["Namespace_path_is_incomplete_expected_a_value_type_function_or_interface"] = 30002] = "Namespace_path_is_incomplete_expected_a_value_type_function_or_interface";
|
|
285
|
+
DiagnosticCode[DiagnosticCode["_private_modifier_is_only_allowed_on_declarations_inside_a_namespace"] = 30003] = "_private_modifier_is_only_allowed_on_declarations_inside_a_namespace";
|
|
286
|
+
DiagnosticCode[DiagnosticCode["Namespaces_cannot_be_declared_here"] = 30004] = "Namespaces_cannot_be_declared_here";
|
|
287
|
+
DiagnosticCode[DiagnosticCode["_0_is_not_a_namespace"] = 30005] = "_0_is_not_a_namespace";
|
|
288
|
+
DiagnosticCode[DiagnosticCode["Enum_members_cannot_have_explicit_values"] = 30100] = "Enum_members_cannot_have_explicit_values";
|
|
289
|
+
DiagnosticCode[DiagnosticCode["Duplicate_enum_member_0"] = 30101] = "Duplicate_enum_member_0";
|
|
290
|
+
DiagnosticCode[DiagnosticCode["Enum_must_have_at_least_one_member"] = 30102] = "Enum_must_have_at_least_one_member";
|
|
291
|
+
DiagnosticCode[DiagnosticCode["Property_0_is_not_a_member_of_enum_1"] = 30103] = "Property_0_is_not_a_member_of_enum_1";
|
|
292
|
+
DiagnosticCode[DiagnosticCode["Enum_member_pattern_cannot_have_fields"] = 30104] = "Enum_member_pattern_cannot_have_fields";
|
|
283
293
|
DiagnosticCode[DiagnosticCode["Dev_was_too_lazy_to_add_a_prooper_error_message_Something_went_wrong"] = 42069] = "Dev_was_too_lazy_to_add_a_prooper_error_message_Something_went_wrong";
|
|
284
294
|
})(DiagnosticCode || (DiagnosticCode = {}));
|
|
285
295
|
/** Translates a diagnostic code to its respective string. */
|
|
@@ -563,6 +573,16 @@ export function diagnosticCodeToString(code) {
|
|
|
563
573
|
case 17009: return "'super' must be called before accessing 'this' in the constructor of a derived class.";
|
|
564
574
|
case 17011: return "'super' must be called before accessing a property of 'super' in the constructor of a derived class.";
|
|
565
575
|
case 20000: return "Unkonwn AST node.";
|
|
576
|
+
case 30001: return "Namespace '{0}' has no exported member '{1}'.";
|
|
577
|
+
case 30002: return "Namespace path is incomplete; expected a value, type, function, or interface.";
|
|
578
|
+
case 30003: return "'private' modifier is only allowed on declarations inside a namespace.";
|
|
579
|
+
case 30004: return "Namespaces cannot be declared here.";
|
|
580
|
+
case 30005: return "'{0}' is not a namespace.";
|
|
581
|
+
case 30100: return "Enum members cannot have explicit values.";
|
|
582
|
+
case 30101: return "Duplicate enum member '{0}'.";
|
|
583
|
+
case 30102: return "Enum must have at least one member.";
|
|
584
|
+
case 30103: return "Property '{0}' is not a member of enum '{1}'.";
|
|
585
|
+
case 30104: return "Enum member pattern cannot have fields.";
|
|
566
586
|
case 42069: return "Dev was too lazy to add a prooper error message. Something went wrong";
|
|
567
587
|
default: return "";
|
|
568
588
|
}
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
package/dist/parser/Parser.d.ts
CHANGED
|
@@ -12,7 +12,8 @@ import { SourceRange } from "../ast/Source/SourceRange.js";
|
|
|
12
12
|
import { SimpleVarDecl } from "../ast/nodes/statements/declarations/VarDecl/SimpleVarDecl.js";
|
|
13
13
|
import { ArrayLikeDeconstr } from "../ast/nodes/statements/declarations/VarDecl/ArrayLikeDeconstr.js";
|
|
14
14
|
import { ParentesizedExpr } from "../ast/nodes/expr/ParentesizedExpr.js";
|
|
15
|
-
import { FuncExpr } from "../ast/nodes/expr/functions/FuncExpr.js";
|
|
15
|
+
import { FuncExpr, TypeParamDecl } from "../ast/nodes/expr/functions/FuncExpr.js";
|
|
16
|
+
import { TemplateStrExpr } from "../ast/nodes/expr/litteral/TemplateStrExpr.js";
|
|
16
17
|
import { BlockStmt } from "../ast/nodes/statements/BlockStmt.js";
|
|
17
18
|
import { BreakStmt } from "../ast/nodes/statements/BreakStmt.js";
|
|
18
19
|
import { ContinueStmt } from "../ast/nodes/statements/ContinueStmt.js";
|
|
@@ -25,6 +26,7 @@ import { FailStmt } from "../ast/nodes/statements/FailStmt.js";
|
|
|
25
26
|
import { TraceStmt } from "../ast/nodes/statements/TraceStmt.js";
|
|
26
27
|
import { AssertStmt } from "../ast/nodes/statements/AssertStmt.js";
|
|
27
28
|
import { TestStmt } from "../ast/nodes/statements/TestStmt.js";
|
|
29
|
+
import { TestParam } from "../ast/nodes/statements/TestParam.js";
|
|
28
30
|
import { MatchStmt } from "../ast/nodes/statements/MatchStmt.js";
|
|
29
31
|
import { WhileStmt } from "../ast/nodes/statements/WhileStmt.js";
|
|
30
32
|
import { CaseExpr } from "../ast/nodes/expr/CaseExpr.js";
|
|
@@ -39,7 +41,8 @@ import { TypeAliasDecl } from "../ast/nodes/statements/declarations/TypeAliasDec
|
|
|
39
41
|
import { EnumDecl, EnumValueDecl } from "../ast/nodes/statements/declarations/EnumDecl.js";
|
|
40
42
|
import { AssignmentStmt } from "../ast/nodes/statements/AssignmentStmt.js";
|
|
41
43
|
import { AstTypeExpr } from "../ast/nodes/types/AstTypeExpr.js";
|
|
42
|
-
import { UsingStmt } from "../ast/nodes/statements/UsingStmt.js";
|
|
44
|
+
import { UsingAliasStmt, UsingPath, UsingRhs, UsingStmt } from "../ast/nodes/statements/UsingStmt.js";
|
|
45
|
+
import { NamespaceDecl, NamespaceMemberStmt } from "../ast/nodes/statements/declarations/NamespaceDecl.js";
|
|
43
46
|
import { BodyStmt, TopLevelStmt } from "../ast/nodes/statements/PebbleStmt.js";
|
|
44
47
|
import { Precedence } from "./Precedence.js";
|
|
45
48
|
import { ContractDecl } from "../ast/nodes/statements/declarations/ContractDecl.js";
|
|
@@ -57,8 +60,50 @@ export declare class Parser extends DiagnosticEmitter {
|
|
|
57
60
|
parseTopLevelStatement(): TopLevelStmt | undefined;
|
|
58
61
|
parseContractDecl(startPos: number): ContractDecl | undefined;
|
|
59
62
|
parseStateDecl(startPos: number): StateDecl | undefined;
|
|
60
|
-
parseUsingDecl(): UsingStmt | undefined;
|
|
63
|
+
parseUsingDecl(): UsingStmt | UsingAliasStmt | undefined;
|
|
64
|
+
/**
|
|
65
|
+
* parse a dotted chain of identifiers: `A`, `A.B`, `A.B.C`, ...
|
|
66
|
+
* used for namespace paths on the RHS of `using` statements.
|
|
67
|
+
*/
|
|
68
|
+
parseUsingPath(): UsingPath | undefined;
|
|
69
|
+
/**
|
|
70
|
+
* parse the RHS of `using { ... } = <rhs>;`:
|
|
71
|
+
* - if it begins with a native type keyword (or a generic struct
|
|
72
|
+
* with type args), it's parsed as `AstTypeExpr` (legacy
|
|
73
|
+
* struct-destructure behavior)
|
|
74
|
+
* - if it's a single identifier followed by `<`, it's also parsed as
|
|
75
|
+
* a generic type expression
|
|
76
|
+
* - otherwise, it's parsed as a dotted `UsingPath`
|
|
77
|
+
* (a namespace path; the compiler decides whether it's a struct
|
|
78
|
+
* type or a namespace based on what the head identifier resolves to)
|
|
79
|
+
*/
|
|
80
|
+
parseUsingRhs(): UsingRhs | undefined;
|
|
81
|
+
/**
|
|
82
|
+
* parse a namespace body: `{ (private? <member-decl>)* }`
|
|
83
|
+
*
|
|
84
|
+
* called with `namespace` already consumed; `startPos` is the position
|
|
85
|
+
* of the `namespace` keyword.
|
|
86
|
+
*/
|
|
87
|
+
parseNamespaceDecl(startPos: number): NamespaceDecl | undefined;
|
|
88
|
+
/**
|
|
89
|
+
* parse a single namespace body member. delegates to the relevant
|
|
90
|
+
* top-level-style parser based on the next token, but rejects
|
|
91
|
+
* declarations that aren't allowed inside a namespace body
|
|
92
|
+
* (no `export`, no `import`, no `using`, no `contract`, no `test`).
|
|
93
|
+
*/
|
|
94
|
+
parseNamespaceMember(): NamespaceMemberStmt | undefined;
|
|
61
95
|
parseTypeParameters(): Identifier[] | undefined;
|
|
96
|
+
/**
|
|
97
|
+
* Parses a function's type-parameter list with optional `implements`
|
|
98
|
+
* interface constraints:
|
|
99
|
+
* `<T, U implements ToData, V implements Foo>`
|
|
100
|
+
*
|
|
101
|
+
* Returns `TypeParamDecl[]` so the compiler can read each param's
|
|
102
|
+
* optional constraint at template-registration time. Struct/interface
|
|
103
|
+
* decls keep using the simpler {@link parseTypeParameters} which
|
|
104
|
+
* returns bare `Identifier[]`.
|
|
105
|
+
*/
|
|
106
|
+
parseFuncTypeParameters(): TypeParamDecl[] | undefined;
|
|
62
107
|
parseTypeArguments(): AstTypeExpr[] | undefined;
|
|
63
108
|
parseExport(startPos?: number): ExportImportStmt | ExportStarStmt | undefined;
|
|
64
109
|
parseTypeStmt(flags?: CommonFlags, startPos?: number): TypeAliasDecl | TypeImplementsStmt | undefined;
|
|
@@ -132,9 +177,34 @@ export declare class Parser extends DiagnosticEmitter {
|
|
|
132
177
|
parseIfStatement(): IfStmt | undefined;
|
|
133
178
|
parseReturn(): ReturnStmt | undefined;
|
|
134
179
|
parseTestStatement(): TestStmt | undefined;
|
|
180
|
+
/**
|
|
181
|
+
* Parses the parameter list of a `test` declaration:
|
|
182
|
+
* `( <id>: <type> ('via' <expr>)? (, <id>: <type> ('via' <expr>)? )* )?`
|
|
183
|
+
*
|
|
184
|
+
* Assumes the opening `(` has already been consumed by the caller.
|
|
185
|
+
* Consumes the closing `)` on success.
|
|
186
|
+
*
|
|
187
|
+
* `via` is recognised here ONLY — function/method/contract parameter
|
|
188
|
+
* parsing uses `parseParameters()` which never looks for `Token.Via`.
|
|
189
|
+
*/
|
|
190
|
+
parseTestParameters(): TestParam[] | undefined;
|
|
135
191
|
parseMatchStatement(): MatchStmt | undefined;
|
|
136
192
|
parseFailStatement(): FailStmt | undefined;
|
|
137
193
|
parseTraceStatement(): TraceStmt | undefined;
|
|
194
|
+
/**
|
|
195
|
+
* Parse a backtick-delimited template literal:
|
|
196
|
+
*
|
|
197
|
+
* `text ${expr1} more text ${expr2} ...`
|
|
198
|
+
*
|
|
199
|
+
* Tokenizer state: on entry, the current token is
|
|
200
|
+
* `Token.StringTemplateLiteralQuote`; the tokenizer is positioned at
|
|
201
|
+
* the opening backtick. `readString()` (called with no arg) consumes
|
|
202
|
+
* the backtick + the first fragment up to `${` or to the closing
|
|
203
|
+
* backtick; if it stopped at `${` it sets `readingTemplateString = true`
|
|
204
|
+
* and the parser must consume an expression + `}` and then call
|
|
205
|
+
* `readString(CharCode.Backtick)` to read the next fragment.
|
|
206
|
+
*/
|
|
207
|
+
parseTemplateLiteral(startPos: number): TemplateStrExpr | undefined;
|
|
138
208
|
parseAssertStatement(): AssertStmt | undefined;
|
|
139
209
|
parseWhileStatement(): WhileStmt | undefined;
|
|
140
210
|
/**
|