semantifold 0.3.0 → 0.4.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 (297) hide show
  1. package/README.md +58 -15
  2. package/build/index.d.ts +48 -2
  3. package/build/index.d.ts.map +1 -1
  4. package/build/index.js +57 -8
  5. package/build/src/artifact-path.d.ts +23 -1
  6. package/build/src/artifact-path.d.ts.map +1 -1
  7. package/build/src/artifact-path.js +45 -3
  8. package/build/src/artifacts.d.ts.map +1 -1
  9. package/build/src/artifacts.js +66 -1
  10. package/build/src/backends/c-validation.d.ts.map +1 -1
  11. package/build/src/backends/c-validation.js +7 -3
  12. package/build/src/backends/cpp-validation.d.ts.map +1 -1
  13. package/build/src/backends/cpp-validation.js +7 -3
  14. package/build/src/backends/csharp.js +7 -1
  15. package/build/src/backends/dart-runtime.d.ts +2 -0
  16. package/build/src/backends/dart-runtime.d.ts.map +1 -0
  17. package/build/src/backends/dart-runtime.js +41 -0
  18. package/build/src/backends/dart.d.ts +20 -0
  19. package/build/src/backends/dart.d.ts.map +1 -0
  20. package/build/src/backends/dart.js +321 -0
  21. package/build/src/backends/effects.d.ts +60 -0
  22. package/build/src/backends/effects.d.ts.map +1 -0
  23. package/build/src/backends/effects.js +746 -0
  24. package/build/src/backends/go.js +18 -4
  25. package/build/src/backends/identifiers.d.ts +36 -4
  26. package/build/src/backends/identifiers.d.ts.map +1 -1
  27. package/build/src/backends/identifiers.js +154 -10
  28. package/build/src/backends/index.d.ts.map +1 -1
  29. package/build/src/backends/index.js +27 -4
  30. package/build/src/backends/ios.d.ts +68 -0
  31. package/build/src/backends/ios.d.ts.map +1 -0
  32. package/build/src/backends/ios.js +1503 -0
  33. package/build/src/backends/java.d.ts.map +1 -1
  34. package/build/src/backends/java.js +429 -36
  35. package/build/src/backends/javascript.d.ts +6 -0
  36. package/build/src/backends/javascript.d.ts.map +1 -1
  37. package/build/src/backends/javascript.js +380 -24
  38. package/build/src/backends/kotlin-runtime.d.ts +3 -0
  39. package/build/src/backends/kotlin-runtime.d.ts.map +1 -0
  40. package/build/src/backends/kotlin-runtime.js +29 -0
  41. package/build/src/backends/kotlin.d.ts +23 -0
  42. package/build/src/backends/kotlin.d.ts.map +1 -0
  43. package/build/src/backends/kotlin.js +136 -0
  44. package/build/src/backends/native-validation.d.ts +2 -2
  45. package/build/src/backends/native-validation.d.ts.map +1 -1
  46. package/build/src/backends/native-validation.js +2 -2
  47. package/build/src/backends/ordered-expressions.d.ts.map +1 -1
  48. package/build/src/backends/ordered-expressions.js +39 -7
  49. package/build/src/backends/php-stdlib-support.d.ts +19 -0
  50. package/build/src/backends/php-stdlib-support.d.ts.map +1 -0
  51. package/build/src/backends/php-stdlib-support.js +227 -0
  52. package/build/src/backends/php.d.ts.map +1 -1
  53. package/build/src/backends/php.js +448 -33
  54. package/build/src/backends/program.d.ts +81 -0
  55. package/build/src/backends/program.d.ts.map +1 -0
  56. package/build/src/backends/program.js +1308 -0
  57. package/build/src/backends/python.js +7 -1
  58. package/build/src/backends/ruby.d.ts.map +1 -1
  59. package/build/src/backends/ruby.js +310 -24
  60. package/build/src/backends/rust-runtime.d.ts +7 -0
  61. package/build/src/backends/rust-runtime.d.ts.map +1 -0
  62. package/build/src/backends/rust-runtime.js +32 -0
  63. package/build/src/backends/rust-validation.d.ts +9 -0
  64. package/build/src/backends/rust-validation.d.ts.map +1 -0
  65. package/build/src/backends/rust-validation.js +78 -0
  66. package/build/src/backends/rust.d.ts +24 -0
  67. package/build/src/backends/rust.d.ts.map +1 -0
  68. package/build/src/backends/rust.js +344 -0
  69. package/build/src/backends/scalars.d.ts +14 -6
  70. package/build/src/backends/scalars.d.ts.map +1 -1
  71. package/build/src/backends/scalars.js +167 -17
  72. package/build/src/backends/shared.d.ts +23 -4
  73. package/build/src/backends/shared.d.ts.map +1 -1
  74. package/build/src/backends/shared.js +2158 -62
  75. package/build/src/backends/stdlib-support.d.ts +14 -0
  76. package/build/src/backends/stdlib-support.d.ts.map +1 -0
  77. package/build/src/backends/stdlib-support.js +237 -0
  78. package/build/src/backends/swift-runtime.d.ts +3 -0
  79. package/build/src/backends/swift-runtime.d.ts.map +1 -0
  80. package/build/src/backends/swift-runtime.js +14 -0
  81. package/build/src/backends/swift.d.ts +8 -0
  82. package/build/src/backends/swift.d.ts.map +1 -0
  83. package/build/src/backends/swift.js +127 -0
  84. package/build/src/backends/typescript.d.ts.map +1 -1
  85. package/build/src/backends/typescript.js +344 -24
  86. package/build/src/backends/wasm.d.ts +43 -0
  87. package/build/src/backends/wasm.d.ts.map +1 -0
  88. package/build/src/backends/wasm.js +2164 -0
  89. package/build/src/backends/writer.d.ts +235 -4
  90. package/build/src/backends/writer.d.ts.map +1 -1
  91. package/build/src/backends/writer.js +468 -3
  92. package/build/src/diagnostic.d.ts +4 -3
  93. package/build/src/diagnostic.d.ts.map +1 -1
  94. package/build/src/diagnostic.js +5 -3
  95. package/build/src/frontends/c.d.ts.map +1 -1
  96. package/build/src/frontends/c.js +5 -3
  97. package/build/src/frontends/cpp.d.ts.map +1 -1
  98. package/build/src/frontends/cpp.js +5 -3
  99. package/build/src/frontends/csharp.d.ts.map +1 -1
  100. package/build/src/frontends/csharp.js +7 -3
  101. package/build/src/frontends/dart.d.ts +10 -0
  102. package/build/src/frontends/dart.d.ts.map +1 -0
  103. package/build/src/frontends/dart.js +913 -0
  104. package/build/src/frontends/index.d.ts +3 -1
  105. package/build/src/frontends/index.d.ts.map +1 -1
  106. package/build/src/frontends/index.js +15 -5
  107. package/build/src/frontends/java.d.ts +110 -1
  108. package/build/src/frontends/java.d.ts.map +1 -1
  109. package/build/src/frontends/java.js +1725 -70
  110. package/build/src/frontends/javascript-typescript.d.ts +69 -1
  111. package/build/src/frontends/javascript-typescript.d.ts.map +1 -1
  112. package/build/src/frontends/javascript-typescript.js +1825 -93
  113. package/build/src/frontends/kotlin.d.ts +10 -0
  114. package/build/src/frontends/kotlin.d.ts.map +1 -0
  115. package/build/src/frontends/kotlin.js +685 -0
  116. package/build/src/frontends/php.d.ts +118 -1
  117. package/build/src/frontends/php.d.ts.map +1 -1
  118. package/build/src/frontends/php.js +1583 -76
  119. package/build/src/frontends/program.d.ts +74 -0
  120. package/build/src/frontends/program.d.ts.map +1 -0
  121. package/build/src/frontends/program.js +989 -0
  122. package/build/src/frontends/ruby.d.ts +68 -1
  123. package/build/src/frontends/ruby.d.ts.map +1 -1
  124. package/build/src/frontends/ruby.js +1446 -101
  125. package/build/src/frontends/rust-parser.d.ts +11 -0
  126. package/build/src/frontends/rust-parser.d.ts.map +1 -0
  127. package/build/src/frontends/rust-parser.js +15 -0
  128. package/build/src/frontends/rust.d.ts +14 -0
  129. package/build/src/frontends/rust.d.ts.map +1 -0
  130. package/build/src/frontends/rust.js +715 -0
  131. package/build/src/frontends/scalars.d.ts +10 -0
  132. package/build/src/frontends/scalars.d.ts.map +1 -1
  133. package/build/src/frontends/scalars.js +28 -2
  134. package/build/src/frontends/swift.d.ts +10 -0
  135. package/build/src/frontends/swift.d.ts.map +1 -0
  136. package/build/src/frontends/swift.js +860 -0
  137. package/build/src/frontends/types.d.ts +186 -0
  138. package/build/src/frontends/types.d.ts.map +1 -0
  139. package/build/src/frontends/types.js +634 -0
  140. package/build/src/language-registry.d.ts +46 -4
  141. package/build/src/language-registry.d.ts.map +1 -1
  142. package/build/src/language-registry.js +167 -13
  143. package/build/src/mapping.d.ts +2 -2
  144. package/build/src/mapping.d.ts.map +1 -1
  145. package/build/src/mapping.js +31 -10
  146. package/build/src/semantic/capabilities.d.ts +66 -0
  147. package/build/src/semantic/capabilities.d.ts.map +1 -0
  148. package/build/src/semantic/capabilities.js +649 -0
  149. package/build/src/semantic/effects.d.ts +26 -0
  150. package/build/src/semantic/effects.d.ts.map +1 -0
  151. package/build/src/semantic/effects.js +764 -0
  152. package/build/src/semantic/generics.d.ts +23 -0
  153. package/build/src/semantic/generics.d.ts.map +1 -0
  154. package/build/src/semantic/generics.js +61 -0
  155. package/build/src/semantic/lifetime.d.ts +37 -0
  156. package/build/src/semantic/lifetime.d.ts.map +1 -0
  157. package/build/src/semantic/lifetime.js +527 -0
  158. package/build/src/semantic/provenance.d.ts +9 -2
  159. package/build/src/semantic/provenance.d.ts.map +1 -1
  160. package/build/src/semantic/provenance.js +462 -20
  161. package/build/src/semantic/scalars.d.ts +11 -0
  162. package/build/src/semantic/scalars.d.ts.map +1 -1
  163. package/build/src/semantic/scalars.js +16 -1
  164. package/build/src/semantic/stdlib.d.ts +254 -0
  165. package/build/src/semantic/stdlib.d.ts.map +1 -0
  166. package/build/src/semantic/stdlib.js +880 -0
  167. package/build/src/semantic/types.d.ts +2952 -202
  168. package/build/src/semantic/types.d.ts.map +1 -1
  169. package/build/src/semantic/types.js +688 -15
  170. package/build/src/semantic/validate.d.ts +85 -5
  171. package/build/src/semantic/validate.d.ts.map +1 -1
  172. package/build/src/semantic/validate.js +2576 -98
  173. package/build/src/stdlib-facades.d.ts +304 -0
  174. package/build/src/stdlib-facades.d.ts.map +1 -0
  175. package/build/src/stdlib-facades.js +1167 -0
  176. package/build/src/stdlib-negotiation.d.ts +69 -0
  177. package/build/src/stdlib-negotiation.d.ts.map +1 -0
  178. package/build/src/stdlib-negotiation.js +403 -0
  179. package/build/src/stdlib-providers.d.ts +72 -0
  180. package/build/src/stdlib-providers.d.ts.map +1 -0
  181. package/build/src/stdlib-providers.js +339 -0
  182. package/build/src/toolchains.d.ts +55 -1
  183. package/build/src/toolchains.d.ts.map +1 -1
  184. package/build/src/toolchains.js +15 -4
  185. package/docs/architecture.md +45 -13
  186. package/docs/dart.md +60 -0
  187. package/docs/goals.md +3 -3
  188. package/docs/ios.md +121 -0
  189. package/docs/kotlin.md +42 -0
  190. package/docs/language-support.md +231 -26
  191. package/docs/multi-file-modules.md +52 -0
  192. package/docs/parser-qualification.md +121 -8
  193. package/docs/plans/2026-09-05-standard-library-portability.md +10 -10
  194. package/docs/rust.md +88 -0
  195. package/docs/source-maps.md +15 -7
  196. package/docs/standard-library-portability.md +39 -8
  197. package/docs/swift.md +44 -0
  198. package/docs/testing.md +366 -4
  199. package/docs/webassembly.md +52 -0
  200. package/index.js +63 -8
  201. package/node_modules/semantifold-tree-sitter-legacy-internal/README.md +2 -2
  202. package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter-rust/LICENSE +21 -0
  203. package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter-rust/README.md +45 -0
  204. package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter-rust/binding.gyp +30 -0
  205. package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter-rust/bindings/node/binding.cc +20 -0
  206. package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter-rust/bindings/node/binding_test.js +9 -0
  207. package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter-rust/bindings/node/index.d.ts +28 -0
  208. package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter-rust/bindings/node/index.js +11 -0
  209. package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter-rust/grammar.js +1630 -0
  210. package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter-rust/package.json +64 -0
  211. package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter-rust/prebuilds/darwin-arm64/tree-sitter-rust.node +0 -0
  212. package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter-rust/prebuilds/darwin-x64/tree-sitter-rust.node +0 -0
  213. package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter-rust/prebuilds/linux-arm64/tree-sitter-rust.node +0 -0
  214. package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter-rust/prebuilds/linux-x64/tree-sitter-rust.node +0 -0
  215. package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter-rust/prebuilds/win32-arm64/tree-sitter-rust.node +0 -0
  216. package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter-rust/prebuilds/win32-x64/tree-sitter-rust.node +0 -0
  217. package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter-rust/queries/highlights.scm +159 -0
  218. package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter-rust/queries/injections.scm +9 -0
  219. package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter-rust/queries/tags.scm +60 -0
  220. package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter-rust/src/grammar.json +9405 -0
  221. package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter-rust/src/node-types.json +5399 -0
  222. package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter-rust/src/parser.c +192569 -0
  223. package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter-rust/src/scanner.c +393 -0
  224. package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter-rust/src/tree_sitter/alloc.h +54 -0
  225. package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter-rust/src/tree_sitter/array.h +290 -0
  226. package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter-rust/src/tree_sitter/parser.h +266 -0
  227. package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter-rust/tree-sitter-rust.wasm +0 -0
  228. package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter-rust/tree-sitter.json +53 -0
  229. package/node_modules/semantifold-tree-sitter-legacy-internal/package.json +3 -2
  230. package/node_modules/semantifold-tree-sitter-legacy-internal/src/c.js +5 -4
  231. package/package.json +5 -2
  232. package/src/artifact-path.js +47 -2
  233. package/src/artifacts.js +67 -0
  234. package/src/backends/c-validation.js +6 -1
  235. package/src/backends/cpp-validation.js +6 -1
  236. package/src/backends/csharp.js +3 -0
  237. package/src/backends/dart-runtime.js +41 -0
  238. package/src/backends/dart.js +326 -0
  239. package/src/backends/effects.js +705 -0
  240. package/src/backends/go.js +14 -2
  241. package/src/backends/identifiers.js +160 -9
  242. package/src/backends/index.js +27 -2
  243. package/src/backends/ios.js +1612 -0
  244. package/src/backends/java.js +454 -36
  245. package/src/backends/javascript.js +389 -23
  246. package/src/backends/kotlin-runtime.js +29 -0
  247. package/src/backends/kotlin.js +141 -0
  248. package/src/backends/native-validation.js +1 -1
  249. package/src/backends/ordered-expressions.js +40 -6
  250. package/src/backends/php-stdlib-support.js +239 -0
  251. package/src/backends/php.js +469 -32
  252. package/src/backends/program.js +1407 -0
  253. package/src/backends/python.js +3 -0
  254. package/src/backends/ruby.js +326 -23
  255. package/src/backends/rust-runtime.js +34 -0
  256. package/src/backends/rust-validation.js +75 -0
  257. package/src/backends/rust.js +335 -0
  258. package/src/backends/scalars.js +141 -16
  259. package/src/backends/shared.js +2304 -124
  260. package/src/backends/stdlib-support.js +234 -0
  261. package/src/backends/swift-runtime.js +14 -0
  262. package/src/backends/swift.js +132 -0
  263. package/src/backends/typescript.js +349 -23
  264. package/src/backends/wasm.js +2208 -0
  265. package/src/backends/writer.js +520 -2
  266. package/src/diagnostic.js +4 -2
  267. package/src/frontends/c.js +4 -2
  268. package/src/frontends/cpp.js +4 -2
  269. package/src/frontends/csharp.js +4 -2
  270. package/src/frontends/dart.js +963 -0
  271. package/src/frontends/index.js +14 -4
  272. package/src/frontends/java.js +1977 -69
  273. package/src/frontends/javascript-typescript.js +2046 -102
  274. package/src/frontends/kotlin.js +713 -0
  275. package/src/frontends/php.js +1725 -79
  276. package/src/frontends/program.js +1062 -0
  277. package/src/frontends/ruby.js +1624 -98
  278. package/src/frontends/rust-parser.js +18 -0
  279. package/src/frontends/rust.js +714 -0
  280. package/src/frontends/scalars.js +31 -1
  281. package/src/frontends/swift.js +893 -0
  282. package/src/frontends/types.js +750 -0
  283. package/src/language-registry.js +172 -12
  284. package/src/mapping.js +33 -9
  285. package/src/semantic/capabilities.js +671 -0
  286. package/src/semantic/effects.js +737 -0
  287. package/src/semantic/generics.js +58 -0
  288. package/src/semantic/lifetime.js +517 -0
  289. package/src/semantic/provenance.js +412 -19
  290. package/src/semantic/scalars.js +17 -0
  291. package/src/semantic/stdlib.js +921 -0
  292. package/src/semantic/types.js +765 -14
  293. package/src/semantic/validate.js +2934 -209
  294. package/src/stdlib-facades.js +1211 -0
  295. package/src/stdlib-negotiation.js +446 -0
  296. package/src/stdlib-providers.js +377 -0
  297. package/src/toolchains.js +16 -3
