Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

u3: inline cell deconstruction #536

Merged
merged 3 commits into from
Oct 13, 2023
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
134 changes: 29 additions & 105 deletions pkg/noun/retrieve.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,35 @@
#include "trace.h"
#include "xtract.h"


// declarations of inline functions
//
c3_o
u3r_cell(u3_noun a, u3_noun* b, u3_noun* c);
c3_o
u3r_trel(u3_noun a, u3_noun* b, u3_noun* c, u3_noun* d);
c3_o
u3r_qual(u3_noun a,
u3_noun* b,
u3_noun* c,
u3_noun* d,
u3_noun* e);
c3_o
u3r_quil(u3_noun a,
u3_noun* b,
u3_noun* c,
u3_noun* d,
u3_noun* e,
u3_noun* f);
c3_o
u3r_hext(u3_noun a,
u3_noun* b,
u3_noun* c,
u3_noun* d,
u3_noun* e,
u3_noun* f,
u3_noun* g);

/* _frag_word(): fast fragment/branch prediction for top word.
*/
static u3_weak
Expand Down Expand Up @@ -833,27 +862,6 @@ u3r_bite(u3_noun bite, u3_atom* bloq, u3_atom *step)
}
}

/* u3r_cell():
**
** Factor (a) as a cell (b c).
*/
c3_o
u3r_cell(u3_noun a,
u3_noun* b,
u3_noun* c)
{
u3_assert(u3_none != a);

if ( _(u3a_is_atom(a)) ) {
return c3n;
}
else {
if ( b ) *b = u3a_h(a);
if ( c ) *c = u3a_t(a);
return c3y;
}
}

/* u3r_p():
**
** & [0] if [a] is of the form [b *c].
Expand Down Expand Up @@ -937,90 +945,6 @@ u3r_pqrs(u3_noun a,
else return c3n;
}

/* u3r_trel():
**
** Factor (a) as a trel (b c d).
*/
c3_o
u3r_trel(u3_noun a,
u3_noun *b,
u3_noun *c,
u3_noun *d)
{
u3_noun guf;

if ( (c3y == u3r_cell(a, b, &guf)) &&
(c3y == u3r_cell(guf, c, d)) ) {
return c3y;
}
else {
return c3n;
}
}

/* u3r_qual():
**
** Factor (a) as a qual (b c d e).
*/
c3_o
u3r_qual(u3_noun a,
u3_noun* b,
u3_noun* c,
u3_noun* d,
u3_noun* e)
{
u3_noun guf;

if ( (c3y == u3r_cell(a, b, &guf)) &&
(c3y == u3r_trel(guf, c, d, e)) ) {
return c3y;
}
else return c3n;
}

/* u3r_quil():
**
** Factor (a) as a quil (b c d e f).
*/
c3_o
u3r_quil(u3_noun a,
u3_noun* b,
u3_noun* c,
u3_noun* d,
u3_noun* e,
u3_noun* f)
{
u3_noun guf;

if ( (c3y == u3r_cell(a, b, &guf)) &&
(c3y == u3r_qual(guf, c, d, e, f)) ) {
return c3y;
}
else return c3n;
}

/* u3r_hext():
**
** Factor (a) as a hext (b c d e f g)
*/
c3_o
u3r_hext(u3_noun a,
u3_noun* b,
u3_noun* c,
u3_noun* d,
u3_noun* e,
u3_noun* f,
u3_noun* g)
{
u3_noun guf;

if ( (c3y == u3r_cell(a, b, &guf)) &&
(c3y == u3r_quil(guf, c, d, e, f, g)) ) {
return c3y;
}
else return c3n;
}

/* u3r_met():
**
** Return the size of (b) in bits, rounded up to
Expand Down
151 changes: 96 additions & 55 deletions pkg/noun/retrieve.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,107 @@
#define U3_RETRIEVE_H

#include "c3.h"
#include "allocate.h"
#include "error.h"
#include "gmp.h"
#include "types.h"

/** u3r_*: read without ever crashing.
**/

/* u3r_cell(): factor (a) as a cell (b c).
*/
inline c3_o
u3r_cell(u3_noun a, u3_noun* b, u3_noun* c)
{
u3a_cell* cel_u;

u3_assert(u3_none != a);

if ( c3y == u3a_is_cell(a) ) {
cel_u = u3a_to_ptr(a);
if ( b ) *b = cel_u->hed;
if ( c ) *c = cel_u->tel;
return c3y;
}
else {
return c3n;
}
}

/* u3r_trel(): factor (a) as a trel (b c d).
*/
inline c3_o
u3r_trel(u3_noun a, u3_noun *b, u3_noun *c, u3_noun *d)
{
u3_noun guf;

if ( (c3y == u3r_cell(a, b, &guf)) &&
(c3y == u3r_cell(guf, c, d)) ) {
return c3y;
}
else {
return c3n;
}
}

/* u3r_qual(): factor (a) as a qual (b c d e).
*/
inline c3_o
u3r_qual(u3_noun a,
u3_noun* b,
u3_noun* c,
u3_noun* d,
u3_noun* e)
{
u3_noun guf;

if ( (c3y == u3r_cell(a, b, &guf)) &&
(c3y == u3r_trel(guf, c, d, e)) ) {
return c3y;
}
else return c3n;
}

/* u3r_quil(): factor (a) as a quil (b c d e f).
*/
inline c3_o
u3r_quil(u3_noun a,
u3_noun* b,
u3_noun* c,
u3_noun* d,
u3_noun* e,
u3_noun* f)
{
u3_noun guf;

if ( (c3y == u3r_cell(a, b, &guf)) &&
(c3y == u3r_qual(guf, c, d, e, f)) ) {
return c3y;
}
else return c3n;
}

/* u3r_hext(): factor (a) as a hext (b c d e f g)
*/
inline c3_o
u3r_hext(u3_noun a,
u3_noun* b,
u3_noun* c,
u3_noun* d,
u3_noun* e,
u3_noun* f,
u3_noun* g)
{
u3_noun guf;

if ( (c3y == u3r_cell(a, b, &guf)) &&
(c3y == u3r_quil(guf, c, d, e, f, g)) ) {
return c3y;
}
else return c3n;
}

/* u3r_at(): fragment `a` of `b`, or u3_none.
*/
u3_weak
Expand Down Expand Up @@ -183,61 +279,6 @@
c3_o
u3r_bite(u3_noun bite, u3_atom* bloq, u3_atom *step);

/* u3r_cell():
**
** Divide `a` as a cell `[b c]`.
*/
c3_o
u3r_cell(u3_noun a,
u3_noun* b,
u3_noun* c);

/* u3r_trel():
**
** Divide `a` as a trel `[b c d]`.
*/
c3_o
u3r_trel(u3_noun a,
u3_noun* b,
u3_noun* c,
u3_noun* d);

/* u3r_qual():
**
** Divide (a) as a qual [b c d e].
*/
c3_o
u3r_qual(u3_noun a,
u3_noun* b,
u3_noun* c,
u3_noun* d,
u3_noun* e);

/* u3r_quil():
**
** Divide (a) as a quil [b c d e f].
*/
c3_o
u3r_quil(u3_noun a,
u3_noun* b,
u3_noun* c,
u3_noun* d,
u3_noun* e,
u3_noun* f);

/* u3r_hext():
**
** Divide (a) as a hext [b c d e f g].
*/
c3_o
u3r_hext(u3_noun a,
u3_noun* b,
u3_noun* c,
u3_noun* d,
u3_noun* e,
u3_noun* f,
u3_noun* g);

/* u3r_p():
**
** & [0] if [a] is of the form [b *c].
Expand Down
Loading