Merge pull request #3703 from urbit/jb/restore-treap-jets

u3: add more jets for list and treap operations
This commit is contained in:
Joe Bryan 2020-10-15 15:12:10 -07:00 committed by GitHub
commit 33d93cc483
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
23 changed files with 810 additions and 161 deletions

View File

@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:06808af2c089441d2cb497fc95e3292b6229b3dfa034272d46c7c41f34eb6a3b
size 6268465
oid sha256:9745f1dc04da93914d1a79ea2e8c8eb04d4469ef8a83d084158282056b693a02
size 6260435

View File

@ -778,6 +778,7 @@
(weld (scag b a) [c (slag b a)])
::
++ welp :: faceless weld
~/ %welp
=| {* *}
|@
++ $
@ -787,6 +788,7 @@
--
::
++ zing :: promote
~/ %zing
=| *
|@
++ $
@ -1196,8 +1198,10 @@
?|((b n.a) $(a l.a) $(a r.a))
::
++ apt :: check correctness
=< $
~/ %apt
=| {l/(unit) r/(unit)}
|- ^- ?
|. ^- ?
?~ a &
?& ?~(l & (gor n.a u.l))
?~(r & (gor u.r n.a))
@ -1346,6 +1350,7 @@
c(l a(r l.c))
::
++ rep :: reduce to product
~/ %rep
|* b/_=>(~ |=({* *} +<+))
|-
?~ a +<+.b
@ -1490,8 +1495,10 @@
$(a r.a, c (peg c 7))
::
++ apt :: check correctness
=< $
~/ %apt
=| {l/(unit) r/(unit)}
|- ^- ?
|. ^- ?
?~ a &
?& ?~(l & &((gor p.n.a u.l) !=(p.n.a u.l)))
?~(r & &((gor u.r p.n.a) !=(u.r p.n.a)))
@ -1603,6 +1610,7 @@
d(l a(r l.d))
::
++ rep :: reduce to product
~/ %rep
|* b/_=>(~ |=({* *} +<+))
|-
?~ a +<+.b
@ -1619,6 +1627,7 @@
[-.f a(l +.e, r +.f)]
::
++ run :: apply gate to values
~/ %run
|* b/gate
|-
?~ a a
@ -1685,18 +1694,23 @@
::
::
++ urn :: apply gate to nodes
~/ %urn
|* b/$-({* *} *)
|-
?~ a ~
a(n n.a(q (b p.n.a q.n.a)), l $(a l.a), r $(a r.a))
::
++ wyt :: depth of map
|- ^- @
=< $
~% %wyt + ~
|. ^- @
?~(a 0 +((add $(a l.a) $(a r.a))))
::
++ key :: set of keys
=< $
~/ %key
=+ b=`(set _?>(?=(^ a) p.n.a))`~
|- ^+ b
|. ^+ b
?~ a b
$(a r.a, b $(a l.a, b (~(put in b) p.n.a)))
::

View File

@ -55,6 +55,11 @@
%+ expect-eq
!> ~
!> (find `(list @)`~[6] l)
:: Checks for incomplete match
::
%+ expect-eq
!> ~
!> (find "bcd" "abc")
==
::
++ test-list-flop

View File

@ -123,7 +123,7 @@
::
:: and the ordering 1 < 2 < 3.
::
:: 1 should be in the left brach and 3 in the right one.
:: 1 should be in the left branch and 3 in the right one.
::
=/ balanced-a=(map @ @) [[2 2] [[1 1] ~ ~] [[3 3] ~ ~]]
:: doesn't follow vertical ordering

View File

@ -92,7 +92,7 @@
:: 1.923.673.882
::
:: and the ordering 1 < 2 < 3.
:: 1 should be in the left brach and 3 in the right one.
:: 1 should be in the left branch and 3 in the right one.
::
=/ balanced-a=(set @) [2 [1 ~ ~] [3 ~ ~]]
:: Doesn't follow vertical ordering

View File

@ -81,6 +81,11 @@
u3_noun
u3kdb_gas(u3_noun a, u3_noun b);
/* u3kdb_uni(): map union.
*/
u3_noun
u3kdb_uni(u3_noun a, u3_noun b);
/* u3kdi_gas(): list to map.
*/
u3_noun

View File

@ -72,22 +72,32 @@
/** Tier 4.
**/
u3_noun u3qdb_all(u3_noun, u3_noun);
u3_noun u3qdb_any(u3_noun, u3_noun);
u3_noun u3qdb_apt(u3_noun);
u3_noun u3qdb_bif(u3_noun, u3_noun);
u3_noun u3qdb_dif(u3_noun, u3_noun);
u3_noun u3qdb_gas(u3_noun, u3_noun);
u3_noun u3qdb_get(u3_noun, u3_noun);
u3_noun u3qdb_has(u3_noun, u3_noun);
u3_noun u3qdb_int(u3_noun, u3_noun);
u3_noun u3qdb_key(u3_noun);
u3_noun u3qdb_put(u3_noun, u3_noun, u3_noun);
u3_noun u3qdb_run(u3_noun, u3_noun);
# define u3qdb_tap u3qdi_tap
u3_noun u3qdb_uni(u3_noun, u3_noun);
u3_noun u3qdb_urn(u3_noun, u3_noun);
# define u3qdb_wyt u3qdi_wyt
u3_noun u3qdi_apt(u3_noun);
u3_noun u3qdi_bif(u3_noun, u3_noun);
u3_noun u3qdi_dif(u3_noun, u3_noun);
u3_noun u3qdi_gas(u3_noun, u3_noun);
u3_noun u3qdi_has(u3_noun, u3_noun);
u3_noun u3qdi_int(u3_noun, u3_noun);
u3_noun u3qdi_put(u3_noun, u3_noun);
u3_noun u3qdi_rep(u3_noun, u3_noun);
u3_noun u3qdi_run(u3_noun, u3_noun);
u3_noun u3qdi_tap(u3_noun);
u3_noun u3qdi_uni(u3_noun, u3_noun);
u3_noun u3qdi_wyt(u3_noun);

