*** empty log message ***

This commit is contained in:
hyung-hwan 2005-07-05 10:22:35 +00:00
parent 32711250c4
commit eca4b4145c
3 changed files with 28 additions and 16 deletions

View File

@ -1,5 +1,5 @@
/* /*
* $Id: object.c,v 1.33 2005-07-05 09:52:00 bacon Exp $ * $Id: object.c,v 1.34 2005-07-05 10:22:35 bacon Exp $
*/ */
#include <xp/stx/object.h> #include <xp/stx/object.h>
@ -26,14 +26,19 @@ xp_word_t xp_stx_alloc_word_object (
n = nfields + variable_nfields; n = nfields + variable_nfields;
idx = xp_stx_memory_alloc (&stx->memory, idx = xp_stx_memory_alloc (&stx->memory,
n * xp_sizeof(xp_word_t) + xp_sizeof(xp_stx_object_t)); n * xp_sizeof(xp_word_t) + xp_sizeof(xp_stx_object_t));
if (idx >= stx->memory.capacity) return idx; /* failed */ if (idx >= stx->memory.capacity) return idx; /* failed TODO: return a difference value OINDEX_INVALID */
idx = XP_STX_TO_OINDEX(idx);
obj = XP_STX_WORD_OBJECT(stx,idx); obj = XP_STX_WORD_OBJECT(stx,idx);
obj->header.class = stx->nil; obj->header.class = stx->nil;
obj->header.access = (n << 2) | XP_STX_WORD_INDEXED; obj->header.access = (n << 2) | XP_STX_WORD_INDEXED;
if (variable_data == XP_NULL) { if (variable_data == XP_NULL) {
while (n > nfields) obj->data[--n] = stx->nil; while (n > nfields) {
n--;
xp_printf (XP_TEXT("%d\n"), n);
obj->data[n] = stx->nil;
}
} }
else { else {
while (n > nfields) { while (n > nfields) {
@ -66,6 +71,7 @@ xp_word_t xp_stx_alloc_byte_object (
&stx->memory, n + xp_sizeof(xp_stx_object_t)); &stx->memory, n + xp_sizeof(xp_stx_object_t));
if (idx >= stx->memory.capacity) return idx; /* failed */ if (idx >= stx->memory.capacity) return idx; /* failed */
idx = XP_STX_TO_OINDEX(idx);
obj = XP_STX_BYTE_OBJECT(stx,idx); obj = XP_STX_BYTE_OBJECT(stx,idx);
obj->header.class = stx->nil; obj->header.class = stx->nil;
obj->header.access = (n << 2) | XP_STX_BYTE_INDEXED; obj->header.access = (n << 2) | XP_STX_BYTE_INDEXED;
@ -101,6 +107,7 @@ xp_word_t xp_stx_alloc_char_objectx (
(n + 1) * xp_sizeof(xp_char_t) + xp_sizeof(xp_stx_object_t)); (n + 1) * xp_sizeof(xp_char_t) + xp_sizeof(xp_stx_object_t));
if (idx >= stx->memory.capacity) return idx; /* failed */ if (idx >= stx->memory.capacity) return idx; /* failed */
idx = XP_STX_TO_OINDEX(idx);
obj = XP_STX_CHAR_OBJECT(stx,idx); obj = XP_STX_CHAR_OBJECT(stx,idx);
obj->header.class = stx->nil; obj->header.class = stx->nil;
obj->header.access = (n << 2) | XP_STX_CHAR_INDEXED; obj->header.access = (n << 2) | XP_STX_CHAR_INDEXED;
@ -123,6 +130,8 @@ xp_word_t xp_stx_allocn_char_object (xp_stx_t* stx, ...)
xp_va_list ap; xp_va_list ap;
xp_stx_char_object_t* obj; xp_stx_char_object_t* obj;
xp_assert (stx->nil == XP_STX_NIL);
xp_va_start (ap, stx); xp_va_start (ap, stx);
while ((p = xp_va_arg(ap, const xp_char_t*)) != XP_NULL) { while ((p = xp_va_arg(ap, const xp_char_t*)) != XP_NULL) {
n += xp_strlen(p); n += xp_strlen(p);
@ -133,8 +142,7 @@ xp_word_t xp_stx_allocn_char_object (xp_stx_t* stx, ...)
(n + 1) * xp_sizeof(xp_char_t) + xp_sizeof(xp_stx_object_t)); (n + 1) * xp_sizeof(xp_char_t) + xp_sizeof(xp_stx_object_t));
if (idx >= stx->memory.capacity) return idx; /* failed */ if (idx >= stx->memory.capacity) return idx; /* failed */
xp_assert (stx->nil == XP_STX_NIL); idx = XP_STX_TO_OINDEX(idx);
obj = XP_STX_CHAR_OBJECT(stx,idx); obj = XP_STX_CHAR_OBJECT(stx,idx);
obj->header.class = stx->nil; obj->header.class = stx->nil;
obj->header.access = (n << 2) | XP_STX_CHAR_INDEXED; obj->header.access = (n << 2) | XP_STX_CHAR_INDEXED;
@ -155,7 +163,7 @@ xp_word_t xp_stx_allocn_char_object (xp_stx_t* stx, ...)
xp_word_t xp_stx_hash_char_object (xp_stx_t* stx, xp_word_t idx) xp_word_t xp_stx_hash_char_object (xp_stx_t* stx, xp_word_t idx)
{ {
xp_assert (XP_STX_TYPE(stx,idx) == XP_STX_CHAR_INDEXED); xp_assert (!XP_STX_IS_SMALLINT(idx) && XP_STX_IS_CHAR_OBJECT(stx, idx));
return xp_stx_strxhash ( return xp_stx_strxhash (
XP_STX_DATA(stx,idx), XP_STX_SIZE(stx,idx)); XP_STX_DATA(stx,idx), XP_STX_SIZE(stx,idx));
} }

View File

@ -1,5 +1,5 @@
/* /*
* $Id: object.h,v 1.23 2005-07-05 09:52:00 bacon Exp $ * $Id: object.h,v 1.24 2005-07-05 10:22:35 bacon Exp $
*/ */
#ifndef _XP_STX_OBJECT_H_ #ifndef _XP_STX_OBJECT_H_
@ -7,10 +7,6 @@
#include <xp/stx/stx.h> #include <xp/stx/stx.h>
#define XP_STX_IS_SMALLINT(x) (((x) & 0x01) == 0x01)
#define XP_STX_TO_SMALLINT(x) (((x) << 1) | 0x01)
#define XP_STX_FROM_SMALLINT(x) ((x) >> 1)
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif

View File

@ -1,5 +1,5 @@
/* /*
* $Id: stx.h,v 1.33 2005-07-05 09:52:00 bacon Exp $ * $Id: stx.h,v 1.34 2005-07-05 10:22:35 bacon Exp $
*/ */
#ifndef _XP_STX_STX_H_ #ifndef _XP_STX_STX_H_
@ -85,11 +85,19 @@ struct xp_stx_t
xp_bool_t __wantabort; /* TODO: make it a function pointer */ xp_bool_t __wantabort; /* TODO: make it a function pointer */
}; };
#define XP_STX_NIL 0 #define XP_STX_IS_SMALLINT(x) (((x) & 0x01) == 0x01)
#define XP_STX_TRUE 1 #define XP_STX_TO_SMALLINT(x) (((x) << 1) | 0x01)
#define XP_STX_FALSE 2 #define XP_STX_FROM_SMALLINT(x) ((x) >> 1)
#define XP_STX_OBJECT(stx,idx) (((stx)->memory).slots[idx]) #define XP_STX_IS_OINDEX(x) (((x) & 0x01) == 0x00)
#define XP_STX_TO_OINDEX(x) (((x) << 1) | 0x00)
#define XP_STX_FROM_OINDEX(x) ((x) >> 1)
#define XP_STX_NIL XP_STX_TO_OINDEX(0)
#define XP_STX_TRUE XP_STX_TO_OINDEX(1)
#define XP_STX_FALSE XP_STX_TO_OINDEX(2)
#define XP_STX_OBJECT(stx,idx) (((stx)->memory).slots[XP_STX_FROM_OINDEX(idx)])
#define XP_STX_CLASS(stx,idx) (XP_STX_OBJECT(stx,(idx))->header.class) #define XP_STX_CLASS(stx,idx) (XP_STX_OBJECT(stx,(idx))->header.class)
#define XP_STX_ACCESS(stx,idx) (XP_STX_OBJECT(stx,(idx))->header.access) #define XP_STX_ACCESS(stx,idx) (XP_STX_OBJECT(stx,(idx))->header.access)
#define XP_STX_DATA(stx,idx) ((void*)(XP_STX_OBJECT(stx,idx) + 1)) #define XP_STX_DATA(stx,idx) ((void*)(XP_STX_OBJECT(stx,idx) + 1))