Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 27 additions & 25 deletions pkg/noun/jets/b/levy.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,37 +5,39 @@

#include "noun.h"

static u3_noun
_levy_in(u3j_site* sit_u, u3_noun a)
{
if ( 0 == a ) {
return c3y;
} else {
u3_noun loz;

if ( c3n == u3du(a) ) {
return u3m_bail(c3__exit);
}
else switch ( (loz = u3j_gate_slam(sit_u, u3k(u3h(a)))) ) {
case c3y: return _levy_in(sit_u, u3t(a));
case c3n: return c3n;
default: u3z(loz);
return u3m_bail(c3__exit);
}
}
}

u3_noun
u3qb_levy(u3_noun a,
u3_noun b)
{
u3_noun pro;
u3j_site sit_u;
u3j_gate_prep(&sit_u, u3k(b));
pro = _levy_in(&sit_u, a);
u3j_gate_lose(&sit_u);
u3_noun pro = c3y;
c3_o loz_o;

if ( u3_nul != a ) {
u3j_site sit_u;
u3_noun i, t;
u3j_gate_prep(&sit_u, u3k(b));
u3k(a);

do {
i = u3h(a);

loz_o = u3x_loob(u3j_gate_slam(&sit_u, u3k(i)));
if ( c3n == loz_o ) {
pro = c3n;
break;
}

t = u3k(u3t(a));
u3z(a), a = t;
} while ( u3_nul != a );

u3z(a);
Copy link
Contributor Author

@dozreg-toplud dozreg-toplud Aug 28, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A note for list logic jets: almost all changes include a transfer loop, where at the entry we gain a reference to a and then iterate over the list, gaining its tail and losing the list, then replacing the list with its tail. It means that at the end of the loop we still have a reference to a noun in a. We almost never lose it though, because a is 0, except for +levy/+lien, where we might break from the loop earlier.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

technically the very first gain of the list is not necessary and we could unroll the loop, doing things as usual in the first iteration and starting to count the references after that, but IMO whatever gain we get from that is not worth the bloated code

u3j_gate_lose(&sit_u);
}

return pro;
}

