@@ -4,21 +4,21 @@ description: Unified data and behavior with Java-style organization and Rust-pow
|
|||||||
icon: Shapes
|
icon: Shapes
|
||||||
---
|
---
|
||||||
|
|
||||||
Classes in Mist bridge the gap between Java's organizational structure and Rust's performance. They group fields, constructors, and methods within a single cohesive block, using `fn` for methods and `*self` for the instance parameter.
|
Classes in Mist bridge the gap between Java's organizational structure and Rust's performance. They group fields, constructors, and methods within a single cohesive block, using C-style method signatures with `&self` for the instance parameter.
|
||||||
|
|
||||||
## Basic Syntax
|
## Basic Syntax
|
||||||
|
|
||||||
A class groups fields and methods together. Fields use semicolons and the `name Type` convention. Methods use `fn` and take `*self` as the first parameter for shared access.
|
A class groups fields and methods together. Fields use semicolons and the `Type name` convention. Methods use C-style syntax with `&self` as the first parameter for shared access.
|
||||||
|
|
||||||
```mist
|
```mist
|
||||||
pub class Logger {
|
pub class Logger {
|
||||||
prefix String;
|
String prefix;
|
||||||
|
|
||||||
pub fn info(*self, message *str) {
|
pub void info(&self, message str&) {
|
||||||
self.log(LogLevel::Info, message);
|
self.log(LogLevel::Info, message);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn log(*self, level LogLevel, message *str) {
|
void log(&self, LogLevel level, message str&) {
|
||||||
println!("{level} {} {}", self.prefix, message);
|
println!("{level} {} {}", self.prefix, message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -37,58 +37,71 @@ pub constructor() {
|
|||||||
Constructors can take parameters:
|
Constructors can take parameters:
|
||||||
|
|
||||||
```mist
|
```mist
|
||||||
pub constructor(prefix String) {
|
pub constructor(String prefix) {
|
||||||
self.prefix = prefix;
|
self.prefix = prefix;
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
## Instance Methods & `*self`
|
## Instance Methods & `&self`
|
||||||
|
|
||||||
Methods use `*self` (shared reference) or `*mut self` (mutable reference) as the first parameter. The return type is placed after the parameter list.
|
Methods use `&self` (shared reference) or `&mut self` (mutable reference) as the first parameter.
|
||||||
|
|
||||||
```mist
|
```mist
|
||||||
pub fn warning(*self, message *str) {
|
pub void warning(&self, message str&) {
|
||||||
self.log(LogLevel::Warning, message);
|
self.log(LogLevel::Warning, message);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn reset(*mut self) {
|
pub void reset(&mut self) {
|
||||||
self.prefix = String::new();
|
self.prefix = String::new();
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
## Inheritance
|
## Inheritance
|
||||||
|
|
||||||
Classes support single inheritance with the `:` syntax. Use `super -> Super::new()` in the constructor to call the parent constructor. Override methods with `override` or `override(Parent)`.
|
Classes support single inheritance with the `:` syntax. Use `super = Super::new()` in the constructor to call the parent constructor. Override methods by placing `override(Parent)` after the parameter list.
|
||||||
|
|
||||||
```mist
|
```mist
|
||||||
pub class Animal {
|
pub class Animal {
|
||||||
pub name String;
|
pub String name;
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
self.name = "Rex".to_string();
|
self.name = "Rex".to_string();
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn speak(*self) {
|
pub String speak(&self) {
|
||||||
println!("Unknown");
|
"Unknown".to_string()
|
||||||
}
|
|
||||||
|
|
||||||
pub fn legs(*self) {
|
|
||||||
println!("Unknown");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub class Dog : Animal {
|
pub class Dog : Animal {
|
||||||
constructor() {
|
constructor() {
|
||||||
super -> Super::new();
|
super = Super::new();
|
||||||
}
|
}
|
||||||
|
|
||||||
pub override fn speak(*self) {
|
pub String speak(&self) override(Animal) {
|
||||||
println!("Woof!");
|
"Woof!".to_string()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## Trait Implementations
|
||||||
|
|
||||||
|
Traits can be implemented directly inside a class body:
|
||||||
|
|
||||||
|
```mist
|
||||||
|
pub class Dog : Animal {
|
||||||
|
constructor() {
|
||||||
|
self.name = name;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Explicit override is useful for super inheritance
|
pub String speak(&self) override(Animal) {
|
||||||
pub override(Animal) fn legs(*self) {
|
"Woof!".to_string()
|
||||||
println!("4 legs");
|
}
|
||||||
|
|
||||||
|
impl std::fmt::Display {
|
||||||
|
Result<(), std::fmt::Error> fmt(&self, std::fmt::Formatter<'_> mut& f) {
|
||||||
|
write!(f, "🐾 {}", self.name)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
@@ -99,37 +112,24 @@ Classes support generic type parameters:
|
|||||||
|
|
||||||
```mist
|
```mist
|
||||||
pub class Container<T> {
|
pub class Container<T> {
|
||||||
pub value T;
|
T value;
|
||||||
|
|
||||||
constructor(val T) {
|
constructor(T val) {
|
||||||
self.value = val;
|
self.value = val;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get(*self) *T {
|
pub &T get(&self) {
|
||||||
&self.value
|
&self.value
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
## Allocations
|
|
||||||
In classes, it's very important to initialize heap allocated fields in `constructor` using `path -> expr`, here is the most common example:
|
|
||||||
```mist
|
|
||||||
pub class Dog : Animal {
|
|
||||||
pub heap_alloc Box<i32>;
|
|
||||||
|
|
||||||
constructor() {
|
|
||||||
super -> Super::new();
|
|
||||||
self.heap_alloc -> Box::new(69);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
```
|
|
||||||
This outputs `std::ptr::write` which is a force write to memory without dropping what "exists", and it's commonly used in uninitialized memory, such as uninitialized dynamic fields.
|
|
||||||
|
|
||||||
## Key Characteristics
|
## Key Characteristics
|
||||||
|
|
||||||
- **Unified Scope**: Data and behavior live in one class block.
|
- **Unified Scope**: Data and behavior live in one class block.
|
||||||
- **`fn` Methods**: Methods use the `fn` keyword, consistent with free functions.
|
- **C-Style Methods**: Return type before name — no `fn` keyword.
|
||||||
- **`*self` Parameter**: The self reference is explicit and uses prefix `*` syntax.
|
- **`&self` Parameter**: The self reference is explicit and uses `&` syntax.
|
||||||
- **Inheritance**: Single inheritance with `override` for polymorphic dispatch.
|
- **Inheritance**: Single inheritance with `override(Parent)` for polymorphic dispatch.
|
||||||
- **Encapsulation**: Visibility modifiers (`pub`) control API exposure.
|
- **Encapsulation**: Visibility modifiers (`pub`) control API exposure.
|
||||||
|
- **Inline Impl**: Traits can be implemented directly within the class body.
|
||||||
- **Zero-Cost Classes**: Under the hood, Mist desugars these into idiomatic Rust structs and implementation blocks.
|
- **Zero-Cost Classes**: Under the hood, Mist desugars these into idiomatic Rust structs and implementation blocks.
|
||||||
|
|||||||
@@ -1,14 +1,14 @@
|
|||||||
---
|
---
|
||||||
title: Enums
|
title: Enums
|
||||||
description: Defining algebraic data types with Mist's data-first convention.
|
description: Defining algebraic data types with Mist's type-first convention.
|
||||||
icon: Layers
|
icon: Layers
|
||||||
---
|
---
|
||||||
|
|
||||||
Enums in Mist serve as powerful algebraic data types (ADTs), maintaining the exact behavior and safety of Rust enums while using square brackets for tuple variant types and `name Type` for struct-like fields.
|
Enums in Mist serve as powerful algebraic data types (ADTs), maintaining the exact behavior and safety of Rust enums while using parentheses for tuple variants and `Type name` for struct-like fields.
|
||||||
|
|
||||||
## Basic Syntax
|
## Basic Syntax
|
||||||
|
|
||||||
An enum can contain unit variants, tuple variants (with types in square brackets), or struct-like variants.
|
An enum can contain unit variants, tuple variants (with types in parentheses), or struct-like variants.
|
||||||
|
|
||||||
```mist
|
```mist
|
||||||
pub enum TaskState {
|
pub enum TaskState {
|
||||||
@@ -16,8 +16,8 @@ pub enum TaskState {
|
|||||||
InProgress,
|
InProgress,
|
||||||
Completed,
|
Completed,
|
||||||
Failed {
|
Failed {
|
||||||
reason String,
|
String reason,
|
||||||
code i32,
|
i32 code,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
@@ -29,57 +29,59 @@ Mist supports all standard variant shapes:
|
|||||||
```mist
|
```mist
|
||||||
enum OptionInt {
|
enum OptionInt {
|
||||||
None, // Unit
|
None, // Unit
|
||||||
Some[i32], // Tuple (square brackets)
|
Some(i32), // Tuple (parentheses)
|
||||||
}
|
}
|
||||||
|
|
||||||
enum Shape {
|
enum Shape {
|
||||||
Circle { radius i32 }, // Struct-like
|
Circle { i32 radius }, // Struct-like
|
||||||
Rect { w i32, h i32 },
|
Rect { i32 w, i32 h },
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
### Instantiation & Matching
|
### Instantiation & Matching
|
||||||
|
|
||||||
Tuple variants are created with parentheses and matched with brackets:
|
Tuple variants are created and matched with parentheses:
|
||||||
|
|
||||||
```mist
|
```mist
|
||||||
let x = OptionInt::Some(42);
|
let x = OptionInt::Some(42);
|
||||||
|
|
||||||
match (x) {
|
match x {
|
||||||
OptionInt::None => { println!("none"); }
|
OptionInt::None => { println!("none"); }
|
||||||
OptionInt::Some[v] => { println!("{}", v); }
|
OptionInt::Some(v) => { println!("{}", v); }
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
Struct variants use brace notation:
|
Struct variants use brace notation:
|
||||||
|
|
||||||
```mist
|
```mist
|
||||||
let c = Shape::Circle { radius: 5 };
|
let c = Shape::Circle {
|
||||||
|
radius: 5,
|
||||||
|
};
|
||||||
|
|
||||||
match (c) {
|
match c {
|
||||||
Shape::Circle { radius } => { println!("{}", radius); }
|
Shape::Circle { radius } => { println!("{}", radius); }
|
||||||
Shape::Rect { .. } => { /* ignore */ }
|
Shape::Rect { .. } => { /* ignore */ }
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
## Generics & Lifetimes
|
## Generics
|
||||||
|
|
||||||
Enums declare generics and lifetimes in angle brackets after the name. Reference types use the `*` prefix.
|
Enums declare generics and lifetimes in angle brackets after the name.
|
||||||
|
|
||||||
```mist
|
```mist
|
||||||
pub enum Validation<'a, T> {
|
pub enum Validation<'a, T> {
|
||||||
Valid(T),
|
Valid(T),
|
||||||
Invalid {
|
Invalid {
|
||||||
message *'a str,
|
&'a str message,
|
||||||
error_id u32,
|
u32 error_id,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
## Key Characteristics
|
## Key Characteristics
|
||||||
|
|
||||||
- **Consistent Declaration**: Struct-like variants use the `name Type` order, consistent with Mist structs.
|
- **Consistent Declaration**: Struct-like variants use `Type name` order, consistent with Mist structs.
|
||||||
- **Square Bracket Tuples**: Tuple variant types use `[]` brackets, distinct from function calls.
|
- **Parentheses Tuples**: Tuple variants use `()` syntax, consistent with Rust.
|
||||||
- **Rust-Native ADTs**: Enums compile directly to Rust enums, allowing exhaustive pattern matching and zero-cost abstraction.
|
- **Rust-Native ADTs**: Enums compile directly to Rust enums, allowing exhaustive pattern matching and zero-cost abstraction.
|
||||||
- **Shared Visibility**: The `pub` modifier at the enum level exports all variants.
|
- **Shared Visibility**: The `pub` modifier at the enum level exports all variants.
|
||||||
- **Comma-Separated Members**: Fields within struct-like variants are separated by commas.
|
- **Comma-Separated Members**: Fields within struct-like variants are separated by commas.
|
||||||
|
|||||||
@@ -4,67 +4,78 @@ description: Defining execution blocks with C-style ergonomics and Rust-powered
|
|||||||
icon: SquareFunction
|
icon: SquareFunction
|
||||||
---
|
---
|
||||||
|
|
||||||
Functions are the primary unit of execution in Mist, declared with the `fn` keyword. Parameters follow the `name Type` convention and the return type is placed after the parameter list.
|
Functions are the primary unit of execution in Mist, using C-style syntax with the return type before the name. The last expression in a block is implicitly returned.
|
||||||
|
|
||||||
## Basic Syntax
|
## Basic Syntax
|
||||||
|
|
||||||
A standard function begins with `fn`, followed by its name, parameters, and an optional return type. The last expression in a block is implicitly returned.
|
Functions place the return type before the name, followed by parameters in parentheses.
|
||||||
|
|
||||||
```mist
|
```mist
|
||||||
fn add(a i32, b i32) i32 {
|
void greet() {
|
||||||
a + b
|
println!("Hello!");
|
||||||
}
|
}
|
||||||
|
|
||||||
fn greet() {
|
i32 add(i32 a, i32 b) {
|
||||||
println!("Hello!");
|
a + b
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
## Visibility & Exports
|
## Visibility & Modules
|
||||||
|
|
||||||
Functions are private to their module by default. The `pub` modifier exports the function for cross-module access.
|
Functions use `pub` for public visibility. Files declare a module with `pub module name;`.
|
||||||
|
|
||||||
```mist
|
```mist
|
||||||
pub fn get_version() i32 {
|
pub module utils;
|
||||||
|
|
||||||
|
pub i32 get_version() {
|
||||||
1
|
1
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn internal_use() i32 {
|
pub void process() {
|
||||||
0
|
// ...
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
## Mutable Parameters
|
## Mutable Parameters
|
||||||
|
|
||||||
Use `mut` on a parameter to allow reassignment within the function body.
|
Use `mut` after the type to allow reassignment within the function body.
|
||||||
|
|
||||||
```mist
|
```mist
|
||||||
fn update_score(mut current_score i32, bonus i32) i32 {
|
void update_score(i32 mut current_score, i32 bonus) {
|
||||||
current_score = current_score + bonus;
|
current_score = current_score + bonus;
|
||||||
current_score
|
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
## Generics & Lifetimes
|
## Methods & `&self`
|
||||||
|
|
||||||
Generics and lifetimes are declared in angle brackets after the function name. Lifetimes are placed before the `*` in reference types.
|
Methods take `&self` (immutable) or `&mut self` (mutable) as the first parameter.
|
||||||
|
|
||||||
```mist
|
```mist
|
||||||
fn choose_longer<'a>(s1 *'a str, s2 *'a str) *'a str {
|
struct Counter {
|
||||||
if (s1.len() > s2.len()) { s1 } else { s2 }
|
i32 value,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Counter {
|
||||||
|
pub i32 get(&self) {
|
||||||
|
self.value
|
||||||
|
}
|
||||||
|
|
||||||
|
pub void increment(&mut self) {
|
||||||
|
self.value += 1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
## Closures
|
## Closures
|
||||||
|
|
||||||
Closures are anonymous functions defined with the `fn` keyword followed by parameters, an optional return type, and a body or expression.
|
Closures are anonymous functions defined with arrow syntax:
|
||||||
|
|
||||||
```mist
|
```mist
|
||||||
let add = fn(a, b) -> a + b;
|
let add = (a, b) => a + b;
|
||||||
add(2, 3);
|
add(2, 3);
|
||||||
|
|
||||||
// With a block body
|
// With a block body
|
||||||
let greet = fn(name *str) {
|
let greet = (name str&) => {
|
||||||
println!("Hello {}", name);
|
println!("Hello {}", name);
|
||||||
};
|
};
|
||||||
```
|
```
|
||||||
@@ -75,15 +86,17 @@ Metadata is applied via the `#[attr]` syntax directly above the declaration.
|
|||||||
|
|
||||||
```mist
|
```mist
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn is_active(id u32) bool {
|
pub i32 clamp(i32 value, i32 min, i32 max) {
|
||||||
id > 0
|
if value < min { min }
|
||||||
|
else if value > max { max }
|
||||||
|
else { value }
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
## Key Characteristics
|
## Key Characteristics
|
||||||
|
|
||||||
- **`fn` Keyword**: Every function starts with `fn`, making declarations instantly recognizable.
|
- **C-Style Syntax**: Return type before name — no `fn` keyword.
|
||||||
- **Implicit Returns**: The final expression in a block is automatically returned.
|
- **Implicit Returns**: The final expression in a block is automatically returned.
|
||||||
- **Unified Abstraction**: Lifetimes and type constraints are declared in one location.
|
- **`&self` / `&mut self`**: Explicit self parameter in method definitions.
|
||||||
- **Closure Support**: Anonymous functions with optional return type annotations.
|
- **Closure Support**: Arrow syntax `(params) => expr` for anonymous functions.
|
||||||
- **Zero-Cost Mapping**: Every function maps directly to a Rust `fn`.
|
- **Zero-Cost Mapping**: Every function maps directly to a Rust `fn`.
|
||||||
|
|||||||
@@ -6,9 +6,24 @@ icon: FolderTree
|
|||||||
|
|
||||||
Mist organizes code through a file-system based module system with explicit path imports.
|
Mist organizes code through a file-system based module system with explicit path imports.
|
||||||
|
|
||||||
## The Module System
|
## Module Declarations
|
||||||
|
|
||||||
Each `.mist` file in `src/` corresponds to a module. and a `directory/package.mist` is a package like mod.rs, packages don't need `package.mist` to be functional, as long as a `.mist` file exists it will map it to pacakge_name::file_name.
|
Each `.mist` file declares itself as a module with `pub module name;` at the top. A `package.mist` file acts like `mod.rs` — it is the entry point for its directory.
|
||||||
|
|
||||||
|
```mist
|
||||||
|
// src/utils/helper.mist
|
||||||
|
pub module helper;
|
||||||
|
|
||||||
|
pub void greet() {
|
||||||
|
println!("Hello!");
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
```mist
|
||||||
|
// src/utils/package.mist
|
||||||
|
pub module utils;
|
||||||
|
// This module exports submodules and items
|
||||||
|
```
|
||||||
|
|
||||||
## Imports
|
## Imports
|
||||||
|
|
||||||
@@ -51,6 +66,7 @@ A typical Mist project looks like this:
|
|||||||
```
|
```
|
||||||
my-project/
|
my-project/
|
||||||
├── Cargo.toml
|
├── Cargo.toml
|
||||||
|
├── Mist.toml
|
||||||
├── src/
|
├── src/
|
||||||
│ ├── main.mist
|
│ ├── main.mist
|
||||||
│ ├── my_api/
|
│ ├── my_api/
|
||||||
|
|||||||
@@ -1,29 +1,29 @@
|
|||||||
---
|
---
|
||||||
title: Pointers & References
|
title: Pointers & References
|
||||||
description: Explicit memory access with prefix pointer syntax and Rust-native safety.
|
description: Explicit memory access with postfix reference syntax and Rust-native safety.
|
||||||
icon: MousePointer2
|
icon: MousePointer2
|
||||||
---
|
---
|
||||||
|
|
||||||
Mist uses a prefix `*` syntax for reference types. While the symbols look like C-style pointers, they adhere strictly to Rust's ownership and borrowing rules.
|
Mist uses a postfix `&` syntax for reference types. While familiar from C++, these references adhere strictly to Rust's ownership and borrowing rules.
|
||||||
|
|
||||||
## Basic Syntax
|
## Basic Syntax
|
||||||
|
|
||||||
Reference types are written with `*` before the type. Use `*mut` for mutable references. The `&` and `&mut` operators create references from values.
|
Reference types are written with `&` after the type. Use `mut&` for mutable references. The `&` and `&mut` operators create references from values.
|
||||||
|
|
||||||
```mist
|
```mist
|
||||||
let x i32 = 42;
|
i32 x = 42;
|
||||||
let r *i32 = &x;
|
i32& r = &x;
|
||||||
|
|
||||||
let mut y = 42;
|
let mut y = 42;
|
||||||
let r *mut i32 = &mut y;
|
i32 mut& r = &mut y;
|
||||||
*r = 100;
|
*r = 100;
|
||||||
```
|
```
|
||||||
|
|
||||||
In function parameters:
|
In function parameters:
|
||||||
|
|
||||||
```mist
|
```mist
|
||||||
fn increment(value *mut i32, limit *i32) {
|
void increment(i32 mut& value, i32& limit) {
|
||||||
if (*value < *limit) {
|
if *value < *limit {
|
||||||
*value = *value + 1;
|
*value = *value + 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -31,30 +31,37 @@ fn increment(value *mut i32, limit *i32) {
|
|||||||
|
|
||||||
## Lifetimes
|
## Lifetimes
|
||||||
|
|
||||||
Lifetimes are placed between `*` and the type, reading as "pointer with lifetime to type":
|
Lifetimes are placed before the type in the `&` suffix:
|
||||||
|
|
||||||
```mist
|
```mist
|
||||||
pub struct Inspector<'a> {
|
pub struct Inspector<'a> {
|
||||||
pub target *'a str,
|
&'a str target,
|
||||||
pub counter *'a mut u32,
|
&'a mut u32 counter,
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
## Allocations
|
## In Classes
|
||||||
In classes, it's very important to initialize heap allocated fields in `constructor` using `path -> expr`, here is the most common example:
|
|
||||||
|
Methods use `&self` for immutable access and `&mut self` for mutable access:
|
||||||
|
|
||||||
```mist
|
```mist
|
||||||
pub class Dog : Animal {
|
pub class Logger {
|
||||||
constructor() {
|
String prefix;
|
||||||
super -> Super::new();
|
|
||||||
|
pub void info(&self, message str&) {
|
||||||
|
println!("{}", message);
|
||||||
|
}
|
||||||
|
|
||||||
|
pub void reset(&mut self) {
|
||||||
|
self.prefix = String::new();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
This outputs `std::ptr::write` which is a force write to memory without dropping what "exists", and it's commonly used in uninitialized memory, such as uninitialized dynamic fields.
|
|
||||||
|
|
||||||
## Key Characteristics
|
## Key Characteristics
|
||||||
|
|
||||||
- **Prefix Pointer Syntax**: `*Type` for shared references, `*mut Type` for mutable references.
|
- **Postfix Reference Syntax**: `T&` for shared references, `T mut&` for mutable references.
|
||||||
- **Explicit Intent**: The `*mut` syntax clearly distinguishes read-only from writable references, mapping 1:1 to Rust's `&` and `&mut`.
|
- **Explicit Intent**: The `mut&` syntax clearly distinguishes read-only from writable references.
|
||||||
- **Visual Consistency**: Lifetimes (`'a`) are placed before the type in `*'a Type`, keeping the declaration flow left-to-right.
|
- **Visual Consistency**: Lifetimes (`'a`) are placed before the type in `&'a T`.
|
||||||
- **Safety Guaranteed**: Despite the "pointer" appearance, the Mist compiler enforces Rust's borrow checker.
|
- **Safety Guaranteed**: The Mist compiler enforces Rust's borrow checker.
|
||||||
- **Zero Overhead**: Mist pointers compile to identical machine code as Rust references.
|
- **Zero Overhead**: Mist references compile to identical machine code as Rust references.
|
||||||
|
|||||||
@@ -1,20 +1,20 @@
|
|||||||
---
|
---
|
||||||
title: Structs
|
title: Structs
|
||||||
description: Data modeling with Mist's name-first field convention.
|
description: Data modeling with Mist's type-first field convention.
|
||||||
icon: Form
|
icon: Form
|
||||||
---
|
---
|
||||||
|
|
||||||
Structs in Mist follow the same structural logic as Rust, with fields using the language-wide `name Type` convention and comma-separated grouping.
|
Structs in Mist follow the same structural logic as Rust, with fields using the language-wide `Type name` convention and comma-separated grouping.
|
||||||
|
|
||||||
## Basic Syntax
|
## Basic Syntax
|
||||||
|
|
||||||
A struct is defined by its name followed by a block of fields. Each field places the identifier before the type.
|
A struct is defined by its name followed by a block of fields. Each field places the type before the identifier.
|
||||||
|
|
||||||
```mist
|
```mist
|
||||||
pub struct Task {
|
pub struct Task {
|
||||||
pub name String,
|
pub String name,
|
||||||
pub state TaskState,
|
pub TaskState state,
|
||||||
pub executions i32,
|
pub i32 executions,
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -24,14 +24,14 @@ Use the `pub` modifier to make the struct or its individual fields accessible fr
|
|||||||
|
|
||||||
```mist
|
```mist
|
||||||
pub struct NetworkNode {
|
pub struct NetworkNode {
|
||||||
pub id u32,
|
pub u32 id,
|
||||||
address *str,
|
str& address,
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
## Instantiation
|
## Instantiation
|
||||||
|
|
||||||
Structs are instantiated using the standard brace syntax.
|
Structs are instantiated using standard brace syntax.
|
||||||
|
|
||||||
```mist
|
```mist
|
||||||
let task = Task {
|
let task = Task {
|
||||||
@@ -41,29 +41,44 @@ let task = Task {
|
|||||||
};
|
};
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## Mutation
|
||||||
|
|
||||||
|
Use `let mut` to allow field reassignment.
|
||||||
|
|
||||||
|
```mist
|
||||||
|
let mut p = Point {
|
||||||
|
x: 1,
|
||||||
|
y: 2,
|
||||||
|
};
|
||||||
|
p.x = 100;
|
||||||
|
```
|
||||||
|
|
||||||
## Destructuring
|
## Destructuring
|
||||||
|
|
||||||
Struct patterns use `let` with the struct name and field bindings:
|
Struct patterns use `let` with the struct name and field bindings:
|
||||||
|
|
||||||
```mist
|
```mist
|
||||||
let p = Point { x: 3, y: 4 };
|
let p = Point {
|
||||||
|
x: 3,
|
||||||
|
y: 4,
|
||||||
|
};
|
||||||
let Point { x, y } = p;
|
let Point { x, y } = p;
|
||||||
```
|
```
|
||||||
|
|
||||||
## Generics & Lifetimes
|
## Generics
|
||||||
|
|
||||||
Generics and lifetimes are declared in angle brackets after the struct name. Reference types use the `*` prefix.
|
Generics and lifetimes are declared in angle brackets after the struct name.
|
||||||
|
|
||||||
```mist
|
```mist
|
||||||
pub struct Buffer<'a, T> {
|
pub struct Buffer<'a, T> {
|
||||||
pub data *'a T,
|
&'a T data,
|
||||||
pub len usize,
|
usize len,
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
## Key Characteristics
|
## Key Characteristics
|
||||||
|
|
||||||
- **Name-First Declaration**: Fields use `name Type` order, consistent with function parameters and variable declarations.
|
- **Type-First Declaration**: Fields use `Type name` order, consistent with function parameters and variable declarations.
|
||||||
- **Comma-Separated Members**: Fields are separated by commas, maintaining a clean delimiter style.
|
- **Comma-Separated Members**: Fields are separated by commas, maintaining a clean delimiter style.
|
||||||
- **Rust Compatibility**: Maps 1:1 to Rust structs, ensuring zero-cost abstraction and full ecosystem interoperability.
|
- **Rust Compatibility**: Maps 1:1 to Rust structs, ensuring zero-cost abstraction and full ecosystem interoperability.
|
||||||
- **Direct Visibility**: The `pub` modifier controls access at the struct and field level.
|
- **Direct Visibility**: The `pub` modifier controls access at the struct and field level.
|
||||||
|
|||||||
@@ -4,16 +4,16 @@ description: Defining shared behavior and contracts with Mist's signature ergono
|
|||||||
icon: Sparkles
|
icon: Sparkles
|
||||||
---
|
---
|
||||||
|
|
||||||
Traits in Mist define a set of methods that a type must implement, facilitating polymorphism and shared behavior. Method signatures use the `fn` keyword with `*self` for the instance parameter.
|
Traits in Mist define a set of methods that a type must implement, facilitating polymorphism and shared behavior. Method signatures use C-style syntax with `&self` for the instance parameter.
|
||||||
|
|
||||||
## Defining a Trait
|
## Defining a Trait
|
||||||
|
|
||||||
A trait lists method signatures using `fn`, with `*self` as the instance parameter and the return type after the parameter list.
|
A trait lists method signatures using return-type-first syntax, with `&self` as the instance parameter.
|
||||||
|
|
||||||
```mist
|
```mist
|
||||||
pub trait Drawable {
|
pub trait Drawable {
|
||||||
fn draw(*self);
|
void draw(&self);
|
||||||
fn metadata(*self) *str;
|
str& metadata(&self);
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -23,11 +23,11 @@ Use `impl Trait for Type` to provide implementations:
|
|||||||
|
|
||||||
```mist
|
```mist
|
||||||
impl Drawable for Task {
|
impl Drawable for Task {
|
||||||
fn draw(*self) {
|
void draw(&self) {
|
||||||
println!("Drawing task: {}", self.name);
|
println!("Drawing task: {}", self.name);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn metadata(*self) *str {
|
str& metadata(&self) {
|
||||||
self.name
|
self.name
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -39,9 +39,9 @@ Traits can provide default behavior for methods that implementing types may over
|
|||||||
|
|
||||||
```mist
|
```mist
|
||||||
pub trait Identifiable {
|
pub trait Identifiable {
|
||||||
fn get_id(*self) u32;
|
u32 get_id(&self);
|
||||||
|
|
||||||
fn is_valid(*self) bool {
|
bool is_valid(&self) {
|
||||||
self.get_id() > 0
|
self.get_id() > 0
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -53,18 +53,18 @@ A trait can require another trait using the colon `:` syntax:
|
|||||||
|
|
||||||
```mist
|
```mist
|
||||||
pub trait Speak {
|
pub trait Speak {
|
||||||
fn speak(*self) String;
|
String speak(&self);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait Greet : Speak {
|
pub trait Greet : Speak {
|
||||||
fn greet(*self) String;
|
String greet(&self);
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
## Key Characteristics
|
## Key Characteristics
|
||||||
|
|
||||||
- **`fn` Signatures**: Method signatures use `fn`, consistent with free functions.
|
- **C-Style Signatures**: Return type before name — no `fn` keyword.
|
||||||
- **Explicit Context**: Methods use `*self` as the first parameter, mapping directly to Rust's reference rules.
|
- **Explicit Context**: Methods use `&self` as the first parameter, mapping directly to Rust's reference rules.
|
||||||
- **Default Methods**: Traits can provide default implementations.
|
- **Default Methods**: Traits can provide default implementations.
|
||||||
- **Super-traits**: Colon syntax for expressing trait requirements.
|
- **Super-traits**: Colon syntax for expressing trait requirements.
|
||||||
- **Static Dispatch**: By default, Mist traits leverage Rust's zero-cost generics and monomorphization.
|
- **Static Dispatch**: By default, Mist traits leverage Rust's zero-cost generics and monomorphization.
|
||||||
|
|||||||
+20
-16
@@ -8,12 +8,16 @@ icon: Rocket
|
|||||||
|
|
||||||
Mist is currently distributed as a Cargo crate. To get started, you'll need to have the Rust toolchain installed.
|
Mist is currently distributed as a Cargo crate. To get started, you'll need to have the Rust toolchain installed.
|
||||||
|
|
||||||
Run the following command to install the Mist compiler:
|
Run the following command to install the Mist toolchain:
|
||||||
|
|
||||||
```bash title="Terminal"
|
```bash title="Terminal"
|
||||||
cargo install [email protected].1-alpha.0
|
cargo install [email protected].7-alpha.0
|
||||||
```
|
```
|
||||||
|
|
||||||
|
> (ℹ) For a more streamlined development experience, Install the following VSCode extensions:
|
||||||
|
> 1. [Mist syntax highlighting VSCode extension](https://marketplace.visualstudio.com/items?itemName=selimaj-dev.mist-syntax)
|
||||||
|
> 2. [Mist analyzer LSP VSCode extension](https://marketplace.visualstudio.com/items?itemName=selimaj-dev.mist-analyzer)
|
||||||
|
|
||||||
Once the installation finishes, verify it by checking the version:
|
Once the installation finishes, verify it by checking the version:
|
||||||
|
|
||||||
```bash title="Terminal"
|
```bash title="Terminal"
|
||||||
@@ -22,39 +26,39 @@ mist version
|
|||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
## 2. Setting Up Your Project
|
## 2. Setting Up Your Cargo Project
|
||||||
|
|
||||||
Mist works alongside Cargo to handle the heavy lifting. Use `init` to scaffold a new project:
|
Mist works alongside Cargo to handle the heavy lifting. Use `cargo new` or `cargo init` to scaffold a new project:
|
||||||
|
|
||||||
```bash title="Terminal"
|
```bash title="Terminal"
|
||||||
cargo new my-mist-app
|
cargo new my-mist-app
|
||||||
cd my-mist-app
|
cd my-mist-app
|
||||||
mist init
|
|
||||||
```
|
```
|
||||||
|
|
||||||
This creates a `src/main.mist` and wires up the output directory (`.mist/src/`) in your `Cargo.toml`.
|
This creates a `src/main.mist` and wires up the output directory (`.mist/src/`) in your `Cargo.toml`.
|
||||||
|
|
||||||
### Manual Setup
|
### 3. Adding mist to your Cargo project
|
||||||
|
|
||||||
If you prefer to configure things yourself, create a `mist.json` file:
|
Mist needs a `Mist.toml` in the root of the project (Alongside `Cargo.toml`) to know what to transpile as the main file (eg. main.mist, lib.mist).
|
||||||
|
|
||||||
```json title="mist.json"
|
```toml title="Mist.toml"
|
||||||
{
|
# main.mist is now the main package
|
||||||
"src": "src",
|
package = "main.mist"
|
||||||
"output": "build"
|
|
||||||
}
|
# Side packages that work as cargo binaries
|
||||||
|
packages = []
|
||||||
```
|
```
|
||||||
|
|
||||||
Source files go in `src/` and the transpiled output goes to `.mist/src/`. Non-Mist files in `src/` (e.g. Rust sidecar files) are copied through as-is.
|
Source files go in `src/` and the transpiled output goes to `.mist/src/`. Non-Mist files in `src/` (e.g. Rust sidecar files) are copied through as-is.
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
## 3. Your First Program
|
## 4. Your First Program
|
||||||
|
|
||||||
Create a new file at `src/main.mist` and add the following code:
|
Create a new file at `src/main.mist` and add the following code:
|
||||||
|
|
||||||
```mist title="src/main.mist"
|
```mist title="src/main.mist"
|
||||||
fn main() {
|
void main() {
|
||||||
println!("Hello World!");
|
println!("Hello World!");
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
@@ -62,7 +66,7 @@ fn main() {
|
|||||||
### Build and Run
|
### Build and Run
|
||||||
|
|
||||||
```bash title="Terminal"
|
```bash title="Terminal"
|
||||||
mist run # or the short alias: mist r
|
mist run # or: mist r
|
||||||
mist build # or: mist b
|
mist build # or: mist b
|
||||||
mist check # or: mist c
|
mist check # or: mist c
|
||||||
mist transpile # or: mist t
|
mist transpile # or: mist t
|
||||||
@@ -74,7 +78,7 @@ mist transpile # or: mist t
|
|||||||
|
|
||||||
| Command | Alias | Description |
|
| Command | Alias | Description |
|
||||||
| -------------------- | ----- | ----------------------------------------------- |
|
| -------------------- | ----- | ----------------------------------------------- |
|
||||||
| `mist init` | | Initializes a new Mist project |
|
| `mist init` | | Initializes a new Mist project (Deprecated) |
|
||||||
| `mist run` | `r` | Runs the project in the current directory |
|
| `mist run` | `r` | Runs the project in the current directory |
|
||||||
| `mist build` | `b` | Builds the project in the current directory |
|
| `mist build` | `b` | Builds the project in the current directory |
|
||||||
| `mist transpile` | `t` | Transpiles the project in the current directory |
|
| `mist transpile` | `t` | Transpiles the project in the current directory |
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ description: Understanding the Alpha state of Mist and our technical roadmap.
|
|||||||
icon: TriangleAlert
|
icon: TriangleAlert
|
||||||
---
|
---
|
||||||
|
|
||||||
Mist is currently in a **Volatile Alpha** stage. Our current priority is exploring **Syntax and Features**. We believe in stabilizing the developer experience and the "feel" of the language before locking in the deep architectural logic of the compiler.
|
Mist is currently in a **Volatile Alpha** stage (latest: v0.3.7-alpha.0). Our current priority is exploring **Syntax and Features**. We believe in stabilizing the developer experience and the "feel" of the language before locking in the deep architectural logic of the compiler.
|
||||||
|
|
||||||
The compiler, transpiler, and CLI are partially bootstrapped — written in Mist itself. This gives us real-world feedback on every language design decision.
|
The compiler, transpiler, and CLI are partially bootstrapped — written in Mist itself. This gives us real-world feedback on every language design decision.
|
||||||
|
|
||||||
|
|||||||
@@ -4,26 +4,23 @@ description: Directing execution with expression-based logic, pattern matching,
|
|||||||
icon: Split
|
icon: Split
|
||||||
---
|
---
|
||||||
|
|
||||||
Control flow in Mist provides a bridge between C-style procedural logic and Rust's expression-oriented design. Blocks, if statements, while/for/loop loops, and match expressions all support statement bodies.
|
Control flow in Mist provides a bridge between C-style procedural logic and Rust's expression-oriented design. Conditions do not require parentheses, and blocks support expression bodies.
|
||||||
|
|
||||||
## Conditionals
|
## Conditionals
|
||||||
|
|
||||||
The `if` statement evaluates a boolean expression:
|
The `if` statement evaluates a boolean expression without parentheses:
|
||||||
|
|
||||||
```mist
|
```mist
|
||||||
if (score > 50) {
|
if score > 50 {
|
||||||
println!("Pass");
|
println!("Pass");
|
||||||
} else if (score == 50) {
|
} else if score == 50 {
|
||||||
println!("Borderline");
|
println!("Borderline");
|
||||||
} else {
|
} else {
|
||||||
println!("Fail");
|
println!("Fail");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Single-statement body (no braces needed)
|
|
||||||
if (is_active) println!("Running");
|
|
||||||
|
|
||||||
// Expression body (implicit return)
|
// Expression body (implicit return)
|
||||||
let result = if (valid) { "ok" } else { "err" };
|
let result = if valid { "ok" } else { "err" };
|
||||||
```
|
```
|
||||||
|
|
||||||
## Match
|
## Match
|
||||||
@@ -31,7 +28,7 @@ let result = if (valid) { "ok" } else { "err" };
|
|||||||
The `match` statement provides exhaustive pattern matching with support for multiple patterns per arm via `|`:
|
The `match` statement provides exhaustive pattern matching with support for multiple patterns per arm via `|`:
|
||||||
|
|
||||||
```mist
|
```mist
|
||||||
match (task_state) {
|
match task_state {
|
||||||
TaskState::Pending => { println!("Queued"); }
|
TaskState::Pending => { println!("Queued"); }
|
||||||
TaskState::Failed { reason, code } => {
|
TaskState::Failed { reason, code } => {
|
||||||
println!("Error {}: {}", code, reason);
|
println!("Error {}: {}", code, reason);
|
||||||
@@ -49,9 +46,9 @@ Patterns support destructuring, or-patterns, and wildcards:
|
|||||||
let x = 2;
|
let x = 2;
|
||||||
let result;
|
let result;
|
||||||
|
|
||||||
match (x) {
|
match x {
|
||||||
1 => { result = 10; }
|
1 => { result = 10; }
|
||||||
2 => { result = 20; }
|
2 => result = 20,
|
||||||
3 => { result = 30; }
|
3 => { result = 30; }
|
||||||
_ => panic!();
|
_ => panic!();
|
||||||
}
|
}
|
||||||
@@ -66,33 +63,39 @@ An infinite loop construct:
|
|||||||
```mist
|
```mist
|
||||||
loop {
|
loop {
|
||||||
println!("forever");
|
println!("forever");
|
||||||
if (done) break;
|
if done { break; }
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
### For-In Loop
|
### For-In Loop
|
||||||
|
|
||||||
For loops iterate over an expression using the `pattern : expr` syntax:
|
For loops iterate over an expression using `for pattern in expr` syntax:
|
||||||
|
|
||||||
```mist
|
```mist
|
||||||
for (i : 0..4) {
|
for i in 0 .. 4 {
|
||||||
sum += i;
|
sum += i;
|
||||||
}
|
}
|
||||||
|
|
||||||
// With pattern destructuring
|
// With pattern destructuring
|
||||||
for ([k, _] : pairs) {
|
for (k, _) in pairs {
|
||||||
keys += k;
|
keys += k;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// With range variable
|
||||||
|
let r = 0 .. 5;
|
||||||
|
for i in r {
|
||||||
|
count++;
|
||||||
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
### While Loop
|
### While Loop
|
||||||
|
|
||||||
```mist
|
```mist
|
||||||
while (count < 5) {
|
while count < 5 {
|
||||||
count++;
|
count++;
|
||||||
}
|
}
|
||||||
|
|
||||||
while (active) {
|
while active {
|
||||||
wait_for_event();
|
wait_for_event();
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
@@ -105,7 +108,8 @@ while (active) {
|
|||||||
|
|
||||||
## Key Characteristics
|
## Key Characteristics
|
||||||
|
|
||||||
- **Statement Bodies**: If, while, for, and loop branches can omit braces for single statements or expressions.
|
- **No Parentheses**: Conditions in `if`, `while`, and `match` do not require parentheses.
|
||||||
- **Implicit Returns**: Expression bodies (without `;`) implicitly return their value.
|
- **Implicit Returns**: Expression bodies implicitly return their value.
|
||||||
- **Pattern Integration**: Loops and match arms utilize Mist's pattern system for data destructuring.
|
- **Pattern Integration**: Loops and match arms utilize Mist's pattern system for data destructuring.
|
||||||
- **Multiple Patterns**: Match arms support `|` for matching multiple patterns.
|
- **Multiple Patterns**: Match arms support `|` for matching multiple patterns.
|
||||||
|
- **Expression `if`**: `if/else` blocks can be used as expressions.
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ Primary expressions are the starting point of any logic chain. These include lit
|
|||||||
|
|
||||||
```mist
|
```mist
|
||||||
let x = 42;
|
let x = 42;
|
||||||
let y = Math::PI;
|
let pi = Math::PI;
|
||||||
let coordinates = (10, 20, 30);
|
let coordinates = (10, 20, 30);
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -72,9 +72,11 @@ let content = fs::read_to_string(path)?;
|
|||||||
|
|
||||||
### Range Operators
|
### Range Operators
|
||||||
|
|
||||||
|
Ranges use spaced `..` syntax:
|
||||||
|
|
||||||
```mist
|
```mist
|
||||||
0..10 // exclusive range (0 to 9)
|
0 .. 10 // exclusive range (0 to 9)
|
||||||
0..=10 // inclusive range (0 to 10)
|
0 ..= 10 // inclusive range (0 to 10)
|
||||||
```
|
```
|
||||||
|
|
||||||
### Arrays
|
### Arrays
|
||||||
@@ -108,6 +110,17 @@ let is_equal = (x == y);
|
|||||||
let complex = (a + b) * (c / d);
|
let complex = (a + b) * (c / d);
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## Closures
|
||||||
|
|
||||||
|
Closures use arrow syntax with optional type annotations:
|
||||||
|
|
||||||
|
```mist
|
||||||
|
let add = (a, b) => a + b;
|
||||||
|
let greet = (name str&) => {
|
||||||
|
println!("Hello {}", name);
|
||||||
|
};
|
||||||
|
```
|
||||||
|
|
||||||
## Operator Table
|
## Operator Table
|
||||||
|
|
||||||
| Category | Operators |
|
| Category | Operators |
|
||||||
@@ -126,3 +139,4 @@ let complex = (a + b) * (c / d);
|
|||||||
- **Macro Integration**: Macros use `!` as a postfix operation.
|
- **Macro Integration**: Macros use `!` as a postfix operation.
|
||||||
- **Type Casting**: `as Type` provides explicit type conversion at the expression level.
|
- **Type Casting**: `as Type` provides explicit type conversion at the expression level.
|
||||||
- **Error Propagation**: The `?` operator enables early returns for `Result`/`Option` types.
|
- **Error Propagation**: The `?` operator enables early returns for `Result`/`Option` types.
|
||||||
|
- **Arrow Closures**: `(params) => expr` for concise anonymous functions.
|
||||||
|
|||||||
@@ -4,15 +4,27 @@ description: Local state management with type inference and explicit mutability.
|
|||||||
icon: Variable
|
icon: Variable
|
||||||
---
|
---
|
||||||
|
|
||||||
Variables in Mist are declared with the `let` keyword. Like Rust, variables are immutable by default, and types are written after the name for scannability.
|
Variables in Mist support two declaration styles: inferred typing with `let` and explicit type annotation. Like Rust, variables are immutable by default.
|
||||||
|
|
||||||
## Basic Declaration
|
## Basic Declaration
|
||||||
|
|
||||||
Variables use `let` for automatic type inference. The type annotation is optional — when omitted, the compiler infers the type from the value.
|
Use `let` for automatic type inference:
|
||||||
|
|
||||||
```mist
|
```mist
|
||||||
let x = 42;
|
let x = 42;
|
||||||
let greeting = "Hello Mist";
|
let greeting = "Hello Mist";
|
||||||
|
let s = "hello, world!";
|
||||||
|
```
|
||||||
|
|
||||||
|
## Explicit Typing
|
||||||
|
|
||||||
|
Type annotations are placed before the name:
|
||||||
|
|
||||||
|
```mist
|
||||||
|
i32 x = 42;
|
||||||
|
bool is_active = true;
|
||||||
|
str& name = "mist";
|
||||||
|
f64 pi = 3.14;
|
||||||
```
|
```
|
||||||
|
|
||||||
## Mutability
|
## Mutability
|
||||||
@@ -24,14 +36,20 @@ let mut score = 0;
|
|||||||
score = 100;
|
score = 100;
|
||||||
```
|
```
|
||||||
|
|
||||||
## Explicit Typing
|
Or with explicit typing:
|
||||||
|
|
||||||
Type annotations are placed after the name:
|
|
||||||
|
|
||||||
```mist
|
```mist
|
||||||
let id u64 = 1000234;
|
i32 mut counter = 0;
|
||||||
let is_active bool = true;
|
counter = 10;
|
||||||
let name *str = "mist";
|
```
|
||||||
|
|
||||||
|
## Strings
|
||||||
|
|
||||||
|
String references use `str&` for a natural left-to-right read:
|
||||||
|
|
||||||
|
```mist
|
||||||
|
str& name = "mist";
|
||||||
|
str& greeting = "Hello";
|
||||||
```
|
```
|
||||||
|
|
||||||
## Arrays
|
## Arrays
|
||||||
@@ -43,16 +61,17 @@ let zeros = [0; 10]; // Repeat notation: ten zeroes
|
|||||||
|
|
||||||
## Pattern Destructuring
|
## Pattern Destructuring
|
||||||
|
|
||||||
Tuples are destructured using square brackets:
|
Tuples are destructured using parentheses:
|
||||||
|
|
||||||
```mist
|
```mist
|
||||||
let [a, b] = (10, "hello");
|
let (a, b) = (10, "hello");
|
||||||
let [a, [b, c]] = (1, (2, 3));
|
let (a, (b, c)) = (1, (2, 3));
|
||||||
```
|
```
|
||||||
|
|
||||||
## Key Characteristics
|
## Key Characteristics
|
||||||
|
|
||||||
- **Predictable Order**: The `let` keyword signals a binding, followed by the name, optional type, and optional value.
|
- **Dual Declaration Styles**: `let` for inference, `Type name` for explicit typing.
|
||||||
- **Safety First**: Immutability by default prevents accidental state changes.
|
- **Safety First**: Immutability by default prevents accidental state changes.
|
||||||
- **Zero-Cost Inference**: Type inference is handled entirely at compile time.
|
- **Zero-Cost Inference**: Type inference is handled entirely at compile time.
|
||||||
- **Shadowing**: Mist supports variable shadowing within the same scope.
|
- **Shadowing**: Mist supports variable shadowing within the same scope.
|
||||||
|
- **`str&` Notation**: String references use postfix `&` for clear left-to-right reading.
|
||||||
|
|||||||
+55
-18
@@ -4,33 +4,71 @@ description: The mindset, ergonomics, and feeling of writing Mist.
|
|||||||
icon: Brain
|
icon: Brain
|
||||||
---
|
---
|
||||||
|
|
||||||
**Mist** is a systems programming language designed for those who value the "craft" of software. It is built to provide a serene, tactile authoring environment that stays out of your way, allowing you to focus entirely on the architecture of your solution.
|
**Mist** is a pragmatic systems programming language built on Rust. It uses C/C++ style syntax for quick onboarding while compiling directly to efficient Rust code with zero-cost abstractions and no runtime overhead.
|
||||||
|
|
||||||
By compiling directly to Rust, Mist offers a refined surface layer that maintains industrial-grade safety and performance while prioritizing a flow state that is often lost in modern systems development.
|
All of your favorite Rust libraries work with Mist. It is designed for **low-level applications and embedded programming**, where a type-first approach is preferred and staying close to the metal matters.
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
## The Philosophy of Ergonomics
|
## C++ You Know, Rust You Trust
|
||||||
|
|
||||||
Writing Mist should feel intentional and deeply satisfying. It is built on the belief that systems programming is at its best when it is **calm, predictable, and direct**.
|
Mist is meant to feel like C++ but **be** Rust. It bridges the gap between the ergonomics of a classic systems language and the safety guarantees of Rust's ownership model.
|
||||||
|
|
||||||
### Reducing Expression Overhead
|
### Type-First Syntax
|
||||||
|
|
||||||
Complexity often arises from "expression overhead"—the mental energy spent navigating intricate syntax and symbols. Mist reduces this friction by:
|
Low-level and embedded development demands clarity about what your data is. Mist puts the **type first** — before the name — so declarations read naturally:
|
||||||
|
|
||||||
* **Predictable Flow:** By adopting a consistent `name: Type` convention, code follows a natural rhythm that is easy to write and instantly scannable.
|
```mist
|
||||||
* **Structural Clarity:** Features like unified `class` blocks and explicit `constructor` keywords provide a clear, organized home for your logic, reducing the need to jump between disparate files or implementation blocks.
|
i32 score = 100;
|
||||||
* **Tactile Precision:** Every symbol, from `*mut` pointers to pattern-based variables, is designed to feel physically connected to the data it represents, making the "mechanics" of the language feel like a well-calm tool in your hand.
|
Vec<String> args = env::args().collect();
|
||||||
|
void* data = allocate(size);
|
||||||
|
```
|
||||||
|
|
||||||
|
This mirrors C/C++ declaration syntax, making Mist instantly familiar to embedded and systems programmers while compiling into Rust's strict type system.
|
||||||
|
|
||||||
|
### C-Style Functions
|
||||||
|
|
||||||
|
Functions use the return type before the name — no `fn` keyword needed:
|
||||||
|
|
||||||
|
```mist
|
||||||
|
i32 add(i32 a, i32 b) {
|
||||||
|
a + b
|
||||||
|
}
|
||||||
|
|
||||||
|
void log(message *str) {
|
||||||
|
println!("{}", message);
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
Every function maps directly to a Rust `fn` underneath.
|
||||||
|
|
||||||
|
### Minimal Friction
|
||||||
|
|
||||||
|
* No `let` keyword — `Type name = value` is all you need.
|
||||||
|
* Consistent `name Type` convention across parameters, fields, and locals.
|
||||||
|
* Explicit pointers with `*T` and `*mut T` — clear intent without ceremony.
|
||||||
|
* String references use `str&` for a natural left-to-right read.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Built for Low-Level and Embedded
|
||||||
|
|
||||||
|
Mist is designed from the ground up for systems where resources are constrained and control is required:
|
||||||
|
|
||||||
|
* **No runtime** — no garbage collector, no hidden allocator, no VM.
|
||||||
|
* **Direct memory control** — explicit pointers, manual allocation, predictable layout.
|
||||||
|
* **Zero-cost abstractions** — classes, traits, and generics all resolve at compile time.
|
||||||
|
* **Works with existing Cargo tooling** — use any Rust crate as a library.
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
## A Transparent Surface Layer
|
## A Transparent Surface Layer
|
||||||
|
|
||||||
Mist is not a replacement for Rust; it is a **ergonomic interface** for it. It provides a way to interact with the world’s most powerful systems model through a cleaner lens.
|
Mist is not a replacement for Rust; it is an **ergonomic interface** for it. It provides a way to interact with the world's most powerful systems model through a cleaner lens.
|
||||||
|
|
||||||
* **Zero-Cost Abstractions:** Every high-level structure in Mist—whether it’s a class, an enum variant, or a trait implementation—maps directly to an optimized Rust primitive. There is no "magic," no hidden runtime, and no garbage collector.
|
* **Zero-Cost Abstractions:** Every high-level structure in Mist — classes, enums, traits — maps directly to optimized Rust primitives. No magic, no hidden runtime.
|
||||||
* **Grounded Safety:** Mist doesn't hide memory safety; it makes it easier to express. You retain the full power of the borrow checker, but with a syntax that feels like a classic, high-performance toolkit.
|
* **Grounded Safety:** Mist doesn't hide memory safety; it makes it easier to express. You retain the full power of the borrow checker with syntax that feels like classic C++.
|
||||||
* **Native Fluency:** Because Mist compiles to idiomatic, readable Rust, it is a first-class citizen of the ecosystem. You can utilize any existing crate while writing code that feels uniquely "Mist".
|
* **Native Fluency:** Mist compiles to idiomatic, readable Rust, making it a first-class citizen of the ecosystem. Use any crate while writing code that feels distinctly Mist.
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
@@ -40,8 +78,7 @@ Mist is partially bootstrapped — the compiler's CLI, transpiler, and analyzer
|
|||||||
|
|
||||||
## Why Mist?
|
## Why Mist?
|
||||||
|
|
||||||
Mist is for the developer who needs the rigor of a systems language but wants the comfort of a modern, streamlined environment.
|
* **Familiarity:** C/C++ developers can be productive immediately — no new optical model to learn.
|
||||||
|
* **Safety:** Rust's borrow checker and type system under every expression, no exceptions.
|
||||||
* **Mental Longevity:** Designed for large-scale codebases where readability is paramount to long-term maintenance.
|
* **Control:** Explicit types, explicit pointers, explicit allocation — nothing hidden.
|
||||||
* **Direct Control:** You stay close to the metal, but the language handles the "noise" of idiomatic expression.
|
* **Ecosystem:** The entire Rust crate ecosystem available at your fingertips.
|
||||||
* **Craftsmanship:** Mist is where the discipline of systems programming meets the comfort of a high-end workshop.
|
|
||||||
|
|||||||
+73
-25
@@ -33,9 +33,6 @@
|
|||||||
{
|
{
|
||||||
"include": "#types"
|
"include": "#types"
|
||||||
},
|
},
|
||||||
{
|
|
||||||
"include": "#namespaces"
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
"include": "#imports"
|
"include": "#imports"
|
||||||
},
|
},
|
||||||
@@ -45,6 +42,9 @@
|
|||||||
{
|
{
|
||||||
"include": "#struct_literals"
|
"include": "#struct_literals"
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"include": "#impl"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"include": "#method_calls"
|
"include": "#method_calls"
|
||||||
},
|
},
|
||||||
@@ -212,12 +212,19 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"match": "\\b(fn)\\s+([a-zA-Z_][a-zA-Z0-9_]*)",
|
"match": "\\b(fn)\\s+([a-zA-Z_][a-zA-Z0-9_]*)\\s+([a-zA-Z_][a-zA-Z0-9_]*)",
|
||||||
"captures": {
|
"captures": {
|
||||||
"1": {
|
"1": {
|
||||||
"name": "storage.type.mist"
|
"name": "storage.type.mist"
|
||||||
},
|
},
|
||||||
"2": {
|
"2": {
|
||||||
|
"patterns": [
|
||||||
|
{
|
||||||
|
"include": "#types"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"3": {
|
||||||
"name": "entity.name.function.mist"
|
"name": "entity.name.function.mist"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -227,7 +234,7 @@
|
|||||||
"keywords": {
|
"keywords": {
|
||||||
"patterns": [
|
"patterns": [
|
||||||
{
|
{
|
||||||
"match": "\\b(if|else|while|for|return|break|continue|match|loop)\\b",
|
"match": "\\b(if|else|while|for|return|break|continue|match|loop|in)\\b",
|
||||||
"name": "keyword.control.mist"
|
"name": "keyword.control.mist"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -235,7 +242,7 @@
|
|||||||
"name": "storage.modifier.mist"
|
"name": "storage.modifier.mist"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"match": "\\b(pub|mut|use|mod|as|dyn|unsafe|self|super|Super|constructor|override)\\b",
|
"match": "\\b(pub|mut|use|module|as|dyn|unsafe|self|super|Super|constructor|override)\\b",
|
||||||
"name": "keyword.other.mist"
|
"name": "keyword.other.mist"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -316,38 +323,38 @@
|
|||||||
"types": {
|
"types": {
|
||||||
"patterns": [
|
"patterns": [
|
||||||
{
|
{
|
||||||
"match": "(?<![A-Za-z])(f32|f64|i128|i16|i32|i64|i8|isize|u128|u16|u32|u64|u8|usize)\\b",
|
"match": "(?<![A-Za-z])(f32|f64|i128|i16|i32|i64|i8|isize|u128|u16|u32|u64|u8|usize|str|char|bool|void)\\b",
|
||||||
"name": "entity.name.type.numeric.mist"
|
"name": "storage.type.built-in.primitive.mist"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"match": "(?<![A-Za-z])(str|char|bool)\\b",
|
"match": "\\b((?:[a-z_][a-zA-Z0-9_]*::)*)([A-Z][A-Za-z0-9_]*)\\b",
|
||||||
"name": "entity.name.type.other.mist"
|
"captures": {
|
||||||
|
"1": {
|
||||||
|
"name": "entity.name.namespace.mist"
|
||||||
|
},
|
||||||
|
"2": {
|
||||||
|
"name": "entity.name.type.mist"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"include": "#operators"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"match": "\\b_?[A-Z][A-Za-z0-9_]*\\b(?!!)",
|
"match": "\\b[A-Z][A-Za-z0-9_]*\\b",
|
||||||
"name": "entity.name.type.mist"
|
"name": "entity.name.type.mist"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"namespaces": {
|
|
||||||
"match": "\\b([a-zA-Z_][a-zA-Z0-9_]*)(?=\\s*::)",
|
|
||||||
"captures": {
|
|
||||||
"1": {
|
|
||||||
"name": "entity.name.namespace.mist"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"imports": {
|
"imports": {
|
||||||
"match": "\\buse\\s+([a-zA-Z_][a-zA-Z0-9_]*(?:\\s*::\\s*[a-zA-Z_][a-zA-Z0-9_]*)*)\\s*;",
|
"match": "\\buse\\s+([a-zA-Z_][a-zA-Z0-9_]*(?:\\s*::\\s*[a-zA-Z_][a-zA-Z0-9_]*)*)\\s*;",
|
||||||
"captures": {
|
"patterns": [
|
||||||
"1": {
|
{
|
||||||
"name": "entity.name.namespace.mist"
|
"include": "#types"
|
||||||
}
|
}
|
||||||
},
|
],
|
||||||
"name": "meta.import.mist"
|
"name": "meta.import.mist"
|
||||||
},
|
},
|
||||||
"modules": {
|
"modules": {
|
||||||
"match": "(?:pub\\s+)?\\bmod\\s+([a-zA-Z_][a-zA-Z0-9_]*)\\s*;",
|
"match": "(?:pub\\s+)?\\bmodule\\s+([a-zA-Z_][a-zA-Z0-9_]*)\\s*;",
|
||||||
"captures": {
|
"captures": {
|
||||||
"1": {
|
"1": {
|
||||||
"name": "entity.name.namespace.module.mist"
|
"name": "entity.name.namespace.module.mist"
|
||||||
@@ -444,10 +451,51 @@
|
|||||||
"match": "\\b([a-zA-Z_][a-zA-Z0-9_]*)\\s*(?=\\()",
|
"match": "\\b([a-zA-Z_][a-zA-Z0-9_]*)\\s*(?=\\()",
|
||||||
"name": "entity.name.function.mist"
|
"name": "entity.name.function.mist"
|
||||||
},
|
},
|
||||||
|
"impl": {
|
||||||
|
"patterns": [
|
||||||
|
{
|
||||||
|
"match": "\\b(impl)\\s+([a-zA-Z_][a-zA-Z0-9_]*)\\s+for\\s+([a-zA-Z_][a-zA-Z0-9_]*)",
|
||||||
|
"captures": {
|
||||||
|
"1": {
|
||||||
|
"name": "storage.type.mist"
|
||||||
|
},
|
||||||
|
"2": {
|
||||||
|
"patterns": [
|
||||||
|
{
|
||||||
|
"include": "#types"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"3": {
|
||||||
|
"patterns": [
|
||||||
|
{
|
||||||
|
"include": "#types"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"match": "\\b(impl)\\s+([a-zA-Z_][a-zA-Z0-9_]*)\\s+",
|
||||||
|
"captures": {
|
||||||
|
"1": {
|
||||||
|
"name": "storage.type.mist"
|
||||||
|
},
|
||||||
|
"2": {
|
||||||
|
"patterns": [
|
||||||
|
{
|
||||||
|
"include": "#types"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
"operators": {
|
"operators": {
|
||||||
"patterns": [
|
"patterns": [
|
||||||
{
|
{
|
||||||
"match": "(?:\\+=|-=|\\*=|\\/=|%=|&=|\\|=|\\^=|<<=|>>=|<<|>>|\\.\\.=|\\.\\.|<=|>=|==|!=|&&|\\|\\||[+\\-*/%<>&|^=!]|\\+\\+|--)",
|
"match": "(?:\\+=|-=|\\*=|\\/=|%=|&=|\\|=|\\^=|<<=|>>=|<<|>>|\\.\\.=|\\.\\.|<=|>=|==|!=|&&|\\|\\||[+\\-*/%<>&|^=!]|\\+\\+|--|:)",
|
||||||
"name": "keyword.operator.mist"
|
"name": "keyword.operator.mist"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|||||||
+33
-62
@@ -12,19 +12,24 @@ const MotionLink = motion(Link);
|
|||||||
|
|
||||||
export const mistShowcase = [
|
export const mistShowcase = [
|
||||||
{
|
{
|
||||||
title: "Rust.. With ergonomics?",
|
title: "Rust.. With classes?",
|
||||||
description:
|
description:
|
||||||
"C/C++/Java style syntax for comfort. Mist is designed for fast, readable systems code with minimal friction compared to raw Rust.",
|
"C++ style syntax for comfort. Mist is designed for fast, readable systems code with minimal friction compared to raw Rust.",
|
||||||
code: `fn main() {
|
code: `pub class Player
|
||||||
println!("Hello, World!");
|
{
|
||||||
|
pub String name;
|
||||||
|
pub i32 hp;
|
||||||
|
|
||||||
greet("Developer");
|
pub constructor(str& name)
|
||||||
}
|
{
|
||||||
|
self.name = name.to_string();
|
||||||
|
self.hp = 100;
|
||||||
|
}
|
||||||
|
|
||||||
pub fn greet(name *str) {
|
pub bool is_dead(&self)
|
||||||
let greeting String = name.to_string();
|
{
|
||||||
|
self.hp <= 0
|
||||||
println!("Hello, {}!", greeting);
|
}
|
||||||
}`,
|
}`,
|
||||||
cta: true,
|
cta: true,
|
||||||
},
|
},
|
||||||
@@ -33,67 +38,33 @@ pub fn greet(name *str) {
|
|||||||
title: "Fast and works with Rust",
|
title: "Fast and works with Rust",
|
||||||
description:
|
description:
|
||||||
"All of your favorite Rust libraries work with Mist. It compiles directly into efficient Rust code with zero-cost abstractions and no runtime overhead.",
|
"All of your favorite Rust libraries work with Mist. It compiles directly into efficient Rust code with zero-cost abstractions and no runtime overhead.",
|
||||||
code: `use std::sync::Arc;
|
code: `use serde::Deserialize;
|
||||||
use external_lib;
|
|
||||||
|
|
||||||
void process_data() {
|
#[Deserialize]
|
||||||
let list = Arc::new(Vec::new());
|
pub struct MyJsonComponent
|
||||||
external_lib::perform_task(list);
|
{
|
||||||
|
pub String name,
|
||||||
}`,
|
}`,
|
||||||
},
|
},
|
||||||
|
|
||||||
{
|
{
|
||||||
title: "Class and Type System",
|
title: "Class and Type System",
|
||||||
description:
|
description:
|
||||||
"Classes are syntactic sugar for Rust structs. Using ':' provides inheritance-style syntax over struct composition, compiling into the underlying Rust type system.",
|
"Classes work similarly to c++ inheritance, with safety ensuring that fields are initialized",
|
||||||
code: `pub class Dog : Animal {
|
code: `pub class Car : Vehicle
|
||||||
constructor() {
|
{
|
||||||
super -> Super::new();
|
pub i32 horse_power;
|
||||||
|
|
||||||
|
constructor()
|
||||||
|
{
|
||||||
|
super = Super::new();
|
||||||
|
self.horse_power = 300;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub override fn speak(*self) {
|
pub void accelerate() override
|
||||||
println!("Woof!");
|
{
|
||||||
}
|
// speed inherited from Vehicle (via DerefMut)
|
||||||
|
self.speed *= horse_power;
|
||||||
// Explicit override is useful for super inheritance
|
|
||||||
pub override(Animal) fn legs(*self) u32 {
|
|
||||||
println!("4 legs");
|
|
||||||
}
|
|
||||||
}`,
|
|
||||||
},
|
|
||||||
|
|
||||||
{
|
|
||||||
title: "Better Developer Experience",
|
|
||||||
description:
|
|
||||||
"While Rust can already be a great DX, Mist implements concepts that are proven to improve modular structure.",
|
|
||||||
code: `pub class Animal {
|
|
||||||
pub name String;
|
|
||||||
|
|
||||||
constructor() {
|
|
||||||
self.name = "Rex".to_string();
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn speak(*self) {
|
|
||||||
println!("Unknown");
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn legs(*self) {
|
|
||||||
println!("Unknown");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub class Dog : Animal {
|
|
||||||
constructor() {
|
|
||||||
super -> Super::new();
|
|
||||||
}
|
|
||||||
|
|
||||||
pub override fn speak(*self) {
|
|
||||||
println!("Woof!");
|
|
||||||
}
|
|
||||||
|
|
||||||
// Explicit override is useful for super inheritance
|
|
||||||
pub override(Animal) fn legs(*self) {
|
|
||||||
println!("4 legs");
|
|
||||||
}
|
}
|
||||||
}`,
|
}`,
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user