Skip to content
Shrawan-13Public

About

Nova — a memory-safe, ahead-of-time compiled language with a Rust-inspired ownership model and C-level performance

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

Nova Programming Language

Nova is a memory-safe, ahead-of-time compiled programming language with a Rust-inspired ownership and borrow model and C-level performance.

The compiler (nova) is implemented in Go for fast iteration and compiles Nova source to optimized native code via C/GCC. Every module of a program is compiled into its own C translation unit.

Quick Start

Build the compiler:

cd nova
make build

Run a program:

./nova run examples/hello.nv

Build a binary:

./nova build examples/fib.nv -o fib
./fib

Check a file:

./nova check examples/hello.nv

Run the test suite:

./nova test tests/spec

Create a project:

./nova init my-project

The language in one minute

mod util;                              // load util.nv

use util::parse;                      // import an item

struct Point { x: i64, y: i64 }       // a struct
enum Color { Red, Green }             // an enum
trait Shape { fn area(&self) -> i64; }// a trait

fn distance(p: Point) -> i64 {        // a function
    let mut total = 0;
    for i in 0..10 {                   // a range
        total = total + i;
    }
    return total;
}

fn main() {
    let mut numbers: Vec<i64> = Vec::new();   // a generic vector
    numbers.push(1);

    let text = String::from("hello");         // an owned string
    text.push_str(" world");

    let value = parse("42");                  // a Result
    match value {
        Result::Ok(v) => println(v),
        Result::Err(e) => println(e),
    }
    return 0;
}

Memory safety

  • String, Vec<T> and HashMap<K, V> own their memory and release it automatically at the end of their scope.
  • User defined types keep move semantics: the borrow checker rejects the use of a value after it was moved.
  • &T is a shared borrow, &mut T an exclusive borrow.
  • Every index is checked at runtime and every panic reports the file, the line and the column.
  • Integer arithmetic traps on overflow and on a division by zero.

Tool chain

Command Description
nova run <file> compile and run a program
nova build <file> [-o out] compile to a native binary
nova check <file> type check without generating code
nova test [dir] run the in-language test suite
nova init [dir] create a new project
nova dump ast|types <file> print the syntax tree or the resolved types
nova lsp language server (see docs/lsp.md)

Layout

  • cmd/nova — compiler driver, test runner, project scaffolding, language server.
  • lang/ — lexer, parser, AST, prelude and module loader.
  • sema/ — type checker, borrow checker, trait resolution.
  • codegen/ — C code generation, runtime and ownership helpers.
  • types/ — the type system.
  • diag/ — structured diagnostics.
  • stdlib/std/ — the standard library.
  • tests/ — the test suite.
  • bench/ — the benchmark suite.
  • docs/ — the language reference, the LSP specification and the self hosting plan.

Documentation

  • docs/language.md — the language reference.
  • docs/lsp.md — the language server specification.
  • docs/self-hosting.md — the self-hosting plan.
  • docs/roadmap.md — the status of the implementation.

About

Nova — a memory-safe, ahead-of-time compiled language with a Rust-inspired ownership model and C-level performance

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages