@harmoniclabs/pebble 0.1.10 → 0.2.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/IRNodes/IRConst.js +14 -3
- package/dist/IR/IRNodes/IRNative/index.js +5 -1
- package/dist/IR/toUPLC/CompilerOptions.d.ts +22 -7
- package/dist/IR/toUPLC/CompilerOptions.js +5 -1
- package/dist/IR/tree_utils/bytesToHex.d.ts +8 -0
- package/dist/IR/tree_utils/bytesToHex.js +69 -0
- package/dist/ast/nodes/expr/functions/FuncExpr.d.ts +16 -2
- package/dist/ast/nodes/expr/functions/FuncExpr.js +17 -0
- package/dist/ast/nodes/expr/litteral/LitteralExpr.d.ts +2 -1
- package/dist/ast/nodes/expr/litteral/LitteralExpr.js +2 -0
- package/dist/ast/nodes/expr/litteral/TemplateStrExpr.d.ts +30 -0
- package/dist/ast/nodes/expr/litteral/TemplateStrExpr.js +35 -0
- package/dist/ast/nodes/statements/ExportStmt.d.ts +3 -3
- package/dist/ast/nodes/statements/PebbleStmt.d.ts +4 -3
- package/dist/ast/nodes/statements/PebbleStmt.js +6 -2
- package/dist/ast/nodes/statements/TestParam.d.ts +18 -0
- package/dist/ast/nodes/statements/TestParam.js +18 -0
- package/dist/ast/nodes/statements/TestStmt.d.ts +5 -3
- package/dist/ast/nodes/statements/TestStmt.js +3 -1
- package/dist/ast/nodes/statements/UsingStmt.d.ts +32 -2
- package/dist/ast/nodes/statements/UsingStmt.js +39 -3
- package/dist/ast/nodes/statements/declarations/NamespaceDecl.d.ts +21 -0
- package/dist/ast/nodes/statements/declarations/NamespaceDecl.js +31 -0
- package/dist/compiler/AstCompiler/AstCompiler.d.ts +26 -0
- package/dist/compiler/AstCompiler/AstCompiler.js +203 -3
- package/dist/compiler/AstCompiler/internal/_deriveContractBody/_deriveContractBody.js +13 -2
- package/dist/compiler/AstCompiler/internal/exprs/_compileCallExpr.js +97 -6
- package/dist/compiler/AstCompiler/internal/exprs/_compileFuncExpr.js +12 -5
- package/dist/compiler/AstCompiler/internal/exprs/_compileLitteralExpr.js +59 -0
- package/dist/compiler/AstCompiler/internal/exprs/_compilePropAccessExpr.d.ts +2 -3
- package/dist/compiler/AstCompiler/internal/exprs/_compilePropAccessExpr.js +28 -0
- package/dist/compiler/AstCompiler/internal/exprs/_compileVarAccessExpr.js +2 -0
- package/dist/compiler/AstCompiler/internal/statements/_compileStatement.js +4 -1
- package/dist/compiler/AstCompiler/internal/statements/_compileTestStmt.d.ts +15 -1
- package/dist/compiler/AstCompiler/internal/statements/_compileTestStmt.js +70 -30
- package/dist/compiler/AstCompiler/internal/statements/_compileUsingAliasStmt.d.ts +11 -0
- package/dist/compiler/AstCompiler/internal/statements/_compileUsingAliasStmt.js +26 -0
- package/dist/compiler/AstCompiler/internal/statements/_compileUsingStmt.d.ts +9 -4
- package/dist/compiler/AstCompiler/internal/statements/_compileUsingStmt.js +51 -10
- package/dist/compiler/AstCompiler/internal/types/_compileDataEncodedConcreteType.js +21 -2
- package/dist/compiler/AstCompiler/internal/types/_compileSopEncodedConcreteType.js +17 -2
- package/dist/compiler/AstCompiler/scope/AstScope.d.ts +70 -1
- package/dist/compiler/AstCompiler/scope/AstScope.js +91 -0
- package/dist/compiler/AstCompiler/utils/getPropAccessReturnType.js +25 -1
- package/dist/compiler/AstCompiler/utils/monomorphizeGeneric.d.ts +36 -0
- package/dist/compiler/AstCompiler/utils/monomorphizeGeneric.js +123 -0
- package/dist/compiler/AstCompiler/utils/resolveNamespaceChain.d.ts +28 -0
- package/dist/compiler/AstCompiler/utils/resolveNamespaceChain.js +95 -0
- package/dist/compiler/AstCompiler/utils/resolveNamespacePath.d.ts +37 -0
- package/dist/compiler/AstCompiler/utils/resolveNamespacePath.js +93 -0
- package/dist/compiler/Compiler.d.ts +9 -1
- package/dist/compiler/Compiler.js +204 -9
- package/dist/compiler/TirCompiler/expressify/expressifyVars.js +26 -7
- package/dist/compiler/test/TestResult.d.ts +38 -0
- package/dist/compiler/test/TestResult.js +6 -0
- package/dist/compiler/test/fuzz/PRNG.d.ts +26 -0
- package/dist/compiler/test/fuzz/PRNG.js +59 -0
- 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.d.ts +17 -0
- package/dist/compiler/tir/expressions/TirNativeFunc.js +53 -106
- package/dist/compiler/tir/expressions/TirShowExpr.d.ts +52 -0
- package/dist/compiler/tir/expressions/TirShowExpr.js +199 -0
- package/dist/compiler/tir/expressions/TirTraceExpr.js +11 -7
- package/dist/compiler/tir/program/TypedProgram.d.ts +101 -0
- package/dist/compiler/tir/program/TypedProgram.js +43 -0
- package/dist/compiler/tir/program/stdScope/populateBuiltinInterfaces.d.ts +17 -0
- package/dist/compiler/tir/program/stdScope/populateBuiltinInterfaces.js +70 -0
- package/dist/compiler/tir/program/stdScope/populateStdNamespace.d.ts +22 -0
- package/dist/compiler/tir/program/stdScope/populateStdNamespace.js +574 -0
- package/dist/compiler/tir/program/stdScope/stdScope.d.ts +1 -0
- package/dist/compiler/tir/program/stdScope/stdScope.js +1 -1
- package/dist/compiler/tir/statements/TirStmt.js +0 -1
- package/dist/compiler/tir/statements/TirTestStmt.d.ts +46 -0
- package/dist/compiler/tir/statements/TirTestStmt.js +35 -0
- package/dist/compiler/tir/types/TirNativeType/TirNativeType.d.ts +50 -1
- package/dist/compiler/tir/types/TirNativeType/TirNativeType.js +53 -1
- package/dist/compiler/tir/types/TirType.js +3 -1
- package/dist/compiler/tir/types/utils/canAssignTo.js +8 -1
- package/dist/compiler/tir/types/utils/inferTypeArgs.d.ts +19 -0
- package/dist/compiler/tir/types/utils/inferTypeArgs.js +79 -0
- package/dist/compiler/tir/types/utils/substituteTypeParams.d.ts +9 -0
- package/dist/compiler/tir/types/utils/substituteTypeParams.js +62 -0
- package/dist/diagnostics/diagnosticMessages.generated.d.ts +5 -0
- package/dist/diagnostics/diagnosticMessages.generated.js +10 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +2 -0
- package/dist/parser/Parser.d.ts +73 -3
- package/dist/parser/Parser.js +333 -33
- package/dist/tokenizer/Token.d.ts +105 -102
- package/dist/tokenizer/Token.js +110 -109
- package/dist/tokenizer/utils/tokenFromKeyword.js +9 -6
- package/dist/utils/semverSatisfies.d.ts +1 -0
- package/dist/utils/semverSatisfies.js +161 -0
- package/dist/version.generated.d.ts +1 -0
- package/dist/version.generated.js +2 -0
- package/package.json +3 -2
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
// Tiny npm-style semver range matcher. Supports exact versions, comparator
|
|
2
|
+
// prefixes (>=, >, <=, <, =), caret (^), tilde (~), wildcards (*, x, X),
|
|
3
|
+
// hyphen ranges (a - b), AND (whitespace), and OR (||). Prerelease/build
|
|
4
|
+
// metadata is dropped; only the numeric MAJOR.MINOR.PATCH is compared.
|
|
5
|
+
function parseLoose(input) {
|
|
6
|
+
let s = input.trim().replace(/^v/i, "");
|
|
7
|
+
if (s.length === 0)
|
|
8
|
+
return null;
|
|
9
|
+
s = s.split(/[-+]/)[0];
|
|
10
|
+
if (s === "" || s === "*" || s === "x" || s === "X") {
|
|
11
|
+
return [undefined, undefined, undefined];
|
|
12
|
+
}
|
|
13
|
+
const m = s.match(/^(\d+|x|X|\*)(?:\.(\d+|x|X|\*))?(?:\.(\d+|x|X|\*))?$/);
|
|
14
|
+
if (!m)
|
|
15
|
+
return null;
|
|
16
|
+
const conv = (p) => p === undefined || p === "x" || p === "X" || p === "*"
|
|
17
|
+
? undefined
|
|
18
|
+
: parseInt(p, 10);
|
|
19
|
+
return [conv(m[1]), conv(m[2]), conv(m[3])];
|
|
20
|
+
}
|
|
21
|
+
function parseStrict(input) {
|
|
22
|
+
const p = parseLoose(input);
|
|
23
|
+
if (!p)
|
|
24
|
+
return null;
|
|
25
|
+
if (p[0] === undefined || p[1] === undefined || p[2] === undefined)
|
|
26
|
+
return null;
|
|
27
|
+
return [p[0], p[1], p[2]];
|
|
28
|
+
}
|
|
29
|
+
function fillLow(p) {
|
|
30
|
+
return [p[0] ?? 0, p[1] ?? 0, p[2] ?? 0];
|
|
31
|
+
}
|
|
32
|
+
function cmp(a, b) {
|
|
33
|
+
if (a[0] !== b[0])
|
|
34
|
+
return a[0] < b[0] ? -1 : 1;
|
|
35
|
+
if (a[1] !== b[1])
|
|
36
|
+
return a[1] < b[1] ? -1 : 1;
|
|
37
|
+
if (a[2] !== b[2])
|
|
38
|
+
return a[2] < b[2] ? -1 : 1;
|
|
39
|
+
return 0;
|
|
40
|
+
}
|
|
41
|
+
function satisfiesComp(v, c) {
|
|
42
|
+
const r = cmp(v, c.v);
|
|
43
|
+
switch (c.op) {
|
|
44
|
+
case ">": return r > 0;
|
|
45
|
+
case ">=": return r >= 0;
|
|
46
|
+
case "<": return r < 0;
|
|
47
|
+
case "<=": return r <= 0;
|
|
48
|
+
case "=": return r === 0;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
function caretUpper(p) {
|
|
52
|
+
const [a, b, c] = p;
|
|
53
|
+
if ((a ?? 0) !== 0)
|
|
54
|
+
return [(a ?? 0) + 1, 0, 0];
|
|
55
|
+
if ((b ?? 0) !== 0)
|
|
56
|
+
return [0, (b ?? 0) + 1, 0];
|
|
57
|
+
return [0, 0, (c ?? 0) + 1];
|
|
58
|
+
}
|
|
59
|
+
function tildeUpper(p) {
|
|
60
|
+
const [a, b] = p;
|
|
61
|
+
if (b !== undefined)
|
|
62
|
+
return [a ?? 0, b + 1, 0];
|
|
63
|
+
return [(a ?? 0) + 1, 0, 0];
|
|
64
|
+
}
|
|
65
|
+
function expandToken(tok) {
|
|
66
|
+
tok = tok.trim();
|
|
67
|
+
if (tok === "" || tok === "*" || tok === "x" || tok === "X") {
|
|
68
|
+
return [{ op: ">=", v: [0, 0, 0] }];
|
|
69
|
+
}
|
|
70
|
+
const cmpMatch = tok.match(/^(>=|<=|>|<|=)\s*(.+)$/);
|
|
71
|
+
if (cmpMatch) {
|
|
72
|
+
const op = cmpMatch[1];
|
|
73
|
+
const p = parseLoose(cmpMatch[2]);
|
|
74
|
+
if (!p)
|
|
75
|
+
return null;
|
|
76
|
+
return [{ op, v: fillLow(p) }];
|
|
77
|
+
}
|
|
78
|
+
if (tok.startsWith("^")) {
|
|
79
|
+
const p = parseLoose(tok.slice(1));
|
|
80
|
+
if (!p)
|
|
81
|
+
return null;
|
|
82
|
+
return [
|
|
83
|
+
{ op: ">=", v: fillLow(p) },
|
|
84
|
+
{ op: "<", v: caretUpper(p) }
|
|
85
|
+
];
|
|
86
|
+
}
|
|
87
|
+
if (tok.startsWith("~")) {
|
|
88
|
+
const p = parseLoose(tok.slice(1));
|
|
89
|
+
if (!p)
|
|
90
|
+
return null;
|
|
91
|
+
return [
|
|
92
|
+
{ op: ">=", v: fillLow(p) },
|
|
93
|
+
{ op: "<", v: tildeUpper(p) }
|
|
94
|
+
];
|
|
95
|
+
}
|
|
96
|
+
const p = parseLoose(tok);
|
|
97
|
+
if (!p)
|
|
98
|
+
return null;
|
|
99
|
+
const [a, b, c] = p;
|
|
100
|
+
if (a === undefined)
|
|
101
|
+
return [{ op: ">=", v: [0, 0, 0] }];
|
|
102
|
+
if (b === undefined)
|
|
103
|
+
return [
|
|
104
|
+
{ op: ">=", v: [a, 0, 0] },
|
|
105
|
+
{ op: "<", v: [a + 1, 0, 0] }
|
|
106
|
+
];
|
|
107
|
+
if (c === undefined)
|
|
108
|
+
return [
|
|
109
|
+
{ op: ">=", v: [a, b, 0] },
|
|
110
|
+
{ op: "<", v: [a, b + 1, 0] }
|
|
111
|
+
];
|
|
112
|
+
return [{ op: "=", v: [a, b, c] }];
|
|
113
|
+
}
|
|
114
|
+
function expandRangePart(part) {
|
|
115
|
+
const hyphen = part.match(/^(\S+)\s+-\s+(\S+)$/);
|
|
116
|
+
if (hyphen) {
|
|
117
|
+
const lo = parseLoose(hyphen[1]);
|
|
118
|
+
const hi = parseLoose(hyphen[2]);
|
|
119
|
+
if (!lo || !hi)
|
|
120
|
+
return null;
|
|
121
|
+
const lower = { op: ">=", v: fillLow(lo) };
|
|
122
|
+
const [ha, hb, hc] = hi;
|
|
123
|
+
if (ha === undefined)
|
|
124
|
+
return [lower];
|
|
125
|
+
if (hb === undefined)
|
|
126
|
+
return [lower, { op: "<", v: [ha + 1, 0, 0] }];
|
|
127
|
+
if (hc === undefined)
|
|
128
|
+
return [lower, { op: "<", v: [ha, hb + 1, 0] }];
|
|
129
|
+
return [lower, { op: "<=", v: [ha, hb, hc] }];
|
|
130
|
+
}
|
|
131
|
+
const tokens = part.split(/\s+/).filter(t => t.length > 0);
|
|
132
|
+
if (tokens.length === 0)
|
|
133
|
+
return null;
|
|
134
|
+
const result = [];
|
|
135
|
+
for (const tok of tokens) {
|
|
136
|
+
const cmps = expandToken(tok);
|
|
137
|
+
if (!cmps)
|
|
138
|
+
return null;
|
|
139
|
+
result.push(...cmps);
|
|
140
|
+
}
|
|
141
|
+
return result;
|
|
142
|
+
}
|
|
143
|
+
export function semverSatisfies(version, range) {
|
|
144
|
+
if (typeof version !== "string" || typeof range !== "string")
|
|
145
|
+
return false;
|
|
146
|
+
const v = parseStrict(version);
|
|
147
|
+
if (!v)
|
|
148
|
+
return false;
|
|
149
|
+
const trimmed = range.trim();
|
|
150
|
+
if (trimmed.length === 0)
|
|
151
|
+
return false;
|
|
152
|
+
const ors = trimmed.split("||").map(s => s.trim());
|
|
153
|
+
for (const part of ors) {
|
|
154
|
+
const cmps = expandRangePart(part);
|
|
155
|
+
if (!cmps)
|
|
156
|
+
continue;
|
|
157
|
+
if (cmps.every(c => satisfiesComp(v, c)))
|
|
158
|
+
return true;
|
|
159
|
+
}
|
|
160
|
+
return false;
|
|
161
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const COMPILER_VERSION = "0.2.0";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@harmoniclabs/pebble",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
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",
|
|
@@ -17,9 +17,10 @@
|
|
|
17
17
|
"prepublishOnly": "npm run ci",
|
|
18
18
|
"buidl": "npm run build",
|
|
19
19
|
"build": "rm -rf ./dist && npm run build:light",
|
|
20
|
-
"build:light": "npm run genDiagnosticMessages && tsc --project ./tsconfig.json && tsc-alias -p ./tsconfig.json",
|
|
20
|
+
"build:light": "npm run genDiagnosticMessages && npm run --silent genVersion && tsc --project ./tsconfig.json && tsc-alias -p ./tsconfig.json",
|
|
21
21
|
"build-and-replace": "npm run build && cp -r ./dist ../pebble-cli/node_modules/@harmoniclabs/pebble",
|
|
22
22
|
"genDiagnosticMessages": "node ./scripts/genDiagnosticMessages.js",
|
|
23
|
+
"genVersion": "node ./scripts/genVersion.js",
|
|
23
24
|
"test": "jest",
|
|
24
25
|
"test-dbg": "node --nolazy --inspect-brk ./node_modules/jest/bin/jest.js --runInBand --colors --verbose",
|
|
25
26
|
"test:debug": "node --nolazy --inspect-brk ./node_modules/jest/bin/jest.js --runInBand --colors --verbose",
|