feat(reflect): generic value tree + Reflect.serialize/apply + JSON bridge (#44)
A self-describing Value node (null/int/fixed/bool/str/list/object) with constructors, builders (Value.add/put) and accessors (get/at/count/kind/ as_int/as_str/…). Reflect.serialize(entity) walks an entity's whole component set into a value tree — one member per component, each a sub-object of its fields — and Reflect.apply(entity, value) writes one back; a fixed field becomes a fixed node, everything else an int node, so the round-trip is bit-exact, with the model id under "@kind". Json.encode/parse bridge the tree to and from compact, stable, diffable text, with fixed written as an exact terminating decimal that parses back bit-for-bit (verified across the raw Q16.16 range). Together: a one-call, bit-exact save/load for entities. Written in Ludic and spliced on demand (runtime/native/value.ludic + reflect_io.ludic, like Query/Light), so a program that doesn't touch Value.*/Json.*/Reflect.serialize compiles byte-identically and the C-free bootstrap fixpoint holds (verified). The general tagged-union/any language type stays tracked in #1; this ships the concrete value tree the serializer needs. Adds 21 namespace-method docs pages + Value/Json sections, examples/library/serialize.ludic, and a regression case. Whole CI set green: x test 72/72, x test-tools 30/30, check-impl/vocabulary/docs. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
parent
0d1b09e4f0
commit
9452557f3c
31 changed files with 16753 additions and 14898 deletions
7
docs/language/json/_section.md
Normal file
7
docs/language/json/_section.md
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
---
|
||||
id: json
|
||||
title: Json
|
||||
order: 36
|
||||
---
|
||||
|
||||
The text bridge over the <a href="value"><code>Value</code></a> tree: <a href="json-encode"><code>Json.encode</code></a> turns a value tree into compact, stable JSON text and <a href="json-parse"><code>Json.parse</code></a> reads it back. Together with <a href="reflect-serialize"><code>Reflect.serialize</code></a>/<a href="reflect-apply"><code>Reflect.apply</code></a> this is a one-call, bit-exact save/load for entities, and a diffable on-disk format for tooling. Determinism holds: the same tree always encodes to the same bytes.
|
||||
14
docs/language/json/json-encode.md
Normal file
14
docs/language/json/json-encode.md
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
---
|
||||
id: json-encode
|
||||
name: Json.encode
|
||||
category: json
|
||||
kind: namespace-method
|
||||
tokens: Json.encode
|
||||
sig: Json.encode(value) -> string
|
||||
tip: Serialize a value tree to compact JSON text.
|
||||
order: 1
|
||||
ns: Json
|
||||
member: encode
|
||||
---
|
||||
|
||||
Walks a value tree and returns compact JSON text. <code>int</code> nodes become integers, <code>fixed</code> nodes an exact decimal, <code>bool</code> <code>true</code>/<code>false</code>, <code>str</code> a quoted (escaped) string, and lists/objects the usual <code>[…]</code>/<code>{…}</code> — object members keep insertion order, so the output is stable and diffable. The inverse is <a href="json-parse"><code>Json.parse</code></a>; together with <a href="reflect-serialize"><code>Reflect.serialize</code></a> this is a one-call save.
|
||||
14
docs/language/json/json-parse.md
Normal file
14
docs/language/json/json-parse.md
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
---
|
||||
id: json-parse
|
||||
name: Json.parse
|
||||
category: json
|
||||
kind: namespace-method
|
||||
tokens: Json.parse
|
||||
sig: Json.parse(text: string) -> value
|
||||
tip: Parse JSON text into a value tree.
|
||||
order: 2
|
||||
ns: Json
|
||||
member: parse
|
||||
---
|
||||
|
||||
Parses JSON <code>text</code> into a value tree — the inverse of <a href="json-encode"><code>Json.encode</code></a>. Numbers with a decimal point become <code>fixed</code> nodes (recovered bit-for-bit from a value written by <code>Json.encode</code>), whole numbers <code>int</code> nodes. It is a lean, best-effort reader for trusted saves, not a validating parser; feed a parsed object to <a href="reflect-apply"><code>Reflect.apply</code></a> to load it into an entity.
|
||||
Loading…
Add table
Add a link
Reference in a new issue