Merge branch 'test' of https://github.com/urbit/urbit into test

This commit is contained in:
Philip C Monk 2014-11-19 21:30:39 -05:00
commit 2fa60f4ec4
13 changed files with 239 additions and 81 deletions

View File

@ -33,7 +33,11 @@
/* u3a_minimum: minimum number of words in a box.
*/
#ifdef U3_MEMORY_DEBUG
# define u3a_minimum 8
#else
# define u3a_minimum 6
#endif
/* u3a_fbox_no: number of free lists per size.
*/
@ -352,6 +356,11 @@
c3_w
u3a_mark_ptr(void* ptr_v);
/* u3a_mark_mptr(): mark a u3_malloc-allocated ptr for gc.
*/
c3_w
u3a_mark_mptr(void* ptr_v);
/* u3a_mark_noun(): mark a noun for gc. Produce size.
*/
c3_w

View File

@ -68,9 +68,9 @@
void
u3e_save(void);
/* u3e_live(): start the persistence system.
/* u3e_live(): start the persistence system. Return c3y if no image.
*/
void
c3_o
u3e_live(c3_o nuu_o, c3_c* dir_c);
/* u3e_boot(): start the u3 system.

View File

@ -313,7 +313,7 @@
c3_c* pax_c; // absolute path
struct _u3_udir* par_u; // in directory
c3_c* dot_c; // extension point or 0
mpz_t mod_mp; // mtime as @da
c3_w mod_w[4]; // mtime
struct _u3_ufil* nex_u; // internal list
} u3_ufil;
@ -334,7 +334,7 @@
*/
typedef struct _u3_uhot {
u3_udir dir_u; // root directory
mpz_t who_mp; // owner as GMP
c3_w who_w[4]; // owner as words
struct _u3_uhot* nex_u; // internal list
} u3_uhot;

View File

@ -74,7 +74,7 @@ static u3j_harm _mood__hoon__by_has_a[] = {{".2", u3wdb_has, c3y}, {}};
static u3j_harm _mood__hoon__by_int_a[] = {{".2", u3wdb_int, c3y}, {}};
static u3j_harm _mood__hoon__by_put_a[] = {{".2", u3wdb_put, c3y}, {}};
static u3j_harm _mood__hoon__by_tap_a[] = {{".2", u3wdb_tap, c3y}, {}};
static u3j_harm _mood__hoon__by_uni_a[] = {{".2", u3wdb_uni, c3y}, {}};
// static u3j_harm _mood__hoon__by_uni_a[] = {{".2", u3wdb_uni, c3y}, {}};
static u3j_core _mood__hoon__by_d[] =
{ { "gas", _mood__hoon__by_gas_a },
{ "get", _mood__hoon__by_get_a },
@ -82,7 +82,7 @@ static u3j_core _mood__hoon__by_d[] =
{ "int", _mood__hoon__by_int_a },
{ "put", _mood__hoon__by_put_a },
{ "tap", _mood__hoon__by_tap_a },
{ "uni", _mood__hoon__by_uni_a },
// { "uni", _mood__hoon__by_uni_a },
{}
};
@ -92,7 +92,7 @@ static u3j_harm _mood__hoon__in_mer_a[] = {{".2", u3wdi_mer}, {}};
static u3j_harm _mood__hoon__in_int_a[] = {{".2", u3wdi_int}, {}};
static u3j_harm _mood__hoon__in_put_a[] = {{".2", u3wdi_put}, {}};
static u3j_harm _mood__hoon__in_tap_a[] = {{".2", u3wdi_tap}, {}};
static u3j_harm _mood__hoon__in_uni_a[] = {{".2", u3wdi_uni}, {}};
// static u3j_harm _mood__hoon__in_uni_a[] = {{".2", u3wdi_uni}, {}};
static u3j_core _mood__hoon__in_d[] =
{ { "gas", _mood__hoon__in_gas_a },
{ "has", _mood__hoon__in_has_a },
@ -100,7 +100,7 @@ static u3j_core _mood__hoon__in_d[] =
{ "int", _mood__hoon__in_int_a },
{ "put", _mood__hoon__in_put_a },
{ "tap", _mood__hoon__in_tap_a },
{ "uni", _mood__hoon__in_uni_a },
// { "uni", _mood__hoon__in_uni_a },
{}
};

