Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,13 @@ if(BUILD_TESTING)
target_compile_features(nil_pattern_engine_tests PRIVATE cxx_std_17)
add_test(NAME nil.pattern-engine COMMAND $<TARGET_FILE:nil_pattern_engine_tests>)

add_executable(nil_nildata_engine_tests tests/nildata_engine_tests.cpp)
target_link_libraries(nil_nildata_engine_tests PRIVATE nilruntime)
target_include_directories(nil_nildata_engine_tests PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/nilcompiler/src")
target_compile_features(nil_nildata_engine_tests PRIVATE cxx_std_17)
add_test(NAME nil.nildata-engine COMMAND $<TARGET_FILE:nil_nildata_engine_tests>)
set_tests_properties(nil.nildata-engine PROPERTIES LABELS "serialization;runtime;rc" TIMEOUT 60)

add_executable(nil_pattern_syntax_tests tests/pattern_syntax_tests.cpp)
target_link_libraries(nil_pattern_syntax_tests PRIVATE nilcompiler_core)
target_compile_features(nil_pattern_syntax_tests PRIVATE cxx_std_17)
Expand Down Expand Up @@ -2425,6 +2432,7 @@ if(BUILD_TESTING)
tuple-arrays tuple-arrays-matrix
text-patterns text-patterns-matrix
pattern-operations pattern-operations-matrix
nildata-roundtrip nildata-roundtrip-matrix
indexed-expression-types
bugpass-allocation-types
bugpass-grouped-expressions
Expand Down Expand Up @@ -2468,6 +2476,20 @@ if(BUILD_TESTING)
LABELS "tools;native;rc" SKIP_RETURN_CODE 77 TIMEOUT 240)
endif()
endforeach()
add_test(NAME nil.nildata-cli-contract
COMMAND "${Python3_EXECUTABLE}"
"${CMAKE_CURRENT_SOURCE_DIR}/tests/nildata_cli_contract.py"
--compiler $<TARGET_FILE:nilcompiler>)
set_tests_properties(nil.nildata-cli-contract PROPERTIES LABELS "serialization;tools;rc" TIMEOUT 120)
add_test(NAME nil.nildata-intrinsic-contract
COMMAND "${Python3_EXECUTABLE}"
"${CMAKE_CURRENT_SOURCE_DIR}/tests/tools/nildata_intrinsic_contract.py"
--interpreter $<TARGET_FILE:nilinterpreter>
--assembler $<TARGET_FILE:nilassembler>
--linker $<TARGET_FILE:nillinker>
--runtime $<TARGET_FILE:nilruntime>
--llvm "${NIL_ENABLE_LLVM}")
set_tests_properties(nil.nildata-intrinsic-contract PROPERTIES LABELS "serialization;native;interpreter;rc" TIMEOUT 120)
foreach(bugpass_contract IN ITEMS lexer argument)
add_test(NAME nil.bugpass-${bugpass_contract}-contract
COMMAND "${Python3_EXECUTABLE}"
Expand Down
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,9 @@ The framework includes:
splitting and literal replacement.
- **A shared standard library.** `nil.std.*` provides collections, text,
mathematics, binary I/O, diagnostics, and reflection, alongside SQLite and
PostgreSQL access. Existing `ny.lang.*` imports remain compatible aliases.
PostgreSQL access. [NILData](docs/standard-library/nildata.md) provides
structured data with prose-style blocks, exact numeric values, one array type
and checked JSON interchange. Existing `ny.lang.*` imports remain aliases.
- **Interpreted and native execution.** The toolchain supports NIL
interpretation, LLVM JIT and ahead-of-time compilation, and separate
assembly and linking through `nilassembler` and `nillinker`.
Expand Down
1 change: 1 addition & 0 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ command-line help, and executable tests as bugs.
sequence toward shared workspace semantics.
- [Standard-library status](standard-library/index.md) — layout, maturity, and
what is deliberately outside the core library.
- [NILData](standard-library/nildata.md) — structured data, JSON interchange and explicit NyData migration.
- [Examples](../examples/README.md) — small examples tied to repository fixtures.
- [Matrix](../matrix/README.md) — prose-oriented frontend, syntax, and examples.
- [Ny](../ny/README.md) — systems-language frontend and reference entry point.
Expand Down
3 changes: 2 additions & 1 deletion docs/design/NIL-0006-ai-module.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,8 @@ NIL-0006 is only one part of the framework's AI tooling direction:
evaluation. It is currently the more developed automation surface for NIL
debugging.
- `nilaix/src/ny_crash.ny` contains explicit helpers for writing `.nycrash`
artifacts in NyData form. These helpers are not automatic crash reporting for
artifacts in an older INI-like report format, historically labeled NyData.
That format is distinct from NILData 1. These helpers are not automatic crash reporting for
every Ny binary.

## Remaining proposal
Expand Down
62 changes: 62 additions & 0 deletions docs/design/NIL-0017-nildata.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# NIL-0017: Versioned NILData and one shared value model

Status: implemented initial bounded document profile.

NILData is the framework's declarative data notation. Its named statements and
explicit blocks follow Matrix's prose conventions, while its values remain
independent of program execution. Loading a document never evaluates an
expression, expands an environment variable, imports code, or runs interpolation.

The former NyData implementations disagreed: the compiler encoded arrays as
numbered objects and inferred scalar types from text; the standard library had
separate list blocks and only text-valued scalars. Both accepted incomplete
input. Renaming those implementations would preserve incompatible data models.

## Decision

Define a versioned UTF-8 grammar and one shared implementation in
`nilcompiler/src/nildata.cpp`, linked into the compiler and runtime. The CLI,
interpreter, JIT and native programs use the same parser, validation, value
operations and serializers. The public library is `nil.std.nildata`.

Values are null, boolean, integer, decimal, text, object or array. **Array is the
only sequence kind**, including empty, heterogeneous and nested sequences.
Objects with numeric keys remain objects. Number tokens retain their exact
decimal spelling instead of being converted through binary floating point.

The library's `Value` contains a validated JSON text representation. Each
operation revalidates that representation because callers can construct public
records themselves. Updates return independent values. This avoids hidden
document handles and recursive native record layouts, and gives both execution
routes the same ownership behavior. It also means repeated queries and updates
reparse and copy documents; this initial API is for bounded documents, with no
streaming or constant-time access claim.

The serialization engine uses JSON as an internal representation and interchange
format. NILData's public grammar is independent; JSON's punctuation does not
appear in object and array declarations. Strings use explicit quoting and
escapes so text can contain whitespace, newlines and closing-marker words
without ambiguity. The [format and API contract](../standard-library/nildata.md)
defines the exact grammar and limits.

## Compatibility

`ny.lang.nydata` and `nil.std.nydata` imports resolve to `nil.std.nildata`.
This preserves module spelling, not the old recursive types or function
signatures. The new checked API deliberately replaces the old API.

Legacy document loading is explicit. Separate importers cover the old library
and compiler wrappers. They reject incomplete blocks and duplicate members;
scalar fields remain text and numbered objects remain objects. Information
discarded by an old writer cannot be recovered by inferring its appearance.
There is no legacy fallback inside `loads` and no legacy writer.

## Scope

The version header, bounds, full-input checks and deterministic output make the
format suitable for bounded configuration and tool messages. Schemas, source
editing that preserves comments, streaming, signing/canonicalization and a
Matrix shell integration are separate work. Sorted keys and preserved numeric
lexemes are deterministic serialization, not a semantic canonical form for
cryptographic signatures. This decision makes no change to the language's
typed `array<T>` syntax or storage ABI.
1 change: 1 addition & 0 deletions docs/design/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ not assigned architecture identifiers.
| NIL-0014 | [Explicit formatted text with original expression locations](NIL-0014-formatted-text.md) | Implemented initial scalar/text profile |
| NIL-0015 | [Structural tuples](NIL-0015-structural-tuples.md) | Implemented nonempty typed values and local destructuring |
| NIL-0016 | [Shared text patterns and collected queries](NIL-0016-patterns-and-queries.md) | Implemented initial byte-pattern and eager array-query profiles |
| NIL-0017 | [Versioned NILData and one shared value model](NIL-0017-nildata.md) | Implemented initial bounded document profile |
| NIL-0093 | [Executable context is artifact self-description](NIL-0093-executable-context.md) | Implemented within the documented inspection profile |

## Retained Ny feature references
Expand Down
2 changes: 1 addition & 1 deletion docs/design/nypm.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ The manifest format is not yet frozen. The current direction uses a Ny-readable
artifact, and native-build metadata. Before implementation, the design must
settle:

- whether manifests are executable Ny, declarative NyData, or a restricted
- whether manifests are executable Ny, declarative NILData, or a restricted
manifest grammar;
- the canonical package and module naming rules;
- semantic-version constraint behavior;
Expand Down
11 changes: 9 additions & 2 deletions docs/standard-library/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ The active tree uses neutral family folders: `nil.std.io` lives under
remain aliases of the same module identities.

The active logical modules are `prelude` and `nil.std.core`, `collections`,
`datetime`, `db`, `diagnostics`, `io`, `math`, `net`, `nydata`, `reflection`, `runtime`,
`datetime`, `db`, `diagnostics`, `io`, `math`, `net`, `nildata`, `reflection`, `runtime`,
`security`, `system`, `text`, and `threading`. Quarantine is broader than parser
failure: an experimental source may compile yet still lack complete language
semantics, an executable provider, or behavioral evidence.
Expand All @@ -68,11 +68,18 @@ packages/ny.ui.mimic/
Other opt-in experiments, including `ny.godot`, also live under
`packages`. `nilaix` is a separate UI/AI integration sandbox.

## NILData

`nil.std.nildata` provides checked, versioned data loading and serialization,
exact integer/decimal tokens, a single array kind, typed accessors and functional
updates. JSON interchange and explicit NyData migration share the same runtime
engine on VM and native routes. See the [NILData contract](nildata.md).

## Current module families

The active tree includes these deliberately scoped families:

- core values and algorithms, collections, text, math, date/time, and NyData
- core values and algorithms, collections, text, math, date/time, and NILData
- Matrix-authored checked array access, bounded fill, overlap-safe copy, and gather
- stable numeric and text index ordering for parallel attribute arrays
- independent deterministic random generators with cloning and finite floating ranges
Expand Down
171 changes: 171 additions & 0 deletions docs/standard-library/nildata.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,171 @@
# NILData

`nil.std.nildata` provides versioned structured data for Ny and Matrix, JSON
interchange, and explicit migration from NyData. A shared runtime engine serves
the command-line converter and every language execution route.

## Format

```nildata
nildata 1
object
name is "Anomalous"
enabled is true
scale is -1.6
modules is an array
item is "shell"
item is "desktop"
end array
metadata is an object
"display name" is "NIL framework"
end object
end object
```

A document is UTF-8, begins with `nildata 1`, and contains exactly one root
value. The version header is required. Keywords are case-sensitive. Statements
occupy separate lines; indentation is for readability. Blank lines and `#`
comments outside quoted text are allowed. Writers use LF and two-space
indentation. Readers also accept CRLF. Root containers may also use `an object` and
`an array`; writers use the shorter root forms.

| Value | Syntax |
| --- | --- |
| Null | `null` |
| Boolean | `true`, `false` |
| Integer | `0`, `-17`, `9007199254740993` |
| Decimal | `-1.6`, `1e400`, `-0.0` |
| Text | `"hello"`, `"line one\nline two"` |
| Object | root `object`, nested `an object`, closed by `end object` |
| Array | root `array`, nested `an array`, closed by `end array` |

Object statements are `key is value`; array statements are `item is value`.
Keys may be ASCII identifiers (`[A-Za-z_][A-Za-z0-9_]*`) or quoted text. Quoted
keys allow spaces, punctuation, empty names and Unicode. Object names are
case-sensitive. Duplicate names, including equivalent escaped names, are errors.
Array entries are ordered, may contain different kinds, and may nest arrays or
objects. Empty blocks are valid. `list` is not a NILData type or keyword.

Numbers use the JSON decimal grammar: optional `-`, integer digits without
leading zeros, an optional fractional part, and an optional signed exponent.
A fraction or exponent identifies a decimal; otherwise the value is an integer.
The exact token is retained, including large integers, exponent spelling and
negative zero. No implicit range limit or floating-point rounding is imposed;
conversion to a language numeric type is a separate checked operation. NaN,
infinity, hexadecimal, a leading `+`, `.5`, and `1.` are rejected.

Text and quoted keys use JSON escapes: `\"`, `\\`, `\/`, `\b`, `\f`, `\n`,
`\r`, `\t` and `\uXXXX` with valid surrogate pairs. Raw control characters and
literal newlines inside quotes are rejected. Escaped newlines preserve exact
content, including blank lines, indentation and text such as `end object`.
`"true"`, `"42"` and `"null"` remain text. There is no interpolation or execution.

Serialization sorts object keys by their UTF-8 byte spelling, preserves array
order and number tokens, and normalizes quoting and indentation. Comments and
original source formatting are not retained. Numeric-key objects are never
reinterpreted as arrays. Repeated normalization is stable; this is not a
cryptographic canonicalization specification.

## Library API

```ny
import nil.std.nildata

fn main() -> i32
let source = "nildata 1\nobject\n name is \"Anomalous\"\nend object\n"
let parsed = loads(source)
if parsed.is_error() then
println(parsed.unwrap_error())
return 1
end if
println(to_json(parsed.unwrap()).unwrap())
return 0
end fn
```

Matrix imports the same module with `read everything from nil.std.nildata`.
Public function names use the usual Matrix hyphen spelling, such as `from-json`
and `array-get`.

`Value` holds `encoded: text`. Treat it as opaque and use the checked functions;
all operations validate it even when a caller constructs a `Value` directly.
Functions return `Result<..., text>` with a diagnostic on failure. They never
return a partially parsed document or silently coerce one kind to another.

| Operation | Successful result |
| --- | --- |
| `loads(text)`, `from_json(text)` | `Value` |
| `dumps(Value)`, `to_json(Value)` | serialized `text` |
| `kind(Value)` | `null`, `boolean`, `integer`, `decimal`, `text`, `object` or `array` as text |
| `numeric_text(Value)` | exact integer/decimal token |
| `as_i64(Value)` | checked signed 64-bit integer; fractions/exponents and overflow fail |
| `text_value(Value)`, `bool_value(Value)` | decoded `text` or `bool`, respectively |
| `size(Value)` | array length or object member count as `i64` |
| `new_object()`, `new_array()`, `null_value()` | new `Value` |
| `string_value(text)`, `boolean_value(bool)` | new `Value` |
| `integer_value(text)`, `decimal_value(text)` | new value from an exact numeric token of that kind |
| `object_has(Value, text)` | `bool` |
| `object_get(Value, text)` | `Option<Value>`; missing key is `None`, explicit null is `Some` |
| `object_key(Value, i64)` | `Option<text>` in sorted key order |
| `object_set(Value, text, Value)` | new object with the member added or replaced |
| `array_get(Value, i64)` | `Option<Value>` |
| `array_append(Value, Value)` | new array with one item appended |
| `array_set(Value, i64, Value)`, `array_remove(Value, i64)` | new array with one existing item replaced or removed |
| `object_remove(Value, text)` | new object with a member removed; absent key is a successful no-op |

Updates return a new value and leave the input unchanged. Missing keys and
nonnegative indexes beyond the end yield `None` for lookup. Negative indexes,
out-of-range update/removal indexes, wrong kinds and malformed values are errors. There is no mutable native handle
to close or keep alive.

Encoded U+0000 can round-trip through documents and JSON. Extracting it as
language text or an enumerated key fails explicitly on both routes, because the
native text ABI cannot represent embedded NUL. Raw NUL arguments are rejected.

## Bounds and diagnostics

Inputs, operation arguments and serialized outputs are limited to 1 MiB each.
A tree contains at most 65,536 values and supports depth 32 below its root.
Combined results of updates are checked against the same limits. JSON and
NILData reject invalid UTF-8, duplicate keys, trailing input and malformed
numbers or escapes. NILData syntax errors identify the failing source line; nested
JSON scalar errors also include their local byte offset. Diagnostic wording
is not a stable machine protocol. Encoding, resource-limit and operation
errors may have no source line.

Values are stored as encoded documents; operations parse and copy them. This
initial API is bounded and deterministic, with no streaming, zero-copy or
constant-time indexing guarantee. For hot loops, extract ordinary language
values once and operate on them directly.

## CLI and migration

```sh
nilcompiler --to-nildata input.json
nilcompiler --to-json input.nildata
nilcompiler --import-nydata legacy-library.nydata
nilcompiler --import-nydata-compiler legacy-compiler.nydata
```

Commands emit a complete document to stdout only after successful conversion.
Inputs must be regular files; symlinks and special files are rejected.
Errors use stderr and a nonzero exit status. `--to-nydata` is retired and reports
the replacement command. New files use `.nildata`; VS Code supplies syntax
highlighting, comments and folding without treating data as executable Matrix.

`import_nydata(text)` reads the old library's single named object/list/field
root. `import_nydata_compiler(text)` wraps the old compiler's top-level named
blocks as object members. Both return `Result<Value, text>`. Legacy fields stay
text; the library importer turns explicit list blocks into arrays, while the
compiler importer rejects list blocks. Numbered objects stay objects. Empty
compiler input represents an empty object. Legacy `#` text is literal, not a
comment.
The compiler dialect never had an unambiguous root-array or scalar encoding,
so a member named `root` remains a member. Legacy indentation/whitespace and
scalar types already discarded by old writers cannot be reconstructed.

Legacy importers require matching complete block endings, reject duplicate
members and reject trailing or unexpected tokens. `loads` accepts versioned
NILData only. Old module imports `nil.std.nydata` and `ny.lang.nydata` are aliases
for `nil.std.nildata`; old `nydata_value` records and `dumps(value, name, indent)`
signatures must migrate to the checked API. No legacy writer is shipped.
Loading
Loading