DEV Community

Cover image for Zeen: A New Systems Programming Language with a Comptime Engine
mealet
mealet

Posted on

Zeen: A New Systems Programming Language with a Comptime Engine

Website: zeen-lang.tech
Github: mealet/zeen

(Would appreciate if you'd leave a star on Github)

What is Zeen

Zeen - a modern systems programming language designed for simplicity, safety, and predictable control over memory. It provides toolchains and compiler rules to operate data easily and drop it automatically after usage with move semantics to avoid any runtime overhead. The main idea is to create a tool to develop efficient software where most errors are caught at compile time.

Zeen took many design choices from Rust and Zig programming languages, which makes it more familiar for most developers. Besides that it introduces its own approach to ownership, memory management, and compile-time execution.

Development Tools

Besides compiler and set of libraries (core, std), Zeen has:

Small Example

fn print_this[T: Display](value: T) {
  @println("Yeah, I've printed this: {}", value);
}

fn main() {
  print_this(123);
  print_this("hello!");
}
Enter fullscreen mode Exit fullscreen mode

Quick Start

  1. Install latest release following official guide from documentation.
  2. Create new project with Zora:
zora new my_project
cd my_project
Enter fullscreen mode Exit fullscreen mode
  1. Write code and run your binary package:
zora run
Enter fullscreen mode Exit fullscreen mode

New Comptime Engine

Last update v0.4.0 brought a lot of enhancements: frontend performance, new warnings system, new macros, fixed C ABI and Comptime Engine.

Zeen's comptime engine allows you to move some evaluations or constructions away from runtime to the compiler.

You can define and eval constants, create Comptime functions which can construct new types, export expressions and declarations, emit declarations into current scope, format print at the compile time and more. Here's some examples of it.

Simple constants and splicing:

comptime N = 16;
comptime SquaredN = N * N;

fn main() {
  @println("{} -> {}", N, SquaredN);
  @println("$(N) -> $(SquaredN)");
}
Enter fullscreen mode Exit fullscreen mode

Advanced usage (declarations, type values and etc):

comptime fn pair_of(struct_name: comptime_str, a: zeen_type, b: zeen_type) zeen_decl {
  @zeen_decl(
    struct $(struct_name) {
      pub a: $(a),
      pub b: $(b),
    }
  )
}

comptime {
  @emit(pair_of("NumsPair", i32, f32));
}

fn main() {
  let pair = NumsPair { .a = 1, .b = 1.0 };
  @println("{} {}", pair.a, pair.b);
}
Enter fullscreen mode Exit fullscreen mode

See more info and examples on changelog and comptime docs pages.

Top comments (2)

Collapse
 
nikita-tolstykh profile image
Nikita Tolstykh •

Thanks for a quick introduction into the Zeen programming language. So it means that the code can be defined in a runtime or a compile time execution via the Zeen programming language syntax explicitly?

Collapse
 
mealet profile image
mealet •

Hello and thanks for your comment!

Yes. As Zeen is an AOT compiler he ships runtime code into executable binaries (or libs, depends on what you're creating), but explicit usage of "comptime" keyword and its variations you can evaluate code at the compile time.

But also this keyword + specified macros and types allows you to produce new code and macros via "comptime functions" (may be familiar from Zig comptime or Rust macros)