77
n/a.c
View File

@ -236,10 +236,10 @@ u3a_sane(void)
}
#endif
/* _ca_walloc(): u3a_walloc() internals.
/* _ca_willoc(): u3a_walloc() internals.
*/
static void*
_ca_walloc(c3_w len_w, c3_w ald_w, c3_w alp_w)
_ca_willoc(c3_w len_w, c3_w ald_w, c3_w alp_w)
{
c3_w siz_w = c3_max(u3a_minimum, u3a_boxed(len_w));
c3_w sel_w = _box_slot(siz_w);
@ -331,6 +331,25 @@ _ca_walloc(c3_w len_w, c3_w ald_w, c3_w alp_w)
}
}
/* _ca_walloc(): u3a_walloc() internals.
*/
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);
#if 0
if ( u3a_botox(ptr_v) == (u3a_box*)(void *)0x27f50a02c ) {
static int xuc_i;
printf("xuc_i %d\r\n", xuc_i);
// if ( 2 == xuc_i ) { abort(); }
xuc_i++;
}
#endif
return ptr_v;
}
int FOO;
/* u3a_walloc(): allocate storage words on hat.
@ -503,7 +522,17 @@ u3a_malloc(size_t len_i)
c3_w pad_w = _me_align_pad(ptr_p, 4, 3);
c3_w* out_w = u3a_into(ptr_p + pad_w + 1);
#if 1
if ( u3a_botox(out_w) == (u3a_box*)(void *)0x202320b88) {
static int xuc_i;
printf("xuc_i %d\r\n", xuc_i);
// if ( 1 == xuc_i ) { abort(); }
xuc_i++;
}
#endif
out_w[-1] = pad_w;
return out_w;
}
@ -868,6 +897,10 @@ _me_copy_south(u3_noun dog)
// printf("south: cell %p to %p\r\n", old_u, new_u);
if ( old_u->mug_w == 0x730e66cc ) {
fprintf(stderr, "BAD: take %p\r\n", new_u);
}
new_u->mug_w = old_u->mug_w;
// new_u->mug_w = 0;
new_u->hed = _me_copy_south_in(old_u->hed);
@ -1219,6 +1252,19 @@ u3a_mark_ptr(void* ptr_v)
}
}
/* u3a_mark_mptr(): mark a malloc-allocated ptr for gc.
*/
c3_w
u3a_mark_mptr(void* ptr_v)
{
c3_w* ptr_w = ptr_v;
c3_w pad_w = ptr_w[-1];
c3_w* org_w = ptr_w - (pad_w + 1);
// printf("free %p %p\r\n", org_w, ptr_w);
return u3a_mark_ptr(org_w);
}
/* u3a_mark_noun(): mark a noun for gc. Produce size.
*/
c3_w
@ -1327,22 +1373,24 @@ u3a_sweep(c3_c* cap_c)
printf("dank %p (%d, %d)\r\n", box_u, box_u->use_w, box_u->eus_w);
}
else {
printf("weak %p %x (%d, %d)\r\n",
printf("weak %p %x (cell) %x (%d, %d)\r\n",
box_u,
(u3_noun)u3a_to_pom(u3a_outa(u3a_boxto(box_w))),
((u3a_noun *)(u3a_boxto(box_w)))->mug_w,
box_u->use_w, box_u->eus_w);
// u3m_p("weak", u3a_to_pom(u3a_outa(u3a_boxto(box_w))));
u3m_p("weak", u3a_to_pom(u3a_outa(u3a_boxto(box_w))));
}
weq_w += box_u->siz_w;
}
else {
printf("leak %p %x (%d)\r\n",
printf("leak %p %x (cell)/%x (%d)\r\n",
box_u,
(u3_noun)u3a_to_pom(u3a_outa(u3a_boxto(box_w))),
((u3a_noun *)(u3a_boxto(box_w)))->mug_w
? ((u3a_noun *)(u3a_boxto(box_w)))->mug_w
: u3r_mug(u3a_to_pom(u3a_outa(u3a_boxto(box_w)))),
box_u->use_w);
// u3m_p("leak", u3a_to_pom(u3a_outa(u3a_boxto(box_w))));
u3m_p("leak", u3a_to_pom(u3a_outa(u3a_boxto(box_w))));
leq_w += box_u->siz_w;
}
if ( box_u->cod_w ) {
@ -1574,6 +1622,21 @@ u3a_lush(c3_w lab_w)
void
u3a_lop(c3_w lab_w)
{
u3_Code = 0;
u3_Code = lab_w;
}
#else
/* u3a_lush(): leak push.
*/
c3_w
u3a_lush(c3_w lab_w)
{
return 0;
}
/* u3a_lop(): leak pop.
*/
void
u3a_lop(c3_w lab_w)
{
}
#endif

5
n/e.c
View File

@ -807,7 +807,7 @@ u3e_save(void)
/* u3e_live(): start the persistence system.
*/
void
c3_o
u3e_live(c3_o nuu_o, c3_c* dir_c)
{
u3P.dir_c = dir_c;
@ -834,7 +834,7 @@ u3e_live(c3_o nuu_o, c3_c* dir_c)
(c3n == _ce_image_open(&u3P.sou_u, c3n)) )
{
fprintf(stderr, "boot: no image\r\n");
exit(1);
return u3e_live(c3y, dir_c);
}
}
@ -879,4 +879,5 @@ u3e_live(c3_o nuu_o, c3_c* dir_c)
nuu_o = c3y;
}
}
return nuu_o;
}

10
n/i.c
View File

@ -192,6 +192,8 @@ u3i_vint(u3_noun a)
}
}
c3_w BAD;
/* u3i_cell():
**
** Produce the cell `[a b]`.
@ -216,9 +218,13 @@ u3i_cell(u3_noun a, u3_noun b)
pro = u3a_to_pom(u3a_outa(nov_w));
#if 0
if ( 0x15d47649 == u3r_mug(pro) ) {
fprintf(stderr, "BAD %x\r\n", pro);
if ( (0x730e66cc == u3r_mug(pro)) &&
(c3__tssg == u3h(u3t(u3t(pro)))) ) {
static c3_w xuc_w;
fprintf(stderr, "BAD %x %p\r\n", pro, u3a_to_ptr(a));
BAD = pro;
if ( xuc_w == 1 ) u3m_bail(c3__exit);
xuc_w++;
}
#endif
#if 1

2
n/m.c
View File

@ -1411,7 +1411,7 @@ u3m_boot(c3_o nuu_o, c3_o bug_o, c3_c* dir_c)
/* Activate the storage system.
*/
u3e_live(nuu_o, dir_c);
nuu_o = u3e_live(nuu_o, dir_c);
/* Construct or activate the allocator.
*/

6
n/v.c
View File

@ -222,9 +222,9 @@ _cv_nock_poke(u3_noun ovo)
}
#endif
// u3_leak_on(1);
u3a_lush(u3h(u3t(ovo)));
pro = u3n_slam_on(fun, sam);
// u3_leak_off;
u3a_lop(0);
#if 0
{
@ -497,7 +497,7 @@ _cv_mark_ova(u3p(u3v_cart) egg_p)
while ( egg_p ) {
u3v_cart* egg_u = u3to(u3v_cart, egg_p);
u3a_mark_ptr(egg_u);
u3a_mark_mptr(egg_u);
u3a_mark_noun(egg_u->vir);
egg_p = egg_u->nex_p;

View File

@ -167,13 +167,35 @@ u3_loop_signal_memory()
static void
_lo_init()
{
c3_l cod_l;
cod_l = u3a_lush(c3__unix);
u3_unix_io_init();
u3a_lop(cod_l);
cod_l = u3a_lush(c3__ames);
u3_ames_io_init();
u3a_lop(cod_l);
cod_l = u3a_lush(c3__term);
u3_term_io_init();
u3a_lop(cod_l);
cod_l = u3a_lush(c3__http);
u3_http_io_init();
u3a_lop(cod_l);
cod_l = u3a_lush(c3__cttp);
u3_cttp_io_init();
u3a_lop(cod_l);
cod_l = u3a_lush(c3__save);
u3_save_io_init();
u3a_lop(cod_l);
cod_l = u3a_lush(c3__temp);
u3_temp_io_init();
u3a_lop(cod_l);
}
/* _lo_talk(): bring up listeners across the process.
@ -181,10 +203,23 @@ _lo_init()
static void
_lo_talk()
{
c3_l cod_l;
cod_l = u3a_lush(c3__unix);
u3_unix_io_talk();
u3a_lop(cod_l);
cod_l = u3a_lush(c3__ames);
u3_ames_io_talk();
u3a_lop(cod_l);
cod_l = u3a_lush(c3__http);
u3_http_io_talk();
u3a_lop(cod_l);
cod_l = u3a_lush(c3__term);
u3_term_io_talk();
u3a_lop(cod_l);
}
/* u3_lo_exit(): terminate I/O across the process.
@ -192,13 +227,35 @@ _lo_talk()
void
u3_lo_exit(void)
{
c3_l cod_l;
cod_l = u3a_lush(c3__unix);
u3_unix_io_exit();
u3a_lop(cod_l);
cod_l = u3a_lush(c3__ames);
u3_ames_io_exit();
u3a_lop(cod_l);
cod_l = u3a_lush(c3__term);
u3_term_io_exit();
u3a_lop(cod_l);
cod_l = u3a_lush(c3__http);
u3_http_io_exit();
u3a_lop(cod_l);
cod_l = u3a_lush(c3__cttp);
u3_cttp_io_exit();
u3a_lop(cod_l);
cod_l = u3a_lush(c3__save);
u3_save_io_exit();
u3a_lop(cod_l);
cod_l = u3a_lush(c3__temp);
u3_temp_io_exit();
u3a_lop(cod_l);
}
/* _lo_poll(): reset event flags across the process.
@ -206,12 +263,31 @@ u3_lo_exit(void)
static void
_lo_poll(void)
{
c3_l cod_l;
cod_l = u3a_lush(c3__ames);
u3_ames_io_poll();
u3a_lop(cod_l);
cod_l = u3a_lush(c3__http);
u3_http_io_poll();
u3a_lop(cod_l);
cod_l = u3a_lush(c3__term);
u3_term_io_poll();
u3a_lop(cod_l);
cod_l = u3a_lush(c3__save);
u3_save_io_poll();
u3a_lop(cod_l);
cod_l = u3a_lush(c3__unix);
u3_unix_io_poll();
u3a_lop(cod_l);
cod_l = u3a_lush(c3__temp);
u3_temp_io_poll();
u3a_lop(cod_l);
}
#if 0

View File

@ -1509,6 +1509,7 @@ _raft_lame(u3_noun ovo, u3_noun why, u3_noun tan)
u3z(ovo);
gon = u3m_soft(0, u3v_poke, u3k(bov));
if ( u3_blip == u3h(gon) ) {
_raft_sure(bov, u3k(u3h(u3t(gon))), u3k(u3t(u3t(gon))));
@ -1684,6 +1685,8 @@ _raft_kick_all(u3_noun vir)
}
}
int FOO;
/* u3_raft_work(): work.
*/
void

112
v/unix.c
View File

@ -20,6 +20,39 @@
#include "all.h"
#include "v/vere.h"
/* _unix_ship_in(): c3_w[4] to ship.
*/
static u3_noun
_unix_ship_in(c3_w* who_w)
{
return u3i_words(4, who_w);
}
/* _unix_ship_out(): ship to c3_w[4]. RETAIN.
*/
static void
_unix_ship_out(u3_noun own, c3_w* who_w)
{
u3r_words(0, 4, who_w, own);
{
u3_noun inn = _unix_ship_in(who_w);
c3_assert(_(u3r_sing(inn, own)));
u3z(inn);
}
}
/* _unix_ship_sing(): yes iff two ships are identical.
*/
static c3_o
_unix_ship_sing(c3_w* one_w, c3_w* two_w)
{
return __((one_w[0] == two_w[0]) &&
(one_w[1] == two_w[1]) &&
(one_w[2] == two_w[2]) &&
(one_w[3] == two_w[3]));
}
/* _unix_down(): descend path.
*/
static c3_c*
@ -216,7 +249,7 @@ static void
_unix_file_watch(u3_ufil* fil_u,
u3_udir* dir_u,
c3_c* pax_c,
mpz_t mod_mp)
c3_w* mod_w)
{
// (1) build data structure
//
@ -232,7 +265,8 @@ _unix_file_watch(u3_ufil* fil_u,
: 0;
}
fil_u->par_u = dir_u;
mpz_init_set(fil_u->mod_mp, mod_mp);
fil_u->mod_w[0] = mod_w[0]; fil_u->mod_w[1] = mod_w[1];
fil_u->mod_w[2] = mod_w[2]; fil_u->mod_w[3] = mod_w[3];
fil_u->nex_u = 0;
c3_assert(!fil_u->dot_c || (fil_u->dot_c > fil_u->pax_c));
@ -360,7 +394,6 @@ _unix_file_done(uv_handle_t* was_u)
// uL(fprintf(uH, "file: dun: %s\n", fil_u->pax_c));
free(fil_u->pax_c);
mpz_clear(fil_u->mod_mp);
free(fil_u);
}
@ -428,23 +461,6 @@ _unix_dir_free(u3_udir* dir_u)
uv_close((uv_handle_t*)&dir_u->was_u, _unix_dir_done);
}
#if 0
/* _unix_file_update(): update file, true if plausibly changed.
*/
static u3_noun
_unix_file_update(u3_ufil* fil_u, mpz_t mod_mp)
{
if ( 0 == mpz_cmp(mod_mp, fil_u->mod_mp) ) {
return c3n;
} else {
mpz_clear(fil_u->mod_mp);
mpz_init_set(fil_u->mod_mp, mod_mp);
return c3y;
}
}
#endif
/* _unix_dir_update(): update directory.
*/
static void
@ -537,7 +553,7 @@ _unix_dir_update(u3_udir* dir_u, DIR* rid_u)
}
else {
if ( !S_ISDIR(buf_u.st_mode) ) {
mpz_t mod_mp;
c3_w mod_w[4];
u3_ufil* fil_u;
if ( ( NULL == strrchr(out_u->d_name, '.')) ||
@ -549,7 +565,7 @@ _unix_dir_update(u3_udir* dir_u, DIR* rid_u)
{
u3_noun mod = c3_stat_mtime(&buf_u);
u3r_mp(mod_mp, mod);
u3r_words(0, 4, mod_w, mod);
u3z(mod);
}
for ( fil_u = dir_u->fil_u; fil_u; fil_u = fil_u->nex_u ) {
@ -561,12 +577,11 @@ _unix_dir_update(u3_udir* dir_u, DIR* rid_u)
fil_u = c3_malloc(sizeof(u3_ufil));
// uL(fprintf(uH, "found file %s\n", pax_c));
_unix_file_watch(fil_u, dir_u, pax_c, mod_mp);
_unix_file_watch(fil_u, dir_u, pax_c, mod_w);
fil_u->nex_u = dir_u->fil_u;
dir_u->fil_u = fil_u;
}
mpz_clear(mod_mp);
}
else {
u3_udir* dis_u;
@ -993,18 +1008,10 @@ _unix_ship_update(u3_uhot* hot_u)
if ( c3n == dir_u->dry ) {
DIR* rid_u = _unix_opendir(dir_u->pax_c);
u3_udir* dis_u;
u3_noun who, hox;
u3_noun who = _unix_ship_in(hot_u->who_w);
u3_noun hox = u3dc("scot", 'p', u3k(who));
_unix_dir_update(dir_u, rid_u);
{
mpz_t who_mp;
mpz_init_set(who_mp, hot_u->who_mp);
who = u3i_mp(who_mp);
hox = u3dc("scot", 'p', u3k(who));
}
for ( dis_u = dir_u->dis_u; dis_u; dis_u = dis_u->nex_u ) {
u3_noun syd = _unix_dir_name(dis_u);
@ -1040,6 +1047,7 @@ _unix_hot_gain(u3_noun who, u3_noun mek)
} else closedir(rid_u);
// uL(fprintf(uH, "GAIN %s\n", pax_c));
free(hox_c);
u3z(hox);
u3_unix_acquire(pax_c);
@ -1048,8 +1056,7 @@ _unix_hot_gain(u3_noun who, u3_noun mek)
u3_uhot* hot_u = c3_malloc(sizeof(u3_uhot));
_unix_dir_watch(&hot_u->dir_u, 0, pax_c);
u3r_mp(hot_u->who_mp, who);
_unix_ship_out(who, hot_u->who_w);
u3z(who);
hot_u->nex_u = u3_Host.unx_u.hot_u;
@ -1091,16 +1098,15 @@ _unix_home(u3_noun who)
{
u3_unix* unx_u = &u3_Host.unx_u;
u3_uhot* hot_u;
mpz_t who_mp;
c3_w who_w[4];
u3r_mp(who_mp, who);
_unix_ship_out(who, who_w);
for ( hot_u = unx_u->hot_u;
hot_u && (0 != mpz_cmp(who_mp, hot_u->who_mp));
hot_u && _(_unix_ship_sing(who_w, hot_u->who_w));
hot_u = hot_u->nex_u )
{
// uL(fprintf(uH, "uh: %p, %s\n", hot_u, hot_u->dir_u.pax_c));
}
mpz_clear(who_mp);
return hot_u;
}
@ -1198,17 +1204,15 @@ _unix_desk_sync_tofu(u3_udir* dir_u,
(*fil_u)->dot_c = (pax_c + ((*fil_u)->dot_c - (*fil_u)->pax_c));
(*fil_u)->pax_c = pax_c;
mpz_clear((*fil_u)->mod_mp);
u3r_mp((*fil_u)->mod_mp, u3A->now);
u3r_words(0, 4, (*fil_u)->mod_w, u3A->now);
}
else {
mpz_t mod_mp;
c3_w mod_w[4];
u3r_mp(mod_mp, u3A->now);
u3r_words(0, 4, mod_w, u3A->now);
*fil_u = c3_malloc(sizeof(u3_ufil));
_unix_file_watch(*fil_u, dir_u, pax_c, mod_mp);
mpz_clear(mod_mp);
_unix_file_watch(*fil_u, dir_u, pax_c, mod_w);
}
}
u3z(pre); u3z(ext); u3z(mis);
@ -1361,14 +1365,13 @@ u3_unix_ef_look(void)
{
for ( won = u3A->own; u3_nul != won; won = u3t(won) ) {
u3_noun who = u3h(won);
mpz_t who_mp;
c3_w who_w[4];
u3r_mp(who_mp, who);
_unix_ship_out(who, who_w);
for ( hot_u = unx_u->hot_u;
hot_u && (0 != mpz_cmp(who_mp, hot_u->who_mp));
hot_u && !_(_unix_ship_sing(who_w, hot_u->who_w));
hot_u = hot_u->nex_u );
mpz_clear(who_mp);
if ( 0 == hot_u ) {
_unix_hot_gain(u3k(who), c3n);
}
@ -1382,13 +1385,10 @@ u3_unix_ef_look(void)
while ( 0 != (hot_u=*het_u) ) {
for ( won = u3A->own; u3_nul != won; won = u3t(won) ) {
u3_noun who = u3h(won);
mpz_t who_mp;
c3_w cmp_w;
c3_w who_w[4];
u3r_mp(who_mp, who);
cmp_w = mpz_cmp(who_mp, hot_u->who_mp);
mpz_clear(who_mp);
if ( 0 == cmp_w ) {
_unix_ship_out(who, who_w);
if ( _(_unix_ship_sing(who_w, hot_u->who_w)) ) {
break;
}
}