diff --git a/content/docs/components/classes.mdx b/content/docs/components/classes.mdx index cb0ed2e..90a3a84 100644 --- a/content/docs/components/classes.mdx +++ b/content/docs/components/classes.mdx @@ -4,21 +4,21 @@ description: Unified data and behavior with Java-style organization and Rust-pow 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 -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 pub class Logger { - prefix String; + String prefix; - pub fn info(*self, message *str) { + pub void info(&self, message str&) { self.log(LogLevel::Info, message); } - fn log(*self, level LogLevel, message *str) { + void log(&self, LogLevel level, message str&) { println!("{level} {} {}", self.prefix, message); } } @@ -37,58 +37,71 @@ pub constructor() { Constructors can take parameters: ```mist -pub constructor(prefix String) { +pub constructor(String 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 -pub fn warning(*self, message *str) { +pub void warning(&self, message str&) { self.log(LogLevel::Warning, message); } -pub fn reset(*mut self) { +pub void reset(&mut self) { self.prefix = String::new(); } ``` ## 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 pub class Animal { - pub name String; + pub String name; constructor() { self.name = "Rex".to_string(); } - pub fn speak(*self) { - println!("Unknown"); - } - - pub fn legs(*self) { - println!("Unknown"); + pub String speak(&self) { + "Unknown".to_string() } } pub class Dog : Animal { constructor() { - super -> Super::new(); + super = Super::new(); } - pub override fn speak(*self) { - println!("Woof!"); + pub String speak(&self) override(Animal) { + "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 override(Animal) fn legs(*self) { - println!("4 legs"); + pub String speak(&self) override(Animal) { + "Woof!".to_string() + } + + 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 pub class Container { - pub value T; + T value; - constructor(val T) { + constructor(T val) { self.value = val; } - pub fn get(*self) *T { + pub &T get(&self) { &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; - - 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 - **Unified Scope**: Data and behavior live in one class block. -- **`fn` Methods**: Methods use the `fn` keyword, consistent with free functions. -- **`*self` Parameter**: The self reference is explicit and uses prefix `*` syntax. -- **Inheritance**: Single inheritance with `override` for polymorphic dispatch. +- **C-Style Methods**: Return type before name โ€” no `fn` keyword. +- **`&self` Parameter**: The self reference is explicit and uses `&` syntax. +- **Inheritance**: Single inheritance with `override(Parent)` for polymorphic dispatch. - **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. diff --git a/content/docs/components/enums.mdx b/content/docs/components/enums.mdx index 994278c..cd26c50 100644 --- a/content/docs/components/enums.mdx +++ b/content/docs/components/enums.mdx @@ -1,14 +1,14 @@ --- 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 --- -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 -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 pub enum TaskState { @@ -16,8 +16,8 @@ pub enum TaskState { InProgress, Completed, Failed { - reason String, - code i32, + String reason, + i32 code, }, } ``` @@ -29,57 +29,59 @@ Mist supports all standard variant shapes: ```mist enum OptionInt { None, // Unit - Some[i32], // Tuple (square brackets) + Some(i32), // Tuple (parentheses) } enum Shape { - Circle { radius i32 }, // Struct-like - Rect { w i32, h i32 }, + Circle { i32 radius }, // Struct-like + Rect { i32 w, i32 h }, } ``` ### Instantiation & Matching -Tuple variants are created with parentheses and matched with brackets: +Tuple variants are created and matched with parentheses: ```mist let x = OptionInt::Some(42); -match (x) { +match x { OptionInt::None => { println!("none"); } - OptionInt::Some[v] => { println!("{}", v); } + OptionInt::Some(v) => { println!("{}", v); } } ``` Struct variants use brace notation: ```mist -let c = Shape::Circle { radius: 5 }; +let c = Shape::Circle { + radius: 5, +}; -match (c) { +match c { Shape::Circle { radius } => { println!("{}", radius); } 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 pub enum Validation<'a, T> { Valid(T), Invalid { - message *'a str, - error_id u32, + &'a str message, + u32 error_id, }, } ``` ## Key Characteristics -- **Consistent Declaration**: Struct-like variants use the `name Type` order, consistent with Mist structs. -- **Square Bracket Tuples**: Tuple variant types use `[]` brackets, distinct from function calls. +- **Consistent Declaration**: Struct-like variants use `Type name` order, consistent with Mist structs. +- **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. - **Shared Visibility**: The `pub` modifier at the enum level exports all variants. - **Comma-Separated Members**: Fields within struct-like variants are separated by commas. diff --git a/content/docs/components/functions.mdx b/content/docs/components/functions.mdx index 7c74a82..ab90cec 100644 --- a/content/docs/components/functions.mdx +++ b/content/docs/components/functions.mdx @@ -4,67 +4,78 @@ description: Defining execution blocks with C-style ergonomics and Rust-powered 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 -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 -fn add(a i32, b i32) i32 { - a + b +void greet() { + println!("Hello!"); } -fn greet() { - println!("Hello!"); +i32 add(i32 a, i32 b) { + 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 -pub fn get_version() i32 { +pub module utils; + +pub i32 get_version() { 1 } -pub(crate) fn internal_use() i32 { - 0 +pub void process() { + // ... } ``` ## 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 -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 } ``` -## 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 -fn choose_longer<'a>(s1 *'a str, s2 *'a str) *'a str { - if (s1.len() > s2.len()) { s1 } else { s2 } +struct Counter { + i32 value, +} + +impl Counter { + pub i32 get(&self) { + self.value + } + + pub void increment(&mut self) { + self.value += 1; + } } ``` ## 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 -let add = fn(a, b) -> a + b; +let add = (a, b) => a + b; add(2, 3); // With a block body -let greet = fn(name *str) { +let greet = (name str&) => { println!("Hello {}", name); }; ``` @@ -75,15 +86,17 @@ Metadata is applied via the `#[attr]` syntax directly above the declaration. ```mist #[inline] -pub fn is_active(id u32) bool { - id > 0 +pub i32 clamp(i32 value, i32 min, i32 max) { + if value < min { min } + else if value > max { max } + else { value } } ``` ## 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. -- **Unified Abstraction**: Lifetimes and type constraints are declared in one location. -- **Closure Support**: Anonymous functions with optional return type annotations. +- **`&self` / `&mut self`**: Explicit self parameter in method definitions. +- **Closure Support**: Arrow syntax `(params) => expr` for anonymous functions. - **Zero-Cost Mapping**: Every function maps directly to a Rust `fn`. diff --git a/content/docs/components/modules-imports.mdx b/content/docs/components/modules-imports.mdx index 37ecfe3..488538a 100644 --- a/content/docs/components/modules-imports.mdx +++ b/content/docs/components/modules-imports.mdx @@ -6,9 +6,24 @@ icon: FolderTree 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 @@ -51,6 +66,7 @@ A typical Mist project looks like this: ``` my-project/ โ”œโ”€โ”€ Cargo.toml +โ”œโ”€โ”€ Mist.toml โ”œโ”€โ”€ src/ โ”‚ โ”œโ”€โ”€ main.mist โ”‚ โ”œโ”€โ”€ my_api/ diff --git a/content/docs/components/pointers-references.mdx b/content/docs/components/pointers-references.mdx index bade751..31a264a 100644 --- a/content/docs/components/pointers-references.mdx +++ b/content/docs/components/pointers-references.mdx @@ -1,29 +1,29 @@ --- 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 --- -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 -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 -let x i32 = 42; -let r *i32 = &x; +i32 x = 42; +i32& r = &x; let mut y = 42; -let r *mut i32 = &mut y; +i32 mut& r = &mut y; *r = 100; ``` In function parameters: ```mist -fn increment(value *mut i32, limit *i32) { - if (*value < *limit) { +void increment(i32 mut& value, i32& limit) { + if *value < *limit { *value = *value + 1; } } @@ -31,30 +31,37 @@ fn increment(value *mut i32, limit *i32) { ## 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 pub struct Inspector<'a> { - pub target *'a str, - pub counter *'a mut u32, + &'a str target, + &'a mut u32 counter, } ``` -## Allocations -In classes, it's very important to initialize heap allocated fields in `constructor` using `path -> expr`, here is the most common example: +## In Classes + +Methods use `&self` for immutable access and `&mut self` for mutable access: + ```mist -pub class Dog : Animal { - constructor() { - super -> Super::new(); +pub class Logger { + String prefix; + + 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 -- **Prefix Pointer Syntax**: `*Type` for shared references, `*mut Type` for mutable references. -- **Explicit Intent**: The `*mut` syntax clearly distinguishes read-only from writable references, mapping 1:1 to Rust's `&` and `&mut`. -- **Visual Consistency**: Lifetimes (`'a`) are placed before the type in `*'a Type`, keeping the declaration flow left-to-right. -- **Safety Guaranteed**: Despite the "pointer" appearance, the Mist compiler enforces Rust's borrow checker. -- **Zero Overhead**: Mist pointers compile to identical machine code as Rust 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. +- **Visual Consistency**: Lifetimes (`'a`) are placed before the type in `&'a T`. +- **Safety Guaranteed**: The Mist compiler enforces Rust's borrow checker. +- **Zero Overhead**: Mist references compile to identical machine code as Rust references. diff --git a/content/docs/components/structs.mdx b/content/docs/components/structs.mdx index bbbcdba..8bb1901 100644 --- a/content/docs/components/structs.mdx +++ b/content/docs/components/structs.mdx @@ -1,20 +1,20 @@ --- title: Structs -description: Data modeling with Mist's name-first field convention. +description: Data modeling with Mist's type-first field convention. 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 -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 pub struct Task { - pub name String, - pub state TaskState, - pub executions i32, + pub String name, + pub TaskState state, + pub i32 executions, } ``` @@ -24,14 +24,14 @@ Use the `pub` modifier to make the struct or its individual fields accessible fr ```mist pub struct NetworkNode { - pub id u32, - address *str, + pub u32 id, + str& address, } ``` ## Instantiation -Structs are instantiated using the standard brace syntax. +Structs are instantiated using standard brace syntax. ```mist 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 Struct patterns use `let` with the struct name and field bindings: ```mist -let p = Point { x: 3, y: 4 }; +let p = Point { + x: 3, + y: 4, +}; 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 pub struct Buffer<'a, T> { - pub data *'a T, - pub len usize, + &'a T data, + usize len, } ``` ## 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. - **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. diff --git a/content/docs/components/traits.mdx b/content/docs/components/traits.mdx index 4c5fe89..5fe5af3 100644 --- a/content/docs/components/traits.mdx +++ b/content/docs/components/traits.mdx @@ -4,16 +4,16 @@ description: Defining shared behavior and contracts with Mist's signature ergono 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 -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 pub trait Drawable { - fn draw(*self); - fn metadata(*self) *str; + void draw(&self); + str& metadata(&self); } ``` @@ -23,11 +23,11 @@ Use `impl Trait for Type` to provide implementations: ```mist impl Drawable for Task { - fn draw(*self) { + void draw(&self) { println!("Drawing task: {}", self.name); } - fn metadata(*self) *str { + str& metadata(&self) { self.name } } @@ -39,9 +39,9 @@ Traits can provide default behavior for methods that implementing types may over ```mist 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 } } @@ -53,18 +53,18 @@ A trait can require another trait using the colon `:` syntax: ```mist pub trait Speak { - fn speak(*self) String; + String speak(&self); } pub trait Greet : Speak { - fn greet(*self) String; + String greet(&self); } ``` ## Key Characteristics -- **`fn` Signatures**: Method signatures use `fn`, consistent with free functions. -- **Explicit Context**: Methods use `*self` as the first parameter, mapping directly to Rust's reference rules. +- **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. - **Default Methods**: Traits can provide default implementations. - **Super-traits**: Colon syntax for expressing trait requirements. - **Static Dispatch**: By default, Mist traits leverage Rust's zero-cost generics and monomorphization. diff --git a/content/docs/index.mdx b/content/docs/index.mdx index 226a1e0..ecb4092 100644 --- a/content/docs/index.mdx +++ b/content/docs/index.mdx @@ -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. -Run the following command to install the Mist compiler: +Run the following command to install the Mist toolchain: ```bash title="Terminal" -cargo install mist-lang@0.3.1-alpha.0 +cargo install mist-lang@0.3.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: ```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" cargo new 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`. -### 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" -{ - "src": "src", - "output": "build" -} +```toml title="Mist.toml" +# main.mist is now the main package +package = "main.mist" + +# 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. --- -## 3. Your First Program +## 4. Your First Program Create a new file at `src/main.mist` and add the following code: ```mist title="src/main.mist" -fn main() { +void main() { println!("Hello World!"); } ``` @@ -62,7 +66,7 @@ fn main() { ### Build and Run ```bash title="Terminal" -mist run # or the short alias: mist r +mist run # or: mist r mist build # or: mist b mist check # or: mist c mist transpile # or: mist t @@ -74,7 +78,7 @@ mist transpile # or: mist t | 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 build` | `b` | Builds the project in the current directory | | `mist transpile` | `t` | Transpiles the project in the current directory | diff --git a/content/docs/limitations.mdx b/content/docs/limitations.mdx index 918e52b..ba296ae 100644 --- a/content/docs/limitations.mdx +++ b/content/docs/limitations.mdx @@ -4,7 +4,7 @@ description: Understanding the Alpha state of Mist and our technical roadmap. 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. diff --git a/content/docs/logic/control-flow.mdx b/content/docs/logic/control-flow.mdx index fe421e2..9ea8f48 100644 --- a/content/docs/logic/control-flow.mdx +++ b/content/docs/logic/control-flow.mdx @@ -4,26 +4,23 @@ description: Directing execution with expression-based logic, pattern matching, 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 -The `if` statement evaluates a boolean expression: +The `if` statement evaluates a boolean expression without parentheses: ```mist -if (score > 50) { +if score > 50 { println!("Pass"); -} else if (score == 50) { +} else if score == 50 { println!("Borderline"); } else { println!("Fail"); } -// Single-statement body (no braces needed) -if (is_active) println!("Running"); - // Expression body (implicit return) -let result = if (valid) { "ok" } else { "err" }; +let result = if valid { "ok" } else { "err" }; ``` ## 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 `|`: ```mist -match (task_state) { +match task_state { TaskState::Pending => { println!("Queued"); } TaskState::Failed { reason, code } => { println!("Error {}: {}", code, reason); @@ -49,9 +46,9 @@ Patterns support destructuring, or-patterns, and wildcards: let x = 2; let result; -match (x) { +match x { 1 => { result = 10; } - 2 => { result = 20; } + 2 => result = 20, 3 => { result = 30; } _ => panic!(); } @@ -66,33 +63,39 @@ An infinite loop construct: ```mist loop { println!("forever"); - if (done) break; + if done { break; } } ``` ### 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 -for (i : 0..4) { +for i in 0 .. 4 { sum += i; } // With pattern destructuring -for ([k, _] : pairs) { +for (k, _) in pairs { keys += k; } + +// With range variable +let r = 0 .. 5; +for i in r { + count++; +} ``` ### While Loop ```mist -while (count < 5) { +while count < 5 { count++; } -while (active) { +while active { wait_for_event(); } ``` @@ -105,7 +108,8 @@ while (active) { ## Key Characteristics -- **Statement Bodies**: If, while, for, and loop branches can omit braces for single statements or expressions. -- **Implicit Returns**: Expression bodies (without `;`) implicitly return their value. +- **No Parentheses**: Conditions in `if`, `while`, and `match` do not require parentheses. +- **Implicit Returns**: Expression bodies implicitly return their value. - **Pattern Integration**: Loops and match arms utilize Mist's pattern system for data destructuring. - **Multiple Patterns**: Match arms support `|` for matching multiple patterns. +- **Expression `if`**: `if/else` blocks can be used as expressions. diff --git a/content/docs/logic/expressions.mdx b/content/docs/logic/expressions.mdx index 9d588f6..5dd9e1e 100644 --- a/content/docs/logic/expressions.mdx +++ b/content/docs/logic/expressions.mdx @@ -12,7 +12,7 @@ Primary expressions are the starting point of any logic chain. These include lit ```mist let x = 42; -let y = Math::PI; +let pi = Math::PI; let coordinates = (10, 20, 30); ``` @@ -72,9 +72,11 @@ let content = fs::read_to_string(path)?; ### Range Operators +Ranges use spaced `..` syntax: + ```mist -0..10 // exclusive range (0 to 9) -0..=10 // inclusive range (0 to 10) +0 .. 10 // exclusive range (0 to 9) +0 ..= 10 // inclusive range (0 to 10) ``` ### Arrays @@ -108,6 +110,17 @@ let is_equal = (x == y); 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 | Category | Operators | @@ -126,3 +139,4 @@ let complex = (a + b) * (c / d); - **Macro Integration**: Macros use `!` as a postfix operation. - **Type Casting**: `as Type` provides explicit type conversion at the expression level. - **Error Propagation**: The `?` operator enables early returns for `Result`/`Option` types. +- **Arrow Closures**: `(params) => expr` for concise anonymous functions. diff --git a/content/docs/logic/variables.mdx b/content/docs/logic/variables.mdx index fbb4d5c..a0b333d 100644 --- a/content/docs/logic/variables.mdx +++ b/content/docs/logic/variables.mdx @@ -4,15 +4,27 @@ description: Local state management with type inference and explicit mutability. 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 -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 let x = 42; 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 @@ -24,14 +36,20 @@ let mut score = 0; score = 100; ``` -## Explicit Typing - -Type annotations are placed after the name: +Or with explicit typing: ```mist -let id u64 = 1000234; -let is_active bool = true; -let name *str = "mist"; +i32 mut counter = 0; +counter = 10; +``` + +## Strings + +String references use `str&` for a natural left-to-right read: + +```mist +str& name = "mist"; +str& greeting = "Hello"; ``` ## Arrays @@ -43,16 +61,17 @@ let zeros = [0; 10]; // Repeat notation: ten zeroes ## Pattern Destructuring -Tuples are destructured using square brackets: +Tuples are destructured using parentheses: ```mist -let [a, b] = (10, "hello"); -let [a, [b, c]] = (1, (2, 3)); +let (a, b) = (10, "hello"); +let (a, (b, c)) = (1, (2, 3)); ``` ## 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. - **Zero-Cost Inference**: Type inference is handled entirely at compile time. - **Shadowing**: Mist supports variable shadowing within the same scope. +- **`str&` Notation**: String references use postfix `&` for clear left-to-right reading. diff --git a/content/docs/philosophy.mdx b/content/docs/philosophy.mdx index 397421d..abab179 100644 --- a/content/docs/philosophy.mdx +++ b/content/docs/philosophy.mdx @@ -4,33 +4,71 @@ description: The mindset, ergonomics, and feeling of writing Mist. 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. -* **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. -* **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. +```mist +i32 score = 100; +Vec 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 -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. -* **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. -* **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". +* **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 with syntax that feels like classic C++. +* **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? -Mist is for the developer who needs the rigor of a systems language but wants the comfort of a modern, streamlined environment. - -* **Mental Longevity:** Designed for large-scale codebases where readability is paramount to long-term maintenance. -* **Direct Control:** You stay close to the metal, but the language handles the "noise" of idiomatic expression. -* **Craftsmanship:** Mist is where the discipline of systems programming meets the comfort of a high-end workshop. +* **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. +* **Control:** Explicit types, explicit pointers, explicit allocation โ€” nothing hidden. +* **Ecosystem:** The entire Rust crate ecosystem available at your fingertips. diff --git a/public/mist.tmLanguage.json b/public/mist.tmLanguage.json index 43a0581..5aa3f27 100644 --- a/public/mist.tmLanguage.json +++ b/public/mist.tmLanguage.json @@ -33,9 +33,6 @@ { "include": "#types" }, - { - "include": "#namespaces" - }, { "include": "#imports" }, @@ -45,6 +42,9 @@ { "include": "#struct_literals" }, + { + "include": "#impl" + }, { "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": { "1": { "name": "storage.type.mist" }, "2": { + "patterns": [ + { + "include": "#types" + } + ] + }, + "3": { "name": "entity.name.function.mist" } } @@ -227,7 +234,7 @@ "keywords": { "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" }, { @@ -235,7 +242,7 @@ "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" }, { @@ -316,38 +323,38 @@ "types": { "patterns": [ { - "match": "(?>=|<<|>>|\\.\\.=|\\.\\.|<=|>=|==|!=|&&|\\|\\||[+\\-*/%<>&|^=!]|\\+\\+|--)", + "match": "(?:\\+=|-=|\\*=|\\/=|%=|&=|\\|=|\\^=|<<=|>>=|<<|>>|\\.\\.=|\\.\\.|<=|>=|==|!=|&&|\\|\\||[+\\-*/%<>&|^=!]|\\+\\+|--|:)", "name": "keyword.operator.mist" } ] diff --git a/src/app/(home)/page.tsx b/src/app/(home)/page.tsx index 6499cba..ddef00d 100644 --- a/src/app/(home)/page.tsx +++ b/src/app/(home)/page.tsx @@ -12,19 +12,24 @@ const MotionLink = motion(Link); export const mistShowcase = [ { - title: "Rust.. With ergonomics?", + title: "Rust.. With classes?", description: - "C/C++/Java style syntax for comfort. Mist is designed for fast, readable systems code with minimal friction compared to raw Rust.", - code: `fn main() { - println!("Hello, World!"); + "C++ style syntax for comfort. Mist is designed for fast, readable systems code with minimal friction compared to raw Rust.", + code: `pub class Player +{ + pub String name; + pub i32 hp; - greet("Developer"); -} - -pub fn greet(name *str) { - let greeting String = name.to_string(); - - println!("Hello, {}!", greeting); + pub constructor(str& name) + { + self.name = name.to_string(); + self.hp = 100; + } + + pub bool is_dead(&self) + { + self.hp <= 0 + } }`, cta: true, }, @@ -33,67 +38,33 @@ pub fn greet(name *str) { title: "Fast and works with Rust", 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.", - code: `use std::sync::Arc; -use external_lib; + code: `use serde::Deserialize; -void process_data() { - let list = Arc::new(Vec::new()); - external_lib::perform_task(list); +#[Deserialize] +pub struct MyJsonComponent +{ + pub String name, }`, }, { title: "Class and Type System", description: - "Classes are syntactic sugar for Rust structs. Using ':' provides inheritance-style syntax over struct composition, compiling into the underlying Rust type system.", - code: `pub class Dog : Animal { - constructor() { - super -> Super::new(); + "Classes work similarly to c++ inheritance, with safety ensuring that fields are initialized", + code: `pub class Car : Vehicle +{ + pub i32 horse_power; + + constructor() + { + super = Super::new(); + self.horse_power = 300; } - pub override fn speak(*self) { - println!("Woof!"); - } - - // 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"); + pub void accelerate() override + { + // speed inherited from Vehicle (via DerefMut) + self.speed *= horse_power; } }`, },