u3_noun
u3wb_levy(u3_noun cor)
{
Expand Down
52 changes: 27 additions & 25 deletions pkg/noun/jets/b/lien.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,37 +5,39 @@

#include "noun.h"

static u3_noun
_lien_in(u3j_site* sit_u, u3_noun a)
{
if ( 0 == a ) {
return c3n;
} else {
u3_noun loz;

if ( c3n == u3du(a) ) {
return u3m_bail(c3__exit);
}
else switch ( (loz = u3j_gate_slam(sit_u, u3k(u3h(a)))) ) {
case c3y: return c3y;
case c3n: return _lien_in(sit_u, u3t(a));
default: u3z(loz);
return u3m_bail(c3__exit);
}
}
}

u3_noun
u3qb_lien(u3_noun a,
u3_noun b)
{
u3_noun pro;
u3j_site sit_u;
u3j_gate_prep(&sit_u, u3k(b));
pro = _lien_in(&sit_u, a);
u3j_gate_lose(&sit_u);
u3_noun pro = c3n;
c3_o loz_o;

if ( u3_nul != a ) {
u3j_site sit_u;
u3_noun i, t;
u3j_gate_prep(&sit_u, u3k(b));
u3k(a);

do {
i = u3h(a);

loz_o = u3x_loob(u3j_gate_slam(&sit_u, u3k(i)));
if ( c3y == loz_o ) {
pro = c3y;
break;
}

t = u3k(u3t(a));
u3z(a), a = t;
} while ( u3_nul != a );

u3z(a);
u3j_gate_lose(&sit_u);
}

return pro;
}

u3_noun
u3wb_lien(u3_noun cor)
{
Expand Down
10 changes: 7 additions & 3 deletions pkg/noun/jets/b/murn.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,14 @@ u3qb_murn(u3_noun a, u3_noun b)
if ( u3_nul != a ) {
u3_noun* hed;
u3_noun* tel;
u3_noun res, i, t = a;
u3_noun res, i, t;
u3j_site sit_u;

u3j_gate_prep(&sit_u, u3k(b));
u3k(a);

do {
u3x_cell(t, &i, &t);
i = u3h(a);

res = u3j_gate_slam(&sit_u, u3k(i));

Expand All @@ -30,8 +31,11 @@ u3qb_murn(u3_noun a, u3_noun b)
lit = tel;
u3z(res);
}

t = u3k(u3t(a));
u3z(a), a = t;
}
while ( u3_nul != t );
while ( u3_nul != a );

u3j_gate_lose(&sit_u);
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/noun/jets/b/reel.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@
do {
u3x_cell(t, &i, &t);
top = u3a_push(&pil_u);
*top = i;
*top = u3k(i);
} while ( u3_nul != t );

u3j_gate_prep(&sit_u, u3k(b));

while ( c3n == u3a_pile_done(&pil_u) ) {
pro = u3j_gate_slam(&sit_u, u3nc(u3k(*top), pro));
pro = u3j_gate_slam(&sit_u, u3nc(*top, pro));
top = u3a_pop(&pil_u);
}

Expand Down
12 changes: 9 additions & 3 deletions pkg/noun/jets/b/roll.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,18 @@

if ( u3_nul != a ) {
u3j_site sit_u;
u3_noun i, t = a;
u3_noun i, t;
u3j_gate_prep(&sit_u, u3k(b));
u3k(a);

do {
u3x_cell(t, &i, &t);
i = u3h(a);

pro = u3j_gate_slam(&sit_u, u3nc(u3k(i), pro));
} while ( u3_nul != t );

t = u3k(u3t(a));
u3z(a), a = t;
} while ( u3_nul != a );
u3j_gate_lose(&sit_u);
}

Expand Down
10 changes: 7 additions & 3 deletions pkg/noun/jets/b/skid.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,15 @@ u3qb_skid(u3_noun a, u3_noun b)
u3_noun* rig = &r;

if ( u3_nul != a) {
u3_noun i, t = a;
u3_noun i, t;
u3_noun* hed;
u3_noun* tel;
u3j_site sit_u;
u3j_gate_prep(&sit_u, u3k(b));
u3k(a);

do {
u3x_cell(t, &i, &t);
i = u3h(a);

switch ( u3j_gate_slam(&sit_u, u3k(i)) ) {
case c3y: {
Expand All @@ -37,8 +38,11 @@ u3qb_skid(u3_noun a, u3_noun b)

default: u3m_bail(c3__exit);
}

t = u3k(u3t(a));
u3z(a), a = t;
}
while ( u3_nul != t );
while ( u3_nul != a );

u3j_gate_lose(&sit_u);
}
Expand Down
10 changes: 7 additions & 3 deletions pkg/noun/jets/b/skim.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,15 @@ u3qb_skim(u3_noun a, u3_noun b)
u3_noun* lit = &pro;

if ( u3_nul != a) {
u3_noun i, t = a;
u3_noun i, t;
u3_noun* hed;
u3_noun* tel;
u3j_site sit_u;
u3j_gate_prep(&sit_u, u3k(b));
u3k(a);

do {
u3x_cell(t, &i, &t);
i = u3h(a);

switch ( u3j_gate_slam(&sit_u, u3k(i)) ) {
case c3y: {
Expand All @@ -32,8 +33,11 @@ u3qb_skim(u3_noun a, u3_noun b)

default: u3m_bail(c3__exit);
}

t = u3k(u3t(a));
u3z(a), a = t;
}
while ( u3_nul != t );
while ( u3_nul != a );

u3j_gate_lose(&sit_u);
}
Expand Down
10 changes: 7 additions & 3 deletions pkg/noun/jets/b/skip.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,15 @@ u3qb_skip(u3_noun a, u3_noun b)
u3_noun* lit = &pro;

if ( u3_nul != a) {
u3_noun i, t = a;
u3_noun i, t;
u3_noun* hed;
u3_noun* tel;
u3j_site sit_u;
u3j_gate_prep(&sit_u, u3k(b));
u3k(a);

do {
u3x_cell(t, &i, &t);
i = u3h(a);

switch ( u3j_gate_slam(&sit_u, u3k(i)) ) {
case c3y: break;
Expand All @@ -32,8 +33,11 @@ u3qb_skip(u3_noun a, u3_noun b)

default: u3m_bail(c3__exit);
}

t = u3k(u3t(a));
u3z(a), a = t;
}
while ( u3_nul != t );
while ( u3_nul != a );

u3j_gate_lose(&sit_u);
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/noun/jets/b/sort.c
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ _sort(u3j_site* sit_u, u3_noun list)
// since the list was already validated and measured
//
u3a_cell* cel_u = u3a_to_ptr(list);
arr_u[i_w] = cel_u->hed;
arr_u[i_w] = u3k(cel_u->hed);
list = cel_u->tel;
}

Expand All @@ -89,7 +89,7 @@ _sort(u3j_site* sit_u, u3_noun list)
u3_noun pro = u3_nul;
for (c3_w i_w = len_w; i_w--;)
{
pro = u3nc(u3k(arr_u[i_w]), pro);
pro = u3nc(arr_u[i_w], pro);
}

u3a_free(arr_u);
Expand Down
10 changes: 7 additions & 3 deletions pkg/noun/jets/b/turn.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,23 @@ u3qb_turn(u3_noun a, u3_noun b)
if ( u3_nul != a ) {
u3_noun* hed;
u3_noun* tel;
u3_noun i, t = a;
u3_noun i, t;
u3j_site sit_u;

u3j_gate_prep(&sit_u, u3k(b));
u3k(a);

do {
u3x_cell(t, &i, &t);
i = u3h(a);

*lit = u3i_defcons(&hed, &tel);
*hed = u3j_gate_slam(&sit_u, u3k(i));
lit = tel;

t = u3k(u3t(a));
u3z(a), a = t;
}
while ( u3_nul != t );
while ( u3_nul != a );

u3j_gate_lose(&sit_u);
}
Expand Down
Loading