For simplicity it would be sufficient to have a pure Rust to MASM compiler.
There's probably already a way to run the compiler, but this is just an example of how it would work.
midenc some_rust_file.rs masm_output.masm
Consider a simple Rust function:
fn divide_sum(a: u32, b: u32, c: u32) -> u32 {
if c == 0 {
panic!("Division by zero");
} else {
(a + b) / c
}
}
The compiler would convert the Rust function into Miden Assembly:
# inputs => [a, b, c]
# outputs => [result]
proc.divide_sum
swap.2
dup
push.0
eq
if.true
push.0
assert
else
swap.2
add
swap
div
end
end
(This could probably be optimized; this is just an illustrative example.)
Ideally, the compiler would automatically use u32mul and u32div and would, by default, ensure no underflow or overflow occurs.
Here is an example of fixed point arithmetic done in MASM that would be nice to be able to do in rust: https://github.com/compolabs/spark-miden-v1/blob/56587a07732fa8e40cd7b577e60d7874c608ea00/src/notes/SWAPp.masm#L77
Would also be cool, although probably more difficult to be able to hash things in Rust exactly like how hashing occurs in MASM: https://github.com/compolabs/spark-miden-v1/blob/56587a07732fa8e40cd7b577e60d7874c608ea00/src/notes/SWAPp.masm#L204
Although not a requirement at the beginning, it would be very useful to be able to access Miden kernel functions using Rust. This would enable writing Miden notes and accounts in pure Rust.
Imagine if you could write notes and accounts in pure rust. Something like this:
use miden::note;
use miden::wallet;
// Miden Note Example
fn divide_sum(a: u32, b: u32, c: u32) -> u32 {
if c == 0 {
panic!("Division by zero");
} else {
(a + b) / c
}
}
fn main() {
let res = divide_sum(5,5,2);
let serial_num = note::get_serial_number();
# ... more logic ...
}
I know this is a primitive example, but it's very cool to think about.