Skip to content

Commit 1c6add6

Browse files
committed
feat: add --dep flag and connect driver to overall execution flow, add examples
1 parent 857cc5a commit 1c6add6

14 files changed

Lines changed: 324 additions & 18 deletions

File tree

examples/multiple_deps/main.simf

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
use merkle::build_root::{get_root, hash as and_hash};
2+
use base_math::simple_op::hash as or_hash;
3+
4+
pub fn get_block_value_hash(prev_hash: u32, tx1: u32, tx2: u32) -> u32 {
5+
let root: u32 = get_root(tx1, tx2);
6+
or_hash(prev_hash, root)
7+
}
8+
9+
fn main() {
10+
let block_val_hash: u32 = get_block_value_hash(5, 10, 20);
11+
assert!(jet::eq_32(block_val_hash, 27));
12+
13+
let first_value: u32 = 15;
14+
let second_value: u32 = 22;
15+
assert!(jet::eq_32(and_hash(first_value, second_value), 6));
16+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
pub fn hash(x: u32, y: u32) -> u32 {
2+
jet::xor_32(x, y)
3+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
use math::simple_op::hash as temp_hash;
2+
3+
pub fn get_root(tx1: u32, tx2: u32) -> u32 {
4+
temp_hash(tx1, tx2)
5+
}
6+
7+
pub fn hash(tx1: u32, tx2: u32) -> u32 {
8+
jet::and_32(tx1, tx2)
9+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
pub fn sha256(data: u32) -> u256 {
2+
let ctx: Ctx8 = jet::sha_256_ctx_8_init();
3+
let ctx: Ctx8 = jet::sha_256_ctx_8_add_4(ctx, data);
4+
jet::sha_256_ctx_8_finalize(ctx)
5+
}

examples/simple_multidep/main.simf

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
use math::arithmetic::add;
2+
use crypto::hashes::sha256;
3+
4+
fn main() {
5+
let sum: u32 = add(2, 3);
6+
let hash: u256 = sha256(sum);
7+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
pub fn add(a: u32, b: u32) -> u32 {
2+
let (_, res): (bool, u32) = jet::add_32(a, b);
3+
res
4+
}

examples/single_dep/main.simf

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
pub use temp::constants::utils::two as smth;
2+
use temp::funcs::{get_five, Smth};
3+
4+
fn seven() -> u32 {
5+
7
6+
}
7+
8+
fn main() {
9+
let (_, temp): (bool, u32) = jet::add_32(smth(), get_five());
10+
assert!(jet::eq_32(temp, seven()));
11+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
pub use temp::funcs::Smth;
2+
3+
pub fn two() -> Smth {
4+
2
5+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
pub type Smth = u32;
2+
3+
pub fn get_five() -> u32 {
4+
5
5+
}

src/driver/linearization.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use crate::driver::DependencyGraph;
1414
/// This is a core component of the [`DependencyGraph`].
1515
impl DependencyGraph {
1616
/// Returns the deterministic, BOTTOM-UP load order of dependencies.
17-
pub(crate) fn linearize(&self) -> Result<Vec<usize>, LinearizationError> {
17+
pub(super) fn linearize(&self) -> Result<Vec<usize>, LinearizationError> {
1818
let mut visited = HashSet::new();
1919
let mut visiting = Vec::new();
2020
let mut order = Vec::new();

0 commit comments

Comments
 (0)