diff --git a/README.md b/README.md index e69de29..b867b01 100644 --- a/README.md +++ b/README.md @@ -0,0 +1,129 @@ +
+
+
+ A small, fast language. It looks like Go, runs like C, and you never write anything low-level. +
+ +--- + +Dino compiles to C and then to a native program. There is no garbage collector, no pointers +and no manual memory: you write plain code and the compiler works out the rest. + +```dino +enum Shape { + Circle(r: float) + Rect(w, h: float) +} + +func area(s: Shape): float { + return match s { + Circle(r) => 3.14 * r * r + Rect(w, h) => w * h + } +} + +func parse_age(text: string): (int, error) { + var n, err = text.to_int() + if err != nil { return 0, err } + if n < 0 { return 0, error("age cannot be negative") } + return n, nil +} + +func main() { + var shapes = [Shape.Circle(1.0), Shape.Rect(2.0, 3.0)] + for s in shapes { print(area(s)) } + + var counts: map[string, int] = {} + for word in "the cat and the hat".split(" ") { counts[word] += 1 } + print(counts) + + var age, err = parse_age("-4") + if err != nil { print("error:", err) } +} +``` +```text +3.14 +6.0 +{the: 2, cat: 1, and: 1, hat: 1} +error: age cannot be negative +``` + +## Why Dino + +- **Simple syntax.** `var`, `func`, `for`, `match`. One loop keyword, no semicolons, no + parentheses around conditions. Types are inferred. +- **Fast.** Your code becomes C and is built by `cc`, so it runs at native speed. +- **Safe memory without the work.** Values are copied, not shared by accident. Mutation is + worked out for you. `shared` and `weak` exist for the few times you need a graph or a cache. +- **Errors you can see.** A function that can fail returns `(T, error)`. A value that may be + missing is `T?`. Both must be handled. +- **Modern basics.** Enums that carry data, exhaustive `match`, generics, interfaces, + closures, maps, characters, modules. +- **Tooling included.** A formatter, a language server, and editor files, all in the one `dino` + program. + +## Get started + +You need a [Rust toolchain](https://rustup.rs) to build the compiler and a C compiler +(`gcc` or `clang`, available as `cc`) to build your programs. Dino itself has no dependencies. + +```text +cargo build --release +cp target/release/dino ~/.local/bin/ # or anywhere on your PATH +``` + +Save this as `hello.dino`: + +```dino +func main() { + print("Hello, Dino!") +} +``` + +```text +dino run hello.dino +``` + +| Command | What it does | +|---------|--------------| +| `dino run file.dino [args...]` | Compile and run. Extra words reach the program as `os.args`. | +| `dino build file.dino -o out` | Make an executable you can keep. | +| `dino check file.dino` | Look for errors without building. | +| `dino emit-c file.dino` | Print the generated C. | +| `dino fmt [--check] path...` | Format code (`--check` only reports). | +| `dino lsp` | Start the language server (editors run this for you). | + +## Learn the language + +The [`docs/`](docs/README.md) folder is a short course, written to be read in order: +first steps, values, control flow, functions, lists and maps, structs and enums, errors, +memory, generics and interfaces, modules, and a full cheatsheet. Every example in it is run by +the test suite, so what you read is what happens. + +The last chapter builds a calculator over five files. It lives in +[`examples/calc`](examples/calc), next to many smaller programs in +[`examples/basics`](examples/basics). + +For the exact rules of the language, see [`SPEC.md`](SPEC.md). + +## Editors + +Syntax colours for VS Code and Vim/Neovim live in [`editors/`](editors/README.md). The language +server gives you error underlines as you type, format on save, an outline, go to definition, +hover, completion and parameter hints in any editor that speaks LSP. + +## Project layout + +| Path | What is there | +|------|---------------| +| `src/` | The compiler: lexer, parser, checker, C generator, formatter, language server | +| `tests/` | The test suite (programs are compiled and run with leak checking) | +| `docs/` | The course | +| `examples/` | Programs to read and run | +| `editors/` | VS Code and Vim files, and setup notes | + +Run the tests with `cargo test`.