This is an automated archive made by the Lemmit Bot.

The original was posted on /r/programminglanguages by /u/Lord_Mystic12 on 2024-11-10 22:48:30+00:00.


Introducing Helix – A New Programming Language

So me and some friends have been making a new programming language for about a year now, and we’re finally ready to showcase our progress. We’d love to hear your thoughts, feedback, or suggestions!

What is Helix?

Helix is a systems/general-purpose programming language focused on performance and safety. We aim for Helix to be a supercharged Rust, with compatibility matching C++—and more!

Features include:

  • Classes, Interfaces, Structs and most OOP features
  • Generics, Traits, and Type Bounds
  • Pattern Matching, Guards, and Control Flow
  • Memory Safety and performance as core tenets
  • A readable syntax, even at the scale of C++/Rust

Current State of Development

Helix is still in early development, so expect plenty of changes. Our current roadmap includes:

  1. Finalizing our C+±based compiler
  2. Rewriting the compiler in Helix for self-hosting
  3. Building:
    • A standard library
    • A package manager
    • A build system
    • LSP server/client support
    • And more!

If you’re interested in contributing, let me know!

Example Code: Future Helix

Here’s a snippet of future Helix code that doesn’t work yet due to the absence of a standard library:

import std::io;

fn main() -> i32 {
    let name = input("What is your name? ");
    print(f"Hello, {name}!");

    return 0;
}

Example Code: Current Helix (C++ Backend)

While we’re working on the standard library, here’s an example of what works right now:

ffi "c++" import "iostream";

fn main() -> i32 {
    let name: string;

    std::cout << "What is your name? ";
    std::cin >> name;

    std::cout << "Hello, " << name << "!";

    return 0;
}

Currently, Helix supports C++ includes, essentially making it a C++ re-skin for now.

More Complex Example: Matrix and Point Classes

Here’s a more advanced example with matrix operations and specialization for points:

import std::io;
import std::memory;
import std::libc;

#[impl(Arithmetic)] // Procedural macro, not inheritance
class Point {
    let x: i32;
    let y: i32;
}

class Matrix requires  if Arithmetic in T {
    priv {
        let rows: i32;
        let cols: i32;
        let data: unsafe *T;
    }

    fn Matrix(self, r: i32, c: i32) {
        self.rows = r;
        self.cols = c;
         = std::libc::malloc((self.rows * self.cols) * sizeof(T)) as unsafe *T;
    }

    op + fn add(self, other: &Matrix::) -> Matrix:: { // rust like turbofish syntax is only temporary and will be remoevd in the self hosted compiler
        let result = Matrix::(self.rows, self.cols);
        for (let i: i32 = 0; i < self.rows * self.cols; ++i):
            ...
        return result;
    }

    fn print(self) {
        for i in range(self.rows) {
            for j in range(self.cols) {
                ::print(f"({self(i, j)}) ");
            }
        }
    }
}

extend Matrix for Point { // Specialization for Matrix
    op + fn add(const other: &Matrix::) -> Matrix:: {
        ...
    }

    fn print() {
        ...
    }
}

fn main() -> i32 {
    let intMatrix = Matrix::(2, 2); // Matrix of i32s
    intMatrix(0, 0) = 1;
    intMatrix(0, 1) = 2;
    intMatrix.print();

    let pointMatrix = Matrix::(2, 2); // Specialized Matrix for Point
    pointMatrix(0, 0) = Point{x=1, y=2};
    pointMatrix(0, 1) = Point{x=3, y=4};
    pointMatrix.print();

    let intMatrix2 = Matrix::(2, 2); // Another Matrix of i32s
    intMatrix2(0, 0) = 2;
    intMatrix2(0, 1) = 3;

    let intMatrixSum = intMatrix + intMatrix2;
    intMatrixSum.print();

    return 0;
}

We’d love to hear your thoughts on Helix and where you see its potential. If you find the project intriguing, feel free to explore our repo and give it a star—it helps us gauge community interest!

The repository for anyone interested!