Closer to running a jet.

This commit is contained in:
C. Guy Yarvin 2014-09-06 15:39:28 -07:00
parent 2578107992
commit af5128c851
11 changed files with 272 additions and 263 deletions

View File

@ -37,6 +37,7 @@ CXXFLAGS=$(CFLAGS)
CLD=g++ -L/usr/local/lib -L/opt/local/lib
ifeq ($(OS),osx)
COSFLAGS=-fno-diagnostics-fixit-info
CLDOSFLAGS=-bind_at_load
OSLIBS=-framework CoreServices -framework CoreFoundation
endif
@ -48,16 +49,8 @@ ifeq ($(OS),bsd)
OSLIBS=-lpthread -lncurses -lkvm
endif
ifeq ($(STATIC),yes)
LIBS=-lssl -lcrypto -lncurses /usr/local/lib/libsigsegv.a /usr/local/lib/libgmp.a $(OSLIBS)
else
LIBS=-lssl -lcrypto -lgmp -lncurses -lsigsegv $(OSLIBS)
endif
INCLUDE=include
MDEFINES=-DU2_OS_$(OS) -DU2_OS_ENDIAN_$(ENDIAN) -D U2_LIB=\"$(LIB)\"
CFLAGS= -g -msse3 -ffast-math \
CFLAGS= $(COSFLAGS) \
-g -msse3 -ffast-math \
-funsigned-char \
-I/usr/local/include \
-I/opt/local/include \
@ -71,6 +64,15 @@ CFLAGS= -g -msse3 -ffast-math \
$(DEFINES) \
$(MDEFINES)
ifeq ($(STATIC),yes)
LIBS=-lssl -lcrypto -lncurses /usr/local/lib/libsigsegv.a /usr/local/lib/libgmp.a $(OSLIBS)
else
LIBS=-lssl -lcrypto -lgmp -lncurses -lsigsegv $(OSLIBS)
endif
INCLUDE=include
MDEFINES=-DU2_OS_$(OS) -DU2_OS_ENDIAN_$(ENDIAN) -D U2_LIB=\"$(LIB)\"
CWFLAGS=-Wall
.c.o:

View File

@ -23,3 +23,9 @@
*/
extern u3_cs_dash u3_Dash;
# define u3D u3_Dash
/* u3_Code: memory code.
*/
#ifdef U3_MEMORY_DEBUG
c3_global c3_w u3_Code;
#endif

View File

@ -22,7 +22,7 @@
typedef struct _u3_cs_box {
c3_w siz_w; // size of this box
c3_w use_w; // reference count; free if 0
# ifdef U2_MEMORY_DEBUG
# ifdef U3_MEMORY_DEBUG
c3_w cod_w; // tracing code
# endif
} u3_cs_box;

View File

@ -1,4 +1,4 @@
/* include/f/tune.h
/* include/n/tune.h
**
** This file is in the public domain.
*/
@ -6,9 +6,8 @@
**/
# define u3_cc_fbox_no 28
# undef U2_MEMORY_DEBUG
# ifdef U2_MEMORY_DEBUG
# define u3_leak_on(x) (COD_w = x)
extern c3_w COD_w;
# define u3_leak_off (COD_w = 0)
# define U3_MEMORY_DEBUG
# ifdef U3_MEMORY_DEBUG
# define u3_leak_on(x) (u2_Code = x)
# define u3_leak_off (u2_Code = 0)
# endif

View File

@ -85,11 +85,11 @@
u3_atom b,
u3_noun l)
{
u3_noun c = u3_ch_get(har_u, u3k(a));
u3_noun c = u3_ch_get(har_u, a);
u3_noun x;
if ( u3_none == c ) {
u3_ch_put(har_u, u3k(a), u3k(b));
u3_ch_put(har_u, a, u3k(b));
if ( u3_yes == u3ud(a) ) {
x = _jam_in_flat(har_u, a, l);

6
n/a.c
View File

@ -40,8 +40,8 @@ _box_make(void* box_v, c3_w siz_w, c3_w use_w)
box_w[siz_w - 1] = siz_w;
box_u->use_w = use_w;
# ifdef U2_MEMORY_DEBUG
box_u->cod_w = COD_w;
# ifdef U3_MEMORY_DEBUG
box_u->cod_w = u3_Code;
# endif
return box_u;
@ -212,7 +212,7 @@ u3_ca_walloc(c3_w len_w)
box_u->use_w = 1;
#ifdef U2_MEMORY_DEBUG
box_u->cod_w = COD_w;
box_u->cod_w = u3_Code;
#endif
return u3_co_boxto(box_u);
}

4
n/h.c
View File

@ -179,6 +179,8 @@ _ch_some_add(void* han_v, c3_w lef_w, c3_w rem_w, u3_noun kev)
}
/* u3_ch_put(): insert in hashtable.
**
** `key` is RETAINED; `val` is transferred.
*/
void
u3_ch_put(u3_ch_root* har_u, u3_noun key, u3_noun val)
@ -266,6 +268,8 @@ _ch_node_get(u3_ch_node* han_u, c3_w lef_w, c3_w rem_w, u3_noun key)
}
/* u3_ch_get(): read from hashtable.
**
** `key` is RETAINED.
*/
u3_weak
u3_ch_get(u3_ch_root* har_u, u3_noun key)

30
n/j.c
View File

@ -12,11 +12,15 @@
c3_w len_l = 0;
c3_w i_w;
for ( i_w = 0; 0 != dev_u[len_l].cos_c; i_w++ ) {
u3_cs_core* kid_u = &dev_u[i_w];
if ( dev_u ) {
for ( i_w = 0; 0 != dev_u[i_w].cos_c; i_w++ ) {
u3_cs_core* kid_u = &dev_u[i_w];
kid_u->par_u = par_u;
len_l = _cj_count(kid_u, kid_u->dev_u);
kid_u->par_u = par_u;
if ( kid_u->dev_u ) {
len_l = _cj_count(kid_u, kid_u->dev_u);
}
}
}
return 1 + len_l;
}
@ -27,27 +31,33 @@
{
c3_w i_w;
for ( i_w = 0; 0 != dev_u[i_w].cos_c; i_w++ ) {
u3_cs_core* kid_u = &dev_u[i_w];
if ( dev_u ) {
for ( i_w = 0; 0 != dev_u[i_w].cos_c; i_w++ ) {
u3_cs_core* kid_u = &dev_u[i_w];
kid_u->jax_l = jax_l;
ray_u[jax_l++] = *kid_u;
kid_u->jax_l = jax_l;
ray_u[jax_l++] = *kid_u;
jax_l = _cj_install(ray_u, jax_l, kid_u->dev_u);
jax_l = _cj_install(ray_u, jax_l, kid_u->dev_u);
}
}
return jax_l;
}
/* u3_cj_boot(): initialize jet system.
*/
void
u3_cj_boot(void)
{
c3_w jax_l;
u3D.len_l =_cj_count(0, u3D.dev_u);
u3D.ray_u = (u3_cs_core*) malloc(u3D.len_l * sizeof(u3_cs_core));
memset(u3D.ray_u, 0, (u3D.len_l * sizeof(u3_cs_core)));
_cj_install(u3D.ray_u, 1, u3D.dev_u);
jax_l = _cj_install(u3D.ray_u, 1, u3D.dev_u);
printf("boot: installed %d jets\n", jax_l);
}
/* _cj_insert(): append copy of core driver to jet table.

3
n/m.c
View File

@ -136,6 +136,9 @@ u3_cm_dump(void)
u3_cs_box* box_u = (void *)box_w;
if ( 0 != box_u->use_w ) {
#ifdef U3_MEMORY_DEBUG
printf("live %d words, code %x\n", box_u->siz_w, box_u->cod_w);
#endif
mem_w += box_u->siz_w;
}
box_w += box_u->siz_w;

170
n/r.c
View File

@ -1344,3 +1344,173 @@ u3_cr_tape(u3_noun a)
return a_y;
}
#if 0
/* Finalization mix for better avalanching.
*/
static c3_w
_mur_fmix(c3_w h_w)
{
h_w ^= h_w >> 16;
h_w *= 0x85ebca6b;
h_w ^= h_w >> 13;
h_w *= 0xc2b2ae35;
h_w ^= h_w >> 16;
return h_w;
}
/* _mur_words(): raw MurmurHash3 on raw words.
*/
static c3_w
_mur_words(c3_w syd_w, const c3_w* key_w, c3_w len_w)
{
c3_w goc_w = syd_w;
c3_w lig_w = 0xcc9e2d51;
c3_w duf_w = 0x1b873593;
c3_w i_w;
for ( i_w = 0; i_w < len_w; i_w++ ) {
c3_w kop_w = key_w[i_w];
kop_w *= lig_w;
kop_w = c3_rotw(15, kop_w);
kop_w *= duf_w;
goc_w ^= kop_w;
goc_w = c3_rotw(13, goc_w);
goc_w = (goc_w * 5) + 0xe6546b64;
}
goc_w ^= len_w;
goc_w = _mur_fmix(goc_w);
return goc_w;
}
/* u3_mur_words(): 31-bit nonzero MurmurHash3 on raw words.
*/
c3_w
u3_mur_words(const c3_w* key_w, c3_w len_w)
{
c3_w syd_w = 0xcafebabe;
while ( 1 ) {
c3_w haz_w = _mur_words(syd_w, key_w, len_w);
c3_w ham_w = (haz_w >> 31) ^ (haz_w & 0x7fffffff);
if ( 0 != ham_w ) return ham_w;
else syd_w++;
}
}
/* u3_mur_both():
**
** Join two murs.
*/
c3_w
u3_mur_both(c3_w lef_w, c3_w rit_w)
{
c3_w ham_w = lef_w ^ (0x7fffffff ^ rit_w);
return u3_mur_words(&ham_w, (0 == ham_w) ? 0 : 1);
}
/* u3_mur(): MurmurHash3 on a noun.
*/
c3_w
u3_mur(u3_noun veb)
{
if ( u3_fly_is_cat(veb) ) {
return u3_mur_words(&veb, (0 == veb) ? 0 : 1);
}
else {
c3_w mur_w;
if ( (mur_w=*u3_at_dog_mur(veb)) ) {
return mur_w;
}
if ( u3_dog_is_pom(veb) ) {
mur_w = u3_mur_both(u3_mur(u3h(veb)), u3_mur(u3t(veb)));
}
else {
c3_w len_w = u3_met(5, veb);
c3_w* buf_w = malloc(4 * len_w);
u3_words(0, len_w, buf_w, veb);
mur_w = u3_mur_words(buf_w, len_w);
free(buf_w);
}
*u3_at_dog_mur(veb) = mur_w;
return mur_w;
}
}
/* u3_mur_string():
**
** Compute the mur of `a`, LSB first.
*/
c3_w
u3_mur_string(const c3_c *a_c)
{
c3_w len_w = strlen(a_c);
c3_w wor_w = ((len_w + 3) >> 2);
c3_w* buf_w = alloca(4 * wor_w);
c3_w i_w;
for ( i_w = 0; i_w < wor_w; i_w++ ) { buf_w[i_w] = 0; }
for ( i_w = 0; i_w < len_w; i_w++ ) {
c3_w inx_w = (i_w >> 2);
c3_w byt_w = (i_w & 3);
buf_w[inx_w] |= (a_c[i_w] << (8 * byt_w));
}
return u3_mur_words(buf_w, wor_w);
}
/* u3_mur_cell():
**
** Compute the mur of the cell `[hed tel]`.
*/
c3_w
u3_mur_cell(u3_noun hed,
u3_noun tel)
{
c3_w lus_w = u3_mur(hed);
c3_w biq_w = u3_mur(tel);
return u3_mur_both(lus_w, biq_w);
}
/* u3_mur_trel():
**
** Compute the mur of `[a b c]`.
*/
c3_w
u3_mur_trel(u3_noun a,
u3_noun b,
u3_noun c)
{
return u3_mur_both(u3_mur(a), u3_mur_both(u3_mur(b), u3_mur(c)));
}
/* u3_mur_qual():
**
** Compute the mur of `[a b c d]`.
*/
c3_w
u3_mur_qual(u3_noun a,
u3_noun b,
u3_noun c,
u3_noun d)
{
return u3_mur_both(u3_mur(a),
u3_mur_both(u3_mur(b),
u3_mur_both(u3_mur(c), u3_mur(d))));
}
#endif

277
w/test.c
View File

@ -56,68 +56,6 @@ u3_walk_load(c3_c* pas_c)
}
#endif
static void
_road_dump(void)
{
c3_w hat_w;
c3_w fre_w = 0;
c3_w i_w;
hat_w = u3_so(u3_co_is_north) ? u3R->hat_w - u3R->rut_w
: u3R->hat_w - u3R->rut_w;
for ( i_w = 0; i_w < u3_cc_fbox_no; i_w++ ) {
u3_cs_fbox* fre_u = u3R->all.fre_u[i_w];
while ( fre_u ) {
fre_w += fre_u->box_u.siz_w;
fre_u = fre_u->nex_u;
}
}
printf("dump: hat_w %x, fre_w %x, allocated %x\n",
hat_w, fre_w, (hat_w - fre_w));
if ( 0 != (hat_w - fre_w) ) {
c3_w* box_w = u3R->rut_w;
c3_w mem_w = 0;
while ( box_w < u3R->hat_w ) {
u3_cs_box* box_u = (void *)box_w;
if ( 0 != box_u->use_w ) {
mem_w += box_u->siz_w;
}
box_w += box_u->siz_w;
}
printf("second count: %x\n", mem_w);
}
}
static void
_test_jam(void)
{
_road_dump();
{
u3_noun pil = u3_walk_load("urb/urbit.pill");
u3_noun cue, jam;
printf("cueing pill - %d bytes\n", u3_cr_met(3, pil));
cue = u3_cke_cue(pil);
printf("cued - mug %x\n", u3_cr_mug(cue));
#if 1
jam = u3_cke_jam(cue);
printf("jammed - %d bytes\n", u3_cr_met(3, jam));
cue = u3_cke_cue(jam);
printf("cued - mug %x\n", u3_cr_mug(cue));
#endif
u3z(cue);
}
_road_dump();
}
#if 0
static c3_w*
_test_walloc(c3_w siz_w)
@ -199,6 +137,7 @@ test(void)
}
#endif
#if 0
static void
_test_hash(void)
{
@ -231,6 +170,44 @@ _test_hash(void)
}
_road_dump();
}
#endif
#if 0
static void
_test_jam(void)
{
_road_dump();
{
u3_noun pil = u3_walk_load("pill/easy1.pill");
u3_noun cue, jam;
printf("cueing pill - %d bytes\n", u3_cr_met(3, pil));
cue = u3_cke_cue(pil);
printf("cued - mug %x\n", u3_cr_mug(cue));
#if 1
jam = u3_cke_jam(cue);
printf("jammed - %d bytes\n", u3_cr_met(3, jam));
cue = u3_cke_cue(jam);
printf("cued - mug %x\n", u3_cr_mug(cue));
#endif
u3z(cue);
}
_road_dump();
}
#endif
static void
_test_easy1(void)
{
u3_noun cor = u3_cke_cue(u3_walk_load("pill/easy1.pill"));
u3_noun val;
printf("test_easy1: core mug %x\n", u3_cr_mug(cor));
val = u3_cn_slam_on(cor, u3nc(42, 17));
printf("val %d\n", val);
}
// A simple memory tester.
//
@ -242,176 +219,14 @@ main(int argc, char *argv[])
// _test_words();
u3_cm_boot(U2_OS_LoomBase, (1 << U2_OS_LoomBits));
u3_cj_boot();
printf("booted.\n");
_test_hash();
}
#if 0
/* Finalization mix for better avalanching.
*/
static c3_w
_mur_fmix(c3_w h_w)
{
h_w ^= h_w >> 16;
h_w *= 0x85ebca6b;
h_w ^= h_w >> 13;
h_w *= 0xc2b2ae35;
h_w ^= h_w >> 16;
return h_w;
}
/* _mur_words(): raw MurmurHash3 on raw words.
*/
static c3_w
_mur_words(c3_w syd_w, const c3_w* key_w, c3_w len_w)
{
c3_w goc_w = syd_w;
c3_w lig_w = 0xcc9e2d51;
c3_w duf_w = 0x1b873593;
c3_w i_w;
for ( i_w = 0; i_w < len_w; i_w++ ) {
c3_w kop_w = key_w[i_w];
kop_w *= lig_w;
kop_w = c3_rotw(15, kop_w);
kop_w *= duf_w;
goc_w ^= kop_w;
goc_w = c3_rotw(13, goc_w);
goc_w = (goc_w * 5) + 0xe6546b64;
u3_cm_dump();
{
// _test_hash();
// _test_jam();
_test_easy1();
}
goc_w ^= len_w;
goc_w = _mur_fmix(goc_w);
return goc_w;
u3_cm_dump();
}
/* u3_mur_words(): 31-bit nonzero MurmurHash3 on raw words.
*/
c3_w
u3_mur_words(const c3_w* key_w, c3_w len_w)
{
c3_w syd_w = 0xcafebabe;
while ( 1 ) {
c3_w haz_w = _mur_words(syd_w, key_w, len_w);
c3_w ham_w = (haz_w >> 31) ^ (haz_w & 0x7fffffff);
if ( 0 != ham_w ) return ham_w;
else syd_w++;
}
}
/* u3_mur_both():
**
** Join two murs.
*/
c3_w
u3_mur_both(c3_w lef_w, c3_w rit_w)
{
c3_w ham_w = lef_w ^ (0x7fffffff ^ rit_w);
return u3_mur_words(&ham_w, (0 == ham_w) ? 0 : 1);
}
/* u3_mur(): MurmurHash3 on a noun.
*/
c3_w
u3_mur(u3_noun veb)
{
if ( u3_fly_is_cat(veb) ) {
return u3_mur_words(&veb, (0 == veb) ? 0 : 1);
}
else {
c3_w mur_w;
if ( (mur_w=*u3_at_dog_mur(veb)) ) {
return mur_w;
}
if ( u3_dog_is_pom(veb) ) {
mur_w = u3_mur_both(u3_mur(u3h(veb)), u3_mur(u3t(veb)));
}
else {
c3_w len_w = u3_met(5, veb);
c3_w* buf_w = malloc(4 * len_w);
u3_words(0, len_w, buf_w, veb);
mur_w = u3_mur_words(buf_w, len_w);
free(buf_w);
}
*u3_at_dog_mur(veb) = mur_w;
return mur_w;
}
}
/* u3_mur_string():
**
** Compute the mur of `a`, LSB first.
*/
c3_w
u3_mur_string(const c3_c *a_c)
{
c3_w len_w = strlen(a_c);
c3_w wor_w = ((len_w + 3) >> 2);
c3_w* buf_w = alloca(4 * wor_w);
c3_w i_w;
for ( i_w = 0; i_w < wor_w; i_w++ ) { buf_w[i_w] = 0; }
for ( i_w = 0; i_w < len_w; i_w++ ) {
c3_w inx_w = (i_w >> 2);
c3_w byt_w = (i_w & 3);
buf_w[inx_w] |= (a_c[i_w] << (8 * byt_w));
}
return u3_mur_words(buf_w, wor_w);
}
/* u3_mur_cell():
**
** Compute the mur of the cell `[hed tel]`.
*/
c3_w
u3_mur_cell(u3_noun hed,
u3_noun tel)
{
c3_w lus_w = u3_mur(hed);
c3_w biq_w = u3_mur(tel);
return u3_mur_both(lus_w, biq_w);
}
/* u3_mur_trel():
**
** Compute the mur of `[a b c]`.
*/
c3_w
u3_mur_trel(u3_noun a,
u3_noun b,
u3_noun c)
{
return u3_mur_both(u3_mur(a), u3_mur_both(u3_mur(b), u3_mur(c)));
}
/* u3_mur_qual():
**
** Compute the mur of `[a b c d]`.
*/
c3_w
u3_mur_qual(u3_noun a,
u3_noun b,
u3_noun c,
u3_noun d)
{
return u3_mur_both(u3_mur(a),
u3_mur_both(u3_mur(b),
u3_mur_both(u3_mur(c), u3_mur(d))));
}
#endif