This commit is contained in:
Philip C Monk 2014-12-02 20:07:22 -05:00
commit 2e72c44d80
8 changed files with 202 additions and 71 deletions

View File

@ -68,7 +68,6 @@
extern u3j_dash u3j_Dash;
# define u3D u3j_Dash
/** Functions.
**/
/* u3j_boot(): initialize jet system.

52
i/n/t.h
View File

@ -2,8 +2,51 @@
**
** This file is in the public domain.
*/
/** Options.
**/
/* U3_CPU_DEBUG: activate profiling.
*/
# define U3_CPU_DEBUG
/** Data structures.
**/
/* u3t_trace: fast execution flags.
*/
typedef struct _u3t_trace {
c3_o noc_o; // now executing in nock interpreter
c3_o glu_o; // now executing in jet glue
c3_o mal_o; // now executing in allocator
c3_o far_o; // now executing in fragmentor.
} u3t_trace;
/** Macros.
**/
# ifdef U3_CPU_DEBUG
# define u3t_on(var) \
(u3T.var = (u3C.wag_w & u3o_debug_cpu) \
? (c3n == u3T.var) ? c3y : (abort(), 0) \
: u3T.var)
# else
# define u3t_on(var)
#endif
# ifdef U3_CPU_DEBUG
# define u3t_off(var) \
(u3T.var = (u3C.wag_w & u3o_debug_cpu) \
? (c3y == u3T.var) ? c3n : (abort(), 0) \
: u3T.var)
# else
# define u3t_off(var)
#endif
/** Functions.
**/
/* u3t_init(): initialize tracing layer.
*/
void
u3t_init(void);
/* u3t_push(): push on trace stack.
*/
void
@ -58,3 +101,12 @@
*/
void
u3t_boot(void);
/** Globals.
**/
/* u3_Trace / u3C: global memory control.
*/
c3_global u3t_trace u3t_Trace;
# define u3T u3t_Trace

40
n/a.c
View File

