diff --git a/ase/stx/memory.c b/ase/stx/memory.c index 1a75b634..a02bf9ff 100644 --- a/ase/stx/memory.c +++ b/ase/stx/memory.c @@ -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 @@ -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 */ if (mem->free == XP_NULL) { 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); diff --git a/ase/stx/memory.h b/ase/stx/memory.h index 25358461..35ff2c86 100644 --- a/ase/stx/memory.h +++ b/ase/stx/memory.h @@ -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_ @@ -10,24 +10,38 @@ 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; -#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 */ 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 @@ -35,15 +49,29 @@ struct xp_stx_memory_t xp_stx_word_t capacity; xp_stx_object_t** slots; 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; }; +#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 extern "C" { #endif diff --git a/ase/stx/object.c b/ase/stx/object.c new file mode 100644 index 00000000..e86a43be --- /dev/null +++ b/ase/stx/object.c @@ -0,0 +1,50 @@ +/* + * $Id: object.c,v 1.1 2005-05-06 17:17:59 bacon Exp $ + */ + +#include + +/* 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; +} diff --git a/ase/stx/object.h b/ase/stx/object.h new file mode 100644 index 00000000..20ff9c66 --- /dev/null +++ b/ase/stx/object.h @@ -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 + +#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 diff --git a/ase/stx/xpstx.tgt b/ase/stx/xpstx.tgt index c9b8a9d8..d49c17ad 100644 --- a/ase/stx/xpstx.tgt +++ b/ase/stx/xpstx.tgt @@ -42,7 +42,7 @@ WVList 0 10 WPickList -4 +6 11 MItem 3 @@ -121,26 +121,26 @@ WVList 0 29 MItem -3 -*.h +8 +object.c 30 WString -3 -NIL +4 +COBJ 31 WVList 0 32 WVList 0 --1 +11 1 1 0 33 MItem -8 -memory.h +3 +*.h 34 WString 3 @@ -151,7 +151,43 @@ WVList 36 WVList 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 0 diff --git a/ase/stx/xpstx.wpj b/ase/stx/xpstx.wpj index f7bb4c64..f6e34827 100644 --- a/ase/stx/xpstx.wpj +++ b/ase/stx/xpstx.wpj @@ -4,8 +4,8 @@ projectIdent VpeMain 1 WRect -4300 -333 +1500 +440 4330 9200 2 diff --git a/ase/test/stx/stx.c b/ase/test/stx/stx.c new file mode 100644 index 00000000..23400674 --- /dev/null +++ b/ase/test/stx/stx.c @@ -0,0 +1,31 @@ +#include +#include + +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; +} + diff --git a/ase/test/stx/stx.tgt b/ase/test/stx/stx.tgt new file mode 100644 index 00000000..d2d4cc51 --- /dev/null +++ b/ase/test/stx/stx.tgt @@ -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 diff --git a/ase/test/stx/stx.wpj b/ase/test/stx/stx.wpj new file mode 100644 index 00000000..4481ab97 --- /dev/null +++ b/ase/test/stx/stx.wpj @@ -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