* cleaned up some uses of naked strings in the runtime system.

This commit is contained in:
Abdulaziz Ghuloum 2007-05-19 14:13:51 -04:00
parent 267da9e77c
commit 182de12428
8 changed files with 40 additions and 23 deletions

Binary file not shown.

View File

@ -1109,12 +1109,12 @@ add_object_proc(gc_t* gc, ikp x)
else if(tag == string_tag){
if(is_fixnum(fst)){
int strlen = unfix(fst);
int memreq = align(strlen + disp_string_data + 1);
int memreq = align(strlen*string_char_size + disp_string_data + 1);
ikp new_str = gc_alloc_new_data(memreq, gen, gc) + string_tag;
ref(new_str, off_string_length) = fst;
memcpy(new_str+off_string_data,
x + off_string_data,
strlen + 1);
strlen*string_char_size + 1);
ref(x, -string_tag) = forward_ptr;
ref(x, wordsize-string_tag) = new_str;
#if accounting

View File

@ -97,7 +97,7 @@
#define off_string_length (disp_string_length - string_tag)
#define off_string_data (disp_string_data - string_tag)
#define string_data(x) ((char*)((x) + off_string_data))
//#define string_data(x) ((char*)((x) + off_string_data))
#define string_set(x,i,c) \
((((unsigned char*)(x)) + off_string_data + (int)(i))[0] = \
(((int)(c)) >> IK_CHAR_SHIFT))

View File

@ -137,11 +137,17 @@ int main(int argc, char** argv){
while(i > 0){
char* s = argv[i];
int n = strlen(s);
ikp str = ik_alloc(pcb, align(n+disp_string_data+1));
ref(str, disp_string_length) = fix(n);
strcpy((char*)str+disp_string_data, s);
ikp str = ik_alloc(pcb, align(n*string_char_size+disp_string_data+1))
+ string_tag;
ref(str, off_string_length) = fix(n);
{
int i;
for(i=0; i<n; i++){
string_set(str, i, integer_to_char(s[i]));
}
}
ikp p = ik_alloc(pcb, pair_size);
ref(p, disp_car) = str + string_tag;
ref(p, disp_car) = str;
ref(p, disp_cdr) = arg_list;
arg_list = p+pair_tag;
i--;

View File

@ -106,7 +106,9 @@ print(FILE* fh, ikp x){
else if(tagof(x) == string_tag){
ikp fxlen = ref(x, off_string_length);
int len = unfix(fxlen);
char* data = string_data(x);
fprintf(stderr, "bug: printer busted!\n");
exit(-1);
char* data = 0; //string_data(x);
fprintf(fh, "\"");
int i;
for(i=0; i<len; i++){

View File

@ -479,7 +479,7 @@ ikp ik_uuid(ikp str){
return str;
}
#if 0
ikp ik_write(ikp fdptr, ikp idx, ikp str){
fprintf(stderr, "IK_WRITE\n");
int fd = unfix(fdptr);
@ -492,6 +492,7 @@ ikp ik_write(ikp fdptr, ikp idx, ikp str){
}
return true_object;
}
#endif
/*
@ -505,6 +506,7 @@ ikp ik_write(ikp fdptr, ikp idx, ikp str){
* int unlink(const char *pathname);
*/
#if 0
ikp ik_open_file(ikp str, ikp flagptr){
int flags;
int f = unfix(flagptr);
@ -537,6 +539,7 @@ ikp ik_open_file(ikp str, ikp flagptr){
}
return fix(fd);
}
#endif
/*
@ -829,12 +832,19 @@ ikrt_open_output_file(ikp fname, ikp flagptr, ikpcb* pcb){
/* [(replace) 1] */
/* [(truncate) 2] */
/* [(append) 3] */
char* name;
if(tagof(fname) == bytevector_tag){
name = (char*) fname + off_bytevector_data;
} else {
fprintf(stderr, "bug in ikrt_open_output_file\n");
exit(-1);
}
int flags;
int f = unfix(flagptr);
if(f == 0){
flags = O_WRONLY | O_CREAT;
} else if(f == 1){
unlink(string_data(fname));
unlink(name);
flags = O_WRONLY | O_CREAT;
} else if(f == 2){
flags = O_WRONLY | O_TRUNC | O_CREAT;
@ -845,13 +855,6 @@ ikrt_open_output_file(ikp fname, ikp flagptr, ikpcb* pcb){
(int)flagptr);
exit(-10);
}
char* name;
if(tagof(fname) == bytevector_tag){
name = (char*) fname + off_bytevector_data;
} else {
fprintf(stderr, "bug in ikrt_open_output_file\n");
exit(-1);
}
int fd = open(name, flags, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
if(fd == -1){
fprintf(stderr, "openfile failed: %s\n", strerror(errno));
@ -868,7 +871,8 @@ ikrt_write_file(ikp fd, ikp buff, ikp idx, ikpcb* pcb){
if(tagof(buff) == bytevector_tag){
bytes = write(unfix(fd), buff+off_bytevector_data, unfix(idx));
} else {
bytes = write(unfix(fd), string_data(buff), unfix(idx));
fprintf(stderr, "bug in ikrt_write_file\n");
exit(-1);
}
return fix(bytes);
}
@ -953,7 +957,7 @@ ikp
ikrt_getenv(ikp str, ikpcb* pcb){
fprintf(stderr, "getenv busted!\n");
exit(-1);
char* v = getenv(string_data(str));
char* v = getenv((char*)str + off_bytevector_data);
if(v){
int n = strlen(v);
ikp s = ik_alloc(pcb, align(n+disp_string_data+1)) + string_tag;
@ -973,7 +977,8 @@ ikp
ikrt_setenv(ikp key, ikp val, ikp overwrite){
fprintf(stderr, "setenv busted!\n");
exit(-1);
int err = setenv(string_data(key), string_data(val),
int err = setenv((char*)key+off_bytevector_data,
(char*)val+off_bytevector_data,
overwrite!=false_object);
if(err){
return false_object;

View File

@ -19,7 +19,7 @@ compute_hash(ikp str){
int len = unfix(ref(str, off_string_length));
char* data = (char*) str + off_string_data;
int h = len;
char* last = data + len;
char* last = data + len * string_char_size;
while(data < last){
char c = *data;
h = h + c;
@ -37,7 +37,10 @@ static int strings_eqp(ikp str1, ikp str2){
ikp len = ref(str1, off_string_length);
if(len == ref(str2, off_string_length)){
return
(memcmp(str1+off_string_data, str2+off_string_data, unfix(len)) == 0);
(memcmp(str1+off_string_data,
str2+off_string_data,
unfix(len) * string_char_size)
== 0);
}
return 0;
}
@ -175,7 +178,7 @@ ikrt_strings_to_gensym(ikp str, ikp ustr, ikpcb* pcb){
}
#if 0
ikp
ik_cstring_to_symbol(char* str, ikpcb* pcb){
int n = strlen(str);
@ -186,3 +189,4 @@ ik_cstring_to_symbol(char* str, ikpcb* pcb){
ikp sym = ikrt_string_to_symbol(s, pcb);
return sym;
}
#endif

Binary file not shown.