From 8e975917e8332776a493548d872469ead511478f Mon Sep 17 00:00:00 2001 From: Elliot Glaysher Date: Thu, 30 Apr 2020 13:07:20 -0700 Subject: [PATCH] jets: (scow %ud ...) is jetted, along with its +scot equivalent. --- pkg/urbit/include/jets/w.h | 2 + pkg/urbit/jets/e/scow.c | 80 ++++++++++++++++++++++++++++++++++++++ pkg/urbit/jets/tree.c | 4 ++ 3 files changed, 86 insertions(+) create mode 100644 pkg/urbit/jets/e/scow.c diff --git a/pkg/urbit/include/jets/w.h b/pkg/urbit/include/jets/w.h index 57c1d3d574..b5da487f64 100644 --- a/pkg/urbit/include/jets/w.h +++ b/pkg/urbit/include/jets/w.h @@ -125,6 +125,8 @@ u3_noun u3we_rexp(u3_noun); u3_noun u3we_trip(u3_noun); + u3_noun u3we_scow(u3_noun); + u3_noun u3we_scot(u3_noun); u3_noun u3we_slaw(u3_noun); u3_noun u3we_pfix(u3_noun); diff --git a/pkg/urbit/jets/e/scow.c b/pkg/urbit/jets/e/scow.c new file mode 100644 index 0000000000..02dfc60450 --- /dev/null +++ b/pkg/urbit/jets/e/scow.c @@ -0,0 +1,80 @@ +/* j/3/scow.c +** +*/ +#include "all.h" + +#include + +u3_noun +_print_ud(u3_atom ud) +{ + // number of characters printed "between" periods. + int between = 0; + u3_atom list = 0; + + do { + if (between == 3) { + list = u3nc('.', list); + between = 0; + } + list = u3nc(u3qa_add(u3qa_mod(u3k(ud), 10), '0'), list); + between++; + ud = u3qa_div(ud, 10); + } while (c3n == u3r_sing(ud, 0)); + + return list; +} + +// +u3_noun +u3we_scow(u3_noun cor) +{ + u3_noun mod; + u3_noun atom; + + if (c3n == u3r_mean(cor, u3x_sam_2, &mod, + u3x_sam_3, &atom, 0) || + !_(u3a_is_cat(mod))) { + return u3m_bail(c3__fail); + } + + switch (mod) { + /* case c3__da: */ + /* return _parse_da(cor, txt); */ + + /* case 'p': */ + /* return _parse_p(txt); */ + + case c3__ud: + return _print_ud(atom); + + /* // %ta is used once in link.hoon. don't bother. */ + + /* case c3__tas: */ + /* return _parse_tas(txt); */ + + default: + return u3_none; + } +} + +u3_noun +u3we_scot(u3_noun cor) +{ + u3_noun mod; + u3_noun atom; + + if (c3n == u3r_mean(cor, u3x_sam_2, &mod, + u3x_sam_3, &atom, 0) || + !_(u3a_is_cat(mod))) { + return u3m_bail(c3__fail); + } + + switch (mod) { + case c3__ud: + return u3qc_rap(3, _print_ud(atom)); + + default: + return u3_none; + } +} diff --git a/pkg/urbit/jets/tree.c b/pkg/urbit/jets/tree.c index d595c06e7f..d3eb207665 100644 --- a/pkg/urbit/jets/tree.c +++ b/pkg/urbit/jets/tree.c @@ -608,6 +608,8 @@ static c3_c* _141_qua_trip_ha[] = { }; static u3j_harm _141_qua_slaw_a[] = {{".2", u3we_slaw}, {}}; +static u3j_harm _141_qua_scot_a[] = {{".2", u3we_scot}, {}}; +static u3j_harm _141_qua_scow_a[] = {{".2", u3we_scow}, {}}; static u3j_harm _141_qua__po_ind_a[] = {{".2", u3wcp_ind}, {}}; @@ -887,6 +889,8 @@ static u3j_core _141_qua_d[] = { "mink", 7, _141_qua_mink_a, 0, _141_qua_mink_ha }, { "mule", 7, _141_qua_mule_a, 0, _141_qua_mule_ha }, + { "scot", 7, _141_qua_scot_a, 0, 0 }, + { "scow", 7, _141_qua_scow_a, 0, 0 }, { "slaw", 7, _141_qua_slaw_a, 0, 0 }, {} };