@harmoniclabs/pebble 0.2.0 → 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 +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/_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
|
@@ -229,16 +229,6 @@ export class TirNativeFunc {
|
|
|
229
229
|
void_t
|
|
230
230
|
], returnT));
|
|
231
231
|
}
|
|
232
|
-
static strictChooseList(elemT, returnT) {
|
|
233
|
-
return new TirNativeFunc(IRNativeTag.strictChooseList, new TirFuncT([
|
|
234
|
-
// list
|
|
235
|
-
new TirListT(elemT),
|
|
236
|
-
// caseNil
|
|
237
|
-
returnT,
|
|
238
|
-
// caseCons
|
|
239
|
-
returnT
|
|
240
|
-
], returnT));
|
|
241
|
-
}
|
|
242
232
|
// List operations with type parameters
|
|
243
233
|
static mkCons(elemT) {
|
|
244
234
|
return new TirNativeFunc(IRNativeTag.mkCons, new TirFuncT([
|
|
@@ -577,8 +567,8 @@ export class TirNativeFunc {
|
|
|
577
567
|
], bytes_t));
|
|
578
568
|
}
|
|
579
569
|
// Custom utility functions
|
|
580
|
-
static
|
|
581
|
-
return new TirNativeFunc(IRNativeTag.
|
|
570
|
+
static dropList(elemT) {
|
|
571
|
+
return new TirNativeFunc(IRNativeTag.dropList, new TirFuncT([
|
|
582
572
|
// n
|
|
583
573
|
int_t,
|
|
584
574
|
// list
|
|
@@ -7,6 +7,7 @@ import { IRNative } from "../../../IR/IRNodes/IRNative/index.js";
|
|
|
7
7
|
import { IRVar } from "../../../IR/IRNodes/IRVar.js";
|
|
8
8
|
import { data_t } from "../program/stdScope/stdScope.js";
|
|
9
9
|
import { TirDataStructType, TirSoPStructType } from "../types/TirStructType.js";
|
|
10
|
+
import { TirEnumType } from "../types/TirEnumType.js";
|
|
10
11
|
import { isTirType } from "../types/TirType.js";
|
|
11
12
|
import { getListTypeArg } from "../types/utils/getListTypeArg.js";
|
|
12
13
|
import { getOptTypeArg } from "../types/utils/getOptTypeArg.js";
|
|
@@ -99,6 +100,8 @@ export function _toDataUplcFunc(origin_t) {
|
|
|
99
100
|
return IRNative._id;
|
|
100
101
|
if (from_t instanceof TirIntT)
|
|
101
102
|
return IRNative.iData;
|
|
103
|
+
if (from_t instanceof TirEnumType)
|
|
104
|
+
return IRNative.iData;
|
|
102
105
|
if (from_t instanceof TirBytesT)
|
|
103
106
|
return IRNative.bData;
|
|
104
107
|
if (from_t instanceof TirVoidT)
|
|
@@ -7,6 +7,7 @@ import { TirIntT } from "../types/TirNativeType/native/int.js";
|
|
|
7
7
|
import { TirDataOptT } from "../types/TirNativeType/native/Optional/data.js";
|
|
8
8
|
import { TirStringT } from "../types/TirNativeType/native/string.js";
|
|
9
9
|
import { TirDataStructType } from "../types/TirStructType.js";
|
|
10
|
+
import { TirEnumType } from "../types/TirEnumType.js";
|
|
10
11
|
import { getUnaliased } from "../types/utils/getUnaliased.js";
|
|
11
12
|
import { _inlineFromData } from "./TirFromDataExpr.js";
|
|
12
13
|
import { _inlineToData } from "./TirToDataExpr.js";
|
|
@@ -49,12 +50,21 @@ export class TirTypeConversionExpr {
|
|
|
49
50
|
if (to_t instanceof TirIntT) {
|
|
50
51
|
if (from_t instanceof TirIntT)
|
|
51
52
|
return exprIR;
|
|
53
|
+
// enum is already an int at runtime; identity conversion.
|
|
54
|
+
if (from_t instanceof TirEnumType)
|
|
55
|
+
return exprIR;
|
|
52
56
|
if (from_t instanceof TirBytesT)
|
|
53
57
|
return _ir_apps(IRNative._bytesToIntBE, exprIR);
|
|
54
58
|
if (from_t instanceof TirBoolT)
|
|
55
59
|
return _ir_apps(IRNative._boolToInt, exprIR);
|
|
56
60
|
throw new Error(`Cannot convert from ${from_t.toString()} to ${to_t.toString()}`);
|
|
57
61
|
}
|
|
62
|
+
if (to_t instanceof TirEnumType) {
|
|
63
|
+
// identity at runtime — same enum type.
|
|
64
|
+
if (from_t instanceof TirEnumType)
|
|
65
|
+
return exprIR;
|
|
66
|
+
throw new Error(`Cannot convert from ${from_t.toString()} to ${to_t.toString()}`);
|
|
67
|
+
}
|
|
58
68
|
if (to_t instanceof TirBytesT) {
|
|
59
69
|
if (from_t instanceof TirBytesT)
|
|
60
70
|
return exprIR;
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { SourceRange } from "../../../ast/Source/SourceRange.js";
|
|
2
|
-
import {
|
|
3
|
-
import { IRVar } from "../../../IR/IRNodes/IRVar.js";
|
|
2
|
+
import type { IRTerm } from "../../../IR/IRTerm.js";
|
|
4
3
|
import { ResolveValueResult } from "../../AstCompiler/scope/AstScope.js";
|
|
5
4
|
import { TirType } from "../types/TirType.js";
|
|
6
5
|
import type { ITirExpr } from "./ITirExpr.js";
|
|
@@ -17,5 +16,5 @@ export declare class TirVariableAccessExpr implements ITirExpr {
|
|
|
17
16
|
get isConstant(): boolean;
|
|
18
17
|
get varName(): string;
|
|
19
18
|
deps(): string[];
|
|
20
|
-
toIR(ctx: ToIRTermCtx):
|
|
19
|
+
toIR(ctx: ToIRTermCtx): IRTerm;
|
|
21
20
|
}
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import { IRSelfCall } from "../../../IR/IRNodes/IRSelfCall.js";
|
|
2
|
-
import { IRVar } from "../../../IR/IRNodes/IRVar.js";
|
|
3
1
|
export class TirVariableAccessExpr {
|
|
4
2
|
range;
|
|
5
3
|
resolvedValue;
|
|
@@ -35,8 +33,7 @@ export class TirVariableAccessExpr {
|
|
|
35
33
|
deps() { return [this.varName]; }
|
|
36
34
|
toIR(ctx) {
|
|
37
35
|
const ir = ctx.getVarAccessIR(this.varName);
|
|
38
|
-
if (!
|
|
39
|
-
|| ir instanceof IRSelfCall)) {
|
|
36
|
+
if (!ir) {
|
|
40
37
|
throw new Error(`variable '${this.varName}' is missing in [${ctx.allVariables().join(", ")}]`);
|
|
41
38
|
}
|
|
42
39
|
return ir;
|
|
@@ -1,9 +1,17 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { IRSelfCall } from "../../../IR/IRNodes/IRSelfCall.js";
|
|
1
|
+
import type { IRTerm } from "../../../IR/IRTerm.js";
|
|
3
2
|
export declare class ToIRTermCtx {
|
|
4
3
|
readonly parent: ToIRTermCtx | undefined;
|
|
5
4
|
readonly _creationStack?: string | undefined;
|
|
6
5
|
private readonly localVars;
|
|
6
|
+
/**
|
|
7
|
+
* Per-name overrides whose lookup synthesizes a fresh IR term at each
|
|
8
|
+
* access (rather than resolving to a pre-allocated IRVar). Used to
|
|
9
|
+
* implement lazy field extraction in case-arms — the body's references
|
|
10
|
+
* to pattern-bound fields each emit an `IRLetted` over the extraction
|
|
11
|
+
* IR, so the letted-handling pass can dedup, hoist or eliminate as
|
|
12
|
+
* appropriate.
|
|
13
|
+
*/
|
|
14
|
+
private readonly deferredAccess;
|
|
7
15
|
private _firstVariableIsRecursive;
|
|
8
16
|
_children: ToIRTermCtx[];
|
|
9
17
|
constructor(parent: ToIRTermCtx | undefined);
|
|
@@ -13,7 +21,16 @@ export declare class ToIRTermCtx {
|
|
|
13
21
|
newChild(): ToIRTermCtx;
|
|
14
22
|
private localVarSym;
|
|
15
23
|
getVarAccessSym(name: string): symbol | undefined;
|
|
16
|
-
|
|
24
|
+
private getDeferredAccessFactory;
|
|
25
|
+
getVarAccessIR(name: string): IRTerm | undefined;
|
|
26
|
+
/**
|
|
27
|
+
* Register a per-name lookup override. Subsequent `getVarAccessIR(name)`
|
|
28
|
+
* calls in this context (or its descendants) return the IR term produced
|
|
29
|
+
* by `factory()`. The factory is invoked once per access — wrap the
|
|
30
|
+
* result in `IRLetted` if you want the IR-level let-handling pass to
|
|
31
|
+
* dedup / hoist / eliminate as appropriate.
|
|
32
|
+
*/
|
|
33
|
+
defineDeferredAccess(name: string, factory: () => IRTerm): void;
|
|
17
34
|
/**
|
|
18
35
|
* @returns the symbol of the defined variable (for eventual `new IRFunc( ... )`)
|
|
19
36
|
**/
|
|
@@ -5,6 +5,15 @@ export class ToIRTermCtx {
|
|
|
5
5
|
parent;
|
|
6
6
|
_creationStack;
|
|
7
7
|
localVars = new Map();
|
|
8
|
+
/**
|
|
9
|
+
* Per-name overrides whose lookup synthesizes a fresh IR term at each
|
|
10
|
+
* access (rather than resolving to a pre-allocated IRVar). Used to
|
|
11
|
+
* implement lazy field extraction in case-arms — the body's references
|
|
12
|
+
* to pattern-bound fields each emit an `IRLetted` over the extraction
|
|
13
|
+
* IR, so the letted-handling pass can dedup, hoist or eliminate as
|
|
14
|
+
* appropriate.
|
|
15
|
+
*/
|
|
16
|
+
deferredAccess = new Map();
|
|
8
17
|
_firstVariableIsRecursive = false;
|
|
9
18
|
_children = [];
|
|
10
19
|
constructor(parent) {
|
|
@@ -37,15 +46,51 @@ export class ToIRTermCtx {
|
|
|
37
46
|
return (this.localVarSym(name)
|
|
38
47
|
?? this.parent?.getVarAccessSym(name));
|
|
39
48
|
}
|
|
49
|
+
getDeferredAccessFactory(name) {
|
|
50
|
+
return (this.deferredAccess.get(name)
|
|
51
|
+
?? this.parent?.getDeferredAccessFactory(name));
|
|
52
|
+
}
|
|
40
53
|
getVarAccessIR(name) {
|
|
54
|
+
// deferred accesses (lazy field extraction in case-arms etc.)
|
|
55
|
+
// shadow symbol-based lookups when present.
|
|
56
|
+
const deferred = this.getDeferredAccessFactory(name);
|
|
57
|
+
if (deferred)
|
|
58
|
+
return deferred();
|
|
41
59
|
const accessSym = this.getVarAccessSym(name);
|
|
42
60
|
if (typeof accessSym !== "symbol")
|
|
43
61
|
return undefined;
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
62
|
+
// Recursive accesses must use IRSelfCall (the recursive symbol is
|
|
63
|
+
// bound by an IRRecursive, not an IRFunc — IRVar references would
|
|
64
|
+
// not find a binder during the unused-var pass). Walk the parent
|
|
65
|
+
// chain to find the ctx that owns `name`; that ctx may not be the
|
|
66
|
+
// current one when we're deep inside the recursive function's body
|
|
67
|
+
// (e.g. inside a `case` continuation that newChild'd from it).
|
|
68
|
+
let cur = this;
|
|
69
|
+
while (cur) {
|
|
70
|
+
const localSym = cur.localVars.get(name);
|
|
71
|
+
if (localSym !== undefined) {
|
|
72
|
+
if (cur._firstVariableIsRecursive
|
|
73
|
+
&& name === cur.localVars.keys().next().value)
|
|
74
|
+
return new IRSelfCall(accessSym);
|
|
75
|
+
break;
|
|
76
|
+
}
|
|
77
|
+
cur = cur.parent;
|
|
78
|
+
}
|
|
47
79
|
return new IRVar(accessSym);
|
|
48
80
|
}
|
|
81
|
+
/**
|
|
82
|
+
* Register a per-name lookup override. Subsequent `getVarAccessIR(name)`
|
|
83
|
+
* calls in this context (or its descendants) return the IR term produced
|
|
84
|
+
* by `factory()`. The factory is invoked once per access — wrap the
|
|
85
|
+
* result in `IRLetted` if you want the IR-level let-handling pass to
|
|
86
|
+
* dedup / hoist / eliminate as appropriate.
|
|
87
|
+
*/
|
|
88
|
+
defineDeferredAccess(name, factory) {
|
|
89
|
+
if (this.localVars.has(name) || this.deferredAccess.has(name)) {
|
|
90
|
+
throw new Error(`variable '${name}' already defined in the current scope`);
|
|
91
|
+
}
|
|
92
|
+
this.deferredAccess.set(name, factory);
|
|
93
|
+
}
|
|
49
94
|
/**
|
|
50
95
|
* @returns the symbol of the defined variable (for eventual `new IRFunc( ... )`)
|
|
51
96
|
**/
|
|
@@ -119,7 +119,7 @@ export declare class TirSubExpr implements ITirBinaryExpr {
|
|
|
119
119
|
left: TirExpr;
|
|
120
120
|
right: TirExpr;
|
|
121
121
|
readonly range: SourceRange;
|
|
122
|
-
|
|
122
|
+
get type(): TirType;
|
|
123
123
|
constructor(left: TirExpr, right: TirExpr, range: SourceRange);
|
|
124
124
|
toString(): string;
|
|
125
125
|
pretty(indent: number): string;
|
|
@@ -132,7 +132,7 @@ export declare class TirMultExpr implements ITirBinaryExpr {
|
|
|
132
132
|
left: TirExpr;
|
|
133
133
|
right: TirExpr;
|
|
134
134
|
readonly range: SourceRange;
|
|
135
|
-
|
|
135
|
+
get type(): TirType;
|
|
136
136
|
constructor(left: TirExpr, right: TirExpr, range: SourceRange);
|
|
137
137
|
toString(): string;
|
|
138
138
|
pretty(indent: number): string;
|
|
@@ -5,6 +5,8 @@ import { getUnaliased } from "../../types/utils/getUnaliased.js";
|
|
|
5
5
|
import { CEKConst, Machine } from "@harmoniclabs/plutus-machine";
|
|
6
6
|
import { TirBytesT } from "../../types/TirNativeType/native/bytes.js";
|
|
7
7
|
import { TirIntT } from "../../types/TirNativeType/native/int.js";
|
|
8
|
+
import { TirEnumType } from "../../types/TirEnumType.js";
|
|
9
|
+
import { TirValueT } from "../../types/TirNativeType/native/value.js";
|
|
8
10
|
import { IRNative } from "../../../../IR/IRNodes/IRNative/index.js";
|
|
9
11
|
import { IRConst } from "../../../../IR/IRNodes/IRConst.js";
|
|
10
12
|
import { compileIRToUPLC } from "../../../../IR/toUPLC/compileIRToUPLC.js";
|
|
@@ -87,7 +89,7 @@ export class TirLessThanExpr {
|
|
|
87
89
|
get isConstant() { return this.left.isConstant && this.right.isConstant; }
|
|
88
90
|
toIR(ctx) {
|
|
89
91
|
const type = getUnaliased(this.left.type);
|
|
90
|
-
const irFunc = (type instanceof TirIntT ? IRNative.lessThanInteger :
|
|
92
|
+
const irFunc = ((type instanceof TirIntT || type instanceof TirEnumType) ? IRNative.lessThanInteger :
|
|
91
93
|
type instanceof TirBytesT ? IRNative.lessThanByteString :
|
|
92
94
|
undefined);
|
|
93
95
|
if (!irFunc)
|
|
@@ -124,7 +126,7 @@ export class TirGreaterThanExpr {
|
|
|
124
126
|
get isConstant() { return this.left.isConstant && this.right.isConstant; }
|
|
125
127
|
toIR(ctx) {
|
|
126
128
|
const type = getUnaliased(this.left.type);
|
|
127
|
-
const irFunc = (type instanceof TirIntT ? IRNative.lessThanInteger :
|
|
129
|
+
const irFunc = ((type instanceof TirIntT || type instanceof TirEnumType) ? IRNative.lessThanInteger :
|
|
128
130
|
type instanceof TirBytesT ? IRNative.lessThanByteString :
|
|
129
131
|
undefined);
|
|
130
132
|
if (!irFunc)
|
|
@@ -163,7 +165,7 @@ export class TirLessThanEqualExpr {
|
|
|
163
165
|
get isConstant() { return this.left.isConstant && this.right.isConstant; }
|
|
164
166
|
toIR(ctx) {
|
|
165
167
|
const type = getUnaliased(this.left.type);
|
|
166
|
-
const irFunc = (type instanceof TirIntT ? IRNative.lessThanEqualInteger :
|
|
168
|
+
const irFunc = ((type instanceof TirIntT || type instanceof TirEnumType) ? IRNative.lessThanEqualInteger :
|
|
167
169
|
type instanceof TirBytesT ? IRNative.lessThanEqualsByteString :
|
|
168
170
|
undefined);
|
|
169
171
|
if (!irFunc)
|
|
@@ -200,7 +202,7 @@ export class TirGreaterThanEqualExpr {
|
|
|
200
202
|
get isConstant() { return this.left.isConstant && this.right.isConstant; }
|
|
201
203
|
toIR(ctx) {
|
|
202
204
|
const type = getUnaliased(this.left.type);
|
|
203
|
-
const irFunc = (type instanceof TirIntT ? IRNative.lessThanEqualInteger :
|
|
205
|
+
const irFunc = ((type instanceof TirIntT || type instanceof TirEnumType) ? IRNative.lessThanEqualInteger :
|
|
204
206
|
type instanceof TirBytesT ? IRNative.lessThanEqualsByteString :
|
|
205
207
|
undefined);
|
|
206
208
|
if (!irFunc)
|
|
@@ -285,9 +287,14 @@ export class TirAddExpr {
|
|
|
285
287
|
_creationStack;
|
|
286
288
|
get type() {
|
|
287
289
|
const leftType = getUnaliased(this.left.type);
|
|
290
|
+
if (leftType instanceof TirValueT)
|
|
291
|
+
return this.left.type;
|
|
288
292
|
if (leftType instanceof TirIntT
|
|
289
293
|
|| leftType instanceof TirBytesT)
|
|
290
294
|
return leftType;
|
|
295
|
+
// enum + int yields an int (enums lower to ints at runtime)
|
|
296
|
+
if (leftType instanceof TirEnumType)
|
|
297
|
+
return int_t;
|
|
291
298
|
throw new Error("invalid type for addition");
|
|
292
299
|
}
|
|
293
300
|
constructor(left, right, range) {
|
|
@@ -312,9 +319,10 @@ export class TirAddExpr {
|
|
|
312
319
|
get isConstant() { return this.left.isConstant && this.right.isConstant; }
|
|
313
320
|
toIR(ctx) {
|
|
314
321
|
const type = getUnaliased(this.left.type);
|
|
315
|
-
const irFunc = (type instanceof TirIntT ? IRNative.addInteger :
|
|
322
|
+
const irFunc = ((type instanceof TirIntT || type instanceof TirEnumType) ? IRNative.addInteger :
|
|
316
323
|
type instanceof TirBytesT ? IRNative.appendByteString :
|
|
317
|
-
|
|
324
|
+
type instanceof TirValueT ? IRNative.unionValue :
|
|
325
|
+
undefined);
|
|
318
326
|
if (!irFunc)
|
|
319
327
|
throw new Error("invalid left type for TirAddExpr");
|
|
320
328
|
return _ir_apps(irFunc, this.left.toIR(ctx), this.right.toIR(ctx));
|
|
@@ -329,7 +337,12 @@ export class TirSubExpr {
|
|
|
329
337
|
left;
|
|
330
338
|
right;
|
|
331
339
|
range;
|
|
332
|
-
type
|
|
340
|
+
get type() {
|
|
341
|
+
const leftType = getUnaliased(this.left.type);
|
|
342
|
+
if (leftType instanceof TirValueT)
|
|
343
|
+
return this.left.type;
|
|
344
|
+
return int_t;
|
|
345
|
+
}
|
|
333
346
|
constructor(left, right, range) {
|
|
334
347
|
this.left = left;
|
|
335
348
|
this.right = right;
|
|
@@ -348,6 +361,11 @@ export class TirSubExpr {
|
|
|
348
361
|
}
|
|
349
362
|
get isConstant() { return this.left.isConstant && this.right.isConstant; }
|
|
350
363
|
toIR(ctx) {
|
|
364
|
+
const type = getUnaliased(this.left.type);
|
|
365
|
+
if (type instanceof TirValueT) {
|
|
366
|
+
// a - b → unionValue a (negateValue b)
|
|
367
|
+
return _ir_apps(IRNative.unionValue, this.left.toIR(ctx), _ir_apps(IRNative._negateValue, this.right.toIR(ctx)));
|
|
368
|
+
}
|
|
351
369
|
return _ir_apps(IRNative.subtractInteger, this.left.toIR(ctx), this.right.toIR(ctx));
|
|
352
370
|
}
|
|
353
371
|
deps() {
|
|
@@ -360,7 +378,15 @@ export class TirMultExpr {
|
|
|
360
378
|
left;
|
|
361
379
|
right;
|
|
362
380
|
range;
|
|
363
|
-
type
|
|
381
|
+
get type() {
|
|
382
|
+
const leftTy = getUnaliased(this.left.type);
|
|
383
|
+
const rightTy = getUnaliased(this.right.type);
|
|
384
|
+
if (leftTy instanceof TirValueT)
|
|
385
|
+
return this.left.type;
|
|
386
|
+
if (rightTy instanceof TirValueT)
|
|
387
|
+
return this.right.type;
|
|
388
|
+
return int_t;
|
|
389
|
+
}
|
|
364
390
|
constructor(left, right, range) {
|
|
365
391
|
this.left = left;
|
|
366
392
|
this.right = right;
|
|
@@ -379,6 +405,17 @@ export class TirMultExpr {
|
|
|
379
405
|
}
|
|
380
406
|
get isConstant() { return this.left.isConstant && this.right.isConstant; }
|
|
381
407
|
toIR(ctx) {
|
|
408
|
+
const leftTy = getUnaliased(this.left.type);
|
|
409
|
+
const rightTy = getUnaliased(this.right.type);
|
|
410
|
+
// scaleValue :: int -> Value -> Value
|
|
411
|
+
if (leftTy instanceof TirValueT) {
|
|
412
|
+
// Value * int → scaleValue int Value
|
|
413
|
+
return _ir_apps(IRNative.scaleValue, this.right.toIR(ctx), this.left.toIR(ctx));
|
|
414
|
+
}
|
|
415
|
+
if (rightTy instanceof TirValueT) {
|
|
416
|
+
// int * Value → scaleValue int Value
|
|
417
|
+
return _ir_apps(IRNative.scaleValue, this.left.toIR(ctx), this.right.toIR(ctx));
|
|
418
|
+
}
|
|
382
419
|
return _ir_apps(IRNative.multiplyInteger, this.left.toIR(ctx), this.right.toIR(ctx));
|
|
383
420
|
}
|
|
384
421
|
deps() {
|
|
@@ -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 }
|