The Onyx Programming Language
An efficient, procedural, and pragmatic programming language
Efficient
The Onyx compiler is fast. Turnaround time is non-existent using Onyx's custom WebAssembly code generator.
Procedural
Onyx uses a simple programming and memory model. It is familiar to anyone with any programming experience.
Pragmatic
Onyx exists to solve real problems. It provides a wide-range of orthogonal language features to fit any task.
Read about design goals of Onyx.
Install Onyx
Run the following command on your Linux or MacOS system to install the latest version of Onyx.
Read the Installation Guide for more details.
Language Features
For full language documentation and reference see the Onyx Book.
Modern Syntax
Onyx uses a modernized C-like syntax, similar to Jai or Odin. Onyx is a procedural language, but does allow for functional-inspired syntax using the pipe operator.
use core { printf, iter }
main :: () {
for i in 1 .. 10 {
fact := factorial(i)
printf("{}! = {}\n", i, fact)
}
}
factorial :: (n: i32) -> i32 {
return iter.as_iter(1 .. n)
|> iter.fold(1, (x, y) => x * y)
}
Type Safety
Onyx is strictly type-checked. The type-inference in Onyx allows for many types to be omitted with out sacrificing safety.
use core { printf }
main :: () {
// Inferred variable type
x := 10
// Function with entirely inferred types.
change_value :: x => x + 10
// Onyx figures out the types of
// `change_value` when you call it.
printf("Value: {}.\n", change_value(x))
}
Fast Compilation
Onyx's compiler is written entirely in C and features a incredibly fast compilation. The server for this site was compiled in just 47 milliseconds.
$ onyx build -V build.onyx
File search path:
/home/brendan/.onyx
.
Type table size: 151092 bytes.
Foreign blocks size: 8 bytes.
Tagged procedure size: 840 bytes.
Tagged global size: 8 bytes.
Statistics:
Time taken: 47.000000 ms
Processed 22144 lines
Processed 115240 tokens
Outputting to WASM file: site.wasm
WebAssembly
Onyx compiles solely to WebAssembly. You can use a builtin WebAssembly runtime using onyx run
, or compile to WASM and run using a WebAssembly runner, like Wasmer or Wasmtime.
# Compile and run directly.
$ onyx run hello.onyx
Hello, World!
# This time target 'WASI'.
$ onyx build -r wasi -o hello.wasm hello.onyx
# Run using Wasmer.
$ wasmer run hello.wasm
Hello, World!
C-FFI
Onyx features built-in support for linking to native C-libraries on Linux and MacOS.
use core {*}
// Using #dyncall dynamically loads
// the library at runtime using dlopen().
#foreign #dyncall "libc.so" {
write :: (fd: i32, msg: [] u8) -> i32 ---
}
main :: () {
msg: [] u8 = "Hello, libc!"
write(1, msg)
}
Examples
Learn more from complete examples on the Examples page.
Onyx Community
The Onyx programming language is on Discord! It is the place to chat about language features, discuss problems you are having, and showcase your projects.
Onyx is an open source project so contributions from the community are welcome and encouraged!
The onyx-lang/onyx
GitHub repository is the official source of Onyx.
Recent News
Beta Release 0.1.12
19th May 2024
This intermediate release brings quality of life improvements to the pipe operator, small syntax refinements, and small improvements to WebAssembly module generation.
Beta Release 0.1.11
21st April 2024
This release brings even more core library uniformity though some breaking changes, some syntax refinements, and an exciting experimental feature: compiler extensions!