a bunch of stuff

This commit is contained in:
Max G 2015-07-29 23:43:55 +03:00
parent 24c0a807ab
commit ac23f4ac70
11 changed files with 185 additions and 18 deletions

View File

@ -167,6 +167,7 @@ J_C_OFILES=\
jets/c/con.o \
jets/c/cut.o \
jets/c/dor.o \
jets/c/dvr.o \
jets/c/dis.o \
jets/c/end.o \
jets/c/gor.o \
@ -178,9 +179,11 @@ J_C_OFILES=\
jets/c/mug.o \
jets/c/peg.o \
jets/c/po.o \
jets/c/pow.o \
jets/c/rap.o \
jets/c/rip.o \
jets/c/rsh.o \
jets/c/sqt.o \
jets/c/vor.o
J_D_OFILES=\
@ -211,8 +214,8 @@ J_E_OFILES=\
jets/e/mule.o \
jets/e/parse.o \
jets/e/rd.o \
jets/e/rs.o \
jets/e/rq.o \
jets/e/rs.o \
jets/e/repg.o \
jets/e/rexp.o \
jets/e/rub.o \

View File

@ -47,6 +47,7 @@
u3_noun u3qc_cut(u3_atom, u3_atom, u3_atom, u3_atom);
u3_noun u3qc_dis(u3_atom, u3_atom);
u3_noun u3qc_dor(u3_atom, u3_atom);
u3_noun u3qc_dvr(u3_atom, u3_atom);
u3_noun u3qc_end(u3_atom, u3_atom, u3_atom);
u3_noun u3qc_gor(u3_atom, u3_atom);
u3_noun u3qc_hor(u3_atom, u3_atom);
@ -55,9 +56,11 @@
u3_noun u3qc_met(u3_atom, u3_atom);
u3_noun u3qc_mix(u3_atom, u3_atom);
u3_noun u3qc_peg(u3_atom, u3_atom);
u3_noun u3qc_pow(u3_atom, u3_atom);
u3_noun u3qc_rap(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_sqt(u3_atom);
u3_noun u3qc_vor(u3_atom, u3_atom);
/** Tier 4.

View File

@ -46,6 +46,7 @@
u3_noun u3wc_cut(u3_noun);
u3_noun u3wc_dis(u3_noun);
u3_noun u3wc_dor(u3_noun);
u3_noun u3wc_dvr(u3_noun);
u3_noun u3wc_end(u3_noun);
u3_noun u3wc_gor(u3_noun);
u3_noun u3wc_hor(u3_noun);
@ -55,9 +56,11 @@
u3_noun u3wc_mix(u3_noun);
u3_noun u3wc_mug(u3_noun);
u3_noun u3wc_peg(u3_noun);
u3_noun u3wc_pow(u3_noun);
u3_noun u3wc_rap(u3_noun);
u3_noun u3wc_rip(u3_noun);
u3_noun u3wc_rsh(u3_noun);
u3_noun u3wc_sqt(u3_noun);
u3_noun u3wc_vor(u3_noun);
u3_noun u3wcp_ins(u3_noun);

44
jets/c/dvr.c Normal file
View File

@ -0,0 +1,44 @@
/* j/3/dvr.c
**
*/
#include "all.h"
/* functions
*/
u3_noun
u3qc_dvr(u3_atom a, u3_atom b)
{
if ( 0 == b) {
return u3m_bail(c3__exit);
}
else {
if ( _(u3a_is_cat(a)) && _(u3a_is_cat(b)) ) {
return u3nc(a / b, a % b);
}
else {
mpz_t a_mp, b_mp;
u3r_mp(a_mp, a);
u3r_mp(b_mp, b);
mpz_tdiv_qr(a_mp, b_mp, a_mp, b_mp);
return u3nc(u3k(u3i_mp(a_mp)), u3k(u3i_mp(b_mp)));
}
}
}
u3_noun
u3wc_dvr(u3_noun cor)
{
u3_noun a, b;
if ( (c3n == u3r_mean(cor, u3x_sam_2, &a, u3x_sam_3, &b, 0)) ||
(c3n == u3ud(a)) )
{
return u3m_bail(c3__exit);
} else {
return u3qc_dvr(a, b);
}
}

37
jets/c/pow.c Normal file
View File

@ -0,0 +1,37 @@
/* j/3/pow.c
**
*/
#include "all.h"
/* functions
*/
u3_noun
u3qc_pow(u3_atom a, u3_atom b)
{
if ( !_(u3a_is_cat(b)) ) {
return u3m_bail(c3__fail);
}
else {
mpz_t a_mp;
u3r_mp(a_mp, a);
mpz_pow_ui(a_mp, a_mp, b);
return u3i_mp(a_mp);
}
}
u3_noun
u3wc_pow(u3_noun cor)
{
u3_noun a, b;
if ( (c3n == u3r_mean(cor, u3x_sam_2, &a, u3x_sam_3, &b, 0)) ||
(c3n == u3ud(a)) )
{
return u3m_bail(c3__exit);
} else {
return u3qc_pow(a, b);
}
}

33
jets/c/sqt.c Normal file
View File

@ -0,0 +1,33 @@
/* j/3/sqt.c
**
*/
#include "all.h"
/* functions
*/
u3_noun
u3qc_sqt(u3_atom a)
{
mpz_t a_mp, b_mp;
u3r_mp(a_mp, a);
mpz_init(b_mp);
mpz_sqrtrem(a_mp, b_mp, a_mp);
return u3nc(u3k(u3i_mp(a_mp)), u3k(u3i_mp(b_mp)));
}
u3_noun
u3wc_sqt(u3_noun cor)
{
u3_noun a;
if ( (u3_none == (a = u3r_at(u3x_sam, cor))) ||
(c3n == u3ud(a)) )
{
return u3m_bail(c3__exit);
} else {
return u3qc_sqt(a);
}
}

View File

@ -41,6 +41,7 @@ static u3j_harm _mood__hoon_con_a[] = {{".2", u3wc_con, c3y}, {}};
static u3j_harm _mood__hoon_cut_a[] = {{".2", u3wc_cut, c3y}, {}};
static u3j_harm _mood__hoon_dis_a[] = {{".2", u3wc_dis, c3y}, {}};
static u3j_harm _mood__hoon_dor_a[] = {{".2", u3wc_dor, c3y}, {}};
static u3j_harm _mood__hoon_dvr_a[] = {{".2", u3wc_dvr, c3y}, {}};
static u3j_harm _mood__hoon_end_a[] = {{".2", u3wc_end, c3y}, {}};
static u3j_harm _mood__hoon_gor_a[] = {{".2", u3wc_gor, c3y}, {}};
static u3j_harm _mood__hoon_hor_a[] = {{".2", u3wc_hor, c3y}, {}};
@ -50,9 +51,11 @@ static u3j_harm _mood__hoon_met_a[] = {{".2", u3wc_met, c3y}, {}};
static u3j_harm _mood__hoon_mix_a[] = {{".2", u3wc_mix, c3y}, {}};
static u3j_harm _mood__hoon_mug_a[] = {{".2", u3wc_mug, c3y}, {}};
static u3j_harm _mood__hoon_peg_a[] = {{".2", u3wc_peg, c3y}, {}};
static u3j_harm _mood__hoon_pow_a[] = {{".2", u3wc_pow, c3y}, {}};
static u3j_harm _mood__hoon_rap_a[] = {{".2", u3wc_rap, c3y}, {}};
static u3j_harm _mood__hoon_rip_a[] = {{".2", u3wc_rip, c3y}, {}};
static u3j_harm _mood__hoon_rsh_a[] = {{".2", u3wc_rsh, c3y}, {}};
static u3j_harm _mood__hoon_sqt_a[] = {{".2", u3wc_sqt, c3y}, {}};
static u3j_harm _mood__hoon_vor_a[] = {{".2", u3wc_vor, c3y}, {}};
static u3j_harm _mood__hoon__po_ind_a[] = {{".2", u3wcp_ind}, {}};
@ -459,6 +462,7 @@ static u3j_core _mood__hoon_d[] =
{ "cut", _mood__hoon_cut_a },
{ "dis", _mood__hoon_dis_a },
{ "dor", _mood__hoon_dor_a },
{ "dvr", _mood__hoon_dvr_a },
{ "end", _mood__hoon_end_a },
{ "gor", _mood__hoon_gor_a },
{ "hor", _mood__hoon_hor_a },
@ -468,9 +472,11 @@ static u3j_core _mood__hoon_d[] =
{ "mix", _mood__hoon_mix_a },
{ "mug", _mood__hoon_mug_a },
{ "peg", _mood__hoon_peg_a },
{ "pow", _mood__hoon_pow_a },
{ "rap", _mood__hoon_rap_a },
{ "rip", _mood__hoon_rip_a },
{ "rsh", _mood__hoon_rsh_a },
{ "sqt", _mood__hoon_sqt_a },
{ "vor", _mood__hoon_vor_a },
{ "po", 0, _mood__hoon__po_d },

View File

@ -1447,14 +1447,32 @@ u3r_bytes(c3_w a_w,
c3_y* c_y,
u3_atom d)
{
c3_w i_w;
c3_assert(u3_none != d);
c3_assert(_(u3a_is_atom(d)));
/* Efficiency: don't call u3r_byte().
*/
for ( i_w = 0; i_w < b_w; i_w++ ) {
c_y[i_w] = u3r_byte((a_w + i_w), d);
if ( _(u3a_is_cat(d)) ) {
c3_w e_w = d >> (c3_min(a_w, 4) << 3);
c3_w m_w = c3_min(b_w, 4);
memcpy(c_y, (c3_y*)&e_w, m_w);
if ( b_w > 4 ) {
memset(c_y + 4, 0, b_w - 4);
}
}
else {
u3a_atom* d_u = u3a_to_ptr(d);
c3_w n_w = d_u->len_w << 2;
c3_y* x_y = (c3_y*)d_u->buf_w + a_w;
if ( a_w >= n_w ) {
memset(c_y, 0, b_w);
}
else {
c3_w z_w = c3_min(b_w, n_w - a_w);
memcpy(c_y, x_y, z_w);
if ( b_w > n_w - a_w ) {
memset(c_y + z_w, 0, b_w + a_w - n_w);
}
}
}
}
@ -1546,14 +1564,34 @@ u3r_words(c3_w a_w,
c3_w* c_w,
u3_atom d)
{
c3_w i_w;
c3_assert(u3_none != d);
c3_assert(_(u3a_is_atom(d)));
/* Efficiency: don't call u3r_word().
*/
for ( i_w = 0; i_w < b_w; i_w++ ) {
c_w[i_w] = u3r_word((a_w + i_w), d);
if ( b_w == 0 ) {
return;
}
if ( _(u3a_is_cat(d)) ) {
if ( a_w == 0 ) {
*c_w = d;
memset((c3_y*)(c_w + 1), 0, (b_w - 1) << 2);
}
else {
memset((c3_y*)c_w, 0, b_w << 2);
}
}
else {
u3a_atom* d_u = u3a_to_ptr(d);
if ( a_w >= d_u->len_w ) {
memset((c3_y*)c_w, 0, b_w << 2);
}
else {
c3_w z_w = c3_min(b_w, d_u->len_w - a_w);
c3_w* x_w = d_u->buf_w + a_w;
memcpy((c3_y*)c_w, (c3_y*)x_w, z_w << 2);
if ( b_w > d_u->len_w - a_w ) {
memset((c3_y*)(c_w + z_w), 0, (b_w + a_w - d_u->len_w) << 2);
}
}
}
}