Skip to main content

simple_chain/
lib.rs

1//! Example JAR chain.
2//!
3//! The chain's endpoint receives an `args_len` (currently ignored)
4//! and returns a u64 — the sum of a fixed array. Exercises the
5//! transpiled-Image runtime end-to-end: stack frame, array on
6//! the stack, iterative sum, function return through the
7//! `#[subsoil::endpoint]` trampoline's halt wrapper.
8
9#![cfg_attr(target_os = "none", no_std)]
10
11/// Compute and return the sum of `[1, 2, 3, 4, 5]`.
12///
13/// Lives in the lib so the bench/test infrastructure can call it
14/// natively on the host as well.
15pub fn simple_chain_sum() -> u64 {
16    let xs = [1u64, 2, 3, 4, 5];
17    let mut acc = 0u64;
18    let mut i = 0;
19    while i < xs.len() {
20        acc = acc.wrapping_add(xs[i]);
21        i += 1;
22    }
23    acc
24}