View File

@ -20,6 +20,7 @@
u3_noun u3wb_bind(u3_noun);
u3_noun u3wb_clap(u3_noun);
u3_noun u3wb_drop(u3_noun);
u3_noun u3wb_find(u3_noun);
u3_noun u3wb_flop(u3_noun);
u3_noun u3wb_lent(u3_noun);
u3_noun u3wb_levy(u3_noun);
@ -38,6 +39,8 @@
u3_noun u3wb_sort(u3_noun);
u3_noun u3wb_turn(u3_noun);
u3_noun u3wb_weld(u3_noun);
# define u3wb_welp u3wb_weld
u3_noun u3wb_zing(u3_noun);
/** Tier 3.
**/
@ -79,6 +82,9 @@
/** Tier 4.
**/
u3_noun u3wdb_all(u3_noun);
u3_noun u3wdb_any(u3_noun);
u3_noun u3wdb_apt(u3_noun);
u3_noun u3wdb_bif(u3_noun);
u3_noun u3wdb_del(u3_noun);
u3_noun u3wdb_dif(u3_noun);
@ -87,10 +93,16 @@
u3_noun u3wdb_has(u3_noun);
u3_noun u3wdb_int(u3_noun);
u3_noun u3wdb_jab(u3_noun);
u3_noun u3wdb_key(u3_noun);
u3_noun u3wdb_put(u3_noun);
# define u3wdb_tap u3wdi_tap
u3_noun u3wdb_uni(u3_noun);
u3_noun u3wdb_urn(u3_noun);
# define u3wdb_rep u3wdi_rep
u3_noun u3wdb_run(u3_noun);
# define u3wdb_wyt u3wdi_wyt
u3_noun u3wdi_apt(u3_noun);
u3_noun u3wdi_bif(u3_noun);
u3_noun u3wdi_del(u3_noun);
u3_noun u3wdi_dif(u3_noun);
@ -98,6 +110,8 @@
u3_noun u3wdi_has(u3_noun);
u3_noun u3wdi_int(u3_noun);
u3_noun u3wdi_put(u3_noun);
u3_noun u3wdi_rep(u3_noun);
u3_noun u3wdi_run(u3_noun);
u3_noun u3wdi_tap(u3_noun);
u3_noun u3wdi_uni(u3_noun);
u3_noun u3wdi_wyt(u3_noun);

48
pkg/urbit/jets/b/find.c Normal file
View File

@ -0,0 +1,48 @@
/* j/2/find.c
**
*/
#include "all.h"
STATIC_ASSERT( (UINT32_MAX > u3a_cells),
"list index precision" );
u3_noun
u3qb_find(u3_noun nedl, u3_noun hstk)
{
if ( u3_nul != nedl ) {
c3_w i_w = 0;
while ( u3_nul != hstk ) {
u3_noun i_h, t_h = hstk;
u3_noun i_n, t_n = nedl;
u3x_cell(t_h, &i_h, &t_h);
u3x_cell(t_n, &i_n, &t_n);
while ( c3y == u3r_sing(i_n, i_h) ) {
if ( u3_nul == t_n ) {
return u3nc(u3_nul, u3i_word(i_w));
}
else if ( u3_nul == t_h ) {
break;
}
else {
u3x_cell(t_h, &i_h, &t_h);
u3x_cell(t_n, &i_n, &t_n);
}
}
hstk = u3t(hstk);
i_w++;
}
}
return u3_nul;
}
u3_noun
u3wb_find(u3_noun cor)
{
u3_noun a, b;
u3x_mean(cor, u3x_sam_2, &a, u3x_sam_3, &b, 0);
return u3qb_find(a, b);
}

45
pkg/urbit/jets/b/zing.c Normal file
View File

@ -0,0 +1,45 @@
/* j/2/zing.c
**
*/
#include "all.h"
u3_noun
u3qb_zing(u3_noun a)
{
u3_noun pro;
u3_noun* lit = &pro;
if ( u3_nul == a ) {
*lit = u3_nul;
}
else {
u3_noun i, t = a;
u3x_cell(t, &i, &t);
while ( u3_nul != t ) {
u3_noun* hed;
u3_noun* tel;
u3_noun i_i, t_i = i;
while ( u3_nul != t_i ) {
u3x_cell(t_i, &i_i, &t_i);
*lit = u3i_defcons(&hed, &tel);
*hed = u3k(i_i);
lit = tel;
}
u3x_cell(t, &i, &t);
}
*lit = u3k(i);
}
return pro;
}
u3_noun
u3wb_zing(u3_noun cor)
{
return u3qb_zing(u3x_at(u3x_sam, cor));
}

49
pkg/urbit/jets/d/by_all.c Normal file
View File

@ -0,0 +1,49 @@
/* j/4/by_all.c
**
*/
#include "all.h"
static u3_noun
_by_all(u3_noun a, u3j_site* sit_u)
{
if ( u3_nul == a ) {
return c3y;
}
else {
u3_noun n_a, l_a, r_a;
u3x_trel(a, &n_a, &l_a, &r_a);
switch ( u3j_gate_slam(sit_u, u3k(u3t(n_a))) ) {
case c3y: break;
case c3n: return c3n;
default: return u3m_bail(c3__exit);
}
if ( c3n == _by_all(l_a, sit_u) ) {
return c3n;
}
return _by_all(r_a, sit_u);
}
}
u3_noun
u3qdb_all(u3_noun a, u3_noun b)
{
u3_noun pro;
u3j_site sit_u;
u3j_gate_prep(&sit_u, u3k(b));
pro = _by_all(a, &sit_u);
u3j_gate_lose(&sit_u);
return pro;
}
u3_noun
u3wdb_all(u3_noun cor)
{
u3_noun a, b;
u3x_mean(cor, u3x_sam, &b, u3x_con_sam, &a, 0);
return u3qdb_all(a, b);
}

