Updated docs to new version
This commit is contained in:
@@ -15,8 +15,8 @@ Outer attributes apply to the next item:
|
||||
```mist
|
||||
#[derive(Debug, Clone)]
|
||||
struct Point {
|
||||
i32 x,
|
||||
i32 y,
|
||||
i32 x;
|
||||
i32 y;
|
||||
}
|
||||
|
||||
#[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
|
||||
|
||||
```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
|
||||
|
||||
You can implement directly on the class body:
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
---
|
||||
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
|
||||
---
|
||||
|
||||
@@ -18,6 +18,23 @@ use std::collections::HashMap;
|
||||
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
|
||||
|
||||
Mist maps the module tree to Rust's module system:
|
||||
|
||||
@@ -9,13 +9,13 @@ icon: Box
|
||||
```mist
|
||||
pub struct Point
|
||||
{
|
||||
i32 x,
|
||||
i32 y,
|
||||
i32 x;
|
||||
i32 y;
|
||||
}
|
||||
|
||||
pub struct Generic<T>
|
||||
{
|
||||
T value,
|
||||
T value;
|
||||
}
|
||||
```
|
||||
|
||||
@@ -24,8 +24,8 @@ Fields can be public or private:
|
||||
```mist
|
||||
struct User
|
||||
{
|
||||
pub str& name,
|
||||
i32 age, // private
|
||||
pub str& name;
|
||||
i32 age; // private
|
||||
}
|
||||
```
|
||||
|
||||
@@ -34,19 +34,19 @@ struct User
|
||||
```mist
|
||||
pub enum Option<T>
|
||||
{
|
||||
Some(T),
|
||||
None,
|
||||
Some(T);
|
||||
None;
|
||||
}
|
||||
|
||||
pub enum Message
|
||||
{
|
||||
Quit,
|
||||
Move(i32, i32),
|
||||
Write { str& content, i32 length },
|
||||
Quit;
|
||||
Move(i32, i32);
|
||||
Write { str& content; i32 length; };
|
||||
}
|
||||
```
|
||||
|
||||
Enum variants can be:
|
||||
- **Named** — `Variant`
|
||||
- **Tuple** — `Variant(T1, T2)`
|
||||
- **Struct** — `Variant { T1 field1, T2 field2 }`
|
||||
- **Struct** — `Variant { T1 field1; T2 field2; }`
|
||||
|
||||
@@ -19,13 +19,14 @@ true // Boolean
|
||||
false // Boolean
|
||||
"hello" // String
|
||||
(1, true, "x") // Tuple
|
||||
[1, 2, 3] // Array
|
||||
```
|
||||
|
||||
### Identifiers & Keywords
|
||||
|
||||
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_]*`.
|
||||
|
||||
|
||||
@@ -14,6 +14,8 @@ i32 'a& // Reference with lifetime
|
||||
i32 unsafe& // Const pointer
|
||||
i32 mut unsafe& // Mutable pointer
|
||||
(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) // Closure trait (Fn)
|
||||
bool FnMut(i32) // Closure trait (FnMut)
|
||||
|
||||
@@ -5,14 +5,15 @@ icon: Variable
|
||||
---
|
||||
|
||||
```mist
|
||||
let x = 42; // Type-inferred immutable
|
||||
let mut y = 10; // Mutable variable
|
||||
i32 z = 100; // Explicit type annotation
|
||||
str& s = "hello"; // Typed string reference
|
||||
bool b = true; // Typed boolean
|
||||
f64 f = 3.14; // Typed float
|
||||
let (a, b) = (1, "two"); // Destructuring
|
||||
let (x, (y, z)) = (1, (2, 3)); // Nested destructuring
|
||||
let x = 42; // Type-inferred immutable
|
||||
let mut y = 10; // Mutable variable
|
||||
i32 z = 100; // Explicit type annotation
|
||||
str& s = "hello"; // Typed string reference
|
||||
bool b = true; // Typed boolean
|
||||
f64 f = 3.14; // Typed float
|
||||
(i32, str&) as x, y = (1, "hello"); // Typed tuple destructuring
|
||||
let (a, b) = (1, "two"); // Destructuring
|
||||
let (x, (y, z)) = (1, (2, 3)); // Nested destructuring
|
||||
```
|
||||
|
||||
Variable declarations follow either of two forms:
|
||||
@@ -22,6 +23,16 @@ let <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
|
||||
|
||||
```mist
|
||||
|
||||
Reference in New Issue
Block a user