@@ -3,16 +3,26 @@
3
3
  import {isDenseArray} from "./array.js"
4
4
  import {SemantifoldDiagnostic, unsupportedRole} from "./diagnostic.js"
5
5
  import {generateJava} from "./backends/java.js"
6
+ import {generateKotlin} from "./backends/kotlin.js"
6
7
  import {generateCSharpProject} from "./backends/csharp.js"
7
8
  import {generateGoModule} from "./backends/go.js"
9
+ import {generateRustProject} from "./backends/rust.js"
10
+ import {generateSwift} from "./backends/swift.js"
11
+ import {generateDartPackage} from "./backends/dart.js"
8
12
  import {generateJavaScript} from "./backends/javascript.js"
9
13
  import {generatePhp} from "./backends/php.js"
10
14
  import {generatePython} from "./backends/python.js"
11
15
  import {generateRuby} from "./backends/ruby.js"
12
16
  import {generateTypeScript} from "./backends/typescript.js"
17
+ import {generateBrowserWasm} from "./backends/wasm.js"
18
+ import {generateIosApplication} from "./backends/ios.js"
13
19
  import {parseJava} from "./frontends/java.js"
20
+ import {parseKotlin} from "./frontends/kotlin.js"
14
21
  import {parseCSharp} from "./frontends/csharp.js"
