-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #391 from 0xPolygonMiden/greenhat/i390-add-fib-exa…
…mple chore: add fibonacci sequence example
- Loading branch information
Showing
27 changed files
with
239 additions
and
287 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# Rust program examples | ||
|
||
These examples are built using `cargo-miden`. | ||
|
||
`cargo miden` is a `cargo` cargo extension. Check out its [documentation](https://0xpolygonmiden.github.io/compiler/usage/cargo-miden/#compiling-to-miden-assembly) | ||
for more details on how to build and run the compiled programs. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/target |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
[package] | ||
name = "fibonacci" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
[lib] | ||
# Build this crate as a self-contained, C-style dynamic library | ||
# This is required to emit the proper Wasm module type | ||
crate-type = ["cdylib"] | ||
|
||
[dependencies] | ||
# Miden SDK consists of a stdlib (intrinsic functions for VM ops, stdlib functions and types) | ||
# and transaction kernel API for the Miden rollup | ||
|
||
miden = { git = "https://github.com/0xPolygonMiden/compiler" } | ||
|
||
|
||
[profile.release] | ||
# optimize the output for size | ||
opt-level = "z" | ||
# Explicitly disable panic infrastructure on Wasm, as | ||
# there is no proper support for them anyway, and it | ||
# ensures that panics do not pull in a bunch of standard | ||
# library code unintentionally | ||
panic = "abort" | ||
|
||
[profile.dev] | ||
# Explicitly disable panic infrastructure on Wasm, as | ||
# there is no proper support for them anyway, and it | ||
# ensures that panics do not pull in a bunch of standard | ||
# library code unintentionally | ||
panic = "abort" | ||
opt-level = 1 | ||
debug-assertions = false | ||
overflow-checks = false | ||
debug = true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# fibonacci | ||
|
||
## Useful commands | ||
|
||
`fibonacci` is built using the [Miden compiler](https://github.com/0xPolygonMiden/compiler). | ||
|
||
`cargo miden` is a `cargo` cargo extension. Check out its [documentation](https://0xpolygonmiden.github.io/compiler/usage/cargo-miden/#compiling-to-miden-assembly) | ||
for more details on how to build and run the compiled programs. | ||
|
||
## Compile | ||
|
||
```bash | ||
cargo miden build --release | ||
``` | ||
|
||
## Run | ||
|
||
```bash | ||
midenc run target/miden/release/fibonacci.masp --inputs inputs.toml | ||
``` | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
[inputs] | ||
stack = [25] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
[toolchain] | ||
channel = "nightly-2025-01-16" | ||
components = ["rustfmt", "rust-src"] | ||
targets = ["wasm32-wasi"] | ||
profile = "minimal" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
// Do not link against libstd (i.e. anything defined in `std::`) | ||
#![no_std] | ||
|
||
// However, we could still use some standard library types while | ||
// remaining no-std compatible, if we uncommented the following lines: | ||
// | ||
// extern crate alloc; | ||
// use alloc::vec::Vec; | ||
|
||
// // Global allocator to use heap memory in no-std environment | ||
// #[global_allocator] | ||
// static ALLOC: BumpAlloc = miden::BumpAlloc::new(); | ||
|
||
// Required for no-std crates | ||
#[panic_handler] | ||
fn my_panic(_info: &core::panic::PanicInfo) -> ! { | ||
loop {} | ||
} | ||
|
||
// Pass up to 16 u32 inputs as entrypoint function parameters. | ||
// The output is temporarely limited to 1 u32 value | ||
// | ||
// NOTE: | ||
// The name of the entrypoint function is expected to be `entrypoint`. Do not remove the | ||
// `#[no_mangle]` attribute, otherwise, the rustc will mangle the name and it'll not be recognized | ||
// by the Miden compiler. | ||
#[no_mangle] | ||
pub fn entrypoint(n: u32) -> u32 { | ||
let mut a = 0; | ||
let mut b = 1; | ||
for _ in 0..n { | ||
let c = a + b; | ||
a = b; | ||
b = c; | ||
} | ||
a | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
builtin.component #[name = #root] #[namespace = #root_ns] #[version = 1.0.0] #[visibility = public] { | ||
|
||
builtin.module #[name = #fibonacci] #[visibility = public] { | ||
|
||
builtin.function public @entrypoint(v0: i32) -> i32 { | ||
^block3(v0: i32): | ||
v2 = hir.constant 0 : i32; | ||
v3 = hir.constant 0 : i32; | ||
v4 = hir.constant 1 : i32; | ||
hir.br block5 v4, v0, v3; | ||
^block4(v1: i32): | ||
|
||
^block5(v6: i32, v7: i32, v10: i32): | ||
v8 = hir.constant 0 : i32; | ||
v9 = hir.neq v7, v8 : i1; | ||
hir.cond_br block7, block8 v9; | ||
^block6(v5: i32): | ||
|
||
^block7: | ||
v11 = hir.constant -1 : i32; | ||
v12 = hir.add v7, v11 : i32 #[overflow = wrapping]; | ||
v13 = hir.add v10, v6 : i32 #[overflow = wrapping]; | ||
hir.br block5 v13, v12, v6; | ||
^block8: | ||
hir.ret v10; | ||
}; | ||
builtin.global_variable #[name = #__stack_pointer] #[ty = i32] #[visibility = private] { | ||
|
||
hir.ret_imm #[value = 1048576]; | ||
}; | ||
}; | ||
}; |
4 changes: 2 additions & 2 deletions
4
tests/integration/expected/fib.masm → tests/integration/expected/examples/fib.masm
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
# mod miden_integration_tests_rust_fib_wasm | ||
# mod fibonacci | ||
|
||
export.fib | ||
export.entrypoint | ||
push.0 | ||
push.1 | ||
movup.2 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.