khan: skeleton for effect parsing

This is a direct port from http.c, including _reck_lily, which should
probably get factored out.

We parse sequence numbers even though they aren't yet stored on the C
side, just in case we wind up needing them later.

Still not actually handling effects.
This commit is contained in:
Jōshin 2021-10-21 07:03:49 +00:00
parent 64730a3b30
commit 21b60615d1

View File

@ -234,6 +234,65 @@ _khan_io_talk(u3_auto* car_u)
_khan_born_bail);
}
/* _khan_ef_handle(): handle result.
*/
static void
_khan_ef_handle(u3_khan* kan_u,
c3_l sev_l,
c3_l coq_l,
c3_l seq_l,
u3_noun tag,
u3_noun dat)
{
u3l_log("khan: avow\n");
// TODO handle effects
}
// TODO refactor these: they are duplicated from http.c
/* _reck_mole(): parse simple atomic mole.
*/
static u3_noun
_reck_mole(u3_noun fot,
u3_noun san,
c3_d* ato_d)
{
u3_noun uco = u3dc("slaw", fot, san);
u3_noun p_uco, q_uco;
if ( (c3n == u3r_cell(uco, &p_uco, &q_uco)) ||
(u3_nul != p_uco) )
{
u3l_log("strange mole %s\n", u3r_string(san));
u3z(fot); u3z(uco); return c3n;
}
else {
*ato_d = u3r_chub(0, q_uco);
u3z(fot); u3z(uco); return c3y;
}
}
/* _reck_lily(): parse little atom.
*/
static u3_noun
_reck_lily(u3_noun fot, u3_noun txt, c3_l* tid_l)
{
c3_d ato_d;
if ( c3n == _reck_mole(fot, txt, &ato_d) ) {
return c3n;
} else {
if ( ato_d >= 0x80000000ULL ) {
return c3n;
} else {
*tid_l = (c3_l) ato_d;
return c3y;
}
}
}
/* _khan_io_kick(): apply effects.
*/
static c3_o
@ -241,22 +300,57 @@ _khan_io_kick(u3_auto* car_u, u3_noun wir, u3_noun cad)
{
u3_khan* kan_u = (u3_khan*)car_u;
u3_noun tag, dat, i_wir;
u3_noun tag, dat, i_wir, t_wir;
c3_o ret_o;
if ( (c3n == u3r_cell(wir, &i_wir, 0))
|| (c3n == u3r_cell(cad, &tag, &dat))
|| (c3__khan != i_wir) )
{
ret_o = c3n;
u3z(wir); u3z(cad);
return c3n;
}
else {
ret_o = c3y;
// TODO do something
}
u3_noun pud = t_wir;
u3_noun p_pud, t_pud, tt_pud, q_pud, r_pud, s_pud;
c3_l sev_l, coq_l, seq_l;
u3z(wir); u3z(cad);
return ret_o;
if ( (c3n == u3r_cell(pud, &p_pud, &t_pud)) ||
(c3n == _reck_lily(c3__uv, u3k(p_pud), &sev_l)) )
{
u3z(wir); u3z(cad);
return c3n;
}
if ( u3_nul == t_pud ) {
coq_l = seq_l = 0;
}
else {
if ( (c3n == u3r_cell(t_pud, &q_pud, &tt_pud)) ||
(c3n == _reck_lily(c3__ud, u3k(q_pud), &coq_l)) )
{
u3z(wir); u3z(cad);
return c3n;
}
if ( u3_nul == tt_pud ) {
seq_l = 0;
}
else {
if ( (c3n == u3r_cell(tt_pud, &r_pud, &s_pud)) ||
(u3_nul != s_pud) ||
(c3n == _reck_lily(c3__ud, u3k(r_pud), &seq_l)) )
{
u3z(wir); u3z(cad);
return c3n;
}
}
}
_khan_ef_handle(kan_u, sev_l, coq_l, seq_l, u3k(tag), u3k(dat));
u3z(wir); u3z(cad);
return c3y;
}
}
/* _khan_io_exit(): unlink socket, shut down connections.