15
22
  import {parseGo} from "./frontends/go.js"
23
+ import {parseRust} from "./frontends/rust.js"
24
+ import {parseSwift} from "./frontends/swift.js"
25
+ import {parseDart} from "./frontends/dart.js"
16
26
  import {parseCpp} from "./frontends/cpp.js"
17
27
  import {generateCpp} from "./backends/cpp.js"
18
28
  import {parseC} from "./frontends/c.js"
@@ -27,22 +37,37 @@ const acceptanceStageOrder = ["parse", "generate", "restore", "compile", "link",
27
37
  const acceptanceStages = new Map(acceptanceStageOrder.map((stage, index) => [stage, index]))
28
38
  const registryKeys = new Set([
29
39
  "acceptance", "applicationBackend", "artifactMultiplicity", "binaryBackend", "defaultFilename", "frontend", "id",
30
- "interoperability", "mapping", "mediaType", "roundTrip", "textBackend"
40
+ "features", "interoperability", "mapping", "mediaType", "provider", "roundTrip", "textBackend"
31
41
  ])
32
42
 
33
43
  /** @typedef {"frontend" | "textBackend" | "binaryBackend" | "applicationBackend" | "interoperability"} RegistryRole */
34
- /** @typedef {(input: {filename: string, source: string}) => import("./semantic/types.js").SemanticModule} Frontend */
35
44
  /** @typedef {(...values: unknown[]) => unknown} RegistryImplementation */
36
45
 
46
+ /**
47
+ * @typedef FrontendInput
48
+ * @property {readonly import("./semantic/types.js").EffectCapabilityDeclaration[]} [capabilities] - Compiler-authorized declarations.
49
+ * @property {string} filename - Source filename.
50
+ * @property {string} source - Source text.
51
+ * @property {{isEntry: boolean, functions: Map<string, import("./semantic/types.js").FunctionDeclaration>, records: Map<string, import("./semantic/types.js").RecordDeclaration>, errors?: Map<string, import("./semantic/types.js").ErrorDeclaration>, valueRecords?: Map<string, import("./semantic/types.js").RecordDeclaration>}} [program] - Program conversion context.
52
+ */
53
+
54
+ /**
55
+ * @callback Frontend
56
+ * @param {FrontendInput} input - Frontend request.
57
+ * @returns {import("./semantic/types.js").SemanticModule} Semantic module.
58
+ */
59
+
37
60
  /**
38
61
  * @typedef LanguageRegistryRecord
39
62
  * @property {string} id - Stable identity.
40
63
  * @property {{stages: import("./semantic/types.js").AcceptanceStage[], toolchains: string[]}} acceptance - Acceptance declaration.
41
64
  * @property {"single" | "multiple"} artifactMultiplicity - Artifact multiplicity.
65
+ * @property {import("./semantic/types.js").LanguageFeatureCapabilities} features - Semantic feature capabilities.
42
66
  * @property {import("./semantic/types.js").LanguageMappingCapabilities} mapping - Mapping capabilities.
43
67
  * @property {boolean} roundTrip - Round-trip declaration.
44
68
  * @property {string} [defaultFilename] - Default backend filename.
45
69
  * @property {string} [mediaType] - Default backend media type.
70
+ * @property {boolean} [provider] - Target host stdlib provider/native-binding role.
46
71
  * @property {RegistryImplementation} [frontend] - Frontend adapter.
47
72
  * @property {RegistryImplementation} [textBackend] - Text backend.
48
73
  * @property {RegistryImplementation} [binaryBackend] - Binary backend.
@@ -82,6 +107,9 @@ export function createLanguageRegistry(candidateRecords) {
82
107
  }
83
108
  if (recordsById.has(id)) invalidRegistry(`Duplicate registry ID '${id}'.`, id)
84
109
  if (Object.keys(candidate).some((key) => !registryKeys.has(key))) invalidRegistry(`Registry record '${id}' has unknown fields.`, id)
110
+ if (candidate.provider !== undefined && typeof candidate.provider != "boolean") {
111
+ invalidRegistry(`Registry record '${id}' declares an invalid provider role.`, id)
112
+ }
85
113
 
86
114
  for (const role of registryRoles) {
87
115
  if (candidate[role] !== undefined && typeof candidate[role] != "function") {
@@ -94,6 +122,48 @@ export function createLanguageRegistry(candidateRecords) {
94
122
  invalidRegistry(`Registry record '${id}' has an invalid artifact multiplicity.`, id)
95
123
  }
96
124
  if (typeof candidate.roundTrip != "boolean") invalidRegistry(`Registry record '${id}' requires a Boolean round-trip declaration.`, id)
125
+ const featuresCandidate = candidate.features ?? {
126
+ closedRecords: false,
127
+ conditionControlledLoops: false,
128
+ effectfulCapabilitiesAndResources: false,
129
+ generalFunctionsAndCalls: false,
130
+ immutableCollections: false,
131
+ optionalValues: false,
132
+ orderedListIteration: false,
133
+ orderedMapIteration: false,
134
+ referenceClasses: false,
135
+ typedErrors: false,
136
+ typeParametersAndGenerics: false
137
+ }
138
+
139
+ if (!isPlainObject(featuresCandidate) ||
140
+ Object.keys(featuresCandidate).sort().join(",") != "closedRecords,conditionControlledLoops,effectfulCapabilitiesAndResources,generalFunctionsAndCalls,immutableCollections,optionalValues,orderedListIteration,orderedMapIteration,referenceClasses,typeParametersAndGenerics,typedErrors" ||
141
+ typeof featuresCandidate.closedRecords != "boolean" ||
142
+ typeof featuresCandidate.conditionControlledLoops != "boolean" ||
143
+ typeof featuresCandidate.effectfulCapabilitiesAndResources != "boolean" ||
144
+ typeof featuresCandidate.generalFunctionsAndCalls != "boolean" ||
145
+ typeof featuresCandidate.immutableCollections != "boolean" ||
146
+ typeof featuresCandidate.optionalValues != "boolean" ||
147
+ typeof featuresCandidate.orderedListIteration != "boolean" ||
148
+ typeof featuresCandidate.orderedMapIteration != "boolean" ||
149
+ typeof featuresCandidate.referenceClasses != "boolean" ||
150
+ typeof featuresCandidate.typedErrors != "boolean" ||
151
+ typeof featuresCandidate.typeParametersAndGenerics != "boolean") {
152
+ invalidRegistry(`Registry record '${id}' has an invalid feature declaration.`, id)
153
+ }
154
+ const features = deepFreeze(/** @type {import("./semantic/types.js").LanguageFeatureCapabilities} */ ({
155
+ closedRecords: featuresCandidate.closedRecords,
156
+ conditionControlledLoops: featuresCandidate.conditionControlledLoops,
157
+ effectfulCapabilitiesAndResources: featuresCandidate.effectfulCapabilitiesAndResources,
158
+ generalFunctionsAndCalls: featuresCandidate.generalFunctionsAndCalls,
159
+ immutableCollections: featuresCandidate.immutableCollections,
160
+ optionalValues: featuresCandidate.optionalValues,
161
+ orderedListIteration: featuresCandidate.orderedListIteration,
162
+ orderedMapIteration: featuresCandidate.orderedMapIteration,
163
+ referenceClasses: featuresCandidate.referenceClasses,
164
+ typedErrors: featuresCandidate.typedErrors,
165
+ typeParametersAndGenerics: featuresCandidate.typeParametersAndGenerics
166
+ }))
97
167
  const mappingCandidate = candidate.mapping
