/* s11n-c.c */ static C_word fixnum_to_bytes(C_word c, C_word self, C_word k, C_word x) { C_word *a = C_alloc(C_SIZEOF_STRING(sizeof(C_word))); C_kontinue(k, C_string(&a, sizeof(C_word), (C_char *)&x)); } static C_word word_to_bytes(C_word c, C_word self, C_word k, C_word x) { C_word *a = C_alloc(C_SIZEOF_STRING(sizeof(unsigned long))); unsigned long n = C_num_to_unsigned_long(x); C_kontinue(k, C_string(&a, sizeof(unsigned long), (C_char *)&n)); } static C_word header_to_bytes(C_word c, C_word self, C_word k, C_word x) { C_word *a = C_alloc(C_SIZEOF_STRING(sizeof(C_header))); C_kontinue(k, C_string(&a, sizeof(C_header), (C_char *)x)); } static void bytes_to_block(C_word c, C_word self, C_word k, C_word str) { C_header h = *((C_header *)C_data_pointer(str)); int size = h & C_HEADER_SIZE_MASK; C_allocate_vector(6, C_SCHEME_UNDEFINED, k, C_fix(size), C_mk_bool((h & C_BYTEBLOCK_BIT) != 0), C_SCHEME_UNDEFINED, C_mk_bool((h & C_8ALIGN_BIT) != 0)); } static ___scheme_value bytes_to_size(C_word str) { C_header h = *((C_header *)C_data_pointer(str)); return C_fix(h & C_HEADER_SIZE_MASK); } static ___scheme_value bytes_to_word(___scheme_value str) { return C_fix(*((unsigned long *)C_data_pointer(str))); } static ___scheme_value insert_bytes(___scheme_value x, ___scheme_value str) { C_memcpy(C_data_pointer(x), C_data_pointer(str), C_header_size(str)); return C_SCHEME_UNDEFINED; } static ___scheme_value set_procedure_ptr(___scheme_value x, ___scheme_value pid) { void *ptr = C_lookup_procedure_ptr(C_c_string(pid)); if(ptr != NULL) { C_block_item(x, 0) = (C_word)ptr; return C_SCHEME_TRUE; } else return C_SCHEME_FALSE; } static ___scheme_value bytes_to_fixnum(___scheme_value str) { return *((C_word *)C_data_pointer(str)); } static ___scheme_value set_header(___scheme_value x, ___scheme_value str) { C_block_header(x) = *((C_header *)C_data_pointer(str)); return x; }