Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Cria

A modern, statically typed, compiled programming language. It was created to evolve with my learning about Rust. So, test it just for fun. "Code that reads like thought, runs like metal."

Quick Start

# Install (from source)
git clone https://github.com/crialang/cria
cd cria
cargo build --release

# Create a project
cria init hello
cd hello
cria run

Hello World

fn main() {
    println!("Hello, World!")
}

Language Showcase

use std.http.{Server, Request, Response}
use std.collections.Map

// Structs with derived traits
@derive(Debug, Clone)
struct User {
    id: Int
    name: String
    email: String
}

// Algebraic data types
enum AuthResult {
    Success(User)
    InvalidCredentials
    AccountLocked { until: DateTime }
}

// Async/await + error handling
async fn authenticate(email: String, password: String) -> Result[AuthResult, DbError] {
    let user = await db.find_by_email(email)?.ok_or(AuthResult.InvalidCredentials)?
    
    if user.is_locked() {
        return Ok(AuthResult.AccountLocked { until: user.locked_until })
    }
    
    if await password.verify(user.password_hash)? {
        Ok(AuthResult.Success(user))
    } else {
        Ok(AuthResult.InvalidCredentials)
    }
}

// Pattern matching
fn handle_auth(result: AuthResult) -> Response {
    match result {
        AuthResult.Success(user) => {
            let token = jwt.sign(user.id)
            Response.ok({"token": token})
        }
        AuthResult.InvalidCredentials =>
            Response.unauthorized("invalid credentials")
        AuthResult.AccountLocked { until } =>
            Response.forbidden("account locked until $until")
    }
}

// Generics + traits
trait Repository[T] {
    async fn find(self, id: Int) -> Result[Option[T], DbError]
    async fn save(self, item: T) -> Result[T, DbError]
    async fn delete(self, id: Int) -> Result[Bool, DbError]
}

// List comprehensions
fn active_users(users: List[User]) -> List[String] {
    [u.name for u in users if u.is_active()]
}

// Main entry point
async fn main() -> Result[(), Error] {
    let server = Server.new("0.0.0.0:8080")
    println!("Listening on :8080")
    await server.serve(handle_auth)?
    Ok(())
}

Features

Feature Status
Static typing + inference
Generics + traits
Pattern matching
Async/await
No null (Option[T])
Result[T,E] error handling
Native binary output 🔄 WIP
WebAssembly target 📋 Planned
Package manager 📋 Planned
LSP / VS Code extension 📋 Planned

Project Structure

compiler/       criac — lexer, parser, type checker, codegen
runtime/        VM, GC, async scheduler
cli/            cria — the user CLI tool
package-manager dependency resolution & registry
lsp/            Language Server Protocol server
std/            Standard library (written in Cria)
vscode-extension VS Code integration
docs/           Language spec & book

Implementation Language

The Cria toolchain is implemented in Rust for:

  • Memory safety in the compiler itself
  • Excellent LLVM bindings (inkwell)
  • Strong ecosystem (cargo, rayon, crossbeam)
  • Cross-platform compilation

Development Status & Roadmap

Current State (2026-04-20) — Phase 0 complete

The workspace compiles with zero errors. The core pipeline skeleton is in place:

Component File(s) Status
Lexer compiler/src/lexer/ ✅ Complete — all tokens, interpolated strings, Unicode, hex/bin/oct literals
AST compiler/src/ast/mod.rs ✅ Complete — all node types (expr, stmt, pattern, type, items)
Parser compiler/src/parser/mod.rs ✅ Complete — recursive descent + Pratt for expressions
Type checker compiler/src/typechecker/mod.rs 🔄 Skeleton — HM unification, collect/check passes
HIR compiler/src/ir/mod.rs 🔄 Skeleton — three-address code definition
Codegen compiler/src/codegen/mod.rs 🔄 Stubs — LLVM native, WASM, bytecode VM defined
Runtime VM runtime/src/vm.rs 🔄 Skeleton — opcode set defined, execution loop pending
GC runtime/src/gc.rs 🔄 Skeleton — tri-color mark-and-sweep structure ready
Async scheduler runtime/src/scheduler.rs 🔄 Skeleton — M:N work-stealing structure defined
CLI cli/src/main.rs ✅ Complete — all commands wired (build/run stubs through compiler)
LSP server lsp/src/main.rs 🔄 Skeleton — tower-lsp wired, diagnostics working
Package manager package-manager/src/main.rs 🔄 Skeleton — manifest/lockfile types, resolver stub
Stdlib std/ 🔄 Partial — Option, Result, List defined in Cria
VS Code extension vscode-extension/ 🔄 Skeleton — LSP client + commands

