*** empty log message ***

This commit is contained in:
hyung-hwan 2005-05-08 07:39:51 +00:00
parent da4594c0e8
commit e050695338
9 changed files with 230 additions and 109 deletions

View File

@ -1,5 +1,5 @@
/* /*
* $Id: memory.c,v 1.3 2005-05-06 17:17:59 bacon Exp $ * $Id: memory.c,v 1.4 2005-05-08 07:39:51 bacon Exp $
*/ */
#include <xp/stx/memory.h> #include <xp/stx/memory.h>
@ -63,7 +63,7 @@ void xp_stx_garbage_collect (xp_stx_memory_t* mem)
/* TODO: implement this function */ /* TODO: implement this function */
} }
xp_stx_word_t xp_stx_alloc_object (xp_stx_memory_t* mem, xp_stx_word_t nbytes) xp_stx_word_t xp_stx_alloc_objmem (xp_stx_memory_t* mem, xp_stx_word_t nbytes)
{ {
xp_stx_object_t** slot; xp_stx_object_t** slot;
xp_stx_object_t* object; xp_stx_object_t* object;
@ -88,7 +88,7 @@ xp_stx_word_t xp_stx_alloc_object (xp_stx_memory_t* mem, xp_stx_word_t nbytes)
return (xp_stx_word_t)(slot - mem->slots); return (xp_stx_word_t)(slot - mem->slots);
} }
void xp_stx_dealloc_object (xp_stx_memory_t* mem, xp_stx_word_t object_index) void xp_stx_dealloc_objmem (xp_stx_memory_t* mem, xp_stx_word_t object_index)
{ {
/* /*
* THIS IS PRIMITIVE LOW-LEVEL DEALLOC. THIS WILL NOT * THIS IS PRIMITIVE LOW-LEVEL DEALLOC. THIS WILL NOT

View File

@ -1,76 +1,11 @@
/* /*
* $Id: memory.h,v 1.3 2005-05-06 17:17:59 bacon Exp $ * $Id: memory.h,v 1.4 2005-05-08 07:39:51 bacon Exp $
*/ */
#ifndef _XP_STX_MEMORY_H_ #ifndef _XP_STX_MEMORY_H_
#define _XP_STX_MEMORY_H_ #define _XP_STX_MEMORY_H_
#include <xp/types.h> #include <xp/stx/stx.h>
#include <xp/macros.h>
typedef struct xp_stx_memory_t xp_stx_memory_t;
typedef struct xp_stx_object_t xp_stx_object_t;
typedef struct xp_stx_byte_object_t xp_stx_byte_object_t;
typedef struct xp_stx_string_object_t xp_stx_string_object_t;
typedef xp_byte_t xp_stx_byte_t;
typedef xp_char_t xp_stx_char_t;
typedef xp_size_t xp_stx_word_t;
typedef xp_size_t xp_stx_size_t;
typedef xp_size_t xp_stx_index_t;
typedef xp_stx_object_t* xp_stx_pointer_t;
/* common object header structure */
struct xp_stx_object_t
{
/* access - is_byte_indexed: 1; size: rest */
xp_stx_word_t access;
xp_stx_word_t class;
xp_stx_word_t data[1];
};
struct xp_stx_byte_object_t
{
xp_stx_word_t access;
xp_stx_word_t class;
xp_stx_byte_t data[1];
};
struct xp_stx_string_object_t
{
xp_stx_word_t access;
xp_stx_word_t class;
xp_stx_char_t data[1];
};
struct xp_stx_memory_t
{
xp_stx_word_t capacity;
xp_stx_object_t** slots;
xp_stx_object_t** free;
xp_bool_t __malloced;
};
#define XP_STX_NIL (0)
#define XP_STX_OBJECT(mem,at) \
((xp_stx_object_t*)(mem->slots[at]))
#define XP_STX_BYTE_OBJECT(mem,at) \
((xp_stx_byte_object_t*)(mem->slots[at]))
#define XP_STX_STRING_OBJECT(mem,at) \
((xp_stx_string_object_t*)(mem->slots[at]))
#define XP_STX_OBJECT_ACCESS(mem,at) ((XP_STX_OBJECT(mem,at))->access)
#define XP_STX_OBJECT_CLASS(mem,at) ((XP_STX_OBJECT(mem,at))->class)
#define XP_STX_OBJECT_DATA(mem,at) \
(((XP_STX_OBJECT_ACCESS(mem,at) & 0x04) == 0x00)? \
(XP_STX_OBJECT(mem,at)).data): \
(((XP_STX_OBJECT_ACCESS(mem,at) & 0x04) == 0x01)? \
(XP_STX_BYTE_OBJECT(mem,at)).data): \
(XP_STX_STRING_OBJECT(mem,at)).data))
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
@ -81,8 +16,8 @@ xp_stx_memory_t* xp_stx_memory_open (
void xp_stx_memory_close (xp_stx_memory_t* mem); void xp_stx_memory_close (xp_stx_memory_t* mem);
void xp_stx_gaxpage_collect (xp_stx_memory_t* mem); void xp_stx_gaxpage_collect (xp_stx_memory_t* mem);
xp_stx_word_t xp_stx_alloc_object (xp_stx_memory_t* mem, xp_stx_word_t size); xp_stx_word_t xp_stx_alloc_objmem (xp_stx_memory_t* mem, xp_stx_word_t size);
void xp_stx_dealloc_object (xp_stx_memory_t* mem, xp_stx_word_t object_index); void xp_stx_dealloc_objmem (xp_stx_memory_t* mem, xp_stx_word_t object_index);
#ifdef __cplusplus #ifdef __cplusplus
} }

