Skip to content
This repository was archived by the owner on May 7, 2024. It is now read-only.

Commit 6d35008

Browse files
committed
feat: add mux and foldhood_plus builtins
1 parent 5499128 commit 6d35008

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

src/core/lang/builtins.rs

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
use crate::core::lang::lang::{foldhood, mid, nbr};
2+
use crate::core::vm::round_vm::round_vm::RoundVM;
3+
4+
pub fn mux<A, TH, EL>(vm: RoundVM, cond: bool, th: TH, el: EL) -> (RoundVM, A)
5+
where
6+
TH: Fn(RoundVM) -> (RoundVM, A),
7+
EL: Fn(RoundVM) -> (RoundVM, A),
8+
{
9+
if cond {
10+
th(vm)
11+
} else {
12+
el(vm)
13+
}
14+
}
15+
16+
pub fn foldhood_plus<A: Copy + 'static, F, G, H>(vm: RoundVM, init: F, aggr: G, expr: H) -> (RoundVM, A)
17+
where
18+
F: Fn(RoundVM) -> (RoundVM, A) + Copy,
19+
G: Fn(A, A) -> A,
20+
H: Fn(RoundVM) -> (RoundVM, A) + Copy,
21+
{
22+
foldhood(
23+
vm,
24+
init,
25+
aggr,
26+
|vm1| {
27+
let (vm_, self_id) = mid(vm1);
28+
let (vm__, nbr_id) = nbr(vm_, |vm2| mid(vm2));
29+
mux(vm__, self_id == nbr_id, expr, init)
30+
}
31+
)
32+
}

src/core/lang/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
pub mod lang;
22
pub mod execution;
3+
pub mod builtins;
34
mod test;

0 commit comments

Comments
 (0)