@ -4,8 +4,6 @@
*/
#include "all.h"
extern int SAM, SAZ;
/* _box_slot(): select the right free list to search for a block.
*/
c3_w
@ -337,11 +335,12 @@ _ca_willoc(c3_w len_w, c3_w ald_w, c3_w alp_w)
static void*
_ca_walloc(c3_w len_w, c3_w ald_w, c3_w alp_w)
{
void* ptr_v = _ca_willoc(len_w, ald_w, alp_w);
void* ptr_v;
u3t_on(mal_o);
ptr_v = _ca_willoc(len_w, ald_w, alp_w);
u3t_off(mal_o);
if ( SAM ) {
SAZ += len_w;
}
#if 0
if ( SUB ) {
fprintf(stderr, "sub: at %p; kid %p\r\n",
@ -375,14 +374,14 @@ _ca_walloc(c3_w len_w, c3_w ald_w, c3_w alp_w)
return ptr_v;
}
int FOO;
/* u3a_walloc(): allocate storage words on hat.
*/
void*
u3a_walloc(c3_w len_w)
{
void* ptr_v = _ca_walloc(len_w, 1, 0);
void* ptr_v;
ptr_v = _ca_walloc(len_w, 1, 0);
#if 0
if ( (703 == u3_Code) &&
@ -394,9 +393,7 @@ u3a_walloc(c3_w len_w)
u3a_box* box_u = u3a_botox(ptr_v);
box_u->cod_w = 999;
FOO = 1;
}
// if ( 9 == xuc_i ) { FOO = 1; }
xuc_i++;
}
#endif
@ -436,9 +433,14 @@ u3a_wfree(void* tox_v)
u3a_box* box_u = u3a_botox(tox_v);
c3_w* box_w = (c3_w *)(void *)box_u;
u3t_on(mal_o);
c3_assert(box_u->use_w != 0);
box_u->use_w -= 1;
if ( 0 != box_u->use_w ) return;
if ( 0 != box_u->use_w ) {
u3t_off(mal_o);
return;
}
#if 0
/* Clear the contents of the block, for debugging.
@ -512,6 +514,7 @@ u3a_wfree(void* tox_v)
_box_attach(box_u);
}
}
u3t_off(mal_o);
}
#if 0
@ -1179,16 +1182,17 @@ top:
u3_noun
u3a_gain(u3_noun som)
{
// u3t_on(mal_o);
c3_assert(u3_none != som);
if ( _(u3a_is_cat(som)) ) {
return som;
}
else {
return _(u3a_is_north(u3R))
if ( !_(u3a_is_cat(som)) ) {
som = _(u3a_is_north(u3R))
? _me_gain_north(som)
: _me_gain_south(som);
}
// u3t_off(mal_o);
return som;
}
/* u3a_lose(): lose a reference count.
@ -1196,6 +1200,7 @@ u3a_gain(u3_noun som)
void
u3a_lose(u3_noun som)
{
// u3t_on(mal_o);
if ( !_(u3a_is_cat(som)) ) {
if ( _(u3a_is_north(u3R)) ) {
_me_lose_north(som);
@ -1203,6 +1208,7 @@ u3a_lose(u3_noun som)
_me_lose_south(som);
}
}
// u3t_off(mal_o);
}
/* u3a_use(): reference count.

16
n/j.c
View File

@ -578,11 +578,13 @@ u3_weak
u3j_kick(u3_noun cor, u3_noun axe)
{
if ( !_(u3du(cor)) ) { return u3_none; }
u3t_on(glu_o);
{
u3_noun bat = u3h(cor);
u3_weak cax = u3j_find(bat);
if ( u3_none == cax ) { return u3_none; }
if ( u3_none == cax ) { u3t_off(glu_o); return u3_none; }
{
u3_noun mop = u3t(u3h(u3t(cax)));
u3_noun hap = u3h(u3t(u3h(cax)));
@ -590,13 +592,14 @@ u3j_kick(u3_noun cor, u3_noun axe)
u3_noun inx = u3kdb_get(u3k(hap), u3k(axe));
if ( u3_none == inx ) {
u3z(cax); return u3_none;
u3z(cax); u3t_off(glu_o); return u3_none;
}
#if 1
else if ( !_(_cj_fine(cup, mop, cor)) ) {
fprintf(stderr, "improper core %x\r\n", u3r_mug(cor));
u3m_p("improper core for label", u3h(u3t(u3t(u3h(cax)))));
abort();
u3m_p("improper label", u3h(u3t(u3t(u3h(cax)))));
u3t_off(glu_o);
return u3_none;
}
#endif
@ -612,8 +615,9 @@ u3j_kick(u3_noun cor, u3_noun axe)
if ( _(pof_o) ) {
pof_o = u3t_come(bat);
}
u3t_off(glu_o);
pro = _cj_kick_z(cor, cop_u, ham_u, axe);
if ( u3_none == pro ) {
if ( _(pof_o) ) {
pro = u3n_nock_on(cor, u3nq(9, axe, 0, 1));
@ -765,6 +769,7 @@ u3j_mine(u3_noun clu, u3_noun cor)
u3_noun bat = u3h(cor);
u3_noun cax;
u3t_on(glu_o);
if ( !_(u3du(cor)) ) {
u3z(clu);
}
@ -780,6 +785,7 @@ u3j_mine(u3_noun clu, u3_noun cor)
}
}
u3z(cor);
u3t_off(glu_o);
}
/* _cj_cold_reap_to: reap clog map. RETAINS `sab`, TRANSFERS `bas`.

12
n/m.c
View File

@ -808,6 +808,10 @@ u3m_soft_top(c3_w sec_w, // timer seconds
_cm_signal_deep(0);
if ( 0 != (sig_l = sigsetjmp(u3_Signal, 1)) ) {
// reinitialize trace state
//
u3t_init();
// return to blank state
//
_cm_signal_done();
@ -927,6 +931,8 @@ u3m_soft_run(u3_noun fly,
pro = u3nc(0, u3m_love(pro));
}
else {
u3t_init();
/* Produce - or fall again.
*/
{
@ -1011,6 +1017,8 @@ u3m_soft_esc(u3_noun sam)
pro = u3m_love(pro);
}
else {
u3t_init();
/* Push the error back up to the calling context - not the run we
** are in, but the caller of the run, matching pure nock semantics.
*/
@ -1431,6 +1439,10 @@ u3m_boot(c3_o nuu_o, c3_o bug_o, c3_c* dir_c)
*/
nuu_o = u3e_live(nuu_o, dir_c);
/* Activate tracing.
*/
u3t_init();
/* Construct or activate the allocator.
*/
_cm_pave(nuu_o, bug_o);

93
n/n.c
View File

@ -4,15 +4,15 @@
*/
#include "all.h"
extern int FOO;
static u3_noun _n_nock_on(u3_noun bus, u3_noun fol);
/* _cn_hint(): process hint.
/* _n_hint(): process hint.
*/
static u3_noun
_cn_hint(u3_noun zep,
u3_noun hod,
u3_noun bus,
u3_noun nex)
_n_hint(u3_noun zep,
u3_noun hod,
u3_noun bus,
u3_noun nex)
{
switch ( zep ) {
default: {
@ -20,7 +20,7 @@ _cn_hint(u3_noun zep,
u3a_lose(zep);
u3a_lose(hod);
return u3n_nock_on(bus, nex);
return _n_nock_on(bus, nex);
}
case c3__hunk:
@ -40,19 +40,21 @@ _cn_hint(u3_noun zep,
u3t(u3t(u3t(hod))));
}
#endif
pro = u3n_nock_on(bus, nex);
pro = _n_nock_on(bus, nex);
u3t_drop();
return pro;
}
case c3__slog: {
u3t_off(noc_o);
u3t_slog(hod);
return u3n_nock_on(bus, nex);
u3t_on(noc_o);
return _n_nock_on(bus, nex);
}
case c3__germ: {
u3_noun pro = u3n_nock_on(bus, nex);
u3_noun pro = _n_nock_on(bus, nex);
if ( c3y == u3r_sing(pro, hod) ) {
u3z(pro); return hod;
@ -62,16 +64,19 @@ _cn_hint(u3_noun zep,
}
case c3__fast: {
u3_noun pro = u3n_nock_on(bus, nex);
u3_noun pro = _n_nock_on(bus, nex);
u3t_off(noc_o);
u3j_mine(hod, u3k(pro));
u3t_on(noc_o);
return pro;
}
case c3__memo: {
u3z(hod);
#if 0
return u3n_nock_on(bus, nex);
return _n_nock_on(bus, nex);
#else
{
u3_noun pro = u3z_find_2(c3__nock, bus, nex);
@ -80,7 +85,7 @@ _cn_hint(u3_noun zep,
u3z(bus); u3z(nex);
return pro;
}
pro = u3n_nock_on(u3k(bus), u3k(nex));
pro = _n_nock_on(u3k(bus), u3k(nex));
u3z_save_2(c3__nock, bus, nex, pro);
u3z(bus); u3z(nex);
@ -93,7 +98,7 @@ _cn_hint(u3_noun zep,
case c3__sole: {
u3z(hod);
{
u3_noun pro = u3n_nock_on(bus, nex);
u3_noun pro = _n_nock_on(bus, nex);
// return u3z_uniq(pro);
return pro;
@ -102,12 +107,10 @@ _cn_hint(u3_noun zep,
}
}
extern u3_noun BAD;
/* u3n_nock_on(): produce .*(bus fol). Do not virtualize.
/* _n_nock_on(): produce .*(bus fol). Do not virtualize.
*/
u3_noun
u3n_nock_on(u3_noun bus, u3_noun fol)
_n_nock_on(u3_noun bus, u3_noun fol)
{
u3_noun hib, gal;
@ -120,8 +123,8 @@ u3n_nock_on(u3_noun bus, u3_noun fol)
if ( c3y == u3r_du(hib) ) {
u3_noun poz, riv;
poz = u3n_nock_on(u3k(bus), u3k(hib));
riv = u3n_nock_on(bus, u3k(gal));
poz = _n_nock_on(u3k(bus), u3k(hib));
riv = _n_nock_on(bus, u3k(gal));
u3a_lose(fol);
return u3i_cell(poz, riv);
@ -151,8 +154,8 @@ u3n_nock_on(u3_noun bus, u3_noun fol)
c3_assert(!"not reached");
case 2: {
u3_noun nex = u3n_nock_on(u3k(bus), u3k(u3t(gal)));
u3_noun seb = u3n_nock_on(bus, u3k(u3h(gal)));
u3_noun nex = _n_nock_on(u3k(bus), u3k(u3t(gal)));
u3_noun seb = _n_nock_on(bus, u3k(u3h(gal)));
u3a_lose(fol);
bus = seb;
@ -164,7 +167,7 @@ u3n_nock_on(u3_noun bus, u3_noun fol)
case 3: {
u3_noun gof, pro;
gof = u3n_nock_on(bus, u3k(gal));
gof = _n_nock_on(bus, u3k(gal));
pro = u3r_du(gof);
u3a_lose(gof); u3a_lose(fol);
@ -175,7 +178,7 @@ u3n_nock_on(u3_noun bus, u3_noun fol)
case 4: {
u3_noun gof, pro;
gof = u3n_nock_on(bus, u3k(gal));
gof = _n_nock_on(bus, u3k(gal));
pro = u3i_vint(gof);
u3a_lose(fol);
@ -184,7 +187,7 @@ u3n_nock_on(u3_noun bus, u3_noun fol)
c3_assert(!"not reached");
case 5: {
u3_noun wim = u3n_nock_on(bus, u3k(gal));
u3_noun wim = _n_nock_on(bus, u3k(gal));
u3_noun pro = u3r_sing(u3h(wim), u3t(wim));
u3a_lose(wim); u3a_lose(fol);
@ -197,7 +200,7 @@ u3n_nock_on(u3_noun bus, u3_noun fol)
u3x_trel(gal, &b_gal, &c_gal, &d_gal);
{
u3_noun tys = u3n_nock_on(u3k(bus), u3k(b_gal));
u3_noun tys = _n_nock_on(u3k(bus), u3k(b_gal));
u3_noun nex;
if ( 0 == tys ) {
@ -218,7 +221,7 @@ u3n_nock_on(u3_noun bus, u3_noun fol)
u3x_cell(gal, &b_gal, &c_gal);
{
u3_noun bod = u3n_nock_on(bus, u3k(b_gal));
u3_noun bod = _n_nock_on(bus, u3k(b_gal));
u3_noun nex = u3k(c_gal);
u3a_lose(fol);
@ -234,7 +237,7 @@ u3n_nock_on(u3_noun bus, u3_noun fol)
u3x_cell(gal, &b_gal, &c_gal);
{
u3_noun heb = u3n_nock_on(u3k(bus), u3k(b_gal));
u3_noun heb = _n_nock_on(u3k(bus), u3k(b_gal));
u3_noun bod = u3nc(heb, bus);
u3_noun nex = u3k(c_gal);
@ -251,8 +254,12 @@ u3n_nock_on(u3_noun bus, u3_noun fol)
u3x_cell(gal, &b_gal, &c_gal);
{
u3_noun seb = u3n_nock_on(bus, u3k(c_gal));
u3_noun pro = u3j_kick(seb, b_gal);
u3_noun seb = _n_nock_on(bus, u3k(c_gal));
u3_noun pro;
u3t_off(noc_o);
pro = u3j_kick(seb, b_gal);
u3t_on(noc_o);
if ( u3_none != pro ) {
u3a_lose(fol);
@ -288,7 +295,7 @@ u3n_nock_on(u3_noun bus, u3_noun fol)
u3_noun d_gal = q_gal;
zep = u3k(b_gal);
hod = u3n_nock_on(u3k(bus), u3k(c_gal));
hod = _n_nock_on(u3k(bus), u3k(c_gal));
nex = u3k(d_gal);
}
else {
@ -301,13 +308,17 @@ u3n_nock_on(u3_noun bus, u3_noun fol)
}
u3a_lose(fol);
return _cn_hint(zep, hod, bus, nex);
return _n_hint(zep, hod, bus, nex);
}
}
case 11: {
u3_noun gof = u3n_nock_on(bus, u3k(gal));
u3_noun val = u3m_soft_esc(u3k(gof));
u3_noun gof = _n_nock_on(bus, u3k(gal));
u3_noun val;
u3t_off(noc_o);
val = u3m_soft_esc(u3k(gof));
u3t_on(noc_o);
if ( !_(u3du(val)) ) {
u3m_bail(u3nt(1, gof, 0));
@ -328,6 +339,20 @@ u3n_nock_on(u3_noun bus, u3_noun fol)
}
}
/* u3n_nock_on(): produce .*(bus fol). Do not virtualize.
*/
u3_noun
u3n_nock_on(u3_noun bus, u3_noun fol)
{
u3_noun pro;
u3t_on(noc_o);
pro = _n_nock_on(bus, fol);
u3t_off(noc_o);
return pro;
}
/* u3n_kick_on(): fire `gat` without changing the sample.
*/
u3_noun

12
n/r.c
View File

@ -55,21 +55,25 @@ _frag_deep(c3_w a_w, u3_noun b)
** Return fragment (a) of (b), or u3_none if not applicable.
*/
u3_weak
u3r_at(u3_atom a,
u3_noun b)
u3r_at(u3_atom a, u3_noun b)
{
c3_assert(u3_none != a);
c3_assert(u3_none != b);
u3t_on(far_o);
if ( 0 == a ) {
u3t_off(far_o);
return u3_none;
}
if ( _(u3a_is_cat(a)) ) {
u3t_off(far_o);
return _frag_word(a, b);
}
else {
if ( !_(u3a_is_pug(a)) ) {
u3t_off(far_o);
return u3_none;
}
else {
@ -83,11 +87,15 @@ u3r_at(u3_atom a,
b = _frag_deep(a_u->buf_w[len_w - 1], b);
if ( u3_none == b ) {
u3t_off(far_o);
return b;
} else {
len_w--;
}
}
u3t_off(far_o);
return b;
}
}

47
n/t.c
View File

@ -179,24 +179,37 @@ _t_samp_process(u3_road* rod_u)
}
#endif
int SAM;
int SAZ;
/* u3t_samp(): sample.
*/
void
u3t_samp(void)
{
u3C.wag_w &= ~u3o_debug_cpu;
// Profile sampling, because it allocates on the home road,
// only works on when we're not at home.
//
c3_assert(!SAM);
SAM = 1;
SAZ = 0;
if ( &(u3H->rod_u) != u3R ) {
c3_l mot_l;
u3a_road* rod_u;
if ( _(u3T.mal_o) ) {
mot_l = c3_s3('m','a','l');
}
else if ( _(u3T.far_o) ) {
mot_l = c3_s3('f','a','r');
}
else if ( _(u3T.noc_o) ) {
c3_assert(!_(u3T.glu_o));
mot_l = c3_s3('n','o','c');
}
else if ( _(u3T.glu_o) ) {
mot_l = c3_s3('g','l','u');
}
else {
mot_l = c3_s3('f','u','n');
}
rod_u = u3R;
u3R = &(u3H->rod_u);
{
@ -206,11 +219,11 @@ u3t_samp(void)
if ( 0 == u3R->pro.day ) {
u3R->pro.day = u3v_do("doss", 0);
}
u3R->pro.day = u3dc("pi-noon", lab, u3R->pro.day);
u3R->pro.day = u3dt("pi-noon", mot_l, lab, u3R->pro.day);
}
u3R = rod_u;
}
SAM = 0;
u3C.wag_w |= u3o_debug_cpu;
}
/* u3t_come(): push on profile stack; return yes if active push. RETAIN.
@ -263,16 +276,26 @@ void _ct_sigaction(c3_i x_i)
u3t_samp();
}
/* u3t_init(): initialize tracing layer.
*/
void
u3t_init(void)
{
u3T.noc_o = c3n;
u3T.glu_o = c3n;
u3T.mal_o = c3n;
u3T.far_o = c3n;
}
/* u3t_boot(): turn sampling on.
*/
void
u3t_boot(void)
{
if ( u3C.wag_w & u3o_debug_cpu ) {
if ( u3C.wag_w & u3o_debug_cpu ) {
#if defined(U3_OS_osx)
#if 1
{
SAZ = 0;
struct itimerval itm_v;
struct sigaction sig_s;
sigset_t set;