From c8da5efe2bdea0f0b6a0d224339a00692a3f59b5 Mon Sep 17 00:00:00 2001 From: Paul Driver Date: Sun, 10 Jun 2018 10:39:36 -0700 Subject: [PATCH 01/16] first pass at nock 12 impl --- noun/nock.c | 183 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 183 insertions(+) diff --git a/noun/nock.c b/noun/nock.c index 89ebaa4e57..10124cd43e 100644 --- a/noun/nock.c +++ b/noun/nock.c @@ -526,6 +526,23 @@ _n_nock_on(u3_noun bus, u3_noun fol) #define SLIB 70 #define SLIS 71 #define SAVE 72 +// nock 12 +#define MUTH 73 +#define KUTH 74 +#define MUTT 75 +#define KUTT 76 +#define MUSM 77 +#define KUSM 78 +#define MUCS 79 +#define KUCS 80 +#define MUTB 81 +#define MUTS 82 +#define MITB 83 +#define MITS 84 +#define KUTB 85 +#define KUTS 86 +#define KITB 87 +#define KITS 88 /* _n_arg(): return the size (in bytes) of an opcode's argument */ @@ -538,6 +555,7 @@ _n_arg(c3_y cod_y) case SAMB: case SANB: case SBIP: case SBIN: case SLIB: case SKIB: case KICB: case TICB: case BUSH: case BAST: case BALT: + case KITB: case MITB: return sizeof(c3_y); case FASK: case FASL: case FISL: case FISK: @@ -545,6 +563,7 @@ _n_arg(c3_y cod_y) case SAMS: case SANS: case SIPS: case SINS: case SLIS: case SKIS: case KICS: case TICS: case SUSH: case SAST: case SALT: + case KITS: case MITS: return sizeof(c3_s); case SWIP: case SWIN: @@ -657,6 +676,7 @@ _n_melt(u3_noun ops, c3_w* byc_w, c3_w* cal_w, case BUSH: case FIBK: case FIBL: case SANB: case LIBL: case LIBK: + case KITB: case MITB: a_w = (*lit_w)++; if ( a_w <= 0xFF ) { siz_y[i_w] = 2; @@ -885,6 +905,7 @@ _n_prog_asm(u3_noun ops, u3n_prog* pog_u, u3_noun sip) case FIBK: case FIBL: case LIBK: case LIBL: case BUSH: case SANB: + case KITB: case MITB: _n_prog_asm_inx(buf_y, &i_w, lit_s, cod); pog_u->lit_u.non[lit_s++] = u3k(u3t(op)); break; @@ -992,6 +1013,10 @@ static char* opcode_names[] = { "balt", "salt", "skib", "skis", "slib", "slis", "save", + "muth", "kuth", "mutt", "kutt", + "musm", "kusm", "mucs", "kucs", + "mutb", "muts", "mitb", "mits", + "kutb", "kuts", "kitb", "kits", }; #endif @@ -1289,6 +1314,42 @@ _n_comp(u3_noun* ops, u3_noun fol, c3_o los_o, c3_o tel_o) ++tot_w; _n_emit(ops, (c3y == los_o) ? WILS : WISH); break; + case 12: { + u3_noun axe, nef; + u3x_cell(arg, &hed, &tel); + u3x_cell(hed, &axe, &nef); + tot_w += _n_comp(ops, tel, c3n, c3n); + ++tot_w; _n_emit(ops, SWAP); + tot_w += _n_comp(ops, nef, c3n, c3n); + + ++tot_w; + switch ( axe ) { + case 2: + _n_emit(ops, (c3y == los_o) ? MUTH : KUTH); + break; + + case 3: + _n_emit(ops, (c3y == los_o) ? MUTT : KUTT); + break; + + case u3x_sam: + _n_emit(ops, (c3y == los_o) ? MUSM : KUSM); + break; + + case u3x_con_sam: + _n_emit(ops, (c3y == los_o) ? MUCS : KUCS); + break; + + default: + op_y = (c3y == los_o) + ? (axe <= 0xFF) ? MUTB : (axe <= 0xFFFF) ? MUTS : MITB // overflows to MITL + : (axe <= 0xFF) ? KUTB : (axe <= 0xFFFF) ? KUTS : KITB; // overflows to KITS + _n_emit(ops, u3nc(op_y, axe)); + break; + } + break; + } + default: u3m_bail(c3__exit); return 0; @@ -1533,6 +1594,26 @@ _n_kale(u3_noun a) return a; } + +/* _n_edit(): PRODUCE a modified big with its axe axis + * changed to som. axe is RETAINED. + */ +static u3_noun +_n_edit(u3_noun big, u3_noun axe, u3_noun som) +{ + if ( c3y == u3a_is_cat(axe) ) { + return u3i_molt(big, axe, som, 0); + } + else { + u3_noun mor = u3qc_mas(axe); + u3_noun pro = ( 2 == u3qc_cap(axe) ) + ? u3nc(_n_edit(u3k(u3h(big)), mor, som), u3k(u3t(big))) + : u3nc(u3k(u3h(big)), _n_edit(u3k(u3t(big)), mor, som)); + u3z(mor); + return pro; + } +} + typedef struct { u3n_prog* pog_u; c3_w ip_w; @@ -1573,6 +1654,10 @@ _n_burn(u3n_prog* pog_u, u3_noun bus, c3_ys mov, c3_ys off) &&do_balt, &&do_salt, &&do_skib, &&do_skis, &&do_slib, &&do_slis, &&do_save, + &&do_muth, &&do_kuth, &&do_mutt, &&do_kutt, + &&do_musm, &&do_kusm, &&do_mucs, &&do_kucs, + &&do_mutb, &&do_muts, &&do_mitb, &&do_mits, + &&do_kutb, &&do_kuts, &&do_kitb, &&do_kits, }; u3j_site* sit_u; @@ -2158,6 +2243,104 @@ _n_burn(u3n_prog* pog_u, u3_noun bus, c3_ys mov, c3_ys off) *top = x; u3z(o); BURN(); + + do_kuth: + x = _n_pep(mov, off); + top = _n_swap(mov, off); + goto muth_in; + do_muth: + x = _n_pep(mov, off); + _n_toss(mov, off); + top = _n_peek(off); + muth_in: + o = *top; + *top = u3nc(x, u3k(u3t(o))); + u3z(o); + BURN(); + + do_kutt: + x = _n_pep(mov, off); + top = _n_swap(mov, off); + goto mutt_in; + do_mutt: + x = _n_pep(mov, off); + _n_toss(mov, off); + top = _n_peek(off); + mutt_in: + o = *top; + *top = u3nc(u3k(u3h(o)), x); + u3z(o); + BURN(); + + do_kusm: + x = _n_pep(mov, off); + top = _n_swap(mov, off); + goto musm_in; + do_musm: + x = _n_pep(mov, off); + _n_toss(mov, off); + top = _n_peek(off); + musm_in: + o = *top; + *top = u3nt(u3k(u3h(o)), x, u3k(u3t(u3t(o)))); + u3z(o); + BURN(); + + do_kucs: + x = _n_pep(mov, off); + top = _n_swap(mov, off); + goto mucs_in; + do_mucs: + x = _n_pep(mov, off); + _n_toss(mov, off); + top = _n_peek(off); + mucs_in: + o = *top; + *top = u3nc(u3k(u3h(o)), + u3nt(u3k(u3h(u3t(o))), x, u3k(u3t(u3t(u3t(o)))))); + u3z(o); + BURN(); + + do_kitb: + x = pog_u->lit_u.non[pog[ip_w++]]; + goto kut_in; + + do_kits: + x = pog_u->lit_u.non[_n_resh(pog, &ip_w)]; + goto kut_in; + + do_kuts: + x = _n_resh(pog, &ip_w); + goto kut_in; + + do_kutb: + x = pog[ip_w++]; + kut_in: + o = _n_pep(mov, off); + top = _n_swap(mov, off); + goto edit_in; + + do_mitb: + x = pog_u->lit_u.non[pog[ip_w++]]; + goto mut_in; + + do_mits: + x = pog_u->lit_u.non[_n_resh(pog, &ip_w)]; + goto mut_in; + + do_muts: + x = _n_resh(pog, &ip_w); + goto mut_in; + + do_mutb: + x = pog[ip_w++]; + mut_in: + o = _n_pep(mov, off); + _n_toss(mov, off); + top = _n_peek(off); + edit_in: + *top = _n_edit(*top, x, o); + BURN(); } } From 0c64dabc972a26e82276198b9e8866424874a1f8 Mon Sep 17 00:00:00 2001 From: Paul Driver Date: Sun, 10 Jun 2018 14:02:07 -0700 Subject: [PATCH 02/16] bugfixes --- noun/jets.c | 16 ++++++++++++---- noun/nock.c | 13 ++++++++----- 2 files changed, 20 insertions(+), 9 deletions(-) diff --git a/noun/jets.c b/noun/jets.c index 00fe06f242..e186b4a1b4 100644 --- a/noun/jets.c +++ b/noun/jets.c @@ -1399,15 +1399,23 @@ u3j_site_ream(u3j_site* sit_u) static void _cj_site_lock(u3_noun loc, u3_noun cor, u3j_site* sit_u) { + u3_weak fol; if ( (u3_none != sit_u->bat) && (c3y == u3r_sing(sit_u->bat, u3h(cor))) ) { return; } - sit_u->pog_p = _cj_prog(loc, u3r_at(sit_u->axe, cor)); - if ( u3_none != sit_u->bat ) { - u3z(sit_u->bat); + + fol = u3r_at(sit_u->axe, cor); + if ( u3_none == fol ) { + u3m_bail(c3__exit); + } + else { + sit_u->pog_p = _cj_prog(loc, fol); + if ( u3_none != sit_u->bat ) { + u3z(sit_u->bat); + } + sit_u->bat = u3k(u3h(cor)); } - sit_u->bat = u3k(u3h(cor)); } /* _cj_burn(): stop tracing glu and call a nock program diff --git a/noun/nock.c b/noun/nock.c index 10124cd43e..c63a466c39 100644 --- a/noun/nock.c +++ b/noun/nock.c @@ -543,6 +543,7 @@ _n_nock_on(u3_noun bus, u3_noun fol) #define KUTS 86 #define KITB 87 #define KITS 88 +#define LAST 89 /* _n_arg(): return the size (in bytes) of an opcode's argument */ @@ -555,7 +556,7 @@ _n_arg(c3_y cod_y) case SAMB: case SANB: case SBIP: case SBIN: case SLIB: case SKIB: case KICB: case TICB: case BUSH: case BAST: case BALT: - case KITB: case MITB: + case MUTB: case KUTB: case MITB: case KITB: return sizeof(c3_y); case FASK: case FASL: case FISL: case FISK: @@ -563,14 +564,14 @@ _n_arg(c3_y cod_y) case SAMS: case SANS: case SIPS: case SINS: case SLIS: case SKIS: case KICS: case TICS: case SUSH: case SAST: case SALT: - case KITS: case MITS: + case MUTS: case KUTS: case MITS: case KITS: return sizeof(c3_s); case SWIP: case SWIN: return sizeof(c3_l); default: - c3_assert( cod_y <= SAVE ); + c3_assert( cod_y < LAST ); return 0; } } @@ -874,6 +875,7 @@ _n_prog_asm(u3_noun ops, u3n_prog* pog_u, u3_noun sip) /* 8-bit direct args */ case FABK: case FABL: case LITB: case LILB: + case MUTB: case KUTB: case SAMB: buf_y[i_w--] = (c3_y) u3t(op); buf_y[i_w] = (c3_y) cod; @@ -882,6 +884,7 @@ _n_prog_asm(u3_noun ops, u3n_prog* pog_u, u3_noun sip) /* 16-bit direct args */ case FASK: case FASL: case LILS: case LITS: + case MUTS: case KUTS: case SAMS: case SIPS: case SINS: { c3_s off_s = u3t(op); buf_y[i_w--] = (c3_y) (off_s >> 8); @@ -1342,9 +1345,9 @@ _n_comp(u3_noun* ops, u3_noun fol, c3_o los_o, c3_o tel_o) default: op_y = (c3y == los_o) - ? (axe <= 0xFF) ? MUTB : (axe <= 0xFFFF) ? MUTS : MITB // overflows to MITL + ? (axe <= 0xFF) ? MUTB : (axe <= 0xFFFF) ? MUTS : MITB // overflows to MITS : (axe <= 0xFF) ? KUTB : (axe <= 0xFFFF) ? KUTS : KITB; // overflows to KITS - _n_emit(ops, u3nc(op_y, axe)); + _n_emit(ops, u3nc(op_y, u3k(axe))); break; } break; From 61f9a39f3551cc1266f383119c028043cb0f183b Mon Sep 17 00:00:00 2001 From: Paul Driver Date: Mon, 11 Jun 2018 15:04:49 -0700 Subject: [PATCH 03/16] disable hike jet, kill errant and unneccessary mutate-context-sample opcodes --- jets/f/hike.c | 1 + jets/tree.c | 4 +++- noun/nock.c | 43 +++++++++++-------------------------------- 3 files changed, 15 insertions(+), 33 deletions(-) diff --git a/jets/f/hike.c b/jets/f/hike.c index 567b1ca0d5..6b1bb5b369 100644 --- a/jets/f/hike.c +++ b/jets/f/hike.c @@ -89,6 +89,7 @@ u3qf_hike(u3_noun axe, u3_noun pac) { + c3_assert(0); if ( (u3_nul == pac) ) { return u3nc(0, u3k(axe)); } diff --git a/jets/tree.c b/jets/tree.c index 6ca70d2186..cf490820f4 100644 --- a/jets/tree.c +++ b/jets/tree.c @@ -285,11 +285,13 @@ static u3j_core _143_hex_d[] = 0, }; +/* hike disabled while implementing edit static u3j_harm _143_pen_hike_a[] = {{".2", u3wf_hike}, {}}; static c3_c* _143_pen_hike_ha[] = { "7503dc65fe3164b3e95f81b51afd64ab615e26516b60df95241244e2b793d024", 0, }; +*/ static u3j_harm _143_pen_look_a[] = {{".2", u3wf_look}, {}}; static c3_c* _143_pen_look_ha[] = { "04349d58bcb1317eba57eed8011c27a3ef7c3332c6595e45307a2d06bfc0e8d0", @@ -473,7 +475,7 @@ static u3j_core _143_pen_d[] = { "flor", 7, _143_pen_flor_a, 0, _143_pen_flor_ha }, { "fork", 7, _143_pen_fork_a, 0, _143_pen_fork_ha }, { "help", 7, _143_pen_help_a, 0, _143_pen_help_ha }, - { "hike", 7, _143_pen_hike_a, 0, _143_pen_hike_ha }, +// { "hike", 7, _143_pen_hike_a, 0, _143_pen_hike_ha }, { "look", 7, _143_pen_look_a, 0, _143_pen_look_ha }, { "loot", 7, _143_pen_loot_a, 0, _143_pen_loot_ha }, diff --git a/noun/nock.c b/noun/nock.c index c63a466c39..ca95069207 100644 --- a/noun/nock.c +++ b/noun/nock.c @@ -533,17 +533,15 @@ _n_nock_on(u3_noun bus, u3_noun fol) #define KUTT 76 #define MUSM 77 #define KUSM 78 -#define MUCS 79 -#define KUCS 80 -#define MUTB 81 -#define MUTS 82 -#define MITB 83 -#define MITS 84 -#define KUTB 85 -#define KUTS 86 -#define KITB 87 -#define KITS 88 -#define LAST 89 +#define MUTB 79 +#define MUTS 80 +#define MITB 81 +#define MITS 82 +#define KUTB 83 +#define KUTS 84 +#define KITB 85 +#define KITS 86 +#define LAST 87 /* _n_arg(): return the size (in bytes) of an opcode's argument */ @@ -1017,7 +1015,7 @@ static char* opcode_names[] = { "skib", "skis", "slib", "slis", "save", "muth", "kuth", "mutt", "kutt", - "musm", "kusm", "mucs", "kucs", + "musm", "kusm", "mutb", "muts", "mitb", "mits", "kutb", "kuts", "kitb", "kits", }; @@ -1339,10 +1337,6 @@ _n_comp(u3_noun* ops, u3_noun fol, c3_o los_o, c3_o tel_o) _n_emit(ops, (c3y == los_o) ? MUSM : KUSM); break; - case u3x_con_sam: - _n_emit(ops, (c3y == los_o) ? MUCS : KUCS); - break; - default: op_y = (c3y == los_o) ? (axe <= 0xFF) ? MUTB : (axe <= 0xFFFF) ? MUTS : MITB // overflows to MITS @@ -1658,7 +1652,7 @@ _n_burn(u3n_prog* pog_u, u3_noun bus, c3_ys mov, c3_ys off) &&do_skib, &&do_skis, &&do_slib, &&do_slis, &&do_save, &&do_muth, &&do_kuth, &&do_mutt, &&do_kutt, - &&do_musm, &&do_kusm, &&do_mucs, &&do_kucs, + &&do_musm, &&do_kusm, &&do_mutb, &&do_muts, &&do_mitb, &&do_mits, &&do_kutb, &&do_kuts, &&do_kitb, &&do_kits, }; @@ -2289,21 +2283,6 @@ _n_burn(u3n_prog* pog_u, u3_noun bus, c3_ys mov, c3_ys off) u3z(o); BURN(); - do_kucs: - x = _n_pep(mov, off); - top = _n_swap(mov, off); - goto mucs_in; - do_mucs: - x = _n_pep(mov, off); - _n_toss(mov, off); - top = _n_peek(off); - mucs_in: - o = *top; - *top = u3nc(u3k(u3h(o)), - u3nt(u3k(u3h(u3t(o))), x, u3k(u3t(u3t(u3t(o)))))); - u3z(o); - BURN(); - do_kitb: x = pog_u->lit_u.non[pog[ip_w++]]; goto kut_in; From 0fe4157b8252d9965356a1e9134b94d62ae6aeba Mon Sep 17 00:00:00 2001 From: Paul Driver Date: Tue, 12 Jun 2018 10:23:47 -0700 Subject: [PATCH 04/16] small memory leak for large edits --- noun/nock.c | 1 + 1 file changed, 1 insertion(+) diff --git a/noun/nock.c b/noun/nock.c index ca95069207..a2e3a91948 100644 --- a/noun/nock.c +++ b/noun/nock.c @@ -1607,6 +1607,7 @@ _n_edit(u3_noun big, u3_noun axe, u3_noun som) ? u3nc(_n_edit(u3k(u3h(big)), mor, som), u3k(u3t(big))) : u3nc(u3k(u3h(big)), _n_edit(u3k(u3t(big)), mor, som)); u3z(mor); + u3z(big); return pro; } } From a3f27a6a39c55d5430689bfd1a18a31673da078e Mon Sep 17 00:00:00 2001 From: Paul Driver Date: Tue, 12 Jun 2018 10:24:36 -0700 Subject: [PATCH 05/16] bypass mat and chop directly in jam --- jets/e/jam.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/jets/e/jam.c b/jets/e/jam.c index 9085567367..209b9e0f1e 100644 --- a/jets/e/jam.c +++ b/jets/e/jam.c @@ -57,9 +57,17 @@ _jam_buf_chop(_jam_buf* buf_u, c3_w met_w, u3_noun a) static void _jam_buf_atom(_jam_buf* buf_u, u3_noun a) { - u3_noun mat = u3qe_mat(a); - _jam_buf_chop(buf_u, u3h(mat), u3t(mat)); - u3z(mat); + if ( 0 == a ) { + _jam_buf_chop(buf_u, 1, 1); + } + else { + c3_w b_w = u3r_met(0, a), + c_w = u3r_met(0, b_w); + c3_assert(c_w <= 32); + _jam_buf_chop(buf_u, c_w+1, 1 << c_w); + _jam_buf_chop(buf_u, c_w-1, b_w & ((1 << (c_w-1)) - 1)); + _jam_buf_chop(buf_u, b_w, a); + } } static u3_noun From e629272ac6aa8931a7e2994aaecaccfc71a00c3c Mon Sep 17 00:00:00 2001 From: Paul Driver Date: Thu, 14 Jun 2018 11:36:56 -0700 Subject: [PATCH 06/16] avoid allocating an atom for _cj_bash --- jets/e/jam.c | 144 +++++++++++++++++++++++++++------------------------ noun/jets.c | 39 ++++++++++++-- 2 files changed, 112 insertions(+), 71 deletions(-) diff --git a/jets/e/jam.c b/jets/e/jam.c index 209b9e0f1e..5869d657bc 100644 --- a/jets/e/jam.c +++ b/jets/e/jam.c @@ -40,7 +40,7 @@ _jam_buf_grow(_jam_buf* buf_u, c3_w mor_w) ++new_w; } - buf_u->wor_w = u3a_realloc(buf_u->wor_w, new_w * sizeof(c3_w)); + buf_u->wor_w = u3a_wealloc(buf_u->wor_w, new_w); memset(buf_u->wor_w + old_w, 0, (new_w - old_w) * sizeof(c3_w)); } } @@ -70,91 +70,99 @@ _jam_buf_atom(_jam_buf* buf_u, u3_noun a) } } -static u3_noun -_jam_buf_top(u3_noun a) -{ - u3p(u3h_root) har_p = u3h_new(); - c3_o nor_o = u3a_is_north(u3R); - c3_y wis_y = c3_wiseof(u3_noun); - c3_ys mov = ( c3y == nor_o ? -wis_y : wis_y ); - c3_ys off = ( c3y == nor_o ? 0 : -wis_y ); - u3_noun* top, *don = u3to(u3_noun, u3R->cap_p + off); - _jam_buf buf_u; - u3_weak c; - c3_o cel_o; - c3_w* sal_w, len_w; +/* functions +*/ + /* u3qe_jam_buf(): jam without atom allocation. returns + * atom-suitable words, and *bit_w will + * have the length (in bits). return should + * be freed with u3a_wfree(). + */ + c3_w* + u3qe_jam_buf(u3_noun a, c3_w* bit_w) + { + u3p(u3h_root) har_p = u3h_new(); + c3_o nor_o = u3a_is_north(u3R); + c3_y wis_y = c3_wiseof(u3_noun); + c3_ys mov = ( c3y == nor_o ? -wis_y : wis_y ); + c3_ys off = ( c3y == nor_o ? 0 : -wis_y ); + u3_noun* top, *don = u3to(u3_noun, u3R->cap_p + off); + u3_weak c; + c3_o cel_o; + c3_w len_w; + _jam_buf buf_u; - buf_u.a_w = 144; // fib(12) is small enough to be reasonably fast to allocate. - buf_u.b_w = 89; // fib(11) is needed to get fib(13). - len_w = buf_u.a_w >> 5; - if ( (len_w << 5) != buf_u.a_w ) { - ++len_w; - } - buf_u.wor_w = u3a_calloc(len_w, sizeof(c3_w)); - buf_u.bit_w = 0; + buf_u.a_w = 144; // fib(12) is small enough to be reasonably fast to allocate. + buf_u.b_w = 89; // fib(11) is needed to get fib(13). + len_w = buf_u.a_w >> 5; + if ( (len_w << 5) != buf_u.a_w ) { + ++len_w; + } + buf_u.wor_w = u3a_walloc(len_w); + buf_u.bit_w = 0; + memset(buf_u.wor_w, 0, len_w * sizeof(c3_w)); - u3R->cap_p += mov; - top = u3to(u3_noun, u3R->cap_p + off); - *top = a; + u3R->cap_p += mov; + top = u3to(u3_noun, u3R->cap_p + off); + *top = a; - while ( top != don ) { - a = *top; - cel_o = u3du(a); - c = u3h_git(har_p, a); - if ( u3_none != c ) { - if ( c3y == cel_o ) { - _jam_buf_chop(&buf_u, 2, 3); - _jam_buf_atom(&buf_u, c); - } - else { - if ( u3r_met(0, a) <= u3r_met(0, c) ) { - _jam_buf_chop(&buf_u, 1, 0); - _jam_buf_atom(&buf_u, a); + while ( top != don ) { + a = *top; + cel_o = u3du(a); + c = u3h_git(har_p, a); + if ( u3_none != c ) { + if ( c3y == cel_o ) { + _jam_buf_chop(&buf_u, 2, 3); + _jam_buf_atom(&buf_u, c); } else { - _jam_buf_chop(&buf_u, 2, 3); - _jam_buf_atom(&buf_u, c); + if ( u3r_met(0, a) <= u3r_met(0, c) ) { + _jam_buf_chop(&buf_u, 1, 0); + _jam_buf_atom(&buf_u, a); + } + else { + _jam_buf_chop(&buf_u, 2, 3); + _jam_buf_atom(&buf_u, c); + } } - } - u3R->cap_p -= mov; - top = u3to(u3_noun, u3R->cap_p + off); - } - else { - u3h_put(har_p, a, buf_u.bit_w); - if ( c3n == cel_o ) { - _jam_buf_chop(&buf_u, 1, 0); - _jam_buf_atom(&buf_u, a); u3R->cap_p -= mov; top = u3to(u3_noun, u3R->cap_p + off); } else { - _jam_buf_chop(&buf_u, 2, 1); - *top = u3t(a); + u3h_put(har_p, a, buf_u.bit_w); + if ( c3n == cel_o ) { + _jam_buf_chop(&buf_u, 1, 0); + _jam_buf_atom(&buf_u, a); + u3R->cap_p -= mov; + top = u3to(u3_noun, u3R->cap_p + off); + } + else { + _jam_buf_chop(&buf_u, 2, 1); + *top = u3t(a); - u3R->cap_p += mov; - top = u3to(u3_noun, u3R->cap_p + off); - *top = u3h(a); + u3R->cap_p += mov; + top = u3to(u3_noun, u3R->cap_p + off); + *top = u3h(a); + } } } - } - len_w = buf_u.bit_w >> 5; - if ( (len_w << 5) != buf_u.bit_w ) { - ++len_w; + *bit_w = buf_u.bit_w; + u3h_free(har_p); + return buf_u.wor_w; } - sal_w = u3a_slab(len_w); - memcpy(sal_w, buf_u.wor_w, len_w*sizeof(c3_w)); - u3a_free(buf_u.wor_w); - u3h_free(har_p); - return u3a_moot(sal_w); -} - -/* functions -*/ u3_noun u3qe_jam(u3_atom a) { - return _jam_buf_top(a); + c3_w bit_w, *sal_w; + c3_w* wor_w = u3qe_jam_buf(a, &bit_w); + c3_w len_w = bit_w >> 5; + if ( (len_w << 5) != bit_w ) { + ++len_w; + } + sal_w = u3a_slab(len_w); + memcpy(sal_w, wor_w, len_w*sizeof(c3_w)); + u3a_wfree(wor_w); + return u3a_moot(sal_w); } u3_noun u3we_jam(u3_noun cor) diff --git a/noun/jets.c b/noun/jets.c index e186b4a1b4..5da4c3b566 100644 --- a/noun/jets.c +++ b/noun/jets.c @@ -3,6 +3,12 @@ */ #include "all.h" +#if defined(U3_OS_osx) +#include +#else +#include +#endif + /** Data structures. **/ @@ -90,6 +96,9 @@ _cj_hash(c3_c* has_c) return pro; } +// in the jam jet file +c3_w* u3qe_jam_buf(u3_noun, c3_w* bit_w); + /* _cj_bash(): battery hash. RETAIN. */ static u3_noun @@ -108,10 +117,34 @@ _cj_bash(u3_noun bat) rod_u = u3to(u3_road, rod_u->par_p); } else { - u3_noun jan = u3qe_jam(bat); - pro = u3qe_shax(jan); + c3_w bit_w, met_w; + c3_w* wor_w; + c3_y* fat_y; + c3_y dig_y[32]; + + wor_w = u3qe_jam_buf(bat, &bit_w); + met_w = bit_w >> 3; + if ( bit_w != met_w << 3 ) { + ++met_w; + } + // assume little-endian + fat_y = (c3_y*) wor_w; +#if defined(U3_OS_osx) + CC_SHA256_CTX ctx_h; + + CC_SHA256_Init(&ctx_h); + CC_SHA256_Update(&ctx_h, fat_y, met_w); + CC_SHA256_Final(dig_y, &ctx_h); +#else + SHA256_CTX ctx_h; + + SHA256_Init(&ctx_h); + SHA256_Update(&ctx_h, fat_y, met_w); + SHA256_Final(dig_y, &ctx_h); +#endif + pro = u3i_bytes(32, dig_y); u3h_put(u3R->jed.bas_p, bat, u3k(pro)); - u3z(jan); + u3a_wfree(wor_w); break; } } From 6ce5fb681ea4f5ab442c6c7c877c5a31f74aef76 Mon Sep 17 00:00:00 2001 From: Paul Driver Date: Thu, 14 Jun 2018 12:25:45 -0700 Subject: [PATCH 07/16] bail in _n_edit on invalid path --- noun/nock.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/noun/nock.c b/noun/nock.c index a2e3a91948..1ac6de74f9 100644 --- a/noun/nock.c +++ b/noun/nock.c @@ -1603,6 +1603,9 @@ _n_edit(u3_noun big, u3_noun axe, u3_noun som) } else { u3_noun mor = u3qc_mas(axe); + if ( c3n == u3du(big) ) { + u3m_bail(c3__exit); + } u3_noun pro = ( 2 == u3qc_cap(axe) ) ? u3nc(_n_edit(u3k(u3h(big)), mor, som), u3k(u3t(big))) : u3nc(u3k(u3h(big)), _n_edit(u3k(u3t(big)), mor, som)); From 7dcc2303d119b42389e4a07bd3ab0ab50888a33a Mon Sep 17 00:00:00 2001 From: Paul Driver Date: Tue, 26 Jun 2018 11:49:15 -0700 Subject: [PATCH 08/16] mutating edit --- include/noun/allocate.h | 9 +++ include/noun/imprison.h | 8 +++ noun/imprison.c | 144 ++++++++++++++++++++++++++++++++++++++++ noun/nock.c | 26 +------- 4 files changed, 162 insertions(+), 25 deletions(-) diff --git a/include/noun/allocate.h b/include/noun/allocate.h index d2a8a55b66..8533158d99 100644 --- a/include/noun/allocate.h +++ b/include/noun/allocate.h @@ -256,6 +256,15 @@ ? u3a_north_is_senior(r, som) \ : u3a_south_is_senior(r, som) ) +# define u3a_is_mutable(r, som) \ + ( _(u3a_is_atom(som)) \ + ? c3n \ + : _(u3a_is_senior(r, som)) \ + ? c3n \ + : _(u3a_is_junior(r, som)) \ + ? c3n \ + : (u3a_botox(u3a_to_ptr(som))->use_w == 1) \ + ? c3y : c3n ) /** Globals. **/ diff --git a/include/noun/imprison.h b/include/noun/imprison.h index efda35fab3..f552c87f5e 100644 --- a/include/noun/imprison.h +++ b/include/noun/imprison.h @@ -55,6 +55,14 @@ u3_noun u3i_qual(u3_noun a, u3_noun b, u3_noun c, u3_noun d); + /* u3i_edit(): + ** + ** Mutate `big` at axis `axe` with new value `som` + ** `axe` is RETAINED. + */ + u3_noun + u3i_edit(u3_noun big, u3_noun axe, u3_noun som); + /* u3i_string(): ** ** Produce an LSB-first atom from the C string `a`. diff --git a/noun/imprison.c b/noun/imprison.c index c08e967f40..c0d16c3dc8 100644 --- a/noun/imprison.c +++ b/noun/imprison.c @@ -262,6 +262,150 @@ u3i_qual(u3_noun a, u3_noun b, u3_noun c, u3_noun d) return u3i_cell(a, u3i_trel(b, c, d)); } +static u3_noun +_edit_cat(u3_noun big, c3_l axe_l, u3_noun som) +{ + if ( c3n == u3du(big) ) { + return u3m_bail(c3__exit); + } + else { + u3_noun pro; + switch ( axe_l ) { + case 2: + pro = u3nc(som, u3k(u3t(big))); + break; + case 3: + pro = u3nc(u3k(u3h(big)), som); + break; + default: { + c3_l mor_l = u3x_mas(axe_l); + pro = ( 2 == u3x_cap(axe_l) ) + ? u3nc(_edit_cat(u3k(u3h(big)), mor_l, som), u3k(u3t(big))) + : u3nc(u3k(u3h(big)), _edit_cat(u3k(u3t(big)), mor_l, som)); + break; + } + } + u3z(big); + return pro; + } +} + +static u3_noun +_edit(u3_noun big, u3_noun axe, u3_noun som) +{ + if ( c3y == u3a_is_cat(axe) ) { + return _edit_cat(big, (c3_l) axe, som); + } + else if ( c3n == u3du(big) ) { + return u3m_bail(c3__exit); + } + else { + u3_noun mor = u3qc_mas(axe), + pro = ( 2 == u3qc_cap(axe) ) + ? u3nc(_edit(u3k(u3h(big)), mor, som), u3k(u3t(big))) + : u3nc(u3k(u3h(big)), _edit(u3k(u3t(big)), mor, som)); + u3z(mor); + u3z(big); + return pro; + } +} + +static u3_noun _edit_or_mutate_cat(u3_noun, c3_l, u3_noun); +static u3_noun _edit_or_mutate(u3_noun, u3_noun, u3_noun); + +static void +_mutate_cat(u3_noun big, c3_l axe_l, u3_noun som) +{ + if ( c3n == u3du(big) ) { + u3m_bail(c3__exit); + } + else { + u3a_cell* cel_u = (void*) u3a_to_ptr(big); + switch ( axe_l ) { + case 2: + u3z(cel_u->hed); + cel_u->hed = som; + break; + case 3: + u3z(cel_u->tel); + cel_u->tel = som; + break; + default: { + u3_noun* tar = ( 2 == u3x_cap(axe_l) ) + ? &(cel_u->hed) + : &(cel_u->tel); + *tar = _edit_or_mutate_cat(*tar, u3x_mas(axe_l), som); + } + } + } +} + +static void +_mutate(u3_noun big, u3_noun axe, u3_noun som) +{ + if ( c3y == u3a_is_cat(axe) ) { + _mutate_cat(big, (c3_l) axe, som); + } + else if ( c3n == u3du(big) ) { + u3m_bail(c3__exit); + } + else { + u3a_cell* cel_u = (void*) u3a_to_ptr(big); + u3_noun mor = u3qc_mas(axe); + u3_noun* tar = ( 2 == u3qc_cap(axe) ) + ? &(cel_u->hed) + : &(cel_u->tel); + *tar = _edit_or_mutate(*tar, mor, som); + u3z(mor); + } +} + +static u3_noun +_edit_or_mutate_cat(u3_noun big, c3_l axe_l, u3_noun som) +{ + if ( c3y == u3a_is_mutable(u3R, big) ) { + _mutate_cat(big, axe_l, som); + return big; + } + else { + return _edit_cat(big, axe_l, som); + } +} + +static u3_noun +_edit_or_mutate(u3_noun big, u3_noun axe, u3_noun som) +{ + if ( c3y == u3a_is_cat(axe) ) { + return _edit_or_mutate_cat(big, (c3_l) axe, som); + } + else if ( c3y == u3a_is_mutable(u3R, big) ) { + _mutate(big, axe, som); + return big; + } + else { + return _edit(big, axe, som); + } +} + +/* u3i_edit(): +** +** Mutate `big` at axis `axe` with new value `som`. +** `axe` is RETAINED. +*/ +u3_noun +u3i_edit(u3_noun big, u3_noun axe, u3_noun som) +{ + switch ( axe ) { + case 0: + return u3m_bail(c3__exit); + case 1: + u3z(big); + return som; + default: + return _edit_or_mutate(big, axe, som); + } +} + /* u3i_string(): ** ** Produce an LSB-first atom from the C string `a`. diff --git a/noun/nock.c b/noun/nock.c index 1ac6de74f9..2150ae223e 100644 --- a/noun/nock.c +++ b/noun/nock.c @@ -1591,30 +1591,6 @@ _n_kale(u3_noun a) return a; } - -/* _n_edit(): PRODUCE a modified big with its axe axis - * changed to som. axe is RETAINED. - */ -static u3_noun -_n_edit(u3_noun big, u3_noun axe, u3_noun som) -{ - if ( c3y == u3a_is_cat(axe) ) { - return u3i_molt(big, axe, som, 0); - } - else { - u3_noun mor = u3qc_mas(axe); - if ( c3n == u3du(big) ) { - u3m_bail(c3__exit); - } - u3_noun pro = ( 2 == u3qc_cap(axe) ) - ? u3nc(_n_edit(u3k(u3h(big)), mor, som), u3k(u3t(big))) - : u3nc(u3k(u3h(big)), _n_edit(u3k(u3t(big)), mor, som)); - u3z(mor); - u3z(big); - return pro; - } -} - typedef struct { u3n_prog* pog_u; c3_w ip_w; @@ -2325,7 +2301,7 @@ _n_burn(u3n_prog* pog_u, u3_noun bus, c3_ys mov, c3_ys off) _n_toss(mov, off); top = _n_peek(off); edit_in: - *top = _n_edit(*top, x, o); + *top = u3i_edit(*top, x, o); BURN(); } } From 82c89c1696a6a049a3c180c1dd16b89f5a236a90 Mon Sep 17 00:00:00 2001 From: Joe Bryan Date: Wed, 10 Oct 2018 16:25:04 -0400 Subject: [PATCH 09/16] 1. duplicates hint (%10) and wish (%11) at %13 and %14 (nock 4K) --- jets/f/ut_mint.c | 16 ++++++++-------- jets/f/ut_mull.c | 10 +++++----- noun/jets.c | 4 ++-- noun/nock.c | 15 +++++++++++++++ 4 files changed, 30 insertions(+), 15 deletions(-) diff --git a/jets/f/ut_mint.c b/jets/f/ut_mint.c index 7dd189300b..5e4f280ca1 100644 --- a/jets/f/ut_mint.c +++ b/jets/f/ut_mint.c @@ -148,16 +148,16 @@ } static u3_noun - _mint_coke(u3_noun nug) + _mint_cove(u3_noun nug) { if ( 0 == u3h(nug) ) { return u3k(u3t(nug)); } - else if ( 10 == u3h(nug) ) { - return _mint_coke(u3t(u3t(nug))); + else if ( (10 == u3h(nug)) || (13 == u3h(nug)) ) { + return _mint_cove(u3t(u3t(nug))); } else { - return u3m_error("mint-coke"); + return u3m_error("mint-cove"); } } @@ -370,7 +370,7 @@ u3_noun wam = u3qfu_play(van, sut, p_gen); u3_noun dok = u3nc(c3__wing, u3k(q_gen)); u3_noun vol = _mint_corn(van, sut, dok); - u3_noun axe = _mint_coke(vol); + u3_noun axe = _mint_cove(vol); ret = u3nc(_mint_nice(van, gol, _mint_bean()), u3qfu_fish(van, wam, axe)); @@ -471,7 +471,7 @@ u3_noun viz = _mint_in(van, sut, c3__noun, q_gen); ret = u3nc(u3k(u3h(nef)), - u3nt(11, u3nc(1, u3nc(151, u3k(u3h(nef)))), u3k(u3t(viz)))); + u3nt(14, u3nc(1, u3nc(151, u3k(u3h(nef)))), u3k(u3t(viz)))); u3z(viz); u3z(nef); @@ -683,7 +683,7 @@ _mint_corn(van, sut, u3t(p_gen))); } ret = u3nc(u3k(u3h(hum)), - u3nt(10, bez, u3k(u3t(hum)))); + u3nt(13, bez, u3k(u3t(hum)))); u3z(hum); return ret; @@ -786,7 +786,7 @@ u3_noun hum = _mint_in(van, sut, gol, q_gen); u3_noun bez = u3nt(c3__spot, 1, u3k(p_gen)); - ret = u3nc(u3k(u3h(hum)), u3nt(10, bez, u3k(u3t(hum)))); + ret = u3nc(u3k(u3h(hum)), u3nt(13, bez, u3k(u3t(hum)))); u3z(hum); } u3t_drop(); diff --git a/jets/f/ut_mull.c b/jets/f/ut_mull.c index e078407433..1a00c6099a 100644 --- a/jets/f/ut_mull.c +++ b/jets/f/ut_mull.c @@ -63,16 +63,16 @@ } } static u3_noun - _mull_coke(u3_noun nug) + _mull_cove(u3_noun nug) { if ( 0 == u3h(nug) ) { return u3k(u3t(nug)); } - else if ( 10 == u3h(nug) ) { - return _mull_coke(u3t(u3t(nug))); + else if ( (10 == u3h(nug)) || (13 == u3h(nug)) ) { + return _mull_cove(u3t(u3t(nug))); } else { - return u3m_error("mull-coke"); + return u3m_error("mull-cove"); } } @@ -109,7 +109,7 @@ u3_noun gen) { u3_noun fug = u3qfu_mint(van, sut, c3__noun, gen); - u3_noun axe = _mull_coke(u3t(fug)); + u3_noun axe = _mull_cove(u3t(fug)); u3z(fug); return axe; diff --git a/noun/jets.c b/noun/jets.c index f2c4759605..3b27b4a1f0 100644 --- a/noun/jets.c +++ b/noun/jets.c @@ -249,7 +249,7 @@ _cj_axis(u3_noun fol) { u3_noun p_fol, q_fol, r_fol; - while ( _(u3du(fol)) && (10 == u3h(fol)) ) + while ( _(u3du(fol)) && ((10 == u3h(fol)) || (13 == u3h(fol))) ) { fol = u3t(u3t(fol)); } if ( !_(u3r_trel(fol, &p_fol, &q_fol, &r_fol)) ) { @@ -436,7 +436,7 @@ _cj_je_fsck(u3_noun clu) if ( 0 == (nam_c = _cj_chum(p_clu)) ) { u3z(clu); return u3_none; } - while ( _(u3du(q_clu)) && (10 == u3h(q_clu)) ) { + while ( _(u3du(q_clu)) && ((10 == u3h(q_clu)) || (13 == u3h(q_clu))) ) { q_clu = u3t(u3t(q_clu)); } if ( !_(u3du(q_clu)) ) { diff --git a/noun/nock.c b/noun/nock.c index c784d87ab4..a2d77fde1a 100644 --- a/noun/nock.c +++ b/noun/nock.c @@ -1289,6 +1289,21 @@ _n_comp(u3_noun* ops, u3_noun fol, c3_o los_o, c3_o tel_o) ++tot_w; _n_emit(ops, (c3y == los_o) ? WILS : WISH); break; + // temporary home for hint + case 13: + u3x_cell(arg, &hed, &tel); + tot_w += _n_bint(ops, hed, tel, los_o, tel_o); + break; + + // temporary home for wish + case 14: + u3x_cell(arg, &hed, &tel); + tot_w += _n_comp(ops, hed, c3n, c3n); + ++tot_w; _n_emit(ops, SWAP); + tot_w += _n_comp(ops, tel, c3n, c3n); + ++tot_w; _n_emit(ops, (c3y == los_o) ? WILS : WISH); + break; + default: u3m_bail(c3__exit); return 0; From f64b5c8f801d4ef64c1c9e0a2e4ceefe159bf9e7 Mon Sep 17 00:00:00 2001 From: Joe Bryan Date: Wed, 10 Oct 2018 18:15:37 -0400 Subject: [PATCH 10/16] 2. removes %10 and %11 (nock 4K) --- jets/f/ut_mint.c | 2 +- jets/f/ut_mull.c | 2 +- noun/jets.c | 4 ++-- noun/nock.c | 13 ------------- 4 files changed, 4 insertions(+), 17 deletions(-) diff --git a/jets/f/ut_mint.c b/jets/f/ut_mint.c index 5e4f280ca1..a88d32557b 100644 --- a/jets/f/ut_mint.c +++ b/jets/f/ut_mint.c @@ -153,7 +153,7 @@ if ( 0 == u3h(nug) ) { return u3k(u3t(nug)); } - else if ( (10 == u3h(nug)) || (13 == u3h(nug)) ) { + else if ( (13 == u3h(nug)) ) { return _mint_cove(u3t(u3t(nug))); } else { diff --git a/jets/f/ut_mull.c b/jets/f/ut_mull.c index 1a00c6099a..4474f592cc 100644 --- a/jets/f/ut_mull.c +++ b/jets/f/ut_mull.c @@ -68,7 +68,7 @@ if ( 0 == u3h(nug) ) { return u3k(u3t(nug)); } - else if ( (10 == u3h(nug)) || (13 == u3h(nug)) ) { + else if ( (13 == u3h(nug)) ) { return _mull_cove(u3t(u3t(nug))); } else { diff --git a/noun/jets.c b/noun/jets.c index 3b27b4a1f0..9cd1ebebc8 100644 --- a/noun/jets.c +++ b/noun/jets.c @@ -249,7 +249,7 @@ _cj_axis(u3_noun fol) { u3_noun p_fol, q_fol, r_fol; - while ( _(u3du(fol)) && ((10 == u3h(fol)) || (13 == u3h(fol))) ) + while ( _(u3du(fol)) && ((13 == u3h(fol))) ) { fol = u3t(u3t(fol)); } if ( !_(u3r_trel(fol, &p_fol, &q_fol, &r_fol)) ) { @@ -436,7 +436,7 @@ _cj_je_fsck(u3_noun clu) if ( 0 == (nam_c = _cj_chum(p_clu)) ) { u3z(clu); return u3_none; } - while ( _(u3du(q_clu)) && ((10 == u3h(q_clu)) || (13 == u3h(q_clu))) ) { + while ( _(u3du(q_clu)) && ((13 == u3h(q_clu))) ) { q_clu = u3t(u3t(q_clu)); } if ( !_(u3du(q_clu)) ) { diff --git a/noun/nock.c b/noun/nock.c index a2d77fde1a..73e6b1743f 100644 --- a/noun/nock.c +++ b/noun/nock.c @@ -1276,19 +1276,6 @@ _n_comp(u3_noun* ops, u3_noun fol, c3_o los_o, c3_o tel_o) } break; - case 10: - u3x_cell(arg, &hed, &tel); - tot_w += _n_bint(ops, hed, tel, los_o, tel_o); - break; - - case 11: - u3x_cell(arg, &hed, &tel); - tot_w += _n_comp(ops, hed, c3n, c3n); - ++tot_w; _n_emit(ops, SWAP); - tot_w += _n_comp(ops, tel, c3n, c3n); - ++tot_w; _n_emit(ops, (c3y == los_o) ? WILS : WISH); - break; - // temporary home for hint case 13: u3x_cell(arg, &hed, &tel); From 4d6950d68a06f7d8c32eebaa51bbb931c85844f4 Mon Sep 17 00:00:00 2001 From: Joe Bryan Date: Wed, 10 Oct 2018 18:40:13 -0400 Subject: [PATCH 11/16] 3. implements hint at %11 and wish at %12 (nock 4K) --- jets/f/ut_mint.c | 2 +- jets/f/ut_mull.c | 2 +- noun/jets.c | 4 ++-- noun/nock.c | 13 +++++++++++++ 4 files changed, 17 insertions(+), 4 deletions(-) diff --git a/jets/f/ut_mint.c b/jets/f/ut_mint.c index a88d32557b..f63b67eda2 100644 --- a/jets/f/ut_mint.c +++ b/jets/f/ut_mint.c @@ -153,7 +153,7 @@ if ( 0 == u3h(nug) ) { return u3k(u3t(nug)); } - else if ( (13 == u3h(nug)) ) { + else if ( (11 == u3h(nug)) || (13 == u3h(nug)) ) { return _mint_cove(u3t(u3t(nug))); } else { diff --git a/jets/f/ut_mull.c b/jets/f/ut_mull.c index 4474f592cc..c22d91cf7a 100644 --- a/jets/f/ut_mull.c +++ b/jets/f/ut_mull.c @@ -68,7 +68,7 @@ if ( 0 == u3h(nug) ) { return u3k(u3t(nug)); } - else if ( (13 == u3h(nug)) ) { + else if ( (11 == u3h(nug)) || (13 == u3h(nug)) ) { return _mull_cove(u3t(u3t(nug))); } else { diff --git a/noun/jets.c b/noun/jets.c index 9cd1ebebc8..11df57d4ba 100644 --- a/noun/jets.c +++ b/noun/jets.c @@ -249,7 +249,7 @@ _cj_axis(u3_noun fol) { u3_noun p_fol, q_fol, r_fol; - while ( _(u3du(fol)) && ((13 == u3h(fol))) ) + while ( _(u3du(fol)) && ((11 == u3h(fol)) || (13 == u3h(fol))) ) { fol = u3t(u3t(fol)); } if ( !_(u3r_trel(fol, &p_fol, &q_fol, &r_fol)) ) { @@ -436,7 +436,7 @@ _cj_je_fsck(u3_noun clu) if ( 0 == (nam_c = _cj_chum(p_clu)) ) { u3z(clu); return u3_none; } - while ( _(u3du(q_clu)) && ((13 == u3h(q_clu))) ) { + while ( _(u3du(q_clu)) && ((11 == u3h(q_clu)) || (13 == u3h(q_clu))) ) { q_clu = u3t(u3t(q_clu)); } if ( !_(u3du(q_clu)) ) { diff --git a/noun/nock.c b/noun/nock.c index 73e6b1743f..23be93f0b3 100644 --- a/noun/nock.c +++ b/noun/nock.c @@ -1276,6 +1276,19 @@ _n_comp(u3_noun* ops, u3_noun fol, c3_o los_o, c3_o tel_o) } break; + case 11: + u3x_cell(arg, &hed, &tel); + tot_w += _n_bint(ops, hed, tel, los_o, tel_o); + break; + + case 12: + u3x_cell(arg, &hed, &tel); + tot_w += _n_comp(ops, hed, c3n, c3n); + ++tot_w; _n_emit(ops, SWAP); + tot_w += _n_comp(ops, tel, c3n, c3n); + ++tot_w; _n_emit(ops, (c3y == los_o) ? WILS : WISH); + break; + // temporary home for hint case 13: u3x_cell(arg, &hed, &tel); From c3ca5c24b6b346b0d00695217c16f4d224e17653 Mon Sep 17 00:00:00 2001 From: Joe Bryan Date: Wed, 10 Oct 2018 18:44:17 -0400 Subject: [PATCH 12/16] 4. emits %11 and %12 (nock 4K) --- jets/f/ut_mint.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/jets/f/ut_mint.c b/jets/f/ut_mint.c index f63b67eda2..0d0f54e397 100644 --- a/jets/f/ut_mint.c +++ b/jets/f/ut_mint.c @@ -471,7 +471,7 @@ u3_noun viz = _mint_in(van, sut, c3__noun, q_gen); ret = u3nc(u3k(u3h(nef)), - u3nt(14, u3nc(1, u3nc(151, u3k(u3h(nef)))), u3k(u3t(viz)))); + u3nt(12, u3nc(1, u3nc(151, u3k(u3h(nef)))), u3k(u3t(viz)))); u3z(viz); u3z(nef); @@ -683,7 +683,7 @@ _mint_corn(van, sut, u3t(p_gen))); } ret = u3nc(u3k(u3h(hum)), - u3nt(13, bez, u3k(u3t(hum)))); + u3nt(11, bez, u3k(u3t(hum)))); u3z(hum); return ret; @@ -786,7 +786,7 @@ u3_noun hum = _mint_in(van, sut, gol, q_gen); u3_noun bez = u3nt(c3__spot, 1, u3k(p_gen)); - ret = u3nc(u3k(u3h(hum)), u3nt(13, bez, u3k(u3t(hum)))); + ret = u3nc(u3k(u3h(hum)), u3nt(11, bez, u3k(u3t(hum)))); u3z(hum); } u3t_drop(); From 8f42a29933cae14a0c0f3a039bf996faf9cf6588 Mon Sep 17 00:00:00 2001 From: Joe Bryan Date: Wed, 10 Oct 2018 19:15:35 -0400 Subject: [PATCH 13/16] 5. removes %13 and %14 (nock 4K) --- jets/f/ut_mint.c | 2 +- jets/f/ut_mull.c | 2 +- noun/jets.c | 4 ++-- noun/nock.c | 15 --------------- 4 files changed, 4 insertions(+), 19 deletions(-) diff --git a/jets/f/ut_mint.c b/jets/f/ut_mint.c index 0d0f54e397..117c9c0d16 100644 --- a/jets/f/ut_mint.c +++ b/jets/f/ut_mint.c @@ -153,7 +153,7 @@ if ( 0 == u3h(nug) ) { return u3k(u3t(nug)); } - else if ( (11 == u3h(nug)) || (13 == u3h(nug)) ) { + else if ( 11 == u3h(nug) ) { return _mint_cove(u3t(u3t(nug))); } else { diff --git a/jets/f/ut_mull.c b/jets/f/ut_mull.c index c22d91cf7a..760ebbf1f1 100644 --- a/jets/f/ut_mull.c +++ b/jets/f/ut_mull.c @@ -68,7 +68,7 @@ if ( 0 == u3h(nug) ) { return u3k(u3t(nug)); } - else if ( (11 == u3h(nug)) || (13 == u3h(nug)) ) { + else if ( 11 == u3h(nug) ) { return _mull_cove(u3t(u3t(nug))); } else { diff --git a/noun/jets.c b/noun/jets.c index 11df57d4ba..40405b543e 100644 --- a/noun/jets.c +++ b/noun/jets.c @@ -249,7 +249,7 @@ _cj_axis(u3_noun fol) { u3_noun p_fol, q_fol, r_fol; - while ( _(u3du(fol)) && ((11 == u3h(fol)) || (13 == u3h(fol))) ) + while ( _(u3du(fol)) && (11 == u3h(fol)) ) { fol = u3t(u3t(fol)); } if ( !_(u3r_trel(fol, &p_fol, &q_fol, &r_fol)) ) { @@ -436,7 +436,7 @@ _cj_je_fsck(u3_noun clu) if ( 0 == (nam_c = _cj_chum(p_clu)) ) { u3z(clu); return u3_none; } - while ( _(u3du(q_clu)) && ((11 == u3h(q_clu)) || (13 == u3h(q_clu))) ) { + while ( _(u3du(q_clu)) && (11 == u3h(q_clu)) ) { q_clu = u3t(u3t(q_clu)); } if ( !_(u3du(q_clu)) ) { diff --git a/noun/nock.c b/noun/nock.c index 23be93f0b3..459f6cb2e9 100644 --- a/noun/nock.c +++ b/noun/nock.c @@ -1289,21 +1289,6 @@ _n_comp(u3_noun* ops, u3_noun fol, c3_o los_o, c3_o tel_o) ++tot_w; _n_emit(ops, (c3y == los_o) ? WILS : WISH); break; - // temporary home for hint - case 13: - u3x_cell(arg, &hed, &tel); - tot_w += _n_bint(ops, hed, tel, los_o, tel_o); - break; - - // temporary home for wish - case 14: - u3x_cell(arg, &hed, &tel); - tot_w += _n_comp(ops, hed, c3n, c3n); - ++tot_w; _n_emit(ops, SWAP); - tot_w += _n_comp(ops, tel, c3n, c3n); - ++tot_w; _n_emit(ops, (c3y == los_o) ? WILS : WISH); - break; - default: u3m_bail(c3__exit); return 0; From 147941ba0774eb0c09ee7a5b79cbc2a1b0bbc7ea Mon Sep 17 00:00:00 2001 From: Joe Bryan Date: Wed, 10 Oct 2018 19:51:37 -0400 Subject: [PATCH 14/16] 6. implements edit at %10 (nock 4K) --- noun/nock.c | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/noun/nock.c b/noun/nock.c index b1af247b7a..69a4661d17 100644 --- a/noun/nock.c +++ b/noun/nock.c @@ -526,7 +526,7 @@ _n_nock_on(u3_noun bus, u3_noun fol) #define SLIB 70 #define SLIS 71 #define SAVE 72 -// nock 12 +// nock 10 #define MUTH 73 #define KUTH 74 #define MUTT 75 @@ -1302,20 +1302,7 @@ _n_comp(u3_noun* ops, u3_noun fol, c3_o los_o, c3_o tel_o) } break; - case 11: - u3x_cell(arg, &hed, &tel); - tot_w += _n_bint(ops, hed, tel, los_o, tel_o); - break; - - case 12: - u3x_cell(arg, &hed, &tel); - tot_w += _n_comp(ops, hed, c3n, c3n); - ++tot_w; _n_emit(ops, SWAP); - tot_w += _n_comp(ops, tel, c3n, c3n); - ++tot_w; _n_emit(ops, (c3y == los_o) ? WILS : WISH); - break; - - case 12: { + case 10: { u3_noun axe, nef; u3x_cell(arg, &hed, &tel); u3x_cell(hed, &axe, &nef); @@ -1347,6 +1334,19 @@ _n_comp(u3_noun* ops, u3_noun fol, c3_o los_o, c3_o tel_o) break; } + case 11: + u3x_cell(arg, &hed, &tel); + tot_w += _n_bint(ops, hed, tel, los_o, tel_o); + break; + + case 12: + u3x_cell(arg, &hed, &tel); + tot_w += _n_comp(ops, hed, c3n, c3n); + ++tot_w; _n_emit(ops, SWAP); + tot_w += _n_comp(ops, tel, c3n, c3n); + ++tot_w; _n_emit(ops, (c3y == los_o) ? WILS : WISH); + break; + default: u3m_bail(c3__exit); return 0; From 7507de1e6c2eec01a8d2fb41e8895864cbc26ede Mon Sep 17 00:00:00 2001 From: Joe Bryan Date: Wed, 10 Oct 2018 20:20:05 -0400 Subject: [PATCH 15/16] 7. updates %5 to require two subformulas (nock 4K) --- noun/nock.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/noun/nock.c b/noun/nock.c index 69a4661d17..adc1cf015e 100644 --- a/noun/nock.c +++ b/noun/nock.c @@ -1211,8 +1211,8 @@ _n_comp(u3_noun* ops, u3_noun fol, c3_o los_o, c3_o tel_o) u3x_cell(arg, &hed, &tel); if ( c3n == u3du(hed) ) { - tot_w += _n_comp(ops, arg, los_o, c3n); - ++tot_w; _n_emit(ops, SAMC); + u3m_bail(c3__exit); + return 0; } else { c3_t hec_t, tec_t; From 898beb29310508cd8a193ffe14483ce0f8b0113f Mon Sep 17 00:00:00 2001 From: Joe Bryan Date: Wed, 10 Oct 2018 20:25:23 -0400 Subject: [PATCH 16/16] 8. updates nock 4K spec --- Spec/nock/4.txt | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/Spec/nock/4.txt b/Spec/nock/4.txt index b6dafee9d9..3457d6bf65 100644 --- a/Spec/nock/4.txt +++ b/Spec/nock/4.txt @@ -1,5 +1,7 @@ A noun is an atom or a cell. An atom is a natural number. A cell is an ordered pair of nouns. +Reduce by the first matching pattern; variables match any noun. + nock(a) *a [a b c] [a [b c]] @@ -9,7 +11,6 @@ nock(a) *a +a 1 + a =[a a] 0 =[a b] 1 -=a =a /[1 a] a /[2 a b] a @@ -30,15 +31,15 @@ nock(a) *a *[a 2 b c] *[*[a b] *[a c]] *[a 3 b] ?*[a b] *[a 4 b] +*[a b] -*[a 5 b] =*[a b] +*[a 5 b c] =[*[a b] *[a c]] -*[a 6 b c d] *[a 2 [0 1] 2 [1 c d] [1 0] 2 [1 2 3] [1 0] 4 4 b] -*[a 7 b c] *[a 2 b 1 c] -*[a 8 b c] *[a 7 [[7 [0 1] b] 0 1] c] -*[a 9 b c] *[a 7 c 2 [0 1] 0 b] -*[a 10 [b c] d] *[a 8 c 7 [0 3] d] -*[a 10 b c] *[a c] -*[a 12 [b c] d] #[b *[a c] *[a d]] +*[a 6 b c d] *[a *[[c d] 0 *[[2 3] 0 *[a 4 4 b]]]] +*[a 7 b c] *[*[a b] c] +*[a 8 b c] *[[*[a b] a] c] +*[a 9 b c] *[*[a c] 2 [0 1] 0 b] +*[a 10 [b c] d] #[b *[a c] *[a d]] + +*[a 11 [b c] d] *[[*[a c] *[a d]] 0 3] +*[a 11 b c] *[a c] *a *a -