View File

@ -1,50 +1,58 @@
/* /*
* $Id: object.c,v 1.1 2005-05-06 17:17:59 bacon Exp $ * $Id: object.c,v 1.2 2005-05-08 07:39:51 bacon Exp $
*/ */
#include <xp/stx/object.h> #include <xp/stx/object.h>
#include <xp/stx/memory.h>
/* n: number of instance variables */ /* n: number of instance variables */
xp_stx_word_t xp_stx_instantiate (xp_stx_memory_t* mem, xp_size_t n) xp_stx_word_t xp_stx_alloc_object (xp_stx_t* stx, xp_size_t n)
{ {
xp_stx_word_t at; xp_stx_word_t at;
/* bytes to allocated = /* bytes to allocated =
* number of instance variables * word_size * number of instance variables * word_size
*/ */
at = xp_stx_alloc_object (mem, n * xp_sizeof(xp_stx_word_t)); at = xp_stx_alloc_objmem (
if (at >= mem->capacity) return at; /* failed */ &stx->memory, n * xp_sizeof(xp_stx_word_t));
if (at >= stx->memory.capacity) return at; /* failed */
XP_STX_OBJECT_CLASS(&stx->memory,at) = stx->nil;
XP_STX_OBJECT_ACCESS(&stx->memory,at) = ((n << 2) | 0x00);
while (n--) XP_STX_OBJECT(&stx->memory,at)->data[n] = stx->nil;
XP_STX_OBJECT_CLASS(mem,at) = XP_STX_NIL;
XP_STX_OBJECT_ACCESS(mem,at) = ((n << 2) | 0x00);
while (n--) XP_STX_OBJECT(mem,at)->data[n] = XP_STX_NIL;
return at; return at;
} }
xp_stx_word_t xp_stx_instantiate_byte (xp_stx_memory_t* mem, xp_size_t n) /* n: number of bytes */
xp_stx_word_t xp_stx_alloc_byte_object (xp_stx_t* stx, xp_size_t n)
{ {
xp_stx_word_t at; xp_stx_word_t at;
at = xp_stx_alloc_object (mem, n); at = xp_stx_alloc_objmem (&stx->memory, n);
if (at >= mem->capacity) return at; /* failed */ if (at >= stx->memory.capacity) return at; /* failed */
XP_STX_OBJECT_CLASS(&stx->memory,at) = stx->nil;
XP_STX_OBJECT_ACCESS(&stx->memory,at) = ((n << 2) | 0x01);
while (n--) XP_STX_BYTE_OBJECT(&stx->memory,at)->data[n] = 0;
XP_STX_OBJECT_CLASS(mem,at) = XP_STX_NIL;
XP_STX_OBJECT_ACCESS(mem,at) = ((n << 2) | 0x01);
while (n--) XP_STX_BYTE_OBJECT(mem,at)->data[n] = 0;
return at; return at;
} }
xp_stx_word_t xp_stx_instantiate_string ( /* n: length of the string */
xp_stx_memory_t* mem, xp_stx_char_t* str, xp_stx_word_t n) xp_stx_word_t xp_stx_alloc_string_object (
xp_stx_t* stx, xp_stx_char_t* str, xp_stx_word_t n)
{ {
xp_stx_word_t at; xp_stx_word_t at;
at = xp_stx_alloc_object (mem, n * xp_sizeof(xp_stx_char_t)); at = xp_stx_alloc_objmem (
if (at >= mem->capacity) return at; /* failed */ &stx->memory, (n + 1) * xp_sizeof(xp_stx_char_t));
if (at >= stx->memory.capacity) return at; /* failed */
XP_STX_OBJECT_CLASS(mem,at) = XP_STX_NIL; XP_STX_OBJECT_CLASS(&stx->memory,at) = stx->nil;
XP_STX_OBJECT_ACCESS(mem,at) = ((n << 2) | 0x02); XP_STX_OBJECT_ACCESS(&stx->memory,at) = ((n << 2) | 0x02);
while (n--) XP_STX_BYTE_OBJECT(mem,at)->data[n] = str[n]; XP_STX_BYTE_OBJECT(&stx->memory,at)->data[n] = XP_STX_CHAR('\0');
while (n--) XP_STX_BYTE_OBJECT(&stx->memory,at)->data[n] = str[n];
return at; return at;
} }

