Updated docs to new version
This commit is contained in:
@@ -15,8 +15,8 @@ Outer attributes apply to the next item:
|
|||||||
```mist
|
```mist
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
struct Point {
|
struct Point {
|
||||||
i32 x,
|
i32 x;
|
||||||
i32 y,
|
i32 y;
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|||||||
@@ -33,6 +33,29 @@ class Player
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### Virtual Methods
|
||||||
|
|
||||||
|
The `virtual` keyword marks methods as dispatchable through the vtable, enabling polymorphic behavior:
|
||||||
|
|
||||||
|
```mist
|
||||||
|
pub class Animal
|
||||||
|
{
|
||||||
|
str& name;
|
||||||
|
|
||||||
|
pub constructor(str& name)
|
||||||
|
{
|
||||||
|
self.name = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
pub virtual void speak(&self)
|
||||||
|
{
|
||||||
|
println!("...");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
When a method is marked `virtual`, it can be overridden in subclasses and will be dispatched dynamically at runtime through the vtable. Non-virtual methods are called statically.
|
||||||
|
|
||||||
### Inheritance
|
### Inheritance
|
||||||
|
|
||||||
```mist
|
```mist
|
||||||
@@ -59,6 +82,8 @@ void speak(&self) override(Animal)
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
Methods marked `override` are automatically virtual if the parent method is virtual. The semantic analyzer validates that overridden methods match the parent's signature.
|
||||||
|
|
||||||
### Implementations
|
### Implementations
|
||||||
|
|
||||||
You can implement directly on the class body:
|
You can implement directly on the class body:
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
---
|
---
|
||||||
title: Modules & Imports
|
title: Modules & Imports
|
||||||
description: Module declarations, imports, re-exports, and module resolution rules.
|
description: Module declarations, imports, re-exports, include directives, and module resolution rules.
|
||||||
icon: FolderTree
|
icon: FolderTree
|
||||||
---
|
---
|
||||||
|
|
||||||
@@ -18,6 +18,23 @@ use std::collections::HashMap;
|
|||||||
pub use my_module::MyType;
|
pub use my_module::MyType;
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### Include Directives
|
||||||
|
|
||||||
|
Mist supports C-style include directives for importing external files and crates:
|
||||||
|
|
||||||
|
```mist
|
||||||
|
// Global include (C-style)
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
// Use include (import from crate)
|
||||||
|
pub use my_crate::my_module;
|
||||||
|
|
||||||
|
// Local include (import from relative path)
|
||||||
|
#include "my_local_module.mist"
|
||||||
|
```
|
||||||
|
|
||||||
|
Include directives allow you to bring in external code without using the module system, which is useful for C interop and local file organization.
|
||||||
|
|
||||||
### Module Resolution
|
### Module Resolution
|
||||||
|
|
||||||
Mist maps the module tree to Rust's module system:
|
Mist maps the module tree to Rust's module system:
|
||||||
|
|||||||
@@ -9,13 +9,13 @@ icon: Box
|
|||||||
```mist
|
```mist
|
||||||
pub struct Point
|
pub struct Point
|
||||||
{
|
{
|
||||||
i32 x,
|
i32 x;
|
||||||
i32 y,
|
i32 y;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct Generic<T>
|
pub struct Generic<T>
|
||||||
{
|
{
|
||||||
T value,
|
T value;
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -24,8 +24,8 @@ Fields can be public or private:
|
|||||||
```mist
|
```mist
|
||||||
struct User
|
struct User
|
||||||
{
|
{
|
||||||
pub str& name,
|
pub str& name;
|
||||||
i32 age, // private
|
i32 age; // private
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -34,19 +34,19 @@ struct User
|
|||||||
```mist
|
```mist
|
||||||
pub enum Option<T>
|
pub enum Option<T>
|
||||||
{
|
{
|
||||||
Some(T),
|
Some(T);
|
||||||
None,
|
None;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub enum Message
|
pub enum Message
|
||||||
{
|
{
|
||||||
Quit,
|
Quit;
|
||||||
Move(i32, i32),
|
Move(i32, i32);
|
||||||
Write { str& content, i32 length },
|
Write { str& content; i32 length; };
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
Enum variants can be:
|
Enum variants can be:
|
||||||
- **Named** — `Variant`
|
- **Named** — `Variant`
|
||||||
- **Tuple** — `Variant(T1, T2)`
|
- **Tuple** — `Variant(T1, T2)`
|
||||||
- **Struct** — `Variant { T1 field1, T2 field2 }`
|
- **Struct** — `Variant { T1 field1; T2 field2; }`
|
||||||
|
|||||||
@@ -19,13 +19,14 @@ true // Boolean
|
|||||||
false // Boolean
|
false // Boolean
|
||||||
"hello" // String
|
"hello" // String
|
||||||
(1, true, "x") // Tuple
|
(1, true, "x") // Tuple
|
||||||
|
[1, 2, 3] // Array
|
||||||
```
|
```
|
||||||
|
|
||||||
### Identifiers & Keywords
|
### Identifiers & Keywords
|
||||||
|
|
||||||
Keywords are reserved and cannot be used as identifiers:
|
Keywords are reserved and cannot be used as identifiers:
|
||||||
|
|
||||||
`if`, `else`, `fn`, `for`, `while`, `match`, `return`, `break`, `continue`, `struct`, `enum`, `class`, `trait`, `impl`, `use`, `pub`, `mut`, `let`, `true`, `false`, `dyn`, `loop`, `unsafe`, `override`, `const`, `type`
|
`if`, `else`, `fn`, `for`, `while`, `match`, `return`, `break`, `continue`, `struct`, `enum`, `class`, `trait`, `impl`, `use`, `pub`, `mut`, `let`, `true`, `false`, `dyn`, `loop`, `unsafe`, `override`, `const`, `type`, `virtual`
|
||||||
|
|
||||||
Identifiers follow the pattern `[a-zA-Z_][a-zA-Z0-9_]*`.
|
Identifiers follow the pattern `[a-zA-Z_][a-zA-Z0-9_]*`.
|
||||||
|
|
||||||
|
|||||||
@@ -14,6 +14,8 @@ i32 'a& // Reference with lifetime
|
|||||||
i32 unsafe& // Const pointer
|
i32 unsafe& // Const pointer
|
||||||
i32 mut unsafe& // Mutable pointer
|
i32 mut unsafe& // Mutable pointer
|
||||||
(i32, bool) // Tuple type
|
(i32, bool) // Tuple type
|
||||||
|
i32[]& // Array type (static non-fixed size)
|
||||||
|
i32[10] // Array type (fixed size)
|
||||||
bool fn(i32) // Function pointer type
|
bool fn(i32) // Function pointer type
|
||||||
bool Fn(i32) // Closure trait (Fn)
|
bool Fn(i32) // Closure trait (Fn)
|
||||||
bool FnMut(i32) // Closure trait (FnMut)
|
bool FnMut(i32) // Closure trait (FnMut)
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ i32 z = 100; // Explicit type annotation
|
|||||||
str& s = "hello"; // Typed string reference
|
str& s = "hello"; // Typed string reference
|
||||||
bool b = true; // Typed boolean
|
bool b = true; // Typed boolean
|
||||||
f64 f = 3.14; // Typed float
|
f64 f = 3.14; // Typed float
|
||||||
|
(i32, str&) as x, y = (1, "hello"); // Typed tuple destructuring
|
||||||
let (a, b) = (1, "two"); // Destructuring
|
let (a, b) = (1, "two"); // Destructuring
|
||||||
let (x, (y, z)) = (1, (2, 3)); // Nested destructuring
|
let (x, (y, z)) = (1, (2, 3)); // Nested destructuring
|
||||||
```
|
```
|
||||||
@@ -22,6 +23,16 @@ let <pattern> [= <expr>];
|
|||||||
<type> <pattern> [= <expr>];
|
<type> <pattern> [= <expr>];
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### Tuple Variable Declarations
|
||||||
|
|
||||||
|
Tuple variables can be declared with explicit type annotations using `as`:
|
||||||
|
|
||||||
|
```mist
|
||||||
|
(i32, bool) (x, y) as = (1, true);
|
||||||
|
|
||||||
|
i32 a, b = (1, 2, 3);
|
||||||
|
```
|
||||||
|
|
||||||
### Const and Static
|
### Const and Static
|
||||||
|
|
||||||
```mist
|
```mist
|
||||||
|
|||||||
Reference in New Issue
Block a user