@harmoniclabs/pebble 0.1.3-dev0 → 0.1.3-dev2
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/IRNodes/IRConst.js +4 -6
- package/dist/IR/toUPLC/compileIRToUPLC.js +2 -0
- package/dist/IR/toUPLC/subRoutines/performUplcOptimizationsAndReturnRoot/ensureProperlyForcedBuiltinsAndReturnRoot.d.ts +2 -0
- package/dist/IR/toUPLC/subRoutines/performUplcOptimizationsAndReturnRoot/ensureProperlyForcedBuiltinsAndReturnRoot.js +163 -0
- package/dist/IR/toUPLC/subRoutines/performUplcOptimizationsAndReturnRoot/performUplcOptimizationsAndReturnRoot.js +12 -2
- package/dist/IR/tree_utils/intToUtf8Bytes.d.ts +8 -0
- package/dist/IR/tree_utils/intToUtf8Bytes.js +49 -0
- package/dist/ast/nodes/statements/PebbleStmt.d.ts +2 -1
- package/dist/ast/nodes/statements/PebbleStmt.js +2 -0
- package/dist/ast/nodes/statements/TraceStmt.d.ts +11 -0
- package/dist/ast/nodes/statements/TraceStmt.js +10 -0
- package/dist/compiler/AstCompiler/AstCompiler.d.ts +11 -0
- package/dist/compiler/AstCompiler/AstCompiler.js +185 -0
- package/dist/compiler/AstCompiler/internal/_deriveContractBody/_deriveContractBody.js +8 -0
- package/dist/compiler/AstCompiler/internal/statements/_compileStatement.js +4 -0
- package/dist/compiler/AstCompiler/internal/statements/_compileTraceStmt.d.ts +4 -0
- package/dist/compiler/AstCompiler/internal/statements/_compileTraceStmt.js +15 -0
- package/dist/compiler/Compiler.d.ts +5 -0
- package/dist/compiler/Compiler.js +26 -2
- package/dist/compiler/TirCompiler/expressify/determineReassignedVariablesAndReturn.js +5 -3
- package/dist/compiler/TirCompiler/expressify/expressify.js +8 -0
- package/dist/compiler/TirCompiler/expressify/expressifyIfBranch.js +2 -0
- package/dist/compiler/TirCompiler/expressify/expressifyVars.js +10 -1
- package/dist/compiler/tir/expressions/TirExpr.d.ts +2 -1
- package/dist/compiler/tir/expressions/TirExpr.js +2 -0
- package/dist/compiler/tir/expressions/TirNativeFunc.js +3 -3
- package/dist/compiler/tir/expressions/TirTraceExpr.d.ts +22 -0
- package/dist/compiler/tir/expressions/TirTraceExpr.js +53 -0
- package/dist/compiler/tir/expressions/TirTypeConversionExpr.js +6 -0
- package/dist/compiler/tir/statements/TirStmt.d.ts +2 -1
- package/dist/compiler/tir/statements/TirStmt.js +2 -0
- package/dist/compiler/tir/statements/TirTraceStmt.d.ts +15 -0
- package/dist/compiler/tir/statements/TirTraceStmt.js +20 -0
- package/dist/index.d.ts +0 -2
- package/dist/index.js +0 -2
- package/dist/parser/Parser.d.ts +2 -0
- package/dist/parser/Parser.js +15 -0
- package/dist/tokenizer/Token.d.ts +82 -81
- package/dist/tokenizer/Token.js +82 -81
- package/dist/tokenizer/utils/tokenFromKeyword.js +2 -0
- package/dist/utils/array/keepSortedArrInplace.js +15 -0
- package/package.json +7 -10
|
@@ -8,6 +8,11 @@ export declare class Compiler extends DiagnosticEmitter {
|
|
|
8
8
|
constructor(io?: CompilerIoApi, cfg?: CompilerOptions, diagnostics?: DiagnosticMessage[]);
|
|
9
9
|
compile(config?: Partial<CompilerOptions>): Promise<Uint8Array>;
|
|
10
10
|
export(config: Partial<ExportOptions> & HasFuncitonName): Promise<Uint8Array>;
|
|
11
|
+
run(config?: Partial<CompilerOptions>): Promise<{
|
|
12
|
+
result: import("@harmoniclabs/plutus-machine").CEKValueObj;
|
|
13
|
+
budgetSpent: import("@harmoniclabs/plutus-machine").ExBudget;
|
|
14
|
+
logs: string[];
|
|
15
|
+
}>;
|
|
11
16
|
private _compileBackend;
|
|
12
17
|
}
|
|
13
18
|
interface HasFuncitonName {
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { compileUPLC, UPLCProgram } from "@harmoniclabs/uplc";
|
|
1
|
+
import { compileUPLC, parseUPLC, UPLCProgram } from "@harmoniclabs/uplc";
|
|
2
|
+
import { Machine } from "@harmoniclabs/plutus-machine";
|
|
2
3
|
import { DiagnosticEmitter } from "../diagnostics/DiagnosticEmitter.js";
|
|
3
4
|
import { defaultOptions } from "../IR/toUPLC/CompilerOptions.js";
|
|
4
5
|
import { AstCompiler } from "./AstCompiler/AstCompiler.js";
|
|
@@ -60,11 +61,34 @@ export class Compiler extends DiagnosticEmitter {
|
|
|
60
61
|
}
|
|
61
62
|
return this._compileBackend(cfg, program);
|
|
62
63
|
}
|
|
64
|
+
async run(config) {
|
|
65
|
+
const cfg = {
|
|
66
|
+
...this.cfg,
|
|
67
|
+
...config,
|
|
68
|
+
// NEVER generate markers when running
|
|
69
|
+
addMarker: false,
|
|
70
|
+
};
|
|
71
|
+
const astCompiler = new AstCompiler(cfg, this.io, this.diagnostics);
|
|
72
|
+
const program = await astCompiler.run();
|
|
73
|
+
if (this.diagnostics.length > 0) {
|
|
74
|
+
let msg;
|
|
75
|
+
globalThis.console && console.log(this.diagnostics);
|
|
76
|
+
const fstErrorMsg = this.diagnostics[0].toString();
|
|
77
|
+
const nDiags = this.diagnostics.length;
|
|
78
|
+
while (msg = this.diagnostics.shift()) {
|
|
79
|
+
this.io.stdout.write(msg.toString() + "\n");
|
|
80
|
+
}
|
|
81
|
+
throw new Error("compilation failed with " + nDiags + " diagnostic messages; first message: " + fstErrorMsg);
|
|
82
|
+
}
|
|
83
|
+
const serialized = this._compileBackend(cfg, program);
|
|
84
|
+
const uplcProgram = parseUPLC(serialized);
|
|
85
|
+
return Machine.eval(uplcProgram.body);
|
|
86
|
+
}
|
|
63
87
|
_compileBackend(cfg, program) {
|
|
64
88
|
// backend starts here
|
|
65
89
|
const ir = compileTypedProgram(cfg, program);
|
|
66
90
|
const uplc = compileIRToUPLC(ir, cfg);
|
|
67
|
-
const serialized = compileUPLC(new UPLCProgram(cfg.targetUplcVersion, uplc))
|
|
91
|
+
const serialized = compileUPLC(new UPLCProgram(cfg.targetUplcVersion, uplc));
|
|
68
92
|
const outDir = cfg.outDir;
|
|
69
93
|
const outPath = outDir + (outDir.endsWith("/") ? "" : "/") + "out.flat";
|
|
70
94
|
this.io.writeFile(outPath, serialized, cfg.root);
|
|
@@ -9,6 +9,7 @@ import { TirBlockStmt } from "../../tir/statements/TirBlockStmt.js";
|
|
|
9
9
|
import { TirBreakStmt } from "../../tir/statements/TirBreakStmt.js";
|
|
10
10
|
import { TirContinueStmt } from "../../tir/statements/TirContinueStmt.js";
|
|
11
11
|
import { TirFailStmt } from "../../tir/statements/TirFailStmt.js";
|
|
12
|
+
import { TirTraceStmt } from "../../tir/statements/TirTraceStmt.js";
|
|
12
13
|
import { TirForOfStmt } from "../../tir/statements/TirForOfStmt.js";
|
|
13
14
|
import { TirForStmt } from "../../tir/statements/TirForStmt.js";
|
|
14
15
|
import { TirIfStmt } from "../../tir/statements/TirIfStmt.js";
|
|
@@ -25,6 +26,7 @@ export function determineReassignedVariablesAndReturn(stmt) {
|
|
|
25
26
|
let returns = false;
|
|
26
27
|
while (stmt = stack.pop()) {
|
|
27
28
|
if (stmt instanceof TirFailStmt
|
|
29
|
+
|| stmt instanceof TirTraceStmt
|
|
28
30
|
|| isTirVarDecl(stmt)
|
|
29
31
|
|| stmt instanceof TirBreakStmt
|
|
30
32
|
|| stmt instanceof TirContinueStmt
|
|
@@ -84,9 +86,8 @@ export function determineReassignedVariablesAndFlowInfos(stmt) {
|
|
|
84
86
|
let canContinue = false;
|
|
85
87
|
while (stmt = stack.pop()) {
|
|
86
88
|
if (stmt instanceof TirFailStmt
|
|
89
|
+
|| stmt instanceof TirTraceStmt
|
|
87
90
|
|| isTirVarDecl(stmt)
|
|
88
|
-
|| stmt instanceof TirBreakStmt
|
|
89
|
-
|| stmt instanceof TirContinueStmt
|
|
90
91
|
|| stmt instanceof TirAssertStmt)
|
|
91
92
|
continue;
|
|
92
93
|
if (stmt instanceof TirBreakStmt) {
|
|
@@ -193,7 +194,8 @@ export function definitelyFails(stmt) {
|
|
|
193
194
|
|| stmt instanceof TirBreakStmt
|
|
194
195
|
|| stmt instanceof TirContinueStmt
|
|
195
196
|
|| stmt instanceof TirAssertStmt
|
|
196
|
-
|| stmt instanceof TirAssignmentStmt
|
|
197
|
+
|| stmt instanceof TirAssignmentStmt
|
|
198
|
+
|| stmt instanceof TirTraceStmt)
|
|
197
199
|
continue;
|
|
198
200
|
// const tsEnsureExsaustiveCheck: never = stmt;
|
|
199
201
|
}
|
|
@@ -3,6 +3,7 @@ import { getUniqueInternalName } from "../../internalVar.js";
|
|
|
3
3
|
import { TirLitVoidExpr } from "../../tir/expressions/litteral/TirLitVoidExpr.js";
|
|
4
4
|
import { TirCaseExpr, TirCaseMatcher, TirWildcardCaseMatcher } from "../../tir/expressions/TirCaseExpr.js";
|
|
5
5
|
import { TirFailExpr } from "../../tir/expressions/TirFailExpr.js";
|
|
6
|
+
import { TirTraceExpr } from "../../tir/expressions/TirTraceExpr.js";
|
|
6
7
|
import { TirLettedExpr } from "../../tir/expressions/TirLettedExpr.js";
|
|
7
8
|
import { TirVariableAccessExpr } from "../../tir/expressions/TirVariableAccessExpr.js";
|
|
8
9
|
import { TirAssertStmt } from "../../tir/statements/TirAssertStmt.js";
|
|
@@ -11,6 +12,7 @@ import { TirBlockStmt } from "../../tir/statements/TirBlockStmt.js";
|
|
|
11
12
|
import { TirBreakStmt } from "../../tir/statements/TirBreakStmt.js";
|
|
12
13
|
import { TirContinueStmt } from "../../tir/statements/TirContinueStmt.js";
|
|
13
14
|
import { TirFailStmt } from "../../tir/statements/TirFailStmt.js";
|
|
15
|
+
import { TirTraceStmt } from "../../tir/statements/TirTraceStmt.js";
|
|
14
16
|
import { TirForOfStmt } from "../../tir/statements/TirForOfStmt.js";
|
|
15
17
|
import { TirForStmt } from "../../tir/statements/TirForStmt.js";
|
|
16
18
|
import { TirIfStmt } from "../../tir/statements/TirIfStmt.js";
|
|
@@ -217,6 +219,12 @@ loopReplacements, assertions = []) {
|
|
|
217
219
|
return TirAssertAndContinueExpr.fromStmtsAndContinuation(assertions, new TirFailExpr(undefined, ctx.returnType, stmt.range));
|
|
218
220
|
}
|
|
219
221
|
}
|
|
222
|
+
else if (stmt instanceof TirTraceStmt) {
|
|
223
|
+
const modifiedExpr = expressifyVars(ctx, stmt.expr);
|
|
224
|
+
stmt.expr = modifiedExpr;
|
|
225
|
+
const continuation = expressifyFuncBody(ctx, bodyStmts, loopReplacements);
|
|
226
|
+
return TirAssertAndContinueExpr.fromStmtsAndContinuation(assertions, new TirTraceExpr(modifiedExpr, continuation, stmt.range));
|
|
227
|
+
}
|
|
220
228
|
else if (stmt instanceof TirAssertStmt) {
|
|
221
229
|
const condition = expressifyVars(ctx, stmt.condition);
|
|
222
230
|
stmt.condition = condition;
|
|
@@ -8,6 +8,7 @@ import { TirBlockStmt } from "../../tir/statements/TirBlockStmt.js";
|
|
|
8
8
|
import { TirBreakStmt } from "../../tir/statements/TirBreakStmt.js";
|
|
9
9
|
import { TirContinueStmt } from "../../tir/statements/TirContinueStmt.js";
|
|
10
10
|
import { TirFailStmt } from "../../tir/statements/TirFailStmt.js";
|
|
11
|
+
import { TirTraceStmt } from "../../tir/statements/TirTraceStmt.js";
|
|
11
12
|
import { TirForOfStmt } from "../../tir/statements/TirForOfStmt.js";
|
|
12
13
|
import { TirForStmt } from "../../tir/statements/TirForStmt.js";
|
|
13
14
|
import { TirIfStmt } from "../../tir/statements/TirIfStmt.js";
|
|
@@ -60,6 +61,7 @@ function replaceReturnStatements(body, wrapReturnExpr, sopType) {
|
|
|
60
61
|
|| stmt instanceof TirBreakStmt
|
|
61
62
|
|| stmt instanceof TirContinueStmt
|
|
62
63
|
|| stmt instanceof TirFailStmt
|
|
64
|
+
|| stmt instanceof TirTraceStmt
|
|
63
65
|
|| stmt instanceof TirAssertStmt
|
|
64
66
|
|| stmt instanceof TirAssignmentStmt)
|
|
65
67
|
continue;
|
|
@@ -28,6 +28,7 @@ import { TirPropAccessExpr } from "../../tir/expressions/TirPropAccessExpr.js";
|
|
|
28
28
|
import { TirTernaryExpr } from "../../tir/expressions/TirTernaryExpr.js";
|
|
29
29
|
import { TirToDataExpr } from "../../tir/expressions/TirToDataExpr.js";
|
|
30
30
|
import { TirTraceIfFalseExpr } from "../../tir/expressions/TirTraceIfFalseExpr.js";
|
|
31
|
+
import { TirTraceExpr } from "../../tir/expressions/TirTraceExpr.js";
|
|
31
32
|
import { TirTypeConversionExpr } from "../../tir/expressions/TirTypeConversionExpr.js";
|
|
32
33
|
import { TirVariableAccessExpr } from "../../tir/expressions/TirVariableAccessExpr.js";
|
|
33
34
|
import { TirUnaryExclamation } from "../../tir/expressions/unary/TirUnaryExclamation.js";
|
|
@@ -212,6 +213,13 @@ export function expressifyVars(ctx, expr) {
|
|
|
212
213
|
expr.traceStrExpr = modifiedTraceStrExpr;
|
|
213
214
|
return expr;
|
|
214
215
|
}
|
|
216
|
+
if (expr instanceof TirTraceExpr) {
|
|
217
|
+
const modifiedTraceExpr = expressifyVars(ctx, expr.traceExpr);
|
|
218
|
+
const modifiedContinuation = expressifyVars(ctx, expr.continuation);
|
|
219
|
+
expr.traceExpr = modifiedTraceExpr;
|
|
220
|
+
expr.continuation = modifiedContinuation;
|
|
221
|
+
return expr;
|
|
222
|
+
}
|
|
215
223
|
if (expr instanceof TirInlineClosedIR)
|
|
216
224
|
return expr;
|
|
217
225
|
const tsEnsureExhautstiveCheck = expr;
|
|
@@ -243,9 +251,10 @@ function expressifyPropAccess(ctx, propAccessExpr) {
|
|
|
243
251
|
|| expr instanceof TirFuncExpr // functions have no properties
|
|
244
252
|
|| expr instanceof TirParentesizedExpr // typescript being stupid
|
|
245
253
|
|| isTirBinaryExpr(expr) // all of these return either int, bytes or boolean
|
|
246
|
-
// TirAssertAndContinueExpr | TirTraceIfFalseExpr | TirInlineClosedIR
|
|
254
|
+
// TirAssertAndContinueExpr | TirTraceIfFalseExpr | TirTraceExpr | TirInlineClosedIR
|
|
247
255
|
|| expr instanceof TirAssertAndContinueExpr
|
|
248
256
|
|| expr instanceof TirTraceIfFalseExpr
|
|
257
|
+
|| expr instanceof TirTraceExpr
|
|
249
258
|
|| expr instanceof TirInlineClosedIR)
|
|
250
259
|
throw new Error("Invalid property access expression");
|
|
251
260
|
if (expr instanceof TirLitThisExpr) {
|
|
@@ -17,7 +17,8 @@ import { TirHoistedExpr } from "./TirHoistedExpr.js";
|
|
|
17
17
|
import { TirToDataExpr } from "./TirToDataExpr.js";
|
|
18
18
|
import { TirAssertAndContinueExpr } from "./TirAssertAndContinueExpr.js";
|
|
19
19
|
import { TirTraceIfFalseExpr } from "./TirTraceIfFalseExpr.js";
|
|
20
|
+
import { TirTraceExpr } from "./TirTraceExpr.js";
|
|
20
21
|
import { TirNativeFunc } from "./TirNativeFunc.js";
|
|
21
22
|
import { TirInlineClosedIR } from "./TirInlineClosedIR.js";
|
|
22
|
-
export type TirExpr = (TirUnaryPrefixExpr | TirLitteralExpr | TirParentesizedExpr | TirFuncExpr | TirCallExpr | TirCaseExpr | TirTypeConversionExpr | TirElemAccessExpr | TirTernaryExpr | TirPropAccessExpr | TirBinaryExpr | TirVariableAccessExpr | TirLettedExpr | TirNativeFunc | TirFailExpr | TirHoistedExpr | TirFromDataExpr | TirToDataExpr | TirAssertAndContinueExpr | TirTraceIfFalseExpr | TirInlineClosedIR);
|
|
23
|
+
export type TirExpr = (TirUnaryPrefixExpr | TirLitteralExpr | TirParentesizedExpr | TirFuncExpr | TirCallExpr | TirCaseExpr | TirTypeConversionExpr | TirElemAccessExpr | TirTernaryExpr | TirPropAccessExpr | TirBinaryExpr | TirVariableAccessExpr | TirLettedExpr | TirNativeFunc | TirFailExpr | TirHoistedExpr | TirFromDataExpr | TirToDataExpr | TirAssertAndContinueExpr | TirTraceIfFalseExpr | TirTraceExpr | TirInlineClosedIR);
|
|
23
24
|
export declare function isTirExpr(thing: any): thing is TirExpr;
|
|
@@ -18,6 +18,7 @@ import { TirHoistedExpr } from "./TirHoistedExpr.js";
|
|
|
18
18
|
import { TirToDataExpr } from "./TirToDataExpr.js";
|
|
19
19
|
import { TirAssertAndContinueExpr } from "./TirAssertAndContinueExpr.js";
|
|
20
20
|
import { TirTraceIfFalseExpr } from "./TirTraceIfFalseExpr.js";
|
|
21
|
+
import { TirTraceExpr } from "./TirTraceExpr.js";
|
|
21
22
|
import { TirNativeFunc } from "./TirNativeFunc.js";
|
|
22
23
|
import { TirInlineClosedIR } from "./TirInlineClosedIR.js";
|
|
23
24
|
export function isTirExpr(thing) {
|
|
@@ -42,5 +43,6 @@ export function isTirExpr(thing) {
|
|
|
42
43
|
|| thing instanceof TirToDataExpr
|
|
43
44
|
|| thing instanceof TirAssertAndContinueExpr
|
|
44
45
|
|| thing instanceof TirTraceIfFalseExpr
|
|
46
|
+
|| thing instanceof TirTraceExpr
|
|
45
47
|
|| thing instanceof TirInlineClosedIR);
|
|
46
48
|
}
|
|
@@ -117,7 +117,7 @@ export class TirNativeFunc {
|
|
|
117
117
|
int_t
|
|
118
118
|
], bool_t));
|
|
119
119
|
}
|
|
120
|
-
//
|
|
120
|
+
// bytes operations
|
|
121
121
|
static get appendByteString() {
|
|
122
122
|
return new TirNativeFunc(IRNativeTag.appendByteString, new TirFuncT([
|
|
123
123
|
// left
|
|
@@ -512,7 +512,7 @@ export class TirNativeFunc {
|
|
|
512
512
|
bytes_t
|
|
513
513
|
], bytes_t));
|
|
514
514
|
}
|
|
515
|
-
//
|
|
515
|
+
// bytes manipulation
|
|
516
516
|
static get integerToByteString() {
|
|
517
517
|
return new TirNativeFunc(IRNativeTag.integerToByteString, new TirFuncT([
|
|
518
518
|
// flag
|
|
@@ -585,7 +585,7 @@ export class TirNativeFunc {
|
|
|
585
585
|
bool_t
|
|
586
586
|
], bytes_t));
|
|
587
587
|
}
|
|
588
|
-
// Additional
|
|
588
|
+
// Additional bytes operations
|
|
589
589
|
static get replicateByte() {
|
|
590
590
|
return new TirNativeFunc(IRNativeTag.replicateByte, new TirFuncT([
|
|
591
591
|
// count
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { SourceRange } from "../../../ast/Source/SourceRange.js";
|
|
2
|
+
import type { IRTerm } from "../../../IR/IRTerm.js";
|
|
3
|
+
import { TirType } from "../types/TirType.js";
|
|
4
|
+
import { ITirExpr } from "./ITirExpr.js";
|
|
5
|
+
import { TirExpr } from "./TirExpr.js";
|
|
6
|
+
import { ToIRTermCtx } from "./ToIRTermCtx.js";
|
|
7
|
+
export declare class TirTraceExpr implements ITirExpr {
|
|
8
|
+
/** must be bytes or int (converted to string via decodeUtf8 in toIR) */
|
|
9
|
+
traceExpr: TirExpr;
|
|
10
|
+
continuation: TirExpr;
|
|
11
|
+
readonly range: SourceRange;
|
|
12
|
+
get type(): TirType;
|
|
13
|
+
constructor(
|
|
14
|
+
/** must be bytes or int (converted to string via decodeUtf8 in toIR) */
|
|
15
|
+
traceExpr: TirExpr, continuation: TirExpr, range: SourceRange);
|
|
16
|
+
toString(): string;
|
|
17
|
+
pretty(indent: number): string;
|
|
18
|
+
clone(): TirExpr;
|
|
19
|
+
deps(): string[];
|
|
20
|
+
get isConstant(): boolean;
|
|
21
|
+
toIR(ctx: ToIRTermCtx): IRTerm;
|
|
22
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { _ir_apps } from "../../../IR/IRNodes/IRApp.js";
|
|
2
|
+
import { IRNative } from "../../../IR/IRNodes/IRNative/index.js";
|
|
3
|
+
import { hoisted_intToUtf8Bytes } from "../../../IR/tree_utils/intToUtf8Bytes.js";
|
|
4
|
+
import { mergeSortedStrArrInplace } from "../../../utils/array/mergeSortedStrArrInplace.js";
|
|
5
|
+
import { TirIntT } from "../types/TirNativeType/index.js";
|
|
6
|
+
import { getUnaliased } from "../types/utils/getUnaliased.js";
|
|
7
|
+
export class TirTraceExpr {
|
|
8
|
+
traceExpr;
|
|
9
|
+
continuation;
|
|
10
|
+
range;
|
|
11
|
+
get type() { return this.continuation.type; }
|
|
12
|
+
constructor(
|
|
13
|
+
/** must be bytes or int (converted to string via decodeUtf8 in toIR) */
|
|
14
|
+
traceExpr, continuation, range) {
|
|
15
|
+
this.traceExpr = traceExpr;
|
|
16
|
+
this.continuation = continuation;
|
|
17
|
+
this.range = range;
|
|
18
|
+
}
|
|
19
|
+
toString() {
|
|
20
|
+
return `(trace ${this.traceExpr.toString()} ${this.continuation.toString()})`;
|
|
21
|
+
}
|
|
22
|
+
pretty(indent) {
|
|
23
|
+
const singleIndent = " ";
|
|
24
|
+
const indent_base = singleIndent.repeat(indent);
|
|
25
|
+
const indent_1 = indent_base + singleIndent;
|
|
26
|
+
return (`(trace` +
|
|
27
|
+
`\n${indent_1}${this.traceExpr.pretty(indent + 1)}` +
|
|
28
|
+
`\n${indent_1}${this.continuation.pretty(indent + 1)}` +
|
|
29
|
+
`\n${indent_base})`);
|
|
30
|
+
}
|
|
31
|
+
clone() {
|
|
32
|
+
return new TirTraceExpr(this.traceExpr.clone(), this.continuation.clone(), this.range.clone());
|
|
33
|
+
}
|
|
34
|
+
deps() {
|
|
35
|
+
return mergeSortedStrArrInplace(this.traceExpr.deps(), this.continuation.deps());
|
|
36
|
+
}
|
|
37
|
+
get isConstant() { return this.traceExpr.isConstant && this.continuation.isConstant; }
|
|
38
|
+
toIR(ctx) {
|
|
39
|
+
let bytesIR;
|
|
40
|
+
const exprType = getUnaliased(this.traceExpr.type);
|
|
41
|
+
if (exprType instanceof TirIntT) {
|
|
42
|
+
// int -> bytes via intToUtf8Bytes
|
|
43
|
+
bytesIR = _ir_apps(hoisted_intToUtf8Bytes.clone(), this.traceExpr.toIR(ctx));
|
|
44
|
+
}
|
|
45
|
+
else {
|
|
46
|
+
// assume bytes
|
|
47
|
+
bytesIR = this.traceExpr.toIR(ctx);
|
|
48
|
+
}
|
|
49
|
+
return _ir_apps(IRNative.trace,
|
|
50
|
+
// bytes -> string via decodeUtf8
|
|
51
|
+
_ir_apps(IRNative.decodeUtf8, bytesIR), this.continuation.toIR(ctx));
|
|
52
|
+
}
|
|
53
|
+
}
|
|
@@ -5,6 +5,7 @@ import { TirBytesT } from "../types/TirNativeType/native/bytes.js";
|
|
|
5
5
|
import { TirDataT } from "../types/TirNativeType/native/data.js";
|
|
6
6
|
import { TirIntT } from "../types/TirNativeType/native/int.js";
|
|
7
7
|
import { TirDataOptT } from "../types/TirNativeType/native/Optional/data.js";
|
|
8
|
+
import { TirStringT } from "../types/TirNativeType/native/string.js";
|
|
8
9
|
import { TirDataStructType } from "../types/TirStructType.js";
|
|
9
10
|
import { getUnaliased } from "../types/utils/getUnaliased.js";
|
|
10
11
|
import { _inlineFromData } from "./TirFromDataExpr.js";
|
|
@@ -69,6 +70,11 @@ export class TirTypeConversionExpr {
|
|
|
69
70
|
return _ir_apps(IRNative._intToBool, exprIR);
|
|
70
71
|
throw new Error(`Cannot convert from ${from_t.toString()} to ${to_t.toString()}`);
|
|
71
72
|
}
|
|
73
|
+
if (to_t instanceof TirStringT) {
|
|
74
|
+
if (from_t instanceof TirBytesT)
|
|
75
|
+
return _ir_apps(IRNative.decodeUtf8, exprIR);
|
|
76
|
+
throw new Error(`Cannot convert from ${from_t.toString()} to ${to_t.toString()}`);
|
|
77
|
+
}
|
|
72
78
|
throw new Error(`Cannot convert from ${from_t.toString()} to ${to_t.toString()}`);
|
|
73
79
|
}
|
|
74
80
|
}
|
|
@@ -4,6 +4,7 @@ import { TirBlockStmt } from "./TirBlockStmt.js";
|
|
|
4
4
|
import { TirBreakStmt } from "./TirBreakStmt.js";
|
|
5
5
|
import { TirContinueStmt } from "./TirContinueStmt.js";
|
|
6
6
|
import { TirFailStmt } from "./TirFailStmt.js";
|
|
7
|
+
import { TirTraceStmt } from "./TirTraceStmt.js";
|
|
7
8
|
import { TirForOfStmt } from "./TirForOfStmt.js";
|
|
8
9
|
import { TirForStmt } from "./TirForStmt.js";
|
|
9
10
|
import { TirIfStmt } from "./TirIfStmt.js";
|
|
@@ -30,5 +31,5 @@ export interface ITirStmt extends HasSourceRange {
|
|
|
30
31
|
toString: () => string;
|
|
31
32
|
pretty: (indent: number) => string;
|
|
32
33
|
}
|
|
33
|
-
export type TirStmt = TirVarDecl | TirIfStmt | TirForStmt | TirForOfStmt | TirWhileStmt | TirReturnStmt | TirBlockStmt | TirBreakStmt | TirContinueStmt | TirFailStmt | TirAssertStmt | TirMatchStmt | TirAssignmentStmt;
|
|
34
|
+
export type TirStmt = TirVarDecl | TirIfStmt | TirForStmt | TirForOfStmt | TirWhileStmt | TirReturnStmt | TirBlockStmt | TirBreakStmt | TirContinueStmt | TirFailStmt | TirAssertStmt | TirTraceStmt | TirMatchStmt | TirAssignmentStmt;
|
|
34
35
|
export declare function isTirStmt(thing: any): thing is TirStmt;
|
|
@@ -5,6 +5,7 @@ import { TirBlockStmt } from "./TirBlockStmt.js";
|
|
|
5
5
|
import { TirBreakStmt } from "./TirBreakStmt.js";
|
|
6
6
|
import { TirContinueStmt } from "./TirContinueStmt.js";
|
|
7
7
|
import { TirFailStmt } from "./TirFailStmt.js";
|
|
8
|
+
import { TirTraceStmt } from "./TirTraceStmt.js";
|
|
8
9
|
import { TirForOfStmt } from "./TirForOfStmt.js";
|
|
9
10
|
import { TirForStmt } from "./TirForStmt.js";
|
|
10
11
|
import { TirIfStmt } from "./TirIfStmt.js";
|
|
@@ -32,6 +33,7 @@ export function isTirStmt(thing) {
|
|
|
32
33
|
|| thing instanceof TirContinueStmt
|
|
33
34
|
|| thing instanceof TirFailStmt
|
|
34
35
|
|| thing instanceof TirAssertStmt
|
|
36
|
+
|| thing instanceof TirTraceStmt
|
|
35
37
|
// || thing instanceof TirTestStmt
|
|
36
38
|
|| thing instanceof TirMatchStmt
|
|
37
39
|
|| thing instanceof TirAssignmentStmt
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { SourceRange } from "../../../ast/Source/SourceRange.js";
|
|
2
|
+
import { TirExpr } from "../expressions/TirExpr.js";
|
|
3
|
+
import { ITirStmt } from "./TirStmt.js";
|
|
4
|
+
export declare class TirTraceStmt implements ITirStmt {
|
|
5
|
+
/** must be string */
|
|
6
|
+
expr: TirExpr;
|
|
7
|
+
readonly range: SourceRange;
|
|
8
|
+
constructor(
|
|
9
|
+
/** must be string */
|
|
10
|
+
expr: TirExpr, range: SourceRange);
|
|
11
|
+
toString(): string;
|
|
12
|
+
pretty(indent: number): string;
|
|
13
|
+
definitelyTerminates(): boolean;
|
|
14
|
+
deps(): string[];
|
|
15
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export class TirTraceStmt {
|
|
2
|
+
expr;
|
|
3
|
+
range;
|
|
4
|
+
constructor(
|
|
5
|
+
/** must be string */
|
|
6
|
+
expr, range) {
|
|
7
|
+
this.expr = expr;
|
|
8
|
+
this.range = range;
|
|
9
|
+
}
|
|
10
|
+
toString() {
|
|
11
|
+
return `trace ${this.expr.toString()}`;
|
|
12
|
+
}
|
|
13
|
+
pretty(indent) {
|
|
14
|
+
return `trace ${this.expr.pretty(indent)}`;
|
|
15
|
+
}
|
|
16
|
+
definitelyTerminates() { return false; }
|
|
17
|
+
deps() {
|
|
18
|
+
return this.expr.deps();
|
|
19
|
+
}
|
|
20
|
+
}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
|
-
export * from "@harmoniclabs/bytestring";
|
|
2
1
|
export * from "@harmoniclabs/cbor";
|
|
3
2
|
export * from "@harmoniclabs/obj-utils";
|
|
4
|
-
export * from "@harmoniclabs/pair";
|
|
5
3
|
export * from "@harmoniclabs/plutus-data";
|
|
6
4
|
export * from "@harmoniclabs/plutus-machine";
|
|
7
5
|
export * from "@harmoniclabs/uint8array-utils";
|
package/dist/index.js
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
|
-
export * from "@harmoniclabs/bytestring";
|
|
2
1
|
export * from "@harmoniclabs/cbor";
|
|
3
2
|
export * from "@harmoniclabs/obj-utils";
|
|
4
|
-
export * from "@harmoniclabs/pair";
|
|
5
3
|
export * from "@harmoniclabs/plutus-data";
|
|
6
4
|
export * from "@harmoniclabs/plutus-machine";
|
|
7
5
|
export * from "@harmoniclabs/uint8array-utils";
|
package/dist/parser/Parser.d.ts
CHANGED
|
@@ -22,6 +22,7 @@ import { IfStmt } from "../ast/nodes/statements/IfStmt.js";
|
|
|
22
22
|
import { ReturnStmt } from "../ast/nodes/statements/ReturnStmt.js";
|
|
23
23
|
import { FuncDecl } from "../ast/nodes/statements/declarations/FuncDecl.js";
|
|
24
24
|
import { FailStmt } from "../ast/nodes/statements/FailStmt.js";
|
|
25
|
+
import { TraceStmt } from "../ast/nodes/statements/TraceStmt.js";
|
|
25
26
|
import { AssertStmt } from "../ast/nodes/statements/AssertStmt.js";
|
|
26
27
|
import { TestStmt } from "../ast/nodes/statements/TestStmt.js";
|
|
27
28
|
import { MatchStmt } from "../ast/nodes/statements/MatchStmt.js";
|
|
@@ -131,6 +132,7 @@ export declare class Parser extends DiagnosticEmitter {
|
|
|
131
132
|
parseTestStatement(): TestStmt | undefined;
|
|
132
133
|
parseMatchStatement(): MatchStmt | undefined;
|
|
133
134
|
parseFailStatement(): FailStmt | undefined;
|
|
135
|
+
parseTraceStatement(): TraceStmt | undefined;
|
|
134
136
|
parseAssertStatement(): AssertStmt | undefined;
|
|
135
137
|
parseWhileStatement(): WhileStmt | undefined;
|
|
136
138
|
/**
|
package/dist/parser/Parser.js
CHANGED
|
@@ -41,6 +41,7 @@ import { ReturnStmt } from "../ast/nodes/statements/ReturnStmt.js";
|
|
|
41
41
|
import { EmptyStmt } from "../ast/nodes/statements/EmptyStmt.js";
|
|
42
42
|
import { FuncDecl } from "../ast/nodes/statements/declarations/FuncDecl.js";
|
|
43
43
|
import { FailStmt } from "../ast/nodes/statements/FailStmt.js";
|
|
44
|
+
import { TraceStmt } from "../ast/nodes/statements/TraceStmt.js";
|
|
44
45
|
import { AssertStmt } from "../ast/nodes/statements/AssertStmt.js";
|
|
45
46
|
import { TestStmt } from "../ast/nodes/statements/TestStmt.js";
|
|
46
47
|
import { MatchStmt, MatchStmtCase, MatchStmtElseCase } from "../ast/nodes/statements/MatchStmt.js";
|
|
@@ -1919,6 +1920,12 @@ export class Parser extends DiagnosticEmitter {
|
|
|
1919
1920
|
break;
|
|
1920
1921
|
}
|
|
1921
1922
|
;
|
|
1923
|
+
case Token.Trace:
|
|
1924
|
+
{
|
|
1925
|
+
statement = this.parseTraceStatement();
|
|
1926
|
+
break;
|
|
1927
|
+
}
|
|
1928
|
+
;
|
|
1922
1929
|
// case Token.Try: {
|
|
1923
1930
|
// statement = this.parseTryStatement();
|
|
1924
1931
|
// break;
|
|
@@ -2319,6 +2326,14 @@ export class Parser extends DiagnosticEmitter {
|
|
|
2319
2326
|
return undefined;
|
|
2320
2327
|
return new FailStmt(expr, tn.range());
|
|
2321
2328
|
}
|
|
2329
|
+
parseTraceStatement() {
|
|
2330
|
+
const tn = this.tn;
|
|
2331
|
+
// at 'trace': Expression ';'?
|
|
2332
|
+
const expr = this.parseExpr();
|
|
2333
|
+
if (!expr)
|
|
2334
|
+
return this.error(DiagnosticCode.Expression_expected, tn.range());
|
|
2335
|
+
return new TraceStmt(expr, tn.range());
|
|
2336
|
+
}
|
|
2322
2337
|
parseAssertStatement() {
|
|
2323
2338
|
const tn = this.tn;
|
|
2324
2339
|
const startPos = tn.tokenPos;
|