Quick Start Guide
Get up and running with Neuro in 5 minutes.
Prerequisites
Ensure you have completed the Installation Guide before proceeding.
Your First Command
Check that the compiler is installed:
cargo run -p neurc -- --versionOr if you installed it globally:
neurc --versionChecking a Program
Neuro can validate syntax and types without compiling:
cargo run -p neurc -- check examples/basics/hello.nrExpected output:
Type checking passed for "examples/basics/hello.nr" (1 module(s), 11 HIR items)
Compiling a Program
Compile a Neuro program to a native executable:
cargo run -p neurc -- compile examples/basics/hello.nrThe compiler prints the paths it produced:
Successfully compiled examples/basics/hello.nr -> examples/basics/hello
On Windows the executable is examples\basics\hello.exe; on Unix it is examples/basics/hello.
Running the Executable
Execute the compiled program:
# Windows
.\examples\hello.exe
# Unix
./examples/helloCheck the exit code:
# Windows (PowerShell)
echo $LASTEXITCODE
# Unix
echo $?The hello.nr program returns 26.
A program reports a result two ways, and every example in this repository is verified
on both. main's i32 becomes the exit code, pinned in
examples/expected.txt; whatever the program writes to
standard output is pinned byte for byte in a sibling .out file. For text, print and
println write to standard output:
func main() -> i32 { val name: string = "Neuro" print("hello from ") println(name) return 0}hello from Neuro
Each takes one string, and interpolation renders the holes before the call, so
println("phase {n} of {total}") needs no format arguments. See
examples/basics/greeting.nr for a runnable version
and the functions reference
for the full contract.
Understanding the Examples
hello.nr
The source of examples/basics/hello.nr:
func add(a: i32, b: i32) -> i32 { return a + b} func calculate(x: i32) -> i32 { val doubled: i32 = x * 2 val result: i32 = doubled + 10 return result} func main() -> i32 { val x: i32 = 5 val y: i32 = 3 val sum: i32 = add(x, y) val calculated: i32 = calculate(sum) return calculated}Features demonstrated:
- Function definitions with parameters and return types
- Calling functions and chaining their results
- Immutable variables (
val) - Integer arithmetic
returnstatements (the program exits with the valuemainreturns, here26)
milestone.nr
The source of examples/basics/milestone.nr:
func add(a: i32, b: i32) -> i32 { return a + b} func main() -> i32 { val result = add(5, 3) return result}Features demonstrated:
- Multiple functions in one file
- Function calls with arguments
- Type inference:
resultgets its type from the call's return type
Compile and run:
cargo run -p neurc -- compile examples/basics/milestone.nr
# Windows
.\examples\milestone.exe
# Unix
./examples/milestoneExit code: 8
CLI Options
Check Command
neurc check <file.nr>Validates syntax and types without generating code. Fast feedback for development.
Compile Command
neurc compile <file.nr> [options]Options:
-o, --output <FILE>- Specify output executable path (default: the input filename without its extension,.exeon Windows)-O, --optimization <0-3>- Optimization level (default:0)
Examples:
# Default output (same name as source)
neurc compile examples/basics/hello.nr
# Custom output path
neurc compile examples/basics/hello.nr -o bin/my_program
# Optimized build
neurc compile -O2 examples/basics/hello.nr
# Compile from a different directory
neurc compile ../path/to/program.nrError Messages
Errors print to stderr and the compiler exits with code 1.
Syntax Error Example
Source (bad.nr):
func main() -> i32 { val x: i32 =}Error output:
Error: Module error: failed to parse module `bad.nr`: unexpected token RightBrace, expected expression
Type Error Example
Source (mismatch.nr):
func main() -> i32 { val x: i32 = true return x}Error output:
Type errors found in "mismatch.nr":
1. type mismatch at Span { start: 25, end: 42 }: expected i32, found bool
Error: 1 type error(s) found
Development Workflow
- Write your Neuro code in a
.nrfile - Check syntax and types:
neurc check program.nr - Compile to executable:
neurc compile program.nr - Run the program:
./program(Unix) or.\program.exe(Windows) - Iterate - fix errors and repeat
Recommended Workflow
For faster iteration during development:
# Check only (faster, no code generation)
neurc check program.nr
# When ready, compile and run
neurc compile program.nr && ./programDebug Logging
Enable debug output to see compilation stages:
# Windows (PowerShell)
$env:RUST_LOG="debug"
neurc compile examples/basics/hello.nr
# Unix
RUST_LOG=debug neurc compile examples/basics/hello.nrThis shows each stage as it runs: module resolution and parsing, type checking, HIR lowering, LLVM IR and object-code generation, and linking.
Current Feature Summary
Per-sub-phase status lives in the Quick Roadmap. The current compiler supports:
Types
- Integers:
i8,i16,i32,i64,u8,u16,u32,u64 - Floats:
f16,bf16,f32,f64 - Boolean:
bool;char(32-bit Unicode scalar) - Strings: fat-pointer
stringwith escape sequences (\n,\t,\",\\,\xNN,\u{NNNN});==/!=byte-level comparison;+concatenation;.len()/.clone()/.slice(a..b)(bytes) /.char_slice(a..b)(code points);.chars()iterates the scalars andfor (offset, c) in s.char_indices()binds each one's byte offset - Structs: user-defined types with nominal typing
- Fixed-size arrays
[T; N], tuples(T1, T2, ...), enums with associated data,newtype,typealiases
Variables & Constants
- Immutable variables:
val x: i32 = 10 - Mutable variables:
mut counter: i32 = 0 - Variable reassignment:
counter = counter + 1 - Compile-time constants:
const MAX: i32 = 100at module and function scope - Contextual numeric literal inference (e.g.
val n = 42infersi32)
Functions
- Function definitions with typed parameters
- Explicit
returnstatements - Expression-based implicit returns (trailing expression)
- Recursion and forward references
implblocks with&self/&mut selfmethods andTypeName::funcassociated functions- Generic functions, structs and impls with enforced trait bounds, const generics,
whereclauses, turbofish - Closures and lambdas
|x: i32| x * x; function type(T1, ...) -> R; higher-order functions
Traits & Dispatch
traitdeclarations with required and default methods;impl Trait for Type- Static dispatch via
impl Traitand trait-bounded generics (monomorphized) - Dynamic dispatch via
&dyn Trait(vtable-backed) - Operator overloading through the compiler-known operator traits
Ownership
- Move-by-default with use-after-move detection;
@derive(Copy, Clone);.clone() - Immutable
&Tand mutable&mut Tborrows with*deref; flow-sensitive borrow exclusivity - Explicit lifetime annotations
<'a>; returned-reference lifetime elision - Deterministic
Droprunning at scope exit in reverse declaration order
Control Flow
if/else if/elsechains;ifand blocks as value expressionswhileloops;loop(including as a value expression)- Range-for loops:
for i in 0..n(exclusive) andfor i in 0..=n(inclusive) for x in eover any type implementing the prelude'sIntoIterator/Iteratorprotocol, adapters includedbreakandcontinue, with value-carrying breaks and loop labelsmatchas an exhaustive expression with payload binding, or-patterns, ranges, and guardspanic(msg)/assert(cond)/unreachable()
Operators
- Arithmetic:
+,-,*,/,% - Comparison:
==,!=,<,>,<=,>= - Logical:
&&,||,! - Bitwise:
&,|,^,~,<<(integer types only) - Compound assignment:
+=,-=,*=,/=,%= - Type cast:
asfor numeric conversions and bool-to-int - Coalescing:
??unwraps anOption/Result, else evaluates a lazy fallback - Propagation:
expr?unwraps anOption/Result, else returns the failure to the caller
Modules
- A program may span several files: every
.nrfile is a module, and a directory holding amod.nris a module with children. You compile the root import math,import ./utils::io,import math::{sqrt, sin},asrenames, module aliases, variant imports, andexport importre-export facades- Inline
module Name { ... }blocks group items inside one file, under the same rules - Declarations and struct fields are private to their module until
exportopts them in - An implicit prelude puts
Option,Result, andSome/None/Ok/Errin scope in every file with noimport;@no_preludeon a file's first line opts out - Named arguments:
connect("localhost", port: 8080), in any order after the positional ones. A parameter declaredexternal internal: Trequires the external name at the call site; one declared_ internal: Tis positional-only - Triple-quoted
"""block strings dedented to the closing delimiter's column, and block comments that nest
Common Issues
Compilation succeeds but linking fails
Problem: Missing C toolchain.
Solution: Install C compiler (MSVC on Windows, GCC/Clang on Unix).
"Permission denied" when running executable
Problem: Execute permission not set (Unix).
Solution:
chmod +x ./program
./programSlow compilation
Problem: Building from source in debug mode.
Solution: Use release build for better performance:
cargo build --release -p neurc
cargo run --release -p neurc -- compile program.nrNext Steps
- Your First Program - Detailed tutorial
- Language Reference - Complete language documentation
- CLI Usage Guide - Advanced CLI features
- Troubleshooting - Common problems and solutions
Getting Help
- Check Troubleshooting Guide
- Read Language Reference
- Report issues: https://github.com/PanzerPeter/Neuro/issues
- Read CONTRIBUTING.md for development guidelines