@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
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { ITirExpr } from "../ITirExpr.js";
|
|
2
|
+
import { SourceRange } from "../../../../ast/Source/SourceRange.js";
|
|
3
|
+
import { TirEnumType } from "../../types/TirEnumType.js";
|
|
4
|
+
import { ToIRTermCtx } from "../ToIRTermCtx.js";
|
|
5
|
+
import { IRTerm } from "../../../../IR/index.js";
|
|
6
|
+
import type { TirExpr } from "../TirExpr.js";
|
|
7
|
+
export declare class TirLitEnumMemberExpr implements ITirExpr {
|
|
8
|
+
readonly type: TirEnumType;
|
|
9
|
+
readonly memberIdx: number;
|
|
10
|
+
readonly range: SourceRange;
|
|
11
|
+
readonly isConstant: boolean;
|
|
12
|
+
constructor(type: TirEnumType, memberIdx: number, range: SourceRange);
|
|
13
|
+
get memberName(): string;
|
|
14
|
+
pretty(): string;
|
|
15
|
+
toString(): string;
|
|
16
|
+
clone(): TirExpr;
|
|
17
|
+
deps(): string[];
|
|
18
|
+
toIR(_ctx: ToIRTermCtx): IRTerm;
|
|
19
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { IRConst } from "../../../../IR/index.js";
|
|
2
|
+
export class TirLitEnumMemberExpr {
|
|
3
|
+
type;
|
|
4
|
+
memberIdx;
|
|
5
|
+
range;
|
|
6
|
+
isConstant = true;
|
|
7
|
+
constructor(type, memberIdx, range) {
|
|
8
|
+
this.type = type;
|
|
9
|
+
this.memberIdx = memberIdx;
|
|
10
|
+
this.range = range;
|
|
11
|
+
}
|
|
12
|
+
get memberName() { return this.type.members[this.memberIdx]; }
|
|
13
|
+
pretty() { return this.toString(); }
|
|
14
|
+
toString() {
|
|
15
|
+
return `${this.type.name}.${this.memberName}`;
|
|
16
|
+
}
|
|
17
|
+
clone() {
|
|
18
|
+
return new TirLitEnumMemberExpr(this.type.clone(), this.memberIdx, this.range.clone());
|
|
19
|
+
}
|
|
20
|
+
deps() { return []; }
|
|
21
|
+
toIR(_ctx) {
|
|
22
|
+
return IRConst.int(BigInt(this.memberIdx));
|
|
23
|
+
}
|
|
24
|
+
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { TirLitArrExpr } from "./TirLitArrExpr.js";
|
|
2
|
+
import { TirLitEnumMemberExpr } from "./TirLitEnumMemberExpr.js";
|
|
2
3
|
import { TirLitFailExpr } from "./TirLitFailExpr.js";
|
|
3
4
|
import { TirLitFalseExpr } from "./TirLitFalseExpr.js";
|
|
4
5
|
import { TirLitHexBytesExpr } from "./TirLitHexBytesExpr.js";
|
|
@@ -10,5 +11,5 @@ import { TirLitThisExpr } from "./TirLitThisExpr.js";
|
|
|
10
11
|
import { TirLitTrueExpr } from "./TirLitTrueExpr.js";
|
|
11
12
|
import { TirLitUndefExpr } from "./TirLitUndefExpr.js";
|
|
12
13
|
import { TirLitVoidExpr } from "./TirLitVoidExpr.js";
|
|
13
|
-
export type TirLitteralExpr = TirLitVoidExpr | TirLitUndefExpr | TirLitTrueExpr | TirLitFalseExpr | TirLitStrExpr | TirLitIntExpr | TirLitHexBytesExpr | TirLitThisExpr | TirLitArrExpr | TirLitObjExpr | TirLitNamedObjExpr | TirLitFailExpr;
|
|
14
|
+
export type TirLitteralExpr = TirLitVoidExpr | TirLitUndefExpr | TirLitTrueExpr | TirLitFalseExpr | TirLitStrExpr | TirLitIntExpr | TirLitHexBytesExpr | TirLitThisExpr | TirLitArrExpr | TirLitObjExpr | TirLitNamedObjExpr | TirLitEnumMemberExpr | TirLitFailExpr;
|
|
14
15
|
export declare function isTirLitteralExpr(thing: any): thing is TirLitteralExpr;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { TirLitArrExpr } from "./TirLitArrExpr.js";
|
|
2
|
+
import { TirLitEnumMemberExpr } from "./TirLitEnumMemberExpr.js";
|
|
2
3
|
import { TirLitFailExpr } from "./TirLitFailExpr.js";
|
|
3
4
|
import { TirLitFalseExpr } from "./TirLitFalseExpr.js";
|
|
4
5
|
import { TirLitHexBytesExpr } from "./TirLitHexBytesExpr.js";
|
|
@@ -19,6 +20,7 @@ export function isTirLitteralExpr(thing) {
|
|
|
19
20
|
|| thing instanceof TirLitArrExpr
|
|
20
21
|
|| thing instanceof TirLitObjExpr
|
|
21
22
|
|| thing instanceof TirLitNamedObjExpr
|
|
23
|
+
|| thing instanceof TirLitEnumMemberExpr
|
|
22
24
|
|| thing instanceof TirLitStrExpr
|
|
23
25
|
|| thing instanceof TirLitIntExpr
|
|
24
26
|
|| thing instanceof TirLitHexBytesExpr
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { TirValueT } from "../../types/TirNativeType/native/value.js";
|
|
2
|
+
import { getUnaliased } from "../../types/utils/getUnaliased.js";
|
|
1
3
|
import { _ir_apps } from "../../../../IR/IRNodes/IRApp.js";
|
|
2
4
|
import { IRNative } from "../../../../IR/IRNodes/IRNative/index.js";
|
|
3
5
|
export class TirUnaryMinus {
|
|
@@ -23,6 +25,7 @@ export class TirUnaryMinus {
|
|
|
23
25
|
}
|
|
24
26
|
get isConstant() { return this.operand.isConstant; }
|
|
25
27
|
toIR(ctx) {
|
|
26
|
-
|
|
28
|
+
const operandTy = getUnaliased(this.operand.type);
|
|
29
|
+
return _ir_apps(operandTy instanceof TirValueT ? IRNative._negateValue : IRNative._negateInt, this.operand.toIR(ctx));
|
|
27
30
|
}
|
|
28
31
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { SourceRange } from "../../../../ast/Source/SourceRange.js";
|
|
2
2
|
import { _ir_apps } from "../../../../IR/IRNodes/IRApp.js";
|
|
3
|
+
import { IRCase } from "../../../../IR/IRNodes/IRCase.js";
|
|
3
4
|
import { IRFunc } from "../../../../IR/IRNodes/IRFunc.js";
|
|
4
5
|
import { IRNative } from "../../../../IR/IRNodes/IRNative/index.js";
|
|
5
6
|
import { IRNativeTag } from "../../../../IR/IRNodes/IRNative/IRNativeTag.js";
|
|
@@ -10,9 +11,11 @@ import { TirBlsG1T, TirBlsG2T, TirMlResultT, TirUnConstrDataResultT, TirFuncT, }
|
|
|
10
11
|
import { TirLinearMapT } from "../../types/TirNativeType/native/linearMap.js";
|
|
11
12
|
import { TirLinearMapEntryT } from "../../types/TirNativeType/native/linearMapEntry.js";
|
|
12
13
|
import { TirListT } from "../../types/TirNativeType/native/list.js";
|
|
14
|
+
import { TirArrayT } from "../../types/TirNativeType/native/array.js";
|
|
15
|
+
import { TirValueT } from "../../types/TirNativeType/native/value.js";
|
|
13
16
|
import { TirSopOptT } from "../../types/TirNativeType/native/Optional/sop.js";
|
|
14
17
|
import { TirTypeParam } from "../../types/TirTypeParam.js";
|
|
15
|
-
import { bool_t, bytes_t, data_t, int_t, string_t, void_t, valueLovelacesName, valueAmountOfName, getCredentialHashFuncName, } from "./stdScope.js";
|
|
18
|
+
import { bool_t, bytes_t, data_t, int_t, string_t, void_t, valueLovelacesName, valueAmountOfName, valueMapLovelacesName, valueMapAmountOfName, valueInsertCoinName, valueUnionName, valueContainsName, valueScaleName, valueToDataName, getCredentialHashFuncName, } from "./stdScope.js";
|
|
16
19
|
/**
|
|
17
20
|
* Populate the top-level `std` namespace and its sub-namespaces:
|
|
18
21
|
*
|
|
@@ -264,6 +267,16 @@ export function populateStdNamespace(program) {
|
|
|
264
267
|
// data misc
|
|
265
268
|
defineBuiltin(builtinsNsScope, "equalsData", IRNativeTag.equalsData, new TirFuncT([data_t, data_t], bool_t), blt);
|
|
266
269
|
defineBuiltin(builtinsNsScope, "serialiseData", IRNativeTag.serialiseData, new TirFuncT([data_t], bytes_t), blt);
|
|
270
|
+
// Chang2 / value & array builtins
|
|
271
|
+
const value_native_t = new TirValueT();
|
|
272
|
+
defineBuiltin(builtinsNsScope, "expModInteger", IRNativeTag.expModInteger, new TirFuncT([int_t, int_t, int_t], int_t), blt);
|
|
273
|
+
defineBuiltin(builtinsNsScope, "insertCoin", IRNativeTag.insertCoin, new TirFuncT([bytes_t, bytes_t, int_t, value_native_t], value_native_t), blt);
|
|
274
|
+
defineBuiltin(builtinsNsScope, "lookupCoin", IRNativeTag.lookupCoin, new TirFuncT([bytes_t, bytes_t, value_native_t], int_t), blt);
|
|
275
|
+
defineBuiltin(builtinsNsScope, "unionValue", IRNativeTag.unionValue, new TirFuncT([value_native_t, value_native_t], value_native_t), blt);
|
|
276
|
+
defineBuiltin(builtinsNsScope, "valueContains", IRNativeTag.valueContains, new TirFuncT([value_native_t, value_native_t], bool_t), blt);
|
|
277
|
+
defineBuiltin(builtinsNsScope, "valueData", IRNativeTag.valueData, new TirFuncT([value_native_t], data_t), blt);
|
|
278
|
+
defineBuiltin(builtinsNsScope, "unValueData", IRNativeTag.unValueData, new TirFuncT([data_t], value_native_t), blt);
|
|
279
|
+
defineBuiltin(builtinsNsScope, "scaleValue", IRNativeTag.scaleValue, new TirFuncT([int_t, value_native_t], value_native_t), blt);
|
|
267
280
|
// ------------------------------------------------------------------
|
|
268
281
|
// 5b. std.builtins -- polymorphic intrinsics via native generic templates
|
|
269
282
|
// ------------------------------------------------------------------
|
|
@@ -395,8 +408,20 @@ export function populateStdNamespace(program) {
|
|
|
395
408
|
defineGenericBuiltin(builtinsNsScope, "tailList", 1, ([T]) => new TirFuncT([new TirListT(T)], new TirListT(T)), () => new IRNative(IRNativeTag.tailList));
|
|
396
409
|
// nullList<T>( xs: List<T> ): bool
|
|
397
410
|
defineGenericBuiltin(builtinsNsScope, "nullList", 1, ([T]) => new TirFuncT([new TirListT(T)], bool_t), () => new IRNative(IRNativeTag.nullList));
|
|
398
|
-
// chooseList<A,B>( xs: List<A>, caseNil: B, caseCons: B ): B
|
|
399
|
-
|
|
411
|
+
// chooseList<A,B>( xs: List<A>, caseNil: B, caseCons: B ): B
|
|
412
|
+
// Lowered to a UPLC `Case` on the list: the cons branch ignores h/t
|
|
413
|
+
// (matching the `chooseList` builtin contract — head/tail aren't bound).
|
|
414
|
+
defineGenericBuiltin(builtinsNsScope, "chooseList", 2, ([A, B]) => new TirFuncT([new TirListT(A), B, B], B), () => {
|
|
415
|
+
const xs = Symbol("xs");
|
|
416
|
+
const caseNil = Symbol("caseNil");
|
|
417
|
+
const caseCons = Symbol("caseCons");
|
|
418
|
+
const h = Symbol("_h");
|
|
419
|
+
const t = Symbol("_t");
|
|
420
|
+
return new IRFunc([xs, caseNil, caseCons], new IRCase(new IRVar(xs), [
|
|
421
|
+
new IRFunc([h, t], new IRVar(caseCons)),
|
|
422
|
+
new IRVar(caseNil)
|
|
423
|
+
]));
|
|
424
|
+
});
|
|
400
425
|
// chooseData<T>( d: data, caseConstr: T, caseMap: T, caseList: T,
|
|
401
426
|
// caseIData: T, caseBData: T ): T
|
|
402
427
|
defineGenericBuiltin(builtinsNsScope, "chooseData", 1, ([T]) => new TirFuncT([data_t, T, T, T, T, T], T), () => new IRNative(IRNativeTag.chooseData));
|
|
@@ -414,12 +439,14 @@ export function populateStdNamespace(program) {
|
|
|
414
439
|
// Method-call surface (e.g. `xs.map(f)`) is unchanged.
|
|
415
440
|
// ------------------------------------------------------------------
|
|
416
441
|
const listNsScope = new AstScope(stdNsScope, program, {});
|
|
442
|
+
const arrayNsScope = new AstScope(stdNsScope, program, {});
|
|
417
443
|
const linearMapNsScope = new AstScope(stdNsScope, program, {});
|
|
418
444
|
const bytesNsScope = new AstScope(stdNsScope, program, {});
|
|
419
445
|
const intNsScope = new AstScope(stdNsScope, program, {});
|
|
420
446
|
const boolNsScope = new AstScope(stdNsScope, program, {});
|
|
421
447
|
const dataNsScope = new AstScope(stdNsScope, program, {});
|
|
422
448
|
const valueNsScope = new AstScope(stdNsScope, program, {});
|
|
449
|
+
const valueMapNsScope = new AstScope(stdNsScope, program, {});
|
|
423
450
|
const credentialNsScope = new AstScope(stdNsScope, program, {});
|
|
424
451
|
// ---------- std.list (polymorphic) ----------
|
|
425
452
|
const listNs = "list";
|
|
@@ -428,7 +455,7 @@ export function populateStdNamespace(program) {
|
|
|
428
455
|
defineGenericBuiltin(listNsScope, "head", 1, ([T]) => new TirFuncT([new TirListT(T)], T), () => new IRNative(IRNativeTag.headList), listNs);
|
|
429
456
|
defineGenericBuiltin(listNsScope, "tail", 1, ([T]) => new TirFuncT([new TirListT(T)], new TirListT(T)), () => new IRNative(IRNativeTag.tailList), listNs);
|
|
430
457
|
defineGenericBuiltin(listNsScope, "prepend", 1, ([T]) => new TirFuncT([T, new TirListT(T)], new TirListT(T)), () => new IRNative(IRNativeTag.mkCons), listNs);
|
|
431
|
-
defineGenericBuiltin(listNsScope, "drop", 1, ([T]) => new TirFuncT([int_t, new TirListT(T)], new TirListT(T)), () => new IRNative(IRNativeTag.
|
|
458
|
+
defineGenericBuiltin(listNsScope, "drop", 1, ([T]) => new TirFuncT([int_t, new TirListT(T)], new TirListT(T)), () => new IRNative(IRNativeTag.dropList), listNs);
|
|
432
459
|
defineGenericBuiltin(listNsScope, "foldr", 2, ([T, A]) => new TirFuncT([new TirFuncT([T, A], A), A, new TirListT(T)], A), () => new IRNative(IRNativeTag._foldr), listNs);
|
|
433
460
|
defineGenericBuiltin(listNsScope, "foldl", 2, ([T, A]) => new TirFuncT([new TirFuncT([A, T], A), A, new TirListT(T)], A), () => new IRNative(IRNativeTag._foldl), listNs);
|
|
434
461
|
defineGenericBuiltin(listNsScope, "filter", 1, ([T]) => new TirFuncT([new TirFuncT([T], bool_t), new TirListT(T)], new TirListT(T)), () => new IRNative(IRNativeTag._filter), listNs);
|
|
@@ -521,9 +548,23 @@ export function populateStdNamespace(program) {
|
|
|
521
548
|
}
|
|
522
549
|
scope.functions.set(astName, existingTirFuncName);
|
|
523
550
|
}
|
|
551
|
+
// std.value.* — methods on the native Value
|
|
524
552
|
defineAliasFromProgram(valueNsScope, "amountOf", valueAmountOfName);
|
|
525
553
|
defineAliasFromProgram(valueNsScope, "lovelaces", valueLovelacesName);
|
|
554
|
+
defineAliasFromProgram(valueNsScope, "insert", valueInsertCoinName);
|
|
555
|
+
defineAliasFromProgram(valueNsScope, "union", valueUnionName);
|
|
556
|
+
defineAliasFromProgram(valueNsScope, "contains", valueContainsName);
|
|
557
|
+
defineAliasFromProgram(valueNsScope, "scale", valueScaleName);
|
|
558
|
+
defineAliasFromProgram(valueNsScope, "toData", valueToDataName);
|
|
559
|
+
// std.valueMap.* — methods on the legacy AssocMap-of-AssocMap representation
|
|
560
|
+
defineAliasFromProgram(valueMapNsScope, "amountOf", valueMapAmountOfName);
|
|
561
|
+
defineAliasFromProgram(valueMapNsScope, "lovelaces", valueMapLovelacesName);
|
|
526
562
|
defineAliasFromProgram(credentialNsScope, "hash", getCredentialHashFuncName);
|
|
563
|
+
// ---------- std.array (polymorphic; native array) ----------
|
|
564
|
+
const arrayNs = "array";
|
|
565
|
+
defineGenericBuiltin(arrayNsScope, "length", 1, ([T]) => new TirFuncT([new TirArrayT(T)], int_t), () => new IRNative(IRNativeTag.lengthOfArray), arrayNs);
|
|
566
|
+
defineGenericBuiltin(arrayNsScope, "at", 1, ([T]) => new TirFuncT([new TirArrayT(T), int_t], T), () => new IRNative(IRNativeTag.indexArray), arrayNs);
|
|
567
|
+
defineGenericBuiltin(arrayNsScope, "fromList", 1, ([T]) => new TirFuncT([new TirListT(T)], new TirArrayT(T)), () => new IRNative(IRNativeTag.listToArray), arrayNs);
|
|
527
568
|
// ---------- top-level std.id<T> / std.equals<T> ----------
|
|
528
569
|
// id<T>(x: T): T -- the polymorphic identity. Useful as a default
|
|
529
570
|
// argument or "do-nothing" callback to higher-order code.
|
|
@@ -552,22 +593,26 @@ export function populateStdNamespace(program) {
|
|
|
552
593
|
cryptoNsScope.readonly();
|
|
553
594
|
builtinsNsScope.readonly();
|
|
554
595
|
listNsScope.readonly();
|
|
596
|
+
arrayNsScope.readonly();
|
|
555
597
|
linearMapNsScope.readonly();
|
|
556
598
|
bytesNsScope.readonly();
|
|
557
599
|
intNsScope.readonly();
|
|
558
600
|
boolNsScope.readonly();
|
|
559
601
|
dataNsScope.readonly();
|
|
560
602
|
valueNsScope.readonly();
|
|
603
|
+
valueMapNsScope.readonly();
|
|
561
604
|
credentialNsScope.readonly();
|
|
562
605
|
stdNsScope.defineNamespace({ name: "crypto", publicScope: cryptoNsScope });
|
|
563
606
|
stdNsScope.defineNamespace({ name: "builtins", publicScope: builtinsNsScope });
|
|
564
607
|
stdNsScope.defineNamespace({ name: "list", publicScope: listNsScope });
|
|
608
|
+
stdNsScope.defineNamespace({ name: "array", publicScope: arrayNsScope });
|
|
565
609
|
stdNsScope.defineNamespace({ name: "linearMap", publicScope: linearMapNsScope });
|
|
566
610
|
stdNsScope.defineNamespace({ name: "bytes", publicScope: bytesNsScope });
|
|
567
611
|
stdNsScope.defineNamespace({ name: "int", publicScope: intNsScope });
|
|
568
612
|
stdNsScope.defineNamespace({ name: "boolean", publicScope: boolNsScope });
|
|
569
613
|
stdNsScope.defineNamespace({ name: "data", publicScope: dataNsScope });
|
|
570
614
|
stdNsScope.defineNamespace({ name: "value", publicScope: valueNsScope });
|
|
615
|
+
stdNsScope.defineNamespace({ name: "valueMap", publicScope: valueMapNsScope });
|
|
571
616
|
stdNsScope.defineNamespace({ name: "credential", publicScope: credentialNsScope });
|
|
572
617
|
stdNsScope.readonly();
|
|
573
618
|
program.preludeScope.defineNamespace({ name: "std", publicScope: stdNsScope });
|
|
@@ -152,9 +152,9 @@ export struct Address {
|
|
|
152
152
|
stake: Optional<Credential>
|
|
153
153
|
}
|
|
154
154
|
|
|
155
|
-
export type
|
|
155
|
+
export type ValueMap = LinearMap<PolicyId, LinearMap<TokenName, int>>
|
|
156
156
|
|
|
157
|
-
type
|
|
157
|
+
type ValueMap implements {
|
|
158
158
|
amountOf( policy: PolicyId, name: bytes ): int
|
|
159
159
|
{
|
|
160
160
|
// todo
|
|
@@ -166,6 +166,39 @@ type Value implements {
|
|
|
166
166
|
}
|
|
167
167
|
}
|
|
168
168
|
|
|
169
|
+
// `Value` is a native built-in value (ConstTyTag.value).
|
|
170
|
+
// It is reached from `data` via `unValueData`; the ledger always passes data.
|
|
171
|
+
type Value implements {
|
|
172
|
+
amountOf( policy: PolicyId, name: bytes ): int
|
|
173
|
+
{
|
|
174
|
+
return native.lookupCoin( policy, name, this );
|
|
175
|
+
}
|
|
176
|
+
lovelaces(): int
|
|
177
|
+
{
|
|
178
|
+
return this.amountOf( #, # );
|
|
179
|
+
}
|
|
180
|
+
insert( policy: PolicyId, name: bytes, amount: int ): Value
|
|
181
|
+
{
|
|
182
|
+
return native.insertCoin( policy, name, amount, this );
|
|
183
|
+
}
|
|
184
|
+
union( other: Value ): Value
|
|
185
|
+
{
|
|
186
|
+
return native.unionValue( this, other );
|
|
187
|
+
}
|
|
188
|
+
contains( other: Value ): bool
|
|
189
|
+
{
|
|
190
|
+
return native.valueContains( this, other );
|
|
191
|
+
}
|
|
192
|
+
scale( factor: int ): Value
|
|
193
|
+
{
|
|
194
|
+
return native.scaleValue( factor, this );
|
|
195
|
+
}
|
|
196
|
+
toData(): data
|
|
197
|
+
{
|
|
198
|
+
return native.valueData( this );
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
|
|
169
202
|
export struct OutputDatum {
|
|
170
203
|
NoDatum {}
|
|
171
204
|
DatumHash { hash: Hash32 }
|
|
@@ -11,8 +11,15 @@ export declare const string_t: TirStringT;
|
|
|
11
11
|
export declare const bytes_t: TirBytesT;
|
|
12
12
|
export declare const bool_t: TirBoolT;
|
|
13
13
|
export declare const data_t: TirDataT;
|
|
14
|
+
export declare const valueMapLovelacesName: string;
|
|
15
|
+
export declare const valueMapAmountOfName: string;
|
|
14
16
|
export declare const valueLovelacesName: string;
|
|
15
17
|
export declare const valueAmountOfName: string;
|
|
18
|
+
export declare const valueInsertCoinName: string;
|
|
19
|
+
export declare const valueUnionName: string;
|
|
20
|
+
export declare const valueContainsName: string;
|
|
21
|
+
export declare const valueScaleName: string;
|
|
22
|
+
export declare const valueToDataName: string;
|
|
16
23
|
export declare const getCredentialHashFuncName: string;
|
|
17
24
|
export declare function populateStdScope(program: TypedProgram): void;
|
|
18
25
|
export declare function populatePreludeScope(program: TypedProgram): void;
|
|
@@ -6,6 +6,8 @@ import { TirDataT } from "../../types/TirNativeType/native/data.js";
|
|
|
6
6
|
import { TirIntT } from "../../types/TirNativeType/native/int.js";
|
|
7
7
|
import { TirLinearMapT } from "../../types/TirNativeType/native/linearMap.js";
|
|
8
8
|
import { TirListT } from "../../types/TirNativeType/native/list.js";
|
|
9
|
+
import { TirArrayT } from "../../types/TirNativeType/native/array.js";
|
|
10
|
+
import { TirValueT } from "../../types/TirNativeType/native/value.js";
|
|
9
11
|
import { TirDataOptT } from "../../types/TirNativeType/native/Optional/data.js";
|
|
10
12
|
import { TirSopOptT } from "../../types/TirNativeType/native/Optional/sop.js";
|
|
11
13
|
import { TirStringT } from "../../types/TirNativeType/native/string.js";
|
|
@@ -18,14 +20,23 @@ import { IRNative } from "../../../../IR/IRNodes/IRNative/index.js";
|
|
|
18
20
|
import { IRFunc } from "../../../../IR/IRNodes/IRFunc.js";
|
|
19
21
|
import { IRVar } from "../../../../IR/IRNodes/IRVar.js";
|
|
20
22
|
import { _ir_apps } from "../../../../IR/IRNodes/IRApp.js";
|
|
23
|
+
import { IRConst } from "../../../../IR/IRNodes/IRConst.js";
|
|
21
24
|
export const void_t = new TirVoidT();
|
|
22
25
|
export const int_t = new TirIntT();
|
|
23
26
|
export const string_t = new TirStringT();
|
|
24
27
|
export const bytes_t = new TirBytesT();
|
|
25
28
|
export const bool_t = new TirBoolT();
|
|
26
29
|
export const data_t = new TirDataT();
|
|
27
|
-
export const
|
|
28
|
-
export const
|
|
30
|
+
export const valueMapLovelacesName = PEBBLE_INTERNAL_IDENTIFIER_PREFIX + "sortedValueLovelaces";
|
|
31
|
+
export const valueMapAmountOfName = PEBBLE_INTERNAL_IDENTIFIER_PREFIX + "amountOfValue";
|
|
32
|
+
// Native Value (ConstTyTag.value); methods route to the value builtins.
|
|
33
|
+
export const valueLovelacesName = PEBBLE_INTERNAL_IDENTIFIER_PREFIX + "valueLovelaces";
|
|
34
|
+
export const valueAmountOfName = PEBBLE_INTERNAL_IDENTIFIER_PREFIX + "valueAmountOf";
|
|
35
|
+
export const valueInsertCoinName = PEBBLE_INTERNAL_IDENTIFIER_PREFIX + "valueInsertCoin";
|
|
36
|
+
export const valueUnionName = PEBBLE_INTERNAL_IDENTIFIER_PREFIX + "valueUnion";
|
|
37
|
+
export const valueContainsName = PEBBLE_INTERNAL_IDENTIFIER_PREFIX + "valueContains";
|
|
38
|
+
export const valueScaleName = PEBBLE_INTERNAL_IDENTIFIER_PREFIX + "valueScale";
|
|
39
|
+
export const valueToDataName = PEBBLE_INTERNAL_IDENTIFIER_PREFIX + "valueToData";
|
|
29
40
|
export const getCredentialHashFuncName = PEBBLE_INTERNAL_IDENTIFIER_PREFIX + "getCredentialHash";
|
|
30
41
|
export function populateStdScope(program) {
|
|
31
42
|
const stdScope = program.stdScope;
|
|
@@ -40,6 +51,24 @@ export function populateStdScope(program) {
|
|
|
40
51
|
_defineStdUnambigous(bytes_t);
|
|
41
52
|
_defineStdUnambigous(string_t);
|
|
42
53
|
_defineStdUnambigous(data_t);
|
|
54
|
+
// Register native Value (ConstTyTag.value) in program.types so the prelude
|
|
55
|
+
// alias can wrap it. The user-facing `Value` name is defined in the
|
|
56
|
+
// prelude scope (with methods routed to the value builtins).
|
|
57
|
+
{
|
|
58
|
+
const value_native_t = new TirValueT();
|
|
59
|
+
program.types.set(value_native_t.toTirTypeKey(), value_native_t);
|
|
60
|
+
}
|
|
61
|
+
const array_name = TirArrayT.toTirTypeKey();
|
|
62
|
+
program.defineGenericType(array_name, 1, ([arg]) => new TirArrayT(arg));
|
|
63
|
+
stdScope.defineType(array_name, {
|
|
64
|
+
sopTirName: array_name,
|
|
65
|
+
dataTirName: array_name,
|
|
66
|
+
allTirNames: new Set([
|
|
67
|
+
array_name
|
|
68
|
+
]),
|
|
69
|
+
methodsNames: new Map(),
|
|
70
|
+
isGeneric: true
|
|
71
|
+
});
|
|
43
72
|
const opt_data_name = TirDataOptT.toTirTypeKey();
|
|
44
73
|
program.defineGenericType(opt_data_name, 1, ([arg]) => new TirDataOptT(arg));
|
|
45
74
|
const opt_sop_name = TirSopOptT.toTirTypeKey();
|
|
@@ -542,29 +571,29 @@ export function populatePreludeScope(program) {
|
|
|
542
571
|
payment: credential_t,
|
|
543
572
|
stake: opt_stakeCredential_t
|
|
544
573
|
}, onlyData);
|
|
545
|
-
// type
|
|
574
|
+
// type ValueMap = LinearMap<PolicyId, LinearMap<TokenName, int>>
|
|
546
575
|
const map_tokenName_int_t = program.getAppliedGeneric(TirLinearMapT.toTirTypeKey(), [tokenName_t, int_t]);
|
|
547
576
|
if (!map_tokenName_int_t)
|
|
548
577
|
throw new Error("expected map_tokenName_int_t");
|
|
549
578
|
const map_policyId_map_tokenName_int_t = program.getAppliedGeneric(TirLinearMapT.toTirTypeKey(), [policyId_t, map_tokenName_int_t]);
|
|
550
579
|
if (!map_policyId_map_tokenName_int_t)
|
|
551
580
|
throw new Error("expected map_policyId_map_tokenName_int_t");
|
|
552
|
-
const
|
|
581
|
+
const valueMap_t = _defineUnambigousAlias("ValueMap", map_policyId_map_tokenName_int_t, new Map([
|
|
553
582
|
[
|
|
554
583
|
"lovelaces",
|
|
555
|
-
|
|
584
|
+
valueMapLovelacesName
|
|
556
585
|
],
|
|
557
586
|
[
|
|
558
587
|
"amountOf",
|
|
559
|
-
|
|
588
|
+
valueMapAmountOfName
|
|
560
589
|
],
|
|
561
590
|
]));
|
|
562
|
-
preludeScope.program.functions.set(
|
|
563
|
-
//
|
|
591
|
+
preludeScope.program.functions.set(valueMapLovelacesName, new TirInlineClosedIR(new TirFuncT([valueMap_t], int_t), (ctx) => IRNative._sortedValueLovelaces, SourceRange.unknown));
|
|
592
|
+
// ValueMap.amountOf( policy: PolicyId, name: bytes ): int
|
|
564
593
|
// The IR native _amountOfValue is curried as: (isPolicy)(value)(isTokenName) => int
|
|
565
594
|
// where isPolicy and isTokenName are equality-check predicates.
|
|
566
595
|
// This wrapper adapts (self, policy, tokenName) => _amountOfValue(p => equalsByteString(p, policy))(self)(tn => equalsByteString(tn, tokenName))
|
|
567
|
-
preludeScope.program.functions.set(
|
|
596
|
+
preludeScope.program.functions.set(valueMapAmountOfName, new TirInlineClosedIR(new TirFuncT([valueMap_t, policyId_t, bytes_t], int_t), (ctx) => {
|
|
568
597
|
const self = Symbol("amtOf_self");
|
|
569
598
|
const policy = Symbol("amtOf_policy");
|
|
570
599
|
const tokenName = Symbol("amtOf_tokenName");
|
|
@@ -578,37 +607,51 @@ export function populatePreludeScope(program) {
|
|
|
578
607
|
// isTokenName predicate: \tn -> equalsByteString(tn, tokenName)
|
|
579
608
|
_ir_apps(IRNative.equalsByteString, new IRVar(tokenName))));
|
|
580
609
|
}, SourceRange.unknown));
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
610
|
+
// Native `Value` (ConstTyTag.value). Methods route to the value builtins.
|
|
611
|
+
const value_native_t = program.types.get(TirValueT.toTirTypeKey());
|
|
612
|
+
if (!value_native_t)
|
|
613
|
+
throw new Error("expected native Value type registered");
|
|
614
|
+
const value_t = _defineUnambigousAlias("Value", value_native_t, new Map([
|
|
615
|
+
["lovelaces", valueLovelacesName],
|
|
616
|
+
["amountOf", valueAmountOfName],
|
|
617
|
+
["insert", valueInsertCoinName],
|
|
618
|
+
["union", valueUnionName],
|
|
619
|
+
["contains", valueContainsName],
|
|
620
|
+
["scale", valueScaleName],
|
|
621
|
+
["toData", valueToDataName],
|
|
622
|
+
]));
|
|
623
|
+
// Value.lovelaces(): int -- lookupCoin "" "" self
|
|
624
|
+
preludeScope.program.functions.set(valueLovelacesName, new TirInlineClosedIR(new TirFuncT([value_t], int_t), (ctx) => {
|
|
625
|
+
const self = Symbol("value_lovelaces_self");
|
|
626
|
+
return new IRFunc([self], _ir_apps(IRNative.lookupCoin, IRConst.bytes(new Uint8Array(0)), IRConst.bytes(new Uint8Array(0)), new IRVar(self)));
|
|
627
|
+
}, SourceRange.unknown));
|
|
628
|
+
// Value.amountOf( policy, name ): int -- lookupCoin policy name self
|
|
629
|
+
preludeScope.program.functions.set(valueAmountOfName, new TirInlineClosedIR(new TirFuncT([value_t, policyId_t, bytes_t], int_t), (ctx) => {
|
|
630
|
+
const self = Symbol("value_amountOf_self");
|
|
631
|
+
const policy = Symbol("value_amountOf_policy");
|
|
632
|
+
const tokenName = Symbol("value_amountOf_tokenName");
|
|
633
|
+
return new IRFunc([self, policy, tokenName], _ir_apps(IRNative.lookupCoin, new IRVar(policy), new IRVar(tokenName), new IRVar(self)));
|
|
634
|
+
}, SourceRange.unknown));
|
|
635
|
+
// Value.insert( policy, name, amount ): Value -- insertCoin policy name amount self
|
|
636
|
+
preludeScope.program.functions.set(valueInsertCoinName, new TirInlineClosedIR(new TirFuncT([value_t, policyId_t, bytes_t, int_t], value_t), (ctx) => {
|
|
637
|
+
const self = Symbol("value_insert_self");
|
|
638
|
+
const policy = Symbol("value_insert_policy");
|
|
639
|
+
const tokenName = Symbol("value_insert_tokenName");
|
|
640
|
+
const amount = Symbol("value_insert_amount");
|
|
641
|
+
return new IRFunc([self, policy, tokenName, amount], _ir_apps(IRNative.insertCoin, new IRVar(policy), new IRVar(tokenName), new IRVar(amount), new IRVar(self)));
|
|
642
|
+
}, SourceRange.unknown));
|
|
643
|
+
// Value.union( other ): Value -- unionValue self other
|
|
644
|
+
preludeScope.program.functions.set(valueUnionName, new TirInlineClosedIR(new TirFuncT([value_t, value_t], value_t), (ctx) => IRNative.unionValue, SourceRange.unknown));
|
|
645
|
+
// Value.contains( other ): bool -- valueContains self other
|
|
646
|
+
preludeScope.program.functions.set(valueContainsName, new TirInlineClosedIR(new TirFuncT([value_t, value_t], bool_t), (ctx) => IRNative.valueContains, SourceRange.unknown));
|
|
647
|
+
// Value.scale( factor ): Value -- scaleValue factor self
|
|
648
|
+
preludeScope.program.functions.set(valueScaleName, new TirInlineClosedIR(new TirFuncT([value_t, int_t], value_t), (ctx) => {
|
|
649
|
+
const self = Symbol("value_scale_self");
|
|
650
|
+
const factor = Symbol("value_scale_factor");
|
|
651
|
+
return new IRFunc([self, factor], _ir_apps(IRNative.scaleValue, new IRVar(factor), new IRVar(self)));
|
|
652
|
+
}, SourceRange.unknown));
|
|
653
|
+
// Value.toData(): data -- valueData self
|
|
654
|
+
preludeScope.program.functions.set(valueToDataName, new TirInlineClosedIR(new TirFuncT([value_t], data_t), (ctx) => IRNative.valueData, SourceRange.unknown));
|
|
612
655
|
// struct OutputDatum {
|
|
613
656
|
// NoDatum {}
|
|
614
657
|
// DatumHash { hash: Hash32 }
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { ConstType } from "@harmoniclabs/uplc";
|
|
2
|
+
import { AstFuncName, TirFuncName } from "../../AstCompiler/scope/AstScope.js";
|
|
3
|
+
import { ITirType, TirType } from "./TirType.js";
|
|
4
|
+
export declare class TirEnumType implements ITirType {
|
|
5
|
+
readonly name: string;
|
|
6
|
+
readonly fileUid: string;
|
|
7
|
+
readonly members: readonly string[];
|
|
8
|
+
readonly methodNamesPtr: Map<AstFuncName, TirFuncName>;
|
|
9
|
+
constructor(name: string, fileUid: string, members: readonly string[], methodNamesPtr: Map<AstFuncName, TirFuncName>);
|
|
10
|
+
indexOf(member: string): number;
|
|
11
|
+
isConcrete(): boolean;
|
|
12
|
+
hasDataEncoding(): boolean;
|
|
13
|
+
toString(): string;
|
|
14
|
+
toAstName(): string;
|
|
15
|
+
toTirTypeKey(): string;
|
|
16
|
+
toConcreteTirTypeName(): string;
|
|
17
|
+
toUplcConstType(): ConstType;
|
|
18
|
+
clone(): TirEnumType;
|
|
19
|
+
}
|
|
20
|
+
export declare function isTirEnumType(thing: any): thing is TirEnumType;
|
|
21
|
+
export declare function getEnumType(type: TirType | undefined): TirEnumType | undefined;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { isObject } from "@harmoniclabs/obj-utils";
|
|
2
|
+
import { constT } from "@harmoniclabs/uplc";
|
|
3
|
+
import { TirAliasType } from "./TirAliasType.js";
|
|
4
|
+
export class TirEnumType {
|
|
5
|
+
name;
|
|
6
|
+
fileUid;
|
|
7
|
+
members;
|
|
8
|
+
methodNamesPtr;
|
|
9
|
+
constructor(name, fileUid, members, methodNamesPtr) {
|
|
10
|
+
this.name = name;
|
|
11
|
+
this.fileUid = fileUid;
|
|
12
|
+
this.members = members;
|
|
13
|
+
this.methodNamesPtr = methodNamesPtr;
|
|
14
|
+
}
|
|
15
|
+
indexOf(member) {
|
|
16
|
+
return this.members.indexOf(member);
|
|
17
|
+
}
|
|
18
|
+
isConcrete() { return true; }
|
|
19
|
+
hasDataEncoding() { return true; }
|
|
20
|
+
toString() { return this.name; }
|
|
21
|
+
toAstName() { return this.name; }
|
|
22
|
+
toTirTypeKey() { return "enum_" + this.name + "_" + this.fileUid; }
|
|
23
|
+
toConcreteTirTypeName() { return this.toTirTypeKey(); }
|
|
24
|
+
toUplcConstType() { return constT.int; }
|
|
25
|
+
clone() {
|
|
26
|
+
return new TirEnumType(this.name, this.fileUid, this.members.slice(), this.methodNamesPtr);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
export function isTirEnumType(thing) {
|
|
30
|
+
return isObject(thing) && thing instanceof TirEnumType;
|
|
31
|
+
}
|
|
32
|
+
export function getEnumType(type) {
|
|
33
|
+
while (type instanceof TirAliasType)
|
|
34
|
+
type = type.aliased;
|
|
35
|
+
return type instanceof TirEnumType ? type : undefined;
|
|
36
|
+
}
|
|
@@ -12,9 +12,11 @@ import { TirDataOptT } from "./native/Optional/data.js";
|
|
|
12
12
|
import { TirSopOptT } from "./native/Optional/sop.js";
|
|
13
13
|
import { TirStringT } from "./native/string.js";
|
|
14
14
|
import { TirVoidT } from "./native/void.js";
|
|
15
|
-
|
|
15
|
+
import { TirArrayT } from "./native/array.js";
|
|
16
|
+
import { TirValueT } from "./native/value.js";
|
|
17
|
+
export type TirNamedDestructableNativeType = TirDataT | TirDataOptT<TirType> | TirSopOptT<TirType> | TirListT<TirType> | TirArrayT<TirType> | TirLinearMapT<TirType, TirType>;
|
|
16
18
|
export declare function isTirNamedDestructableNativeType(t: any): t is TirNamedDestructableNativeType;
|
|
17
|
-
export type TirNativeType = TirVoidT | TirBoolT | TirIntT | TirBytesT | TirStringT | TirDataT | TirDataOptT<TirType> | TirSopOptT<TirType> | TirListT<TirType> | TirLinearMapT<TirType, TirType> | TirLinearMapEntryT<TirType, TirType> | TirFuncT | TirUnConstrDataResultT | TirPairDataT | TirBlsG1T | TirBlsG2T | TirMlResultT;
|
|
19
|
+
export type TirNativeType = TirVoidT | TirBoolT | TirIntT | TirBytesT | TirStringT | TirDataT | TirDataOptT<TirType> | TirSopOptT<TirType> | TirListT<TirType> | TirArrayT<TirType> | TirValueT | TirLinearMapT<TirType, TirType> | TirLinearMapEntryT<TirType, TirType> | TirFuncT | TirUnConstrDataResultT | TirPairDataT | TirBlsG1T | TirBlsG2T | TirMlResultT;
|
|
18
20
|
export declare function isTirNativeType(t: any): t is TirNativeType;
|
|
19
21
|
export declare class TirUnConstrDataResultT implements ITirType {
|
|
20
22
|
constructor();
|
|
@@ -11,11 +11,14 @@ import { TirDataOptT } from "./native/Optional/data.js";
|
|
|
11
11
|
import { TirSopOptT } from "./native/Optional/sop.js";
|
|
12
12
|
import { TirStringT } from "./native/string.js";
|
|
13
13
|
import { TirVoidT } from "./native/void.js";
|
|
14
|
+
import { TirArrayT } from "./native/array.js";
|
|
15
|
+
import { TirValueT } from "./native/value.js";
|
|
14
16
|
export function isTirNamedDestructableNativeType(t) {
|
|
15
17
|
return (t instanceof TirDataT
|
|
16
18
|
|| t instanceof TirDataOptT
|
|
17
19
|
|| t instanceof TirSopOptT
|
|
18
20
|
|| t instanceof TirListT
|
|
21
|
+
|| t instanceof TirArrayT
|
|
19
22
|
|| t instanceof TirLinearMapT);
|
|
20
23
|
}
|
|
21
24
|
export function isTirNativeType(t) {
|
|
@@ -28,6 +31,8 @@ export function isTirNativeType(t) {
|
|
|
28
31
|
|| t instanceof TirDataOptT
|
|
29
32
|
|| t instanceof TirSopOptT
|
|
30
33
|
|| t instanceof TirListT
|
|
34
|
+
|| t instanceof TirArrayT
|
|
35
|
+
|| t instanceof TirValueT
|
|
31
36
|
|| t instanceof TirLinearMapT
|
|
32
37
|
|| t instanceof TirLinearMapEntryT
|
|
33
38
|
|| t instanceof TirFuncT // =>
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { ConstType } from "@harmoniclabs/uplc";
|
|
2
|
+
import { TirType, ITirType } from "../../TirType.js";
|
|
3
|
+
export declare class TirArrayT<T extends TirType = TirType> implements ITirType {
|
|
4
|
+
readonly typeArg: T;
|
|
5
|
+
constructor(typeArg: T);
|
|
6
|
+
hasDataEncoding(): boolean;
|
|
7
|
+
static toTirTypeKey(): string;
|
|
8
|
+
toTirTypeKey(): string;
|
|
9
|
+
toConcreteTirTypeName(): string;
|
|
10
|
+
toString(): string;
|
|
11
|
+
toAstName(): string;
|
|
12
|
+
private _isConcrete;
|
|
13
|
+
isConcrete(): boolean;
|
|
14
|
+
clone(): TirArrayT<T>;
|
|
15
|
+
toUplcConstType(): ConstType;
|
|
16
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { constT } from "@harmoniclabs/uplc";
|
|
2
|
+
import { getAppliedTirTypeName } from "../../../program/TypedProgram.js";
|
|
3
|
+
export class TirArrayT {
|
|
4
|
+
typeArg;
|
|
5
|
+
constructor(typeArg) {
|
|
6
|
+
this.typeArg = typeArg;
|
|
7
|
+
}
|
|
8
|
+
hasDataEncoding() { return this.typeArg.hasDataEncoding(); }
|
|
9
|
+
static toTirTypeKey() {
|
|
10
|
+
return "Array";
|
|
11
|
+
}
|
|
12
|
+
toTirTypeKey() {
|
|
13
|
+
return TirArrayT.toTirTypeKey();
|
|
14
|
+
}
|
|
15
|
+
toConcreteTirTypeName() {
|
|
16
|
+
return getAppliedTirTypeName(this.toTirTypeKey(), [this.typeArg.toConcreteTirTypeName()]);
|
|
17
|
+
}
|
|
18
|
+
toString() {
|
|
19
|
+
return `${this.toTirTypeKey()}<${this.typeArg.toString()}>`;
|
|
20
|
+
}
|
|
21
|
+
toAstName() {
|
|
22
|
+
return this.toTirTypeKey();
|
|
23
|
+
}
|
|
24
|
+
_isConcrete = undefined;
|
|
25
|
+
isConcrete() {
|
|
26
|
+
if (typeof this._isConcrete !== "boolean")
|
|
27
|
+
this._isConcrete = this.typeArg.isConcrete();
|
|
28
|
+
return this._isConcrete ?? false;
|
|
29
|
+
}
|
|
30
|
+
clone() {
|
|
31
|
+
const result = new TirArrayT(this.typeArg.clone());
|
|
32
|
+
result._isConcrete = this._isConcrete;
|
|
33
|
+
return result;
|
|
34
|
+
}
|
|
35
|
+
toUplcConstType() {
|
|
36
|
+
return constT.arrayOf(this.typeArg.toUplcConstType());
|
|
37
|
+
}
|
|
38
|
+
}
|
|
@@ -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";
|