@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,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;
|