Nitro is an experimental OOP language with the following goals:
- Compiled to native code like C/C++/Go or Rust.
- Non-fragile and stable ABI.
- A Nitro library will be distributed as a compiled binary similar to JAR or DLL file, not as a source code like most languages did.
- Built-in cross compilation (e.g. one can produce Linux binary on Windows).
- GC using reference counting.
- Runtime reflection.
- Error handling using exception.
- No null value (except a pointer).
- Option type.
Nitro borrowed most of the syntax from Rust except:
- Nitro is an OOP language like Java or C#.
- Easy to learn, especially for people who already know Java, C# or Rust.
- No lifetime, no borrow checker, no const VS mut.
- No borrowed and owned type like
strandString. - Use exception like Java or C# for error handling (no checked exception).
- Nitro was designed for application programming rather than systems programming.
The main different is Nitro compiled to native code instead of Java bytecode or Common Intermediate Language, which can be run without a VM. The benefit with this are:
- Low memory footprint.
- Fast startup.
- Can be run on a client machine directly without a VM.
- Easy to interop with other languages.
The reason Nitro was born is because of:
- D has fragile ABI.
- Swift does not support namespace.
I'm currently writing the stage 0 compiler along side the std library. The goal of stage 0
compiler is to compile the std and cli. Once the first version of cli is fully working Nitro
will become a self-hosted language.
@pub
class Allocator;
impl Allocator {
@pub
fn Alloc(size: UInt, align: UInt): *UInt8 {
@if(unix)
let ptr = aligned_alloc(align, size);
@if(win32)
let ptr = _aligned_malloc(size, align);
if ptr == null {
@if(os != "windows")
abort();
@if(os == "windows")
asm("int 0x29", in("ecx") 7, out(!) _);
}
ptr
}
@pub
fn Free(ptr: *UInt8) {
@if(unix)
free(ptr);
@if(win32)
_aligned_free(ptr);
}
@if(unix)
@ext(C)
fn aligned_alloc(align: UInt, size: UInt): *UInt8;
@if(unix)
@ext(C)
fn free(ptr: *UInt8);
@if(win32)
@ext(C)
fn _aligned_malloc(size: UInt, align: UInt): *UInt8;
@if(win32)
@ext(C)
fn _aligned_free(ptr: *UInt8);
@if(unix)
@ext(C)
fn abort(): !;
}
- Git
- Rust
- C++ toolchain (e.g. MSVC, XCode, GCC)
- CMake
You need to clone this repository with submodules like this:
git clone --recurse-submodules https://github.com/ultimaweapon/nitro.gitRun the following command in the root of this repository:
CMAKE_BUILD_PARALLEL_LEVEL=2 ./build-deps.sh.\build-deps.ps1./build-cli.shSupply debug as a first argument if you want to hack on Nitro.
.\build-cli.ps1Set parameter Type to debug if you want to hack on Nitro (e.g. .\build-cli.ps1 -Type debug).
./build-dist.sh.\build-dist.ps1BSD-2-Clause Plus Patent License