@harmoniclabs/pebble 0.1.0-dev6 → 0.1.0-dev8
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 +1 -1
- package/dist/IR/IRNodes/IRNative/IRNativeTag.d.ts +6 -3
- package/dist/IR/IRNodes/IRNative/IRNativeTag.js +12 -4
- package/dist/IR/IRNodes/IRNative/index.d.ts +5 -2
- package/dist/IR/IRNodes/IRNative/index.js +6 -2
- package/dist/IR/toUPLC/CompilerOptions.d.ts +6 -1
- package/dist/IR/toUPLC/CompilerOptions.js +11 -1
- package/dist/IR/toUPLC/compileIRToUPLC.js +34 -35
- package/dist/IR/toUPLC/ctx/ToUplcCtx.js +2 -10
- package/dist/IR/toUPLC/subRoutines/handleLetted/groupByScope.js +0 -2
- package/dist/IR/toUPLC/subRoutines/handleLetted/index.js +69 -3
- package/dist/IR/toUPLC/subRoutines/replaceNatives/nativeToIR.d.ts +3 -1
- package/dist/IR/toUPLC/subRoutines/replaceNatives/nativeToIR.js +42 -10
- package/dist/IR/toUPLC/subRoutines/rewriteNativesAppliedToConstantsAndReturnRoot.js +292 -17
- package/dist/IR/utils/isClosedIRTerm.js +1 -1
- package/dist/IR/utils/positiveIntAsBytes.js +1 -5
- package/dist/compiler/AstCompiler/AstCompiler.d.ts +3 -0
- package/dist/compiler/AstCompiler/AstCompiler.js +66 -3
- package/dist/compiler/AstCompiler/internal/_deriveContractBody/_deriveContractBody.js +1 -1
- package/dist/compiler/AstCompiler/internal/exprs/_compileExpr.js +4 -0
- package/dist/compiler/AstCompiler/internal/exprs/_compileFuncExpr.js +13 -4
- package/dist/compiler/AstCompiler/internal/exprs/_compileTypeConversionExpr.js +0 -1
- package/dist/compiler/AstCompiler/internal/exprs/_compileVarAccessExpr.js +3 -1
- package/dist/compiler/AstCompiler/internal/statements/_compileAssignmentStmt.js +7 -7
- package/dist/compiler/AstCompiler/internal/statements/_compileVarStmt.d.ts +2 -1
- package/dist/compiler/AstCompiler/internal/statements/_compileVarStmt.js +2 -1
- package/dist/compiler/AstCompiler/scope/AstScope.d.ts +1 -0
- package/dist/compiler/AstCompiler/scope/AstScope.js +5 -0
- package/dist/compiler/Compiler.d.ts +8 -1
- package/dist/compiler/Compiler.js +38 -1
- package/dist/compiler/TirCompiler/compileTirProgram.js +2 -1
- package/dist/compiler/TirCompiler/expressify/ExpressifyCtx.d.ts +4 -2
- package/dist/compiler/TirCompiler/expressify/ExpressifyCtx.js +42 -16
- package/dist/compiler/TirCompiler/expressify/determineReassignedVariablesAndReturn.js +2 -0
- package/dist/compiler/TirCompiler/expressify/expressify.js +26 -9
- package/dist/compiler/TirCompiler/expressify/expressifyForStmt.js +23 -7
- package/dist/compiler/TirCompiler/expressify/expressifyVarAssignmentStmt.d.ts +1 -2
- package/dist/compiler/TirCompiler/expressify/expressifyVarAssignmentStmt.js +15 -8
- package/dist/compiler/TirCompiler/expressify/expressifyVarDecl.js +6 -9
- package/dist/compiler/TirCompiler/expressify/expressifyVars.js +51 -16
- package/dist/compiler/TirCompiler/expressify/flattenSopNamedDeconstructInplace_addTopDestructToCtx_getNestedDeconstruct.js +1 -0
- package/dist/compiler/internalVar.d.ts +1 -1
- package/dist/compiler/internalVar.js +31 -24
- package/dist/compiler/io/CompilerIoApi.d.ts +1 -1
- package/dist/compiler/tir/expressions/TirCallExpr.d.ts +1 -1
- package/dist/compiler/tir/expressions/TirCallExpr.js +1 -1
- package/dist/compiler/tir/expressions/TirCaseExpr.js +2 -0
- package/dist/compiler/tir/expressions/TirFromDataExpr.js +2 -2
- package/dist/compiler/tir/expressions/TirFuncExpr.d.ts +1 -1
- package/dist/compiler/tir/expressions/TirFuncExpr.js +1 -1
- package/dist/compiler/tir/expressions/TirLettedExpr.d.ts +2 -2
- package/dist/compiler/tir/expressions/TirLettedExpr.js +4 -6
- package/dist/compiler/tir/expressions/TirNativeFunc.d.ts +3 -2
- package/dist/compiler/tir/expressions/TirNativeFunc.js +33 -12
- package/dist/compiler/tir/expressions/TirPropAccessExpr.js +1 -2
- package/dist/compiler/tir/expressions/TirVariableAccessExpr.d.ts +0 -1
- package/dist/compiler/tir/expressions/TirVariableAccessExpr.js +9 -5
- package/dist/compiler/tir/expressions/ToIRTermCtx.d.ts +3 -0
- package/dist/compiler/tir/expressions/ToIRTermCtx.js +8 -1
- package/dist/compiler/tir/expressions/binary/TirBinaryExpr.d.ts +1 -0
- package/dist/compiler/tir/expressions/binary/TirBinaryExpr.js +6 -1
- package/dist/compiler/tir/program/TypedProgram.d.ts +2 -2
- package/dist/compiler/tir/program/stdScope/stdScope.js +9 -23
- package/dist/compiler/tir/statements/TirIfStmt.d.ts +0 -1
- package/dist/compiler/tir/statements/TirIfStmt.js +0 -3
- package/dist/parser/Parser.js +18 -2
- package/dist/parser/Precedence.js +1 -0
- package/dist/utils/BitUtils/index.d.ts +1 -1
- package/dist/utils/BitUtils/index.js +1 -1
- package/dist/utils/IsSingleKey.d.ts +1 -1
- package/dist/utils/UPLCFlatUtils/index.d.ts +1 -1
- package/dist/utils/UPLCFlatUtils/index.js +2 -2
- package/dist/utils/array/keepSortedArrInplace.js +1 -0
- package/package.json +7 -6
- package/dist/compiler/TirCompiler/internal/_compileHoistedDeps.d.ts +0 -5
- package/dist/compiler/TirCompiler/internal/_compileHoistedDeps.js +0 -39
|
@@ -6,7 +6,6 @@ export declare class TirIfStmt implements ITirStmt {
|
|
|
6
6
|
thenBranch: TirStmt;
|
|
7
7
|
elseBranch: TirStmt | undefined;
|
|
8
8
|
readonly range: SourceRange;
|
|
9
|
-
private _creationStack?;
|
|
10
9
|
constructor(condition: TirExpr, thenBranch: TirStmt, elseBranch: TirStmt | undefined, range: SourceRange);
|
|
11
10
|
toString(): string;
|
|
12
11
|
pretty(indent: number): string;
|
|
@@ -4,13 +4,11 @@ export class TirIfStmt {
|
|
|
4
4
|
thenBranch;
|
|
5
5
|
elseBranch;
|
|
6
6
|
range;
|
|
7
|
-
_creationStack;
|
|
8
7
|
constructor(condition, thenBranch, elseBranch, range) {
|
|
9
8
|
this.condition = condition;
|
|
10
9
|
this.thenBranch = thenBranch;
|
|
11
10
|
this.elseBranch = elseBranch;
|
|
12
11
|
this.range = range;
|
|
13
|
-
this._creationStack = new Error().stack;
|
|
14
12
|
}
|
|
15
13
|
toString() {
|
|
16
14
|
return (`if( ${this.condition.toString()} ) ` +
|
|
@@ -29,7 +27,6 @@ export class TirIfStmt {
|
|
|
29
27
|
(this.elseBranch ? ` else ${this.elseBranch.pretty(indent)}` : ""));
|
|
30
28
|
}
|
|
31
29
|
definitelyTerminates() {
|
|
32
|
-
console.log(this._creationStack);
|
|
33
30
|
return (this.thenBranch.definitelyTerminates()
|
|
34
31
|
&& (this.elseBranch?.definitelyTerminates() ?? false));
|
|
35
32
|
}
|
package/dist/parser/Parser.js
CHANGED
|
@@ -1139,7 +1139,9 @@ export class Parser extends DiagnosticEmitter {
|
|
|
1139
1139
|
// precedence climbing
|
|
1140
1140
|
// see: http://www.engr.mun.ca/~theo/Misc/exp_parsing.htm#climbing
|
|
1141
1141
|
let nextPrecedence;
|
|
1142
|
-
|
|
1142
|
+
let prevState;
|
|
1143
|
+
outer_while: while ((nextPrecedence = determinePrecedence(tn.peek())) >= precedence) {
|
|
1144
|
+
prevState = tn.mark();
|
|
1143
1145
|
const token = tn.next();
|
|
1144
1146
|
// DO NOT DIRECTLY RETURN FROM HERE
|
|
1145
1147
|
// we need to loop to support right associative operators
|
|
@@ -1320,6 +1322,11 @@ export class Parser extends DiagnosticEmitter {
|
|
|
1320
1322
|
expr = makeBinaryExpr(token, expr, next, tn.range(startPos, tn.pos));
|
|
1321
1323
|
break;
|
|
1322
1324
|
}
|
|
1325
|
+
// comma operator handled in caller (only valid in for statements)
|
|
1326
|
+
case Token.Comma: {
|
|
1327
|
+
tn.reset(prevState);
|
|
1328
|
+
break outer_while;
|
|
1329
|
+
}
|
|
1323
1330
|
default: {
|
|
1324
1331
|
return this.error(DiagnosticCode.Expression_expected, tn.range());
|
|
1325
1332
|
}
|
|
@@ -2016,6 +2023,12 @@ export class Parser extends DiagnosticEmitter {
|
|
|
2016
2023
|
case Token.Question_Question_Equals: {
|
|
2017
2024
|
return this.error(DiagnosticCode.Not_implemented_0, tn.range(), "??=");
|
|
2018
2025
|
}
|
|
2026
|
+
case Token.Plus_Plus: {
|
|
2027
|
+
return makeAssignmentStmt(varIdentifier, Token.Plus_Equals, new LitIntExpr(BigInt(1), tn.range()), tn.range(startPos, tn.pos));
|
|
2028
|
+
}
|
|
2029
|
+
case Token.Minus_Minus: {
|
|
2030
|
+
return makeAssignmentStmt(varIdentifier, Token.Minus_Equals, new LitIntExpr(BigInt(1), tn.range()), tn.range(startPos, tn.pos));
|
|
2031
|
+
}
|
|
2019
2032
|
default: {
|
|
2020
2033
|
return this.error(DiagnosticCode._0_expected, tn.range(), "=");
|
|
2021
2034
|
}
|
|
@@ -2180,8 +2193,11 @@ export class Parser extends DiagnosticEmitter {
|
|
|
2180
2193
|
return this.error(DiagnosticCode.Invalid_for_statement_update, update.range);
|
|
2181
2194
|
updates.push(update);
|
|
2182
2195
|
} while (tn.skip(Token.Comma)); // comma expression (allowed only in for update part)
|
|
2183
|
-
if (!tn.skip(Token.CloseParen))
|
|
2196
|
+
if (!tn.skip(Token.CloseParen)) {
|
|
2197
|
+
const next = tn.peek();
|
|
2198
|
+
console.error('next token after for updates:', Token[next]);
|
|
2184
2199
|
return this.error(DiagnosticCode._0_expected, tn.range(), ")");
|
|
2200
|
+
}
|
|
2185
2201
|
}
|
|
2186
2202
|
const body = this.parseStatement();
|
|
2187
2203
|
if (!body)
|
|
@@ -89,6 +89,7 @@ export function determinePrecedence(kind) {
|
|
|
89
89
|
case Token.Plus_Plus:
|
|
90
90
|
case Token.Minus_Minus: return Precedence.UnaryPostfix;
|
|
91
91
|
case Token.Dot:
|
|
92
|
+
case Token.Exclamation_Dot:
|
|
92
93
|
case Token.Question_Dot:
|
|
93
94
|
case Token.OpenBracket:
|
|
94
95
|
case Token.Exclamation: return Precedence.MemberAccess;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { BitStream } from "@harmoniclabs/bitstream";
|
|
2
|
-
import BitUtils from "../BitUtils/index.js";
|
|
3
2
|
import { assert } from "../assert.js";
|
|
3
|
+
import { BitUtils } from "../BitUtils/index.js";
|
|
4
4
|
export function isInByteOffset(offset) {
|
|
5
5
|
return (offset === 0 ||
|
|
6
6
|
offset === 1 ||
|
|
@@ -14,7 +14,7 @@ export function isInByteOffset(offset) {
|
|
|
14
14
|
/**
|
|
15
15
|
* @static
|
|
16
16
|
*/
|
|
17
|
-
export
|
|
17
|
+
export class UPLCFlatUtils {
|
|
18
18
|
/**
|
|
19
19
|
* @deprecated this is a @static class, it is not supposed to have instances
|
|
20
20
|
*/
|
|
@@ -21,6 +21,7 @@ export function keepSortedStrArrInplace(target, source) {
|
|
|
21
21
|
target.length = i + 1; // truncate target to current index
|
|
22
22
|
return target; // no more elements to keep
|
|
23
23
|
}
|
|
24
|
+
continue; // element is in source, check next without removing this
|
|
24
25
|
}
|
|
25
26
|
// not equal, remove the element
|
|
26
27
|
target.splice(i, 1);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@harmoniclabs/pebble",
|
|
3
|
-
"version": "0.1.0-
|
|
3
|
+
"version": "0.1.0-dev8",
|
|
4
4
|
"description": "A simple, yet rock solid, functional language with an imperative bias, targeting UPLC",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
@@ -20,6 +20,7 @@
|
|
|
20
20
|
"build-and-replace": "npm run build && cp -r ./dist ../pebble-cli/node_modules/@harmoniclabs/pebble",
|
|
21
21
|
"genDiagnosticMessages": "node ./scripts/genDiagnosticMessages.js",
|
|
22
22
|
"test": "jest",
|
|
23
|
+
"test-dbg": "node --nolazy --inspect-brk ./node_modules/jest/bin/jest.js --runInBand --colors --verbose",
|
|
23
24
|
"test:debug": "node --nolazy --inspect-brk ./node_modules/jest/bin/jest.js --runInBand --colors --verbose",
|
|
24
25
|
"clear-jest": "jest --clearCache",
|
|
25
26
|
"test-watch": "jest --watchman",
|
|
@@ -51,14 +52,14 @@
|
|
|
51
52
|
"dependencies": {
|
|
52
53
|
"@harmoniclabs/bigint-utils": "^1.0.0",
|
|
53
54
|
"@harmoniclabs/bytestring": "^1.0.0",
|
|
54
|
-
"@harmoniclabs/cbor": "^1.6.
|
|
55
|
-
"@harmoniclabs/crypto": "^0.
|
|
55
|
+
"@harmoniclabs/cbor": "^1.6.6",
|
|
56
|
+
"@harmoniclabs/crypto": "^0.3.0",
|
|
56
57
|
"@harmoniclabs/obj-utils": "^1.0.0",
|
|
57
58
|
"@harmoniclabs/pair": "^1.0.0",
|
|
58
|
-
"@harmoniclabs/plutus-data": "^1.2.
|
|
59
|
-
"@harmoniclabs/plutus-machine": "^2.1.
|
|
59
|
+
"@harmoniclabs/plutus-data": "^1.2.6",
|
|
60
|
+
"@harmoniclabs/plutus-machine": "^2.1.1",
|
|
60
61
|
"@harmoniclabs/uint8array-utils": "^1.0.4",
|
|
61
|
-
"@harmoniclabs/uplc": "^1.4.
|
|
62
|
+
"@harmoniclabs/uplc": "^1.4.1"
|
|
62
63
|
},
|
|
63
64
|
"devDependencies": {
|
|
64
65
|
"@babel/preset-env": "^7.18.6",
|
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
import { TirHoistedExpr } from "../../tir/expressions/TirHoistedExpr.js";
|
|
2
|
-
import { TirNativeFunc } from "../../tir/expressions/TirNativeFunc.js";
|
|
3
|
-
import { TypedProgram } from "../../tir/program/TypedProgram.js";
|
|
4
|
-
import { DepsNode } from "./deps/DepsNode.js";
|
|
5
|
-
export declare function _compileHoistedDeps(program: TypedProgram, hoistedMap: Map<string, TirHoistedExpr | TirNativeFunc>, deps: string[], depsStack: DepsNode): void;
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import { TirHoistedExpr } from "../../tir/expressions/TirHoistedExpr.js";
|
|
2
|
-
import { ExpressifyCtx } from "../expressify/ExpressifyCtx.js";
|
|
3
|
-
import { expressifyVars } from "../expressify/expressifyVars.js";
|
|
4
|
-
export function _compileHoistedDeps(program, hoistedMap, deps, depsStack) {
|
|
5
|
-
let depName;
|
|
6
|
-
if (deps.some(dep => depsStack.includes(dep)))
|
|
7
|
-
throw new Error("Circular dependency in hoisted expressions NOT YET IMPLEMENTED");
|
|
8
|
-
while (depName = deps.pop()) {
|
|
9
|
-
const funcDecl = program.functions.get(depName);
|
|
10
|
-
if (funcDecl) {
|
|
11
|
-
_compileHoistedDeps(program, hoistedMap, funcDecl.deps(), depsStack.getNext(depName));
|
|
12
|
-
/*
|
|
13
|
-
const funcExpr = funcDecl instanceof TirInlineClosedIR ? funcDecl : expressify(
|
|
14
|
-
funcDecl,
|
|
15
|
-
undefined, // loopReplacements
|
|
16
|
-
program,
|
|
17
|
-
new ExpressifyCtx(
|
|
18
|
-
undefined,
|
|
19
|
-
funcDecl.returnType,
|
|
20
|
-
program,
|
|
21
|
-
hoistedMap
|
|
22
|
-
)
|
|
23
|
-
);
|
|
24
|
-
//*/
|
|
25
|
-
const hoistedExpr = new TirHoistedExpr(depName, funcDecl);
|
|
26
|
-
hoistedMap.set(depName, hoistedExpr);
|
|
27
|
-
continue;
|
|
28
|
-
}
|
|
29
|
-
const constDecl = program.constants.get(depName);
|
|
30
|
-
if (constDecl) {
|
|
31
|
-
_compileHoistedDeps(program, hoistedMap, constDecl.deps(), depsStack.getNext(depName));
|
|
32
|
-
const expr = expressifyVars(new ExpressifyCtx(undefined, constDecl.type, program, hoistedMap), constDecl);
|
|
33
|
-
const hoistedExpr = new TirHoistedExpr(depName, expr);
|
|
34
|
-
hoistedMap.set(depName, hoistedExpr);
|
|
35
|
-
continue;
|
|
36
|
-
}
|
|
37
|
-
throw new Error(`Hoisted dependency "${depName}" not found in program`);
|
|
38
|
-
}
|
|
39
|
-
}
|