@@ -29,17 +29,17 @@ void step(val_t** to_curr, val_t** to_next, int count, int* t_back) {
2929 val_t * ptr_v ;
3030 for (i = 0 ; i < count ; i ++ ) {
3131 v = * * to_curr ;
32- ptr_v = val_unwrap (v );
3332 t = val_typeof (v );
3433 switch (t ) {
3534 case T_BOX :
3635 case T_CONS :
3736 case T_VECT :
3837 case T_STR :
38+ ptr_v = val_unwrap (v );
3939 if (ptr_v >= from && ptr_v < from + heap_size ) {
4040 // this is a pointer to from space so we need to deal with it
41- if (val_unwrap (* ptr_v ) >= to &&
42- val_unwrap (* ptr_v ) < to + heap_size ) {
41+ if (val_unwrap (* ptr_v ) >= to &&
42+ val_unwrap (* ptr_v ) < to + heap_size ) {
4343 // it points to a fwd pointer (points in to to-space), so just set
4444 // curr to what it points to.
4545 * * to_curr = * ptr_v ;
@@ -70,6 +70,10 @@ void step(val_t** to_curr, val_t** to_next, int count, int* t_back) {
7070
7171
7272int64_t * collect_garbage (int64_t * rsp , int64_t * rbp , int64_t * rbx ) {
73+
74+ printf ("Collect garbage: rsp = %" PRIx64 ", rbp = %" PRIx64 ", rbx = %" PRIx64 "\n" ,
75+ (int64_t )rsp , (int64_t )rbp , (int64_t )rbx );
76+
7377 int stack_count = rbp - rsp ;
7478
7579 val_t * tmp ;
@@ -82,7 +86,6 @@ int64_t* collect_garbage(int64_t* rsp, int64_t *rbp, int64_t* rbx) {
8286 // Step through everything on the stack
8387 val_t * rsp_curr = rsp ;
8488 step (& rsp_curr , & to_next , stack_count , & t_back );
85-
8689 int vi ;
8790 // now play catch up between to_curr and to_next
8891 while (to_curr != to_next ) {
@@ -139,8 +142,9 @@ int64_t* alloc_val(int64_t* rsp, int64_t* rbp, int64_t* rbx, int words) {
139142 rbx = collect_garbage (rsp , rbp , rbx );
140143 if (rbx + words >= from + heap_size ) {
141144 printf ("OUT OF MEMORY!!\n" );
142- exit ( 1 );
145+ error_handler ( );
143146 }
144147 }
148+ // printf("returning %" PRIx64 "\n", (int64_t)rbx);
145149 return rbx ;
146150}
0 commit comments