*** empty log message ***

This commit is contained in:
hyung-hwan 2005-05-06 17:18:29 +00:00
parent 7998a3a150
commit da4594c0e8
9 changed files with 404 additions and 27 deletions

View File

@ -1,5 +1,5 @@
/* /*
* $Id: memory.c,v 1.2 2005-05-06 16:07:58 bacon Exp $ * $Id: memory.c,v 1.3 2005-05-06 17:17:59 bacon Exp $
*/ */
#include <xp/stx/memory.h> #include <xp/stx/memory.h>
@ -71,7 +71,7 @@ xp_stx_word_t xp_stx_alloc_object (xp_stx_memory_t* mem, xp_stx_word_t nbytes)
/* find the free object slot */ /* find the free object slot */
if (mem->free == XP_NULL) { if (mem->free == XP_NULL) {
xp_stx_garbage_collect (mem); xp_stx_garbage_collect (mem);
if (mem->free == XP_NULL) return mem->capacity; if (mem->free == XP_NULL) return mem->capacity;;
} }
object = (xp_stx_object_t*)xp_malloc (nbytes); object = (xp_stx_object_t*)xp_malloc (nbytes);

View File

@ -1,5 +1,5 @@
/* /*
* $Id: memory.h,v 1.2 2005-05-06 16:07:58 bacon Exp $ * $Id: memory.h,v 1.3 2005-05-06 17:17:59 bacon Exp $
*/ */
#ifndef _XP_STX_MEMORY_H_ #ifndef _XP_STX_MEMORY_H_
@ -10,24 +10,38 @@
typedef struct xp_stx_memory_t xp_stx_memory_t; typedef struct xp_stx_memory_t xp_stx_memory_t;
typedef struct xp_stx_object_t xp_stx_object_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_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_word_t;
typedef xp_size_t xp_stx_size_t; typedef xp_size_t xp_stx_size_t;
typedef xp_size_t xp_stx_index_t; typedef xp_size_t xp_stx_index_t;
typedef xp_stx_object_t* xp_stx_pointer_t; typedef xp_stx_object_t* xp_stx_pointer_t;
#define XP_STX_OBJECT(mem,index) (mem->slots[index>>1])
/* access - is_byte_indexed: 1; size: rest */
#define XP_STX_OBJECT_HEADER \
xp_stx_word_t access; \
xp_stx_word_t class
/* common object header structure */ /* common object header structure */
struct xp_stx_object_t struct xp_stx_object_t
{ {
XP_STX_OBJECT_HEADER; /* 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 struct xp_stx_memory_t
@ -35,15 +49,29 @@ struct xp_stx_memory_t
xp_stx_word_t capacity; xp_stx_word_t capacity;
xp_stx_object_t** slots; xp_stx_object_t** slots;
xp_stx_object_t** free; xp_stx_object_t** free;
xp_stx_word_t nil;
//xp_stx_word_t smalltalk;
//xp_stx_word_t classes[];
xp_stx_word_t symbol_table;
xp_bool_t __malloced; 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" {
#endif #endif

50
ase/stx/object.c Normal file
View File

@ -0,0 +1,50 @@
/*
* $Id: object.c,v 1.1 2005-05-06 17:17:59 bacon Exp $
*/
#include <xp/stx/object.h>
/* 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 at;
/* bytes to allocated =
* number of instance variables * word_size
*/
at = xp_stx_alloc_object (mem, n * xp_sizeof(xp_stx_word_t));
if (at >= mem->capacity) return at; /* failed */
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;
}
xp_stx_word_t xp_stx_instantiate_byte (xp_stx_memory_t* mem, xp_size_t n)
{
xp_stx_word_t at;
at = xp_stx_alloc_object (mem, n);
if (at >= mem->capacity) return at; /* failed */
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;
}
xp_stx_word_t xp_stx_instantiate_string (
xp_stx_memory_t* mem, xp_stx_char_t* str, xp_stx_word_t n)
{
xp_stx_word_t at;
at = xp_stx_alloc_object (mem, n * xp_sizeof(xp_stx_char_t));
if (at >= mem->capacity) return at; /* failed */
XP_STX_OBJECT_CLASS(mem,at) = XP_STX_NIL;
XP_STX_OBJECT_ACCESS(mem,at) = ((n << 2) | 0x02);
while (n--) XP_STX_BYTE_OBJECT(mem,at)->data[n] = str[n];
return at;
}

14
ase/stx/object.h Normal file
View File

@ -0,0 +1,14 @@
/*
* $Id: object.h,v 1.1 2005-05-06 17:17:59 bacon Exp $
*/
#ifndef _XP_STX_OBJECT_H_
#define _XP_STX_OBJECT_H_
#include <xp/stx/memory.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)
#endif

View File

@ -42,7 +42,7 @@ WVList
0 0
10 10
WPickList WPickList
4 6
11 11
MItem MItem
3 3
@ -121,26 +121,26 @@ WVList
0 0
29 29
MItem MItem
3 8
*.h object.c
30 30
WString WString
3 4
NIL COBJ
31 31
WVList WVList
0 0
32 32
WVList WVList
0 0
-1 11
1 1
1 1
0 0
33 33
MItem MItem
8 3
memory.h *.h
34 34
WString WString
3 3
@ -151,7 +151,43 @@ WVList
36 36
WVList WVList
0 0
29 -1
1
1
0
37
MItem
8
memory.h
38
WString
3
NIL
39
WVList
0
40
WVList
0
33
1
1
0
41
MItem
8
object.h
42
WString
3
NIL
43
WVList
0
44
WVList
0
33
1 1
1 1
0 0

View File

@ -4,8 +4,8 @@ projectIdent
VpeMain VpeMain
1 1
WRect WRect
4300 1500
333 440
4330 4330
9200 9200
2 2

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

@ -0,0 +1,31 @@
#include <xp/stx/memory.h>
#include <xp/bas/stdio.h>
int xp_main ()
{
xp_stx_memory_t mem;
xp_stx_word_t i;
if (xp_stx_memory_open (&mem, 10) == XP_NULL) {
xp_printf (XP_TEXT("cannot open memory\n"));
return -1;
}
for (i = 0; i < 20; i++) {
xp_printf (XP_TEXT("%d, %d\n"),
i, xp_stx_alloc_object(&mem, 100));
}
for (i = 0; i < 5; i++) {
xp_stx_dealloc_object (&mem, i);
}
for (i = 0; i < 20; i++) {
xp_printf (XP_TEXT("%d, %d\n"),
i, xp_stx_alloc_object(&mem, 100));
}
xp_printf (XP_TEXT("End of program\n"));
return 0;
}

175
ase/test/stx/stx.tgt Normal file
View File

@ -0,0 +1,175 @@
40
targetIdent
0
MProject
1
MComponent
0
2
WString
4
NEXE
3
WString
5
nc2en
1
0
1
4
MCommand
0
5
MCommand
0
6
MItem
7
stx.exe
7
WString
4
NEXE
8
WVList
0
9
WVList
0
-1
1
1
0
10
WPickList
5
11
MItem
3
*.c
12
WString
4
COBJ
13
WVList
3
14
MVState
15
WString
3
WCC
16
WString
25
n????Include directories:
1
17
WString
37
$(%watcom)\h;$(%watcom)\h\nt;..\..\..
0
18
MRState
19
WString
3
WCC
20
WString
35
??2??Pentium Register based calling
1
0
21
MRState
22
WString
3
WCC
23
WString
32
??2??Pentium Stack based calling
1
1
24
WVList
0
-1
1
1
0
25
MItem
5
stx.c
26
WString
4
COBJ
27
WVList
0
28
WVList
0
11
1
1
0
29
MItem
5
*.lib
30
WString
3
NIL
31
WVList
0
32
WVList
0
-1
1
1
0
33
MItem
19
..\..\bas\xpbas.lib
34
WString
3
NIL
35
WVList
0
36
WVList
0
29
1
1
0
37
MItem
19
..\..\stx\xpstx.lib
38
WString
3
NIL
39
WVList
0
40
WVList
0
29
1
1
0

43
ase/test/stx/stx.wpj Normal file
View File

@ -0,0 +1,43 @@
40
projectIdent
0
VpeMain
1
WRect
1500
440
7680
9200
2
MProject
3
MCommand
0
4
MCommand
0
1
5
WFileName
7
stx.tgt
6
WVList
1
7
VComponent
8
WRect
0
0
5700
4280
0
0
9
WFileName
7
stx.tgt
0
3
7