@harmoniclabs/pebble 0.1.10 → 0.3.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 (182) hide show
  1. package/dist/IR/CompilationCtx.d.ts +40 -0
  2. package/dist/IR/CompilationCtx.js +54 -0
  3. package/dist/IR/IRHash.d.ts +23 -2
  4. package/dist/IR/IRHash.js +10 -60
  5. package/dist/IR/IRNodes/IRConst.js +35 -4
  6. package/dist/IR/IRNodes/IRHoisted.d.ts +0 -1
  7. package/dist/IR/IRNodes/IRHoisted.js +4 -6
  8. package/dist/IR/IRNodes/IRLetted.d.ts +0 -1
  9. package/dist/IR/IRNodes/IRLetted.js +4 -6
  10. package/dist/IR/IRNodes/IRNative/IRNativeTag.d.ts +22 -2
  11. package/dist/IR/IRNodes/IRNative/IRNativeTag.js +26 -2
  12. package/dist/IR/IRNodes/IRNative/index.d.ts +16 -1
  13. package/dist/IR/IRNodes/IRNative/index.js +31 -2
  14. package/dist/IR/IRNodes/utils/hashVarSym.d.ts +0 -1
  15. package/dist/IR/IRNodes/utils/hashVarSym.js +27 -33
  16. package/dist/IR/toUPLC/CompilerOptions.d.ts +34 -7
  17. package/dist/IR/toUPLC/CompilerOptions.js +19 -10
  18. package/dist/IR/toUPLC/compileIRToUPLC.js +39 -3
  19. package/dist/IR/toUPLC/subRoutines/inlineSingleUseLetBindingsAndReturnRoot.d.ts +23 -0
  20. package/dist/IR/toUPLC/subRoutines/inlineSingleUseLetBindingsAndReturnRoot.js +263 -0
  21. package/dist/IR/toUPLC/subRoutines/introduceCaseForDualHeadTailAndReturnRoot.d.ts +35 -0
  22. package/dist/IR/toUPLC/subRoutines/introduceCaseForDualHeadTailAndReturnRoot.js +169 -0
  23. package/dist/IR/toUPLC/subRoutines/replaceHoistedWithLetted.d.ts +0 -1
  24. package/dist/IR/toUPLC/subRoutines/replaceHoistedWithLetted.js +6 -6
  25. package/dist/IR/toUPLC/subRoutines/replaceNatives/nativeToIR.d.ts +2 -3
  26. package/dist/IR/toUPLC/subRoutines/replaceNatives/nativeToIR.js +106 -65
  27. package/dist/IR/toUPLC/subRoutines/rewriteHeadTailInCaseConsAndReturnRoot.d.ts +30 -0
  28. package/dist/IR/toUPLC/subRoutines/rewriteHeadTailInCaseConsAndReturnRoot.js +95 -0
  29. package/dist/IR/toUPLC/subRoutines/rewriteNativesAppliedToConstantsAndReturnRoot.js +36 -5
  30. package/dist/IR/toUPLC/subRoutines/rewriteToCaseOverConstAndReturnRoot.d.ts +35 -0
  31. package/dist/IR/toUPLC/subRoutines/rewriteToCaseOverConstAndReturnRoot.js +169 -0
  32. package/dist/IR/tree_utils/_ir_caseList.d.ts +15 -0
  33. package/dist/IR/tree_utils/_ir_caseList.js +19 -0
  34. package/dist/IR/tree_utils/bytesToHex.d.ts +8 -0
  35. package/dist/IR/tree_utils/bytesToHex.js +69 -0
  36. package/dist/ast/nodes/expr/functions/FuncExpr.d.ts +16 -2
  37. package/dist/ast/nodes/expr/functions/FuncExpr.js +17 -0
  38. package/dist/ast/nodes/expr/litteral/LitteralExpr.d.ts +2 -1
  39. package/dist/ast/nodes/expr/litteral/LitteralExpr.js +2 -0
  40. package/dist/ast/nodes/expr/litteral/TemplateStrExpr.d.ts +30 -0
  41. package/dist/ast/nodes/expr/litteral/TemplateStrExpr.js +35 -0
  42. package/dist/ast/nodes/statements/ExportStmt.d.ts +3 -3
  43. package/dist/ast/nodes/statements/PebbleStmt.d.ts +4 -3
  44. package/dist/ast/nodes/statements/PebbleStmt.js +6 -2
  45. package/dist/ast/nodes/statements/TestParam.d.ts +18 -0
  46. package/dist/ast/nodes/statements/TestParam.js +18 -0
  47. package/dist/ast/nodes/statements/TestStmt.d.ts +5 -3
  48. package/dist/ast/nodes/statements/TestStmt.js +3 -1
  49. package/dist/ast/nodes/statements/UsingStmt.d.ts +32 -2
  50. package/dist/ast/nodes/statements/UsingStmt.js +39 -3
  51. package/dist/ast/nodes/statements/declarations/NamespaceDecl.d.ts +21 -0
  52. package/dist/ast/nodes/statements/declarations/NamespaceDecl.js +31 -0
  53. package/dist/ast/nodes/statements/declarations/StructDecl.d.ts +16 -2
  54. package/dist/ast/nodes/statements/declarations/StructDecl.js +15 -1
  55. package/dist/compiler/AstCompiler/AstCompiler.d.ts +27 -0
  56. package/dist/compiler/AstCompiler/AstCompiler.js +244 -7
  57. package/dist/compiler/AstCompiler/internal/_deriveContractBody/_deriveContractBody.js +16 -5
  58. package/dist/compiler/AstCompiler/internal/exprs/_compileCallExpr.js +97 -6
  59. package/dist/compiler/AstCompiler/internal/exprs/_compileCaseExpr.js +31 -0
  60. package/dist/compiler/AstCompiler/internal/exprs/_compileFuncExpr.js +12 -5
  61. package/dist/compiler/AstCompiler/internal/exprs/_compileIsExpr.js +12 -0
  62. package/dist/compiler/AstCompiler/internal/exprs/_compileLitteralExpr.js +59 -0
  63. package/dist/compiler/AstCompiler/internal/exprs/_compilePropAccessExpr.d.ts +2 -3
  64. package/dist/compiler/AstCompiler/internal/exprs/_compilePropAccessExpr.js +64 -0
  65. package/dist/compiler/AstCompiler/internal/exprs/_compileUnaryPrefixExpr.js +13 -1
  66. package/dist/compiler/AstCompiler/internal/exprs/_compileVarAccessExpr.js +2 -0
  67. package/dist/compiler/AstCompiler/internal/exprs/binary/_compileAddExpr.js +18 -5
  68. package/dist/compiler/AstCompiler/internal/exprs/binary/_compileEqualExpr.js +3 -1
  69. package/dist/compiler/AstCompiler/internal/exprs/binary/_compileGreaterThanEqualExpr.js +2 -1
  70. package/dist/compiler/AstCompiler/internal/exprs/binary/_compileGreaterThanExpr.js +2 -1
  71. package/dist/compiler/AstCompiler/internal/exprs/binary/_compileLessThanEqualExpr.js +2 -1
  72. package/dist/compiler/AstCompiler/internal/exprs/binary/_compileLessThanExpr.js +2 -1
  73. package/dist/compiler/AstCompiler/internal/exprs/binary/_compileMultExpr.js +24 -6
  74. package/dist/compiler/AstCompiler/internal/exprs/binary/_compileNotEqualExpr.js +2 -1
  75. package/dist/compiler/AstCompiler/internal/exprs/binary/_compileSubExpr.js +16 -5
  76. package/dist/compiler/AstCompiler/internal/statements/_compileMatchStmt.js +33 -20
  77. package/dist/compiler/AstCompiler/internal/statements/_compileStatement.js +4 -1
  78. package/dist/compiler/AstCompiler/internal/statements/_compileTestStmt.d.ts +15 -1
  79. package/dist/compiler/AstCompiler/internal/statements/_compileTestStmt.js +70 -30
  80. package/dist/compiler/AstCompiler/internal/statements/_compileUsingAliasStmt.d.ts +11 -0
  81. package/dist/compiler/AstCompiler/internal/statements/_compileUsingAliasStmt.js +26 -0
  82. package/dist/compiler/AstCompiler/internal/statements/_compileUsingStmt.d.ts +9 -4
  83. package/dist/compiler/AstCompiler/internal/statements/_compileUsingStmt.js +51 -10
  84. package/dist/compiler/AstCompiler/internal/types/_compileDataEncodedConcreteType.js +21 -2
  85. package/dist/compiler/AstCompiler/internal/types/_compileSopEncodedConcreteType.js +17 -2
  86. package/dist/compiler/AstCompiler/scope/AstScope.d.ts +70 -1
  87. package/dist/compiler/AstCompiler/scope/AstScope.js +91 -0
  88. package/dist/compiler/AstCompiler/utils/getPropAccessReturnType.js +36 -1
  89. package/dist/compiler/AstCompiler/utils/monomorphizeGeneric.d.ts +36 -0
  90. package/dist/compiler/AstCompiler/utils/monomorphizeGeneric.js +123 -0
  91. package/dist/compiler/AstCompiler/utils/resolveNamespaceChain.d.ts +28 -0
  92. package/dist/compiler/AstCompiler/utils/resolveNamespaceChain.js +95 -0
  93. package/dist/compiler/AstCompiler/utils/resolveNamespacePath.d.ts +37 -0
  94. package/dist/compiler/AstCompiler/utils/resolveNamespacePath.js +93 -0
  95. package/dist/compiler/Compiler.d.ts +9 -1
  96. package/dist/compiler/Compiler.js +218 -30
  97. package/dist/compiler/TirCompiler/expressify/ExpressifyCtx.js +1 -1
  98. package/dist/compiler/TirCompiler/expressify/expressify.js +30 -2
  99. package/dist/compiler/TirCompiler/expressify/expressifyForStmt.d.ts +2 -1
  100. package/dist/compiler/TirCompiler/expressify/expressifyForStmt.js +45 -7
  101. package/dist/compiler/TirCompiler/expressify/expressifyVars.d.ts +0 -1
  102. package/dist/compiler/TirCompiler/expressify/expressifyVars.js +49 -15
  103. package/dist/compiler/test/TestResult.d.ts +38 -0
  104. package/dist/compiler/test/TestResult.js +6 -0
  105. package/dist/compiler/test/fuzz/PRNG.d.ts +26 -0
  106. package/dist/compiler/test/fuzz/PRNG.js +59 -0
  107. package/dist/compiler/tir/expressions/TirCaseExpr.d.ts +9 -0
  108. package/dist/compiler/tir/expressions/TirCaseExpr.js +144 -122
  109. package/dist/compiler/tir/expressions/TirElemAccessExpr.js +2 -2
  110. package/dist/compiler/tir/expressions/TirExpr.d.ts +2 -1
  111. package/dist/compiler/tir/expressions/TirExpr.js +2 -0
  112. package/dist/compiler/tir/expressions/TirFromDataExpr.js +102 -67
  113. package/dist/compiler/tir/expressions/TirIsExpr.js +14 -1
  114. package/dist/compiler/tir/expressions/TirNativeFunc.d.ts +18 -2
  115. package/dist/compiler/tir/expressions/TirNativeFunc.js +55 -118
  116. package/dist/compiler/tir/expressions/TirShowExpr.d.ts +52 -0
  117. package/dist/compiler/tir/expressions/TirShowExpr.js +199 -0
  118. package/dist/compiler/tir/expressions/TirToDataExpr.js +3 -0
  119. package/dist/compiler/tir/expressions/TirTraceExpr.js +11 -7
  120. package/dist/compiler/tir/expressions/TirTypeConversionExpr.js +10 -0
  121. package/dist/compiler/tir/expressions/TirVariableAccessExpr.d.ts +2 -3
  122. package/dist/compiler/tir/expressions/TirVariableAccessExpr.js +1 -4
  123. package/dist/compiler/tir/expressions/ToIRTermCtx.d.ts +20 -3
  124. package/dist/compiler/tir/expressions/ToIRTermCtx.js +48 -3
  125. package/dist/compiler/tir/expressions/binary/TirBinaryExpr.d.ts +2 -2
  126. package/dist/compiler/tir/expressions/binary/TirBinaryExpr.js +45 -8
  127. package/dist/compiler/tir/expressions/litteral/TirLitEnumMemberExpr.d.ts +19 -0
  128. package/dist/compiler/tir/expressions/litteral/TirLitEnumMemberExpr.js +24 -0
  129. package/dist/compiler/tir/expressions/litteral/TirLitteralExpr.d.ts +2 -1
  130. package/dist/compiler/tir/expressions/litteral/TirLitteralExpr.js +2 -0
  131. package/dist/compiler/tir/expressions/unary/TirUnaryMinus.js +4 -1
  132. package/dist/compiler/tir/program/TypedProgram.d.ts +101 -0
  133. package/dist/compiler/tir/program/TypedProgram.js +43 -0
  134. package/dist/compiler/tir/program/stdScope/populateBuiltinInterfaces.d.ts +17 -0
  135. package/dist/compiler/tir/program/stdScope/populateBuiltinInterfaces.js +70 -0
  136. package/dist/compiler/tir/program/stdScope/populateStdNamespace.d.ts +22 -0
  137. package/dist/compiler/tir/program/stdScope/populateStdNamespace.js +619 -0
  138. package/dist/compiler/tir/program/stdScope/prelude/preludeTypesSrc.js +35 -2
  139. package/dist/compiler/tir/program/stdScope/stdScope.d.ts +8 -0
  140. package/dist/compiler/tir/program/stdScope/stdScope.js +84 -41
  141. package/dist/compiler/tir/statements/TirStmt.js +0 -1
  142. package/dist/compiler/tir/statements/TirTestStmt.d.ts +46 -0
  143. package/dist/compiler/tir/statements/TirTestStmt.js +35 -0
  144. package/dist/compiler/tir/types/TirEnumType.d.ts +21 -0
  145. package/dist/compiler/tir/types/TirEnumType.js +36 -0
  146. package/dist/compiler/tir/types/TirNativeType/TirNativeType.d.ts +53 -2
  147. package/dist/compiler/tir/types/TirNativeType/TirNativeType.js +58 -1
  148. package/dist/compiler/tir/types/TirNativeType/native/array.d.ts +16 -0
  149. package/dist/compiler/tir/types/TirNativeType/native/array.js +38 -0
  150. package/dist/compiler/tir/types/TirNativeType/native/index.d.ts +2 -0
  151. package/dist/compiler/tir/types/TirNativeType/native/index.js +2 -0
  152. package/dist/compiler/tir/types/TirNativeType/native/value.d.ts +18 -0
  153. package/dist/compiler/tir/types/TirNativeType/native/value.js +17 -0
  154. package/dist/compiler/tir/types/TirStructType.js +6 -1
  155. package/dist/compiler/tir/types/TirType.d.ts +3 -2
  156. package/dist/compiler/tir/types/TirType.js +7 -2
  157. package/dist/compiler/tir/types/utils/canAssignTo.js +36 -1
  158. package/dist/compiler/tir/types/utils/canCastTo.js +14 -1
  159. package/dist/compiler/tir/types/utils/getDeconstructableType.d.ts +2 -1
  160. package/dist/compiler/tir/types/utils/getDeconstructableType.js +2 -0
  161. package/dist/compiler/tir/types/utils/inferTypeArgs.d.ts +19 -0
  162. package/dist/compiler/tir/types/utils/inferTypeArgs.js +83 -0
  163. package/dist/compiler/tir/types/utils/normalizeEnumToInt.d.ts +10 -0
  164. package/dist/compiler/tir/types/utils/normalizeEnumToInt.js +17 -0
  165. package/dist/compiler/tir/types/utils/substituteTypeParams.d.ts +9 -0
  166. package/dist/compiler/tir/types/utils/substituteTypeParams.js +67 -0
  167. package/dist/diagnostics/diagnosticMessages.generated.d.ts +10 -0
  168. package/dist/diagnostics/diagnosticMessages.generated.js +20 -0
  169. package/dist/index.d.ts +2 -0
  170. package/dist/index.js +2 -0
  171. package/dist/parser/Parser.d.ts +73 -3
  172. package/dist/parser/Parser.js +362 -46
  173. package/dist/tokenizer/Token.d.ts +106 -102
  174. package/dist/tokenizer/Token.js +111 -109
  175. package/dist/tokenizer/utils/tokenFromKeyword.js +11 -6
  176. package/dist/utils/semverSatisfies.d.ts +1 -0
  177. package/dist/utils/semverSatisfies.js +161 -0
  178. package/dist/version.generated.d.ts +1 -0
  179. package/dist/version.generated.js +2 -0
  180. package/package.json +5 -4
  181. package/dist/IR/tree_utils/_ir_lazyChooseList.d.ts +0 -3
  182. package/dist/IR/tree_utils/_ir_lazyChooseList.js +0 -7
@@ -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
+ }
@@ -0,0 +1,31 @@
1
+ import { VarStmt } from "../VarStmt.js";
2
+ import { FuncDecl } from "./FuncDecl.js";
3
+ import { InterfaceDecl } from "./InterfaceDecl.js";
4
+ import { isPebbleTypeDecl } from "./PebbleTypeDecl.js";
5
+ export function isNamespaceMemberStmt(thing) {
6
+ return (thing instanceof VarStmt
7
+ || thing instanceof FuncDecl
8
+ || isPebbleTypeDecl(thing)
9
+ || thing instanceof InterfaceDecl
10
+ || thing instanceof NamespaceDecl);
11
+ }
12
+ export class NamespaceMember {
13
+ isPrivate;
14
+ stmt;
15
+ range;
16
+ constructor(isPrivate, stmt, range) {
17
+ this.isPrivate = isPrivate;
18
+ this.stmt = stmt;
19
+ this.range = range;
20
+ }
21
+ }
22
+ export class NamespaceDecl {
23
+ name;
24
+ members;
25
+ range;
26
+ constructor(name, members, range) {
27
+ this.name = name;
28
+ this.members = members;
29
+ this.range = range;
30
+ }
31
+ }
@@ -4,9 +4,23 @@ import { HasSourceRange } from "../../HasSourceRange.js";
4
4
  import { SimpleVarDecl } from "./VarDecl/SimpleVarDecl.js";
