Skip to content

Commit a800961

Browse files
committed
fixed bug, missing Vectorof in root-type?
1 parent 1c6866a commit a800961

File tree

3 files changed

+91
-24
lines changed

3 files changed

+91
-24
lines changed

dynamic-typing.rkt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@
149149
(define/override (root-type? t)
150150
(match t
151151
[`Any #t]
152+
[`(Vectorof ,T) #t]
152153
[else (super root-type? t)]))
153154

154155
(define/override (uncover-call-live-roots-exp e)
@@ -165,10 +166,10 @@
165166
(match ty
166167
['Integer 1] ;; 001
167168
['Boolean 4] ;; 100
169+
['Void 5] ;; 101
168170
[`(Vector ,ts ...) 2] ;; 010
169171
[`(Vectorof ,t) 2]
170172
[`(,ts ... -> ,rt) 3] ;; 011
171-
['Void 5] ;; 101
172173
[else (error "in any-tag, unrecognized type" ty)]
173174
))
174175

@@ -232,7 +233,7 @@
232233
(andq (int ,any-mask) ,new-lhs)
233234
(if (eq? ,new-lhs (int ,(any-tag ty)))
234235
,(match ty
235-
[(or 'Integer 'Boolean)
236+
[(or 'Integer 'Boolean 'Void)
236237
;; booleans and integers
237238
`((movq ,new-e ,new-lhs)
238239
(sarq (int ,tag-len) ,new-lhs))]

runtime.c

Lines changed: 86 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,18 @@ static int initialized = 0;
2626
A '1' is a pointer, a '0' is not a pointer.
2727
*/
2828
static const int TAG_IS_NOT_FORWARD_MASK = 1;
29-
static const int TAG_LENGTH_MASK = 126;
29+
static const int TAG_LENGTH_MASK = 126; // 1111110
3030
static const int TAG_LENGTH_RSHIFT = 1;
3131
static const int TAG_PTR_BITFIELD_RSHIFT = 7;
3232

33+
static void print_vector(int64_t* vector_ptr);
34+
static void print_heap(int64_t** rootstack_ptr);
35+
36+
// cheney implements cheney's copying collection algorithm
37+
// There is a stub and explaination below.
38+
static void cheney(int64_t** rootstack_ptr);
39+
40+
3341
// Check to see if a tag is actually a forwarding pointer.
3442
static inline int is_forwarding(int64_t tag) {
3543
return !(tag & TAG_IS_NOT_FORWARD_MASK);
@@ -49,11 +57,11 @@ static inline int64_t get_ptr_bitfield(int64_t tag){
4957
// in dynamic-typing.rkt. -Jeremy
5058
static const int ANY_TAG_MASK = 7;
5159
static const int ANY_TAG_LEN = 3;
52-
static const int ANY_TAG_INT = 1;
53-
static const int ANY_TAG_BOOL = 4;
54-
static const int ANY_TAG_VEC = 2;
55-
static const int ANY_TAG_FUN = 3;
56-
static const int ANY_TAG_VOID = 5;
60+
static const int ANY_TAG_INT = 1; // 001
61+
static const int ANY_TAG_BOOL = 4; // 100
62+
static const int ANY_TAG_VEC = 2; // 010
63+
static const int ANY_TAG_FUN = 3; // 011
64+
static const int ANY_TAG_VOID = 5; // 101
5765
static const int ANY_TAG_PTR = 0; // not an any, a raw pointer
5866

5967
int any_tag(int64_t any) {
@@ -113,13 +121,12 @@ void initialize(uint64_t rootstack_size, uint64_t heap_size)
113121

114122
}
115123

116-
// cheney implements cheney's copying collection algorithm
117-
// There is a stub and explaination below.
118-
static void cheney(int64_t** rootstack_ptr);
119-
120124
void collect(int64_t** rootstack_ptr, uint64_t bytes_requested)
121125
{
122-
//printf("collecting, need %lld\n", bytes_requested);
126+
#if 0
127+
printf("collecting, need %lld\n", bytes_requested);
128+
print_heap(rootstack_ptr);
129+
#endif
123130

124131
// 1. Check our assumptions about the world
125132
assert(initialized);
@@ -169,8 +176,15 @@ void collect(int64_t** rootstack_ptr, uint64_t bytes_requested)
169176
unsigned long old_len = fromspace_end - fromspace_begin;
170177
unsigned long old_bytes = old_len * sizeof(int64_t);
171178
unsigned long new_bytes = old_bytes;
172-
173-
while (new_bytes < needed_bytes) new_bytes = 2 * new_bytes;
179+
180+
#if 1
181+
while (new_bytes < needed_bytes) {
182+
new_bytes = 2 * new_bytes;
183+
}
184+
#else
185+
// this version is good for debugging purposes -Jeremy
186+
new_bytes = needed_bytes;
187+
#endif
174188

175189
// Free and allocate a new tospace of size new_bytes
176190
free(tospace_begin);
@@ -239,7 +253,11 @@ void collect(int64_t** rootstack_ptr, uint64_t bytes_requested)
239253
}
240254
#endif
241255

242-
// printf("finished collecting\n\n");
256+
#if 0
257+
printf("finished collecting\n");
258+
print_heap(rootstack_ptr);
259+
printf("---------------------------------------\n");
260+
#endif
243261
} // collect
244262

245263
// copy_vector is responsible for doing a pointer oblivious
@@ -409,14 +427,16 @@ void cheney(int64_t** rootstack_ptr)
409427
*/
410428
void copy_vector(int64_t** vector_ptr_loc)
411429
{
412-
//printf("copy_vector %lld\n", (int64_t)*vector_ptr_loc);
413430

414431
int64_t* old_vector_ptr = *vector_ptr_loc;
415432
int old_tag = any_tag((int64_t)old_vector_ptr);
416433

417434
if (! is_ptr(old_vector_ptr))
418435
return;
419436
old_vector_ptr = to_ptr(old_vector_ptr);
437+
#if 0
438+
printf("copy_vector %lld\n", (int64_t)old_vector_ptr);
439+
#endif
420440

421441
int64_t tag = old_vector_ptr[0];
422442

@@ -432,7 +452,9 @@ void copy_vector(int64_t** vector_ptr_loc)
432452
*vector_ptr_loc = (int64_t*) (tag | old_tag);
433453

434454
} else {
435-
//printf("\tfirst time copy\n");
455+
#if 0
456+
printf("\tfirst time copy\n");
457+
#endif
436458
// This is the first time we have followed this pointer.
437459

438460
// Since we are about to jumble all the pointers around lets
@@ -441,12 +463,16 @@ void copy_vector(int64_t** vector_ptr_loc)
441463
// The tag we grabbed earlier contains some usefull info for
442464
// forwarding copying the vector.
443465
int length = get_length(tag);
444-
//printf("\tlen: %d\n", length);
466+
#if 0
467+
printf("\tlen: %d\n", length);
468+
#endif
445469

446470
// The new vector is going to be where the free int64_t pointer
447471
// currently points.
448472
int64_t* new_vector_ptr = free_ptr;
449-
//printf("\tto address: %lld\n", (int64_t)new_vector_ptr);
473+
#if 0
474+
printf("\tto address: %lld\n", (int64_t)new_vector_ptr);
475+
#endif
450476

451477
// Copy the old vector to the new one.
452478
// The "length" is the number of elements, so to include the
@@ -530,7 +556,7 @@ void print_any(int64_t any) {
530556
unsigned char len = get_length(tag);
531557
printf("#(");
532558
for (int i = 0; i != len; ++i) {
533-
print_any(vector_ptr[i + 1]);
559+
print_any(vector_ptr[i + 1]); // this is wrong -Jeremy
534560
}
535561
printf(")");
536562
break;
@@ -546,3 +572,44 @@ void print_any(int64_t any) {
546572
exit(-1);
547573
}
548574
}
575+
576+
void print_heap(int64_t** rootstack_ptr)
577+
{
578+
printf("rootstack len = %ld\n", rootstack_ptr - rootstack_begin);
579+
for (int64_t** root_loc = rootstack_begin;
580+
root_loc != rootstack_ptr;
581+
++root_loc) {
582+
if (is_ptr(*root_loc)) {
583+
print_vector(to_ptr(*root_loc));
584+
} else {
585+
printf("%lld", (int64_t)*root_loc);
586+
}
587+
printf("\n");
588+
}
589+
printf("\n");
590+
}
591+
592+
void print_vector(int64_t* vector_ptr)
593+
{
594+
int64_t tag = vector_ptr[0];
595+
unsigned char len = get_length(tag);
596+
int64_t* scan_ptr = vector_ptr;
597+
int64_t* next_ptr = vector_ptr + len + 1;
598+
599+
printf("%lld=#(", (int64_t)vector_ptr);
600+
scan_ptr += 1;
601+
int64_t isPointerBits = get_ptr_bitfield(tag);
602+
while (scan_ptr != next_ptr) {
603+
if ((isPointerBits & 1) == 1 && is_ptr((int64_t*)*scan_ptr)) {
604+
print_vector(to_ptr((int64_t*)*scan_ptr));
605+
} else {
606+
printf("%lld", (int64_t)*scan_ptr);
607+
}
608+
isPointerBits = isPointerBits >> 1;
609+
scan_ptr += 1;
610+
if (scan_ptr != next_ptr) {
611+
printf(", ");
612+
}
613+
}
614+
printf(")");
615+
}

tests/s7_5.rkt

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
(define (hello) 24)
22
(define (world) 24)
33
(let ([x (vector 0 0)])
4-
(let ([y (hello)])
5-
(let ([voidx (vector-set! x 0 y)])
4+
(let ([voidx (vector-set! x 0 (hello))])
65
(let ([voidy (vector-set! x 1 (world))])
76
(+ (- 6) (+ (vector-ref x 0) (vector-ref x 1)))
8-
))))
7+
)))
98

0 commit comments

Comments
 (0)