cleanup of the C files to make all ikptr->int casts ikptr->long int

This commit is contained in:
Abdulaziz Ghuloum 2008-01-01 04:24:36 -05:00
parent 1f5cef4940
commit 15ea12f915
13 changed files with 609 additions and 498 deletions

View File

@ -35,46 +35,47 @@
(fold convert-instruction '() ls)))
(define register-mapping
'([%eax 32 0]
[%ecx 32 1]
[%edx 32 2]
[%ebx 32 3]
[%esp 32 4]
[%ebp 32 5]
[%esi 32 6]
[%edi 32 7]
[%r8 64 0]
[%r9 64 1]
[%r10 64 2]
[%r11 64 3]
[%r12 64 4]
[%r13 64 5]
[%r14 64 6]
[%r15 64 7]
[%al 8 0]
[%cl 8 1]
[%dl 8 2]
[%bl 8 3]
[%ah 8 4]
[%ch 8 5]
[%dh 8 6]
[%bh 8 7]
[/0 0 0]
[/1 0 1]
[/2 0 2]
[/3 0 3]
[/4 0 4]
[/5 0 5]
[/6 0 6]
[/7 0 7]
[xmm0 xmm 0]
[xmm1 xmm 1]
[xmm2 xmm 2]
[xmm3 xmm 3]
[xmm4 xmm 4]
[xmm5 xmm 5]
[xmm6 xmm 6]
[xmm7 xmm 7]
;;; reg cls idx REX.R
'([%eax 32 0 #f]
[%ecx 32 1 #f]
[%edx 32 2 #f]
[%ebx 32 3 #f]
[%esp 32 4 #f]
[%ebp 32 5 #f]
[%esi 32 6 #f]
[%edi 32 7 #f]
[%r8 32 0 #t]
[%r9 32 1 #t]
[%r10 32 2 #t]
[%r11 32 3 #t]
[%r12 32 4 #t]
[%r13 32 5 #t]
[%r14 32 6 #t]
[%r15 32 7 #t]
[%al 8 0 #f]
[%cl 8 1 #f]
[%dl 8 2 #f]
[%bl 8 3 #f]
[%ah 8 4 #f]
[%ch 8 5 #f]
[%dh 8 6 #f]
[%bh 8 7 #f]
[/0 0 0 #f]
[/1 0 1 #f]
[/2 0 2 #f]
[/3 0 3 #f]
[/4 0 4 #f]
[/5 0 5 #f]
[/6 0 6 #f]
[/7 0 7 #f]
[xmm0 xmm 0 #f]
[xmm1 xmm 1 #f]
[xmm2 xmm 2 #f]
[xmm3 xmm 3 #f]
[xmm4 xmm 4 #f]
[xmm5 xmm 5 #f]
[xmm6 xmm 6 #f]
[xmm7 xmm 7 #f]
))
(define register-index
@ -108,6 +109,12 @@
(lambda (x)
(assq x register-mapping)))
(define reg-requires-REX?
(lambda (x)
(cond
[(assq x register-mapping) => cadddr]
[else (error 'reg-required-REX? "not a reg" x)])))
(define-syntax with-args
(syntax-rules (lambda)
[(_ x (lambda (a0 a1) b b* ...))
@ -371,18 +378,93 @@
(module ()
(define who 'assembler)
(define (REX.R bits ac)
(cons (fxlogor #b01000000 bits) ac))
(define (REX+r r ac)
(cond
[(reg-requires-REX? r) (REX.R #b001 ac)]
[else ac]))
(define (REX+RM r rm ac)
(define (C n ac)
(printf "CASE ~s\n" n)
(let f ([ac ac] [i 30])
(unless (or (null? ac) (= i 0))
(if (number? (car ac))
(printf " #x~x" (car ac))
(printf " ~s" (car ac)))
(f (cdr ac) (- i 1))))
(newline)
ac)
(cond
[(mem? rm)
(if (reg-requires-REX? r)
(with-args rm
(lambda (a0 a1)
(cond
[(and (imm? a0) (reg32? a1))
(if (reg-requires-REX? a1)
(C 0 (REX.R #b101 ac))
(C 1 (REX.R #b100 ac)))]
[(and (imm? a1) (reg32? a0))
(if (reg-requires-REX? a0)
(C 2 (REX.R #b101 ac))
(C 3 (REX.R #b100 ac)))]
[(and (reg32? a0) (reg32? a1))
(if (or (reg-requires-REX? a0) (reg-requires-REX? a1))
(error 'REX+RM "unhandled4" a0 a1)
(error 'REX+RM "unhandleda" a1))]
[(and (imm? a0) (imm? a1))
(error 'REX+RM "unhandledb" a1)]
[else (die 'REX+RM "unhandled" a0 a1)])))
(with-args rm
(lambda (a0 a1)
(cond
[(and (imm? a0) (reg32? a1))
(if (reg-requires-REX? a1)
(C 4 (REX.R #b001 ac))
ac)]
[(and (imm? a1) (reg32? a0))
(if (reg-requires-REX? a0)
(C 5 (REX.R #b001 ac))
ac)]
[(and (reg32? a0) (reg32? a1))
(if (reg-requires-REX? a0)
(if (reg-requires-REX? a1)
(error 'REX+RM "unhandled x1" a0 a1)
(C 6 (REX.R #b010 ac)))
(if (reg-requires-REX? a1)
(error 'REX+RM "unhandled x3" a0 a1)
ac))]
[(and (imm? a0) (imm? a1)) ac]
[else (die 'REX+RM "unhandled" a0 a1)]))))]
[(reg? rm)
(if (reg-requires-REX? r)
(if (reg-requires-REX? rm)
(C 7 (REX.R #b101 ac))
(C 8 (REX.R #b100 ac)))
(if (reg-requires-REX? rm)
(C 9 (REX.R #b001 ac))
ac))]
[else (die 'REX+RM "unhandled" rm)]))
(define (CR c r ac)
(CODE+r c r ac))
(REX+r r (CODE+r c r ac)))
(define (CR* c r rm ac)
(CODE c (RM r rm ac)))
(REX+RM r rm (CODE c (RM r rm ac))))
(define (CCR* c0 c1 r rm ac)
(CODE c0 (CODE c1 (RM r rm ac))))
(REX+RM r rm (CODE c0 (CODE c1 (RM r rm ac)))))
(define (CCR c0 c1 r ac)
(CODE c0 (CODE+r c1 r ac)))
(REX+r r (CODE c0 (CODE+r c1 r ac))))
(define (CCCR* c0 c1 c2 r rm ac)
(REX+RM r rm (CODE c0 (CODE c1 (CODE c2 (RM r rm ac))))))
(define (CCI32 c0 c1 i32 ac)
(CODE c0 (CODE c1 (IMM32 i32 ac))))
(define (CCCR* c0 c1 c2 r rm ac)
(CODE c0 (CODE c1 (CODE c2 (RM r rm ac)))))
(add-instructions instr ac
[(ret) (CODE #xC3 ac)]

View File

@ -1 +1 @@
1302
1303

View File

@ -25,11 +25,13 @@ _cpu_has_sse2:
# callee-save registers are $ebx, %esi, %edi, %esp, $ebp
# cpuid modifies %eax, %ebx, %ecx, %edx
# only %ebx needs to be saved/restored
# push %rbx
push %ebx
movl $1, %eax
cpuid
movl %edx, %eax
sarl $26, %eax
andl $1, %eax
# pop %rbx
pop %ebx
ret

View File

@ -377,8 +377,8 @@ ik_collect(int mem_req, ikpcb* pcb){
#endif
{ /* ACCOUNTING */
int bytes = ((int)pcb->allocation_pointer) -
((int)pcb->heap_base);
long int bytes = ((long int)pcb->allocation_pointer) -
((long int)pcb->heap_base);
add_to_collect_count(pcb, bytes);
}
@ -502,14 +502,14 @@ ik_collect(int mem_req, ikpcb* pcb){
old_heap_pages = 0;
}
int free_space =
((unsigned int)pcb->allocation_redline) -
((unsigned int)pcb->allocation_pointer);
long int free_space =
((unsigned long int)pcb->allocation_redline) -
((unsigned long int)pcb->allocation_pointer);
if((free_space <= mem_req) || (pcb->heap_size < IK_HEAPSIZE)){
#ifndef NDEBUG
fprintf(stderr, "REQ=%d, got %d\n", mem_req, free_space);
#endif
int memsize = (mem_req > IK_HEAPSIZE) ? mem_req : IK_HEAPSIZE;
long int memsize = (mem_req > IK_HEAPSIZE) ? mem_req : IK_HEAPSIZE;
memsize = align_to_next_page(memsize);
ik_munmap_from_segment(
pcb->heap_base,
@ -939,27 +939,27 @@ add_code_entry(gc_t* gc, ikptr entry){
static void collect_stack(gc_t* gc, ikptr top, ikptr end){
if(DEBUG_STACK){
fprintf(stderr, "collecting stack from 0x%08x .. 0x%08x\n",
(int) top, (int) end);
fprintf(stderr, "collecting stack from 0x%016lx .. 0x%016lx\n",
(long int) top, (long int) end);
}
while(top < end){
if(DEBUG_STACK){
fprintf(stderr, "collecting frame at 0x%08x: ", (int) top);
fprintf(stderr, "collecting frame at 0x%016lx: ", (long int) top);
}
ikptr rp = ref(top, 0);
int rp_offset = unfix(ref(rp, disp_frame_offset));
long int rp_offset = unfix(ref(rp, disp_frame_offset));
if(DEBUG_STACK){
fprintf(stderr, "rp_offset=%d\n", rp_offset);
fprintf(stderr, "rp_offset=%ld\n", rp_offset);
}
if(rp_offset <= 0){
fprintf(stderr, "invalid rp_offset %d\n", rp_offset);
fprintf(stderr, "invalid rp_offset %ld\n", rp_offset);
exit(-1);
}
/* since the return point is alive, we need to find the code
* object containing it and mark it live as well. the rp is
* updated to reflect the new code object. */
int code_offset = rp_offset - disp_frame_offset;
long int code_offset = rp_offset - disp_frame_offset;
ikptr code_entry = rp - code_offset;
ikptr new_code_entry = add_code_entry(gc, code_entry);
ikptr new_rp = new_code_entry + code_offset;
@ -999,18 +999,18 @@ static void collect_stack(gc_t* gc, ikptr top, ikptr end){
* there is no live mask in this case, instead all values in the
* frame are live.
*/
int framesize = (int) ref(rp, disp_frame_size);
long int framesize = (long int) ref(rp, disp_frame_size);
if(DEBUG_STACK){
fprintf(stderr, "fs=%d\n", framesize);
fprintf(stderr, "fs=%ld\n", framesize);
}
if(framesize < 0){
fprintf(stderr, "invalid frame size %d\n", framesize);
fprintf(stderr, "invalid frame size %ld\n", framesize);
exit(-1);
}
else if(framesize == 0){
framesize = (int)ref(top, wordsize);
framesize = (long int)ref(top, wordsize);
if(framesize <= 0){
fprintf(stderr, "invalid redirected framesize=%d\n", framesize);
fprintf(stderr, "invalid redirected framesize=%ld\n", framesize);
exit(-1);
}
ikptr base = top + framesize - wordsize;
@ -1020,12 +1020,12 @@ static void collect_stack(gc_t* gc, ikptr top, ikptr end){
base -= wordsize;
}
} else {
int frame_cells = framesize >> fx_shift;
int bytes_in_mask = (frame_cells+7) >> 3;
long int frame_cells = framesize >> fx_shift;
long int bytes_in_mask = (frame_cells+7) >> 3;
char* mask = rp + disp_frame_size - bytes_in_mask;
ikptr* fp = (ikptr*)(top + framesize);
int i;
long int i;
for(i=0; i<bytes_in_mask; i++, fp-=8){
unsigned char m = mask[i];
#if DEBUG_STACK
@ -1044,8 +1044,8 @@ static void collect_stack(gc_t* gc, ikptr top, ikptr end){
top += framesize;
}
if(top != end){
fprintf(stderr, "frames did not match up 0x%08x .. 0x%08x\n",
(int) top, (int) end);
fprintf(stderr, "frames did not match up 0x%016lx .. 0x%016lx\n",
(long int) top, (long int) end);
exit(-1);
}
if(DEBUG_STACK){
@ -1158,12 +1158,12 @@ add_object_proc(gc_t* gc, ikptr x)
}
#endif
else if(tag == closure_tag){
int size = disp_closure_data+
(int) ref(fst, disp_code_freevars - disp_code_data);
long int size = disp_closure_data+
(long int) ref(fst, disp_code_freevars - disp_code_data);
if(size > 1024){
fprintf(stderr, "large closure size=0x%08x\n", size);
fprintf(stderr, "large closure size=0x%016lx\n", size);
}
int asize = align(size);
long int asize = align(size);
ikptr y = gc_alloc_new_ptr(asize, gc) + closure_tag;
ref(y, asize-closure_tag-wordsize) = 0;
memcpy(y-closure_tag, x-closure_tag, size);
@ -1179,9 +1179,9 @@ add_object_proc(gc_t* gc, ikptr x)
if(is_fixnum(fst)){
/* real vector */
//fprintf(stderr, "X=0x%08x, FST=0x%08x\n", (int)x, (int)fst);
int size = (int)fst;
long int size = (long int)fst;
assert(size >= 0);
int memreq = align(size + disp_vector_data);
long int memreq = align(size + disp_vector_data);
if(memreq >= pagesize){
if((t & large_object_mask) == large_object_tag){
enqueue_large_ptr(x-vector_tag, size+disp_vector_data, gc);
@ -1223,7 +1223,7 @@ add_object_proc(gc_t* gc, ikptr x)
}
else if(tagof(fst) == rtd_tag){
/* struct / record */
int size = (int) ref(fst, off_rtd_length);
long int size = (long int) ref(fst, off_rtd_length);
if(size & ((1<<align_shift)-1)) {
/* size = n * object_alignment + 4 =>
memreq = n * object_alignment + 8
@ -1231,7 +1231,7 @@ add_object_proc(gc_t* gc, ikptr x)
ikptr y = gc_alloc_new_ptr(size+wordsize, gc) + vector_tag;
ref(y, -vector_tag) = fst;
{
int i;
long int i;
ikptr p = y+disp_record_data-vector_tag;
ikptr q = x+disp_record_data-vector_tag;
ref(p, 0) = ref(q, 0);
@ -1249,7 +1249,7 @@ add_object_proc(gc_t* gc, ikptr x)
ikptr y = gc_alloc_new_ptr(size+(2*wordsize), gc) + vector_tag;
ref(y, -vector_tag) = fst;
{
int i;
long int i;
ikptr p = y+disp_record_data-vector_tag;
ikptr q = x+disp_record_data-vector_tag;
for(i=0; i<size; i+=(2*wordsize)){
@ -1270,7 +1270,7 @@ add_object_proc(gc_t* gc, ikptr x)
}
else if(fst == continuation_tag){
ikptr top = ref(x, off_continuation_top);
int size = (int) ref(x, off_continuation_size);
long int size = (long int) ref(x, off_continuation_size);
#ifndef NDEBUG
if(size > 4096){
fprintf(stderr, "large cont size=0x%08x\n", size);
@ -1311,7 +1311,7 @@ add_object_proc(gc_t* gc, ikptr x)
ref(x, wordsize-vector_tag) = y;
return y;
}
else if((((int)fst) & port_mask) == port_tag){
else if((((long int)fst) & port_mask) == port_tag){
ikptr y = gc_alloc_new_ptr(port_size, gc) + vector_tag;
ref(y, -vector_tag) = fst;
int i;
@ -1330,9 +1330,9 @@ add_object_proc(gc_t* gc, ikptr x)
ref(x, wordsize-vector_tag) = new;
return new;
}
else if((((int)fst) & bignum_mask) == bignum_tag){
int len = ((unsigned int)fst) >> bignum_length_shift;
int memreq = align(disp_bignum_data + len*wordsize);
else if((((long int)fst) & bignum_mask) == bignum_tag){
long int len = ((unsigned long int)fst) >> bignum_length_shift;
long int memreq = align(disp_bignum_data + len*wordsize);
ikptr new = gc_alloc_new_data(memreq, gc) + vector_tag;
memcpy(new-vector_tag, x-vector_tag, memreq);
ref(x, -vector_tag) = forward_ptr;
@ -1351,15 +1351,16 @@ add_object_proc(gc_t* gc, ikptr x)
return y;
}
else {
fprintf(stderr, "unhandled vector with fst=0x%08x\n", (int)fst);
fprintf(stderr, "unhandled vector with fst=0x%016lx\n",
(long int)fst);
assert(0);
exit(-1);
}
}
else if(tag == string_tag){
if(is_fixnum(fst)){
int strlen = unfix(fst);
int memreq = align(strlen*string_char_size + disp_string_data);
long int strlen = unfix(fst);
long int memreq = align(strlen*string_char_size + disp_string_data);
ikptr new_str = gc_alloc_new_data(memreq, gc) + string_tag;
ref(new_str, off_string_length) = fst;
memcpy(new_str+off_string_data,
@ -1373,14 +1374,14 @@ add_object_proc(gc_t* gc, ikptr x)
return new_str;
}
else {
fprintf(stderr, "unhandled string 0x%08x with fst=0x%08x\n",
(int)x, (int)fst);
fprintf(stderr, "unhandled string 0x%016lx with fst=0x%016lx\n",
(long int)x, (long int)fst);
exit(-1);
}
}
else if(tag == bytevector_tag){
int len = unfix(fst);
int memreq = align(len + disp_bytevector_data + 1);
long int len = unfix(fst);
long int memreq = align(len + disp_bytevector_data + 1);
ikptr new_bv = gc_alloc_new_data(memreq, gc) + bytevector_tag;
ref(new_bv, off_bytevector_length) = fst;
memcpy(new_bv+off_bytevector_data,
@ -1401,14 +1402,14 @@ relocate_new_code(ikptr x, gc_t* gc){
ref(x, disp_code_reloc_vector) = relocvector;
ref(x, disp_code_annotation) =
add_object(gc, ref(x, disp_code_annotation), "annotation");
int relocsize = (int)ref(relocvector, off_vector_length);
long int relocsize = (long int)ref(relocvector, off_vector_length);
ikptr p = relocvector + off_vector_data;
ikptr q = p + relocsize;
ikptr code = x + disp_code_data;
while(p < q){
int r = unfix(ref(p, 0));
int tag = r & 3;
int code_off = r >> 2;
long int r = unfix(ref(p, 0));
long int tag = r & 3;
long int code_off = r >> 2;
if(tag == 0){
/* undisplaced pointer */
#ifndef NDEBUG
@ -1422,7 +1423,7 @@ relocate_new_code(ikptr x, gc_t* gc){
}
else if(tag == 2){
/* displaced pointer */
int obj_off = unfix(ref(p, wordsize));
long int obj_off = unfix(ref(p, wordsize));
ikptr old_object = ref(p, 2*wordsize);
ikptr new_object = add_object(gc, old_object, "reloc2");
ref(code, code_off) = new_object + obj_off;
@ -1430,7 +1431,7 @@ relocate_new_code(ikptr x, gc_t* gc){
}
else if(tag == 3){
/* displaced relative pointer */
int obj_off = unfix(ref(p, wordsize));
long int obj_off = unfix(ref(p, wordsize));
ikptr obj = ref(p, 2*wordsize);
#ifndef NDEBUG
//fprintf(stderr, "obj=0x%08x, obj_off=0x%08x\n", (int)obj,
@ -1439,7 +1440,7 @@ relocate_new_code(ikptr x, gc_t* gc){
obj = add_object(gc, obj, "reloc3");
ikptr displaced_object = obj + obj_off;
ikptr next_word = code + code_off + wordsize;
ikptr relative_distance = displaced_object - (int)next_word;
ikptr relative_distance = displaced_object - (long int)next_word;
ref(next_word, -wordsize) = relative_distance;
p += (3*wordsize);
}
@ -1448,7 +1449,7 @@ relocate_new_code(ikptr x, gc_t* gc){
p += (2 * wordsize);
}
else {
fprintf(stderr, "invalid rtag %d in 0x%08x\n", tag, r);
fprintf(stderr, "invalid rtag %ld in 0x%016lx\n", tag, r);
exit(-1);
}
}
@ -1665,9 +1666,9 @@ static void
fix_weak_pointers(gc_t* gc){
unsigned int* segment_vec = gc->segment_vector;
ikpcb* pcb = gc->pcb;
int lo_idx = page_index(pcb->memory_base);
int hi_idx = page_index(pcb->memory_end);
int i = lo_idx;
long int lo_idx = page_index(pcb->memory_base);
long int hi_idx = page_index(pcb->memory_end);
long int i = lo_idx;
int collect_gen = gc->collect_gen;
while(i < hi_idx){
unsigned int t = segment_vec[i];
@ -1721,7 +1722,7 @@ static unsigned int cleanup_mask[generation_count] = {
static void
scan_dirty_pointers_page(gc_t* gc, int page_idx, int mask){
scan_dirty_pointers_page(gc_t* gc, long int page_idx, int mask){
unsigned int* segment_vec = gc->segment_vector;
unsigned int* dirty_vec = gc->pcb->dirty_vector;
unsigned int t = segment_vec[page_idx];
@ -1760,7 +1761,7 @@ scan_dirty_pointers_page(gc_t* gc, int page_idx, int mask){
}
static void
scan_dirty_code_page(gc_t* gc, int page_idx, unsigned int mask){
scan_dirty_code_page(gc_t* gc, long int page_idx, unsigned int mask){
ikptr p = (ikptr)(page_idx << pageshift);
ikptr start = p;
ikptr q = p + pagesize;
@ -1775,15 +1776,15 @@ scan_dirty_code_page(gc_t* gc, int page_idx, unsigned int mask){
p = q;
}
else {
int j = ((int)p - (int)start) / cardsize;
int code_size = unfix(ref(p, disp_code_code_size));
long int j = ((long int)p - (long int)start) / cardsize;
long int code_size = unfix(ref(p, disp_code_code_size));
relocate_new_code(p, gc);
segment_vec = gc->segment_vector;
ikptr rvec = ref(p, disp_code_reloc_vector);
int len = (int)ref(rvec, off_vector_length);
long int len = (long int)ref(rvec, off_vector_length);
assert(len >= 0);
int i;
unsigned int code_d = segment_vec[page_index(rvec)];
long int i;
unsigned long int code_d = segment_vec[page_index(rvec)];
for(i=0; i<len; i+=wordsize){
ikptr r = ref(rvec, i+off_vector_data);
if(is_fixnum(r) || (tagof(r) == immediate_tag)){
@ -1865,9 +1866,9 @@ deallocate_unused_pages(gc_t* gc){
unsigned int* segment_vec = pcb->segment_vector;
char* memory_base = pcb->memory_base;
char* memory_end = pcb->memory_end;
int lo_idx = page_index(memory_base);
int hi_idx = page_index(memory_end);
int i = lo_idx;
long int lo_idx = page_index(memory_base);
long int hi_idx = page_index(memory_end);
long int i = lo_idx;
while(i < hi_idx){
unsigned int t = segment_vec[i];
if(t & dealloc_mask){

View File

@ -92,6 +92,7 @@ inthash(int key) {
#define generation_count 5 /* generations 0 (nursery), 1, 2, 3, 4 */
typedef char* ikptr;
typedef int ikchar;
void ik_error(ikptr args);
@ -238,29 +239,25 @@ ikptr ik_safe_alloc(ikpcb* pcb, int size);
#define IK_FX_MASK 3
#define fx_shift 2
#define fx_mask 3
#define unfix(x) (((int)(x)) >> fx_shift)
#define fix(x) ((ikptr)((x) << fx_shift))
#define is_fixnum(x) ((((int)(x)) & fx_mask) == 0)
#define unfix(x) (((long int)(x)) >> fx_shift)
#define fix(x) ((ikptr)(((long int)(x)) << fx_shift))
#define is_fixnum(x) ((((long int)(x)) & fx_mask) == 0)
#define IK_FIXNUMP(x) \
((((int)(x)) & IK_FX_MASK) == 0)
#define REF(x,n) \
(((ikptr*)(((char*)(x)) + ((int)(n))))[0])
#define ref(x,n) \
(((ikptr*)(((char*)(x)) + ((int)(n))))[0])
(((ikptr*)(((char*)(x)) + ((long int)(n))))[0])
#define IK_MASK(x,m) (((int)(x)) & ((int)(m)))
#define IK_MASK(x,m) (((long int)(x)) & ((long int)(m)))
#define IK_PTAG(x) (((int)(x)) & 7)
#define tagof(x) (((int)(x)) & 7)
#define tagof(x) (((long int)(x)) & 7)
#define IK_STAG(x) REF(x, -IK_PTAG(x))
#define immediate_tag 7
#define IK_UNFIX(x) (((int)(x)) >> IK_FX_SHIFT)
#define IK_FIX(x) ((ikptr)((x) << IK_FX_SHIFT))
#define fix(x) ((ikptr)((x) << fx_shift))
#define IK_CODE_P(x) \
((IK_PTAG(x) == IK_CODE_PRI_TAG) && (IK_STAG(x) == IK_CODE_SEC_TAG))
@ -282,9 +279,11 @@ ikptr ik_safe_alloc(ikpcb* pcb, int size);
#define IK_CHAR_MASK 0xFF
#define IK_CHAR_SHIFT 8
#define IK_CHAR_VAL(x) (((int)(x)) >> IK_CHAR_SHIFT)
#define int_to_scheme_char(x) ((ikptr)(((x) << IK_CHAR_SHIFT) | IK_CHAR_TAG))
#define int_to_scheme_char(x) \
((ikptr)((((unsigned long int)(x)) << IK_CHAR_SHIFT) | IK_CHAR_TAG))
#define IK_PAIR_SIZE 8
#define pair_size 8
#define pair_mask 7
#define pair_tag 1
#define disp_car 0
#define disp_cdr 4
@ -299,6 +298,7 @@ ikptr ik_safe_alloc(ikpcb* pcb, int size);
#define IK_HEAPSIZE (1024 * 4096) /* 4 MB */
#define IK_PAIRP(x) (IK_PTAG(x) == IK_PAIR_TAG)
#define IK_CHARP(x) (IK_MASK(x,IK_CHAR_MASK) == IK_CHAR_TAG)
#define is_char(x) (IK_MASK(x,IK_CHAR_MASK) == IK_CHAR_TAG)
#define IK_STRING_TAG 6
#define string_tag 6
#define disp_string_length 0
@ -311,8 +311,9 @@ ikptr ik_safe_alloc(ikpcb* pcb, int size);
// ((((unsigned char*)(x)) + off_string_data + (int)(i))[0] =
// (((int)(c)) >> IK_CHAR_SHIFT))
#define string_set(x,i,c) \
(((ikptr*)(((ikptr)(x)) + off_string_data))[i] = ((ikptr)(c)))
#define integer_to_char(x) ((ikptr)((((int)(x)) << IK_CHAR_SHIFT) + IK_CHAR_TAG))
(((ikchar*)(((ikptr)(x)) + off_string_data))[i] = ((ikchar)(c)))
#define integer_to_char(x) \
((ikchar)((((int)(x)) << IK_CHAR_SHIFT) + IK_CHAR_TAG))
#define string_char_size 4
#define vector_tag 5
@ -370,7 +371,8 @@ ikptr ik_safe_alloc(ikpcb* pcb, int size);
#define off_closure_code (disp_closure_code - closure_tag)
#define off_closure_data (disp_closure_data - closure_tag)
#define is_closure(x) ((((int)(x)) & closure_mask) == closure_tag)
#define is_closure(x) ((((long int)(x)) & closure_mask) == closure_tag)
#define is_pair(x) ((((long int)(x)) & pair_mask) == pair_tag)
#define record_tag vector_tag
@ -408,9 +410,9 @@ ikptr ik_safe_alloc(ikpcb* pcb, int size);
#define pagesize 4096
#define pageshift 12
#define align_to_next_page(x) \
(((pagesize - 1 + (unsigned int)(x)) >> pageshift) << pageshift)
(((pagesize - 1 + (unsigned long int)(x)) >> pageshift) << pageshift)
#define align_to_prev_page(x) \
((((unsigned int)(x)) >> pageshift) << pageshift)
((((unsigned long int)(x)) >> pageshift) << pageshift)
#define disp_frame_size -17
@ -450,6 +452,6 @@ ikptr ik_safe_alloc(ikpcb* pcb, int size);
#define disp_ratnum_unused 12
#define ik_eof_p(x) ((x) == ik_eof_object)
#define page_index(x) (((unsigned int)(x)) >> pageshift)
#define page_index(x) (((unsigned long int)(x)) >> pageshift)
#endif

View File

@ -117,22 +117,25 @@ check_ecx:
je L_one
cmpl $0, %ecx
je L_two
pushl $0
push $0
L_two:
pushl $0
push $0
L_one:
pushl $0
push $0
L_zero:
pushl %esi # (pushl pcr)
# push %rsi # (pushl pcr)
push %esi # (pushl pcr)
cmpl $0, %eax # (cmpl (int 0) eax)
je L_set # (je (label Lset))
L_loop: # (label Lloop)
movl (%ebx,%eax), %ecx # (movl (mem ebx eax) ecx)
pushl %ecx # (pushl ecx)
# push %rcx # (pushl ecx)
push %ecx # (pushl ecx)
addl $4, %eax # (addl (int 4) eax)
cmpl $0, %eax # (cmpl (int 0) eax)
jne L_loop # (jne (label Lloop))
L_set: # (label Lset)
# call *%rdi # (call cpr)
call *%edi # (call cpr)
movl 8(%esi), %esp # (movl (pcb-ref 'frame-pointer) fpr)
movl 0(%esi), %ebp # (movl (pcb-ref 'allocation-pointer) apr)

View File

@ -37,9 +37,9 @@ ikptr ik_exec_code(ikpcb* pcb, ikptr code_ptr){
cont* k = (cont*)(next_k - vector_tag);
ikptr top = k->top;
ikptr rp = ref(top, 0);
int framesize = (int) ref(rp, disp_frame_size);
long int framesize = (long int) ref(rp, disp_frame_size);
if(framesize <= 0){
fprintf(stderr, "invalid framesize %d\n", framesize);
fprintf(stderr, "invalid framesize %ld\n", framesize);
exit(-1);
}
if(framesize < k->size){
@ -51,15 +51,15 @@ ikptr ik_exec_code(ikpcb* pcb, ikptr code_ptr){
k->size = framesize;
k->next = vector_tag + (ikptr)nk;
/* record side effect */
unsigned int idx = ((unsigned int)(&k->next)) >> pageshift;
unsigned long int idx = ((unsigned long int)(&k->next)) >> pageshift;
pcb->dirty_vector[idx] = -1;
}
pcb->next_k = k->next;
ikptr fbase = pcb->frame_base - wordsize;
ikptr new_fbase = fbase - framesize;
memmove(new_fbase + (int)argc,
fbase + (int)argc,
-(int)argc);
memmove(new_fbase + (long int)argc,
fbase + (long int)argc,
-(long int)argc);
memcpy(new_fbase, top, framesize);
argc = ik_asm_reenter(pcb, new_fbase, argc);
next_k = pcb->next_k;

View File

@ -126,8 +126,8 @@ void ik_fasl_load(ikpcb* pcb, char* fasl_file){
}
static ikptr
alloc_code(int size, ikpcb* pcb, fasl_port* p){
int asize = align(size);
alloc_code(long int size, ikpcb* pcb, fasl_port* p){
long int asize = align(size);
ikptr ap = p->code_ap;
ikptr nap = ap + asize;
if(nap <= p->code_ep){
@ -135,9 +135,9 @@ alloc_code(int size, ikpcb* pcb, fasl_port* p){
return ap;
} else if (asize < pagesize){
ikptr mem = ik_mmap_code(pagesize, 0, pcb);
int bytes_remaining = pagesize - asize;
int previous_bytes =
((unsigned int)p->code_ep) - ((unsigned int)ap);
long int bytes_remaining = pagesize - asize;
long int previous_bytes =
((unsigned long int)p->code_ep) - ((unsigned long int)ap);
if(bytes_remaining <= previous_bytes){
return mem;
} else {
@ -146,7 +146,7 @@ alloc_code(int size, ikpcb* pcb, fasl_port* p){
return mem;
}
} else {
int asize = align_to_next_page(size);
long int asize = align_to_next_page(size);
ikptr mem = ik_mmap_code(asize, 0, pcb);
return mem;
}
@ -159,15 +159,15 @@ ik_relocate_code(ikptr code){
ikptr size = ref(vec, off_vector_length);
ikptr data = code + disp_code_data;
ikptr p = vec + off_vector_data;
ikptr q = p + (int)size;
ikptr q = p + (long int)size;
while(p < q){
int r = unfix(ref(p, 0));
long int r = unfix(ref(p, 0));
if(r == 0){
fprintf(stderr, "unset reloc!\n");
exit(-1);
}
int tag = r & 3;
int code_off = r >> 2;
long int tag = r & 3;
long int code_off = r >> 2;
if(tag == 0){
/* vanilla object */
ref(data, code_off) = ref(p, wordsize);
@ -175,18 +175,18 @@ ik_relocate_code(ikptr code){
}
else if(tag == 2){
/* displaced object */
int obj_off = unfix(ref(p, wordsize));
long int obj_off = unfix(ref(p, wordsize));
ikptr obj = ref(p, 2*wordsize);
ref(data, code_off) = obj + obj_off;
p += (3*wordsize);
}
else if(tag == 3){
/* jump label */
int obj_off = unfix(ref(p, wordsize));
long int obj_off = unfix(ref(p, wordsize));
ikptr obj = ref(p, 2*wordsize);
ikptr displaced_object = obj + obj_off;
ikptr next_word = data + code_off + wordsize;
ikptr relative_distance = displaced_object - (int)next_word;
ikptr relative_distance = displaced_object - (long int)next_word;
ref(next_word, -wordsize) = relative_distance;
p += (3*wordsize);
}
@ -211,7 +211,7 @@ ik_relocate_code(ikptr code){
p += (2*wordsize);
}
else {
fprintf(stderr, "invalid reloc 0x%08x (tag=%d)\n", r, tag);
fprintf(stderr, "invalid reloc 0x%016lx (tag=%ld)\n", r, tag);
exit(-1);
}
}
@ -325,7 +325,7 @@ static ikptr do_read(ikpcb* pcb, fasl_port* p){
fasl_read_buf(p, str+off_string_data, len);
{
unsigned char* pi = (unsigned char*) (str+off_string_data);
ikptr* pj = (ikptr*) (str+off_string_data);
ikchar* pj = (ikchar*) (str+off_string_data);
int i = len-1;
for(i=len-1; i >= 0; i--){
pj[i] = integer_to_char(pi[i]);
@ -339,15 +339,15 @@ static ikptr do_read(ikpcb* pcb, fasl_port* p){
}
else if(c == 'S'){
/* string */
int len;
fasl_read_buf(p, &len, sizeof(int));
long int len;
fasl_read_buf(p, &len, sizeof(long int));
int size = align(len*string_char_size + disp_string_data);
ikptr str = ik_unsafe_alloc(pcb, size) + string_tag;
ref(str, off_string_length) = fix(len);
int i;
long int i;
for(i=0; i<len; i++){
int c;
fasl_read_buf(p, &c, sizeof(int));
ikchar c;
fasl_read_buf(p, &c, sizeof(ikchar));
string_set(str, i, integer_to_char(c));
}
//str[off_string_data+len*string_char_size] = 0;
@ -387,6 +387,7 @@ static ikptr do_read(ikpcb* pcb, fasl_port* p){
return IK_NULL_OBJECT;
}
else if(c == 'c'){
/* FIXME: sounds broken */
unsigned char x = (unsigned char) fasl_read_byte(p);
return int_to_scheme_char(x);
}
@ -549,7 +550,7 @@ static ikptr do_read(ikpcb* pcb, fasl_port* p){
fprintf(stderr, "Error in fasl-read: invalid bignum length %d\n", len);
exit(-1);
}
unsigned int tag = bignum_tag | (sign << bignum_sign_shift) |
unsigned long int tag = bignum_tag | (sign << bignum_sign_shift) |
((len >> 2) << bignum_length_shift);
ikptr x = ik_unsafe_alloc(pcb, align(len + disp_bignum_data)) + vector_tag;
ref(x, -vector_tag) = (ikptr) tag;

File diff suppressed because it is too large Load Diff

View File

@ -33,7 +33,7 @@ void ik_print(ikptr x){
fprintf(stdout, "\n");
}
static char* char_string[128] = {
char* char_string[128] = {
"#\\nul","#\\soh","#\\stx","#\\etx","#\\eot","#\\enq","#\\ack","#\\bel",
"#\\bs", "#\\tab","#\\newline", "#\\vt", "#\\ff", "#\\return", "#\\so",
"#\\si",
@ -57,10 +57,10 @@ static char* char_string[128] = {
static void
print(FILE* fh, ikptr x){
if(IK_FIXNUMP(x)){
fprintf(fh, "%d", IK_UNFIX(x));
if(is_fixnum(x)){
fprintf(fh, "%ld", unfix(x));
}
else if(x == IK_FALSE_OBJECT){
else if(x == false_object){
fprintf(fh, "#f");
}
else if(x == IK_TRUE_OBJECT){
@ -69,8 +69,8 @@ print(FILE* fh, ikptr x){
else if(x == IK_NULL_OBJECT){
fprintf(fh, "()");
}
else if(IK_CHARP(x)){
fprintf(fh, "%s", char_string[IK_CHAR_VAL(x)]);
else if(is_char(x)){
fprintf(fh, "X");
}
#if 0
else if(tagof(x) == symbol_tag){
@ -98,16 +98,16 @@ print(FILE* fh, ikptr x){
else if(is_closure(x)){
fprintf(fh, "#<procedure>");
}
else if(IK_PAIRP(x)){
else if(is_pair(x)){
fprintf(fh, "(");
print(fh, REF(x, IK_OFF_CAR));
ikptr d = REF(x, IK_OFF_CDR);
fprintf(stderr, "d=0x%08x\n", (int)d);
print(fh, ref(x, IK_OFF_CAR));
ikptr d = ref(x, IK_OFF_CDR);
fprintf(stderr, "d=0x%016lx\n", (long int)d);
while(1){
if(IK_PAIRP(d)){
if(is_pair(d)){
fprintf(fh, " ");
print(fh, REF(d, IK_OFF_CAR));
d = REF(d, IK_OFF_CDR);
print(fh, ref(d, IK_OFF_CAR));
d = ref(d, IK_OFF_CDR);
}
else if(d == IK_NULL_OBJECT){
fprintf(fh, ")");

View File

@ -44,7 +44,7 @@ extern char **environ;
#define segment_size (pagesize*pagesize/wordsize)
#define segment_shift (pageshift+pageshift-wordshift)
#define segment_index(x) (((unsigned int)(x)) >> segment_shift)
#define segment_index(x) (((unsigned long int)(x)) >> segment_shift)
void* ik_mmap(int size);
void ik_munmap(void* mem, int size);
@ -54,11 +54,11 @@ extend_table_maybe(char*p, int size, ikpcb* pcb){
assert(size == align_to_next_page(size));
char* q = p + size;
if(p < pcb->memory_base){
int new_lo = segment_index(p);
int old_lo = segment_index(pcb->memory_base);
int hi = segment_index(pcb->memory_end);
int new_vec_size = (hi - new_lo) * pagesize;
int old_vec_size = (hi - old_lo) * pagesize;
long int new_lo = segment_index(p);
long int old_lo = segment_index(pcb->memory_base);
long int hi = segment_index(pcb->memory_end);
long int new_vec_size = (hi - new_lo) * pagesize;
long int old_vec_size = (hi - old_lo) * pagesize;
unsigned char* v = ik_mmap(new_vec_size);
bzero(v, new_vec_size - old_vec_size);
memcpy(v+new_vec_size-old_vec_size, pcb->dirty_vector_base, old_vec_size);
@ -74,11 +74,11 @@ extend_table_maybe(char*p, int size, ikpcb* pcb){
pcb->memory_base = (char*)(new_lo * segment_size);
}
else if (q > pcb->memory_end){
int lo = segment_index(pcb->memory_base);
int old_hi = segment_index(pcb->memory_end);
int new_hi = segment_index(q+segment_size-1);
int new_vec_size = (new_hi - lo) * pagesize;
int old_vec_size = (old_hi - lo) * pagesize;
long int lo = segment_index(pcb->memory_base);
long int old_hi = segment_index(pcb->memory_end);
long int new_hi = segment_index(q+segment_size-1);
long int new_vec_size = (new_hi - lo) * pagesize;
long int old_vec_size = (old_hi - lo) * pagesize;
char* v = ik_mmap(new_vec_size);
memcpy(v, pcb->dirty_vector_base, old_vec_size);
bzero(v+old_vec_size, new_vec_size - old_vec_size);
@ -319,9 +319,9 @@ ikpcb* ik_make_pcb(){
hi_mem = pcb->heap_base + pcb->heap_size + pagesize;
}
int lo_seg = segment_index(lo_mem);
int hi_seg = segment_index(hi_mem+segment_size-1);
int vec_size = (hi_seg - lo_seg) * pagesize;
long int lo_seg = segment_index(lo_mem);
long int hi_seg = segment_index(hi_mem+segment_size-1);
long int vec_size = (hi_seg - lo_seg) * pagesize;
char* dvec = ik_mmap(vec_size);
bzero(dvec, vec_size);
pcb->dirty_vector_base = (unsigned int*) (dvec);
@ -378,8 +378,8 @@ void ik_delete_pcb(ikpcb* pcb){
char* base = pcb->memory_base;
char* end = pcb->memory_end;
unsigned int* segment_vec = pcb->segment_vector;
int i = page_index(base);
int j = page_index(end);
long int i = page_index(base);
long int j = page_index(end);
while(i < j){
unsigned int t = segment_vec[i];
if(t != hole_mt){
@ -387,7 +387,7 @@ void ik_delete_pcb(ikpcb* pcb){
}
i++;
}
int vecsize = (segment_index(end) - segment_index(base)) * pagesize;
long int vecsize = (segment_index(end) - segment_index(base)) * pagesize;
ik_munmap(pcb->dirty_vector_base, vecsize);
ik_munmap(pcb->segment_vector_base, vecsize);
ik_free(pcb, sizeof(ikpcb));
@ -443,9 +443,10 @@ ik_unsafe_alloc(ikpcb* pcb, int size){
}
{ /* ACCOUNTING */
int bytes = ((int)pcb->allocation_pointer) -
((int)pcb->heap_base);
int minor = bytes + pcb->allocation_count_minor;
long int bytes =
((long int)pcb->allocation_pointer) -
((long int)pcb->heap_base);
long int minor = bytes + pcb->allocation_count_minor;
while(minor >= most_bytes_in_minor){
minor -= most_bytes_in_minor;
pcb->allocation_count_major++;
@ -492,7 +493,7 @@ void ik_stack_overflow(ikpcb* pcb){
ref(k, -vector_tag) = continuation_tag;
ref(k, off_continuation_top) = pcb->frame_pointer;
ref(k, off_continuation_size) =
pcb->frame_base - (int)pcb->frame_pointer - wordsize;
pcb->frame_base - (long int)pcb->frame_pointer - wordsize;
ref(k, off_continuation_next) = pcb->next_k;
pcb->next_k = k;
@ -700,9 +701,9 @@ ik_dump_metatable(ikpcb* pcb){
p += pagesize;
s++;
}
fprintf(stderr, "0x%08x + %5d pages = %s\n",
(int) start,
((int)p-(int)start)/pagesize,
fprintf(stderr, "0x%016lx + %5ld pages = %s\n",
(long int) start,
((long int)p-(long int)start)/pagesize,
mtname(t));
}
return void_object;
@ -722,9 +723,9 @@ ik_dump_dirty_vector(ikpcb* pcb){
p += pagesize;
s++;
}
fprintf(stderr, "0x%08x + %5d pages = 0x%08x\n",
(int) start,
((int)p-(int)start)/pagesize,
fprintf(stderr, "0x%016lx + %5ld pages = 0x%08x\n",
(long int) start,
((long int)p-(long int)start)/pagesize,
t);
}
return void_object;
@ -863,8 +864,8 @@ ikrt_gmt_offset(ikptr t){
ikptr
ikrt_bytes_allocated(ikpcb* pcb){
int bytes_in_heap = ((int) pcb->allocation_pointer) -
((int) pcb->heap_base);
int bytes_in_heap = ((long int) pcb->allocation_pointer) -
((long int) pcb->heap_base);
int bytes = bytes_in_heap + pcb->allocation_count_minor;
return fix(bytes);
}
@ -906,10 +907,10 @@ ikrt_getenv(ikptr bv, ikpcb* pcb){
ikptr
ikrt_make_vector1(ikptr len, ikpcb* pcb){
if(is_fixnum(len) && (((int)len) >= 0)){
ikptr s = ik_safe_alloc(pcb, align(((int)len) + disp_vector_data));
if(is_fixnum(len) && (((long int)len) >= 0)){
ikptr s = ik_safe_alloc(pcb, align(((long int)len) + disp_vector_data));
ref(s, 0) = len;
memset(s+disp_vector_data, 0, (int)len);
memset(s+disp_vector_data, 0, (long int)len);
return s+vector_tag;
} else {
return 0;
@ -981,6 +982,6 @@ ikrt_exit(ikptr status, ikpcb* pcb){
ikptr
ikrt_debug(ikptr x){
fprintf(stderr, "DEBUG 0x%08x\n", (int)x);
fprintf(stderr, "DEBUG 0x%016lx\n", (long int)x);
return 0;
};

View File

@ -32,11 +32,11 @@ make_symbol_table(ikpcb* pcb){
return st;
}
static int
static long int
compute_hash(ikptr str){
int len = unfix(ref(str, off_string_length));
long int len = unfix(ref(str, off_string_length));
char* data = (char*) str + off_string_data;
int h = len;
long int h = len;
char* last = data + len * string_char_size;
while(data < last){
char c = *data;

View File

@ -21,9 +21,9 @@
#include <stdlib.h>
#include <assert.h>
static int
static long int
page_idx(char* x){
unsigned int xi = (unsigned int) x;
unsigned long int xi = (unsigned long int) x;
return xi >> pageshift;
}