From 5c3223ba1f4bba7cb78e37c8ae3b2ebb81a5d142 Mon Sep 17 00:00:00 2001 From: "C. Guy Yarvin" Date: Thu, 31 Jul 2014 13:23:02 -0700 Subject: [PATCH] More memory pls. --- f/meme.c | 66 +++++++++++++++++++++++++++------- f/nock.c | 48 +++++++++++++++++++++++++ f/wire.c | 2 ++ include/c/motes.h | 1 + include/f/meme.h | 92 +++++++++++++++++++++++++++++++++++++++-------- v/term.c | 11 ++++++ 6 files changed, 194 insertions(+), 26 deletions(-) diff --git a/f/meme.c b/f/meme.c index ef9e14a16..f0d413e02 100644 --- a/f/meme.c +++ b/f/meme.c @@ -1,21 +1,63 @@ -/* f/rail.c +/* f/meme.c ** ** This file is in the public domain. */ #include "all.h" +#include +#include +#include +#include +#include +#include +#include "v/vere.h" -#ifdef U2_LEAK_DEBUG -c3_w COD_w; -#endif - - -//////// Basic allocation. - - -/* _me_box_make(): make a box. +/* _me_boot_north(): install a north road. */ -c3_w -_me_box_make() +static void +_me_boot_north(void* mem_v, c3_w len_w) +{ + for +} + +/* _me_boot_south(): install a south road. +/* u2_me_boot(): make u2R and u2H from nothing. +*/ +void +u2_me_boot(void* mem_v, c3_w len_w) +{ + c3_w* mem_w = mem_v; + + u2H = (u2_road*) mem_v; + memset(u2H, 0, sizeof(u2_road)); + + u2H->rut_w = (mem_w + c3_sizeof(u2_road)); + u2H->hat_w = u2H->rut_w; + + u2H->mat_w = (mem_w + len_w); + u2H->cap_w = u2H->mat_w; + + u2R = u2H; +} + +/* u2_me_leap(): advance to inner road. +*/ +void +u2_me_leap(void) +{ + + + + + + + + + + + + + + /* _me_free_slot(): select the right free list to search for a block. */ diff --git a/f/nock.c b/f/nock.c index a05b63988..28ff63a7e 100644 --- a/f/nock.c +++ b/f/nock.c @@ -3,6 +3,13 @@ ** This file is in the public domain. */ #include "all.h" +#include +#include +#include +#include +#include +#include +#include "v/vere.h" /** Types. **/ @@ -211,6 +218,47 @@ _nock_hint(u2_noun zep, // transfer return pro; } +#if 0 + case c3__leap: { + u2z(hod); + fprintf(stderr, "leaping!!\r\n"); + { + u2_noun hoe, tax; + + tax = u2_wire_tax(u2_Wire); + u2_wire_tax(u2_Wire) = u2_nul; + + u2_rl_leap(u2_Wire, c3__rock); + + if ( 0 != (hoe = u2_cm_trap()) ) { + u2_noun cod; + + u2_rl_fall(u2_Wire); + hoe = u2_rl_take(u2_Wire, hoe); + u2_rl_flog(u2_Wire); + + u2_wire_tax(u2_Wire) = u2_ckb_weld(u2k(u2t(hoe)), tax); + cod = u2k(u2h(hoe)); + + fprintf(stderr, "error in leap: %s\r\n", u2_cr_string(cod)); + return u2_cm_bail(cod); + } + else { + u2_noun pro = pon ? _nock_mool(bus, nex, pon) : _nock_cool(bus, nex); + + u2_cm_done(); + u2_rl_fall(u2_Wire); + pro = u2_rl_take(u2_Wire, pro); + u2_rl_flog(u2_Wire); + u2_wire_tax(u2_Wire) = tax; + + fprintf(stderr, "leapt!!\r\n"); + u2z(bus); u2z(nex); return pro; + } + } + } +#endif + case c3__memo: { u2z(hod); { diff --git a/f/wire.c b/f/wire.c index c3cf89e68..115388429 100644 --- a/f/wire.c +++ b/f/wire.c @@ -20,9 +20,11 @@ u2_wr_init(c3_m hip_m, { u2_ray wir_r; +#if 0 fprintf(stderr, "initial: hat_r %d, mat_r %d\r\n", hat_r >> LoomPageWords, mat_r >> LoomPageWords); +#endif wir_r = u2_rl_init(hip_m, hat_r, mat_r); u2_rail_hat_r(wir_r) += (c3_wiseof(u2_loom_wire) - c3_wiseof(u2_loom_rail)); diff --git a/include/c/motes.h b/include/c/motes.h index a7736d0d4..f5b1f9057 100644 --- a/include/c/motes.h +++ b/include/c/motes.h @@ -858,6 +858,7 @@ # define c3__rulf c3_s4('r','u','l','f') # define c3__run c3_s3('r','u','n') # define c3__safe c3_s4('s','a','f','e') +# define c3__sag c3_s3('s','a','g') # define c3__sail c3_s4('s','a','i','l') # define c3__same c3_s4('s','a','m','e') # define c3__sand c3_s4('s','a','n','d') diff --git a/include/f/meme.h b/include/f/meme.h index 6d01a0d09..d76f51dd2 100644 --- a/include/f/meme.h +++ b/include/f/meme.h @@ -13,9 +13,10 @@ # define u2_leak_off (COD_w = 0) # endif + /** Data structures. **/ - /* u2_me_box{}: classic allocation box. + /* u2_me_box: classic allocation box. ** ** The box size is also stored at the end of the box in classic ** bad ass malloc style. Hence a box is: @@ -39,7 +40,7 @@ # define u2_me_boxed(len_w) (len_w + c3_wiseof(u2_me_box) + 1) - /* u2_me_free{}: free node in heap. Sets minimum node size. + /* u2_me_free: free node in heap. Sets minimum node size. ** ** XXO: pre_u and nex_u should live in box. */ @@ -51,7 +52,40 @@ # define u2_me_minimum (c3_wiseof(u2_me_free)) - /* u2_me_road{}: allocation and execution context. + /* u2_me_road: contiguous allocation and execution context. + ** + ** The road can point in either direction. If cap > hat, it + ** looks like this ("north"): + ** + ** 0 rut hat ffff + ** | | | | + ** |~~~~~~~~~~~~-------##########################+++++++$~~~~~| + ** | | | | + ** 0 cap mat ffff + ** + ** Otherwise, it looks like this ("south"): + ** + ** 0 mat cap ffff + ** | | | | + ** |~~~~~~~~~~~~$++++++##########################--------~~~~~| + ** | | | | + ** 0 hat rut ffff + ** + ** Legend: - is durable storage (heap); + is temporary storage + ** (stack); ~ is deep storage (immutable); $ is the allocation block; + ** # is free memory. + ** + ** Pointer restrictions: pointers stored in + can point anywhere; + ** pointers in - can only point to - or ~; pointers in ~ can only + ** point to ~. + ** + ** To "leap" is to create a new inner road in the ### free space. + ** but in the reverse direction, so that when the inner road + ** "falls" (terminates), its durable storage is left on the + ** temporary storage of the outer road. + ** + ** In all cases, the pointer in a u2_noun is a word offset into + ** u2H, the top-level road. */ typedef struct _u2_me_road { struct _u2_me_road* par_u; // parent road @@ -66,7 +100,7 @@ struct { // allocation pools u2_me_free* fre_u[u2_me_free_no]; // heap by node size log # ifdef U2_MEMORY_DEBUG - c3_w liv_w; + c3_w liv_w; // number of live words # endif } all; @@ -78,11 +112,11 @@ u2_noun fly; // $+(* (unit)) } ski; - struct { // debug stack + struct { // trace stack u2_noun tax; // (list ,*) } bug; - struct { // profile stack + struct { // profiling stack u2_noun don; // (list ,*) } pro; @@ -92,29 +126,48 @@ } u2_me_road; typedef u2_me_road u2_road; + /** Globals. **/ - /* u2_Home / u2H: root of thread. + /* u2_Loom: base of loom, as a word pointer. + */ + c3_global c3_w* u2_Loom; +# define u2L u2_Loom; + + /* u2_Home / u2H: root of thread. Always north. */ c3_global u2_road* u2_Home; # define u2H u2_Home - /* u2_Road / u2R: current road. + /* u2_Road / u2R: current road (thread-local). */ c3_global u2_road* u2_Road; # define u2R u2_Road + /** Macros. + **/ +# define u2_me_is_north ((u2R->cap > u2R->hat) ? u2_yes : u2_no) +# define u2_me_is_south (!u2_me_is_north) + +# define u2_me_into(x) (((c3_w*)(void*)u2H) + (x)) +# define u2_me_outa(p) (((c3_w*)(void*)(p)) - (c3w*)(void*)u2H) + /** Functions. **/ - /** Arena configuration. - **/ - /* u2_me_boot(): make u2R and u2H from nothing. + /* u2_me_boot(): make u2R and u2H from `len` words at `mem`. */ void u2_me_boot(void* mem_v, c3_w len_w); + /* u2_me_grab(): garbage-collect memory. Assumes u2R == u2H. + */ + void + u2_me_grab(void); + /* u2_me_check(): checkpoint memory to file. + ** + ** Assumes u2R == u2H. */ void u2_me_check(void); @@ -129,7 +182,14 @@ void u2_me_leap(void); - /* u2_me_flog(): release the can, setting cap to mat. + /* u2_me_flog(): release inner-allocated storage. + ** + ** The proper sequence for inner allocation is: + ** + ** u2_me_leap(); + ** // allocate some inner stuff... + ** u2_me_fall(); + ** // inner stuff is still valid, but on cap */ void u2_me_flog(void); @@ -187,6 +247,7 @@ c3_w u2_me_refs(u2_noun som); + /* Atoms from proto-atoms. */ /* u2_me_slab(): create a length-bounded proto-atom. @@ -225,7 +286,8 @@ */ c3_w u2_me_sweep(c3_w liv_w); - + + /** Generic computation. **/ /* u2_me_nock_on(): produce .*(bus fol). @@ -284,7 +346,9 @@ /* u2_me_uniq(): uniquify with memo cache. */ - u2_weak u2_me_u + u2_weak + u2_me_uniq(u2_noun som); + /* u2_rl_find(): ** ** Cache search for function (0 means nock) and sample. diff --git a/v/term.c b/v/term.c index 784d5afc2..5182d98ae 100644 --- a/v/term.c +++ b/v/term.c @@ -1055,6 +1055,17 @@ _term_ef_blit(u2_utty* uty_u, case c3__sav: { _term_it_save(u2k(u2h(u2t(blt))), u2k(u2t(u2t(blt)))); } break; + + case c3__sag: { + u2_noun pib = u2k(u2t(u2t(blt))); + u2_noun jam; + + fprintf(stderr, "jamming...\r\n"); + jam = u2_cke_jam(pib); + fprintf(stderr, "jammed.\r\n"); + + _term_it_save(u2k(u2h(u2t(blt))), jam); + } break; } u2z(blt);