mirror of
https://github.com/urbit/shrub.git
synced 2024-12-19 16:51:42 +03:00
Merge pull request #5261 from DaneBettis/jb/dynamic-hint-template
vere: adds %bout hint, to time a hoon expression in nanoseconds
This commit is contained in:
commit
e1a2eaf822
@ -66,7 +66,7 @@
|
||||
=/ fire-arm=nock
|
||||
~| [%failed-to-compile-test-arm name]
|
||||
q:(~(mint ut typ) p:!>(*tang) [%limb name])
|
||||
[name |.(;;(tang .*(cor fire-arm)))]
|
||||
[name |.(;;(tang ~>(%bout.[1 name] .*(cor fire-arm))))]
|
||||
:: +has-test-prefix: does the arm define a test we should run?
|
||||
::
|
||||
++ has-test-prefix
|
||||
|
@ -112,6 +112,7 @@
|
||||
# define c3__boot c3_s4('b','o','o','t')
|
||||
# define c3__born c3_s4('b','o','r','n')
|
||||
# define c3__both c3_s4('b','o','t','h')
|
||||
# define c3__bout c3_s4('b','o','u','t')
|
||||
# define c3__box c3_s3('b','o','x')
|
||||
# define c3__br c3_s2('b','r')
|
||||
# define c3__bran c3_s4('b','r','a','n')
|
||||
|
@ -93,6 +93,12 @@
|
||||
void
|
||||
u3t_trace_close();
|
||||
|
||||
/* u3t_trace_time(): returns current time since system epoc,
|
||||
* whatever it is per system, in microseconds.
|
||||
*/
|
||||
c3_d
|
||||
u3t_trace_time();
|
||||
|
||||
/* u3t_nock_trace_push(): pushes a frame onto the trace stack;
|
||||
* return yes if active push.
|
||||
*/
|
||||
|
@ -1004,8 +1004,8 @@ _n_emit(u3_noun *ops, u3_noun op)
|
||||
static c3_w _n_comp(u3_noun*, u3_noun, c3_o, c3_o);
|
||||
|
||||
/* _n_bint(): hint-processing helper for _n_comp.
|
||||
* hif: hint-formula (first part of 10). RETAIN.
|
||||
* nef: next-formula (second part of 10). RETAIN.
|
||||
* hif: hint-formula (first part of 11). RETAIN.
|
||||
* nef: next-formula (second part of 11). RETAIN.
|
||||
*/
|
||||
static c3_w
|
||||
_n_bint(u3_noun* ops, u3_noun hif, u3_noun nef, c3_o los_o, c3_o tel_o)
|
||||
@ -1021,9 +1021,7 @@ _n_bint(u3_noun* ops, u3_noun hif, u3_noun nef, c3_o los_o, c3_o tel_o)
|
||||
return _n_comp(ops, nef, los_o, tel_o);
|
||||
}
|
||||
|
||||
// no currently recognized static hints
|
||||
//
|
||||
case u3_none: {
|
||||
case c3__bout: {
|
||||
u3_noun fen = u3_nul;
|
||||
c3_w nef_w = _n_comp(&fen, nef, los_o, tel_o);
|
||||
|
||||
@ -1052,9 +1050,7 @@ _n_bint(u3_noun* ops, u3_noun hif, u3_noun nef, c3_o los_o, c3_o tel_o)
|
||||
tot_w += _n_comp(ops, nef, los_o, tel_o);
|
||||
} break;
|
||||
|
||||
// no currently recognized dynamic hints
|
||||
//
|
||||
case u3_none: {
|
||||
case c3__bout: {
|
||||
u3_noun fen = u3_nul;
|
||||
c3_w nef_w = _n_comp(&fen, nef, los_o, tel_o);
|
||||
|
||||
@ -1677,18 +1673,25 @@ u3n_find(u3_noun key, u3_noun fol)
|
||||
}
|
||||
|
||||
/* _n_hilt_fore(): literal (atomic) dynamic hint, before formula evaluation.
|
||||
** lit: hint atom. TRANSFER
|
||||
** hin: [hint-atom, formula]. TRANSFER
|
||||
** bus: subject. RETAIN
|
||||
** out: token for _n_hilt_hind();
|
||||
** conventionally, [lit] or [lit data]. ~ if unused.
|
||||
** out: token for _n_hilt_hind(); convention:
|
||||
** [hint-atom] or [hint-atom data], ~ if unused.
|
||||
**
|
||||
** any hints herein must be whitelisted in _n_burn().
|
||||
*/
|
||||
static c3_o
|
||||
_n_hilt_fore(u3_atom lit, u3_noun bus, u3_noun* out) // transfer, retain, n/a
|
||||
_n_hilt_fore(u3_noun hin, u3_noun bus, u3_noun* out)
|
||||
{
|
||||
u3z(lit);
|
||||
*out = u3_nul;
|
||||
if ( c3__bout == u3h(hin) ) {
|
||||
u3_atom now = u3i_chub(u3t_trace_time());
|
||||
*out = u3i_cell(u3h(hin), now);
|
||||
}
|
||||
else {
|
||||
*out = u3_nul;
|
||||
}
|
||||
|
||||
u3z(hin);
|
||||
return c3y;
|
||||
}
|
||||
|
||||
@ -1697,9 +1700,20 @@ _n_hilt_fore(u3_atom lit, u3_noun bus, u3_noun* out) // transfer, retain, n/a
|
||||
** pro: product of formula evaluation. RETAIN
|
||||
*/
|
||||
static void
|
||||
_n_hilt_hind(u3_noun tok, u3_noun pro) // transfer, retain
|
||||
_n_hilt_hind(u3_noun tok, u3_noun pro)
|
||||
{
|
||||
c3_assert( u3_nul == tok );
|
||||
u3_noun p_tok, q_tok;
|
||||
if ( (c3y == u3r_cell(tok, &p_tok, &q_tok)) && (c3__bout == p_tok) ) {
|
||||
u3_atom delta = u3ka_sub(u3i_chub(u3t_trace_time()), u3k(q_tok));
|
||||
c3_c str_c[64];
|
||||
snprintf(str_c, 63, "took %" PRIu64 "\xc2\xb5s", u3r_chub(0, delta) );
|
||||
u3t_slog(u3nc(0, u3i_string(str_c)));
|
||||
u3z(delta);
|
||||
}
|
||||
else {
|
||||
c3_assert( u3_nul == tok );
|
||||
}
|
||||
|
||||
u3z(tok);
|
||||
}
|
||||
|
||||
@ -1707,16 +1721,24 @@ _n_hilt_hind(u3_noun tok, u3_noun pro) // transfer, retain
|
||||
** hin: [hint-atom, formula]. TRANSFER
|
||||
** bus: subject. RETAIN
|
||||
** clu: product of the hint-formula. TRANSFER
|
||||
** also, token for _n_hint_hind();
|
||||
** conventionally, [hint-atom] or [hint-atom data]. ~ if unused.
|
||||
** also, token for _n_hilt_hind(); convention:
|
||||
** [hint-atom] or [hint-atom data], ~ if unused.
|
||||
**
|
||||
** any hints herein must be whitelisted in _n_burn().
|
||||
*/
|
||||
static c3_o
|
||||
_n_hint_fore(u3_cell hin, u3_noun bus, u3_noun* clu)
|
||||
{
|
||||
u3z(hin); u3z(*clu);
|
||||
*clu = u3_nul;
|
||||
if ( c3__bout == u3h(hin) ) {
|
||||
u3_atom now = u3i_chub(u3t_trace_time());
|
||||
*clu = u3i_trel(u3h(hin), *clu, now);
|
||||
}
|
||||
else {
|
||||
u3z(*clu);
|
||||
*clu = u3_nul;
|
||||
}
|
||||
|
||||
u3z(hin);
|
||||
return c3y;
|
||||
}
|
||||
|
||||
@ -1727,7 +1749,43 @@ _n_hint_fore(u3_cell hin, u3_noun bus, u3_noun* clu)
|
||||
static void
|
||||
_n_hint_hind(u3_noun tok, u3_noun pro)
|
||||
{
|
||||
c3_assert( u3_nul == tok );
|
||||
u3_noun p_tok, q_tok, r_tok;
|
||||
if ( (c3y == u3r_trel(tok, &p_tok, &q_tok, &r_tok))
|
||||
&& (c3__bout == p_tok) )
|
||||
{
|
||||
// get the microseconds elapsed
|
||||
u3_atom delta = u3ka_sub(u3i_chub(u3t_trace_time()), u3k(r_tok));
|
||||
|
||||
// unpack q_tok to get the priority integer and the tank
|
||||
// p_q_tok is the priority, q_q_tok is the tank we will work with
|
||||
u3_noun p_q_tok, q_q_tok;
|
||||
c3_assert(c3y == u3r_cell(q_tok, &p_q_tok, &q_q_tok));
|
||||
|
||||
// format the timing report
|
||||
c3_c str_c[64];
|
||||
snprintf(str_c, 63, "took %" PRIu64 "\xc2\xb5s", u3r_chub(0, delta) );
|
||||
|
||||
// join the timing report with the original tank from q_q_tok like so:
|
||||
// "q_q_tok: report"
|
||||
// prepend the priority to form a cell of the same shape q_tok
|
||||
// send this to ut3_slog so that it can be logged out
|
||||
u3t_slog(
|
||||
u3nc(
|
||||
u3k(p_q_tok),
|
||||
u3nt(
|
||||
c3__rose,
|
||||
u3nt(u3nt(':', ' ', u3_nul), u3_nul, u3_nul),
|
||||
u3nt(u3k(q_q_tok), u3i_string(str_c), u3_nul)
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
u3z(delta);
|
||||
}
|
||||
else {
|
||||
c3_assert( u3_nul == tok );
|
||||
}
|
||||
|
||||
u3z(tok);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user