View File

@ -1,14 +1,27 @@
/* /*
* $Id: object.h,v 1.1 2005-05-06 17:17:59 bacon Exp $ * $Id: object.h,v 1.2 2005-05-08 07:39:51 bacon Exp $
*/ */
#ifndef _XP_STX_OBJECT_H_ #ifndef _XP_STX_OBJECT_H_
#define _XP_STX_OBJECT_H_ #define _XP_STX_OBJECT_H_
#include <xp/stx/memory.h> #include <xp/stx/stx.h>
#define XP_STX_IS_SMALLINT(x) (((x) & 0x01) == 0x01) #define XP_STX_IS_SMALLINT(x) (((x) & 0x01) == 0x01)
#define XP_STX_TO_SMALLINT(x) ((x) << 1) | 0x01) #define XP_STX_TO_SMALLINT(x) ((x) << 1) | 0x01)
#define XP_STX_FROM_SMALLINT(x) ((x) >> 1) #define XP_STX_FROM_SMALLINT(x) ((x) >> 1)
#ifdef __cplusplus
extern "C" {
#endif
xp_stx_word_t xp_stx_alloc_object (xp_stx_t* stx, xp_size_t n);
xp_stx_word_t xp_stx_alloc_byte_object (xp_stx_t* stx, xp_size_t n);
xp_stx_word_t xp_stx_alloc_string_object (
xp_stx_t* stx, xp_stx_char_t* str, xp_size_t n);
#ifdef __cplusplus
}
#endif
#endif #endif

31
ase/stx/stx.c Normal file
View File

@ -0,0 +1,31 @@
/*
* $Id: stx.c,v 1.1 2005-05-08 07:39:51 bacon Exp $
*/
#include <xp/stx/stx.h>
#include <xp/stx/memory.h>
#include <xp/bas/memory.h>
xp_stx_t* xp_stx_open (xp_stx_t* stx, xp_stx_word_t capacity)
{
if (stx == XP_NULL) {
stx = (xp_stx_t*) xp_malloc (xp_sizeof(stx));
if (stx == XP_NULL) return XP_NULL;
stx->__malloced = xp_true;
}
else stx->__malloced = xp_false;
if (xp_stx_memory_open (&stx->memory, capacity) == XP_NULL) {
if (stx->__malloced) xp_free (stx);
return XP_NULL;
}
return stx;
}
void xp_stx_close (xp_stx_t* stx)
{
xp_stx_memory_close (&stx->memory);
if (stx->__malloced) xp_free (stx);
}

98
ase/stx/stx.h Normal file
View File

