@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,17 @@
1
+ import { TypedProgram } from "../TypedProgram.js";
2
+ /**
3
+ * Register compiler-built interfaces and their built-in implementation
4
+ * factories.
5
+ *
6
+ * - `ToData`: every type that supports a `data` encoding (which is most
7
+ * Pebble types) automatically satisfies it. The factory returns
8
+ * `_toDataUplcFunc(T)` — a closed IR closure `(T) -> data` produced by
9
+ * the same compile-time dispatch that `TirToDataExpr` uses.
10
+ *
11
+ * User types may also implement these interfaces explicitly via
12
+ * `type Foo implements ToData { toData(self): data { ... } }`. When a
13
+ * constraint is resolved at call time, the user-impl path is checked first
14
+ * (via the type's `methodNamesPtr`); only if no user impl exists does the
15
+ * compiler fall back to the built-in factory registered here.
16
+ */
17
+ export declare function populateBuiltinInterfaces(program: TypedProgram): void;
@@ -0,0 +1,70 @@
1
+ import { Identifier } from "../../../../ast/nodes/common/Identifier.js";
2
+ import { SourceRange } from "../../../../ast/Source/SourceRange.js";
3
+ import { AstFuncType } from "../../../../ast/nodes/types/AstNativeTypeExpr.js";
4
+ import { AstNamedTypeExpr } from "../../../../ast/nodes/types/AstNamedTypeExpr.js";
5
+ import { SimpleVarDecl } from "../../../../ast/nodes/statements/declarations/VarDecl/SimpleVarDecl.js";
6
+ import { CommonFlags } from "../../../../common.js";
7
+ // NOTE: `TirToDataExpr` transitively imports `common_hoisted`, which calls
8
+ // `IRConst.data(...)` at module-load time. Loading this at the top would
9
+ // cycle with `TypedProgram` during early compiler bootstrap and trip
10
+ // "Cannot read properties of undefined (reading 'data')" in tests that load
11
+ // the IR layer in isolation. Require it lazily inside the factory instead.
12
+ /**
13
+ * Register compiler-built interfaces and their built-in implementation
14
+ * factories.
15
+ *
16
+ * - `ToData`: every type that supports a `data` encoding (which is most
17
+ * Pebble types) automatically satisfies it. The factory returns
18
+ * `_toDataUplcFunc(T)` — a closed IR closure `(T) -> data` produced by
19
+ * the same compile-time dispatch that `TirToDataExpr` uses.
20
+ *
21
+ * User types may also implement these interfaces explicitly via
22
+ * `type Foo implements ToData { toData(self): data { ... } }`. When a
23
+ * constraint is resolved at call time, the user-impl path is checked first
24
+ * (via the type's `methodNamesPtr`); only if no user impl exists does the
25
+ * compiler fall back to the built-in factory registered here.
26
+ */
27
+ export function populateBuiltinInterfaces(program) {
28
+ const unkRange = SourceRange.unknown;
29
+ // ---- interface ToData { toData(self): data } ----
30
+ const selfParam = new SimpleVarDecl(new Identifier("self", unkRange),
31
+ // self has no annotated type; the implementer's type fills the slot
32
+ undefined, undefined, CommonFlags.None, unkRange);
33
+ const toDataSig = new AstFuncType([selfParam], new AstNamedTypeExpr(new Identifier("data", unkRange), [], unkRange), unkRange);
34
+ const toDataMethods = new Map([
35
+ ["toData", toDataSig],
36
+ ]);
37
+ // Register the interface in the prelude scope so users can write
38
+ // `<T implements ToData>`. The scope walker (`resolveInterface`) finds
39
+ // it via the parent chain.
40
+ program.preludeScope.interfaces.set("ToData", toDataMethods);
41
+ // Built-in impl factory: given a concrete TIR type, return a
42
+ // closed `IRTerm` of type `(T) -> data`. `_toDataUplcFunc` already
43
+ // dispatches compile-time per concrete type — return its hoisted
44
+ // closure directly. Loaded lazily to avoid the bootstrap cycle.
45
+ program.builtinInterfaceImpls.set("ToData", new Map([
46
+ ["toData", (concreteType) => {
47
+ // eslint-disable-next-line @typescript-eslint/no-var-requires
48
+ const { _toDataUplcFunc } = require("../../expressions/TirToDataExpr.js");
49
+ return _toDataUplcFunc(concreteType);
50
+ }],
51
+ ]));
52
+ // ---- interface Show { show(self): bytes } ----
53
+ // Returns a UTF-8 textual representation suitable for human reading
54
+ // and for passing through `trace`. Built-in primitives auto-implement
55
+ // it (int -> decimal, bytes -> lowercase hex, bool -> "true"/"false",
56
+ // data -> serialiseData -> hex, List<T>/LinearMap<K,V> -> recursive,
57
+ // data-encoded structs -> serialiseData -> hex). User types may
58
+ // override with `type X implements Show { show(self): bytes { ... } }`.
59
+ const showSig = new AstFuncType([selfParam], new AstNamedTypeExpr(new Identifier("bytes", unkRange), [], unkRange), unkRange);
60
+ program.preludeScope.interfaces.set("Show", new Map([
61
+ ["show", showSig],
62
+ ]));
63
+ program.builtinInterfaceImpls.set("Show", new Map([
64
+ ["show", (concreteType) => {
65
+ // eslint-disable-next-line @typescript-eslint/no-var-requires
66
+ const { _showUplcFunc } = require("../../expressions/TirShowExpr.js");
67
+ return _showUplcFunc(concreteType);
68
+ }],
69
+ ]));
70
+ }
@@ -0,0 +1,22 @@
1
+ import { TypedProgram } from "../TypedProgram.js";
2
+ /**
3
+ * Populate the top-level `std` namespace and its sub-namespaces:
4
+ *
5
+ * std
6
+ * ├── crypto
7
+ * │ ├── hashing & signatures (sha2_256, blake2b_256, verifyEd25519Signature, ...)
8
+ * │ └── bls12_381
9
+ * │ ├── types: G1, G2, MlResult
10
+ * │ └── g1Add, g1Neg, g2Add, ..., millerLoop, finalVerify
11
+ * └── builtins
12
+ * ├── types: RawConstr
13
+ * ├── arithmetic, byte-string, bitwise, data, string, trace, conversion ops
14
+ * └── (polymorphic intrinsics like mkCons<T> are registered as native
15
+ * generic templates and dispatched through the same monomorphizer
16
+ * as user generic functions — see `populateNativeGenericTemplates`)
17
+ *
18
+ * Identifiers like `std.crypto.sha2_256(b)` resolve through the existing
19
+ * namespace-chain walker; the function is registered on the program as a
20
+ * `TirInlineClosedIR` whose IR is the corresponding `IRNative` tag.
21
+ */
22
+ export declare function populateStdNamespace(program: TypedProgram): void;