@harmoniclabs/pebble 0.2.0 → 0.3.1
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 +22 -2
- 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 +27 -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 +12 -0
- package/dist/IR/toUPLC/CompilerOptions.js +14 -9
- 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/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 +1 -0
- package/dist/compiler/AstCompiler/AstCompiler.js +41 -4
- package/dist/compiler/AstCompiler/internal/_deriveContractBody/_deriveContractBody.js +3 -3
- package/dist/compiler/AstCompiler/internal/exprs/_compileCallExpr.js +57 -10
- package/dist/compiler/AstCompiler/internal/exprs/_compileCaseExpr.js +31 -0
- package/dist/compiler/AstCompiler/internal/exprs/_compileIsExpr.js +12 -0
- package/dist/compiler/AstCompiler/internal/exprs/_compilePropAccessExpr.js +36 -0
- package/dist/compiler/AstCompiler/internal/exprs/_compileUnaryPrefixExpr.js +13 -1
- 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/utils/getPropAccessReturnType.js +11 -0
- package/dist/compiler/Compiler.js +20 -27
- 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 +23 -8
- 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/TirFromDataExpr.js +102 -67
- package/dist/compiler/tir/expressions/TirIsExpr.js +14 -1
- package/dist/compiler/tir/expressions/TirNativeFunc.d.ts +1 -2
- package/dist/compiler/tir/expressions/TirNativeFunc.js +2 -12
- package/dist/compiler/tir/expressions/TirToDataExpr.js +3 -0
- 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/stdScope/populateStdNamespace.js +49 -4
- package/dist/compiler/tir/program/stdScope/prelude/preludeTypesSrc.js +35 -2
- package/dist/compiler/tir/program/stdScope/stdScope.d.ts +7 -0
- package/dist/compiler/tir/program/stdScope/stdScope.js +83 -40
- 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 +4 -2
- package/dist/compiler/tir/types/TirNativeType/TirNativeType.js +5 -0
- 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 +4 -1
- package/dist/compiler/tir/types/utils/canAssignTo.js +28 -0
- 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.js +4 -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.js +5 -0
- package/dist/diagnostics/diagnosticMessages.generated.d.ts +5 -0
- package/dist/diagnostics/diagnosticMessages.generated.js +10 -0
- package/dist/parser/Parser.js +29 -13
- package/dist/tokenizer/Token.d.ts +8 -7
- package/dist/tokenizer/Token.js +8 -7
- package/dist/tokenizer/utils/tokenFromKeyword.js +2 -0
- package/dist/version.generated.d.ts +1 -1
- package/dist/version.generated.js +1 -1
- package/package.json +3 -3
- package/dist/IR/tree_utils/_ir_lazyChooseList.d.ts +0 -3
- package/dist/IR/tree_utils/_ir_lazyChooseList.js +0 -7
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export * from "./Optional/index.js";
|
|
2
|
+
export * from "./array.js";
|
|
2
3
|
export * from "./bool.js";
|
|
3
4
|
export * from "./bytes.js";
|
|
4
5
|
export * from "./data.js";
|
|
@@ -8,4 +9,5 @@ export * from "./linearMap.js";
|
|
|
8
9
|
export * from "./linearMapEntry.js";
|
|
9
10
|
export * from "./list.js";
|
|
10
11
|
export * from "./string.js";
|
|
12
|
+
export * from "./value.js";
|
|
11
13
|
export * from "./void.js";
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { ConstType } from "@harmoniclabs/uplc";
|
|
2
|
+
import { ITirType } from "../../TirType.js";
|
|
3
|
+
export declare class TirValueT implements ITirType {
|
|
4
|
+
clone(): TirValueT;
|
|
5
|
+
isConcrete(): boolean;
|
|
6
|
+
toString(): string;
|
|
7
|
+
toAstName(): string;
|
|
8
|
+
static toTirTypeKey(): string;
|
|
9
|
+
toTirTypeKey(): string;
|
|
10
|
+
toConcreteTirTypeName(): string;
|
|
11
|
+
/**
|
|
12
|
+
* Native `Value` is bidirectionally reachable from `data` via
|
|
13
|
+
* `unValueData` / `valueData`, so it qualifies as data-encoded for
|
|
14
|
+
* the purposes of `data struct` field types.
|
|
15
|
+
*/
|
|
16
|
+
hasDataEncoding(): boolean;
|
|
17
|
+
toUplcConstType(): ConstType;
|
|
18
|
+
}
|
|
@@ -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,6 +1,7 @@
|
|
|
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";
|
|
5
6
|
import { TirTypeParam } from "./TirTypeParam.js";
|
|
6
7
|
export function isTirType(thing) {
|
|
@@ -10,9 +11,11 @@ export function isTirType(thing) {
|
|
|
10
11
|
}
|
|
11
12
|
export function isTirCustomType(thing) {
|
|
12
13
|
return isObject(thing) && (thing instanceof TirAliasType
|
|
13
|
-
|| isTirStructType(thing)
|
|
14
|
+
|| isTirStructType(thing)
|
|
15
|
+
|| isTirEnumType(thing));
|
|
14
16
|
}
|
|
15
17
|
export function isTirNamedDestructableType(thing) {
|
|
16
18
|
return isObject(thing) && (isTirStructType(thing)
|
|
19
|
+
|| isTirEnumType(thing)
|
|
17
20
|
|| isTirNamedDestructableNativeType(thing));
|
|
18
21
|
}
|
|
@@ -5,6 +5,8 @@ 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))
|
|
@@ -239,6 +259,14 @@ function uncheckedGetCanAssign(a, b, symbols) {
|
|
|
239
259
|
return a instanceof TirBlsG2T ? CanAssign.Yes : CanAssign.No;
|
|
240
260
|
if (b instanceof TirMlResultT)
|
|
241
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
|
+
}
|
|
242
270
|
const tsEnsureExhautstiveCheck = b;
|
|
243
271
|
return CanAssign.No;
|
|
244
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
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { TirArrayT } from "../TirNativeType/native/array.js";
|
|
1
2
|
import { TirFuncT } from "../TirNativeType/native/function.js";
|
|
2
3
|
import { TirLinearMapT } from "../TirNativeType/native/linearMap.js";
|
|
3
4
|
import { TirLinearMapEntryT } from "../TirNativeType/native/linearMapEntry.js";
|
|
@@ -34,6 +35,9 @@ export function inferTypeArgs(formal, actual, env) {
|
|
|
34
35
|
if (formal instanceof TirListT && actual instanceof TirListT) {
|
|
35
36
|
return inferTypeArgs(formal.typeArg, actual.typeArg, env);
|
|
36
37
|
}
|
|
38
|
+
if (formal instanceof TirArrayT && actual instanceof TirArrayT) {
|
|
39
|
+
return inferTypeArgs(formal.typeArg, actual.typeArg, env);
|
|
40
|
+
}
|
|
37
41
|
if (formal instanceof TirFuncT && actual instanceof TirFuncT) {
|
|
38
42
|
if (formal.argTypes.length !== actual.argTypes.length)
|
|
39
43
|
return false;
|
|
@@ -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
|
+
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { TirAliasType } from "../TirAliasType.js";
|
|
2
|
+
import { TirArrayT } from "../TirNativeType/native/array.js";
|
|
2
3
|
import { TirFuncT } from "../TirNativeType/native/function.js";
|
|
3
4
|
import { TirLinearMapT } from "../TirNativeType/native/linearMap.js";
|
|
4
5
|
import { TirLinearMapEntryT } from "../TirNativeType/native/linearMapEntry.js";
|
|
@@ -23,6 +24,10 @@ export function substituteTypeParams(t, subst) {
|
|
|
23
24
|
const sub = substituteTypeParams(t.typeArg, subst);
|
|
24
25
|
return sub === t.typeArg ? t : new TirListT(sub);
|
|
25
26
|
}
|
|
27
|
+
if (t instanceof TirArrayT) {
|
|
28
|
+
const sub = substituteTypeParams(t.typeArg, subst);
|
|
29
|
+
return sub === t.typeArg ? t : new TirArrayT(sub);
|
|
30
|
+
}
|
|
26
31
|
if (t instanceof TirFuncT) {
|
|
27
32
|
let changed = false;
|
|
28
33
|
const newArgs = t.argTypes.map(a => {
|
|
@@ -283,6 +283,11 @@ export declare enum DiagnosticCode {
|
|
|
283
283
|
_private_modifier_is_only_allowed_on_declarations_inside_a_namespace = 30003,
|
|
284
284
|
Namespaces_cannot_be_declared_here = 30004,
|
|
285
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,
|
|
286
291
|
Dev_was_too_lazy_to_add_a_prooper_error_message_Something_went_wrong = 42069
|
|
287
292
|
}
|
|
288
293
|
/** Translates a diagnostic code to its respective string. */
|
|
@@ -285,6 +285,11 @@ export var DiagnosticCode;
|
|
|
285
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
286
|
DiagnosticCode[DiagnosticCode["Namespaces_cannot_be_declared_here"] = 30004] = "Namespaces_cannot_be_declared_here";
|
|
287
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";
|
|
288
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";
|
|
289
294
|
})(DiagnosticCode || (DiagnosticCode = {}));
|
|
290
295
|
/** Translates a diagnostic code to its respective string. */
|
|
@@ -573,6 +578,11 @@ export function diagnosticCodeToString(code) {
|
|
|
573
578
|
case 30003: return "'private' modifier is only allowed on declarations inside a namespace.";
|
|
574
579
|
case 30004: return "Namespaces cannot be declared here.";
|
|
575
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.";
|
|
576
586
|
case 42069: return "Dev was too lazy to add a prooper error message. Something went wrong";
|
|
577
587
|
default: return "";
|
|
578
588
|
}
|
package/dist/parser/Parser.js
CHANGED
|
@@ -178,13 +178,19 @@ export class Parser extends DiagnosticEmitter {
|
|
|
178
178
|
case Token.Data: {
|
|
179
179
|
// `next()` skips `data` keyword
|
|
180
180
|
tn.next();
|
|
181
|
+
let extraFlags = StructDeclAstFlags.onlyDataEncoding;
|
|
182
|
+
// accept `data untagged struct ...`
|
|
183
|
+
if (tn.peek() === Token.Untagged) {
|
|
184
|
+
tn.next();
|
|
185
|
+
extraFlags |= StructDeclAstFlags.untagged;
|
|
186
|
+
}
|
|
181
187
|
// positions on (expected) `struct` keyword
|
|
182
188
|
if (tn.peek() !== Token.Struct) {
|
|
183
189
|
console.error(Token[tn.peek()]);
|
|
184
190
|
return this.error(DiagnosticCode._0_expected, tn.range(), "struct");
|
|
185
191
|
}
|
|
186
192
|
tn.next(); // skip `struct`
|
|
187
|
-
statement = this.parseStruct(
|
|
193
|
+
statement = this.parseStruct(extraFlags, flags, startPos);
|
|
188
194
|
break;
|
|
189
195
|
}
|
|
190
196
|
case Token.Runtime: {
|
|
@@ -203,6 +209,22 @@ export class Parser extends DiagnosticEmitter {
|
|
|
203
209
|
statement = this.parseStruct(StructDeclAstFlags.none, flags, startPos);
|
|
204
210
|
break;
|
|
205
211
|
}
|
|
212
|
+
case Token.Untagged: {
|
|
213
|
+
// `untagged` keyword forces listData encoding (single ctor).
|
|
214
|
+
// Accept: `untagged struct ...` or `untagged data struct ...`.
|
|
215
|
+
tn.next(); // skip `untagged`
|
|
216
|
+
let extraFlags = StructDeclAstFlags.untagged;
|
|
217
|
+
if (tn.peek() === Token.Data) {
|
|
218
|
+
tn.next(); // skip `data`
|
|
219
|
+
extraFlags |= StructDeclAstFlags.onlyDataEncoding;
|
|
220
|
+
}
|
|
221
|
+
if (tn.peek() !== Token.Struct) {
|
|
222
|
+
return this.error(DiagnosticCode._0_expected, tn.range(), "struct");
|
|
223
|
+
}
|
|
224
|
+
tn.next(); // skip `struct`
|
|
225
|
+
statement = this.parseStruct(extraFlags, flags, startPos);
|
|
226
|
+
break;
|
|
227
|
+
}
|
|
206
228
|
case Token.Interface: {
|
|
207
229
|
tn.next();
|
|
208
230
|
statement = this.parseInterface(flags, startPos);
|
|
@@ -884,7 +906,7 @@ export class Parser extends DiagnosticEmitter {
|
|
|
884
906
|
[
|
|
885
907
|
new StructConstrDecl(new Identifier(name.text, name.range), [], // fields
|
|
886
908
|
range)
|
|
887
|
-
], structDeclFlags | StructDeclAstFlags.
|
|
909
|
+
], structDeclFlags | StructDeclAstFlags.shortcutSingleConstructor, range.clone());
|
|
888
910
|
}
|
|
889
911
|
let constrIdentifier = undefined;
|
|
890
912
|
// in case of single constr shortcut
|
|
@@ -905,7 +927,7 @@ export class Parser extends DiagnosticEmitter {
|
|
|
905
927
|
tn.skip(Token.Semicolon); // if any
|
|
906
928
|
return new StructDecl(name, typeParams, [
|
|
907
929
|
new StructConstrDecl(new Identifier(name.text, name.range), fields, tn.range(startPos, tn.pos))
|
|
908
|
-
], structDeclFlags | StructDeclAstFlags.
|
|
930
|
+
], structDeclFlags | StructDeclAstFlags.shortcutSingleConstructor, tn.range(startPos, tn.pos));
|
|
909
931
|
}
|
|
910
932
|
const constrFields = this.parseStructConstrFields(flags);
|
|
911
933
|
if (!Array.isArray(constrFields))
|
|
@@ -1885,17 +1907,14 @@ export class Parser extends DiagnosticEmitter {
|
|
|
1885
1907
|
const expr = this.parseExpr(Precedence.Relational + 1);
|
|
1886
1908
|
if (!expr)
|
|
1887
1909
|
return undefined;
|
|
1888
|
-
let noPatternCaseSeen = false;
|
|
1889
1910
|
const cases = new Array();
|
|
1890
1911
|
while (tn.skip(Token.Is)) {
|
|
1891
|
-
if (noPatternCaseSeen)
|
|
1892
|
-
return this.error(DiagnosticCode.This_case_will_never_be_evaluated_because_all_patterns_will_be_catched_before, tn.range());
|
|
1893
1912
|
const startPos = tn.tokenPos;
|
|
1894
1913
|
const matcher = this._parseVarDecl(CommonFlags.Const);
|
|
1895
1914
|
if (!matcher)
|
|
1896
1915
|
return undefined;
|
|
1897
|
-
|
|
1898
|
-
|
|
1916
|
+
// SimpleVarDecl patterns are validated by the AstCompiler, which
|
|
1917
|
+
// has type info (enum-member promotion vs invalid catch-all).
|
|
1899
1918
|
if (matcher.initExpr || matcher.type)
|
|
1900
1919
|
return this.error(DiagnosticCode.Patterns_may_not_have_initializers_or_explicit_types, matcher.initExpr ? matcher.initExpr.range : matcher.type.range);
|
|
1901
1920
|
if (!tn.skip(Token.FatArrow))
|
|
@@ -2626,7 +2645,6 @@ export class Parser extends DiagnosticEmitter {
|
|
|
2626
2645
|
return this.error(DiagnosticCode.Expression_expected, tn.range(startPos - 5, startPos));
|
|
2627
2646
|
if (!tn.skip(Token.OpenBrace))
|
|
2628
2647
|
return this.error(DiagnosticCode._0_expected, tn.range(), "{");
|
|
2629
|
-
let noPatternCaseSeen = false;
|
|
2630
2648
|
const cases = new Array();
|
|
2631
2649
|
while (!tn.skip(Token.CloseBrace)
|
|
2632
2650
|
&& tn.peek() !== Token.Else) {
|
|
@@ -2637,10 +2655,8 @@ export class Parser extends DiagnosticEmitter {
|
|
|
2637
2655
|
const pattern = this._parseVarDecl(CommonFlags.Const, true);
|
|
2638
2656
|
if (!pattern)
|
|
2639
2657
|
return this.error(DiagnosticCode.Pattern_expected, tn.range());
|
|
2640
|
-
|
|
2641
|
-
|
|
2642
|
-
if (pattern instanceof SimpleVarDecl)
|
|
2643
|
-
noPatternCaseSeen = true;
|
|
2658
|
+
// SimpleVarDecl patterns are validated by the AstCompiler, which
|
|
2659
|
+
// has type info (enum-member promotion vs invalid catch-all).
|
|
2644
2660
|
if (!tn.skip(Token.Colon))
|
|
2645
2661
|
return this.error(DiagnosticCode._0_expected, tn.range(), ":");
|
|
2646
2662
|
const statePreBody = tn.mark();
|
|
@@ -164,11 +164,12 @@ export declare enum Token {
|
|
|
164
164
|
List = 117,
|
|
165
165
|
LinearMap = 118,
|
|
166
166
|
Runtime = 119,
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
167
|
+
Untagged = 120,
|
|
168
|
+
Identifier = 121,
|
|
169
|
+
StringLiteral = 122,
|
|
170
|
+
HexBytesLiteral = 123,
|
|
171
|
+
IntegerLiteral = 124,
|
|
172
|
+
StringTemplateLiteralQuote = 125,
|
|
173
|
+
Invalid = 126,
|
|
174
|
+
EndOfFile = 127
|
|
174
175
|
}
|
package/dist/tokenizer/Token.js
CHANGED
|
@@ -204,16 +204,17 @@ export var Token;
|
|
|
204
204
|
// struct decl modifiers
|
|
205
205
|
// taggedModifier, // `tagged` data struct
|
|
206
206
|
Token[Token["Runtime"] = 119] = "Runtime";
|
|
207
|
+
Token[Token["Untagged"] = 120] = "Untagged";
|
|
207
208
|
// literals
|
|
208
|
-
Token[Token["Identifier"] =
|
|
209
|
-
Token[Token["StringLiteral"] =
|
|
210
|
-
Token[Token["HexBytesLiteral"] =
|
|
211
|
-
Token[Token["IntegerLiteral"] =
|
|
209
|
+
Token[Token["Identifier"] = 121] = "Identifier";
|
|
210
|
+
Token[Token["StringLiteral"] = 122] = "StringLiteral";
|
|
211
|
+
Token[Token["HexBytesLiteral"] = 123] = "HexBytesLiteral";
|
|
212
|
+
Token[Token["IntegerLiteral"] = 124] = "IntegerLiteral";
|
|
212
213
|
// FloatLiteral,
|
|
213
|
-
Token[Token["StringTemplateLiteralQuote"] =
|
|
214
|
+
Token[Token["StringTemplateLiteralQuote"] = 125] = "StringTemplateLiteralQuote";
|
|
214
215
|
// meta
|
|
215
|
-
Token[Token["Invalid"] =
|
|
216
|
-
Token[Token["EndOfFile"] =
|
|
216
|
+
Token[Token["Invalid"] = 126] = "Invalid";
|
|
217
|
+
Token[Token["EndOfFile"] = 127] = "EndOfFile";
|
|
217
218
|
})(Token || (Token = {}));
|
|
218
219
|
Object.freeze(Token);
|
|
219
220
|
/*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const COMPILER_VERSION = "0.
|
|
1
|
+
export declare const COMPILER_VERSION = "0.3.1";
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
// This file is auto-generated by scripts/genVersion.js. Do not edit.
|
|
2
|
-
export const COMPILER_VERSION = "0.
|
|
2
|
+
export const COMPILER_VERSION = "0.3.1";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@harmoniclabs/pebble",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.1",
|
|
4
4
|
"description": "A simple, yet rock solid, functional language with an imperative bias, targeting UPLC",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
@@ -53,12 +53,12 @@
|
|
|
53
53
|
"homepage": "https://github.com/HarmonicLabs/pebble#readme",
|
|
54
54
|
"dependencies": {
|
|
55
55
|
"@harmoniclabs/bigint-utils": "^1.0.0",
|
|
56
|
-
"@harmoniclabs/cardano-costmodels-ts": "^1.
|
|
56
|
+
"@harmoniclabs/cardano-costmodels-ts": "^1.6.1",
|
|
57
57
|
"@harmoniclabs/cbor": "^2.0.1",
|
|
58
58
|
"@harmoniclabs/crypto": "^0.3.0",
|
|
59
59
|
"@harmoniclabs/obj-utils": "^1.0.0",
|
|
60
60
|
"@harmoniclabs/plutus-data": "^2.0.1",
|
|
61
|
-
"@harmoniclabs/plutus-machine": "^3.0.
|
|
61
|
+
"@harmoniclabs/plutus-machine": "^3.0.3",
|
|
62
62
|
"@harmoniclabs/uint8array-utils": "^1.0.4",
|
|
63
63
|
"@harmoniclabs/uplc": "^2.0.5"
|
|
64
64
|
},
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import { _ir_apps } from "../IRNodes/IRApp.js";
|
|
2
|
-
import { IRDelayed } from "../IRNodes/IRDelayed.js";
|
|
3
|
-
import { IRForced } from "../IRNodes/IRForced.js";
|
|
4
|
-
import { IRNative } from "../IRNodes/IRNative/index.js";
|
|
5
|
-
export function _ir_lazyChooseList(listTerm, caseNil, caseCons) {
|
|
6
|
-
return new IRForced(_ir_apps(IRNative.strictChooseList, listTerm, new IRDelayed(caseNil), new IRDelayed(caseCons)));
|
|
7
|
-
}
|