Task guides
Each guide reaches one goal: the steps, the code, and what to watch out for. If you haven't built a program yet, start with Get started; for a longer walk through one program, the tutorial builds a quiz step by step.
Text and input
- Read input from the user: read a line into a buffer with
In.ReadLine, and handle the end of input, lines that don't fit, and numbers. - Format text:
$"..."with alignment and number formats, written to stdout, into an arena string or into aStrBuilder. - Keep a string: copy a line or a scratch result into an arena that lives long enough, and collect such strings in a list or map.
Memory and collections
- Choose a collection:
List,Dict,RefList,StrDictorRefDict, keys for objects, and copying a collection into another arena. - Query data without allocating:
Where,Select,Sumand query syntax over spans withlib/Seq.cs, tuples instead of anonymous types, and checking that a loop allocates nothing. - Pass structs by reference: allocate a struct in an arena, pass it with
refandin, return a ref, and keep the ref from outliving a list's buffer or an arena scope. - Catch arena mistakes: turn on
Arena.DebugChecks, name your arenas, and see what the library stops the program for.
Targets
- Build for WebAssembly: the toolchain, building and running a WASI module, and what differs from the native build.
- Build for DOS: the toolchain, the emulators, memory, input from a file, and running a program on a real machine.
- Draw on the VGA screen: graphics mode, colors, drawing a frame without flicker, and reading the keyboard under DOS.
Speed
- Use SIMD:
Vector128andVector256without run-time CPU detection, the-mflags, and the ready-made kernels inlib/Kernels.cs. - Run a loop in parallel:
Parallel.Forover every processor, sharing a total withInterlocked, and one arena per thread. - Run a language model: a small Llama-style model, compiled into the program, telling stories on every target, DOS included.