refactor(lang): rename the fn keyword to function

Expand the function-declaration keyword to the full word across the whole
language and toolchain:
  fn name(...) -> T { ... }   ->   function name(...) -> T { ... }

Done as a self-hosting migration: teach the parser both spellings, reseed,
rewrite every .ludic definition to `function`, then drop `fn`. The compiler
now rejects `fn`. Touches the parser, all selfhost/tools/runtime/example/test
sources, the grammars (TextMate shared+vscode, ludic_syntax.h, JetBrains
LudicTokens.kt), the LSP and formatter, the Python doc/vocab tools
(check-impl, check-docs, validate, palette, test-lsp), and the docs
(fences, prose, kw-fn -> kw-function).

Reseeded; C-free bootstrap fixpoint holds. All suites green (45 regression,
24 self-host, 29 tool); the docs site generates and check.py passes.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
Orkun ÇAKILKAYA 2026-08-30 01:43:22 +03:00
parent 2f19c8d8e2
commit 4c48077d68
86 changed files with 793 additions and 793 deletions

View file

@ -13,7 +13,7 @@
# ---- file IO ----------------------------------------------------------------
# read a whole file into a fresh NUL-terminated buffer (null if it cannot open)
fn read_file(path: ptr) -> ptr {
function read_file(path: ptr) -> ptr {
let f = file_open(path, "rb")
if (f == null) { return null }
file_seek(f, 0, 2)
@ -27,7 +27,7 @@ fn read_file(path: ptr) -> ptr {
}
# overwrite `path` with `s`; returns false if it could not be opened
fn write_file(path: ptr, s: ptr) -> bool {
function write_file(path: ptr, s: ptr) -> bool {
let f = file_open(path, "wb")
if (f == null) { return false }
file_write(f, s, len(s))
@ -35,22 +35,22 @@ fn write_file(path: ptr, s: ptr) -> bool {
return true
}
fn file_exists(path: ptr) -> bool { return shq(`test -e {path}`) }
fn is_exec(path: ptr) -> bool { return shq(`test -x {path}`) }
function file_exists(path: ptr) -> bool { return shq(`test -e {path}`) }
function is_exec(path: ptr) -> bool { return shq(`test -x {path}`) }
# is `a` newer than `b` (like the shell's `-nt`)?
fn newer(a: ptr, b: ptr) -> bool { return shq(`test {a} -nt {b}`) }
function newer(a: ptr, b: ptr) -> bool { return shq(`test {a} -nt {b}`) }
# ---- process control --------------------------------------------------------
# `run` returns the raw wait status; the program's exit code is the high byte.
fn exit_code(st: int) -> int { return (st >> 8) & 255 }
function exit_code(st: int) -> int { return (st >> 8) & 255 }
# run a command, returning its exit code (0 = success)
fn sh(cmd: ptr) -> int { return exit_code(run(cmd)) }
function sh(cmd: ptr) -> int { return exit_code(run(cmd)) }
# run a command, true when it succeeded
fn shq(cmd: ptr) -> bool { return exit_code(run(cmd)) == 0 }
function shq(cmd: ptr) -> bool { return exit_code(run(cmd)) == 0 }
# run `cmd` and return its stdout (stderr discarded). Never null.
fn capture(cmd: ptr) -> ptr {
function capture(cmd: ptr) -> ptr {
let tmp = "/tmp/x_capture.out"
run(`{cmd} > {tmp} 2>/dev/null`)
let s = read_file(tmp)
@ -60,16 +60,16 @@ fn capture(cmd: ptr) -> ptr {
# run `cmd`, join its output lines with single spaces and trim — the Ludic twin
# of the shell idiom `$(cmd | tr '\n' ' ' | sed 's/ *$//')`.
fn capture_line(cmd: ptr) -> ptr {
function capture_line(cmd: ptr) -> ptr {
return capture(`{cmd} | tr '\n' ' ' | sed 's/ *$//'`)
}
# the last line of a command's output (for one-line error messages)
fn capture_tail(cmd: ptr) -> ptr {
function capture_tail(cmd: ptr) -> ptr {
return capture(`{cmd} 2>&1 | tail -1`)
}
fn getenv_or(name: ptr, dflt: ptr) -> ptr {
function getenv_or(name: ptr, dflt: ptr) -> ptr {
let v = getenv(name)
if (v == null) { return dflt }
return v
@ -78,40 +78,40 @@ fn getenv_or(name: ptr, dflt: ptr) -> ptr {
# ---- stdout helpers ---------------------------------------------------------
# write `s` with no trailing newline (print() always adds one)
fn out(s: ptr) -> void { file_write(file_stdout(), s, len(s)) }
fn err(s: ptr) -> void { file_write(file_stderr(), s, len(s)) }
function out(s: ptr) -> void { file_write(file_stdout(), s, len(s)) }
function err(s: ptr) -> void { file_write(file_stderr(), s, len(s)) }
# an ESC byte — the lexer has no \033, so build it by hand
fn esc() -> ptr { let b = bytes(2); b[0] = 27; b[1] = 0; return b }
fn c_green() -> ptr { return esc() + "[32m" }
fn c_red() -> ptr { return esc() + "[31m" }
fn c_reset() -> ptr { return esc() + "[0m" }
function esc() -> ptr { let b = bytes(2); b[0] = 27; b[1] = 0; return b }
function c_green() -> ptr { return esc() + "[32m" }
function c_red() -> ptr { return esc() + "[31m" }
function c_reset() -> ptr { return esc() + "[0m" }
# ---- the PASS/FAIL test harness ---------------------------------------------
var PASS: int = 0
var FAIL: int = 0
fn ok(msg: ptr) -> void {
function ok(msg: ptr) -> void {
PASS = PASS + 1
print(` {c_green()}PASS{c_reset()} {msg}`)
}
fn bad(msg: ptr) -> void {
function bad(msg: ptr) -> void {
FAIL = FAIL + 1
print(` {c_red()}FAIL{c_reset()} {msg}`)
}
fn bad2(msg: ptr, detail: ptr) -> void {
function bad2(msg: ptr, detail: ptr) -> void {
bad(msg)
print(` {detail}`)
}
# assert two strings equal, reporting the mismatch
fn check(label: ptr, got: ptr, want: ptr) -> void {
function check(label: ptr, got: ptr, want: ptr) -> void {
if (got == want) { ok(label) }
else { bad2(label, `expected [{want}] got [{got}]`) }
}
# print the "== N passed, M failed ==" footer and return the process exit code
fn report() -> int {
function report() -> int {
print("")
print(`== {str(PASS)} passed, {str(FAIL)} failed ==`)
if (FAIL == 0) { return 0 }