5
5
  export declare enum StructDeclAstFlags {
6
6
  none = 0,
7
- untaggedSingleConstructor = 1,
7
+ /**
8
+ * Hint that the user used the shortcut single-constructor syntax
9
+ * (`struct Foo { x: int }` rather than `struct Foo { Foo { x: int } }`).
10
+ * Whether the resulting Data encoding is tagged (`constrData(0, ...)`)
11
+ * or untagged (`listData(...)`) is decided by the compiler's
12
+ * `encodingStrategy` option — `"default"` keeps the tagged form for
13
+ * backwards compatibility; `"minimal"` opts shortcut forms in to the
14
+ * untagged form.
15
+ */
16
+ shortcutSingleConstructor = 1,
8
17
  onlyDataEncoding = 2,
9
- onlySopEncoding = 4
18
+ onlySopEncoding = 4,
19
+ /**
20
+ * Explicit `untagged` modifier. Forces the untagged listData encoding
21
+ * regardless of `encodingStrategy`. Requires a single constructor.
22
+ */
23
+ untagged = 8
10
24
  }
11
25
  export declare class StructDecl implements HasSourceRange {
12
26
  readonly name: Identifier;
@@ -1,9 +1,23 @@
1
1
  export var StructDeclAstFlags;
2
2
  (function (StructDeclAstFlags) {
3
3
  StructDeclAstFlags[StructDeclAstFlags["none"] = 0] = "none";
4
- StructDeclAstFlags[StructDeclAstFlags["untaggedSingleConstructor"] = 1] = "untaggedSingleConstructor";
4
+ /**
5
+ * Hint that the user used the shortcut single-constructor syntax
6
+ * (`struct Foo { x: int }` rather than `struct Foo { Foo { x: int } }`).
7
+ * Whether the resulting Data encoding is tagged (`constrData(0, ...)`)
8
+ * or untagged (`listData(...)`) is decided by the compiler's
9
+ * `encodingStrategy` option — `"default"` keeps the tagged form for
10
+ * backwards compatibility; `"minimal"` opts shortcut forms in to the
11
+ * untagged form.
12
+ */
13
+ StructDeclAstFlags[StructDeclAstFlags["shortcutSingleConstructor"] = 1] = "shortcutSingleConstructor";
5
14
  StructDeclAstFlags[StructDeclAstFlags["onlyDataEncoding"] = 2] = "onlyDataEncoding";
6
15
  StructDeclAstFlags[StructDeclAstFlags["onlySopEncoding"] = 4] = "onlySopEncoding";
16
+ /**
17
+ * Explicit `untagged` modifier. Forces the untagged listData encoding
18
+ * regardless of `encodingStrategy`. Requires a single constructor.
19
+ */
20
+ StructDeclAstFlags[StructDeclAstFlags["untagged"] = 8] = "untagged";
7
21
  })(StructDeclAstFlags || (StructDeclAstFlags = {}));
8
22
  export class StructDecl {
9
23
  name;
@@ -86,11 +86,38 @@ export declare class AstCompiler extends DiagnosticEmitter {
86
86
  private _collectInterfaceImplSigs;
87
87
  private _collectTopLevelConst;
88
88
  private _collectTopLevelFuncDeclSig;
89
+ /**
90
+ * Register a generic function template. Compile only the signature in a
91
+ * scope where each type parameter is bound to a `TirTypeParam`; the body
92
+ * is deferred until `monomorphizeGeneric` is invoked at a call site.
93
+ */
94
+ private _registerGenericTemplate;
95
+ /**
96
+ * Resolve a `<T implements I>` constraint clause to a `TypeParamConstraint`.
97
+ *
98
+ * - `decl.constraint` must be a bare `AstNamedTypeExpr` (no type args).
99
+ * - The named interface must be registered in `scope.interfaces`
100
+ * (walking up the parent chain via `resolveInterface`).
101
+ *
102
+ * The returned object captures the AST method signatures verbatim so the
103
+ * monomorphizer doesn't have to re-resolve the interface each time.
104
+ */
105
+ private _resolveTypeParamConstraint;
106
+ /**
107
+ * walks `stmts` for `NamespaceDecl` (optionally wrapped in `ExportStmt`),
108
+ * compiles each one into a `NamespaceSymbol`, and registers it on
109
+ * `enclosingScope` (and `enclosingExports` when exported).
110
+ *
111
+ * removes processed `NamespaceDecl` statements from `stmts`.
112
+ */
113
+ private _collectNamespaceDeclarations;
114
+ private _compileNamespaceDecl;
89
115
  private _collectInterfaceDeclarations;
90
116
  registerInternalTypeDecl(decl: StructDecl | TypeAliasDecl): void;
91
117
  private _collectTypeDeclarations;
92
118
  private _compileStructDecl;
93
119
  private _compileTypeAliasDecl;
120
+ private _compileEnumDecl;
94
121
  private _consumeImportsAddSymsInScope;
95
122
  private _readFile;
96
123
  /** MUST NOT be used as a "seen" log */
@@ -1,5 +1,6 @@
1
1
  import { StructDecl, StructDeclAstFlags } from "../../ast/nodes/statements/declarations/StructDecl.js";
2
2
  import { TypeAliasDecl } from "../../ast/nodes/statements/declarations/TypeAliasDecl.js";
3
+ import { EnumDecl } from "../../ast/nodes/statements/declarations/EnumDecl.js";
3
4
  import { ExportStarStmt } from "../../ast/nodes/statements/ExportStarStmt.js";
4
5
  import { ImportStarStmt } from "../../ast/nodes/statements/ImportStarStmt.js";
5
6
  import { ImportStmt } from "../../ast/nodes/statements/ImportStmt.js";
@@ -12,6 +13,7 @@ import { createMemoryCompilerIoApi } from "../io/CompilerIoApi.js";
12
13
  import { TypedProgram } from "../tir/program/TypedProgram.js";
13
14
  import { TirAliasType } from "../tir/types/TirAliasType.js";
14
15
  import { TirDataStructType, TirSoPStructType, TirStructConstr, TirStructField } from "../tir/types/TirStructType.js";
16
+ import { TirEnumType } from "../tir/types/TirEnumType.js";
15
17
  import { ExportStmt } from "../../ast/nodes/statements/ExportStmt.js";
16
18
  import { ResolveStackNode } from "./utils/deps/ResolveStackNode.js";
17
19
  import { AstCompilationCtx } from "./AstCompilationCtx.js";
@@ -29,14 +31,18 @@ import { CommonFlags } from "../../common.js";
29
31
  import { SimpleVarDecl } from "../../ast/nodes/statements/declarations/VarDecl/SimpleVarDecl.js";
30
32
  import { Identifier } from "../../ast/nodes/common/Identifier.js";
31
33
  import { ArrowKind } from "../../ast/nodes/expr/functions/ArrowKind.js";
32
- import { _compileFuncExpr } from "./internal/exprs/_compileFuncExpr.js";
34
+ import { _compileFuncExpr, getDataFuncSignature } from "./internal/exprs/_compileFuncExpr.js";
35
+ import { TirTypeParam } from "../tir/types/TirTypeParam.js";
33
36
  import { ContractDecl } from "../../ast/nodes/statements/declarations/ContractDecl.js";
34
37
  import { _deriveContractBody } from "./internal/_deriveContractBody/_deriveContractBody.js";
35
38
  import { DiagnosticCategory } from "../../diagnostics/DiagnosticCategory.js";
36
39
  import { VarStmt } from "../../ast/nodes/statements/VarStmt.js";
37
40
  import { _compileSimpleVarDecl } from "./internal/statements/_compileVarStmt.js";
41
+ import { _compileTestStmt } from "./internal/statements/_compileTestStmt.js";
38
42
  import { SourceTypeMap } from "../SourceTypeMap.js";
39
43
  import { isIdentifier } from "../../utils/text.js";
44
+ import { TestStmt } from "../../ast/nodes/statements/TestStmt.js";
45
+ import { NamespaceDecl } from "../../ast/nodes/statements/declarations/NamespaceDecl.js";
40
46
  /*
41
47
  Handling type expressions that depend on other types
42
48
  (such as generics, function return types, and inferred types from complex expressions)
@@ -273,6 +279,9 @@ export class AstCompiler extends DiagnosticEmitter {
273
279
  this._consumeImportsAddSymsInScope(stmts, src.absoluteProjPath, importsScope);
274
280
  const topLevelScope = importsScope.newChildScope({ isFunctionDeclScope: false });
275
281
  const srcExports = this.preludeScope.newChildScope({ isFunctionDeclScope: false });
282
+ // collect namespace declarations (recursively) so that types/interfaces/signatures
283
+ // can refer to symbols defined inside namespaces.
284
+ this._collectNamespaceDeclarations(stmts, src.uid, topLevelScope, srcExports);
276
285
  // collect top level **type** (struct and aliases) declarations
277
286
  this._collectTypeDeclarations(stmts, src.uid, topLevelScope, srcExports);
278
287
  // collect top level **interface** declarations (NOT implementations)
@@ -300,6 +309,17 @@ export class AstCompiler extends DiagnosticEmitter {
300
309
  exportRange = stmt.range;
301
310
  stmt = stmt.stmt;
302
311
  }
312
+ if (stmt instanceof TestStmt) {
313
+ if (isEntryFile) {
314
+ const declContext = AstCompilationCtx.fromScope(this.program, topLevelScope);
315
+ _compileTestStmt(declContext, stmt, srcUid, this.cfg.entry);
316
+ }
317
+ // tests from non-entry files are dropped on the floor:
318
+ // they will be collected when their own file is the entry.
319
+ void stmts.splice(i, 1);
320
+ i--;
321
+ continue;
322
+ }
303
323
  if (!(stmt instanceof FuncDecl
304
324
  || stmt instanceof TypeImplementsStmt
305
325
  || stmt instanceof ContractDecl
@@ -428,6 +448,14 @@ export class AstCompiler extends DiagnosticEmitter {
428
448
  if (this._isExporting && astFuncName === this.program.contractTirFuncName) {
429
449
  this.program.contractTirFuncName = tirFuncName;
430
450
  }
451
+ // Generic function declaration path: do NOT compile the body. Instead,
452
+ // compile the signature in a scope where each type parameter resolves
453
+ // to a fresh `TirTypeParam`, then register a `GenericTemplate` on the
454
+ // program. Call sites instantiate it via `monomorphizeGeneric`.
455
+ if (astFuncExpr.typeParams.length > 0) {
456
+ this._registerGenericTemplate(astFuncExpr, astFuncName, tirFuncName, topLevelScope, srcExports, exportRange);
457
+ return;
458
+ }
431
459
  const declContext = AstCompilationCtx.fromScope(this.program, topLevelScope);
432
460
  const funcExpr = _compileFuncExpr(declContext, astFuncExpr, undefined, // sig
433
461
  false // isMethod
@@ -456,6 +484,160 @@ export class AstCompiler extends DiagnosticEmitter {
456
484
  && this.program.contractTirFuncName === "")
457
485
  this.program.contractTirFuncName = tirFuncName;
458
486
  }
487
+ /**
488
+ * Register a generic function template. Compile only the signature in a
489
+ * scope where each type parameter is bound to a `TirTypeParam`; the body
490
+ * is deferred until `monomorphizeGeneric` is invoked at a call site.
491
+ */
492
+ _registerGenericTemplate(astFuncExpr, astFuncName, tirFuncName, topLevelScope, srcExports, exportRange) {
493
+ if (topLevelScope.functions.has(astFuncName))
494
+ return this.error(DiagnosticCode._0_is_already_defined, astFuncExpr.name.range, astFuncName);
495
+ // Detect duplicate type-param names on the template
496
+ const seenParamNames = new Set();
497
+ const tirTypeParams = [];
498
+ for (const decl of astFuncExpr.typeParams) {
499
+ if (seenParamNames.has(decl.name.text)) {
500
+ return this.error(DiagnosticCode._0_is_already_defined, decl.name.range, decl.name.text);
501
+ }
502
+ seenParamNames.add(decl.name.text);
503
+ tirTypeParams.push(new TirTypeParam(decl.name.text));
504
+ }
505
+ // Build a child scope where each type-param name resolves to its
506
+ // TirTypeParam (via `_compileDataEncodedConcreteType`'s new lookup).
507
+ const templateScope = topLevelScope.newChildScope({
508
+ ...topLevelScope.infos,
509
+ isFunctionDeclScope: false,
510
+ isMethodScope: false
511
+ });
512
+ for (let i = 0; i < astFuncExpr.typeParams.length; i++) {
513
+ templateScope.defineTypeParam(astFuncExpr.typeParams[i].name.text, tirTypeParams[i]);
514
+ }
515
+ // Resolve constraints on each type param (the `implements I` clause).
516
+ // For each constrained param, record the constraint on the template
517
+ // so monomorphizeGeneric can inject the matching dictionary at call
518
+ // sites, and on the template scope so `getPropAccessReturnType` can
519
+ // resolve method calls on `T`-typed values inside the body.
520
+ const constraints = new Array(astFuncExpr.typeParams.length).fill(undefined);
521
+ for (let i = 0; i < astFuncExpr.typeParams.length; i++) {
522
+ const decl = astFuncExpr.typeParams[i];
523
+ if (!decl.constraint)
524
+ continue;
525
+ const con = this._resolveTypeParamConstraint(templateScope, decl);
526
+ if (!con)
527
+ return undefined;
528
+ constraints[i] = con;
529
+ templateScope.defineTypeParamConstraint(decl.name.text, con);
530
+ }
531
+ // Compile only the signature: yields a TirFuncT that may contain
532
+ // TirTypeParams in arg/return positions.
533
+ const templateCtx = AstCompilationCtx.fromScope(this.program, templateScope);
534
+ const placeholderFuncType = getDataFuncSignature(templateCtx, astFuncExpr.signature);
535
+ if (!placeholderFuncType)
536
+ return undefined;
537
+ // Register the template on the program
538
+ this.program.genericTemplates.set(astFuncName, {
539
+ kind: "user",
540
+ astFuncName,
541
+ astFuncExpr,
542
+ typeParams: tirTypeParams,
543
+ definingScope: topLevelScope,
544
+ canonicalTirName: tirFuncName,
545
+ placeholderFuncType,
546
+ constraints,
547
+ });
548
+ // Register the generic placeholder value in the top-level scope so
549
+ // identifier lookup at call sites finds it. The `genericTemplateName`
550
+ // field signals to `_compileCallExpr` that this is a template.
551
+ topLevelScope.functions.set(astFuncName, tirFuncName);
552
+ topLevelScope.defineValue({
553
+ name: astFuncName,
554
+ type: placeholderFuncType,
555
+ isConstant: true,
556
+ genericTemplateName: astFuncName,
557
+ });
558
+ if (exportRange && srcExports) {
559
+ if (srcExports.functions.has(astFuncName)
560
+ || srcExports.variables.has(astFuncName))
561
+ return this.error(DiagnosticCode._0_is_already_exported, exportRange, astFuncName);
562
+ srcExports.functions.set(astFuncName, tirFuncName);
563
+ srcExports.defineValue({
564
+ name: astFuncName,
565
+ type: placeholderFuncType,
566
+ isConstant: true,
567
+ genericTemplateName: astFuncName,
568
+ });
569
+ }
570
+ }
571
+ /**
572
+ * Resolve a `<T implements I>` constraint clause to a `TypeParamConstraint`.
573
+ *
574
+ * - `decl.constraint` must be a bare `AstNamedTypeExpr` (no type args).
575
+ * - The named interface must be registered in `scope.interfaces`
576
+ * (walking up the parent chain via `resolveInterface`).
577
+ *
578
+ * The returned object captures the AST method signatures verbatim so the
579
+ * monomorphizer doesn't have to re-resolve the interface each time.
580
+ */
581
+ _resolveTypeParamConstraint(scope, decl) {
582
+ const constraint = decl.constraint;
583
+ if (!constraint)
584
+ return undefined;
585
+ if (!(constraint instanceof AstNamedTypeExpr))
586
+ return this.error(DiagnosticCode.Type_expected, constraint.range);
587
+ if (constraint.tyArgs.length > 0)
588
+ return this.error(DiagnosticCode.Not_implemented_0, constraint.range, "generic interface as a type-parameter constraint");
589
+ const interfaceName = constraint.name.text;
590
+ const methods = scope.resolveInterface(interfaceName);
591
+ if (!methods)
592
+ return this.error(DiagnosticCode._0_is_not_defined, constraint.name.range, interfaceName);
593
+ return { interfaceName, methods };
594
+ }
595
+ /**
596
+ * walks `stmts` for `NamespaceDecl` (optionally wrapped in `ExportStmt`),
597
+ * compiles each one into a `NamespaceSymbol`, and registers it on
598
+ * `enclosingScope` (and `enclosingExports` when exported).
599
+ *
600
+ * removes processed `NamespaceDecl` statements from `stmts`.
601
+ */
602
+ _collectNamespaceDeclarations(stmts, srcUid, enclosingScope, enclosingExports) {
603
+ for (let i = 0; i < stmts.length; i++) {
604
+ let stmt = stmts[i];
605
+ let exported = false;
606
+ if (stmt instanceof ExportStmt) {
607
+ exported = true;
608
+ stmt = stmt.stmt;
609
+ }
610
+ if (!(stmt instanceof NamespaceDecl))
611
+ continue;
612
+ this._compileNamespaceDecl(stmt, srcUid, enclosingScope, enclosingExports, exported);
613
+ void stmts.splice(i, 1);
614
+ i--;
615
+ }
616
+ }
617
+ _compileNamespaceDecl(decl, srcUid, enclosingScope, enclosingExports, isExported) {
618
+ const nsName = decl.name.text;
619
+ if (enclosingScope.namespaces.has(nsName))
620
+ return this.error(DiagnosticCode._0_is_already_defined, decl.name.range, nsName);
621
+ const compilationScope = enclosingScope.newChildScope({ isFunctionDeclScope: false });
622
+ const publicScope = enclosingScope.newChildScope({ isFunctionDeclScope: false });
623
+ const nsSrcUid = `${srcUid}::${nsName}`;
624
+ // build a synthetic top-level statement list from the namespace's members:
625
+ // wrap public members in ExportStmt so the existing passes route them
626
+ // to `publicScope` automatically; leave private members bare so they only
627
+ // live in `compilationScope`.
628
+ const fakeStmts = decl.members.map((m) => m.isPrivate
629
+ ? m.stmt
630
+ : new ExportStmt(m.stmt, m.range));
631
+ // recurse into nested namespaces first so subsequent passes can
632
+ // resolve `Inner.Member` references.
633
+ this._collectNamespaceDeclarations(fakeStmts, nsSrcUid, compilationScope, publicScope);
634
+ this._collectTypeDeclarations(fakeStmts, nsSrcUid, compilationScope, publicScope);
635
+ this._collectInterfaceDeclarations(fakeStmts, compilationScope, publicScope);
636
+ this._collectAllTopLevelSignatures(fakeStmts, nsSrcUid, compilationScope, publicScope, false);
637
+ enclosingScope.defineNamespace({ name: nsName, publicScope });
638
+ if (isExported)
639
+ enclosingExports.defineNamespace({ name: nsName, publicScope });
640
+ }
459
641
  _collectInterfaceDeclarations(stmts, topLevelScope, srcExports) {
460
642
  for (let i = 0; i < stmts.length; i++) {
461
643
  let stmt = stmts[i];
@@ -495,12 +677,15 @@ export class AstCompiler extends DiagnosticEmitter {
495
677
  stmt = stmt.stmt;
496
678
  }
497
679
  if (!(stmt instanceof StructDecl
498
- || stmt instanceof TypeAliasDecl))
680
+ || stmt instanceof TypeAliasDecl
681
+ || stmt instanceof EnumDecl))
499
682
  continue;
500
- const isGeneric = stmt.typeParams.length > 0;
683
+ const isGeneric = stmt instanceof EnumDecl ? false : stmt.typeParams.length > 0;
501
684
  const tirTypes = stmt instanceof StructDecl
502
685
  ? this._compileStructDecl(stmt, srcUid, topLevelScope)
503
- : this._compileTypeAliasDecl(stmt, srcUid, topLevelScope);
686
+ : stmt instanceof EnumDecl
687
+ ? this._compileEnumDecl(stmt, srcUid, topLevelScope)
688
+ : this._compileTypeAliasDecl(stmt, srcUid, topLevelScope);
504
689
  if (!tirTypes // undefined
505
690
  || !(tirTypes.sop || tirTypes.data) // or both undefined
506
691
  )
@@ -563,6 +748,16 @@ export class AstCompiler extends DiagnosticEmitter {
563
748
  // data encoded type
564
749
  if (!stmt.hasFlag(StructDeclAstFlags.onlySopEncoding)) {
565
750
  let canEncodeToData = true;
751
+ // Untagged Data encoding (`listData(...)`) instead of
752
+ // `constrData(0, ...)`. Requires exactly one constructor and is
753
+ // enabled by either the explicit `untagged` keyword or the
754
+ // shortcut-form syntax when `encodingStrategy === "minimal"`.
755
+ const isUntagged = stmt.constrs.length === 1 && (stmt.hasFlag(StructDeclAstFlags.untagged)
756
+ || (stmt.hasFlag(StructDeclAstFlags.shortcutSingleConstructor)
757
+ && this.cfg.encodingStrategy === "minimal"));
758
+ if (stmt.hasFlag(StructDeclAstFlags.untagged) && stmt.constrs.length !== 1) {
759
+ this.error(DiagnosticCode.Not_implemented_0, stmt.name.range, "`untagged` struct must have exactly one constructor");
760
+ }
566
761
  const dataType = new TirDataStructType(stmt.name.text, srcUid, stmt.constrs.map(ctor => new TirStructConstr(ctor.name.text, ctor.fields.map(field => {
567
762
  if (!field.type)
568
763
  return compiler.error(DiagnosticCode.Type_expected, field.name.range.atEnd());
@@ -576,7 +771,7 @@ export class AstCompiler extends DiagnosticEmitter {
576
771
  }
577
772
  return new TirStructField(field.name.text, fieldType);
578
773
  })
579
- .filter(f => f instanceof TirStructField))), methodsNames);
774
+ .filter(f => f instanceof TirStructField))), methodsNames, isUntagged);
580
775
  if (canEncodeToData)
581
776
  data = dataType;
582
777
  else if (stmt.hasFlag(StructDeclAstFlags.onlyDataEncoding))
@@ -599,11 +794,49 @@ export class AstCompiler extends DiagnosticEmitter {
599
794
  ) : undefined;
600
795
  return sop || data ? { sop, data, methodsNames } : undefined;
601
796
  }
797
+ _compileEnumDecl(stmt, srcUid, _topLevelScope) {
798
+ if (stmt.members.length === 0) {
799
+ this.error(DiagnosticCode.Enum_must_have_at_least_one_member, stmt.name.range);
800
+ return undefined;
801
+ }
802
+ const seen = new Set();
803
+ const memberNames = [];
804
+ for (const m of stmt.members) {
805
+ if (m.value !== undefined) {
806
+ this.error(DiagnosticCode.Enum_members_cannot_have_explicit_values, m.range);
807
+ }
808
+ if (seen.has(m.name.text)) {
809
+ this.error(DiagnosticCode.Duplicate_enum_member_0, m.name.range, m.name.text);
810
+ continue;
811
+ }
812
+ seen.add(m.name.text);
813
+ memberNames.push(m.name.text);
814
+ }
815
+ const methodsNames = new Map();
816
+ const enumType = new TirEnumType(stmt.name.text, srcUid, memberNames, methodsNames);
817
+ return { sop: enumType, data: enumType, methodsNames };
818
+ }
602
819
  _consumeImportsAddSymsInScope(stmts, srcAbsPath, srcImportsScope) {
603
820
  for (let i = 0; i < stmts.length; i++) {
604
821
  const stmt = stmts[i];
605
822
  if (stmt instanceof ImportStarStmt) {
606
- this.error(DiagnosticCode.Not_implemented_0, stmt.range, "import *");
823
+ const importAbsPath = getAbsolutePath(stmt.fromPath.string, srcAbsPath) ?? "";
824
+ const importedSymbols = this.program.getExportedSymbols(importAbsPath);
825
+ if (!importedSymbols) {
826
+ this.error(DiagnosticCode.File_0_not_found, stmt.fromPath.range, importAbsPath);
827
+ void stmts.splice(i, 1);
828
+ i--;
829
+ continue;
830
+ }
831
+ const aliasName = stmt.anIdentifier.text;
832
+ const ok = srcImportsScope.defineNamespace({
833
+ name: aliasName,
834
+ publicScope: importedSymbols
835
+ });
836
+ if (!ok)
837
+ this.error(DiagnosticCode._0_is_already_defined, stmt.anIdentifier.range, aliasName);
838
+ void stmts.splice(i, 1);
839
+ i--;
607
840
  continue;
608
841
  }
609
842
  if (!(stmt instanceof ImportStmt))
@@ -620,10 +853,12 @@ export class AstCompiler extends DiagnosticEmitter {
620
853
  const isType = importedSymbols.types.has(declName);
621
854
  const isFunction = importedSymbols.functions.has(declName);
622
855
  const isInterface = importedSymbols.interfaces.has(declName);
856
+ const isNamespace = importedSymbols.namespaces.has(declName);
623
857
  if (!(isValue
624
858
  || isType
625
859
  || isFunction
626
- || isInterface)) {
860
+ || isInterface
861
+ || isNamespace)) {
627
862
  this.error(DiagnosticCode.Module_0_has_no_exported_member_1, importDecl.identifier.range, stmt.fromPath.string, declName);
628
863
  continue;
629
864
  }
@@ -647,6 +882,8 @@ export class AstCompiler extends DiagnosticEmitter {
647
882
  srcImportsScope.types.set(declName, importedSymbols.types.get(declName));
648
883
  if (isInterface)
649
884
  srcImportsScope.interfaces.set(declName, importedSymbols.interfaces.get(declName));
885
+ if (isNamespace)
886
+ srcImportsScope.defineNamespace(importedSymbols.namespaces.get(declName));
650
887
  }
651
888
  // remove from array so we don't process it again
652
889
  void stmts.splice(i, 1);