Implement jet for ++swp.

This commit is contained in:
Fang 2018-07-13 01:58:32 +02:00
parent 5189295d02
commit b8712677ea
6 changed files with 50 additions and 0 deletions

View File

@ -43,6 +43,11 @@
u3_noun
u3kc_rip(u3_atom a, u3_atom b);
/* u3kc_swp(): reverse block order.
*/
u3_noun
u3kc_swp(u3_atom a, u3_atom b);
/* u3kd: tier 4 functions
*/
/* u3kdb_get(): map get for key `b` in map `a` with u3_none.

View File

@ -66,6 +66,7 @@
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_swp(u3_atom, u3_atom);
u3_noun u3qc_sqt(u3_atom);
u3_noun u3qc_vor(u3_atom, u3_atom);

View File

@ -66,6 +66,7 @@
u3_noun u3wc_rep(u3_noun);
u3_noun u3wc_rip(u3_noun);
u3_noun u3wc_rsh(u3_noun);
u3_noun u3wc_swp(u3_noun);
u3_noun u3wc_sqt(u3_noun);
u3_noun u3wc_vor(u3_noun);

39
jets/c/swp.c Normal file
View File

@ -0,0 +1,39 @@
/* j/3/swp.c
**
*/
#include "all.h"
/* functions
*/
u3_noun
u3qc_swp(u3_atom a,
u3_atom b)
{
//XX write a proper c-style swp, maybe
return u3kc_rep(u3k(a), u3kb_flop(u3qc_rip(a, b)));
}
u3_noun
u3wc_swp(u3_noun cor)
{
u3_noun a, b;
if ( (c3n == u3r_mean(cor, u3x_sam_2, &a, u3x_sam_3, &b, 0)) ||
(c3n == u3ud(a)) ||
(c3n == u3ud(b)) )
{
return u3m_bail(c3__exit);
} else {
return u3qc_swp(a, b);
}
}
u3_noun
u3kc_swp(u3_atom a,
u3_atom b)
{
u3_noun res = u3qc_swp(a, b);
u3z(a); u3z(b);
return res;
}

View File

@ -512,6 +512,7 @@ static u3j_core _143_tri_d[] =
static u3j_harm _143_two_rep_a[] = {{".2", u3wc_rep, 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}, {}};
static u3j_harm _143_two_sqt_a[] = {{".2", u3wc_sqt, c3y}, {}};
static u3j_harm _143_two_vor_a[] = {{".2", u3wc_vor, c3y}, {}};
static u3j_harm _143_two_xeb_a[] = {{".2", u3wc_xeb, c3y}, {}};
@ -618,12 +619,14 @@ static u3j_core _143_two_d[] =
{ "rub", _143_two_rub_a },
{ "peg", _143_two_peg_a },
{ "pow", _143_two_pow_a },
{ "swp", _143_two_swp_a },
{ "sqt", _143_two_sqt_a },
{ "vor", _143_two_vor_a },
{ "xeb", _143_two_xeb_a },
{ "by", 0, _143_two__by_d },
{ "in", 0, _143_two__in_d },
{}
};

View File

@ -73,6 +73,7 @@ jets_c_src = [
'jets/c/rep.c',
'jets/c/rip.c',
'jets/c/rsh.c',
'jets/c/swp.c',
'jets/c/sqt.c',
'jets/c/vor.c',
]