A statically-typed, Rust-inspired programming language designed for embedding as a plugin, extension, or modding language.
Note: Kitlang is a hobby project for personal use and demonstrating compiler construction principles. Kitlang is still a work in progress and many features are still in progress of being tested and validated. Kitlang is NOT ready for any serious application in it's current state and using it as such may lead to instability and undefined behaviour.
- Rust-like Syntax: Familiar syntax for developers with Rust experience.
- Static Type System: Strong type checking with type inference support.
- Flexible: Separation of data and code, does not force object-orientation.
- Embeddable: Provides an easy API for binding functions for interoperability between Kitlang and a host environment.
pub struct Vec2 {
x: f32,
y: f32,
}
impl Vec2 {
pub fn distance_sqr(self, other: Vec2) -> f32 {
let x_diff = other.x - self.x;
let y_diff = other.y - self.y;
(x_diff * x_diff) + (y_diff * y_diff)
}
pub fn distance(self, other: Vec2) -> f32 {
self.distance_sqr(other).sqrt()
}
}
pub fn main() {
let coord_1 = Vec2 { x: 5.0, y: 0.0 };
let coord_2 = Vec2 { x: 10.0, y: 10.0 };
let distance = coord_1.distance(coord_2);
println("Distance: " + distance.to_string());
}- Rust 2024 edition (nightly is currently required for some features)
- Cargo
Add Kitlang to your Cargo.toml:
[dependencies]
kitlang = { git = "https://github.com/zephhhhhh/kitlang" }Or clone the repository:
git clone https://github.com/zephhhhhh/kitlang.git
cd kitlang
cargo build --releasefn main() {
// TODO.. Add basic embedded use example..
}Kitlang follows a traditional multi-pass compiler architecture:
- Converts raw source code into a stream of tokens for syntactic analysis.
- Builds an Abstract Syntax Tree (AST) from tokens. At this stage, identifiers are unresolved strings, representing the structure but not the semantic meaning.
- Builds a definition registry for name resolution
- Resolves paths (e.g.,
usestatements,Module::Struct::method) - Constructs scope chains for local variables and function parameters
- Validates type correctness for all operations
- Ensures function signatures match call sites
- Verifies assignment type compatibility
- Performs type inference for variables declared with no specified type
- Transforms HIR into a simplified representation closer to assembly language, suitable for optimization passes, runtime interpretation and in future, compilation down into a native executable.
- Currently executes MIR directly via an interpreter. Future plans include lowering to assembly for native execution.
kitlang/
└── src/
├── token.rs # Token definitions
├── lexer.rs # Tokenizer
├── ast.rs # Abstract Syntax Tree definitions
├── parser/ # Syntax analysis (Tokens -> AST)
│
├── intermediate/
│ ├── hir/ # High-level IR
│ ├── mir/ # Mid-level IR
│ ├── resolver/ # Name resolution, type resolution, visibility checking, etc.
│ └── type_check.rs # Type system checking
│
├── interpreter/ # MIR interpreter
│
└── spanned_error.rs # Error message formatting
See here for detailed roadmap and priorities.
Run the test suite:
cargo test --testsRun specific test modules:
cargo test lexer- Syntax Reference - Language syntax specification
- MIR Desugaring - MIR transformation details
The documentation for this crate is automatically generated and hosted on GitHub pages on this repo viewable Here
To generate and open the project documentation locally you can run:
cargo doc --document-private-items --openThis project is licensed under the MIT License - see the LICENSE file for details.
- Inspired by the syntax of the Rust programming language
- Rough project and compiler architecture influenced by the rustc compiler