Skip to content

mana-lang/Mana

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

491 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

The Mana Programming Language

Mana — a purple and blue gradient flame logo with the lowercase white text 'mana' beside it.

Write fast, run fast.

A data-centric language purpose-built for game development.

License: MIT C++23 Status: In Development


Mana is a statically-typed, data-centric programming language purpose-built for game development. It features a hybrid execution model, where source code can be selectively compiled to native machine code or to JIT-able bytecode for partial hot-reload execution in a register-based VM, without the need for glue code.

import std.fmt

fn Main() {
    data message = "Hello from Mana!"
    fmt.PrintLine("{message}")

    data scores = [5, 10, 15, 20]
    mut data total: i32 // defaults to 0

    for score in scores {
        total += score
    }
    fmt.Print("Total: {}", total)
}

Development

Mana is currently in the very early stages of development. Some things may be broken or incomplete, and some references may lead to nowhere. Most notably, the code example above won't compile yet, as import statements have not yet been implemented; therefore, printing values is done with PrintV for the time being, which does not yet support string interpolation.

This is actively being worked on, and these issues will be taken care of in due time.

Key Features

  • Data-centric design
    • Everything in Mana (including functions) is data, encouraging a data-centric mental model that helps you understand the flow of data through your program.
  • Hybrid execution
    • Selectively compile to native code or bytecode from the same source, and Hot-Reload bytecode with Hex, Mana's speedy, register-based VM.
  • Statically typed
    • With type inference: data x = 42
    • Or annotations: data x: i32 = 42
  • Expressive Control Flow
    • Simple yet flexible loops
      • infinite: loop { }
      • fixed: loop 8 { }
      • conditional: loop if x > 5 { }
        • post-block eval: loop { } if x > 5
      • counted: loop 8 => i { }
      • range-based: loop 0..10 => i { }
      • and more
    • Iterating ranges with for
      • for val in values
    • Pattern matching with match
  • Explicit & Deduced Assignment
    • Control how data is passed around via explicit assignment operators, or allow Mana to deduce the best assignment form for you.
  • Zero-cost abstractions
    • Never incur any hidden costs in native code
  • Advanced Enumeration
    • Simple yet extensible enumerations with enum
    • Hierarchical, tree-like labels with Tag
      • Fast comparisons across hierarchy levels with in, in? and ==
    • Sum types with variant
  • Compile-time Evaluation & Constraints
    • Conditional compilation with when
    • Generic type constraints with where
    when std.BuildTarget == std.Platforms.Linux.x64 { ... }
    type Foo<T> { a: T => where std.Type.IsIntegral<T> }
  • Powerful Procedures
    • First-class functions via Mana's flexible operator specialization model
    • Function constraints with Attributes such as @[Inline] and @[Pure]
    • Polymorphism for functions and operators
    • Built-in delegates
  • Powerful Type Interface System
    • Create compile-time composite type interfaces with interface for type Foo
      • Keeps transformations and APIs separate from data
    • Name interfaces for separate applications on the same type (interface Bar for type Foo)
    • Import named interfaces by-module
      • Easily disambiguate colliding interfaces
    • Extend existing interfaces from anywhere
    • Lock type fields to make them read-only beyond interface bounds

See the design documentation for the full language details. The documentation is an Obsidian vault, and so it is best read with Obsidian. However, the files are still Markdown, so they should be legible in any MD reader.

In the future, the docs will also include HTML and Markdown versions.

Modules

Module Type Description
Sigil Library Shared, modular frontend, including semantic analysis for LSP
Circe Executable / Library Bytecode compiler
Hex Executable / Library Register-based virtual machine
Salem Executable Native/AOT compiler

Building

Requirements: C++23 compatible compiler with computed-goto support (GCC 13+ or Clang 17+), CMake 3.28+

git clone https://github.com/mana-lang/Mana.git
cd mana

# Configure and build (Debug)
cmake -B .build/debug -DCMAKE_BUILD_TYPE=Debug
cmake --build .build/debug

# Or Release
cmake -B .build/release -DCMAKE_BUILD_TYPE=Release
cmake --build .build/release

Dependencies (spdlog, Catch2) are fetched automatically via CMake's FetchContent.

Running

As CMake can output to arbitrary paths, this example assumes Hex and Circe's executables live in the same folder as the Mana source file, for simplicity.

# Compile a .mn file to bytecode and execute it
./circe hello-world.mn
./hex hello-world.hexe

Running Tests

Mana is currently in the middle of an overhaul of its test suite. Instructions for running tests will be placed here in the future.

Code Examples

See mana/samples/ for example Mana source files covering features which have already been implemented.

See mana/showcase/ for example files covering features which are still planned or in development.

Project Status

The current focus is on maturing the hot-reloadable side of Mana to be competitive with Lua as an embeddable scripting language.

Salem will remain in stasis until Mana is a viable option as a scripting language for development with C++ game engines.

Component Status
Lexer ✅ Functional
Parser ✅ Functional
Semantic Analysis ✅ Functional
Bytecode Compiler (Circe) 🟡 In progress
VM (Hex) 🟡 In progress
LSP / Editor Support (Grimoire) 🟡 In progress
Native Compiler (Salem) 🔴 Future
Build System (Conjure) 🔴 Future

Planned Ecosystem

  • Conjure — Build system and package manager
  • Codex — Debugging tools
  • Grimoire — LSP, editor plugins, and formatters
  • Arcana — Game development framework

Mana ecosystem diagram showing Sigil, Circe, Hex, Salem, Conjure, Grimoire, Codex, and libraries

Project Model

Mana's build system, Conjure, organizes code into Troves and Artifacts.

Artifacts are Virtual Translation Units (VTUs) — Mana doesn't see source files directly. Instead, it treats everything within a named module as a single translation unit, allowing modules to be extended from anywhere.

Diagram showing how source files compose into Artifacts (Virtual Translation Units)

Troves are a named set of Artifacts; in other words, a package.

Diagram showing how Artifacts are organized hierarchically within a Trove

Editor Support

A VS Code syntax highlighting extension is available in grimoire/

This is the beginning of the Grimoire project. For now, simple syntax highlighting will do. Once the project is extended to include LSP support, Grimoire will be moved to its own repository.

If you have VS Code, you can activate syntax highlighting for .mn and .mana files by creating a symlink between Grimoire and VS Code's extensions/ folder

ln -s path_to_mana/Mana/grimoire ~/.vscode/extensions/mana-grimoire

License

MIT

About

A data-centric programming language with a hybrid execution model, purpose-built for game development.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors