Updated highlighting
This commit is contained in:
@@ -10,7 +10,7 @@ Classes in Mist bridge the gap between Java's organizational structure and Rust'
|
|||||||
|
|
||||||
A class groups fields and methods together. Fields follow the `type name` convention, and methods define their logic directly within the class body.
|
A class groups fields and methods together. Fields follow the `type name` convention, and methods define their logic directly within the class body.
|
||||||
|
|
||||||
```cpp
|
```mist
|
||||||
public class Logger {
|
public class Logger {
|
||||||
String prefix;
|
String prefix;
|
||||||
|
|
||||||
@@ -28,7 +28,7 @@ public class Logger {
|
|||||||
|
|
||||||
Unlike languages that use the class name for initialization, Mist uses the explicit `constructor` keyword. This makes the entry point of the class unmistakable.
|
Unlike languages that use the class name for initialization, Mist uses the explicit `constructor` keyword. This makes the entry point of the class unmistakable.
|
||||||
|
|
||||||
```cpp
|
```mist
|
||||||
public constructor(str* prefix) {
|
public constructor(str* prefix) {
|
||||||
self.prefix = prefix.to_string();
|
self.prefix = prefix.to_string();
|
||||||
}
|
}
|
||||||
@@ -38,7 +38,7 @@ public constructor(str* prefix) {
|
|||||||
|
|
||||||
Mist maintains Rust's explicit context handling. Any method that needs to access or modify class data must include `self*` (or `self mut*` for mutations) as its first parameter.
|
Mist maintains Rust's explicit context handling. Any method that needs to access or modify class data must include `self*` (or `self mut*` for mutations) as its first parameter.
|
||||||
|
|
||||||
```cpp
|
```mist
|
||||||
public void warning(self*, str* message) {
|
public void warning(self*, str* message) {
|
||||||
self.log(LogLevel::Warning, message);
|
self.log(LogLevel::Warning, message);
|
||||||
}
|
}
|
||||||
@@ -48,7 +48,7 @@ public void warning(self*, str* message) {
|
|||||||
|
|
||||||
One of Mist's most powerful features is the ability to nest trait implementations directly within the class block. This keeps the logic for how a type behaves (e.g., how it is displayed) physically coupled with the type definition.
|
One of Mist's most powerful features is the ability to nest trait implementations directly within the class block. This keeps the logic for how a type behaves (e.g., how it is displayed) physically coupled with the type definition.
|
||||||
|
|
||||||
```cpp
|
```mist
|
||||||
impl fmt::Display {
|
impl fmt::Display {
|
||||||
std::fmt::Result fmt(self*, std::fmt::Formatter<'_> mut* f) {
|
std::fmt::Result fmt(self*, std::fmt::Formatter<'_> mut* f) {
|
||||||
return write!(f, "logger ({})", self.prefix);
|
return write!(f, "logger ({})", self.prefix);
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ Enums in Mist serve as powerful algebraic data types (ADTs), maintaining the exa
|
|||||||
|
|
||||||
An enum can contain unit variants, tuple variants, or struct-like variants. Following Mist's core philosophy, struct-like variants place the type before the identifier.
|
An enum can contain unit variants, tuple variants, or struct-like variants. Following Mist's core philosophy, struct-like variants place the type before the identifier.
|
||||||
|
|
||||||
```rust
|
```mist
|
||||||
public enum TaskState {
|
public enum TaskState {
|
||||||
Pending,
|
Pending,
|
||||||
InProgress,
|
InProgress,
|
||||||
@@ -26,7 +26,7 @@ public enum TaskState {
|
|||||||
|
|
||||||
Mist supports all standard variant shapes, ensuring a 1:1 mapping to the underlying Rust execution model.
|
Mist supports all standard variant shapes, ensuring a 1:1 mapping to the underlying Rust execution model.
|
||||||
|
|
||||||
```rust
|
```mist
|
||||||
enum Message {
|
enum Message {
|
||||||
Quit, // Unit
|
Quit, // Unit
|
||||||
Move(i32, i32), // Tuple
|
Move(i32, i32), // Tuple
|
||||||
@@ -40,7 +40,7 @@ enum Message {
|
|||||||
|
|
||||||
Just like structs and functions, enums declare generics and lifetimes in a unified block. This is particularly useful for defining custom Result or Option types that handle references.
|
Just like structs and functions, enums declare generics and lifetimes in a unified block. This is particularly useful for defining custom Result or Option types that handle references.
|
||||||
|
|
||||||
```rust
|
```mist
|
||||||
public enum Validation<'a, T> {
|
public enum Validation<'a, T> {
|
||||||
Valid(T),
|
Valid(T),
|
||||||
Invalid {
|
Invalid {
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ Functions are the primary unit of execution in Mist. They prioritize a tradition
|
|||||||
|
|
||||||
A standard function requires a return type, a name, and a body. Use the `void` keyword for functions that do not return a value.
|
A standard function requires a return type, a name, and a body. Use the `void` keyword for functions that do not return a value.
|
||||||
|
|
||||||
```cpp
|
```mist
|
||||||
i32 add(i32 a, i32 b) {
|
i32 add(i32 a, i32 b) {
|
||||||
return a + b;
|
return a + b;
|
||||||
}
|
}
|
||||||
@@ -24,7 +24,7 @@ void log_status(str* message) {
|
|||||||
|
|
||||||
Functions are private to their module by default. The `public` modifier exports the function for cross-module access.
|
Functions are private to their module by default. The `public` modifier exports the function for cross-module access.
|
||||||
|
|
||||||
```cpp
|
```mist
|
||||||
public i32 get_version() {
|
public i32 get_version() {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
@@ -34,7 +34,7 @@ public i32 get_version() {
|
|||||||
|
|
||||||
Parameters follow Rust’s ownership rules but use Mist’s local variable syntax. Use `mut` to allow a function to modify its local binding of a value.
|
Parameters follow Rust’s ownership rules but use Mist’s local variable syntax. Use `mut` to allow a function to modify its local binding of a value.
|
||||||
|
|
||||||
```cpp
|
```mist
|
||||||
void update_score(i32 mut current_score, i32 bonus) {
|
void update_score(i32 mut current_score, i32 bonus) {
|
||||||
current_score = current_score + bonus;
|
current_score = current_score + bonus;
|
||||||
}
|
}
|
||||||
@@ -44,7 +44,7 @@ void update_score(i32 mut current_score, i32 bonus) {
|
|||||||
|
|
||||||
Mist integrates type abstraction and memory management into a single generic block. Lifetimes and type parameters share the `< >` bracket following the identifier.
|
Mist integrates type abstraction and memory management into a single generic block. Lifetimes and type parameters share the `< >` bracket following the identifier.
|
||||||
|
|
||||||
```rust
|
```mist
|
||||||
public str'a* choose_longer<'a, T: Display>(str'a* s1, str'a* s2, T meta) {
|
public str'a* choose_longer<'a, T: Display>(str'a* s1, str'a* s2, T meta) {
|
||||||
println!("Metadata: {}", meta);
|
println!("Metadata: {}", meta);
|
||||||
return if (s1.len() > s2.len()) { s1 } else { s2 };
|
return if (s1.len() > s2.len()) { s1 } else { s2 };
|
||||||
@@ -55,7 +55,7 @@ public str'a* choose_longer<'a, T: Display>(str'a* s1, str'a* s2, T meta) {
|
|||||||
|
|
||||||
Metadata is applied via the `#[attr]` syntax directly above the declaration for compiler hints or testing.
|
Metadata is applied via the `#[attr]` syntax directly above the declaration for compiler hints or testing.
|
||||||
|
|
||||||
```cpp
|
```mist
|
||||||
#[inline]
|
#[inline]
|
||||||
public bool is_active(u32 id) {
|
public bool is_active(u32 id) {
|
||||||
return id > 0;
|
return id > 0;
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ Mist simplifies Rust’s reference system by using a pointer-style syntax. While
|
|||||||
|
|
||||||
References are defined by placing a `*` after the type. By default, pointers are immutable (shared). To allow modification of the underlying data, use the `mut*` modifier.
|
References are defined by placing a `*` after the type. By default, pointers are immutable (shared). To allow modification of the underlying data, use the `mut*` modifier.
|
||||||
|
|
||||||
```cpp
|
```mist
|
||||||
void increment(i32 mut* value, i32* limit) {
|
void increment(i32 mut* value, i32* limit) {
|
||||||
if (value < limit) {
|
if (value < limit) {
|
||||||
value = value + 1;
|
value = value + 1;
|
||||||
@@ -22,7 +22,7 @@ void increment(i32 mut* value, i32* limit) {
|
|||||||
|
|
||||||
Lifetimes are attached directly to the type before the pointer symbol. This maintains a clean visual flow where the "type-contract" (identity, duration, and mutability) is read from left to right.
|
Lifetimes are attached directly to the type before the pointer symbol. This maintains a clean visual flow where the "type-contract" (identity, duration, and mutability) is read from left to right.
|
||||||
|
|
||||||
```cpp
|
```mist
|
||||||
public struct Inspector<'a> {
|
public struct Inspector<'a> {
|
||||||
public str'a* target,
|
public str'a* target,
|
||||||
public u32'a mut* counter,
|
public u32'a mut* counter,
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ Structs in Mist follow the same structural logic as Rust, but apply the language
|
|||||||
|
|
||||||
A struct is defined by its name followed by a block of fields. Each field follows the Mist convention of placing the type before the identifier, separated by commas.
|
A struct is defined by its name followed by a block of fields. Each field follows the Mist convention of placing the type before the identifier, separated by commas.
|
||||||
|
|
||||||
```rust
|
```mist
|
||||||
public struct Task {
|
public struct Task {
|
||||||
public String name,
|
public String name,
|
||||||
public TaskState state,
|
public TaskState state,
|
||||||
@@ -22,7 +22,7 @@ public struct Task {
|
|||||||
|
|
||||||
Use the `public` modifier to make the struct or its individual fields accessible from other modules.
|
Use the `public` modifier to make the struct or its individual fields accessible from other modules.
|
||||||
|
|
||||||
```cpp
|
```mist
|
||||||
public struct NetworkNode {
|
public struct NetworkNode {
|
||||||
public u32 id,
|
public u32 id,
|
||||||
str* address,
|
str* address,
|
||||||
@@ -33,7 +33,7 @@ public struct NetworkNode {
|
|||||||
|
|
||||||
Structs are instantiated using the standard brace syntax.
|
Structs are instantiated using the standard brace syntax.
|
||||||
|
|
||||||
```cpp
|
```mist
|
||||||
var task = Task {
|
var task = Task {
|
||||||
name: "Initialize".to_string(),
|
name: "Initialize".to_string(),
|
||||||
state: TaskState::Pending,
|
state: TaskState::Pending,
|
||||||
@@ -45,7 +45,7 @@ var task = Task {
|
|||||||
|
|
||||||
Generics and lifetimes are declared in angle brackets after the struct name. Lifetimes are associated with the reference/pointer type within the field declarations.
|
Generics and lifetimes are declared in angle brackets after the struct name. Lifetimes are associated with the reference/pointer type within the field declarations.
|
||||||
|
|
||||||
```cpp
|
```mist
|
||||||
public struct Buffer<'a, T> {
|
public struct Buffer<'a, T> {
|
||||||
public T'a* data,
|
public T'a* data,
|
||||||
public usize len,
|
public usize len,
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ Traits in Mist define a set of methods that a type must implement, facilitating
|
|||||||
|
|
||||||
A trait definition lists method signatures that implementing types must satisfy. Like functions, these signatures place the return type before the method name.
|
A trait definition lists method signatures that implementing types must satisfy. Like functions, these signatures place the return type before the method name.
|
||||||
|
|
||||||
```rust
|
```mist
|
||||||
public trait Drawable {
|
public trait Drawable {
|
||||||
void draw(self*);
|
void draw(self*);
|
||||||
str* metadata(self*);
|
str* metadata(self*);
|
||||||
@@ -20,7 +20,7 @@ public trait Drawable {
|
|||||||
|
|
||||||
To implement a trait for a specific type, use the `impl` keyword followed by the trait name and the target type. This block must contain all required methods defined in the trait.
|
To implement a trait for a specific type, use the `impl` keyword followed by the trait name and the target type. This block must contain all required methods defined in the trait.
|
||||||
|
|
||||||
```rust
|
```mist
|
||||||
impl Drawable for Task {
|
impl Drawable for Task {
|
||||||
void draw(self*) {
|
void draw(self*) {
|
||||||
println!("Drawing task: {}", self.name);
|
println!("Drawing task: {}", self.name);
|
||||||
@@ -35,7 +35,7 @@ impl Drawable for Task {
|
|||||||
|
|
||||||
Traits can provide default behavior for methods. Types implementing the trait can choose to override these defaults or use the provided implementation.
|
Traits can provide default behavior for methods. Types implementing the trait can choose to override these defaults or use the provided implementation.
|
||||||
|
|
||||||
```rust
|
```mist
|
||||||
public trait Identifiable {
|
public trait Identifiable {
|
||||||
u32 get_id(self*);
|
u32 get_id(self*);
|
||||||
|
|
||||||
@@ -48,7 +48,7 @@ public trait Identifiable {
|
|||||||
|
|
||||||
Traits can build upon other traits. If a trait requires another trait to be implemented first, use the colon `:` syntax.
|
Traits can build upon other traits. If a trait requires another trait to be implemented first, use the colon `:` syntax.
|
||||||
|
|
||||||
```rust
|
```mist
|
||||||
public trait Animated : Drawable {
|
public trait Animated : Drawable {
|
||||||
void animate(self*, f32 delta_time);
|
void animate(self*, f32 delta_time);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -64,7 +64,7 @@ path = "build/main.rs"
|
|||||||
|
|
||||||
Now for the fun part! Create a new file at `src/main.mist` and add the following code:
|
Now for the fun part! Create a new file at `src/main.mist` and add the following code:
|
||||||
|
|
||||||
```cpp title="src/main.mist"
|
```mist title="src/main.mist"
|
||||||
void main() {
|
void main() {
|
||||||
println!("Hello World!");
|
println!("Hello World!");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ Control flow in Mist provides a bridge between C-style procedural logic and Rust
|
|||||||
|
|
||||||
The `if` statement evaluates a boolean expression. It supports multiple `else if` branches and an optional `else` block.
|
The `if` statement evaluates a boolean expression. It supports multiple `else if` branches and an optional `else` block.
|
||||||
|
|
||||||
```cpp
|
```mist
|
||||||
if (score > 50) {
|
if (score > 50) {
|
||||||
println!("Pass");
|
println!("Pass");
|
||||||
} else if (score == 50) {
|
} else if (score == 50) {
|
||||||
@@ -24,7 +24,7 @@ if (score > 50) {
|
|||||||
|
|
||||||
The `match` statement provides exhaustive pattern matching. Currently, every match arm requires a block `{}` following the `=>` operator.
|
The `match` statement provides exhaustive pattern matching. Currently, every match arm requires a block `{}` following the `=>` operator.
|
||||||
|
|
||||||
```cpp
|
```mist
|
||||||
match (task_state) {
|
match (task_state) {
|
||||||
TaskState::Pending => {
|
TaskState::Pending => {
|
||||||
println!("Queued");
|
println!("Queued");
|
||||||
@@ -46,7 +46,7 @@ Mist supports both functional iteration and traditional low-level loop control.
|
|||||||
|
|
||||||
For manual iteration control, Mist supports the standard three-part `for` loop: initialization, condition, and post-iteration statement.
|
For manual iteration control, Mist supports the standard three-part `for` loop: initialization, condition, and post-iteration statement.
|
||||||
|
|
||||||
```cpp
|
```mist
|
||||||
for (var mut i = 0; i < 10; i = i + 1;) {
|
for (var mut i = 0; i < 10; i = i + 1;) {
|
||||||
println!("Index: {}", i);
|
println!("Index: {}", i);
|
||||||
}
|
}
|
||||||
@@ -56,7 +56,7 @@ for (var mut i = 0; i < 10; i = i + 1;) {
|
|||||||
|
|
||||||
The `for-in` loop iterates over collections or iterators using Mist's pattern matching system.
|
The `for-in` loop iterates over collections or iterators using Mist's pattern matching system.
|
||||||
|
|
||||||
```cpp
|
```mist
|
||||||
for (var item in collection) {
|
for (var item in collection) {
|
||||||
process(item);
|
process(item);
|
||||||
}
|
}
|
||||||
@@ -71,7 +71,7 @@ for ((i32 x, i32 y) in coordinates) {
|
|||||||
|
|
||||||
The `while` loop continues execution as long as the parenthesized expression evaluates to `true`.
|
The `while` loop continues execution as long as the parenthesized expression evaluates to `true`.
|
||||||
|
|
||||||
```cpp
|
```mist
|
||||||
while (active) {
|
while (active) {
|
||||||
wait_for_event();
|
wait_for_event();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ Expressions in Mist are the fundamental units that evaluate to a value. The synt
|
|||||||
|
|
||||||
Primary expressions are the starting point of any logic chain. These include literal values, paths to static members, or grouped expressions in tuples.
|
Primary expressions are the starting point of any logic chain. These include literal values, paths to static members, or grouped expressions in tuples.
|
||||||
|
|
||||||
```java
|
```mist
|
||||||
// Literals and paths
|
// Literals and paths
|
||||||
var x = 42;
|
var x = 42;
|
||||||
var y = Math::PI;
|
var y = Math::PI;
|
||||||
@@ -24,7 +24,7 @@ var coordinates = (10, 20, 30);
|
|||||||
|
|
||||||
Postfix expressions allow you to build on a primary value. This includes calling functions, accessing fields, indexing arrays, or initializing structs.
|
Postfix expressions allow you to build on a primary value. This includes calling functions, accessing fields, indexing arrays, or initializing structs.
|
||||||
|
|
||||||
```java
|
```mist
|
||||||
// Field access and method/function calls
|
// Field access and method/function calls
|
||||||
var len = list.length();
|
var len = list.length();
|
||||||
|
|
||||||
@@ -44,7 +44,7 @@ println!("Value: {}", first); // Macro call via '!'
|
|||||||
|
|
||||||
Prefixes modify the primary expression that follows them. Mist uses these for logical negation, dereferencing, and creating references.
|
Prefixes modify the primary expression that follows them. Mist uses these for logical negation, dereferencing, and creating references.
|
||||||
|
|
||||||
```java
|
```mist
|
||||||
var mut value = 10;
|
var mut value = 10;
|
||||||
|
|
||||||
var ref = &value; // Reference
|
var ref = &value; // Reference
|
||||||
@@ -58,7 +58,7 @@ var is_false = !true; // Logical NOT
|
|||||||
|
|
||||||
Binary operations are applied as postfixes to an expression, following a `bin_op ~ expr` pattern. This supports all standard arithmetic, comparison, and logical operators.
|
Binary operations are applied as postfixes to an expression, following a `bin_op ~ expr` pattern. This supports all standard arithmetic, comparison, and logical operators.
|
||||||
|
|
||||||
```java
|
```mist
|
||||||
var sum = 10 + 20;
|
var sum = 10 + 20;
|
||||||
var is_equal = (x == y);
|
var is_equal = (x == y);
|
||||||
var complex = (a + b) * (c / d);
|
var complex = (a + b) * (c / d);
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ In Mist, variables follow the language-wide `type name` convention. For local sc
|
|||||||
|
|
||||||
Variables are declared using the `var` keyword for automatic type inference. Like Rust, variables are immutable by default.
|
Variables are declared using the `var` keyword for automatic type inference. Like Rust, variables are immutable by default.
|
||||||
|
|
||||||
```java
|
```mist
|
||||||
var message = "Hello Mist"; // Inferred as str*
|
var message = "Hello Mist"; // Inferred as str*
|
||||||
var count = 42; // Inferred as i32
|
var count = 42; // Inferred as i32
|
||||||
```
|
```
|
||||||
@@ -19,7 +19,7 @@ var count = 42; // Inferred as i32
|
|||||||
|
|
||||||
To allow a variable to be reassigned, use the `mut` modifier after the `var` keyword or the explicit type.
|
To allow a variable to be reassigned, use the `mut` modifier after the `var` keyword or the explicit type.
|
||||||
|
|
||||||
```rust
|
```mist
|
||||||
var mut score = 0;
|
var mut score = 0;
|
||||||
score = 100;
|
score = 100;
|
||||||
|
|
||||||
@@ -31,7 +31,7 @@ price = 14.99;
|
|||||||
|
|
||||||
While `var` handles inference, you can explicitly define the type before the identifier. This is often used for clarity in complex logic or when the specific numeric width (e.g., `u8` vs `i32`) matters.
|
While `var` handles inference, you can explicitly define the type before the identifier. This is often used for clarity in complex logic or when the specific numeric width (e.g., `u8` vs `i32`) matters.
|
||||||
|
|
||||||
```rust
|
```mist
|
||||||
u64 large_id = 1000234;
|
u64 large_id = 1000234;
|
||||||
bool is_active = true;
|
bool is_active = true;
|
||||||
```
|
```
|
||||||
@@ -40,7 +40,7 @@ bool is_active = true;
|
|||||||
|
|
||||||
Because variable declarations are patterns, you can destructure tuples or structures directly. This keeps data extraction clean and avoids manual indexing.
|
Because variable declarations are patterns, you can destructure tuples or structures directly. This keeps data extraction clean and avoids manual indexing.
|
||||||
|
|
||||||
```rust
|
```mist
|
||||||
// Destructuring a tuple into local variables
|
// Destructuring a tuple into local variables
|
||||||
(i32, i32) (x, y) = get_coordinates();
|
(i32, i32) (x, y) = get_coordinates();
|
||||||
|
|
||||||
@@ -52,7 +52,7 @@ Because variable declarations are patterns, you can destructure tuples or struct
|
|||||||
|
|
||||||
Constants are immutable values that are evaluated at compile time. They require an explicit type and follow the `const` keyword.
|
Constants are immutable values that are evaluated at compile time. They require an explicit type and follow the `const` keyword.
|
||||||
|
|
||||||
```rust
|
```mist
|
||||||
const i32 MAX_RETRIES = 5;
|
const i32 MAX_RETRIES = 5;
|
||||||
const str* VERSION = "1.0.4";
|
const str* VERSION = "1.0.4";
|
||||||
```
|
```
|
||||||
|
|||||||
Reference in New Issue
Block a user