Explicit. Safe. Predictable.
Miva is more than an acronym—it is a promise:
Memory‑safe, Intuitive, Verifiable, Adaptable
These four pillars define Miva.
-
Memory‑safe
Eliminates use‑after‑free, double‑free, and data races at compile time, with no garbage collection. -
Verifiable behavior
All operations are expressed explicitly—no implicit copies, no magic conversions, no runtime surprises. -
Predictable execution
Zero runtime overhead, no GC pauses, no dynamic dispatch. Performance like C, safety like Rust.
move x: Explicitly transfers ownership; the original variable becomes invalid immediatelyclone x: Explicit deep copy with clear, unambiguous semanticsref x: T: Used only for function parameters to denote a read‑only borrow (not a type, does not escape the function)
Ownership rules:
- Copy types (e.g.,
int,bool, pure‑value structs) → copied automatically- non‑Copy types (e.g.,
[T],string) → require eithermoveorclone
// C-style
int foo() { return 1; }
// Miva-style
foo = (): int => 1
- Functions are first‑class values: assignable, passable, returnable
- Single‑expression functions omit
{}andreturn - Multi‑statement functions automatically return the last expression
- Uses lightweight algebraic type
Result[T, E] - Errors must be handled explicitly; ignoring return values is forbidden
- Deconstruct
Resultvia thechoosestatement, ensuring all branches are covered - Supports
?syntactic sugar, similar to Rust
res := choose may_fail() {
when Ok(value) { value }
when Err(e) {
log("Error: ", e)
return -1
}
};
res := may_fail()?;
panicis reserved for unrecoverable errors (e.g., out‑of‑memory) and is uncatchable and unrecoverable
choose value {
when 0 { "zero" }
when 1 { "one" }
when x if x > 10 { "big number" }
otherwise { "other" }
};
- No
fallthroughpitfalls - No redundant symbols (compared to Rust’s
matchor C’sswitch) - Supports guard conditions (
if) and future deconstruction capabilities
| Feature | Reason |
|---|---|
| Garbage Collection (GC) | Introduces unpredictable latency, violating the “predictable” principle |
panic catching mechanism |
panic represents program failure and should not be used as control flow |
match / switch |
match uses verbose syntax; switch has counterintuitive default fallthrough |
try/catch/finally |
Exception jumps break linear code flow; explicit error handling is encouraged |
goto or arbitrary labels |
Breaks structured programming; Miva supports only natural control flow |
| Global mutable variables | Introduces concurrent data race issues |
What Miva does not do matters more than what it does— restraint is the highest form of design.
- Miva’s FFI requires explicit
unsafedeclaration; calls take the formunsafe ffi_function( /* params */ ) - Any function that calls an
unsafefunction must itself be markedunsafe - If a function calls
unsafecode but the author guarantees memory safety, it may be markedtrusted - Functions marked
trustedorunsaferequire annotation comments:@trusted: ...or@unsafe: ... - A function not marked
unsafemay not callunsafefunctions, but may calltrustedfunctions - This model is more explicit and safer than Rust’s
unsafe
- Miva supports two kinds of FFI: external and inline
import "c:....h"imports header files, which are translated to actualincludedirectives- After
import, all functions reside under thecmodule and areunsafe - Example:
import "c:stdio.h"; // may be written c:cstdio but not recommended
// Safe function
foo = () => {
c.printf("Hello, foo!"); // invalid
}
unsafe main = () => {
c.printf("Hello"); // valid
}
- Miva also allows inline C functions
- Example:
import "c:stdio.h"
c unsafe foo = (ref inp1: int, inp2: int) => { // c unsafe required
printf("Hello, %d %d", inp1, inp2); // direct C function calls
// no c.xxx prefix needed
// may call other functions in the same file, but not other modules
// may access parameters directly
// C++ code is allowed but strongly discouraged:
std::string a = "Hello";
printf("Hello, %s", a.c_str()); // not recommended
}
- Miva does not verify the safety of any C or FFI code
- Miva uses
async/awaitas its concurrency model - Syntax:
async foo = () => {
...
}
main = () => {
res1 := foo(); // res1 is future<unit>
res2 := await foo(); // res2 is unit
}
- Internally implemented using C++20 coroutines
- Miva follows a DOP + FP style
- Rejects full OOP, but provides
obj.method()syntactic sugar - All Miva functions should be free functions
- No function overloading
- Supports operator overloading:
MyStruct = struct {
a: int
}
add_mystruct(a: MyStruct, b: MyStruct) => {
struct MyStruct {
a = (a.a + b.a)
}
}
impl MyStruct {
operator_add = add_mystruct
}
- Naming conventions:
- Structs:
PascalCase - Variables / functions / filenames:
snake_case - Modules: lowercase
foo.bar.xx
- Structs:
- No global variables:
- Immutable globals are replaced by functions:
global = (): type => val - Mutable global variables are a major source of race conditions; Miva strictly forbids them
- Immutable globals are replaced by functions:
- Miva provides two pointer types
ptr<T>: raw pointer- Taking the address of a variable is safe:
addr var - Dereferencing a
ptr<T>is unsafe:deref ptr // only in unsafe or trusted functions
- Taking the address of a variable is safe:
box<T>: heap pointer- Has unique ownership, prohibits shallow copies, and is automatically freed at end of lifetime
- Dereferencing a
box<T>is safe:deref box
Trust the programmer, but do not test their memory. One less frowning symbol, one more intuitive simplicity. Aim not for omnipotence, but for: expressing the safest semantics with the cleanest syntax, generating the most efficient code. Miva is not a simplified Rust, nor a safer Go. Miva is Miva: a language built for the future.
MIT License. Use it, break it, improve it.