@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.
Files changed (97) hide show
  1. package/dist/IR/IRNodes/IRConst.js +14 -3
  2. package/dist/IR/IRNodes/IRNative/index.js +5 -1
  3. package/dist/IR/toUPLC/CompilerOptions.d.ts +22 -7
  4. package/dist/IR/toUPLC/CompilerOptions.js +5 -1
  5. package/dist/IR/tree_utils/bytesToHex.d.ts +8 -0
  6. package/dist/IR/tree_utils/bytesToHex.js +69 -0
  7. package/dist/ast/nodes/expr/functions/FuncExpr.d.ts +16 -2
  8. package/dist/ast/nodes/expr/functions/FuncExpr.js +17 -0
  9. package/dist/ast/nodes/expr/litteral/LitteralExpr.d.ts +2 -1
  10. package/dist/ast/nodes/expr/litteral/LitteralExpr.js +2 -0
  11. package/dist/ast/nodes/expr/litteral/TemplateStrExpr.d.ts +30 -0
  12. package/dist/ast/nodes/expr/litteral/TemplateStrExpr.js +35 -0
  13. package/dist/ast/nodes/statements/ExportStmt.d.ts +3 -3
  14. package/dist/ast/nodes/statements/PebbleStmt.d.ts +4 -3
  15. package/dist/ast/nodes/statements/PebbleStmt.js +6 -2
  16. package/dist/ast/nodes/statements/TestParam.d.ts +18 -0
  17. package/dist/ast/nodes/statements/TestParam.js +18 -0
  18. package/dist/ast/nodes/statements/TestStmt.d.ts +5 -3
  19. package/dist/ast/nodes/statements/TestStmt.js +3 -1
  20. package/dist/ast/nodes/statements/UsingStmt.d.ts +32 -2
  21. package/dist/ast/nodes/statements/UsingStmt.js +39 -3
  22. package/dist/ast/nodes/statements/declarations/NamespaceDecl.d.ts +21 -0
  23. package/dist/ast/nodes/statements/declarations/NamespaceDecl.js +31 -0
  24. package/dist/compiler/AstCompiler/AstCompiler.d.ts +26 -0
  25. package/dist/compiler/AstCompiler/AstCompiler.js +203 -3
  26. package/dist/compiler/AstCompiler/internal/_deriveContractBody/_deriveContractBody.js +13 -2
  27. package/dist/compiler/AstCompiler/internal/exprs/_compileCallExpr.js +97 -6
  28. package/dist/compiler/AstCompiler/internal/exprs/_compileFuncExpr.js +12 -5
  29. package/dist/compiler/AstCompiler/internal/exprs/_compileLitteralExpr.js +59 -0
  30. package/dist/compiler/AstCompiler/internal/exprs/_compilePropAccessExpr.d.ts +2 -3
  31. package/dist/compiler/AstCompiler/internal/exprs/_compilePropAccessExpr.js +28 -0
  32. package/dist/compiler/AstCompiler/internal/exprs/_compileVarAccessExpr.js +2 -0
  33. package/dist/compiler/AstCompiler/internal/statements/_compileStatement.js +4 -1
  34. package/dist/compiler/AstCompiler/internal/statements/_compileTestStmt.d.ts +15 -1
  35. package/dist/compiler/AstCompiler/internal/statements/_compileTestStmt.js +70 -30
  36. package/dist/compiler/AstCompiler/internal/statements/_compileUsingAliasStmt.d.ts +11 -0
  37. package/dist/compiler/AstCompiler/internal/statements/_compileUsingAliasStmt.js +26 -0
  38. package/dist/compiler/AstCompiler/internal/statements/_compileUsingStmt.d.ts +9 -4
  39. package/dist/compiler/AstCompiler/internal/statements/_compileUsingStmt.js +51 -10
  40. package/dist/compiler/AstCompiler/internal/types/_compileDataEncodedConcreteType.js +21 -2
  41. package/dist/compiler/AstCompiler/internal/types/_compileSopEncodedConcreteType.js +17 -2
  42. package/dist/compiler/AstCompiler/scope/AstScope.d.ts +70 -1
  43. package/dist/compiler/AstCompiler/scope/AstScope.js +91 -0
  44. package/dist/compiler/AstCompiler/utils/getPropAccessReturnType.js +25 -1
  45. package/dist/compiler/AstCompiler/utils/monomorphizeGeneric.d.ts +36 -0
  46. package/dist/compiler/AstCompiler/utils/monomorphizeGeneric.js +123 -0
  47. package/dist/compiler/AstCompiler/utils/resolveNamespaceChain.d.ts +28 -0
  48. package/dist/compiler/AstCompiler/utils/resolveNamespaceChain.js +95 -0
  49. package/dist/compiler/AstCompiler/utils/resolveNamespacePath.d.ts +37 -0
  50. package/dist/compiler/AstCompiler/utils/resolveNamespacePath.js +93 -0
  51. package/dist/compiler/Compiler.d.ts +9 -1
  52. package/dist/compiler/Compiler.js +204 -9
  53. package/dist/compiler/TirCompiler/expressify/expressifyVars.js +26 -7
  54. package/dist/compiler/test/TestResult.d.ts +38 -0
  55. package/dist/compiler/test/TestResult.js +6 -0
  56. package/dist/compiler/test/fuzz/PRNG.d.ts +26 -0
  57. package/dist/compiler/test/fuzz/PRNG.js +59 -0
  58. package/dist/compiler/tir/expressions/TirExpr.d.ts +2 -1
  59. package/dist/compiler/tir/expressions/TirExpr.js +2 -0
  60. package/dist/compiler/tir/expressions/TirNativeFunc.d.ts +17 -0
  61. package/dist/compiler/tir/expressions/TirNativeFunc.js +53 -106
  62. package/dist/compiler/tir/expressions/TirShowExpr.d.ts +52 -0
  63. package/dist/compiler/tir/expressions/TirShowExpr.js +199 -0
  64. package/dist/compiler/tir/expressions/TirTraceExpr.js +11 -7
  65. package/dist/compiler/tir/program/TypedProgram.d.ts +101 -0
  66. package/dist/compiler/tir/program/TypedProgram.js +43 -0
  67. package/dist/compiler/tir/program/stdScope/populateBuiltinInterfaces.d.ts +17 -0
  68. package/dist/compiler/tir/program/stdScope/populateBuiltinInterfaces.js +70 -0
  69. package/dist/compiler/tir/program/stdScope/populateStdNamespace.d.ts +22 -0
  70. package/dist/compiler/tir/program/stdScope/populateStdNamespace.js +574 -0
  71. package/dist/compiler/tir/program/stdScope/stdScope.d.ts +1 -0
  72. package/dist/compiler/tir/program/stdScope/stdScope.js +1 -1
  73. package/dist/compiler/tir/statements/TirStmt.js +0 -1
  74. package/dist/compiler/tir/statements/TirTestStmt.d.ts +46 -0
  75. package/dist/compiler/tir/statements/TirTestStmt.js +35 -0
  76. package/dist/compiler/tir/types/TirNativeType/TirNativeType.d.ts +50 -1
  77. package/dist/compiler/tir/types/TirNativeType/TirNativeType.js +53 -1
  78. package/dist/compiler/tir/types/TirType.js +3 -1
  79. package/dist/compiler/tir/types/utils/canAssignTo.js +8 -1
  80. package/dist/compiler/tir/types/utils/inferTypeArgs.d.ts +19 -0
  81. package/dist/compiler/tir/types/utils/inferTypeArgs.js +79 -0
  82. package/dist/compiler/tir/types/utils/substituteTypeParams.d.ts +9 -0
  83. package/dist/compiler/tir/types/utils/substituteTypeParams.js +62 -0
  84. package/dist/diagnostics/diagnosticMessages.generated.d.ts +5 -0
  85. package/dist/diagnostics/diagnosticMessages.generated.js +10 -0
  86. package/dist/index.d.ts +2 -0
  87. package/dist/index.js +2 -0
  88. package/dist/parser/Parser.d.ts +73 -3
  89. package/dist/parser/Parser.js +333 -33
  90. package/dist/tokenizer/Token.d.ts +105 -102
  91. package/dist/tokenizer/Token.js +110 -109
  92. package/dist/tokenizer/utils/tokenFromKeyword.js +9 -6
  93. package/dist/utils/semverSatisfies.d.ts +1 -0
  94. package/dist/utils/semverSatisfies.js +161 -0
  95. package/dist/version.generated.d.ts +1 -0
  96. package/dist/version.generated.js +2 -0
  97. 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";
@@ -0,0 +1,2 @@
1
+ // This file is auto-generated by scripts/genVersion.js. Do not edit.
2
+ export const COMPILER_VERSION = "0.2.0";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@harmoniclabs/pebble",
3
- "version": "0.1.10",
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",