@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
@@ -11,7 +11,7 @@ import { TirDataStructType, TirSoPStructType } from "../../compiler/tir/types/Ti
11
11
  import { getListTypeArg } from "../../compiler/tir/types/utils/getListTypeArg.js";
12
12
  import { TirTypeParam } from "../../compiler/tir/types/TirTypeParam.js";
13
13
  import { constT, isPair, UPLCConst } from "@harmoniclabs/uplc";
14
- import { TirPairDataT, TirUnConstrDataResultT } from "../../compiler/tir/types/TirNativeType/index.js";
14
+ import { TirBlsG1T, TirBlsG2T, TirMlResultT, TirPairDataT, TirUnConstrDataResultT } from "../../compiler/tir/types/TirNativeType/index.js";
15
15
  import { TirBoolT } from "../../compiler/tir/types/TirNativeType/native/bool.js";
16
16
  import { TirBytesT } from "../../compiler/tir/types/TirNativeType/native/bytes.js";
17
17
  import { TirDataT } from "../../compiler/tir/types/TirNativeType/native/data.js";
@@ -169,6 +169,11 @@ function isValueAssignableToType(value, type) {
169
169
  }
170
170
  if (type instanceof TirLinearMapEntryT)
171
171
  return isIRConstPair(value);
172
+ // BLS / ML-result values can't appear as constants in user Pebble code
173
+ if (type instanceof TirBlsG1T
174
+ || type instanceof TirBlsG2T
175
+ || type instanceof TirMlResultT)
176
+ return false;
172
177
  const tsEnsureExsaustiveCheck = type;
173
178
  return false;
174
179
  }
@@ -221,7 +226,10 @@ function serializeIRConstValue(value, type) {
221
226
  || type instanceof TirSopOptT
222
227
  || type instanceof TirLinearMapEntryT
223
228
  || type instanceof TirSoPStructType
224
- || type instanceof TirTypeParam)
229
+ || type instanceof TirTypeParam
230
+ || type instanceof TirBlsG1T
231
+ || type instanceof TirBlsG2T
232
+ || type instanceof TirMlResultT)
225
233
  throw new Error("invalid uplc const type");
226
234
  const tsEnsureExsaustiveCheck = type;
227
235
  throw new Error("unreachable");
@@ -280,7 +288,10 @@ export function tirTypeToUplcType(t) {
280
288
  || t instanceof TirFuncT
281
289
  || t instanceof TirSopOptT
282
290
  || t instanceof TirSoPStructType
283
- || t instanceof TirTypeParam)
291
+ || t instanceof TirTypeParam
292
+ || t instanceof TirBlsG1T
293
+ || t instanceof TirBlsG2T
294
+ || t instanceof TirMlResultT)
284
295
  throw new Error("invalid uplc const type");
285
296
  const tsEnsureExsaustiveCheck = t;
286
297
  throw new Error("tirTypeToUplcType: unreachable");
@@ -8,7 +8,7 @@ import { getUnaliased } from "../../../compiler/tir/types/utils/getUnaliased.js"
8
8
  import { TirDataStructType } from "../../../compiler/tir/types/TirStructType.js";
9
9
  import { TirAliasType } from "../../../compiler/tir/types/TirAliasType.js";
10
10
  import { getListTypeArg } from "../../../compiler/tir/types/utils/getListTypeArg.js";
11
- import { TirPairDataT, TirUnConstrDataResultT } from "../../../compiler/tir/types/TirNativeType/index.js";
11
+ import { TirBlsG1T, TirBlsG2T, TirMlResultT, TirPairDataT, TirUnConstrDataResultT } from "../../../compiler/tir/types/TirNativeType/index.js";
12
12
  import { TirBoolT } from "../../../compiler/tir/types/TirNativeType/native/bool.js";
13
13
  import { TirBytesT } from "../../../compiler/tir/types/TirNativeType/native/bytes.js";
14
14
  import { TirDataT } from "../../../compiler/tir/types/TirNativeType/native/data.js";
@@ -249,6 +249,10 @@ export class IRNative {
249
249
  return getEqUnConstr();
250
250
  if (type instanceof TirVoidT)
251
251
  return getEqVoid();
252
+ if (type instanceof TirBlsG1T
253
+ || type instanceof TirBlsG2T
254
+ || type instanceof TirMlResultT)
255
+ throw new Error("invalid type for std equality");
252
256
  const tsEnsureExsaustiveCheck = type;
253
257
  throw new Error("invalid type for std equality");
254
258
  }
@@ -1,4 +1,6 @@
1
1
  import { UPLCVersion } from "@harmoniclabs/uplc";