Roadmap

Phase 1 — Type Checker (next)

Goal: Every valid Cria program type-checks correctly; clear errors for invalid ones.

  • Name resolution pass (symbol table, scope tree, forward references)
  • Complete HM inference: let-polymorphism, generics monomorphization
  • Trait constraint solving
  • Borrow checker (simplified regions — not full Rust lifetimes)
  • Effect system (experimental, behind a flag)

Files to work on: compiler/src/typechecker/mod.rs, add compiler/src/resolver/mod.rs

Phase 2 — Bytecode VM

Goal: cria run hello.cria executes a real program end-to-end.

  • HIR lowering: typed AST → three-address HIR (compiler/src/ir/lowering.rs)
  • HIR → bytecode compiler (compiler/src/codegen/mod.rs BytecodeBackend)
  • VM execution loop (runtime/src/vm.rs)
  • GC integration (runtime/src/gc.rs)
  • Async scheduler execution (runtime/src/scheduler.rs)
  • Basic stdlib builtins backed by Rust: println!, List, Map, String

Phase 3 — Native Binary (LLVM)

Goal: cria build --release produces a fast native binary.

  • Add inkwell dependency to compiler
  • HIR → LLVM IR emission (compiler/src/codegen/mod.rs NativeBackend)
  • Link with cria-runtime (for GC, scheduler, stdlib)
  • Basic optimizations: inlining, DCE, constant folding
  • Target: Linux x86-64 first, then macOS arm64, Windows x64

Phase 4 — Standard Library

Goal: Enough stdlib to write real programs.

  • std.core — Iterator trait + adaptors
  • std.ioprint, read_line, File, stdin/stdout
  • std.collectionsMap, Set, Queue (backed by Rust HashMap etc.)
  • std.stringsplit, trim, contains, replace, format
  • std.asyncFuture, Channel, spawn, sleep
  • std.processargs, env, exit
  • std.fsread_to_string, write, read_dir

Phase 5 — WebAssembly

Goal: cria build --target wasm32 produces a .wasm file runnable in browsers/WASI.

  • Add wasm-encoder dependency
  • HIR → WASM emission (compiler/src/codegen/mod.rs WasmBackend)
  • WASI imports for filesystem/network
  • Optimize for size (--target wasm32 --optimize size)

Phase 6 — Package Manager & Registry

Goal: cria pkg add http installs and links a real package.

  • Package registry server (separate repo)
  • HTTP download + SHA-256 checksum verification
  • PubGrub version resolver (package-manager/src/main.rs)
  • Lockfile write/read + reproducible builds
  • cria pkg publish to registry

Phase 7 — Tooling Polish

Goal: Developer experience on par with Go/Rust.

  • cria fmt — canonical formatter (parse → pretty-print)
  • cria lint — linting passes on typed AST
  • LSP: hover types, go-to-definition, completions, rename
  • VS Code extension: syntax highlighting grammar (.tmLanguage.json)
  • cria doc — extract doc comments, generate HTML
  • REPL: incremental compilation, history

Phase 8 — Bootstrap (Future)

Goal: Rewrite the compiler in Cria itself.

  • Compiler is self-hosting: criac compiled by criac
  • Standard library fully written in Cria (no Rust shims)

How to Pick Up Where We Left Off

  1. Run cargo check --workspace — should be clean
  2. Read docs/book/architecture.md for the full pipeline diagram
  3. Read SPEC.md for the language reference
  4. The best next task is Phase 1 — Name Resolver:
    • Create compiler/src/resolver/mod.rs
    • Walk the Module AST, build a SymbolTable
    • Replace Ident nodes with resolved Symbol references
    • Wire it between parser and type checker in session.rs

License

MIT OR Apache-2.0

About

A compiled, statically typed programming language. expressive as Swift, safe as Rust, simple as Go.

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages