Skip to content

Latest commit

 

History

History
57 lines (45 loc) · 1.45 KB

File metadata and controls

57 lines (45 loc) · 1.45 KB

Usage

The pipeline

cinderkit build main.ck -o main.cdx     # front half: lex, parse, check, codegen
cinderkit check main.ck                 # type-check only
cinderc build main.cdx -o main.cdxb     # assemble + verify (cindervm)
cinderc run main.cdxb                   # execute

The language

fn main() -> i32 {
    let total = 2 + 3 * 4;      // let binds a frame local
    if total > 10 {             // condition must be bool
        return 1;
    } else {
        return 0;
    }
}
  • fn name() -> i32|bool|void { ... }
  • let name = <expr>;
  • if <bool-expr> { ... } else { ... }
  • while <bool-expr> { ... } — loops are metered automatically
  • return <expr>; — must match the declared type
  • helper(); — expression statements; calls pack their arguments

Operators

Operator Meaning Codegen
+ - * / wrapping arithmetic add sub mul div
< signed less-than lt
> signed greater-than lt on swapped operands
== structural equality eq

Diagnostics

error[E_TYPE_MISMATCH]: return type must be i32, found bool (at line 3)
error[E_UNKNOWN_FN]: unknown function `helper` (at line 5)
error[E_MISSING_RETURN]: function `main` may reach the end without returning (at line 1)

Example

cinderkit build examples/fib.ck -o fib.cdx
cinderc build fib.cdx -o fib.cdxb
cinderc run fib.cdxb

See also: the README for the design rationale.