2
+ import { COMPILER_VERSION } from "../../version.generated.js";
3
+ export { COMPILER_VERSION };
2
4
  export interface CompilerUplcOptimizations {
3
5
  /**
4
6
  *
@@ -21,6 +23,13 @@ export declare const defaultUplcOptimizations: CompilerUplcOptimizations;
21
23
  export declare function isDebugUplcOptimizations(options?: Partial<CompilerUplcOptimizations>): boolean;
22
24
  export declare function completeUplcOptimizations(options: Partial<CompilerUplcOptimizations>, complete?: CompilerUplcOptimizations): CompilerUplcOptimizations;
23
25
  export interface CompilerOptions {
26
+ /**
27
+ * npm-style semver range that the running compiler version must satisfy.
28
+ * Required since `@harmoniclabs/pebble@0.2.0` — the `Compiler` throws
29
+ * when this field is missing or when the running compiler version does
30
+ * not satisfy the range.
31
+ */
32
+ compilerVersion: string;
24
33
  /**
25
34
  * path to the entry file
26
35
  */
@@ -76,10 +85,16 @@ export interface CompilerOptions {
76
85
  **/
77
86
  addMarker: boolean;
78
87
  }
79
- export declare const extremeOptions: CompilerOptions;
80
- export declare const productionOptions: CompilerOptions;
81
- export declare const debugOptions: CompilerOptions;
82
- export declare const defaultOptions: CompilerOptions;
83
- export declare const testOptions: CompilerOptions;
84
- export declare const defulatCompilerOptions: CompilerOptions;
85
- export declare function completeCompilerOptions(options: Partial<CompilerOptions>, complete?: CompilerOptions): CompilerOptions;
88
+ /**
89
+ * Option templates intentionally omit `compilerVersion` — every caller must
90
+ * set it explicitly so a missing `compilerVersion` always surfaces as an
91
+ * error from the `Compiler` constructor.
92
+ */
93
+ export type CompilerDefaults = Omit<CompilerOptions, "compilerVersion">;
94
+ export declare const extremeOptions: CompilerDefaults;
95
+ export declare const productionOptions: CompilerDefaults;
96
+ export declare const debugOptions: CompilerDefaults;
97
+ export declare const defaultOptions: CompilerDefaults;
98
+ export declare const testOptions: CompilerDefaults;
99
+ export declare const defulatCompilerOptions: CompilerDefaults;
100
+ export declare function completeCompilerOptions(options: Partial<CompilerOptions>, complete?: Partial<CompilerOptions>): CompilerOptions;
@@ -1,5 +1,7 @@
1
1
  import { isObject } from "@harmoniclabs/obj-utils";
2
2
  import { defaultUplcVersion, UPLCVersion } from "@harmoniclabs/uplc";
3
+ import { COMPILER_VERSION } from "../../version.generated.js";
4
+ export { COMPILER_VERSION };
3
5
  export const productionUplcOptimizations = Object.freeze({
4
6
  groupApplications: true,
5
7
  inlineSingleUse: true,
@@ -99,7 +101,9 @@ export function completeCompilerOptions(options, complete = defaultOptions) {
99
101
  // console.log( "completeUplcOptimizations( uplcOptimizations )",completeUplcOptimizations( uplcOptimizations ))
100
102
  return {
101
103
  ...complete,
102
- targetUplcVersion,
104
+ // forward compilerVersion verbatim — no fallback; Compiler throws if missing/invalid
105
+ compilerVersion: options.compilerVersion ?? complete.compilerVersion,
106
+ targetUplcVersion: targetUplcVersion,
103
107
  removeTraces: options.removeTraces ?? complete.removeTraces,
104
108
  delayHoists: options.delayHoists ?? complete.delayHoists,
105
109
  uplcOptimizations: completeUplcOptimizations(uplcOptimizations),
@@ -0,0 +1,8 @@
1
+ import { IRHoisted } from "../IRNodes/IRHoisted.js";
2
+ /**
3
+ * Hoisted IR term: `bytes -> bytes`
4
+ *
5
+ * Converts a bytestring to its lowercase hex (`0-9a-f`) UTF-8 encoding.
6
+ * 1-byte input becomes 2 bytes; 32-byte input (e.g. a hash) becomes 64 bytes.
7
+ */
8
+ export declare const hoisted_bytesToHex: IRHoisted;
@@ -0,0 +1,69 @@
1
+ import { _ir_apps } from "../IRNodes/IRApp.js";
2
+ import { IRConst } from "../IRNodes/IRConst.js";
3
+ import { IRFunc } from "../IRNodes/IRFunc.js";
4
+ import { IRHoisted } from "../IRNodes/IRHoisted.js";
5
+ import { IRNative } from "../IRNodes/IRNative/index.js";
6
+ import { IRRecursive } from "../IRNodes/IRRecursive.js";
7
+ import { IRSelfCall } from "../IRNodes/IRSelfCall.js";
8
+ import { IRVar } from "../IRNodes/IRVar.js";
9
+ import { _ir_lazyIfThenElse } from "./_ir_lazyIfThenElse.js";
10
+ // hexChar(n) = if n < 10 then n + 48 else n + 87 // '0' = 48, 'a' = 97 = 87+10
11
+ // goAt(bs, len, i) = if i >= len then ""
12
+ // else cons(hexChar(b/16), cons(hexChar(b%16), goAt(bs, len, i+1)))
13
+ // where b = indexByteString(bs, i)
14
+ // bytesToHex(bs) = goAt(bs, lengthOfByteString(bs), 0)
15
+ const emptyBs = IRConst.bytes(new Uint8Array(0));
16
+ const hexCharSym = Symbol("hexChar_n");
17
+ const hoisted_hexChar = new IRHoisted(new IRFunc([hexCharSym], _ir_lazyIfThenElse(
18
+ // n < 10
19
+ _ir_apps(IRNative.lessThanInteger, new IRVar(hexCharSym), IRConst.int(10)),
20
+ // then n + 48
21
+ _ir_apps(IRNative.addInteger, new IRVar(hexCharSym), IRConst.int(48)),
22
+ // else n + 87
23
+ _ir_apps(IRNative.addInteger, new IRVar(hexCharSym), IRConst.int(87)))));
24
+ hoisted_hexChar.hash;
25
+ // Iteration over the bytes of `bs` from offset 0 to len (passed in as args).
26
+ // We avoid re-computing length on each step.
27
+ //
28
+ // self(bs, len, i) =
29
+ // if i >= len then ""
30
+ // else
31
+ // let b = indexByteString(bs, i)
32
+ // cons( hexChar( quotient(b, 16) ),
33
+ // cons( hexChar( mod(b, 16) ),
34
+ // self(bs, len, i + 1)))
35
+ const self_sym = Symbol("bytesToHex_self");
36
+ const bs_sym = Symbol("bytesToHex_bs");
37
+ const len_sym = Symbol("bytesToHex_len");
38
+ const i_sym = Symbol("bytesToHex_i");
39
+ const b_sym = Symbol("bytesToHex_b");
40
+ const hoisted_bytesToHex_loop = new IRHoisted(new IRRecursive(self_sym, new IRFunc([bs_sym, len_sym, i_sym], _ir_lazyIfThenElse(
41
+ // i >= len <=> NOT (i < len)
42
+ _ir_apps(IRNative.lessThanInteger, new IRVar(i_sym), new IRVar(len_sym)),
43
+ // then: process byte at i and recurse
44
+ (() => {
45
+ // let b = indexByteString(bs, i)
46
+ const b = _ir_apps(IRNative.indexByteString, new IRVar(bs_sym), new IRVar(i_sym));
47
+ // The IR currently doesn't have a direct `let` form here; we
48
+ // emit b twice. The optimiser hoists common sub-expressions
49
+ // when they're cheap; for the byte-at-index access this is
50
+ // acceptable (two cheap builtin calls each iteration).
51
+ const high = _ir_apps(hoisted_hexChar.clone(), _ir_apps(IRNative.quotientInteger, b, IRConst.int(16)));
52
+ const lowB = _ir_apps(IRNative.indexByteString, new IRVar(bs_sym), new IRVar(i_sym));
53
+ const low = _ir_apps(hoisted_hexChar.clone(), _ir_apps(IRNative.modInteger, lowB, IRConst.int(16)));
54
+ return _ir_apps(IRNative.consByteString, high, _ir_apps(IRNative.consByteString, low,
55
+ // self(bs, len, i + 1)
56
+ _ir_apps(new IRSelfCall(self_sym), new IRVar(bs_sym), new IRVar(len_sym), _ir_apps(IRNative.addInteger, new IRVar(i_sym), IRConst.int(1)))));
57
+ })(),
58
+ // else: empty bytes
59
+ emptyBs.clone()))));
60
+ hoisted_bytesToHex_loop.hash;
61
+ const outer_bs_sym = Symbol("bytesToHex_outer_bs");
62
+ /**
63
+ * Hoisted IR term: `bytes -> bytes`
64
+ *
65
+ * Converts a bytestring to its lowercase hex (`0-9a-f`) UTF-8 encoding.
66
+ * 1-byte input becomes 2 bytes; 32-byte input (e.g. a hash) becomes 64 bytes.
67
+ */
68
+ export const hoisted_bytesToHex = new IRHoisted(new IRFunc([outer_bs_sym], _ir_apps(hoisted_bytesToHex_loop.clone(), new IRVar(outer_bs_sym), _ir_apps(IRNative.lengthOfByteString, new IRVar(outer_bs_sym)), IRConst.int(0))));
69
+ hoisted_bytesToHex.hash;
@@ -3,20 +3,34 @@ import { SourceRange } from "../../../Source/SourceRange.js";
3
3
  import { Identifier } from "../../common/Identifier.js";
4
4
  import { HasSourceRange } from "../../HasSourceRange.js";
5
5
  import { BlockStmt } from "../../statements/BlockStmt.js";
6
+ import { AstTypeExpr } from "../../types/AstTypeExpr.js";
6
7
  import { AstFuncType } from "../../types/AstNativeTypeExpr.js";
7
8
  import { PebbleExpr } from "../PebbleExpr.js";
8
9
  import { ArrowKind } from "./ArrowKind.js";
10
+ /**
11
+ * A declared type parameter on a function declaration. Optionally constrained
12
+ * to an interface via `<T implements I>` syntax — when set, every concrete
13
+ * instantiation of the generic function must provide a type that implements
14
+ * `I`, and the compiler threads an implicit `I`-dictionary argument through
15
+ * the function body (see `monomorphizeGeneric`).
16
+ */
17
+ export declare class TypeParamDecl implements HasSourceRange {
18
+ readonly name: Identifier;
19
+ readonly constraint: AstTypeExpr | undefined;
20
+ readonly range: SourceRange;
21
+ constructor(name: Identifier, constraint: AstTypeExpr | undefined, range: SourceRange);
22
+ }
9
23
  /**
10
24
  * a litteral function value
11
25
  **/
12
26
  export declare class FuncExpr implements HasSourceRange {
13
27
  readonly name: Identifier;
14
28
  readonly flags: CommonFlags;
15
- readonly typeParams: Identifier[];
29
+ readonly typeParams: TypeParamDecl[];
16
30
  readonly signature: AstFuncType;
17
31
  body: BlockStmt | PebbleExpr;
18
32
  readonly arrowKind: ArrowKind;
19
33
  readonly range: SourceRange;
20
- constructor(name: Identifier, flags: CommonFlags, typeParams: Identifier[], signature: AstFuncType, body: BlockStmt | PebbleExpr, arrowKind: ArrowKind, range: SourceRange);
34
+ constructor(name: Identifier, flags: CommonFlags, typeParams: TypeParamDecl[], signature: AstFuncType, body: BlockStmt | PebbleExpr, arrowKind: ArrowKind, range: SourceRange);
21
35
  bodyBlockStmt(): BlockStmt;
22
36
  }
@@ -1,5 +1,22 @@
1
1
  import { BlockStmt } from "../../statements/BlockStmt.js";
2
2
  import { ReturnStmt } from "../../statements/ReturnStmt.js";
3
+ /**
4
+ * A declared type parameter on a function declaration. Optionally constrained
5
+ * to an interface via `<T implements I>` syntax — when set, every concrete
6
+ * instantiation of the generic function must provide a type that implements
7
+ * `I`, and the compiler threads an implicit `I`-dictionary argument through
8
+ * the function body (see `monomorphizeGeneric`).
9
+ */
10
+ export class TypeParamDecl {
11
+ name;
12
+ constraint;
13
+ range;
14
+ constructor(name, constraint, range) {
15
+ this.name = name;
16
+ this.constraint = constraint;
17
+ this.range = range;
18
+ }
19
+ }
3
20
  /**
4
21
  * a litteral function value
5
22
  **/
@@ -11,5 +11,6 @@ import { LitThisExpr } from "./LitThisExpr.js";
11
11
  import { LitTrueExpr } from "./LitTrueExpr.js";
12
12
  import { LitUndefExpr } from "./LitUndefExpr.js";
13
13
  import { LitVoidExpr } from "./LitVoidExpr.js";
14
- export type LitteralExpr = LitVoidExpr | LitUndefExpr | LitTrueExpr | LitFalseExpr | LitThisExpr | LitContextExpr | LitArrExpr | LitObjExpr | LitNamedObjExpr | LitStrExpr | LitIntExpr | LitHexBytesExpr | LitFailExpr;
14
+ import { TemplateStrExpr } from "./TemplateStrExpr.js";
15
+ export type LitteralExpr = LitVoidExpr | LitUndefExpr | LitTrueExpr | LitFalseExpr | LitThisExpr | LitContextExpr | LitArrExpr | LitObjExpr | LitNamedObjExpr | LitStrExpr | TemplateStrExpr | LitIntExpr | LitHexBytesExpr | LitFailExpr;
15
16
  export declare function isLitteralExpr(thing: any): thing is LitteralExpr;
@@ -11,6 +11,7 @@ import { LitThisExpr } from "./LitThisExpr.js";
11
11
  import { LitTrueExpr } from "./LitTrueExpr.js";
12
12
  import { LitUndefExpr } from "./LitUndefExpr.js";
13
13
  import { LitVoidExpr } from "./LitVoidExpr.js";
14
+ import { TemplateStrExpr } from "./TemplateStrExpr.js";
14
15
  export function isLitteralExpr(thing) {
15
16
  return (thing instanceof LitVoidExpr
16
17
  || thing instanceof LitUndefExpr
@@ -22,6 +23,7 @@ export function isLitteralExpr(thing) {
22
23
  || thing instanceof LitObjExpr
23
24
  || thing instanceof LitNamedObjExpr
24
25
  || thing instanceof LitStrExpr
26
+ || thing instanceof TemplateStrExpr
25
27
  || thing instanceof LitIntExpr
26
28
  || thing instanceof LitHexBytesExpr
27
29
  || thing instanceof LitFailExpr);
@@ -0,0 +1,30 @@
1
+ import { SourceRange } from "../../../Source/SourceRange.js";
2
+ import { HasSourceRange } from "../../HasSourceRange.js";
3
+ import { PebbleExpr } from "../PebbleExpr.js";
4
+ /**
5
+ * A template string literal: backtick-delimited text with `${expr}`
6
+ * interpolation slots — e.g. `` `hello ${name}, count is ${n}` ``.
7
+ *
8
+ * Stored as alternating literal text fragments and interpolated expressions.
9
+ * For a template with N interpolations, `parts.length === N + 1`.
10
+ *
11
+ * Compilation produces a chain of UTF-8 byte concatenations:
12
+ *
13
+ * parts[0]_bytes
14
+ * ++ show-or-passthrough( exprs[0] )
15
+ * ++ parts[1]_bytes
16
+ * ++ show-or-passthrough( exprs[1] )
17
+ * ++ ...
18
+ * ++ parts[N]_bytes
19
+ *
20
+ * For each interpolated expression: if its type is `bytes` it is passed
21
+ * through verbatim (assumed to already be valid UTF-8 — same convention as
22
+ * `trace`); otherwise the compiler implicitly inserts `.show()` via the
23
+ * built-in Show interface dispatch.
24
+ */
25
+ export declare class TemplateStrExpr implements HasSourceRange {
26
+ readonly parts: string[];
27
+ readonly exprs: PebbleExpr[];
28
+ readonly range: SourceRange;
29
+ constructor(parts: string[], exprs: PebbleExpr[], range: SourceRange);
30
+ }
@@ -0,0 +1,35 @@
1
+ /**
2
+ * A template string literal: backtick-delimited text with `${expr}`
3
+ * interpolation slots — e.g. `` `hello ${name}, count is ${n}` ``.
4
+ *
5
+ * Stored as alternating literal text fragments and interpolated expressions.
6
+ * For a template with N interpolations, `parts.length === N + 1`.
7
+ *
8
+ * Compilation produces a chain of UTF-8 byte concatenations:
9
+ *
10
+ * parts[0]_bytes
11
+ * ++ show-or-passthrough( exprs[0] )
12
+ * ++ parts[1]_bytes
13
+ * ++ show-or-passthrough( exprs[1] )
14
+ * ++ ...
15
+ * ++ parts[N]_bytes
16
+ *
17
+ * For each interpolated expression: if its type is `bytes` it is passed
18
+ * through verbatim (assumed to already be valid UTF-8 — same convention as
19
+ * `trace`); otherwise the compiler implicitly inserts `.show()` via the
20
+ * built-in Show interface dispatch.
21
+ */
22
+ export class TemplateStrExpr {
23
+ parts;
24
+ exprs;
25
+ range;
26
+ constructor(parts, exprs, range) {
27
+ this.parts = parts;
28
+ this.exprs = exprs;
29
+ this.range = range;
30
+ if (parts.length !== exprs.length + 1) {
31
+ throw new Error(`TemplateStrExpr: parts.length (${parts.length}) must equal ` +
32
+ `exprs.length + 1 (${exprs.length + 1})`);
33
+ }
34
+ }
35
+ }
@@ -1,13 +1,13 @@
1
1
  import { SourceRange } from "../../Source/SourceRange.js";
2
2
  import { HasSourceRange } from "../HasSourceRange.js";
3
- import { BodyStmt } from "./PebbleStmt.js";
3
+ import { BodyStmt, TopLevelStmt } from "./PebbleStmt.js";
4
4
  /**
5
5
  * ```ts
6
6
  * export <PebbleStmt>
7
7
  * ```
8
8
  */
9
9
  export declare class ExportStmt implements HasSourceRange {
10
- readonly stmt: BodyStmt;
10
+ readonly stmt: BodyStmt | TopLevelStmt;
11
11
  readonly range: SourceRange;
12
- constructor(stmt: BodyStmt, range: SourceRange);
12
+ constructor(stmt: BodyStmt | TopLevelStmt, range: SourceRange);
13
13
  }
@@ -19,13 +19,14 @@ import { TestStmt } from "./TestStmt.js";
19
19
  import { VarStmt } from "./VarStmt.js";
20
20
  import { WhileStmt } from "./WhileStmt.js";
21
21
  import { AssignmentStmt } from "./AssignmentStmt.js";
22
- import { UsingStmt } from "./UsingStmt.js";
22
+ import { UsingAliasStmt, UsingStmt } from "./UsingStmt.js";
23
23
  import { FuncDecl } from "./declarations/FuncDecl.js";
24
24
  import { ExportStmt } from "./ExportStmt.js";
25
25
  import { InterfaceDecl } from "./declarations/InterfaceDecl.js";
26
26
  import { ContractDecl } from "./declarations/ContractDecl.js";
27
+ import { NamespaceDecl } from "./declarations/NamespaceDecl.js";
27
28
  import { TraceStmt } from "./TraceStmt.js";
28
- export type TopLevelStmt = EmptyStmt | VarStmt | PebbleTypeDecl | InterfaceDecl | FuncDecl | TestStmt | ExportStmt | ExportStarStmt | ExportImportStmt | ImportStmt | ImportStarStmt | TypeImplementsStmt | UsingStmt | ContractDecl;
29
+ export type TopLevelStmt = EmptyStmt | VarStmt | PebbleTypeDecl | InterfaceDecl | FuncDecl | TestStmt | ExportStmt | ExportStarStmt | ExportImportStmt | ImportStmt | ImportStarStmt | TypeImplementsStmt | UsingStmt | UsingAliasStmt | NamespaceDecl | ContractDecl;
29
30
  export declare function isTopLevelStmt(stmt: any): stmt is TopLevelStmt;
30
- export type BodyStmt = IfStmt | VarStmt | ForStmt | ForOfStmt | WhileStmt | ReturnStmt | BlockStmt | BreakStmt | ContinueStmt | EmptyStmt | FailStmt | AssertStmt | TraceStmt | MatchStmt | AssignmentStmt | UsingStmt;
31
+ export type BodyStmt = IfStmt | VarStmt | ForStmt | ForOfStmt | WhileStmt | ReturnStmt | BlockStmt | BreakStmt | ContinueStmt | EmptyStmt | FailStmt | AssertStmt | TraceStmt | MatchStmt | AssignmentStmt | UsingStmt | UsingAliasStmt;
31
32
  export declare function isBodyStmt(stmt: any): stmt is BodyStmt;
@@ -22,10 +22,11 @@ import { WhileStmt } from "./WhileStmt.js";
22
22
  import { isAssignmentStmt } from "./AssignmentStmt.js";
23
23
  import { IncrStmt } from "./IncrStmt.js";
24
24
  import { DecrStmt } from "./DecrStmt.js";
25
- import { UsingStmt } from "./UsingStmt.js";
25
+ import { UsingAliasStmt, UsingStmt } from "./UsingStmt.js";
26
26
  import { FuncDecl } from "./declarations/FuncDecl.js";
27
27
  import { ExportStmt } from "./ExportStmt.js";
28
28
  import { ContractDecl } from "./declarations/ContractDecl.js";
29
+ import { NamespaceDecl } from "./declarations/NamespaceDecl.js";
29
30
  import { TraceStmt } from "./TraceStmt.js";
30
31
  export function isTopLevelStmt(stmt) {
31
32
  return (stmt instanceof EmptyStmt
@@ -40,6 +41,8 @@ export function isTopLevelStmt(stmt) {
40
41
  || stmt instanceof ImportStarStmt
41
42
  || stmt instanceof TypeImplementsStmt
42
43
  || stmt instanceof UsingStmt
44
+ || stmt instanceof UsingAliasStmt
45
+ || stmt instanceof NamespaceDecl
43
46
  || stmt instanceof ContractDecl);
44
47
  }
45
48
  export function isBodyStmt(stmt) {
@@ -62,5 +65,6 @@ export function isBodyStmt(stmt) {
62
65
  // || stmt instanceof ExprStmt
63
66
  || stmt instanceof IncrStmt
64
67
  || stmt instanceof DecrStmt
65
- || stmt instanceof UsingStmt);
68
+ || stmt instanceof UsingStmt
69
+ || stmt instanceof UsingAliasStmt);
66
70
  }
@@ -0,0 +1,18 @@
1
+ import { SourceRange } from "../../Source/SourceRange.js";
2
+ import { Identifier } from "../common/Identifier.js";
3
+ import { PebbleExpr } from "../expr/PebbleExpr.js";
4
+ import { AstTypeExpr } from "../types/AstTypeExpr.js";
5
+ import { HasSourceRange } from "../HasSourceRange.js";
6
+ /**
7
+ * A parameter of a `test` declaration: `<name>: <type> ( via <expr> )?`.
8
+ *
9
+ * This is intentionally a separate node from `SimpleVarDecl` / `VarDecl` so the
10
+ * `via` keyword cannot leak into function/method/contract parameter grammar.
11
+ */
12
+ export declare class TestParam implements HasSourceRange {
13
+ readonly name: Identifier;
14
+ readonly type: AstTypeExpr;
15
+ readonly viaExpr: PebbleExpr | undefined;
16
+ readonly range: SourceRange;
17
+ constructor(name: Identifier, type: AstTypeExpr, viaExpr: PebbleExpr | undefined, range: SourceRange);
18
+ }
@@ -0,0 +1,18 @@
1
+ /**
2
+ * A parameter of a `test` declaration: `<name>: <type> ( via <expr> )?`.
3
+ *
4
+ * This is intentionally a separate node from `SimpleVarDecl` / `VarDecl` so the
5
+ * `via` keyword cannot leak into function/method/contract parameter grammar.
6
+ */
7
+ export class TestParam {
8
+ name;
9
+ type;
10
+ viaExpr;
11
+ range;
12
+ constructor(name, type, viaExpr, range) {
13
+ this.name = name;
14
+ this.type = type;
15
+ this.viaExpr = viaExpr;
16
+ this.range = range;
17
+ }
18
+ }
@@ -1,10 +1,12 @@
1
1
  import { SourceRange } from "../../Source/SourceRange.js";
2
- import { LitStrExpr } from "../expr/litteral/LitStrExpr.js";
2
+ import { Identifier } from "../common/Identifier.js";
3
3
  import { HasSourceRange } from "../HasSourceRange.js";
4
4
  import { BlockStmt } from "./BlockStmt.js";
5
+ import { TestParam } from "./TestParam.js";
5
6
  export declare class TestStmt implements HasSourceRange {
6
- readonly testName: LitStrExpr | undefined;
7
+ readonly testName: Identifier;
8
+ readonly params: TestParam[];
7
9
  readonly body: BlockStmt;
8
10
  readonly range: SourceRange;
9
- constructor(testName: LitStrExpr | undefined, body: BlockStmt, range: SourceRange);
11
+ constructor(testName: Identifier, params: TestParam[], body: BlockStmt, range: SourceRange);
10
12
  }
@@ -1,9 +1,11 @@
1
1
  export class TestStmt {
2
2
  testName;
3
+ params;
3
4
  body;
4
5
  range;
5
- constructor(testName, body, range) {
6
+ constructor(testName, params, body, range) {
6
7
  this.testName = testName;
8
+ this.params = params;
7
9
  this.body = body;
8
10
  this.range = range;
9
11
  }
@@ -2,11 +2,30 @@ import { SourceRange } from "../../Source/SourceRange.js";
2
2
  import { Identifier } from "../common/Identifier.js";
3
3
  import { HasSourceRange } from "../HasSourceRange.js";
4
4
  import { AstTypeExpr } from "../types/AstTypeExpr.js";
5
+ /**
6
+ * dotted chain of identifiers used as the RHS of a `using` statement
7
+ * to refer to a namespace path (e.g. `std.builtins`).
8
+ */
9
+ export declare class UsingPath implements HasSourceRange {
10
+ readonly segments: Identifier[];
11
+ readonly range: SourceRange;
12
+ constructor(segments: Identifier[], range: SourceRange);
13
+ }
14
+ export type UsingRhs = AstTypeExpr | UsingPath;
15
+ /**
16
+ * `using { a, b: renamed } = <rhs>;`
17
+ *
18
+ * `<rhs>` may be either a struct type expression (existing behavior,
19
+ * bringing constructors into scope) or a namespace path (new behavior,
20
+ * destructuring the namespace's exported members into scope).
21
+ */
5
22
  export declare class UsingStmt implements HasSourceRange {
6
23
  readonly constructorNames: UsingStmtDeclaredConstructor[];
7
- readonly structTypeExpr: AstTypeExpr;
24
+ readonly rhs: UsingRhs;
8
25
  readonly range: SourceRange;
9
- constructor(constructorNames: UsingStmtDeclaredConstructor[], structTypeExpr: AstTypeExpr, range: SourceRange);
26
+ constructor(constructorNames: UsingStmtDeclaredConstructor[], rhs: UsingRhs, range: SourceRange);
27
+ /** legacy accessor for code paths still expecting `structTypeExpr` */
28
+ get structTypeExpr(): UsingRhs;
10
29
  }
11
30
  export declare class UsingStmtDeclaredConstructor implements HasSourceRange {
12
31
  readonly constructorName: Identifier;
@@ -14,3 +33,14 @@ export declare class UsingStmtDeclaredConstructor implements HasSourceRange {
14
33
  readonly range: SourceRange;
15
34
  constructor(constructorName: Identifier, renamedConstructorName: Identifier | undefined, range: SourceRange);
16
35
  }
36
+ /**
37
+ * `using <aliasName> = <rhs>;`
38
+ *
39
+ * binds `aliasName` as a local alias for the namespace identified by `rhs`.
40
+ */
41
+ export declare class UsingAliasStmt implements HasSourceRange {
42
+ readonly aliasName: Identifier;
43
+ readonly rhs: UsingPath;
44
+ readonly range: SourceRange;
45
+ constructor(aliasName: Identifier, rhs: UsingPath, range: SourceRange);
46
+ }
@@ -1,12 +1,33 @@
1
+ /**
2
+ * dotted chain of identifiers used as the RHS of a `using` statement
3
+ * to refer to a namespace path (e.g. `std.builtins`).
4
+ */
5
+ export class UsingPath {
6
+ segments;
7
+ range;
8
+ constructor(segments, range) {
9
+ this.segments = segments;
10
+ this.range = range;
11
+ }
12
+ }
13
+ /**
14
+ * `using { a, b: renamed } = <rhs>;`
15
+ *
16
+ * `<rhs>` may be either a struct type expression (existing behavior,
17
+ * bringing constructors into scope) or a namespace path (new behavior,
18
+ * destructuring the namespace's exported members into scope).
19
+ */
1
20
  export class UsingStmt {
2
21
  constructorNames;
3
- structTypeExpr;
22
+ rhs;
4
23
  range;
5
- constructor(constructorNames, structTypeExpr, range) {
24
+ constructor(constructorNames, rhs, range) {
6
25
  this.constructorNames = constructorNames;
7
- this.structTypeExpr = structTypeExpr;
26
+ this.rhs = rhs;
8
27
  this.range = range;
9
28
  }
29
+ /** legacy accessor for code paths still expecting `structTypeExpr` */
30
+ get structTypeExpr() { return this.rhs; }
10
31
  }
11
32
  export class UsingStmtDeclaredConstructor {
12
33
  constructorName;
@@ -18,3 +39,18 @@ export class UsingStmtDeclaredConstructor {
18
39
  this.range = range;
19
40
  }
20
41
  }
42
+ /**
43
+ * `using <aliasName> = <rhs>;`
44
+ *
45
+ * binds `aliasName` as a local alias for the namespace identified by `rhs`.
46
+ */
47
+ export class UsingAliasStmt {
48
+ aliasName;
49
+ rhs;
50
+ range;
51
+ constructor(aliasName, rhs, range) {
52
+ this.aliasName = aliasName;
53
+ this.rhs = rhs;
54
+ this.range = range;
55
+ }
56
+ }
@@ -0,0 +1,21 @@
1
+ import { SourceRange } from "../../../Source/SourceRange.js";
2
+ import { Identifier } from "../../common/Identifier.js";
3
+ import { HasSourceRange } from "../../HasSourceRange.js";
4
+ import { VarStmt } from "../VarStmt.js";
5
+ import { FuncDecl } from "./FuncDecl.js";
6
+ import { InterfaceDecl } from "./InterfaceDecl.js";
7
+ import { PebbleTypeDecl } from "./PebbleTypeDecl.js";
8
+ export type NamespaceMemberStmt = VarStmt | FuncDecl | PebbleTypeDecl | InterfaceDecl | NamespaceDecl;
9
+ export declare function isNamespaceMemberStmt(thing: any): thing is NamespaceMemberStmt;
10
+ export declare class NamespaceMember implements HasSourceRange {
11
+ readonly isPrivate: boolean;
12
+ readonly stmt: NamespaceMemberStmt;
13
+ readonly range: SourceRange;
14
+ constructor(isPrivate: boolean, stmt: NamespaceMemberStmt, range: SourceRange);
15
+ }
16
+ export declare class NamespaceDecl implements HasSourceRange {
17
+ readonly name: Identifier;
18
+ readonly members: NamespaceMember[];
19
+ readonly range: SourceRange;
20
+ constructor(name: Identifier, members: NamespaceMember[], range: SourceRange);
21
+ }