rev 598 - in trunk: include/prothon src
SVN User <[email protected]> Thu, 10 Jun 2004 17:14:54 -0400
| Newsgroups | gmane.comp.lang.prothon.cvs |
|---|---|
| Message-ID | <[email protected]> |
Author: mark
Date: 2004-06-10 17:14:51 -0400 (Thu, 10 Jun 2004)
New Revision: 598
Modified:
trunk/include/prothon/prothon.h
trunk/src/builtins-core.c
trunk/src/builtins-string.c
trunk/src/object.h
Log:
updated string.hash and string.getItem to 24-bits
Modified: trunk/include/prothon/prothon.h
===================================================================
--- trunk/include/prothon/prothon.h 2004-06-10 20:00:45 UTC (rev 597)
+++ trunk/include/prothon/prothon.h 2004-06-10 21:14:51 UTC (rev 598)
@@ -681,6 +681,10 @@
obj_p new_string_n_obj(isp ist, char* string, size_t n);
#define NEW_STRINGN(string, n) new_string_n_obj(ist, string, n)
+// NEW_STRING_CH3_OBJ: Create a new string object from a 24-bit char string of N chars long.
+obj_p new_string_ch3_obj(isp ist, ch3_p ch3p, data_size_t n);
+#define NEW_STRING_CH3(ch3p, n) new_string_ch3_obj(ist, ch3p, n)
+
// SET_STRING_DATA: Change an existing object's data to string data
// clobbers any esisting data pointer
void c2pr_strcpy(isp ist, obj_p obj, char* p, size_t len);
@@ -688,13 +692,16 @@
// PR_STRPTR: retreive string object as a C string
char* pr2c_strptr(isp ist, obj_p str_obj);
-// PR_STRLEN: macro to retreive string length of a string object
-// warning, string objects may contain null chars that this length ignores
-// This corresponds to dsize member of apr_datum_t.
+// PR_STRLEN: macro to retreive string length of a string object (type data_size_t)
#define pr_strlen(str_obj) \
- ( ((str_obj)->data_type == DATA_TYPE_IMMDATA) ? (((size_t)((str_obj)->imm_data_len))/3): \
+ ( ((str_obj)->data_type == DATA_TYPE_IMMDATA) ? (((data_size_t)((str_obj)->imm_data_len))/3): \
(((str_obj)->data_type == DATA_TYPE_DATAPTR) ? ((DATA_SIZE(str_obj)-sizeof(str_t))/3) : 0 ) )
+// PR_CH3PTR: macro to retreive ptr to chars for a string object (type ch3_p)
+#define pr_ch3ptr(str_obj) \
+ ( ((str_obj)->data_type == DATA_TYPE_IMMDATA) ? (str_obj->data.str) : \
+ (((str_obj)->data_type == DATA_TYPE_DATAPTR) ? (((str_p)(str_obj->data.ptr))->str) : NULL ) )
+
// NEW_LIST_OBJ: Create a new list object with a given initial size
obj_p new_list_obj(isp ist, size_t initial_size);
#define NEW_LIST(initial_size) new_list_obj(ist, initial_size)
Modified: trunk/src/builtins-core.c
===================================================================
--- trunk/src/builtins-core.c 2004-06-10 20:00:45 UTC (rev 597)
+++ trunk/src/builtins-core.c 2004-06-10 21:14:51 UTC (rev 598)
@@ -628,7 +628,7 @@
obj_p res = NULL, slice_item1, slice_item2, slice_item3;
int i, index1 = 0, index2 = 0, index3 = 0, slice1_empty=FALSE, slice2_empty=FALSE;
int exp_len, self_len, slice_len = (int) list_len(ist, slice);
- char* self_str = NULL;
+ ch3_p self_str = NULL;
u8_t* self_bytes = NULL;
CHECK_TYPE_EXC(self, OBJ(SEQ_PROTO), "sequence");
@@ -637,7 +637,7 @@
self_bytes = bytes_ptr(self);
self_len = (int) bytes_len(self);
} else if (seq_type == SEQ_TYPE_STRING) {
- self_str = pr2c_strptr(ist, self); if_exc_return NULL;
+ self_str = pr_ch3ptr(self);
self_len = (int) pr_strlen(self);
} else
self_len = (int) list_len(ist, self);
@@ -657,7 +657,7 @@
if (seq_type == SEQ_TYPE_BYTES) {
return NEW_INT(*(self_bytes+index1));
} else if (seq_type == SEQ_TYPE_STRING) {
- return NEW_STRINGN(self_str+index1, 1);
+ return NEW_STRING_CH3(self_str+index1, 1);
} else
return list_item(ist, self, index1);
}
@@ -704,10 +704,10 @@
} break;
case SEQ_TYPE_STRING: {
int j;
- char* s = pr_malloc(exp_len+2);
+ ch3_p s = pr_malloc(exp_len*3+3);
for(i = index1, j=0; i < index2; i += index3, j++)
s[j] = self_str[i];
- res = NEW_STRINGN(s, j);
+ res = NEW_STRING_CH3(s, j);
pr_free(s);
} break;
case SEQ_TYPE_TUPLE:
@@ -731,16 +731,16 @@
int j;
u8_t* s = pr_malloc(exp_len);
for(i = index1, j=0; i > index2; i += index3, j++)
- s[j] = self_str[i];
+ s[j] = self_bytes[i];
res = NEW_BYTES(s, j);
pr_free(s);
} break;
case SEQ_TYPE_STRING: {
int j;
- char* s = pr_malloc(exp_len+2);
+ ch3_p s = pr_malloc(exp_len*3+3);
for(i = index1, j=0; i > index2; i += index3, j++)
s[j] = self_str[i];
- res = NEW_STRINGN(s, j);
+ res = NEW_STRING_CH3(s, j);
pr_free(s);
} break;
case SEQ_TYPE_TUPLE:
Modified: trunk/src/builtins-string.c
===================================================================
--- trunk/src/builtins-string.c 2004-06-10 20:00:45 UTC (rev 597)
+++ trunk/src/builtins-string.c 2004-06-10 21:14:51 UTC (rev 598)
@@ -91,10 +91,18 @@
if(!str) return NULL;
obj = NEW_OBJ(OBJ(STRING_PROTO));
c2pr_strcpy(ist, obj, str, len);
- obj->immutable = TRUE;
return obj;
}
+//********************************* new_string_ch3_obj **************************
+obj_p new_string_ch3_obj(isp ist, ch3_p str, data_size_t len) {
+ obj_p obj;
+ if(!str) return NULL;
+ obj = NEW_OBJ(OBJ(STRING_PROTO));
+ pr2pr_strcpy(ist, obj, str, len);
+ return obj;
+}
+
//********************************* c2pr_strcpy *******************************
void c2pr_strcpy(isp ist, obj_p obj, char* str, data_size_t len) {
str_p obj_str;
@@ -110,7 +118,7 @@
obj_str->size = sizeof(str_t)+size;
ch3p = obj_str->str;
}
- for (i=0; i < len; i++, str++, ch3p++) {
+ for (i=0; i < len; i++, ch3p++, str++) {
ch3p->b0 = *str;
ch3p->b1 = 0;
ch3p->b2 = 0;
@@ -118,6 +126,29 @@
obj->immutable = TRUE;
}
+//********************************* pr2pr_strcpy *******************************
+void pr2pr_strcpy(isp ist, obj_p obj, ch3_p str, data_size_t len) {
+ str_p obj_str;
+ ch3_p ch3p;
+ data_size_t i, size = len*3;
+
+ if (size <= IMM_DATA_LEN) {
+ SET_TYPE_IF_EXC(OBJ(STRING_PROTO), obj, DATA_TYPE_IMMDATA) return;
+ obj->imm_data_len = (int) size;
+ ch3p = obj->data.str;
+ } else {
+ obj_str = obj_malloc(ist, OBJ(STRING_PROTO), obj, sizeof(str_t)+size); if_exc_return;
+ obj_str->size = sizeof(str_t)+size;
+ ch3p = obj_str->str;
+ }
+ for (i=0; i < len; i++, ch3p++, str++) {
+ ch3p->b0 = str->b0;
+ ch3p->b1 = str->b1;
+ ch3p->b2 = str->b2;
+ }
+ obj->immutable = TRUE;
+}
+
//********************************* c2pr_bytcpy *******************************
void c2pr_bytcpy(isp ist, obj_p obj, u8_t* byt, data_size_t len, int latin) {
str_p obj_str;
@@ -346,10 +377,11 @@
DEF(String, hash_, NULL) {
i32_t res = 0x9a7c5e3;
- char *p,*p2;
+ ch3_p p, p2;
BIN_CONTENT_CHK(String);
- for(p2=p=pr2c_strptr(ist, self); *p; p++) res += 131 * (*p);
- pr_free(p2);
+ p = pr_ch3ptr(self);
+ p2 = p + pr_strlen(self);
+ for(; p < p2; p++) res += 131 * ORD(p);
return new_hash_obj(ist, res);
}
Modified: trunk/src/object.h
===================================================================
--- trunk/src/object.h 2004-06-10 20:00:45 UTC (rev 597)
+++ trunk/src/object.h 2004-06-10 21:14:51 UTC (rev 598)
@@ -151,6 +151,7 @@
u8_t* bytes_ptr(obj_p obj);
size_t bytes_len(obj_p obj);
void pr_str2bytes(isp ist, u8_t* buf, obj_p str_obj, int latin);
+void pr2pr_strcpy(isp ist, obj_p obj, ch3_p str, data_size_t len);
void dict2attrs(isp ist, obj_p dict, obj_p obj);
void list2protos(isp ist, obj_p list, obj_p obj);