ludic/examples/networking/net_echo.ludic
Orkuncakilkaya b0b0b62bce feat(lang): L7 memory is safe unless it says unsafe
The typed buffers are slices: words/floats/fixeds/doubles/pointers(n) make
zeroed, bounds-checked []int/[]float/... and the type names mean them. buffer(n)
is a []byte, with text_of, Fs.read_bytes/write_bytes and view(xs, start, n).
bytes(), indexing a raw pointer or bytes, free, resize, Memory.*, raw file calls,
data_of and C externs are refused outside unsafe { } / unsafe function, and a
project's own files may write unsafe only with --unsafe; the runtime and packages
are the platform. A slice passed to an extern goes as its data.

What the change found: Sync's atomics on a slice header, words(n) uninitialised,
input's fixed axes in ints, truetype's fixed outlines as ints, skin matrices
typed int, gl_shader's source table made from raw bytes. render3d gets safe
entry points (safe_api.ludic). Rendering is byte-identical; a frame costs the same.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-24 12:53:27 +03:00

26 lines
1.1 KiB
Text

# net_echo.ludic — N0: the transport seam (NETWORKING-DESIGN §5, §13 N0).
#
# The transport is two calls — net_send puts a datagram on the wire, net_poll
# takes the next one off. A production build binds them to a real socket with
# `extern fn net_send/net_poll` (UDP native, WebRTC/WebSocket wasm); absent that,
# the compiler supplies a built-in in-process loopback, so a program is networked
# end to end with NO foreign host — pure Ludic. This sends four bytes and polls
# them back through the loopback: prints 4, then 10 20 30 42.
program NetEcho {
entry {
unsafe { # raw buffers on purpose: built with --unsafe (L7)
let out = bytes(4)
out[0] = '\n'
out[1] = 20
out[2] = 30
out[3] = '*'
net_send(0, out, 4) # onto the wire (the built-in loopback)
let inb = bytes(64)
let n = net_poll(inb, 64) # take the next datagram back off
print(n) # 4
var i = 0
while i < n { print(inb[i]); i += 1 } # 10 20 30 42
}
}
}