49
pkg/urbit/jets/d/by_any.c Normal file
View File

@ -0,0 +1,49 @@
/* j/4/by_any.c
**
*/
#include "all.h"
static u3_noun
_by_any(u3_noun a, u3j_site* sit_u)
{
if ( u3_nul == a ) {
return c3n;
}
else {
u3_noun n_a, l_a, r_a;
u3x_trel(a, &n_a, &l_a, &r_a);
switch ( u3j_gate_slam(sit_u, u3k(u3t(n_a))) ) {
case c3y: return c3y;
case c3n: break;
default: return u3m_bail(c3__exit);
}
if ( c3y == _by_any(l_a, sit_u) ) {
return c3y;
}
return _by_any(r_a, sit_u);
}
}
u3_noun
u3qdb_any(u3_noun a, u3_noun b)
{
u3_noun pro;
u3j_site sit_u;
u3j_gate_prep(&sit_u, u3k(b));
pro = _by_any(a, &sit_u);
u3j_gate_lose(&sit_u);
return pro;
}
u3_noun
u3wdb_any(u3_noun cor)
{
u3_noun a, b;
u3x_mean(cor, u3x_sam, &b, u3x_con_sam, &a, 0);
return u3qdb_any(a, b);
}

76
pkg/urbit/jets/d/by_apt.c Normal file
View File

@ -0,0 +1,76 @@
/* j/4/by_apt.c
**
*/
#include "all.h"
static c3_o
_by_apt(u3_noun a, u3_weak l, u3_weak r)
{
if ( u3_nul == a ) {
return c3y;
}
else {
u3_noun p_n_a, l_a, r_a;
{
u3_noun n_a;
u3x_trel(a, &n_a, &l_a, &r_a);
p_n_a = u3h(n_a);
}
if ( u3_none != l ) {
if ( (c3n == u3qc_gor(p_n_a, l))
|| (c3y == u3r_sing(p_n_a, l)) )
{
return c3n;
}
}
if ( u3_none != r ) {
if ( (c3n == u3qc_gor(r, p_n_a))
|| (c3y == u3r_sing(r, p_n_a)) )
{
return c3n;
}
}
if ( u3_nul != l_a ) {
u3_noun p_n_l_a = u3h(u3h(l_a));
if ( (c3n == u3qc_mor(p_n_a, p_n_l_a))
|| (c3y == u3r_sing(p_n_a, p_n_l_a)) )
{
return c3n;
}
if ( c3n == _by_apt(l_a, p_n_a, r) ) {
return c3n;
}
}
if ( u3_nul != r_a ) {
u3_noun p_n_r_a = u3h(u3h(r_a));
if ( (c3n == u3qc_mor(p_n_a, p_n_r_a))
|| (c3y == u3r_sing(p_n_a, p_n_r_a)) )
{
return c3n;
}
return _by_apt(r_a, l, p_n_a);
}
return c3y;
}
}
u3_noun
u3qdb_apt(u3_noun a)
{
return _by_apt(a, u3_none, u3_none);
}
u3_noun
u3wdb_apt(u3_noun cor)
{
return u3qdb_apt(u3x_at(u3x_con_sam, cor));
}

View File

