semantifold 0.4.0 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +13 -7
- package/build/index.d.ts +12 -8
- package/build/index.d.ts.map +1 -1
- package/build/index.js +10 -7
- package/build/src/backends/android.d.ts +49 -0
- package/build/src/backends/android.d.ts.map +1 -0
- package/build/src/backends/android.js +1278 -0
- package/build/src/backends/identifiers.d.ts +6 -0
- package/build/src/backends/identifiers.d.ts.map +1 -1
- package/build/src/backends/identifiers.js +30 -1
- package/build/src/backends/ios.js +2 -2
- package/build/src/backends/kotlin.d.ts +10 -0
- package/build/src/backends/kotlin.d.ts.map +1 -1
- package/build/src/backends/kotlin.js +11 -9
- package/build/src/backends/native-validation.d.ts +2 -2
- package/build/src/backends/native-validation.d.ts.map +1 -1
- package/build/src/backends/native-validation.js +2 -2
- package/build/src/backends/program.d.ts +6 -4
- package/build/src/backends/program.d.ts.map +1 -1
- package/build/src/backends/program.js +5 -4
- package/build/src/backends/scalars.d.ts.map +1 -1
- package/build/src/backends/scalars.js +2 -1
- package/build/src/backends/shared.d.ts.map +1 -1
- package/build/src/backends/shared.js +20 -4
- package/build/src/backends/writer.d.ts +21 -1
- package/build/src/backends/writer.d.ts.map +1 -1
- package/build/src/backends/writer.js +25 -2
- package/build/src/backends/zig-runtime.d.ts +5 -0
- package/build/src/backends/zig-runtime.d.ts.map +1 -0
- package/build/src/backends/zig-runtime.js +92 -0
- package/build/src/backends/zig-validation.d.ts +9 -0
- package/build/src/backends/zig-validation.d.ts.map +1 -0
- package/build/src/backends/zig-validation.js +73 -0
- package/build/src/backends/zig.d.ts +42 -0
- package/build/src/backends/zig.d.ts.map +1 -0
- package/build/src/backends/zig.js +584 -0
- package/build/src/frontends/scalars.d.ts.map +1 -1
- package/build/src/frontends/scalars.js +2 -1
- package/build/src/frontends/zig-parser.d.ts +31 -0
- package/build/src/frontends/zig-parser.d.ts.map +1 -0
- package/build/src/frontends/zig-parser.js +17 -0
- package/build/src/frontends/zig.d.ts +14 -0
- package/build/src/frontends/zig.d.ts.map +1 -0
- package/build/src/frontends/zig.js +970 -0
- package/build/src/language-registry.d.ts.map +1 -1
- package/build/src/language-registry.js +40 -1
- package/build/src/mapping.js +2 -2
- package/build/src/semantic/provenance.js +3 -3
- package/build/src/semantic/types.d.ts +184 -4
- package/build/src/semantic/types.d.ts.map +1 -1
- package/build/src/semantic/types.js +45 -3
- package/build/src/semantic/validate.js +2 -2
- package/build/src/toolchains.d.ts +6 -0
- package/build/src/toolchains.d.ts.map +1 -1
- package/build/src/toolchains.js +2 -1
- package/build/src/zig-bindings.d.ts +10 -0
- package/build/src/zig-bindings.d.ts.map +1 -0
- package/build/src/zig-bindings.js +54 -0
- package/docs/android.md +79 -0
- package/docs/architecture.md +13 -5
- package/docs/goals.md +1 -1
- package/docs/ios.md +1 -1
- package/docs/language-support.md +15 -4
- package/docs/parser-qualification.md +31 -1
- package/docs/source-maps.md +7 -3
- package/docs/specification.md +5 -0
- package/docs/testing.md +40 -3
- package/docs/zig.md +33 -0
- package/index.js +9 -6
- package/node_modules/semantifold-tree-sitter-zig-internal/LICENSE +15 -0
- package/node_modules/semantifold-tree-sitter-zig-internal/README.md +5 -0
- package/node_modules/semantifold-tree-sitter-zig-internal/node_modules/@tree-sitter-grammars/tree-sitter-zig/LICENSE +21 -0
- package/node_modules/semantifold-tree-sitter-zig-internal/node_modules/@tree-sitter-grammars/tree-sitter-zig/README.md +21 -0
- package/node_modules/semantifold-tree-sitter-zig-internal/node_modules/@tree-sitter-grammars/tree-sitter-zig/binding.gyp +29 -0
- package/node_modules/semantifold-tree-sitter-zig-internal/node_modules/@tree-sitter-grammars/tree-sitter-zig/bindings/node/binding.cc +20 -0
- package/node_modules/semantifold-tree-sitter-zig-internal/node_modules/@tree-sitter-grammars/tree-sitter-zig/bindings/node/binding_test.js +9 -0
- package/node_modules/semantifold-tree-sitter-zig-internal/node_modules/@tree-sitter-grammars/tree-sitter-zig/bindings/node/index.d.ts +28 -0
- package/node_modules/semantifold-tree-sitter-zig-internal/node_modules/@tree-sitter-grammars/tree-sitter-zig/bindings/node/index.js +11 -0
- package/node_modules/semantifold-tree-sitter-zig-internal/node_modules/@tree-sitter-grammars/tree-sitter-zig/grammar.js +900 -0
- package/node_modules/semantifold-tree-sitter-zig-internal/node_modules/@tree-sitter-grammars/tree-sitter-zig/package.json +57 -0
- package/node_modules/semantifold-tree-sitter-zig-internal/node_modules/@tree-sitter-grammars/tree-sitter-zig/prebuilds/darwin-arm64/@tree-sitter-grammars+tree-sitter-zig.node +0 -0
- package/node_modules/semantifold-tree-sitter-zig-internal/node_modules/@tree-sitter-grammars/tree-sitter-zig/prebuilds/darwin-x64/@tree-sitter-grammars+tree-sitter-zig.node +0 -0
- package/node_modules/semantifold-tree-sitter-zig-internal/node_modules/@tree-sitter-grammars/tree-sitter-zig/prebuilds/linux-arm64/@tree-sitter-grammars+tree-sitter-zig.node +0 -0
- package/node_modules/semantifold-tree-sitter-zig-internal/node_modules/@tree-sitter-grammars/tree-sitter-zig/prebuilds/linux-x64/@tree-sitter-grammars+tree-sitter-zig.node +0 -0
- package/node_modules/semantifold-tree-sitter-zig-internal/node_modules/@tree-sitter-grammars/tree-sitter-zig/prebuilds/win32-arm64/@tree-sitter-grammars+tree-sitter-zig.node +0 -0
- package/node_modules/semantifold-tree-sitter-zig-internal/node_modules/@tree-sitter-grammars/tree-sitter-zig/prebuilds/win32-x64/@tree-sitter-grammars+tree-sitter-zig.node +0 -0
- package/node_modules/semantifold-tree-sitter-zig-internal/node_modules/@tree-sitter-grammars/tree-sitter-zig/queries/folds.scm +23 -0
- package/node_modules/semantifold-tree-sitter-zig-internal/node_modules/@tree-sitter-grammars/tree-sitter-zig/queries/highlights.scm +291 -0
- package/node_modules/semantifold-tree-sitter-zig-internal/node_modules/@tree-sitter-grammars/tree-sitter-zig/queries/indents.scm +22 -0
- package/node_modules/semantifold-tree-sitter-zig-internal/node_modules/@tree-sitter-grammars/tree-sitter-zig/queries/injections.scm +10 -0
- package/node_modules/semantifold-tree-sitter-zig-internal/node_modules/@tree-sitter-grammars/tree-sitter-zig/src/grammar.json +6570 -0
- package/node_modules/semantifold-tree-sitter-zig-internal/node_modules/@tree-sitter-grammars/tree-sitter-zig/src/node-types.json +3178 -0
- package/node_modules/semantifold-tree-sitter-zig-internal/node_modules/@tree-sitter-grammars/tree-sitter-zig/src/parser.c +169829 -0
- package/node_modules/semantifold-tree-sitter-zig-internal/node_modules/@tree-sitter-grammars/tree-sitter-zig/src/tree_sitter/alloc.h +54 -0
- package/node_modules/semantifold-tree-sitter-zig-internal/node_modules/@tree-sitter-grammars/tree-sitter-zig/src/tree_sitter/array.h +291 -0
- package/node_modules/semantifold-tree-sitter-zig-internal/node_modules/@tree-sitter-grammars/tree-sitter-zig/src/tree_sitter/parser.h +266 -0
- package/node_modules/semantifold-tree-sitter-zig-internal/node_modules/@tree-sitter-grammars/tree-sitter-zig/tree-sitter-zig.wasm +0 -0
- package/node_modules/semantifold-tree-sitter-zig-internal/node_modules/@tree-sitter-grammars/tree-sitter-zig/tree-sitter.json +38 -0
- package/node_modules/semantifold-tree-sitter-zig-internal/node_modules/tree-sitter/LICENSE +21 -0
- package/node_modules/semantifold-tree-sitter-zig-internal/node_modules/tree-sitter/README.md +128 -0
- package/node_modules/semantifold-tree-sitter-zig-internal/node_modules/tree-sitter/binding.gyp +80 -0
- package/node_modules/semantifold-tree-sitter-zig-internal/node_modules/tree-sitter/index.js +916 -0
- package/node_modules/semantifold-tree-sitter-zig-internal/node_modules/tree-sitter/package.json +76 -0
- package/node_modules/semantifold-tree-sitter-zig-internal/node_modules/tree-sitter/prebuilds/darwin-arm64/tree-sitter.node +0 -0
- package/node_modules/semantifold-tree-sitter-zig-internal/node_modules/tree-sitter/prebuilds/darwin-x64/tree-sitter.node +0 -0
- package/node_modules/semantifold-tree-sitter-zig-internal/node_modules/tree-sitter/prebuilds/linux-arm64/tree-sitter.node +0 -0
- package/node_modules/semantifold-tree-sitter-zig-internal/node_modules/tree-sitter/prebuilds/linux-x64/tree-sitter.node +0 -0
- package/node_modules/semantifold-tree-sitter-zig-internal/node_modules/tree-sitter/prebuilds/win32-arm64/tree-sitter.node +0 -0
- package/node_modules/semantifold-tree-sitter-zig-internal/node_modules/tree-sitter/prebuilds/win32-x64/tree-sitter.node +0 -0
- package/node_modules/semantifold-tree-sitter-zig-internal/node_modules/tree-sitter/src/addon_data.h +47 -0
- package/node_modules/semantifold-tree-sitter-zig-internal/node_modules/tree-sitter/src/binding.cc +35 -0
- package/node_modules/semantifold-tree-sitter-zig-internal/node_modules/tree-sitter/src/conversions.cc +140 -0
- package/node_modules/semantifold-tree-sitter-zig-internal/node_modules/tree-sitter/src/conversions.h +22 -0
- package/node_modules/semantifold-tree-sitter-zig-internal/node_modules/tree-sitter/src/language.cc +106 -0
- package/node_modules/semantifold-tree-sitter-zig-internal/node_modules/tree-sitter/src/language.h +17 -0
- package/node_modules/semantifold-tree-sitter-zig-internal/node_modules/tree-sitter/src/logger.cc +70 -0
- package/node_modules/semantifold-tree-sitter-zig-internal/node_modules/tree-sitter/src/logger.h +19 -0
- package/node_modules/semantifold-tree-sitter-zig-internal/node_modules/tree-sitter/src/lookaheaditerator.cc +122 -0
- package/node_modules/semantifold-tree-sitter-zig-internal/node_modules/tree-sitter/src/lookaheaditerator.h +33 -0
- package/node_modules/semantifold-tree-sitter-zig-internal/node_modules/tree-sitter/src/node.cc +1088 -0
- package/node_modules/semantifold-tree-sitter-zig-internal/node_modules/tree-sitter/src/node.h +30 -0
- package/node_modules/semantifold-tree-sitter-zig-internal/node_modules/tree-sitter/src/parser.cc +306 -0
- package/node_modules/semantifold-tree-sitter-zig-internal/node_modules/tree-sitter/src/parser.h +35 -0
- package/node_modules/semantifold-tree-sitter-zig-internal/node_modules/tree-sitter/src/query.cc +397 -0
- package/node_modules/semantifold-tree-sitter-zig-internal/node_modules/tree-sitter/src/query.h +40 -0
- package/node_modules/semantifold-tree-sitter-zig-internal/node_modules/tree-sitter/src/tree.cc +316 -0
- package/node_modules/semantifold-tree-sitter-zig-internal/node_modules/tree-sitter/src/tree.h +45 -0
- package/node_modules/semantifold-tree-sitter-zig-internal/node_modules/tree-sitter/src/tree_cursor.cc +213 -0
- package/node_modules/semantifold-tree-sitter-zig-internal/node_modules/tree-sitter/src/tree_cursor.h +52 -0
- package/node_modules/semantifold-tree-sitter-zig-internal/node_modules/tree-sitter/tree-sitter.d.ts +1042 -0
- package/node_modules/semantifold-tree-sitter-zig-internal/node_modules/tree-sitter/vendor/tree-sitter/lib/include/tree_sitter/api.h +1318 -0
- package/node_modules/semantifold-tree-sitter-zig-internal/node_modules/tree-sitter/vendor/tree-sitter/lib/src/alloc.c +48 -0
- package/node_modules/semantifold-tree-sitter-zig-internal/node_modules/tree-sitter/vendor/tree-sitter/lib/src/alloc.h +41 -0
- package/node_modules/semantifold-tree-sitter-zig-internal/node_modules/tree-sitter/vendor/tree-sitter/lib/src/array.h +291 -0
- package/node_modules/semantifold-tree-sitter-zig-internal/node_modules/tree-sitter/vendor/tree-sitter/lib/src/atomic.h +68 -0
- package/node_modules/semantifold-tree-sitter-zig-internal/node_modules/tree-sitter/vendor/tree-sitter/lib/src/clock.h +146 -0
- package/node_modules/semantifold-tree-sitter-zig-internal/node_modules/tree-sitter/vendor/tree-sitter/lib/src/error_costs.h +11 -0
- package/node_modules/semantifold-tree-sitter-zig-internal/node_modules/tree-sitter/vendor/tree-sitter/lib/src/get_changed_ranges.c +501 -0
- package/node_modules/semantifold-tree-sitter-zig-internal/node_modules/tree-sitter/vendor/tree-sitter/lib/src/get_changed_ranges.h +36 -0
- package/node_modules/semantifold-tree-sitter-zig-internal/node_modules/tree-sitter/vendor/tree-sitter/lib/src/host.h +21 -0
- package/node_modules/semantifold-tree-sitter-zig-internal/node_modules/tree-sitter/vendor/tree-sitter/lib/src/language.c +223 -0
- package/node_modules/semantifold-tree-sitter-zig-internal/node_modules/tree-sitter/vendor/tree-sitter/lib/src/language.h +297 -0
- package/node_modules/semantifold-tree-sitter-zig-internal/node_modules/tree-sitter/vendor/tree-sitter/lib/src/length.h +52 -0
- package/node_modules/semantifold-tree-sitter-zig-internal/node_modules/tree-sitter/vendor/tree-sitter/lib/src/lexer.c +435 -0
- package/node_modules/semantifold-tree-sitter-zig-internal/node_modules/tree-sitter/vendor/tree-sitter/lib/src/lexer.h +49 -0
- package/node_modules/semantifold-tree-sitter-zig-internal/node_modules/tree-sitter/vendor/tree-sitter/lib/src/lib.c +12 -0
- package/node_modules/semantifold-tree-sitter-zig-internal/node_modules/tree-sitter/vendor/tree-sitter/lib/src/node.c +920 -0
- package/node_modules/semantifold-tree-sitter-zig-internal/node_modules/tree-sitter/vendor/tree-sitter/lib/src/parser.c +2165 -0
- package/node_modules/semantifold-tree-sitter-zig-internal/node_modules/tree-sitter/vendor/tree-sitter/lib/src/parser.h +266 -0
- package/node_modules/semantifold-tree-sitter-zig-internal/node_modules/tree-sitter/vendor/tree-sitter/lib/src/point.h +62 -0
- package/node_modules/semantifold-tree-sitter-zig-internal/node_modules/tree-sitter/vendor/tree-sitter/lib/src/portable/endian.h +206 -0
- package/node_modules/semantifold-tree-sitter-zig-internal/node_modules/tree-sitter/vendor/tree-sitter/lib/src/query.c +4187 -0
- package/node_modules/semantifold-tree-sitter-zig-internal/node_modules/tree-sitter/vendor/tree-sitter/lib/src/reduce_action.h +34 -0
- package/node_modules/semantifold-tree-sitter-zig-internal/node_modules/tree-sitter/vendor/tree-sitter/lib/src/reusable_node.h +95 -0
- package/node_modules/semantifold-tree-sitter-zig-internal/node_modules/tree-sitter/vendor/tree-sitter/lib/src/stack.c +899 -0
- package/node_modules/semantifold-tree-sitter-zig-internal/node_modules/tree-sitter/vendor/tree-sitter/lib/src/stack.h +130 -0
- package/node_modules/semantifold-tree-sitter-zig-internal/node_modules/tree-sitter/vendor/tree-sitter/lib/src/subtree.c +1066 -0
- package/node_modules/semantifold-tree-sitter-zig-internal/node_modules/tree-sitter/vendor/tree-sitter/lib/src/subtree.h +399 -0
- package/node_modules/semantifold-tree-sitter-zig-internal/node_modules/tree-sitter/vendor/tree-sitter/lib/src/tree.c +170 -0
- package/node_modules/semantifold-tree-sitter-zig-internal/node_modules/tree-sitter/vendor/tree-sitter/lib/src/tree.h +31 -0
- package/node_modules/semantifold-tree-sitter-zig-internal/node_modules/tree-sitter/vendor/tree-sitter/lib/src/tree_cursor.c +712 -0
- package/node_modules/semantifold-tree-sitter-zig-internal/node_modules/tree-sitter/vendor/tree-sitter/lib/src/tree_cursor.h +48 -0
- package/node_modules/semantifold-tree-sitter-zig-internal/node_modules/tree-sitter/vendor/tree-sitter/lib/src/ts_assert.h +11 -0
- package/node_modules/semantifold-tree-sitter-zig-internal/node_modules/tree-sitter/vendor/tree-sitter/lib/src/unicode/ICU_SHA +1 -0
- package/node_modules/semantifold-tree-sitter-zig-internal/node_modules/tree-sitter/vendor/tree-sitter/lib/src/unicode/LICENSE +414 -0
- package/node_modules/semantifold-tree-sitter-zig-internal/node_modules/tree-sitter/vendor/tree-sitter/lib/src/unicode/README.md +29 -0
- package/node_modules/semantifold-tree-sitter-zig-internal/node_modules/tree-sitter/vendor/tree-sitter/lib/src/unicode/ptypes.h +1 -0
- package/node_modules/semantifold-tree-sitter-zig-internal/node_modules/tree-sitter/vendor/tree-sitter/lib/src/unicode/umachine.h +448 -0
- package/node_modules/semantifold-tree-sitter-zig-internal/node_modules/tree-sitter/vendor/tree-sitter/lib/src/unicode/urename.h +1 -0
- package/node_modules/semantifold-tree-sitter-zig-internal/node_modules/tree-sitter/vendor/tree-sitter/lib/src/unicode/utf.h +1 -0
- package/node_modules/semantifold-tree-sitter-zig-internal/node_modules/tree-sitter/vendor/tree-sitter/lib/src/unicode/utf16.h +733 -0
- package/node_modules/semantifold-tree-sitter-zig-internal/node_modules/tree-sitter/vendor/tree-sitter/lib/src/unicode/utf8.h +881 -0
- package/node_modules/semantifold-tree-sitter-zig-internal/node_modules/tree-sitter/vendor/tree-sitter/lib/src/unicode.h +83 -0
- package/node_modules/semantifold-tree-sitter-zig-internal/node_modules/tree-sitter/vendor/tree-sitter/lib/src/wasm/stdlib-symbols.txt +24 -0
- package/node_modules/semantifold-tree-sitter-zig-internal/node_modules/tree-sitter/vendor/tree-sitter/lib/src/wasm/stdlib.c +109 -0
- package/node_modules/semantifold-tree-sitter-zig-internal/node_modules/tree-sitter/vendor/tree-sitter/lib/src/wasm/wasm-stdlib.h +1302 -0
- package/node_modules/semantifold-tree-sitter-zig-internal/node_modules/tree-sitter/vendor/tree-sitter/lib/src/wasm_store.c +1859 -0
- package/node_modules/semantifold-tree-sitter-zig-internal/node_modules/tree-sitter/vendor/tree-sitter/lib/src/wasm_store.h +31 -0
- package/node_modules/semantifold-tree-sitter-zig-internal/package.json +21 -0
- package/node_modules/semantifold-tree-sitter-zig-internal/src/zig.js +134 -0
- package/package.json +11 -6
- package/src/backends/android.js +1374 -0
- package/src/backends/identifiers.js +30 -0
- package/src/backends/ios.js +1 -1
- package/src/backends/kotlin.js +11 -8
- package/src/backends/native-validation.js +1 -1
- package/src/backends/program.js +4 -3
- package/src/backends/scalars.js +1 -0
- package/src/backends/shared.js +22 -3
- package/src/backends/writer.js +27 -2
- package/src/backends/zig-runtime.js +93 -0
- package/src/backends/zig-validation.js +68 -0
- package/src/backends/zig.js +579 -0
- package/src/frontends/scalars.js +1 -0
- package/src/frontends/zig-parser.js +20 -0
- package/src/frontends/zig.js +994 -0
- package/src/language-registry.js +40 -0
- package/src/mapping.js +1 -1
- package/src/semantic/provenance.js +2 -2
- package/src/semantic/types.js +47 -2
- package/src/semantic/validate.js +1 -1
- package/src/toolchains.js +1 -0
- package/src/zig-bindings.js +46 -0
|
@@ -4,10 +4,12 @@ import {unsupportedCapability} from "../diagnostic.js"
|
|
|
4
4
|
|
|
5
5
|
/** @type {Record<Exclude<import("../semantic/types.js").BackendLanguage, "ios">, RegExp>} */
|
|
6
6
|
const identifierPatterns = {
|
|
7
|
+
android: /^(?:_|\p{L})(?:_|\p{L}|\p{Nd})*$/u,
|
|
7
8
|
dart: /^(?:_|\p{L})(?:_|\p{L}|\p{Nd})*$/u,
|
|
8
9
|
kotlin: /^(?:_|\p{L})(?:_|\p{L}|\p{Nd})*$/u,
|
|
9
10
|
swift: /^(?:_|\p{XID_Start})(?:_|\p{XID_Continue})*$/u,
|
|
10
11
|
rust: /^[A-Za-z_][A-Za-z0-9_]*$/u,
|
|
12
|
+
zig: /^[A-Za-z_][A-Za-z0-9_]*$/u,
|
|
11
13
|
cpp: /^[A-Za-z][A-Za-z0-9_]*$/u,
|
|
12
14
|
c: /^[A-Za-z][A-Za-z0-9_]*$/u,
|
|
13
15
|
csharp: /^[A-Za-z_][A-Za-z0-9_]*$/u,
|
|
@@ -23,6 +25,11 @@ const identifierPatterns = {
|
|
|
23
25
|
|
|
24
26
|
/** @type {Record<Exclude<import("../semantic/types.js").BackendLanguage, "ios">, Set<string>>} */
|
|
25
27
|
const reservedWords = {
|
|
28
|
+
android: new Set([
|
|
29
|
+
"as", "break", "class", "continue", "do", "else", "false", "for", "fun", "if", "in", "interface", "is", "null",
|
|
30
|
+
"object", "package", "return", "super", "this", "throw", "true", "try", "typealias", "typeof", "val", "var", "when",
|
|
31
|
+
"while", "_", "main", "println", "Long", "Boolean", "String", "Math", "ArithmeticException"
|
|
32
|
+
]),
|
|
26
33
|
dart: new Set([
|
|
27
34
|
"Function", "Never", "Object", "RangeError", "String", "abstract", "as", "assert", "async", "await", "base",
|
|
28
35
|
"bool", "break", "case", "catch", "class", "const", "continue", "covariant", "default", "deferred", "do",
|
|
@@ -54,6 +61,18 @@ const reservedWords = {
|
|
|
54
61
|
"unsafe", "use", "where", "while", "abstract", "become", "box", "do", "final", "macro", "override", "priv", "typeof", "unsized", "virtual",
|
|
55
62
|
"yield", "try", "union", "_", "main", "String", "std", "i64", "bool"
|
|
56
63
|
]),
|
|
64
|
+
zig: new Set([
|
|
65
|
+
"addrspace", "align", "allowzero", "and", "anyerror", "anyframe", "anyopaque", "anytype", "asm", "async", "await", "break", "callconv",
|
|
66
|
+
"catch", "comptime", "const", "continue", "defer", "else", "enum", "errdefer", "error", "export", "extern", "false",
|
|
67
|
+
"fn", "for", "if", "inline", "linksection", "noalias", "noinline", "nosuspend", "null", "opaque", "or", "orelse",
|
|
68
|
+
"packed", "pub", "resume", "return", "struct", "suspend", "switch", "test", "threadlocal", "true", "try", "union",
|
|
69
|
+
"unreachable", "usingnamespace", "var", "volatile", "while", "_", "main", "std", "bool", "c_char", "c_int", "c_long",
|
|
70
|
+
"c_longdouble", "c_longlong", "c_short", "c_uint", "c_ulong", "c_ulonglong", "c_ushort", "comptime_float",
|
|
71
|
+
"comptime_int", "f16", "f32", "f64", "f80", "f128", "isize", "noreturn", "type", "undefined", "usize", "void",
|
|
72
|
+
"semantifold_arena", "semantifold_fail", "semantifold_integer_add", "semantifold_integer_subtract",
|
|
73
|
+
"semantifold_integer_multiply", "semantifold_integer_negate", "semantifold_string_concat", "semantifold_string_equal",
|
|
74
|
+
"semantifold_string_not_equal", "semantifold_print_integer", "semantifold_print_boolean", "semantifold_print_string"
|
|
75
|
+
]),
|
|
57
76
|
cpp: new Set([
|
|
58
77
|
"alignas", "alignof", "and", "and_eq", "asm", "auto", "bitand", "bitor", "bool", "break", "case", "catch", "char", "char8_t", "char16_t", "char32_t", "class", "compl", "concept", "const", "consteval", "constexpr", "constinit", "const_cast", "continue", "co_await", "co_return", "co_yield", "decltype", "default", "delete", "do", "double", "dynamic_cast", "else", "enum", "explicit", "export", "extern", "false", "float", "for", "friend", "goto", "if", "inline", "int", "long", "mutable", "namespace", "new", "noexcept", "not", "not_eq", "nullptr", "operator", "or", "or_eq", "private", "protected", "public", "register", "reinterpret_cast", "requires", "return", "short", "signed", "sizeof", "static", "static_assert", "static_cast", "struct", "switch", "template", "this", "thread_local", "throw", "true", "try", "typedef", "typeid", "typename", "union", "unsigned", "using", "virtual", "void", "volatile", "wchar_t", "while", "xor", "xor_eq", "std", "string", "numeric_limits",
|
|
59
78
|
// The qualified libstdc++ <string> include chain also exposes these global names.
|
|
@@ -223,6 +242,7 @@ export function validateTargetIdentifier(language, name, role, location) {
|
|
|
223
242
|
language == "python" && name.normalize("NFKC") != name ||
|
|
224
243
|
language == "c" && !isCIdentifier(name) ||
|
|
225
244
|
language == "rust" && !isRustIdentifier(name) ||
|
|
245
|
+
language == "zig" && !isZigIdentifier(name) ||
|
|
226
246
|
language == "cpp" && !isCppIdentifier(name) ||
|
|
227
247
|
language == "dart" && !isDartIdentifier(name) ||
|
|
228
248
|
language == "swift" && (!isSwiftIdentifier(name) || name.normalize("NFC") != name) ||
|
|
@@ -301,6 +321,16 @@ export function isRustIdentifier(name) {
|
|
|
301
321
|
return identifierPatterns.rust.test(name) && !reservedWords.rust.has(name) && !name.startsWith("semantifold_")
|
|
302
322
|
}
|
|
303
323
|
|
|
324
|
+
/**
|
|
325
|
+
* Protects Zig keywords, scalar names, entry plumbing, builtins, and the support namespace.
|
|
326
|
+
* @param {string} name - Caller-owned function or binding name.
|
|
327
|
+
* @returns {boolean} Whether ordinary unquoted Zig syntax can preserve the name.
|
|
328
|
+
*/
|
|
329
|
+
export function isZigIdentifier(name) {
|
|
330
|
+
return identifierPatterns.zig.test(name) && !reservedWords.zig.has(name) && !/^[iu][0-9]+$/u.test(name) &&
|
|
331
|
+
!name.startsWith("semantifold_")
|
|
332
|
+
}
|
|
333
|
+
|
|
304
334
|
/**
|
|
305
335
|
* Protects Swift keywords, scalar names, entry plumbing, and target-only helper names.
|
|
306
336
|
* @param {string} name - Caller-owned function or binding name.
|
package/src/backends/ios.js
CHANGED
|
@@ -13,7 +13,7 @@ import {SourceWriter} from "./writer.js"
|
|
|
13
13
|
|
|
14
14
|
/** @type {Readonly<Set<import("../semantic/types.js").SemanticLanguage>>} */
|
|
15
15
|
const iosSourceLanguages = new Set([
|
|
16
|
-
"php", "ruby", "javascript", "typescript", "java", "kotlin", "python", "csharp", "go", "c", "cpp", "rust", "swift", "dart"
|
|
16
|
+
"php", "ruby", "javascript", "typescript", "java", "kotlin", "python", "csharp", "go", "c", "cpp", "rust", "swift", "dart", "zig"
|
|
17
17
|
])
|
|
18
18
|
const configurationFields = new Set([
|
|
19
19
|
"bundleIdentifier", "capabilities", "deploymentTarget", "displayName", "entitlements", "infoPlist", "lifecycle",
|
package/src/backends/kotlin.js
CHANGED
|
@@ -47,12 +47,12 @@ export function generateKotlin(module, writer) {
|
|
|
47
47
|
writer.mapped(emitScalarType("kotlin", declaration.returnType), {mappingKind: "exact", node: declaration.returnType,
|
|
48
48
|
path: `${path}/returnType`, role: "type"})
|
|
49
49
|
writer.synthetic(" {\n", "Kotlin function body scaffold", [declaration], [path])
|
|
50
|
-
|
|
50
|
+
emitKotlinBlock(writer, declaration.body, " ", `${path}/body`)
|
|
51
51
|
writer.synthetic("}\n", "Kotlin function body scaffold", [declaration], [path])
|
|
52
52
|
})
|
|
53
53
|
|
|
54
54
|
writer.synthetic("\nfun main() {\n", "Kotlin generated main scaffold", [module.entryPoint], ["/entryPoint"])
|
|
55
|
-
|
|
55
|
+
emitKotlinBlock(writer, module.entryPoint.body, " ", "/entryPoint/body")
|
|
56
56
|
writer.synthetic("}\n", "Kotlin generated main scaffold", [module.entryPoint], ["/entryPoint"])
|
|
57
57
|
}
|
|
58
58
|
|
|
@@ -62,10 +62,12 @@ export function generateKotlin(module, writer) {
|
|
|
62
62
|
* @param {import("../semantic/types.js").Block} block - Semantic block.
|
|
63
63
|
* @param {string} indent - Current indentation.
|
|
64
64
|
* @param {string} path - Semantic block path.
|
|
65
|
+
* @param {string} [printTarget] - Target-owned print function spelling.
|
|
65
66
|
* @returns {void}
|
|
66
67
|
*/
|
|
67
|
-
function
|
|
68
|
-
block.statements.forEach((statement, index) =>
|
|
68
|
+
export function emitKotlinBlock(writer, block, indent, path, printTarget = "println") {
|
|
69
|
+
block.statements.forEach((statement, index) =>
|
|
70
|
+
emitKotlinStatement(writer, statement, indent, `${path}/statements/${index}`, printTarget))
|
|
69
71
|
}
|
|
70
72
|
|
|
71
73
|
/**
|
|
@@ -74,9 +76,10 @@ function emitBlock(writer, block, indent, path) {
|
|
|
74
76
|
* @param {import("../semantic/types.js").Statement} statement - Semantic statement.
|
|
75
77
|
* @param {string} indent - Current indentation.
|
|
76
78
|
* @param {string} path - Semantic statement path.
|
|
79
|
+
* @param {string} printTarget - Target-owned print function spelling.
|
|
77
80
|
* @returns {void}
|
|
78
81
|
*/
|
|
79
|
-
function
|
|
82
|
+
function emitKotlinStatement(writer, statement, indent, path, printTarget) {
|
|
80
83
|
writer.synthetic(indent, "indentation", [statement], [path])
|
|
81
84
|
if (statement.kind == "LocalDeclaration") {
|
|
82
85
|
writer.mapped(statement.mutable ? "var" : "val", {mappingKind: "anchor", node: statement, path})
|
|
@@ -111,7 +114,7 @@ function emitStatement(writer, statement, indent, path) {
|
|
|
111
114
|
return
|
|
112
115
|
}
|
|
113
116
|
if (statement.kind == "PrintStatement") {
|
|
114
|
-
writer.synthetic(
|
|
117
|
+
writer.synthetic(`${printTarget}(`, "Kotlin print plumbing", [statement], [path])
|
|
115
118
|
emitExpression(writer, statement.expression, `${path}/expression`, "kotlin", identity)
|
|
116
119
|
writer.synthetic(")\n", "Kotlin println plumbing", [statement], [path])
|
|
117
120
|
return
|
|
@@ -121,11 +124,11 @@ function emitStatement(writer, statement, indent, path) {
|
|
|
121
124
|
writer.synthetic(" (", "Kotlin conditional scaffold", [statement], [path])
|
|
122
125
|
emitExpression(writer, statement.condition, `${path}/condition`, "kotlin", identity)
|
|
123
126
|
writer.synthetic(") {\n", "Kotlin conditional scaffold", [statement.consequent], [`${path}/consequent`])
|
|
124
|
-
|
|
127
|
+
emitKotlinBlock(writer, statement.consequent, `${indent} `, `${path}/consequent`, printTarget)
|
|
125
128
|
writer.synthetic(`${indent}}`, "Kotlin conditional scaffold", [statement.consequent], [`${path}/consequent`])
|
|
126
129
|
if (statement.alternate) {
|
|
127
130
|
writer.synthetic(" else {\n", "Kotlin alternate scaffold", [statement.alternate], [`${path}/alternate`])
|
|
128
|
-
|
|
131
|
+
emitKotlinBlock(writer, statement.alternate, `${indent} `, `${path}/alternate`, printTarget)
|
|
129
132
|
writer.synthetic(`${indent}}`, "Kotlin alternate scaffold", [statement.alternate], [`${path}/alternate`])
|
|
130
133
|
}
|
|
131
134
|
writer.synthetic("\n", "line break", [statement], [path])
|
|
@@ -10,7 +10,7 @@ const semanticEdges = new Set(["functions", "entryPoint", "body", "parameters",
|
|
|
10
10
|
/**
|
|
11
11
|
* Bounds a native occurrence plan and rejects cycles before recursive shared validation.
|
|
12
12
|
* @param {unknown} module - Untrusted backend request.
|
|
13
|
-
* @param {"c" | "cpp" | "kotlin" | "rust" | "swift" | "wasm"} [language] - Backend diagnostic language.
|
|
13
|
+
* @param {"c" | "cpp" | "kotlin" | "rust" | "swift" | "wasm" | "zig"} [language] - Backend diagnostic language.
|
|
14
14
|
* @returns {void}
|
|
15
15
|
*/
|
|
16
16
|
export function validateNativeGraph(module, language = "c") {
|
package/src/backends/program.js
CHANGED
|
@@ -23,7 +23,7 @@ import {programImportName, SourceWriter} from "./writer.js"
|
|
|
23
23
|
/** @type {Readonly<Set<import("../semantic/types.js").SemanticLanguage>>} */
|
|
24
24
|
const programTargets = new Set(["php", "ruby", "javascript", "typescript", "java"])
|
|
25
25
|
/** @type {Readonly<Set<import("../semantic/types.js").BackendLanguage>>} */
|
|
26
|
-
const programApplicationTargets = new Set(["ios"])
|
|
26
|
+
const programApplicationTargets = new Set(["android", "ios"])
|
|
27
27
|
|
|
28
28
|
/**
|
|
29
29
|
* Validates and prepares a complete semantic program for a non-text backend without allocating a writer.
|
|
@@ -68,8 +68,9 @@ export function preflightSemanticProgram({backendLanguage, diagnosticLanguage, p
|
|
|
68
68
|
* @param {import("../semantic/types.js").BackendLanguage} input.language - Registered program target.
|
|
69
69
|
* @param {import("../semantic/types.js").SemanticProgram} input.program - Complete semantic program.
|
|
70
70
|
* @param {"text" | "application"} [input.role] - Explicit artifact role; omitted preserves text generation.
|
|
71
|
-
* @param {import("../semantic/types.js").IosApplicationConfigurationInput} [input.configuration] -
|
|
72
|
-
* @param {import("../semantic/types.js").IosApplicationAssetInput[]} [input.assets] - Exact
|
|
71
|
+
* @param {import("../semantic/types.js").IosApplicationConfigurationInput | import("../semantic/types.js").AndroidApplicationConfigurationInput} [input.configuration] - Application configuration.
|
|
72
|
+
* @param {import("../semantic/types.js").IosApplicationAssetInput[] | import("../semantic/types.js").AndroidApplicationInputFile[]} [input.assets] - Exact caller assets.
|
|
73
|
+
* @param {import("../semantic/types.js").AndroidApplicationInputFile[]} [input.resources] - Exact Android caller resources.
|
|
73
74
|
* @returns {import("../semantic/types.js").GeneratedArtifactSet} Transactionally validated artifact set.
|
|
74
75
|
*/
|
|
75
76
|
export function generateProgramArtifacts(input) {
|
package/src/backends/scalars.js
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
/** @type {Readonly<Record<import("../semantic/types.js").TextBackendLanguage, Readonly<Record<import("../semantic/types.js").FunctionReturnTypeName, string>>>>} */
|
|
4
4
|
const targetScalarTypes = Object.freeze({
|
|
5
|
+
zig: Object.freeze({boolean: "bool", integer: "i64", string: "[]const u8", void: "void"}),
|
|
5
6
|
dart: Object.freeze({boolean: "bool", integer: "int", string: "String", void: "void"}),
|
|
6
7
|
swift: Object.freeze({boolean: "Bool", integer: "Int64", string: "String", void: "Void"}),
|
|
7
8
|
rust: Object.freeze({boolean: "bool", integer: "i64", string: "String", void: "()"}),
|
package/src/backends/shared.js
CHANGED
|
@@ -27,7 +27,7 @@ const binaryOperationSyntax = Object.freeze({
|
|
|
27
27
|
StringEqual: Object.freeze({default: "==", strict: "==="}),
|
|
28
28
|
StringNotEqual: Object.freeze({default: "!=", strict: "!=="})
|
|
29
29
|
})
|
|
30
|
-
const task005Languages = new Set(["php", "ruby", "javascript", "typescript", "java", "dart"])
|
|
30
|
+
const task005Languages = new Set(["php", "ruby", "javascript", "typescript", "java", "dart", "zig"])
|
|
31
31
|
const task006Languages = new Set(["php", "ruby", "javascript", "typescript", "java"])
|
|
32
32
|
const task007Languages = new Set(["php", "ruby", "javascript", "typescript", "java"])
|
|
33
33
|
const task008Languages = new Set(["php", "ruby", "javascript", "typescript", "java"])
|
|
@@ -1952,9 +1952,9 @@ function validateKnownTargetInteger(expression, language, location) {
|
|
|
1952
1952
|
if (language == "java" && value !== undefined && (value < -2147483648n || value > 2147483647n)) {
|
|
1953
1953
|
unsupportedCapability(language, "compile-time-known integer operation outside signed 32-bit int range", location)
|
|
1954
1954
|
}
|
|
1955
|
-
if ((language == "csharp" || language == "go" || language == "c" || language == "cpp" || language == "rust" || language == "swift" || language == "wasm") && value !== undefined &&
|
|
1955
|
+
if ((language == "csharp" || language == "go" || language == "c" || language == "cpp" || language == "rust" || language == "swift" || language == "wasm" || language == "zig") && value !== undefined &&
|
|
1956
1956
|
(value < -9223372036854775808n || value > 9223372036854775807n)) {
|
|
1957
|
-
const scalar = language == "wasm" ? "i64" : language == "swift" ? "Int64" : "long"
|
|
1957
|
+
const scalar = language == "wasm" || language == "zig" ? "i64" : language == "swift" ? "Int64" : "long"
|
|
1958
1958
|
|
|
1959
1959
|
unsupportedCapability(language, `compile-time-known integer operation outside signed 64-bit ${scalar} range`, location)
|
|
1960
1960
|
}
|
|
@@ -2255,6 +2255,12 @@ export function emitExpression(writer, expression, path, language, emitIdentifie
|
|
|
2255
2255
|
emitExpression(writer, argument, `${path}/arguments/${index}`, language, emitIdentifier)
|
|
2256
2256
|
if (dartMultiline) writer.synthetic(",\n", "Dart formatter argument separator", [expression], [path])
|
|
2257
2257
|
})
|
|
2258
|
+
const callArgumentSuffix = writer.callArgumentSuffixFor(expression)
|
|
2259
|
+
|
|
2260
|
+
if (callArgumentSuffix) {
|
|
2261
|
+
writer.synthetic(`${expression.arguments.length ? ", " : ""}${callArgumentSuffix}`,
|
|
2262
|
+
"target-container semantic call argument", [expression], [path])
|
|
2263
|
+
}
|
|
2258
2264
|
if (dartMultiline) writer.synthetic(dartIndent, "Dart call closing indentation", [expression], [path])
|
|
2259
2265
|
writer.mapped(")", {mappingKind: "anchor", node: expression, path})
|
|
2260
2266
|
return
|
|
@@ -2407,6 +2413,19 @@ export function emitExpression(writer, expression, path, language, emitIdentifie
|
|
|
2407
2413
|
return
|
|
2408
2414
|
}
|
|
2409
2415
|
|
|
2416
|
+
if (language == "kotlin" && writer.usesMethodStringEquality() &&
|
|
2417
|
+
(expression.operation == "StringEqual" || expression.operation == "StringNotEqual")) {
|
|
2418
|
+
writer.mapped("(", {mappingKind: "anchor", node: expression, path})
|
|
2419
|
+
if (expression.operation == "StringNotEqual") {
|
|
2420
|
+
writer.mapped("!", {mappingKind: "exact", node: expression, path, role: "operator"})
|
|
2421
|
+
}
|
|
2422
|
+
emitExpression(writer, expression.left, `${path}/left`, language, emitIdentifier)
|
|
2423
|
+
writer.mapped(".equals(", {mappingKind: "exact", node: expression, path, role: "operator"})
|
|
2424
|
+
emitExpression(writer, expression.right, `${path}/right`, language, emitIdentifier)
|
|
2425
|
+
writer.mapped("))", {mappingKind: "anchor", node: expression, path})
|
|
2426
|
+
return
|
|
2427
|
+
}
|
|
2428
|
+
|
|
2410
2429
|
if (language == "csharp" && ["IntegerAdd", "IntegerSubtract", "IntegerMultiply"].includes(expression.operation)) {
|
|
2411
2430
|
writer.mapped("checked(", {mappingKind: "anchor", node: expression, path})
|
|
2412
2431
|
emitExpression(writer, expression.left, `${path}/left`, language, emitIdentifier)
|
package/src/backends/writer.js
CHANGED
|
@@ -80,9 +80,13 @@ export class SourceWriter {
|
|
|
80
80
|
* @param {string[]} [options.stdlibProviderImports] - Ordered provider names this module must import.
|
|
81
81
|
* @param {string} [options.stdlibProviderOwnerModule] - Java owner module identity hosting the shared support block and shims.
|
|
82
82
|
* @param {string[]} [options.stdlibProviderShims] - Java owner program-wide used operations exposed as public static shims.
|
|
83
|
+
* @param {(expression: import("../semantic/types.js").CallExpression) => string} [options.callNameResolver] - Target-container call spelling override.
|
|
84
|
+
* @param {string} [options.callArgumentSuffix] - Synthetic trailing argument for every semantic function call.
|
|
85
|
+
* @param {boolean} [options.methodStringEquality] - Emit string equality through the platform String method.
|
|
83
86
|
*/
|
|
84
|
-
constructor({filename, language, module, program, programPaths, sources,
|
|
85
|
-
stdlibProviderPaths, stdlibProviderImports, stdlibProviderOwnerModule,
|
|
87
|
+
constructor({callArgumentSuffix, callNameResolver, filename, language, methodStringEquality, module, program, programPaths, sources,
|
|
88
|
+
stdlibProviderEntries, stdlibProviderPath, stdlibProviderPaths, stdlibProviderImports, stdlibProviderOwnerModule,
|
|
89
|
+
stdlibProviderShims}) {
|
|
86
90
|
const index = createGenerationIndex(module, sources)
|
|
87
91
|
|
|
88
92
|
this.filename = filename
|
|
@@ -90,6 +94,9 @@ export class SourceWriter {
|
|
|
90
94
|
this.module = module
|
|
91
95
|
this.program = program
|
|
92
96
|
this.programPaths = programPaths
|
|
97
|
+
this.callArgumentSuffix = callArgumentSuffix
|
|
98
|
+
this.callNameResolver = callNameResolver
|
|
99
|
+
this.methodStringEquality = methodStringEquality ?? false
|
|
93
100
|
this.index = index
|
|
94
101
|
this.stdlibProviderEntries = stdlibProviderEntries
|
|
95
102
|
this.stdlibProviderPath = stdlibProviderPath
|
|
@@ -386,6 +393,7 @@ export class SourceWriter {
|
|
|
386
393
|
* @returns {string} Target call name.
|
|
387
394
|
*/
|
|
388
395
|
callNameFor(expression) {
|
|
396
|
+
if (this.callNameResolver) return this.callNameResolver(expression)
|
|
389
397
|
const declarationId = expression.resolution?.declarationId
|
|
390
398
|
const owner = declarationId ? this.declarationModules.get(declarationId) : undefined
|
|
391
399
|
const imported = declarationId ? this.#programModule()?.imports.find((item) => item.declarationId == declarationId) : undefined
|
|
@@ -398,6 +406,23 @@ export class SourceWriter {
|
|
|
398
406
|
return declarationName(owner, declarationId)
|
|
399
407
|
}
|
|
400
408
|
|
|
409
|
+
/**
|
|
410
|
+
* Returns a target-container trailing argument for a semantic call.
|
|
411
|
+
* @param {import("../semantic/types.js").CallExpression} _expression - Resolved semantic call.
|
|
412
|
+
* @returns {string | undefined} Synthetic argument spelling, when configured.
|
|
413
|
+
*/
|
|
414
|
+
callArgumentSuffixFor(_expression) {
|
|
415
|
+
return this.callArgumentSuffix
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
/**
|
|
419
|
+
* Reports whether string equality must avoid a target runtime helper.
|
|
420
|
+
* @returns {boolean} Whether to emit the platform String method.
|
|
421
|
+
*/
|
|
422
|
+
usesMethodStringEquality() {
|
|
423
|
+
return this.methodStringEquality
|
|
424
|
+
}
|
|
425
|
+
|
|
401
426
|
/** Marks emission as occurring inside one top-level reference class. */
|
|
402
427
|
beginReferenceClassEmission() {
|
|
403
428
|
this.referenceClassEmissionDepth += 1
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
|
|
3
|
+
/** Exact Zig 0.15.2 standard-library-only support; the frontend checks every token before collapse. */
|
|
4
|
+
export const zigRuntime = `const std = @import("std");
|
|
5
|
+
|
|
6
|
+
var semantifold_arena = std.heap.ArenaAllocator.init(std.heap.page_allocator);
|
|
7
|
+
|
|
8
|
+
fn semantifold_fail(message: []const u8) noreturn {
|
|
9
|
+
std.fs.File.stderr().writeAll(message) catch {};
|
|
10
|
+
std.process.exit(70);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
fn semantifold_integer_add(left: i64, right: i64) i64 {
|
|
14
|
+
const result = @addWithOverflow(left, right);
|
|
15
|
+
if (result[1] != 0) semantifold_fail("semantifold: integer overflow\\n");
|
|
16
|
+
return result[0];
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
fn semantifold_integer_subtract(left: i64, right: i64) i64 {
|
|
20
|
+
const result = @subWithOverflow(left, right);
|
|
21
|
+
if (result[1] != 0) semantifold_fail("semantifold: integer overflow\\n");
|
|
22
|
+
return result[0];
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
fn semantifold_integer_multiply(left: i64, right: i64) i64 {
|
|
26
|
+
const result = @mulWithOverflow(left, right);
|
|
27
|
+
if (result[1] != 0) semantifold_fail("semantifold: integer overflow\\n");
|
|
28
|
+
return result[0];
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
fn semantifold_integer_negate(value: i64) i64 {
|
|
32
|
+
return semantifold_integer_subtract(0, value);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
fn semantifold_string_concat(left: []const u8, right: []const u8) []const u8 {
|
|
36
|
+
const size = @addWithOverflow(left.len, right.len);
|
|
37
|
+
if (size[1] != 0) semantifold_fail("semantifold: allocation failure\\n");
|
|
38
|
+
const bytes = semantifold_arena.allocator().alloc(u8, size[0]) catch semantifold_fail("semantifold: allocation failure\\n");
|
|
39
|
+
@memcpy(bytes[0..left.len], left);
|
|
40
|
+
@memcpy(bytes[left.len..], right);
|
|
41
|
+
return bytes;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
fn semantifold_string_equal(left: []const u8, right: []const u8) bool {
|
|
45
|
+
return std.mem.eql(u8, left, right);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
fn semantifold_string_not_equal(left: []const u8, right: []const u8) bool {
|
|
49
|
+
return !std.mem.eql(u8, left, right);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
fn semantifold_write(value: []const u8) void {
|
|
53
|
+
const stdout = std.fs.File.stdout();
|
|
54
|
+
stdout.writeAll(value) catch semantifold_fail("semantifold: output failure\\n");
|
|
55
|
+
stdout.writeAll("\\n") catch semantifold_fail("semantifold: output failure\\n");
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
fn semantifold_print_integer(value: i64) void {
|
|
59
|
+
var buffer: [20]u8 = undefined;
|
|
60
|
+
const bytes = std.fmt.bufPrint(&buffer, "{d}", .{value}) catch semantifold_fail("semantifold: output failure\\n");
|
|
61
|
+
semantifold_write(bytes);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
fn semantifold_print_boolean(value: bool) void {
|
|
65
|
+
semantifold_write(if (value) "true" else "false");
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
fn semantifold_print_string(value: []const u8) void {
|
|
69
|
+
semantifold_write(value);
|
|
70
|
+
}
|
|
71
|
+
`
|
|
72
|
+
|
|
73
|
+
/** Fixed native-host Zig build with only the selected optimization option and no package resolution. */
|
|
74
|
+
export const zigBuild = `const std = @import("std");
|
|
75
|
+
|
|
76
|
+
pub fn build(b: *std.Build) void {
|
|
77
|
+
const optimize = b.standardOptimizeOption(.{});
|
|
78
|
+
const executable = b.addExecutable(.{
|
|
79
|
+
.name = "semantifold-generated",
|
|
80
|
+
.root_module = b.createModule(.{
|
|
81
|
+
.root_source_file = b.path("src/main.zig"),
|
|
82
|
+
.target = b.graph.host,
|
|
83
|
+
.optimize = optimize,
|
|
84
|
+
}),
|
|
85
|
+
});
|
|
86
|
+
b.installArtifact(executable);
|
|
87
|
+
|
|
88
|
+
const tests = b.addTest(.{ .root_module = executable.root_module });
|
|
89
|
+
const run_tests = b.addRunArtifact(tests);
|
|
90
|
+
const test_step = b.step("test", "Compile and run tests");
|
|
91
|
+
test_step.dependOn(&run_tests.step);
|
|
92
|
+
}
|
|
93
|
+
`
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
|
|
3
|
+
import {unsupportedCapability} from "../diagnostic.js"
|
|
4
|
+
|
|
5
|
+
/** Repository-owned bound for frozen CST traversal and deterministic project generation. */
|
|
6
|
+
export const maximumZigSourceLength = 1_000_000
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Rejects statically impossible UTF-8 arena sizes without changing the semantic graph.
|
|
10
|
+
* @param {import("../semantic/types.js").SemanticModule} module - Fully validated module.
|
|
11
|
+
* @returns {void}
|
|
12
|
+
*/
|
|
13
|
+
export function validateZigValues(module) {
|
|
14
|
+
/**
|
|
15
|
+
* Infers a known UTF-8 byte size while validating literal shape.
|
|
16
|
+
* @param {import("../semantic/types.js").Expression} expression - Expression to inspect.
|
|
17
|
+
* @param {Map<string, bigint | undefined>} sizes - Known binding sizes.
|
|
18
|
+
* @returns {bigint | undefined} Known byte size when statically available.
|
|
19
|
+
*/
|
|
20
|
+
const size = (expression, sizes) => {
|
|
21
|
+
if (expression.kind == "IntegerLiteral" && (!Number.isSafeInteger(expression.value) || expression.value < 0 || Object.is(expression.value, -0))) {
|
|
22
|
+
unsupportedCapability("zig", "non-safe or noncanonical i64 literal", expression.location)
|
|
23
|
+
}
|
|
24
|
+
if (expression.kind == "StringLiteral") return BigInt(Buffer.byteLength(expression.value, "utf8"))
|
|
25
|
+
if (expression.kind == "IdentifierExpression") return sizes.get(expression.name)
|
|
26
|
+
if (expression.kind == "CallExpression") expression.arguments.forEach(argument => size(argument, sizes))
|
|
27
|
+
else if (expression.kind == "UnaryExpression") size(expression.operand, sizes)
|
|
28
|
+
else if (expression.kind == "BinaryExpression") {
|
|
29
|
+
const left = size(expression.left, sizes)
|
|
30
|
+
const right = size(expression.right, sizes)
|
|
31
|
+
|
|
32
|
+
if (expression.operation == "StringConcat") {
|
|
33
|
+
if ((left ?? 0n) + (right ?? 0n) > 9223372036854775807n) {
|
|
34
|
+
unsupportedCapability("zig", "known immutable UTF-8 slice exceeds the qualified native allocation limit", expression.location)
|
|
35
|
+
}
|
|
36
|
+
if (left !== undefined && right !== undefined) return left + right
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
return undefined
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Propagates conservative known string sizes through one block.
|
|
43
|
+
* @param {import("../semantic/types.js").Block} block - Block to inspect.
|
|
44
|
+
* @param {Map<string, bigint | undefined>} inherited - Sizes visible on entry.
|
|
45
|
+
* @returns {Map<string, bigint | undefined>} Sizes known after the block.
|
|
46
|
+
*/
|
|
47
|
+
const visit = (block, inherited) => {
|
|
48
|
+
const sizes = new Map(inherited)
|
|
49
|
+
|
|
50
|
+
for (const statement of block.statements) {
|
|
51
|
+
if (statement.kind == "LocalDeclaration") sizes.set(statement.name, size(statement.initializer, sizes))
|
|
52
|
+
else if (statement.kind == "AssignmentStatement") sizes.set(statement.target.name, size(statement.expression, sizes))
|
|
53
|
+
else if (statement.kind == "IfStatement") {
|
|
54
|
+
size(statement.condition, sizes)
|
|
55
|
+
const left = visit(statement.consequent, sizes)
|
|
56
|
+
const right = statement.alternate ? visit(statement.alternate, sizes) : sizes
|
|
57
|
+
|
|
58
|
+
for (const name of sizes.keys()) sizes.set(name, left.get(name) === right.get(name) ? left.get(name) : undefined)
|
|
59
|
+
} else if (statement.kind == "ExpressionStatement" || statement.kind == "PrintStatement" || statement.kind == "ReturnStatement") {
|
|
60
|
+
if (statement.expression) size(statement.expression, sizes)
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
return sizes
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
for (const declaration of module.functions) visit(declaration.body, new Map())
|
|
67
|
+
visit(module.entryPoint.body, new Map())
|
|
68
|
+
}
|