feat(stdlib): Tiled P0 — XML reader + base64 decode + gzip framing (#67)
All checks were successful
bootstrap / cfree-fixpoint (push) Successful in 20s
ci / build-and-test (push) Successful in 1m43s
commit-lint / conventional-commits (push) Successful in 2s
docs / build-and-deploy (push) Successful in 27s

The three parsing primitives the TMX path needs that were not already in
the tree (zlib inflate + the JSON reader already shipped):

- Xml.* — a minimal, deterministic pure-Ludic XML reader for the
  element/attribute/CDATA subset TMX/TSX/TX use, spliced on demand. Handles
  nested elements, single/double-quoted attributes, text + <![CDATA[…]]>,
  comments, the <?xml?> prolog and <!DOCTYPE>, the five predefined entities
  and numeric character references.
- Base64.* — standard base64 (RFC 4648) decode + a matching pure-Ludic
  encoder; the decoder ignores the whitespace Tiled wraps into <data>.
  Splicing Base64.* also pulls in inflate.ludic so a plain tool can run the
  full base64 -> zlib/gzip decode chain.
- z_gunzip — gzip framing (RFC 1952) over the existing DEFLATE inflater:
  skip the 10-byte header + optional fields, inflate the body, ignore the
  CRC32/ISIZE trailer.

Golden corpus vendored under assets/tiled-fixtures/ (mapeditor/tiled
examples, attributed, + hand-authored multi-encoding fixtures). New
example library/tiled_p0.ludic proves all three (21 assertions); docs
pages + inventory added so check-impl stays green.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
Orkun ÇAKILKAYA 2026-09-01 14:04:49 +03:00
parent 0b149a6876
commit 79776d1f6a
35 changed files with 20549 additions and 18415 deletions

View file

@ -586,6 +586,27 @@ function emit_ns_call(ns: pointer, meth: pointer, e: Node) -> Val {
if (meth == "encode") { bare = "json_encode"; push(labels, "value") }
if (meth == "parse") { bare = "json_parse"; push(labels, "text") }
}
# Xml.* — the minimal XML reader (runtime/native/xml.ludic, spliced on demand).
# parse returns an Xml node; the accessors read tag/text/attributes/children.
if (ns == "Xml") {
if (meth == "parse") { bare = "xml_parse"; push(labels, "text") }
if (meth == "tag") { bare = "xml_tag"; push(labels, "node") }
if (meth == "text") { bare = "xml_text"; push(labels, "node") }
if (meth == "attr") { bare = "xml_attr"; push(labels, "node"); push(labels, "key") }
if (meth == "attr_int") { bare = "xml_attr_int"; push(labels, "node"); push(labels, "key"); push(labels, "dflt") }
if (meth == "has") { bare = "xml_has"; push(labels, "node"); push(labels, "key") }
if (meth == "attr_count") { bare = "xml_attr_count"; push(labels, "node") }
if (meth == "child_count") { bare = "xml_child_count"; push(labels, "node") }
if (meth == "child") { bare = "xml_child"; push(labels, "node"); push(labels, "index") }
if (meth == "find") { bare = "xml_find"; push(labels, "node"); push(labels, "tag") }
if (meth == "count") { bare = "xml_count"; push(labels, "node"); push(labels, "tag") }
}
# Base64.* — standard base64 codec (runtime/native/base64.ludic, spliced on
# demand). decode/encode round-trip through NUL-terminated strings.
if (ns == "Base64") {
if (meth == "decode") { bare = "base64_decode"; push(labels, "src") }
if (meth == "encode") { bare = "base64_encode"; push(labels, "src") }
}
# #62: a package-provided namespace (declared with @Namespace(Foo)) that none
# of the hardcoded core blocks matched — alias Foo.method to the bare function
# foo_method (positional args), the same generic path the core aliases use.

View file

@ -183,6 +183,9 @@ function p_postfix() -> Node {
if e.a.kind == E_ID and e.a.s == "Reflect" { g_uses_reflect = true } # force-emit the reflection ABI (Reflect.* reads the world schema)
if e.a.kind == E_ID and e.a.s == "Light" { g_uses_light = true } # splice the 2D light-accumulation pass on demand
if e.a.kind == E_ID and (e.a.s == "Value" or e.a.s == "Json") { g_uses_value = true } # splice the value tree + JSON on demand (#44)
if e.a.kind == E_ID and e.a.s == "Xml" { g_uses_xml = true } # splice the XML reader on demand (Tiled #67)
if e.a.kind == E_ID and e.a.s == "Base64" { g_uses_base64 = true } # splice base64 codec + inflate on demand (Tiled #67)
if e.a.kind == E_ID and e.a.s == "Tiled" { g_uses_tiled = true } # splice the Tiled map runtime on demand (#69)
if e.a.kind == E_ID and e.a.s == "Reflect" and (e.s == "serialize" or e.s == "apply") { g_uses_value = true; g_uses_reflect_io = true } # Reflect.serialize/apply -> value tree + world table
# Input.* action-map / record-replay methods (#7) -> splice input.ludic.
# Input.key stays bare (no runtime), so gate on the new methods only.
@ -433,6 +436,9 @@ var g_uses_query: bool = false # a program mentioned Query.* -> splice the qu
var g_uses_reflect: bool = false # a program mentioned Reflect.* -> force-emit the reflection ABI
var g_uses_light: bool = false # a program mentioned Light.* -> splice the 2D light pass
var g_uses_value: bool = false # Value.*/Json.*/Reflect.serialize -> splice the value tree + JSON (#44)
var g_uses_xml: bool = false # Xml.* -> splice the XML reader (Tiled #67)
var g_uses_base64: bool = false # Base64.* -> splice the base64 codec + inflate (Tiled #67)
var g_uses_tiled: bool = false # Tiled.* -> splice the Tiled map runtime (#69)
var g_uses_reflect_io: bool = false # Reflect.serialize/apply -> splice the reflection serializer
var g_uses_esys: bool = false # an engine-owned system component (SpriteAnim/Motion/Light2D) is declared -> splice systems.ludic + force the reflection ABI
var g_uses_input: bool = false # a program used Input.bind/down/poll/… (action maps + record/replay) -> splice input.ludic
@ -712,6 +718,34 @@ function maybe_splice_runtime() -> void {
do_import("runtime/native/value.ludic")
cur_dir = saved
}
# Xml.* (#67) — the minimal pure-Ludic XML reader for the TMX/TSX/TX subset.
# Self-contained (string/slice ops only), so it works in a plain tool too.
if g_uses_xml {
cur_dir = ""
do_import("runtime/native/xml.ludic")
cur_dir = saved
}
# Base64.* (#67) — base64 codec; pull in the DEFLATE inflater alongside it, so
# a plain tool can run the full base64 -> zlib/gzip decode chain (inflate.ludic
# is self-contained; do_import dedupes when a game already linked it via core).
if g_uses_base64 {
cur_dir = ""
do_import("runtime/native/inflate.ludic")
do_import("runtime/native/base64.ludic")
cur_dir = saved
}
# Tiled.* (#69) — the Tiled map runtime: model, GID resolver, loader, draw. It
# reads/writes the tilemap + framebuffer, so it links against core.ludic, and
# it consumes the XML/base64/inflate primitives above.
if g_uses_tiled {
cur_dir = ""
do_import("runtime/native/core.ludic")
do_import("runtime/native/xml.ludic")
do_import("runtime/native/base64.ludic")
do_import("runtime/native/value.ludic")
do_import("runtime/native/tiled.ludic")
cur_dir = saved
}
# Reflect.serialize/apply add the reflection serializer, which stands on both
# the value tree (above) and the world table (force-emitted for Reflect.*).
if g_uses_reflect_io {
@ -821,6 +855,9 @@ function parse_program() -> void {
g_uses_input = false
g_uses_light = false
g_uses_value = false
g_uses_xml = false
g_uses_base64 = false
g_uses_tiled = false
g_uses_reflect_io = false
g_tests = new []Node
g_mod_sys_fn = new []pointer

File diff suppressed because it is too large Load diff