From 1f7caacd15b24af7fc70ab672d4c65eb09c746cd Mon Sep 17 00:00:00 2001 From: Elliot Glaysher Date: Tue, 12 May 2020 10:40:33 -0700 Subject: [PATCH] jet: +rep:in --- pkg/urbit/include/jets/w.h | 1 + pkg/urbit/jets/d/in_rep.c | 41 ++++++++++++++++++++++++++++++++++++++ pkg/urbit/jets/tree.c | 2 ++ 3 files changed, 44 insertions(+) create mode 100644 pkg/urbit/jets/d/in_rep.c diff --git a/pkg/urbit/include/jets/w.h b/pkg/urbit/include/jets/w.h index a0c7aa030c..a3271dc2f8 100644 --- a/pkg/urbit/include/jets/w.h +++ b/pkg/urbit/include/jets/w.h @@ -102,6 +102,7 @@ u3_noun u3wdi_has(u3_noun); u3_noun u3wdi_int(u3_noun); u3_noun u3wdi_put(u3_noun); + u3_noun u3wdi_rep(u3_noun); u3_noun u3wdi_run(u3_noun); u3_noun u3wdi_tap(u3_noun); u3_noun u3wdi_uni(u3_noun); diff --git a/pkg/urbit/jets/d/in_rep.c b/pkg/urbit/jets/d/in_rep.c new file mode 100644 index 0000000000..a7d7376c84 --- /dev/null +++ b/pkg/urbit/jets/d/in_rep.c @@ -0,0 +1,41 @@ +/* j/4/in_rep.c +** +*/ +#include "all.h" + +/* internal functions + */ +static +void +_in_rep(u3_noun a, u3j_site* sit_u, u3_noun* out) +{ + if (u3_nul == a) { + return; + } else { + u3_noun n_a, l_a, r_a; + u3x_trel(a, &n_a, &l_a, &r_a); + + // consumes out refcount + *out = u3j_gate_slam(sit_u, u3nc(u3k(n_a), *out)); + + _in_rep(l_a, sit_u, out); + _in_rep(r_a, sit_u, out); + } +} + +u3_noun +u3wdi_rep(u3_noun cor) +{ + u3_noun a, b; + u3j_site sit_u; + + u3x_mean(cor, u3x_sam, &b, u3x_con_sam, &a, 0); + + u3j_gate_prep(&sit_u, u3k(b)); + + u3_noun out = u3k(u3x_at(u3x_sam_3, b)); + _in_rep(a, &sit_u, &out); + + u3j_gate_lose(&sit_u); + return out; +} diff --git a/pkg/urbit/jets/tree.c b/pkg/urbit/jets/tree.c index c47073f179..124a39d30c 100644 --- a/pkg/urbit/jets/tree.c +++ b/pkg/urbit/jets/tree.c @@ -1574,6 +1574,7 @@ static c3_c* _141_two_xeb_ha[] = { }; static u3j_harm _141_two__in_apt_a[] = {{".2", u3wdi_apt}, {}}; + static u3j_harm _141_two__in_rep_a[] = {{".2", u3wdi_rep}, {}}; static u3j_harm _141_two__in_run_a[] = {{".2", u3wdi_run}, {}}; static u3j_core _141_two__in_d[] = @@ -1585,6 +1586,7 @@ static u3j_core _141_two__in_d[] = { "has", 7, _141_two__in_has_a, 0, _141_two__in_has_ha }, // { "int", 7, _141_two__in_int_a, 0, _141_two__in_int_ha }, { "put", 7, _141_two__in_put_a, 0, _141_two__in_put_ha }, + { "rep", 7, _141_two__in_rep_a }, { "run", 7, _141_two__in_run_a }, { "tap", 7, _141_two__in_tap_a, 0, _141_two__in_tap_ha }, { "wyt", 3, _141_two__in_wyt_a, 0, _141_two__in_wyt_ha },