@ -1,21 +1,15 @@
/* j/4/by_int.c
** XXX THIS IS DISABLED
** specifically, s/hor/gor/g (already done?)
** and eliminate memory leaks
**
*/
#include "all.h"
/* functions
*/
u3_noun
u3qdb_int(u3_noun a,
u3_noun b)
u3qdb_int(u3_noun a, u3_noun b)
{
if ( u3_nul == a ) {
return u3k(u3_nul);
}
else if ( u3_nul == b ) {
return u3k(u3_nul);
if ( (u3_nul == a)
|| (u3_nul == b) )
{
return u3_nul;
}
else {
u3_noun n_a, l_a, r_a;
@ -28,54 +22,44 @@ u3qdb_int(u3_noun a,
u3x_cell(n_b, &p_n_b, &q_n_b);
if ( c3y == u3qc_mor(p_n_a, p_n_b) ) {
if ( c3y == u3r_sing(p_n_a, p_n_b) ) {
return u3nt(u3k(n_b),
u3qdb_int(u3k(l_a), u3k(l_b)),
u3qdb_int(u3k(r_a), u3k(r_b)));
if ( c3y == u3r_sing(p_n_b, p_n_a) ) {
return u3nt(u3k(n_b), u3qdb_int(l_a, l_b), u3qdb_int(r_a, r_b));
}
else if ( c3y == u3qc_gor(p_n_b, p_n_a) ) {
return u3qdb_uni(u3qdb_int(u3k(l_a),
u3nt(u3k(n_b),
u3k(l_b),
u3k(u3_nul))),
u3qdb_int(u3k(a),
u3k(r_b)));
u3_noun new_l_b = u3nt(u3k(n_b), u3k(l_b), u3_nul);
u3_noun new_a = u3qdb_int(l_a, new_l_b);
u3z(new_l_b);
return u3kdb_uni(new_a, u3qdb_int(a, r_b));
}
else {
return u3qdb_uni(u3qdb_int(u3k(r_a),
u3nt(u3k(n_b),
u3k(u3_nul),
u3k(r_b))),
u3qdb_int(u3k(a),
u3k(l_b)));
u3_noun new_r_b = u3nt(u3k(n_b), u3_nul, u3k(r_b));
u3_noun new_a = u3qdb_int(r_a, new_r_b);
u3z(new_r_b);
return u3kdb_uni(new_a, u3qdb_int(a, l_b));
}
}
else if ( c3y == u3r_sing(p_n_b, p_n_a) ) {
return u3nt(u3k(n_b),
u3qdb_int(u3k(l_b), u3k(l_a)),
u3qdb_int(u3k(r_b), u3k(r_a)));
else if ( c3y == u3r_sing(p_n_a, p_n_b) ) {
return u3nt(u3k(n_b), u3qdb_int(l_a, l_b), u3qdb_int(r_a, r_b));
}
else if ( c3y == u3qc_gor(p_n_a, p_n_b) ) {
return u3qdb_uni(u3qdb_int(u3k(l_b),
u3nt(u3k(n_a),
u3k(l_a),
u3k(u3_nul))),
u3qdb_int(u3k(a),
u3k(r_a)));
u3_noun new_l_a = u3nt(u3k(n_a), u3k(l_a), u3_nul);
u3_noun new_a = u3qdb_int(new_l_a, l_b);
u3z(new_l_a);
return u3kdb_uni(new_a, u3qdb_int(r_a, b));
}
else {
return u3qdb_uni(u3qdb_int(u3k(r_b),
u3nt(u3k(n_a),
u3k(u3_nul),
u3k(r_a))),
u3qdb_int(u3k(a),
u3k(l_a)));
u3_noun new_r_a = u3nt(u3k(n_a), u3_nul, u3k(r_a));
u3_noun new_a = u3qdb_int(new_r_a, r_b);
u3z(new_r_a);
return u3kdb_uni(new_a, u3qdb_int(l_a, b));
}
}
}
// XX disabled in tree.c, reference counts presumed wrong
//
u3_noun
u3wdb_int(u3_noun cor)
{

40
pkg/urbit/jets/d/by_key.c Normal file
View File

@ -0,0 +1,40 @@
/* j/4/by_run.c
**
*/
#include "all.h"
// [a] is RETAINED, [set] is TRANSFERRED
//
static u3_noun
_by_key(u3_noun a, u3_noun set)
{
if ( u3_nul == a ) {
return set;
}
else {
u3_noun n_a, l_a, r_a;
u3x_trel(a, &n_a, &l_a, &r_a);
{
u3_noun new = u3qdi_put(set, u3h(n_a));
u3z(set);
set = new;
}
set = _by_key(l_a, set);
return _by_key(r_a, set);
}
}
u3_noun
u3qdb_key(u3_noun a)
{
return _by_key(a, u3_nul);
}
u3_noun
u3wdb_key(u3_noun cor)
{
return u3qdb_key(u3x_at(u3x_con_sam, cor));
}

43
pkg/urbit/jets/d/by_run.c Normal file
View File

@ -0,0 +1,43 @@
/* j/4/by_run.c
**
*/
#include "all.h"
static u3_noun
_by_run(u3_noun a, u3j_site* sit_u)
{
if ( u3_nul == a ) {
return u3_nul;
}
else {
u3_noun n_a, l_a, r_a;
u3_noun p_n_a, q_n_a;
u3x_trel(a, &n_a, &l_a, &r_a);
u3x_cell(n_a, &p_n_a, &q_n_a);
return u3nt(u3nc(u3k(p_n_a), u3j_gate_slam(sit_u, u3k(q_n_a))),
_by_run(l_a, sit_u),
_by_run(r_a, sit_u));
}
}
u3_noun
u3qdb_run(u3_noun a, u3_noun b)
{
u3_noun pro;
u3j_site sit_u;
u3j_gate_prep(&sit_u, u3k(b));
pro = _by_run(a, &sit_u);
u3j_gate_lose(&sit_u);
return pro;
}
u3_noun
u3wdb_run(u3_noun cor)
{
u3_noun a, b;
u3x_mean(cor, u3x_sam, &b, u3x_con_sam, &a, 0);
return u3qdb_run(a, b);
}

View File

@ -1,22 +1,16 @@
/* j/4/by_uni.c
** XXX THIS IS DISABLED
** specifically, s/hor/gor/g (already done?)
** and eliminate memory leaks
*/
*/
#include "all.h"
/* functions
*/
u3_noun
u3qdb_uni(u3_noun a,
u3_noun b)
u3qdb_uni(u3_noun a, u3_noun b)
{
if ( u3_nul == a ) {
return u3k(b);
}
else if ( u3_nul == b ) {
if ( u3_nul == b ) {
return u3k(a);
}
else if ( u3_nul == a ) {
return u3k(b);
}
else {
u3_noun n_a, l_a, r_a;
u3_noun n_b, l_b, r_b;
@ -27,65 +21,66 @@ u3qdb_uni(u3_noun a,
u3x_cell(n_a, &p_n_a, &q_n_a);
u3x_cell(n_b, &p_n_b, &q_n_b);
if ( c3y == u3qc_mor(p_n_a, p_n_b) ) {
if ( c3y == u3r_sing(p_n_a, p_n_b) ) {
return u3nt(u3k(n_b),
u3qdb_uni(u3k(l_a),
u3k(l_b)),
u3qdb_uni(u3k(r_a),
u3k(r_b)));
}
else if ( c3y == u3qc_gor(p_n_b, p_n_a) ) {
return u3qdb_uni(
u3nt(u3k(n_a),
u3qdb_uni(u3k(l_a),
u3nt(u3k(n_b),
u3k(l_b),
u3k(u3_nul))),
u3k(r_a)),
u3k(r_b));
if ( c3y == u3r_sing(p_n_a, p_n_b) ) {
return u3nt(u3k(n_b),
u3qdb_uni(l_a, l_b),
u3qdb_uni(r_a, r_b));
}
else if ( c3y == u3qc_mor(p_n_a, p_n_b) ) {
u3_noun new_a, old_b;
if ( c3y == u3qc_gor(p_n_b, p_n_a) ) {
u3_noun new_b = u3nt(u3k(n_b), u3k(l_b), u3_nul);
u3_noun new_la = u3qdb_uni(l_a, new_b);
u3z(new_b);
new_a = u3nt(u3k(n_a), new_la, u3k(r_a));
old_b = r_b;
}
else {
return u3qdb_uni(
u3nt(u3k(n_a),
u3k(l_a),
u3qdb_uni(u3k(r_a),
u3nt(u3k(n_b),
u3k(u3_nul),
u3k(r_b)))),
u3k(l_b));
u3_noun new_b = u3nt(u3k(n_b), u3_nul, u3k(r_b));
u3_noun new_ra = u3qdb_uni(r_a, new_b);
u3z(new_b);
new_a = u3nt(u3k(n_a), u3k(l_a), new_ra);
old_b = l_b;
}
{
u3_noun pro = u3qdb_uni(new_a, old_b);
u3z(new_a);
return pro;
}
}
else if ( c3y == u3r_sing(p_n_b, p_n_a) ) {
return u3nt(u3k(n_b),
u3qdb_uni(u3k(r_b), u3k(r_a)),
u3qdb_uni(u3k(l_b), u3k(l_a)));
}
else if ( c3y == u3qc_gor(p_n_a, p_n_b) ) {
return u3qdb_uni(
u3k(r_a),
u3nt(u3k(n_b),
u3qdb_uni(u3nt(u3k(n_a),
u3k(l_a),
u3k(u3_nul)),
u3k(l_b)),
u3k(r_b)));
}
else {
return u3qdb_uni(
u3k(l_a),
u3nt(u3k(n_b),
u3k(l_b),
u3qdb_uni(u3k(r_b),
u3nt(u3k(n_a),
u3k(u3_nul),
u3k(r_a)))));
u3_noun old_a, new_b;
if ( c3y == u3qc_gor(p_n_a, p_n_b) ) {
u3_noun new_a = u3nt(u3k(n_a), u3k(l_a), u3_nul);
u3_noun new_lb = u3qdb_uni(new_a, l_b);
u3z(new_a);
new_b = u3nt(u3k(n_b), new_lb, u3k(r_b));
old_a = r_a;
}
else {
u3_noun new_a = u3nt(u3k(n_a), u3_nul, u3k(r_a));
u3_noun new_rb = u3qdb_uni(new_a, r_b);
u3z(new_a);
new_b = u3nt(u3k(n_b), u3k(l_b), new_rb);
old_a = l_a;
}
{
u3_noun pro = u3qdb_uni(old_a, new_b);
u3z(new_b);
return pro;
}
}
}
}
// XX disabled in tree.c, reference counts presumed wrong
//
u3_noun
u3wdb_uni(u3_noun cor)
{
@ -93,3 +88,11 @@ u3wdb_uni(u3_noun cor)
u3x_mean(cor, u3x_sam, &b, u3x_con_sam, &a, 0);
return u3qdb_uni(a, b);
}
u3_noun
u3kdb_uni(u3_noun a, u3_noun b)
{
u3_noun pro = u3qdb_uni(a, b);
u3z(a); u3z(b);
return pro;
}

41
pkg/urbit/jets/d/by_urn.c Normal file
View File

@ -0,0 +1,41 @@
/* j/4/by_urn.c
**
*/
#include "all.h"
static u3_noun
_by_urn(u3_noun a, u3j_site* sit_u)
{
if ( u3_nul == a ) {
return u3_nul;
}
else {
u3_noun n_a, l_a, r_a;
u3x_trel(a, &n_a, &l_a, &r_a);
return u3nt(u3nc(u3k(u3h(n_a)), u3j_gate_slam(sit_u, u3k(n_a))),
_by_urn(l_a, sit_u),
_by_urn(r_a, sit_u));
}
}
u3_noun
u3qdb_urn(u3_noun a, u3_noun b)
{
u3_noun pro;
u3j_site sit_u;
u3j_gate_prep(&sit_u, u3k(b));
pro = _by_urn(a, &sit_u);
u3j_gate_lose(&sit_u);
return pro;
}
u3_noun
u3wdb_urn(u3_noun cor)
{
u3_noun a, b;
u3x_mean(cor, u3x_sam, &b, u3x_con_sam, &a, 0);
return u3qdb_urn(a, b);
}

56
pkg/urbit/jets/d/in_apt.c Normal file
View File

@ -0,0 +1,56 @@
/* j/4/in_apt.c
**
*/
#include "all.h"
static c3_o
_in_apt(u3_noun a, u3_weak l, u3_weak r)
{
if ( u3_nul == a ) {
return c3y;
}
else {
u3_noun n_a, l_a, r_a;
u3x_trel(a, &n_a, &l_a, &r_a);
if ( (u3_none != l) && (c3n == u3qc_gor(n_a, l)) ) {
return c3n;
}
if ( (u3_none != r) && (c3n == u3qc_gor(r, n_a)) ) {
return c3n;
}
if ( u3_nul != l_a ) {
if ( c3n == u3qc_mor(n_a, u3h(l_a)) ) {
return c3n;
}
if ( c3n == _in_apt(l_a, n_a, r) ) {
return c3n;
}
}
if ( u3_nul != r_a ) {
if ( c3n == u3qc_mor(n_a, u3h(r_a)) ) {
return c3n;
}
return _in_apt(r_a, l, n_a);
}
return c3y;
}
}
u3_noun
u3qdi_apt(u3_noun a)
{
return _in_apt(a, u3_none, u3_none);
}
u3_noun
u3wdi_apt(u3_noun cor)
{
return u3qdi_apt(u3x_at(u3x_con_sam, cor));
}

View File

@ -3,52 +3,56 @@
*/
#include "all.h"
/* functions
*/
u3_noun
u3qdi_int(u3_noun a,
u3_noun b)
u3qdi_int(u3_noun a, u3_noun b)
{
if ( u3_nul == a ) {
return u3k(u3_nul);
}
else if ( u3_nul == b ) {
return u3k(u3_nul);
if ( (u3_nul == a)
|| (u3_nul == b) )
{
return u3_nul;
}
else {
u3_noun l_a, n_a, r_a, lr_a;
u3_noun l_b, n_b, r_b, lr_b;
u3_noun c;
u3x_cell(a, &n_a, &lr_a);
u3x_cell(b, &n_b, &lr_b);
u3_noun n_a, l_a, r_a;
u3_noun n_b, l_b, r_b;
if ( c3y == u3qc_mor(n_b, n_a) ) {
c = a; a = b; b = c;
c = n_a; n_a = n_b; n_b = c;
c = lr_a; lr_a = lr_b; lr_b = c;
{
u3_noun lr_a, lr_b;
u3x_cell(a, &n_a, &lr_a);
u3x_cell(b, &n_b, &lr_b);
if ( c3y == u3qc_mor(n_a, n_b) ) {
u3_noun c;
c = a; a = b; b = c;
c = n_a; n_a = n_b; n_b = c;
c = lr_a; lr_a = lr_b; lr_b = c;
}
u3x_cell(lr_a, &l_a, &r_a);
u3x_cell(lr_b, &l_b, &r_b);
}
u3x_cell(lr_a, &l_a, &r_a);
u3x_cell(lr_b, &l_b, &r_b);
if ( c3y == u3r_sing(n_a, n_b) ) {
if ( c3y == u3r_sing(n_b, n_a) ) {
return u3nt(u3k(n_a),
u3qdi_int(l_a, l_b),
u3qdi_int(r_a, r_b));
}
else if ( c3y == u3qc_gor(n_b, n_a) ) {
return u3qdi_uni(u3qdi_int(l_a, u3nt(n_b, l_b, u3_nul)),
u3qdi_int(a, r_b));
u3_noun new_l_b = u3nt(u3k(n_b), u3k(l_b), u3_nul);
u3_noun new_a = u3qdi_int(l_a, new_l_b);
u3z(new_l_b);
return u3kdi_uni(new_a, u3qdi_int(a, r_b));
}
else {
return u3qdi_uni(u3qdi_int(r_a, u3nt(n_b, u3_nul, r_b)),
u3qdi_int(a, l_b));
u3_noun new_r_b = u3nt(u3k(n_b), u3_nul, u3k(r_b));
u3_noun new_a = u3qdi_int(r_a, new_r_b);
u3z(new_r_b);
return u3kdi_uni(new_a, u3qdi_int(a, l_b));
}
}
}
// XX disabled in tree.c, reference counts presumed wrong
//
u3_noun
u3wdi_int(u3_noun cor)
{

44
pkg/urbit/jets/d/in_rep.c Normal file
View File

@ -0,0 +1,44 @@
/* j/4/in_rep.c
**
*/
#include "all.h"
// [a] is RETAINED, [out] is TRANSFERRED
//
static void
_in_rep(u3_noun a, u3j_site* sit_u, u3_noun* out)
{
if ( u3_nul == a ) {
return;
}
else {
u3_noun n_a, l_a, r_a;
u3x_trel(a, &n_a, &l_a, &r_a);
*out = u3j_gate_slam(sit_u, u3nc(u3k(n_a), *out));
_in_rep(l_a, sit_u, out);
_in_rep(r_a, sit_u, out);
}
}
u3_noun
u3qdi_rep(u3_noun a, u3_noun b)
{
u3_noun out = u3k(u3x_at(u3x_sam_3, b));
u3j_site sit_u;
u3j_gate_prep(&sit_u, u3k(b));
_in_rep(a, &sit_u, &out);
u3j_gate_lose(&sit_u);
return out;
}
u3_noun
u3wdi_rep(u3_noun cor)
{
u3_noun a, b;
u3x_mean(cor, u3x_sam, &b, u3x_con_sam, &a, 0);
return u3qdi_rep(a, b);
}

51
pkg/urbit/jets/d/in_run.c Normal file
View File

@ -0,0 +1,51 @@
/* j/4/in_run.c
**
*/
#include "all.h"
// [a] is RETAINED, [out] is TRANSFERRED
//
static void
_in_run(u3_noun a, u3j_site* sit_u, u3_noun* out)
{
if ( u3_nul == a ) {
return;
}
else {
u3_noun n_a, l_a, r_a;
u3x_trel(a, &n_a, &l_a, &r_a);
{
u3_noun new = u3j_gate_slam(sit_u, u3k(n_a));
u3_noun pro = u3qdi_put(*out, new);
u3z(new);
u3z(*out);
*out = pro;
}
_in_run(l_a, sit_u, out);
_in_run(r_a, sit_u, out);
}
}
u3_noun
u3qdi_run(u3_noun a, u3_noun b)
{
u3_noun out = u3_nul;
u3j_site sit_u;
u3j_gate_prep(&sit_u, u3k(b));
_in_run(a, &sit_u, &out);
u3j_gate_lose(&sit_u);
return out;
}
u3_noun
u3wdi_run(u3_noun cor)
{
u3_noun a, b;
u3x_mean(cor, u3x_sam, &b, u3x_con_sam, &a, 0);
return u3qdi_run(a, b);
}

View File

@ -1353,6 +1353,10 @@ static c3_c* _141_tri_ha[] = {
/* layer two
*/
static u3j_harm _141_two_find_a[] = {{".2", u3wb_find, c3y}, {}};
static c3_c* _141_two_find_ha[] = {
0
};
static u3j_harm _141_two_flop_a[] = {{".2", u3wb_flop, c3y}, {}};
static c3_c* _141_two_flop_ha[] = {
"73ac3be0119bcb822621de738f90975d98ce1ff3fb9a52853adc638271f61cd2",
@ -1443,6 +1447,14 @@ static c3_c* _141_two_weld_ha[] = {
"d855628821d57392f575c5da000c7326eaaa19e08cda967a4772859269669df2",
0
};
static u3j_harm _141_two_welp_a[] = {{".2", u3wb_welp, c3y}, {}};
static c3_c* _141_two_welp_ha[] = {
0
};
static u3j_harm _141_two_zing_a[] = {{".2", u3wb_zing, c3y}, {}};
static c3_c* _141_two_zing_ha[] = {
0
};
static u3j_harm _141_two_bex_a[] = {{".2", u3wc_bex, c3y}, {}};
static c3_c* _141_two_bex_ha[] = {
@ -1593,6 +1605,10 @@ static c3_c* _141_two_xeb_ha[] = {
0
};
static u3j_harm _141_two__in_apt_a[] = {{".2", u3wdi_apt}, {}};
static c3_c* _141_two__in_apt_ha[] = {
0
};
static u3j_harm _141_two__in_bif_a[] = {{".2", u3wdi_bif}, {}};
static c3_c* _141_two__in_bif_ha[] = {
"7ccbde61c80246056f6acfd8dc30f560af9e5abd44841c22ba0f49951dbc2f2a",
@ -1619,15 +1635,22 @@ static c3_c* _141_two_xeb_ha[] = {
0
};
// https://github.com/urbit/urbit/issues/328
// static u3j_harm _141_two__in_int_a[] = {{".2", u3wdi_int}, {}};
// static c3_c* _141_two__in_int_ha[] = {0};
static u3j_harm _141_two__in_int_a[] = {{".2", u3wdi_int}, {}};
static c3_c* _141_two__in_int_ha[] = {0};
static u3j_harm _141_two__in_put_a[] = {{".2", u3wdi_put}, {}};
static c3_c* _141_two__in_put_ha[] = {
"4a9fd615fecd2fd36485b3a2f24cdc13afc86f9a478362934b4654297496a03c",
0
};
static u3j_harm _141_two__in_rep_a[] = {{".2", u3wdi_rep}, {}};
static c3_c* _141_two__in_rep_ha[] = {
0
};
static u3j_harm _141_two__in_run_a[] = {{".2", u3wdi_run}, {}};
static c3_c* _141_two__in_run_ha[] = {
0
};
static u3j_harm _141_two__in_tap_a[] = {{".2", u3wdi_tap}, {}};
static c3_c* _141_two__in_tap_ha[] = {
"7dde59e2bd7684e785ce9787bc394571bd1216d7a62398c703447fc951c6b352",
@ -1643,24 +1666,39 @@ static c3_c* _141_two_xeb_ha[] = {
"8369d11970bfa09bd20c5b112a353fa10e8e64c9c081e3a5b17bcf3700127add",
0
};
static u3j_core _141_two__in_d[] =
{ { "bif", 7, _141_two__in_bif_a, 0, _141_two__in_bif_ha },
{ { "apt", 7, _141_two__in_apt_a, 0, _141_two__in_apt_ha },
{ "bif", 7, _141_two__in_bif_a, 0, _141_two__in_bif_ha },
{ "del", 7, _141_two__in_del_a, 0, _141_two__in_del_ha },
{ "dif", 7, _141_two__in_dif_a, 0, _141_two__in_dif_ha },
{ "gas", 7, _141_two__in_gas_a, 0, _141_two__in_gas_ha },
{ "has", 7, _141_two__in_has_a, 0, _141_two__in_has_ha },
// { "int", 7, _141_two__in_int_a, 0, _141_two__in_int_ha },
{ "int", 7, _141_two__in_int_a, 0, _141_two__in_int_ha },
{ "put", 7, _141_two__in_put_a, 0, _141_two__in_put_ha },
{ "rep", 7, _141_two__in_rep_a, 0, _141_two__in_rep_ha },
{ "run", 7, _141_two__in_run_a, 0, _141_two__in_run_ha },
{ "tap", 7, _141_two__in_tap_a, 0, _141_two__in_tap_ha },
{ "wyt", 3, _141_two__in_wyt_a, 0, _141_two__in_wyt_ha },
{ "uni", 7, _141_two__in_uni_a, 0, _141_two__in_uni_ha },
{ "wyt", 3, _141_two__in_wyt_a, 0, _141_two__in_wyt_ha },
{}
};
static c3_c* _141_two__in_ha[] = {
"abf20b11b7d7f9aa8cc7b4de01c15ec3aca3ea07ca09a461a3277fe24c640849",
0
};
static u3j_harm _141_two__by_all_a[] = {{".2", u3wdb_all, c3y}, {}};
static c3_c* _141_two__by_all_ha[] = {
0
};
static u3j_harm _141_two__by_any_a[] = {{".2", u3wdb_any, c3y}, {}};
static c3_c* _141_two__by_any_ha[] = {
0
};
static u3j_harm _141_two__by_apt_a[] = {{".2", u3wdb_apt, c3y}, {}};
static c3_c* _141_two__by_apt_ha[] = {
0
};
static u3j_harm _141_two__by_bif_a[] = {{".2", u3wdb_bif, c3y}, {}};
static c3_c* _141_two__by_bif_ha[] = {
"09ce4cf00dd9b4f95d4d93a984ffab94cb99cb6017bb73531245ea4813855f4e",
@ -1692,42 +1730,69 @@ static c3_c* _141_two__in_ha[] = {
0
};
// https://github.com/urbit/urbit/issues/328
// static u3j_harm _141_two__by_int_a[] = {{".2", u3wdb_int, c3y}, {}};
// static c3_c* _141_two__by_int_ha[] = {0};
static u3j_harm _141_two__by_int_a[] = {{".2", u3wdb_int, c3y}, {}};
static c3_c* _141_two__by_int_ha[] = {0};
static u3j_harm _141_two__by_jab_a[] = {{".2", u3wdb_jab, c3y}, {}};
static c3_c* _141_two__by_jab_ha[] = {
"8bc992aefabd2e0f43c900f2c4f3b06cf330973774d8f43428049cc3b3cb5b94",
0
};
static u3j_harm _141_two__by_key_a[] = {{".2", u3wdb_key, c3y}, {}};
static c3_c* _141_two__by_key_ha[] = {
0
};
static u3j_harm _141_two__by_put_a[] = {{".2", u3wdb_put, c3y}, {}};
static c3_c* _141_two__by_put_ha[] = {
"2cc9f005fde5314e9ad545286493a8c81b5c3b775d645ad82954f405d9414a32",
0
};
static u3j_harm _141_two__by_rep_a[] = {{".2", u3wdb_rep, c3y}, {}};
static c3_c* _141_two__by_rep_ha[] = {
0
};
static u3j_harm _141_two__by_run_a[] = {{".2", u3wdb_run, c3y}, {}};
static c3_c* _141_two__by_run_ha[] = {
0
};
static u3j_harm _141_two__by_tap_a[] = {{".2", u3wdb_tap, c3y}, {}};
static c3_c* _141_two__by_tap_ha[] = {
"7dde59e2bd7684e785ce9787bc394571bd1216d7a62398c703447fc951c6b352",
0
};
// https://github.com/urbit/urbit/issues/328
// static u3j_harm _141_two__by_uni_a[] = {{".2", u3wdb_uni, c3y}, {}};
// static c3_c* _141_two__by_uni_ha[] = {0};
static u3j_harm _141_two__by_uni_a[] = {{".2", u3wdb_uni, c3y}, {}};
static c3_c* _141_two__by_uni_ha[] = {
0
};
static u3j_harm _141_two__by_urn_a[] = {{".2", u3wdb_urn, c3y}, {}};
static c3_c* _141_two__by_urn_ha[] = {
0
};
static u3j_harm _141_two__by_wyt_a[] = {{".2", u3wdb_wyt, c3y}, {}};
static c3_c* _141_two__by_wyt_ha[] = {
0
};
static u3j_core _141_two__by_d[] =
{ { "bif", 7, _141_two__by_bif_a, 0, _141_two__by_bif_ha },
{ { "all", 7, _141_two__by_all_a, 0, _141_two__by_all_ha },
{ "any", 7, _141_two__by_any_a, 0, _141_two__by_any_ha },
{ "apt", 7, _141_two__by_apt_a, 0, _141_two__by_apt_ha },
{ "bif", 7, _141_two__by_bif_a, 0, _141_two__by_bif_ha },
{ "del", 7, _141_two__by_del_a, 0, _141_two__by_del_ha },
{ "dif", 7, _141_two__by_dif_a, 0, _141_two__by_dif_ha },
{ "gas", 7, _141_two__by_gas_a, 0, _141_two__by_gas_ha },
{ "get", 7, _141_two__by_get_a, 0, _141_two__by_get_ha },
{ "has", 7, _141_two__by_has_a, 0, _141_two__by_has_ha },
// { "int", 7, _141_two__by_int_a, 0, _141_two__by_int_ha },
{ "int", 7, _141_two__by_int_a, 0, _141_two__by_int_ha },
{ "jab", 7, _141_two__by_jab_a, 0, _141_two__by_jab_ha },
{ "key", 7, _141_two__by_key_a, 0, _141_two__by_key_ha },
{ "put", 7, _141_two__by_put_a, 0, _141_two__by_put_ha },
{ "rep", 7, _141_two__by_rep_a, 0, _141_two__by_rep_ha },
{ "run", 7, _141_two__by_run_a, 0, _141_two__by_run_ha },
{ "tap", 7, _141_two__by_tap_a, 0, _141_two__by_tap_ha },
// { "uni", 7, _141_two__by_uni_a, 0, _141_two__by_uni_ha },
{ "uni", 7, _141_two__by_uni_a, 0, _141_two__by_uni_ha },
{ "urn", 7, _141_two__by_urn_a, 0, _141_two__by_urn_ha },
{ "wyt", 3, _141_two__by_wyt_a, 0, _141_two__by_wyt_ha },
{}
};
static c3_c* _141_two__by_ha[] = {
@ -1759,6 +1824,7 @@ static c3_c* _141_two_rub_ha[] = {
static u3j_core _141_two_d[] =
{ { "tri", 3, 0, _141_tri_d, _141_tri_ha },
{ "find", 7, _141_two_find_a, 0, _141_two_find_ha },
{ "flop", 7, _141_two_flop_a, 0, _141_two_flop_ha },
{ "lent", 7, _141_two_lent_a, 0, _141_two_lent_ha },
{ "levy", 7, _141_two_levy_a, 0, _141_two_levy_ha },
@ -1777,6 +1843,8 @@ static u3j_core _141_two_d[] =
{ "sort", 7, _141_two_sort_a, 0, _141_two_sort_ha },
{ "turn", 7, _141_two_turn_a, 0, _141_two_turn_ha },
{ "weld", 7, _141_two_weld_a, 0, _141_two_weld_ha },
{ "welp", 7, _141_two_welp_a, 0, _141_two_welp_ha },
{ "zing", 7, _141_two_zing_a, 0, _141_two_zing_ha },
{ "bex", 7, _141_two_bex_a, 0, _141_two_bex_ha },
{ "cat", 7, _141_two_cat_a, 0, _141_two_cat_ha },