From 08994156e143bd2dbd3bdb12bed401bcaf277e1f Mon Sep 17 00:00:00 2001 From: Raymond Pasco Date: Wed, 10 Aug 2016 09:28:53 -0700 Subject: [PATCH] Add missing jet for ++rep (very ghetto) --- Makefile | 1 + include/jets/q.h | 1 + include/jets/w.h | 1 + jets/c/rep.c | 87 ++++++++++++++++++++++++++++++++++++++++++++++++ jets/tree.c | 2 ++ 5 files changed, 92 insertions(+) create mode 100644 jets/c/rep.c diff --git a/Makefile b/Makefile index 1655fa28d..d4611019d 100644 --- a/Makefile +++ b/Makefile @@ -219,6 +219,7 @@ J_C_OFILES=\ jets/c/po.o \ jets/c/pow.o \ jets/c/rap.o \ + jets/c/rep.o \ jets/c/rip.o \ jets/c/rsh.o \ jets/c/sqt.o \ diff --git a/include/jets/q.h b/include/jets/q.h index 5ddeb7904..e0c083432 100644 --- a/include/jets/q.h +++ b/include/jets/q.h @@ -62,6 +62,7 @@ u3_noun u3qc_peg(u3_atom, u3_atom); 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_rip(u3_atom, u3_atom); u3_noun u3qc_rsh(u3_atom, u3_atom, u3_atom); u3_noun u3qc_sqt(u3_atom); diff --git a/include/jets/w.h b/include/jets/w.h index 6e28e2e56..c1e3c5899 100644 --- a/include/jets/w.h +++ b/include/jets/w.h @@ -62,6 +62,7 @@ u3_noun u3wc_peg(u3_noun); u3_noun u3wc_pow(u3_noun); u3_noun u3wc_rap(u3_noun); + u3_noun u3wc_rep(u3_noun); u3_noun u3wc_rip(u3_noun); u3_noun u3wc_rsh(u3_noun); u3_noun u3wc_sqt(u3_noun); diff --git a/jets/c/rep.c b/jets/c/rep.c new file mode 100644 index 000000000..361bb2533 --- /dev/null +++ b/jets/c/rep.c @@ -0,0 +1,87 @@ +/* j/3/rep.c +** +*/ +#include "all.h" + + +/* functions +*/ + u3_noun + u3qc_rep(u3_atom a, + u3_noun b) + { + if ( !_(u3a_is_cat(a)) || (a >= 32) ) { + return u3m_bail(c3__exit); + } + else { + c3_g a_g = a; + c3_w tot_w = 0; + c3_w* sal_w; + + /* Measure and validate the slab required. + */ + { + u3_noun cab = b; + + while ( 1 ) { + u3_noun h_cab; + c3_w len_w; + + if ( 0 == cab ) { + break; + } + else if ( c3n == u3du(cab) ) { + return u3m_bail(c3__exit); + } + else if ( c3n == u3ud(h_cab = u3h(cab)) ) { + return u3m_bail(c3__exit); + } + else if ( (tot_w + (len_w = u3r_met(a_g, h_cab))) < tot_w ) { + return u3m_bail(c3__fail); + } + tot_w++; + cab = u3t(cab); + } + if ( 0 == tot_w ) { + return 0; + } + if ( 0 == (sal_w = u3a_slaq(a_g, tot_w)) ) { + return u3m_bail(c3__fail); + } + } + + /* Chop the list atoms in. + */ + { + u3_noun cab = b; + c3_w pos_w = 0; + + while ( 0 != cab ) { + u3_noun h_cab = u3h(cab); + + u3r_chop(a_g, 0, 1, pos_w, sal_w, h_cab); + pos_w++; + cab = u3t(cab); + } + } + // return u3a_moot(sal_w); + return u3a_malt(sal_w); + } + } + u3_noun + u3wc_rep(u3_noun cor) + { + u3_noun a, b; + + if ( (c3n == u3r_mean(cor, u3x_sam_2, &a, u3x_sam_3, &b, 0)) || + (c3n == u3ud(a)) ) + { + return u3m_bail(c3__exit); + } else { + u3_noun pro; + + pro = u3qc_rep(a, b); + return pro; + } + } + diff --git a/jets/tree.c b/jets/tree.c index 5341351f8..57539ae08 100644 --- a/jets/tree.c +++ b/jets/tree.c @@ -57,6 +57,7 @@ static u3j_harm _mood__hoon_mug_a[] = {{".2", u3wc_mug, c3y}, {}}; static u3j_harm _mood__hoon_peg_a[] = {{".2", u3wc_peg, c3y}, {}}; static u3j_harm _mood__hoon_pow_a[] = {{".2", u3wc_pow, c3y}, {}}; static u3j_harm _mood__hoon_rap_a[] = {{".2", u3wc_rap, c3y}, {}}; +static u3j_harm _mood__hoon_rep_a[] = {{".2", u3wc_rep, c3y}, {}}; static u3j_harm _mood__hoon_rip_a[] = {{".2", u3wc_rip, c3y}, {}}; static u3j_harm _mood__hoon_rsh_a[] = {{".2", u3wc_rsh, c3y}, {}}; static u3j_harm _mood__hoon_sqt_a[] = {{".2", u3wc_sqt, c3y}, {}}; @@ -540,6 +541,7 @@ static u3j_core _mood__hoon_d[] = { "peg", _mood__hoon_peg_a }, { "pow", _mood__hoon_pow_a }, { "rap", _mood__hoon_rap_a }, + { "rep", _mood__hoon_rep_a }, { "rip", _mood__hoon_rip_a }, { "rsh", _mood__hoon_rsh_a }, { "sqt", _mood__hoon_sqt_a },