98
168
 
99
169
  if (!isPlainObject(mappingCandidate)) invalidRegistry(`Registry record '${id}' has an invalid mapping declaration.`, id)
@@ -151,7 +221,7 @@ export function createLanguageRegistry(candidateRecords) {
151
221
  const hasApplicationBackend = typeof candidate.applicationBackend == "function"
152
222
  const hasBackend = hasTextBackend || hasBinaryBackend || hasApplicationBackend
153
223
 
154
- if ((mapping.richText || mapping.sourceMapV3) && !hasTextBackend ||
224
+ if ((mapping.richText || mapping.sourceMapV3 || mapping.binaryRanges) && !hasBackend ||
155
225
  mapping.sourceMapV3 && !mapping.richText ||
156
226
  mapping.binaryRanges && !hasBinaryBackend && !hasApplicationBackend) {
157
227
  invalidRegistry(`Registry record '${id}' declares mapping support without its required backend role.`, id)
@@ -163,11 +233,13 @@ export function createLanguageRegistry(candidateRecords) {
163
233
  invalidRegistry(`Registry record '${id}' declares an acceptance stage without its required role.`, id)
164
234
  }
165
235
 
166
- if ((hasBackend || candidate.defaultFilename !== undefined) &&
236
+ const hasDefaultedBackend = hasTextBackend || hasBinaryBackend
237
+
238
+ if ((hasDefaultedBackend || candidate.defaultFilename !== undefined) &&
167
239
  (typeof candidate.defaultFilename != "string" || candidate.defaultFilename.length == 0)) {
168
240
  invalidRegistry(`Registry backend '${id}' requires a default filename.`, id)
169
241
  }
170
- if ((hasBackend || candidate.mediaType !== undefined) &&
242
+ if ((hasDefaultedBackend || candidate.mediaType !== undefined) &&
171
243
  (typeof candidate.mediaType != "string" || candidate.mediaType.length == 0)) {
172
244
  invalidRegistry(`Registry backend '${id}' requires a media type.`, id)
173
245
  }
@@ -179,11 +251,13 @@ export function createLanguageRegistry(candidateRecords) {
179
251
  const record = deepFreeze(/** @type {LanguageRegistryRecord} */ ({
180
252
  acceptance,
181
253
  artifactMultiplicity,
254
+ features,
182
255
  id,
183
256
  mapping,
184
257
  roundTrip: candidate.roundTrip,
185
258
  ...(typeof candidate.defaultFilename == "string" ? {defaultFilename: candidate.defaultFilename} : {}),
186
259
  ...(typeof candidate.mediaType == "string" ? {mediaType: candidate.mediaType} : {}),
260
+ ...(typeof candidate.provider == "boolean" ? {provider: candidate.provider} : {}),
187
261
  ...(typeof candidate.frontend == "function" ? {frontend: candidate.frontend} : {}),
188
262
  ...(typeof candidate.textBackend == "function" ? {textBackend: candidate.textBackend} : {}),
189
263
  ...(typeof candidate.binaryBackend == "function" ? {binaryBackend: candidate.binaryBackend} : {}),
@@ -193,6 +267,7 @@ export function createLanguageRegistry(candidateRecords) {
193
267
  const descriptor = deepFreeze(/** @type {import("./semantic/types.js").LanguageCapabilities} */ ({
194
268
  acceptance,
195
269
  artifactMultiplicity,
270
+ features,
196
271
  id,
197
272
  mapping,
198
273
  roles: {
@@ -200,6 +275,7 @@ export function createLanguageRegistry(candidateRecords) {
200
275
  binaryBackend: typeof candidate.binaryBackend == "function",
201
276
  frontend: typeof candidate.frontend == "function",
202
277
  interoperability: typeof candidate.interoperability == "function",
278
+ provider: candidate.provider === true,
203
279
  textBackend: typeof candidate.textBackend == "function"
204
280
  },
205
281
  roundTrip: candidate.roundTrip
@@ -240,31 +316,37 @@ export function createLanguageRegistry(candidateRecords) {
240
316
  * PHP registry frontend wrapper.
241
317
  * @type {Frontend}
242
318
  */
243
- const phpFrontend = ({filename, source}) => parsePhp({filename, source})
319
+ const phpFrontend = ({capabilities, filename, program, source}) => parsePhp({capabilities, filename, program, source})
244
320
 
245
321
  /**
246
322
  * Ruby registry frontend wrapper.
247
323
  * @type {Frontend}
248
324
  */
249
- const rubyFrontend = ({filename, source}) => parseRuby({filename, source})
325
+ const rubyFrontend = ({capabilities, filename, program, source}) => parseRuby({capabilities, filename, program, source})
250
326
 
251
327
  /**
252
328
  * JavaScript registry frontend wrapper.
253
329
  * @type {Frontend}
254
330
  */
255
- const javaScriptFrontend = ({filename, source}) => parseJavaScriptTypeScript({filename, language: "javascript", source})
331
+ const javaScriptFrontend = ({capabilities, filename, program, source}) => parseJavaScriptTypeScript({capabilities, filename, language: "javascript", program, source})
256
332
 
257
333
  /**
258
334
  * TypeScript registry frontend wrapper.
259
335
  * @type {Frontend}
260
336
  */
261
- const typeScriptFrontend = ({filename, source}) => parseJavaScriptTypeScript({filename, language: "typescript", source})
337
+ const typeScriptFrontend = ({capabilities, filename, program, source}) => parseJavaScriptTypeScript({capabilities, filename, language: "typescript", program, source})
262
338
 
263
339
  /**
264
340
  * Java registry frontend wrapper.
265
341
  * @type {Frontend}
266
342
  */
267
- const javaFrontend = ({filename, source}) => parseJava({filename, source})
343
+ const javaFrontend = ({capabilities, filename, program, source}) => parseJava({capabilities, filename, program, source})
344
+
345
+ /**
346
+ * Kotlin registry frontend wrapper.
347
+ * @type {Frontend}
348
+ */
349
+ const kotlinFrontend = ({filename, source}) => parseKotlin({filename, source})
268
350
 
269
351
  /**
270
352
  * Python registry frontend wrapper.
@@ -284,9 +366,15 @@ const csharpFrontend = ({filename, source}) => parseCSharp({filename, source})
284
366
  */
285
367
  const goFrontend = ({filename, source}) => parseGo({filename, source})
286
368
 
369
+ /**
370
+ * Dart registry frontend wrapper.
371
+ * @type {Frontend}
372
+ */
373
+ const dartFrontend = ({filename, source}) => parseDart({filename, source})
374
+
287
375
  const records = [
288
376
  language({
289
- acceptance: {stages: ["parse", "generate", "execute"], toolchains: ["php"]},
377
+ acceptance: {stages: ["parse", "generate", "execute"], toolchains: ["php82"]},
290
378
  defaultFilename: "program.php",
291
379
  frontend: phpFrontend,
292
380
  id: "php",
@@ -325,6 +413,14 @@ const records = [
325
413
  mediaType: "text/x-java-source",
326
414
  textBackend: generateJava
327
415
  }),
416
+ language({
417
+ acceptance: {stages: ["parse", "generate", "compile", "execute"], toolchains: ["kotlinc", "java25"]},
418
+ defaultFilename: "Program.kt",
419
+ frontend: kotlinFrontend,
420
+ id: "kotlin",
421
+ mediaType: "text/x-kotlin",
422
+ textBackend: generateKotlin
423
+ }),
328
424
  language({
329
425
  acceptance: {stages: ["parse", "generate", "compile", "execute"], toolchains: ["python"]},
330
426
  defaultFilename: "program.py",
@@ -363,7 +459,57 @@ const records = [
363
459
  language({
364
460
  acceptance: {stages: ["parse", "generate", "compile", "link", "execute"], toolchains: ["clangpp"]},
365
461
  defaultFilename: "program.cpp", frontend: parseCpp, id: "cpp", mediaType: "text/x-c++src", textBackend: generateCpp
366
- })
462
+ }),
463
+ language({
464
+ acceptance: {stages: ["parse", "generate", "compile", "validate", "execute"], toolchains: ["rustc", "cargo"]},
465
+ artifactMultiplicity: "multiple",
466
+ defaultFilename: "src/main.rs", frontend: parseRust, id: "rust", mediaType: "text/x-rust", textBackend: generateRustProject
467
+ }),
468
+ language({acceptance: {stages: ["parse", "generate", "compile", "execute"], toolchains: ["swiftc"]},
469
+ defaultFilename: "program.swift", frontend: parseSwift, id: "swift", mediaType: "text/x-swift", textBackend: generateSwift}),
470
+ language({
471
+ acceptance: {stages: ["parse", "generate", "restore", "compile", "validate", "execute"], toolchains: ["dart"]},
472
+ artifactMultiplicity: "multiple",
473
+ defaultFilename: "bin/program.dart",
474
+ features: {
475
+ closedRecords: false,
476
+ conditionControlledLoops: false,
477
+ effectfulCapabilitiesAndResources: false,
478
+ generalFunctionsAndCalls: true,
479
+ immutableCollections: false,
480
+ optionalValues: false,
481
+ orderedListIteration: false,
482
+ orderedMapIteration: false,
483
+ referenceClasses: false,
484
+ typedErrors: false,
485
+ typeParametersAndGenerics: false
486
+ },
487
+ frontend: dartFrontend,
488
+ id: "dart",
489
+ mediaType: "text/x-dart",
490
+ textBackend: generateDartPackage
491
+ }),
492
+ {
493
+ acceptance: {stages: ["generate", "validate", "instantiate", "execute"], toolchains: ["wasm-validate", "node", "chromium"]},
494
+ applicationBackend: generateBrowserWasm,
495
+ artifactMultiplicity: "multiple",
496
+ binaryBackend: generateBrowserWasm,
497
+ defaultFilename: "program.wasm",
498
+ features: {closedRecords: false, conditionControlledLoops: false, effectfulCapabilitiesAndResources: false, generalFunctionsAndCalls: false, immutableCollections: false, optionalValues: false, orderedListIteration: false, orderedMapIteration: false, referenceClasses: false, typedErrors: false, typeParametersAndGenerics: false},
499
+ id: "wasm",
500
+ mapping: {binaryRanges: true, richText: true, sourceMapV3: true},
501
+ mediaType: "application/wasm",
502
+ roundTrip: false
503
+ },
504
+ {
505
+ acceptance: {stages: ["generate"], toolchains: []},
506
+ applicationBackend: generateIosApplication,
507
+ artifactMultiplicity: "multiple",
508
+ features: {closedRecords: false, conditionControlledLoops: false, effectfulCapabilitiesAndResources: false, generalFunctionsAndCalls: false, immutableCollections: false, optionalValues: false, orderedListIteration: false, orderedMapIteration: false, referenceClasses: false, typedErrors: false, typeParametersAndGenerics: false},
509
+ id: "ios",
510
+ mapping: {binaryRanges: true, richText: true, sourceMapV3: true},
511
+ roundTrip: false
512
+ }
367
513
  ]
368
514
 
369
515
  export const languageRegistry = createLanguageRegistry(records)
@@ -381,7 +527,21 @@ export const supportedLanguages = Object.freeze(languageCapabilities
381
527
  function language(values) {
382
528
  return {
383
529
  artifactMultiplicity: "single",
530
+ features: {
531
+ closedRecords: ["php", "ruby", "javascript", "typescript", "java"].includes(String(values.id)),
532
+ conditionControlledLoops: ["php", "ruby", "javascript", "typescript", "java"].includes(String(values.id)),
533
+ effectfulCapabilitiesAndResources: ["php", "ruby", "javascript", "typescript", "java"].includes(String(values.id)),
534
+ generalFunctionsAndCalls: ["php", "ruby", "javascript", "typescript", "java"].includes(String(values.id)),
535
+ immutableCollections: ["php", "ruby", "javascript", "typescript", "java"].includes(String(values.id)),
536
+ optionalValues: ["php", "ruby", "javascript", "typescript", "java"].includes(String(values.id)),
537
+ orderedListIteration: ["php", "ruby", "javascript", "typescript", "java"].includes(String(values.id)),
538
+ orderedMapIteration: ["php", "ruby", "javascript", "typescript", "java"].includes(String(values.id)),
539
+ referenceClasses: ["php", "ruby", "javascript", "typescript", "java"].includes(String(values.id)),
540
+ typedErrors: ["php", "ruby", "javascript", "typescript", "java"].includes(String(values.id)),
541
+ typeParametersAndGenerics: ["php", "ruby", "javascript", "typescript", "java"].includes(String(values.id))
542
+ },
384
543
  mapping: {binaryRanges: false, richText: true, sourceMapV3: true},
544
+ provider: ["php", "ruby", "javascript", "typescript", "java"].includes(String(values.id)),
385
545
  roundTrip: true,
386
546
  ...values
387
547
  }
package/src/mapping.js CHANGED
@@ -514,7 +514,7 @@ export function composeSourceMaps(outer, inner) {
514
514
  * @param {object} generated - Generated program.
515
515
  * @param {string} generated.content - Exact generated content.
516
516
  * @param {string} generated.filename - Generated filename.
517
- * @param {import("./semantic/types.js").SemanticLanguage} generated.language - Generated language.
517
+ * @param {import("./semantic/types.js").GeneratedTextLanguage} generated.language - Generated text language.
518
518
  * @param {{filename: string, content: string, language?: import("./semantic/types.js").SemanticLanguage}[]} [generated.sources] - Exact source content overrides.
519
519
  * @returns {import("./semantic/types.js").SemantifoldMapping} Imported rich map.
520
520
  */
@@ -712,7 +712,7 @@ export function validateMapping(value) {
712
712
  const spans = mapping.spans
713
713
 
714
714
  if (!generated || typeof generated != "object" || typeof Reflect.get(generated, "filename") != "string" ||
715
- typeof Reflect.get(generated, "content") != "string" || !isLanguage(Reflect.get(generated, "language")) ||
715
+ typeof Reflect.get(generated, "content") != "string" || !isGeneratedLanguage(Reflect.get(generated, "language")) ||
716
716
  !Array.isArray(mapping.sources) ||
717
717
  !Array.isArray(mapping.nodes) || !Array.isArray(mapping.symbols) || !Array.isArray(spans)) {
718
718
  throw new TypeError("Malformed SemantifoldMapping v1 envelope.")
@@ -728,7 +728,7 @@ export function validateMapping(value) {
728
728
  for (const source of mapping.sources) {
729
729
  if (!source || typeof source != "object" || typeof source.id != "string" || source.id.length == 0 || sourceIds.has(source.id) ||
730
730
  typeof source.filename != "string" || source.filename.length == 0 || source.content !== null && typeof source.content != "string" ||
731
- source.language !== null && !isLanguage(source.language)) {
731
+ source.language !== null && !isSemanticLanguage(source.language)) {
732
732
  throw new TypeError("Malformed or duplicate SemantifoldMapping source.")
733
733
  }
734
734
  sourceIds.add(source.id)
@@ -763,8 +763,23 @@ export function validateMapping(value) {
763
763
 
764
764
  for (const symbol of mapping.symbols) {
765
765
  if (!symbol || typeof symbol != "object" || typeof symbol.id != "string" || symbol.id.length == 0 || symbolIds.has(symbol.id) ||
766
- typeof symbol.name != "string" || symbol.name.length == 0 || !["function", "parameter", "local"].includes(symbol.kind) ||
767
- !nodeIds.has(symbol.declarationNodeId) || !Array.isArray(symbol.references)) {
766
+ typeof symbol.name != "string" || symbol.name.length == 0 ||
767
+ !["capability", "resource", "failure", "operation", "record", "class", "error", "field", "constructor", "method", "function", "typeParameter", "parameter", "local", "iteration", "catch"].includes(symbol.kind) ||
768
+ !nodeIds.has(symbol.declarationNodeId) || !Array.isArray(symbol.references) ||
769
+ symbol.semanticDeclarationId !== undefined && (typeof symbol.semanticDeclarationId != "string" || !(
770
+ symbol.kind == "function" && /^(?:[a-z][a-z0-9._-]*#)?function:[0-9]+$/u.test(symbol.semanticDeclarationId) ||
771
+ symbol.kind == "record" && /^(?:[a-z][a-z0-9._-]*#)?record:[0-9]+$/u.test(symbol.semanticDeclarationId) ||
772
+ symbol.kind == "class" && /^(?:[a-z][a-z0-9._-]*#)?class:[0-9]+$/u.test(symbol.semanticDeclarationId) ||
773
+ symbol.kind == "error" && /^(?:[a-z][a-z0-9._-]*#)?error:[0-9]+$/u.test(symbol.semanticDeclarationId) ||
774
+ symbol.kind == "field" && /^(?:[a-z][a-z0-9._-]*#)?(?:record|class):[0-9]+:field:[0-9]+$/u.test(symbol.semanticDeclarationId) ||
775
+ symbol.kind == "constructor" && /^(?:[a-z][a-z0-9._-]*#)?class:[0-9]+:constructor$/u.test(symbol.semanticDeclarationId) ||
776
+ symbol.kind == "method" && /^(?:[a-z][a-z0-9._-]*#)?class:[0-9]+:method:[0-9]+$/u.test(symbol.semanticDeclarationId) ||
777
+ symbol.kind == "typeParameter" && /^(?:[a-z][a-z0-9._-]*#)?(?:function|record):[0-9]+:type:[0-9]+$/u.test(symbol.semanticDeclarationId) ||
778
+ symbol.kind == "capability" && /^(?:module:[0-9]+\/)?capability:[0-9]+$/u.test(symbol.semanticDeclarationId) ||
779
+ symbol.kind == "resource" && /^(?:module:[0-9]+\/)?capability:[0-9]+\/resource:[0-9]+$/u.test(symbol.semanticDeclarationId) ||
780
+ symbol.kind == "failure" && /^(?:module:[0-9]+\/)?capability:[0-9]+\/failure:[0-9]+$/u.test(symbol.semanticDeclarationId) ||
781
+ symbol.kind == "operation" && /^(?:module:[0-9]+\/)?capability:[0-9]+\/operation:[0-9]+$/u.test(symbol.semanticDeclarationId)
782
+ ))) {
768
783
  throw new TypeError("Malformed or duplicate semantic symbol identity.")
769
784
  }
770
785
  symbolIds.add(symbol.id)
@@ -785,7 +800,7 @@ export function validateMapping(value) {
785
800
  validateLocationForSources(symbol.location, sourcesByFilename, sourceCoordinates)
786
801
  for (const reference of symbol.references) {
787
802
  if (!reference || typeof reference != "object" || !nodeIds.has(reference.nodeId) ||
788
- !["declaration", "read", "write", "call"].includes(reference.role)) {
803
+ !["declaration", "type", "construct", "member", "read", "write", "call"].includes(reference.role)) {
789
804
  throw new TypeError("Malformed semantic symbol reference.")
790
805
  }
791
806
  validateLocationForSources(reference.location, sourcesByFilename, sourceCoordinates)
@@ -1099,13 +1114,22 @@ function validPoint(value) {
1099
1114
  }
1100
1115
 
1101
1116
  /**
1102
- * Tests a supported semantic language value.
1117
+ * Tests a supported semantic source-language value.
1103
1118
  * @param {unknown} value - Candidate language.
1104
1119
  * @returns {value is import("./semantic/types.js").SemanticLanguage} Whether supported.
1105
1120
  */
1106
- function isLanguage(value) {
1121
+ function isSemanticLanguage(value) {
1107
1122
  return value == "php" || value == "ruby" || value == "javascript" || value == "typescript" || value == "java" ||
1108
- value == "python" || value == "csharp" || value == "go" || value == "c" || value == "cpp"
1123
+ value == "kotlin" || value == "python" || value == "csharp" || value == "go" || value == "c" || value == "cpp" || value == "rust" || value == "swift" || value == "dart"
1124
+ }
1125
+
1126
+ /**
1127
+ * Tests a supported generated text language value.
1128
+ * @param {unknown} value - Candidate language.
1129
+ * @returns {value is import("./semantic/types.js").GeneratedTextLanguage} Whether supported.
1130
+ */
1131
+ function isGeneratedLanguage(value) {
1132
+ return value == "html" || isSemanticLanguage(value)
1109
1133
  }
1110
1134
 
1111
1135
  /**