From 919780c5707cfe7d74ca273d75edd5bf4b636c8d Mon Sep 17 00:00:00 2001 From: Fang Date: Fri, 13 Jul 2018 01:59:56 +0200 Subject: [PATCH] Implement jet for ++rev. --- include/jets/k.h | 5 +++++ include/jets/q.h | 1 + include/jets/w.h | 1 + jets/c/rev.c | 50 ++++++++++++++++++++++++++++++++++++++++++++++++ jets/tree.c | 2 ++ meson.build | 1 + 6 files changed, 60 insertions(+) create mode 100644 jets/c/rev.c diff --git a/include/jets/k.h b/include/jets/k.h index 0d06a9a641..3eeb4d2273 100644 --- a/include/jets/k.h +++ b/include/jets/k.h @@ -43,6 +43,11 @@ u3_noun u3kc_rip(u3_atom a, u3_atom b); + /* u3kc_rev(): reverse block order, accounting for leading zeroes. + */ + u3_noun + u3kc_rev(u3_atom boz, u3_atom len, u3_atom dat); + /* u3kc_swp(): reverse block order. */ u3_noun diff --git a/include/jets/q.h b/include/jets/q.h index 6a7763a857..09a3a0c249 100644 --- a/include/jets/q.h +++ b/include/jets/q.h @@ -64,6 +64,7 @@ u3_noun u3qc_pow(u3_atom, u3_atom); u3_noun u3qc_rap(u3_atom, u3_noun); u3_noun u3qc_rep(u3_atom, u3_noun); + u3_noun u3qc_rev(u3_atom, u3_atom, u3_atom); u3_noun u3qc_rip(u3_atom, u3_atom); u3_noun u3qc_rsh(u3_atom, u3_atom, u3_atom); u3_noun u3qc_swp(u3_atom, u3_atom); diff --git a/include/jets/w.h b/include/jets/w.h index 0993ab563c..c656d4172d 100644 --- a/include/jets/w.h +++ b/include/jets/w.h @@ -64,6 +64,7 @@ u3_noun u3wc_pow(u3_noun); u3_noun u3wc_rap(u3_noun); u3_noun u3wc_rep(u3_noun); + u3_noun u3wc_rev(u3_noun); u3_noun u3wc_rip(u3_noun); u3_noun u3wc_rsh(u3_noun); u3_noun u3wc_swp(u3_noun); diff --git a/jets/c/rev.c b/jets/c/rev.c new file mode 100644 index 0000000000..eb2e9ef98d --- /dev/null +++ b/jets/c/rev.c @@ -0,0 +1,50 @@ +/* j/3/rev.c +** +*/ +#include "all.h" + +/* functions +*/ + + u3_noun + u3qc_rev(u3_atom boz, + u3_atom len, + u3_atom dat) + { + if ( !_(u3a_is_cat(boz)) || (boz >= 32) || + !_(u3a_is_cat(len)) ) { + return u3m_bail(c3__fail); + } + + dat = u3qc_end(boz, len, dat); + c3_w met = u3r_met(boz, dat); + return u3kc_lsh(u3k(boz), (len - met), u3kc_swp(u3k(boz), dat)); + } + + u3_noun + u3wc_rev(u3_noun cor) + { + u3_noun boz, len, dat; + + if ( (c3n == u3r_mean(cor, u3x_sam_2, &boz, + u3x_sam_6, &len, + u3x_sam_7, &dat, 0)) || + (c3n == u3ud(boz)) || + (c3n == u3ud(len)) || + (c3n == u3ud(dat)) ) + { + return u3m_bail(c3__exit); + } else { + return u3qc_rev(boz, len, dat); + } + } + + u3_noun + u3kc_rev(u3_atom boz, + u3_atom len, + u3_atom dat) + { + u3_noun res = u3qc_rev(boz, len, dat); + u3z(boz); u3z(len); u3z(dat); + return res; + } diff --git a/jets/tree.c b/jets/tree.c index e82317c875..ef71fb74d3 100644 --- a/jets/tree.c +++ b/jets/tree.c @@ -510,6 +510,7 @@ static u3j_core _143_tri_d[] = static u3j_harm _143_two_pow_a[] = {{".2", u3wc_pow, c3y}, {}}; static u3j_harm _143_two_rap_a[] = {{".2", u3wc_rap, c3y}, {}}; static u3j_harm _143_two_rep_a[] = {{".2", u3wc_rep, c3y}, {}}; + static u3j_harm _143_two_rev_a[] = {{".2", u3wc_rev, c3y}, {}}; static u3j_harm _143_two_rip_a[] = {{".2", u3wc_rip, c3y}, {}}; static u3j_harm _143_two_rsh_a[] = {{".2", u3wc_rsh, c3y}, {}}; static u3j_harm _143_two_swp_a[] = {{".2", u3wc_swp, c3y}, {}}; @@ -614,6 +615,7 @@ static u3j_core _143_two_d[] = { "muk", _143_two_muk_a }, { "rap", _143_two_rap_a }, { "rep", _143_two_rep_a }, + { "rev", _143_two_rev_a }, { "rip", _143_two_rip_a }, { "rsh", _143_two_rsh_a }, { "rub", _143_two_rub_a }, diff --git a/meson.build b/meson.build index 772c84c63b..21311ab86c 100644 --- a/meson.build +++ b/meson.build @@ -71,6 +71,7 @@ jets_c_src = [ 'jets/c/pow.c', 'jets/c/rap.c', 'jets/c/rep.c', +'jets/c/rev.c', 'jets/c/rip.c', 'jets/c/rsh.c', 'jets/c/swp.c',