@ -0,0 +1,98 @@
/*
* $Id: stx.h,v 1.1 2005-05-08 07:39:51 bacon Exp $
*/
#ifndef _XP_STX_STX_H_
#define _XP_STX_STX_H_
#include <xp/types.h>
#include <xp/macros.h>
typedef xp_byte_t xp_stx_byte_t;
typedef xp_char_t xp_stx_char_t;
typedef xp_size_t xp_stx_word_t;
typedef xp_size_t xp_stx_size_t;
typedef xp_size_t xp_stx_index_t;
typedef struct xp_stx_object_t xp_stx_object_t;
typedef struct xp_stx_byte_object_t xp_stx_byte_object_t;
typedef struct xp_stx_string_object_t xp_stx_string_object_t;
typedef struct xp_stx_memory_t xp_stx_memory_t;
typedef struct xp_stx_t xp_stx_t;
#define XP_STX_CHAR(x) XP_CHAR(x)
#define XP_STX_TEXT(x) XP_TEXT(x)
/* common object header structure */
struct xp_stx_object_t
{
/* access - is_byte_indexed: 1; size: rest */
xp_stx_word_t access;
xp_stx_word_t class;
xp_stx_word_t data[1];
};
struct xp_stx_byte_object_t
{
xp_stx_word_t access;
xp_stx_word_t class;
xp_stx_byte_t data[1];
};
struct xp_stx_string_object_t
{
xp_stx_word_t access;
xp_stx_word_t class;
xp_stx_char_t data[1];
};
struct xp_stx_memory_t
{
xp_stx_word_t capacity;
xp_stx_object_t** slots;
xp_stx_object_t** free;
xp_bool_t __malloced;
};
struct xp_stx_t
{
xp_stx_memory_t memory;
xp_stx_word_t nil;
xp_stx_word_t true;
xp_stx_word_t false;
xp_bool_t __malloced;
};
#define XP_STX_OBJECT(mem,at) \
((xp_stx_object_t*)((mem)->slots[at]))
#define XP_STX_BYTE_OBJECT(mem,at) \
((xp_stx_byte_object_t*)((mem)->slots[at]))
#define XP_STX_STRING_OBJECT(mem,at) \
((xp_stx_string_object_t*)((mem)->slots[at]))
#define XP_STX_OBJECT_ACCESS(mem,at) ((XP_STX_OBJECT(mem,at))->access)
#define XP_STX_OBJECT_CLASS(mem,at) ((XP_STX_OBJECT(mem,at))->class)
#define XP_STX_OBJECT_DATA(mem,at) \
(((XP_STX_OBJECT_ACCESS(mem,at) & 0x04) == 0x00)? \
(XP_STX_OBJECT(mem,at)).data): \
(((XP_STX_OBJECT_ACCESS(mem,at) & 0x04) == 0x01)? \
(XP_STX_BYTE_OBJECT(mem,at)).data): \
(XP_STX_STRING_OBJECT(mem,at)).data))
#ifdef __cplusplus
extern "C" {
#endif
xp_stx_t* xp_stx_open (xp_stx_t* stx, xp_stx_word_t capacity);
void xp_stx_close (xp_stx_t* stx);
#ifdef __cplusplus
}
#endif
#endif

View File

@ -42,7 +42,7 @@ WVList
0 0
10 10
WPickList WPickList
6 8
11 11
MItem MItem
3 3
@ -139,26 +139,26 @@ WVList
0 0
33 33
MItem MItem
3 5
*.h stx.c
34 34
WString WString
3 4
NIL COBJ
35 35
WVList WVList
0 0
36 36
WVList WVList
0 0
-1 11
1 1
1 1
0 0
37 37
MItem MItem
8 3
memory.h *.h
38 38
WString WString
3 3
@ -169,14 +169,14 @@ WVList
40 40
WVList WVList
0 0
33 -1
1 1
1 1
0 0
41 41
MItem MItem
8 8
object.h memory.h
42 42
WString WString
3 3
@ -187,7 +187,43 @@ WVList
44 44
WVList WVList
0 0
33 37
1
1
0
45
MItem
8
object.h
46
WString
3
NIL
47
WVList
0
48
WVList
0
37
1
1
0
49
MItem
5
stx.h
50
WString
3
NIL
51
WVList
0
52
WVList
0
37
1 1
1 1
0 0

View File

@ -39,5 +39,5 @@ WFileName
9 9
xpstx.tgt xpstx.tgt
0 0
0 4
7 7

View File

@ -13,16 +13,16 @@ int xp_main ()
for (i = 0; i < 20; i++) { for (i = 0; i < 20; i++) {
xp_printf (XP_TEXT("%d, %d\n"), xp_printf (XP_TEXT("%d, %d\n"),
i, xp_stx_alloc_object(&mem, 100)); i, xp_stx_alloc_objmem(&mem, 100));
} }
for (i = 0; i < 5; i++) { for (i = 0; i < 5; i++) {
xp_stx_dealloc_object (&mem, i); xp_stx_dealloc_objmem (&mem, i);
} }
for (i = 0; i < 20; i++) { for (i = 0; i < 20; i++) {
xp_printf (XP_TEXT("%d, %d\n"), xp_printf (XP_TEXT("%d, %d\n"),
i, xp_stx_alloc_object(&mem, 100)); i, xp_stx_alloc_objmem(&mem, 100));
} }
xp_printf (XP_TEXT("End of program\n")); xp_printf (XP_TEXT("End of program\n"));