Skip to content

Latest commit

 

History

History

docs

README.md

Cinder by Example

Cinder is a small systems language with C compatibility, ?T optionals, !T errors, slices, and an LLVM backend.

This guide teaches Cinder through complete, runnable programs. Each page shows a program and its output.

Table of Contents

  1. Hello, World
  2. Variables
  3. Types and Literals
  4. Functions
  5. Control Flow
  6. Structs
  7. Enums
  8. Arrays and Slices
  9. Optionals and Errors
  10. defer
  11. Compile-Time Code
  12. Pointers
  13. Function Pointers
  14. Calling C: extern and FFI
  15. Modules
  16. The Standard Library
  17. Bare Metal: Writing a Kernel

Building and Running

The compiler is ./cinder (a wrapper around main.rb). It needs Ruby and an LLVM toolchain (llvm-as, llc, as, cc).

./cinder check hello.cnd            # parse and type-check only
./cinder build hello.cnd --emit=bin -o hello    # native executable
./hello                              # run it

Pass --mode=release for optimized builds.

The examples in this guide are checked automatically by test/docs_test.rb. If an example stops compiling, the test suite fails.

Conventions Used in This Guide

  • Every program starts with use "std/io.cnd"; when it prints.
  • fn main() -> i32 is the entry point; its return value is the exit code.
  • Output blocks show the expected result of the preceding program.
  • Code fragments (no fn main) illustrate one idea and are not runnable alone.