2013-09-29 00:21:18 +04:00
|
|
|
/* j/3/jam.c
|
|
|
|
**
|
|
|
|
** This file is in the public domain.
|
|
|
|
*/
|
|
|
|
#include "all.h"
|
|
|
|
#include "../pit.h"
|
2014-04-24 06:34:32 +04:00
|
|
|
#include "f/nash.h"
|
2013-09-29 00:21:18 +04:00
|
|
|
/* functions
|
|
|
|
*/
|
2014-04-24 06:34:32 +04:00
|
|
|
struct u2_nash* T_m;
|
2013-09-29 00:21:18 +04:00
|
|
|
static u2_noun
|
2014-08-20 10:22:41 +04:00
|
|
|
_jam_in(u2_atom, u2_atom, u2_noun);
|
2013-09-29 00:21:18 +04:00
|
|
|
|
|
|
|
static u2_noun // produce
|
2014-08-20 10:22:41 +04:00
|
|
|
_jam_in_pair(
|
2013-09-29 00:21:18 +04:00
|
|
|
u2_atom h_a, // retain
|
|
|
|
u2_atom t_a, // retain
|
|
|
|
u2_atom b, // retain
|
|
|
|
u2_noun l) // retain
|
|
|
|
{
|
2014-08-20 10:22:41 +04:00
|
|
|
u2_noun w = u2nc(u2nc(2, 1), u2k(l));
|
|
|
|
u2_noun x = j2_mbc(Pt1, add)(2, b);
|
|
|
|
u2_noun d = _jam_in(h_a, x, w);
|
2013-09-29 00:21:18 +04:00
|
|
|
u2_noun p_d, q_d, r_d;
|
|
|
|
u2_noun r;
|
|
|
|
|
2014-08-20 10:22:41 +04:00
|
|
|
u2_cr_trel(d, &p_d, &q_d, &r_d);
|
2013-09-29 00:21:18 +04:00
|
|
|
{
|
2014-08-20 10:22:41 +04:00
|
|
|
u2_noun y = j2_mbc(Pt1, add)(x, p_d);
|
|
|
|
u2_noun e = _jam_in(t_a, y, q_d);
|
2013-09-29 00:21:18 +04:00
|
|
|
u2_noun p_e, q_e, r_e;
|
|
|
|
|
2014-08-20 10:22:41 +04:00
|
|
|
u2_cr_trel(e, &p_e, &q_e, &r_e);
|
2013-09-29 00:21:18 +04:00
|
|
|
{
|
2014-08-20 10:22:41 +04:00
|
|
|
u2_noun z = j2_mbc(Pt1, add)(p_d, p_e);
|
2013-09-29 00:21:18 +04:00
|
|
|
|
2014-08-20 10:22:41 +04:00
|
|
|
r = u2nt
|
|
|
|
(j2_mbc(Pt1, add)(2, z),
|
|
|
|
u2k(q_e),
|
2014-04-24 06:34:32 +04:00
|
|
|
0);
|
2013-09-29 00:21:18 +04:00
|
|
|
|
2014-08-20 10:22:41 +04:00
|
|
|
u2z(z);
|
2013-09-29 00:21:18 +04:00
|
|
|
}
|
2014-08-20 10:22:41 +04:00
|
|
|
u2z(e);
|
|
|
|
u2z(y);
|
2013-09-29 00:21:18 +04:00
|
|
|
}
|
2014-08-20 10:22:41 +04:00
|
|
|
u2z(d);
|
|
|
|
u2z(x);
|
|
|
|
u2z(w);
|
2013-09-29 00:21:18 +04:00
|
|
|
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
|
|
|
static u2_noun // produce
|
2014-08-20 10:22:41 +04:00
|
|
|
_jam_in_flat(
|
2013-09-29 00:21:18 +04:00
|
|
|
u2_atom a, // retain
|
|
|
|
u2_noun l) // retain
|
|
|
|
{
|
2014-08-20 10:22:41 +04:00
|
|
|
u2_noun d = j2_mby(Pt5, mat)(a);
|
|
|
|
u2_noun x = j2_mbc(Pt1, add)(1, u2h(d));
|
|
|
|
u2_noun y = u2nt
|
|
|
|
(u2k(x),
|
|
|
|
u2nc(u2nc(
|
2013-09-29 00:21:18 +04:00
|
|
|
x,
|
2014-08-20 10:22:41 +04:00
|
|
|
j2_mbc(Pt3, lsh)(0, 1, u2t(d))),
|
|
|
|
u2k(l)),
|
2014-04-24 06:34:32 +04:00
|
|
|
0);
|
2013-09-29 00:21:18 +04:00
|
|
|
|
2014-08-20 10:22:41 +04:00
|
|
|
u2z(d);
|
2013-09-29 00:21:18 +04:00
|
|
|
|
|
|
|
return y;
|
|
|
|
}
|
|
|
|
|
|
|
|
static u2_noun // produce
|
2014-08-20 10:22:41 +04:00
|
|
|
_jam_in_ptr(
|
2013-09-29 00:21:18 +04:00
|
|
|
u2_atom u_c, // retain
|
|
|
|
u2_noun l) // retain
|
|
|
|
{
|
2014-08-20 10:22:41 +04:00
|
|
|
u2_noun d = j2_mby(Pt5, mat)(u_c);
|
|
|
|
u2_atom x = j2_mbc(Pt3, lsh)(0, 2, u2t(d));
|
|
|
|
u2_atom y = j2_mbc(Pt1, add)(2, u2h(d));
|
|
|
|
u2_noun z = u2nt
|
|
|
|
(u2k(y),
|
|
|
|
u2nc(u2nc(y, j2_mbc(Pt3, mix)(3, x)),
|
|
|
|
u2k(l)),
|
2014-04-24 06:34:32 +04:00
|
|
|
0);
|
2013-09-29 00:21:18 +04:00
|
|
|
|
2014-08-20 10:22:41 +04:00
|
|
|
u2z(d);
|
|
|
|
u2z(x);
|
2013-09-29 00:21:18 +04:00
|
|
|
|
|
|
|
return z;
|
|
|
|
}
|
|
|
|
|
|
|
|
static u2_noun // produce
|
2014-08-20 10:22:41 +04:00
|
|
|
_jam_in(
|
2013-09-29 00:21:18 +04:00
|
|
|
u2_noun a, // retain
|
|
|
|
u2_atom b, // retain
|
|
|
|
u2_noun l) // retain
|
|
|
|
{
|
2014-04-24 06:34:32 +04:00
|
|
|
u2_noun c = u2_na_get(T_m, a);
|
2013-09-29 00:21:18 +04:00
|
|
|
u2_noun x;
|
|
|
|
|
2014-05-07 22:21:16 +04:00
|
|
|
if ( u2_none == c ) {
|
2014-05-20 20:59:41 +04:00
|
|
|
u2_na_put(T_m, a, (void*)(c3_p)b);
|
2013-09-29 00:21:18 +04:00
|
|
|
|
2014-08-20 10:22:41 +04:00
|
|
|
if ( u2_yes == u2ud(a) ) {
|
|
|
|
x = _jam_in_flat(a, l);
|
2013-09-29 00:21:18 +04:00
|
|
|
} else {
|
2014-08-20 10:22:41 +04:00
|
|
|
x = _jam_in_pair(u2h(a), u2t(a), b, l);
|
2013-09-29 00:21:18 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
2014-08-20 10:22:41 +04:00
|
|
|
if ( u2_yes == u2ud(a) && u2_cr_met(0, a) <= u2_cr_met(0, c) ) {
|
|
|
|
x = _jam_in_flat(a, l);
|
2013-09-29 00:21:18 +04:00
|
|
|
}
|
|
|
|
else {
|
2014-08-20 10:22:41 +04:00
|
|
|
x = _jam_in_ptr(c, l);
|
2013-09-29 00:21:18 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return x;
|
|
|
|
}
|
|
|
|
|
|
|
|
u2_noun // transfer
|
2014-08-20 10:22:41 +04:00
|
|
|
j2_mby(Pt5, jam)(
|
2013-09-29 00:21:18 +04:00
|
|
|
u2_atom a) // retain
|
|
|
|
{
|
2014-04-24 06:34:32 +04:00
|
|
|
T_m = u2_na_make();
|
2014-08-20 10:22:41 +04:00
|
|
|
u2_noun x = _jam_in(a, 0, u2_nul);
|
|
|
|
u2_noun q = j2_mbc(Pt2, flop)(u2h(u2t(x)));
|
|
|
|
u2_noun r = j2_mbc(Pt3, can)(0, q);
|
2013-09-29 00:21:18 +04:00
|
|
|
|
2014-08-20 10:22:41 +04:00
|
|
|
u2z(x);
|
|
|
|
u2z(q);
|
2014-04-24 06:34:32 +04:00
|
|
|
u2_na_take(T_m);
|
|
|
|
T_m = NULL;
|
2013-09-29 00:21:18 +04:00
|
|
|
return r;
|
|
|
|
}
|
|
|
|
u2_noun // transfer
|
2014-08-20 10:22:41 +04:00
|
|
|
j2_mb(Pt5, jam)(
|
2013-09-29 00:21:18 +04:00
|
|
|
u2_noun cor) // retain
|
|
|
|
{
|
|
|
|
u2_noun a;
|
|
|
|
|
2014-08-20 10:22:41 +04:00
|
|
|
if ( (u2_none == (a = u2_cr_at(u2_cv_sam, cor))) ) {
|
|
|
|
return u2_cm_bail(c3__fail);
|
2013-09-29 00:21:18 +04:00
|
|
|
} else {
|
2014-08-20 10:22:41 +04:00
|
|
|
return j2_mby(Pt5, jam)(a);
|
2013-09-29 00:21:18 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* structures
|
|
|
|
*/
|
2014-04-22 05:22:11 +04:00
|
|
|
u2_ho_jet
|
2013-09-29 00:21:18 +04:00
|
|
|
j2_mbj(Pt5, jam)[] = {
|
2014-04-24 06:34:32 +04:00
|
|
|
{ ".2", c3__hevy, j2_mb(Pt5, jam), Tier5, u2_none, u2_none },
|
2013-09-29 00:21:18 +04:00
|
|
|
{ }
|
|
|
|
};
|