feat(stdlib): add Fs.* / Path.* / Mime.* — filesystem, paths, content types (#10)
All checks were successful
docs / build-and-deploy (push) Successful in 2s

A cohesive filesystem & IO library — the foundation for saves, config, mods, and
asset loading — wrapping the bare file_* builtins into one safe, ergonomic API a
non-expert can use without touching a file descriptor or a byte buffer.

  Path.*  join / dir / base / ext / stem / normalize   (pure lexical string ops)
  Fs.*    exists / is_dir / read_text / write_text / append_text / remove /
          size / mkdir / copy / list
  Mime.*  of (extension table) / sniff (magic bytes: PNG/JPEG/GIF/PDF)

Pure string IR for Path.*; libc (fopen/access/mkdir/rename/opendir…) for Fs.*;
C-free, emitted on demand (g_uses_fsrt). Safety and determinism baked in:
- write_text and copy are atomic (write a temp file, then rename over the target)
  so a crash mid-write never corrupts the previous file;
- mkdir creates parents (mkdir -p);
- list is sorted for a stable, reproducible directory walk;
- fallible calls return values (null / false / -1), never crashes — ready for a
  first-class try/else when the error-handling work lands.

Complements Os.* (#21): Os supplies per-user locations, Fs the operations. v1
targets the native macOS/BSD filesystem with "/" separators; Windows separators,
a sandboxed wasm virtual FS, recursive directory copy, and richer magic-byte
sniffing are documented follow-ups.

- examples/library/fs.ludic: 32 assertions across pure Path ops (incl. normalize
  resolving ./ .. and duplicate slashes), a real create/read/append/copy/list/
  remove cycle under build/, and Mime by-extension + by-magic (GIF signature vs a
  .bin extension). Wired into `x test` (now 56 passed).
- docs: new Path, Fs, and Mime sections + 18 per-symbol pages; inventory updated;
  every fence passes check-docs; site builds via docgen.
- seed regenerated; `x bootstrap-cfree` fixpoint holds.

Closes #10

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
Orkun ÇAKILKAYA 2026-08-30 22:43:50 +03:00
parent bad6cd1ac9
commit dd4f5a26ad
30 changed files with 14298 additions and 10448 deletions

View file

@ -0,0 +1,9 @@
---
id: path
title: Path
order: 6
---
Path manipulation as pure string operations — no disk access, no allocation surprises, just the joining and splitting every save system, mod loader, and asset pipeline needs. Separate a filename from its folder, get an extension, join segments without worrying about doubled or missing separators, and collapse <code>.</code>/<code>..</code>/duplicate slashes into a canonical form.
Paths use <code>/</code> as the separator, matching the native (macOS/BSD) filesystem — the fully supported target today; Windows-style separators are a follow-up. Pair these with <a href="ns-Os"><code>Os</code></a> (which supplies per-user directory *locations*) and <a href="ns-Fs"><code>Fs</code></a> (which does the actual reading and writing).

View file

@ -0,0 +1,25 @@
---
id: path-base
name: Path.base
category: path
kind: namespace-method
tokens: Path.base
sig: Path.base(p) -> string
tip: The final component of a path.
order: 3
ns: Path
member: base
---
Returns the final component — the file or last directory name — after the last <code>/</code>. A path with no separator is returned unchanged. The complement of <a href="path-dir"><code>dir</code></a>.
Parameters:
- `p` — the path
```ludic
program Base {
entry {
if Path.base("mods/foo/data.json") == "data.json" { print(1) }
}
}
```

View file

@ -0,0 +1,25 @@
---
id: path-dir
name: Path.dir
category: path
kind: namespace-method
tokens: Path.dir
sig: Path.dir(p) -> string
tip: The directory part of a path.
order: 2
ns: Path
member: dir
---
Returns everything before the last <code>/</code> — the containing directory. A path with no separator yields <code>"."</code> (the current directory); the root <code>/</code> stays <code>/</code>.
Parameters:
- `p` — the path
```ludic
program Dir {
entry {
if Path.dir("mods/foo/data.json") == "mods/foo" { print(1) }
}
}
```

View file

@ -0,0 +1,25 @@
---
id: path-ext
name: Path.ext
category: path
kind: namespace-method
tokens: Path.ext
sig: Path.ext(p) -> string
tip: The file extension, including the dot.
order: 4
ns: Path
member: ext
---
Returns the extension of the final component, including the leading dot (e.g. <code>".json"</code>), or the empty string when there is none. A leading-dot name (a dotfile like <code>.gitignore</code>) has no extension.
Parameters:
- `p` — the path
```ludic
program Ext {
entry {
if Path.ext("hero.png") == ".png" { print(1) }
}
}
```

View file

@ -0,0 +1,26 @@
---
id: path-join
name: Path.join
category: path
kind: namespace-method
tokens: Path.join
sig: Path.join(a, b) -> string
tip: Join two path segments with the separator.
order: 1
ns: Path
member: join
---
Joins two path segments with a single <code>/</code>, inserting one only when needed (so <code>join("a/", "b")</code> and <code>join("a", "b")</code> both give <code>a/b</code>). If <code>b</code> is absolute it wins; if either side is empty the other is returned.
Parameters:
- `a` — the leading path
- `b` — the trailing path or filename
```ludic
program Join {
entry {
if Path.join("mods", "foo.ludic") == "mods/foo.ludic" { print(1) }
}
}
```

View file

@ -0,0 +1,25 @@
---
id: path-normalize
name: Path.normalize
category: path
kind: namespace-method
tokens: Path.normalize
sig: Path.normalize(p) -> string
tip: Collapse . / .. / duplicate separators.
order: 6
ns: Path
member: normalize
---
Canonicalizes a path lexically (without touching disk): duplicate separators collapse, <code>.</code> segments drop, and <code>..</code> pops the preceding segment. An absolute path never rises above its root. The result is stable, so it is a good key for comparing or sandboxing paths.
Parameters:
- `p` — the path
```ludic
program Normalize {
entry {
if Path.normalize("a/./b/../c") == "a/c" { print(1) }
}
}
```

View file

@ -0,0 +1,25 @@
---
id: path-stem
name: Path.stem
category: path
kind: namespace-method
tokens: Path.stem
sig: Path.stem(p) -> string
tip: The final component without its extension.
order: 5
ns: Path
member: stem
---
Returns the final component with its extension removed — the "stem". Useful for deriving an id or a sibling filename. <code>stem("mods/foo/data.json")</code> is <code>"data"</code>.
Parameters:
- `p` — the path
```ludic
program Stem {
entry {
if Path.stem("data.json") == "data" { print(1) }
}
}
```